File: cert_tool

package info (click to toggle)
squid3 3.4.8-6
  • links: PTS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 31,084 kB
  • sloc: cpp: 165,325; ansic: 21,998; sh: 12,166; makefile: 5,964; perl: 2,153; sql: 322; awk: 118
file content (83 lines) | stat: -rw-r--r-- 2,244 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
#
#  -----------------------------------------------------------------------------
# 
#  Author: Markus Moeller (markus_moeller at compuserve.com)
# 
#  Copyright (C) 2007 Markus Moeller. All rights reserved.
# 
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
# 
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
# 
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
# 
#  -----------------------------------------------------------------------------
#
#
# creates the following files: 
# <server>.cert
# secmod.db
# key3.db
# cert8.db
# 
#
if [ -z "$1" ]; then 
  echo "Usage: `basename $0` ldap-server port"
  exit 0
fi
if [ -z "$2" ]; then
  port=636
else
  port=$2
fi

server=$1

#
# Remove old files
#
rm  ${server}_[0-9]*.cert 2>/dev/null
#
# Get certs and store in .cert file
#
( openssl s_client -showcerts -connect $server:$port 2>/dev/null <<!
QUIT
!
) | awk 'BEGIN{start=0;ostart=0}{if ( $0 ~ /BEGIN CERTIFICATE/ ) { start=start+1 };
      if  ( start > ostart ) {print $0 >>"'$server'_"start".cert"};
      if ( $0 ~ /END CERTIFICATE/) { ostart=start } }' 

#
# from mozilla-nss-tools
# /usr/sfw/bin on Solaris
# 
#
# Create database for Sun ldap and pem file for Openldap 
#
rm ${server}_[0-9]*.pem 2>/dev/null
i=0
ls ${server}_[0-9]*.cert | while read file; do
 i=$(($i+1))
 cat  $file  >> ${server}_$i.pem
 CA=`openssl x509 -noout -text -in  ${server}_$i.pem | grep -i "CA:.*true"`
 if [ -n "$CA" ]; then
   echo "CA is in ${server}_$i.pem"
   certutil -A -a -n "${server}_$i" -i $file -t "C,," -d .
 else
   certutil -A -a -n "${server}_$i" -i $file -t "P,," -d .
 fi
 rm $file
done
echo "Certs:"
certutil -d . -L
echo "are in" 
ls *.db