RAND_pseudo_bytes is good enough for encryption IVs,
[openssl.git] / tools / c_rehash.in
1 #!/bin/sh
2 #
3 # redo the hashes for the certificates in your cert path or the ones passed
4 # on the command line.
5 #
6
7 if [ "$OPENSSL"x = "x" -o ! -x "$OPENSSL" ]; then
8         OPENSSL='openssl'
9         export OPENSSL
10 fi
11 DIR=/usr/local/ssl
12 PATH=$DIR/bin:$PATH
13
14 if [ ! -f "$OPENSSL" ]; then
15     found=0
16     for dir in . `echo $PATH | sed -e 's/:/ /g'`; do
17         if [ -f "$dir/$OPENSSL" ]; then
18             found=1
19             break
20         fi
21     done
22     if [ $found = 0 ]; then
23         echo "c_rehash: rehashing skipped ('openssl' program not available)" 1>&2
24         exit 0
25     fi
26 fi
27
28 SSL_DIR=$DIR/certs
29
30 if [ "$*" = "" ]; then
31         CERTS=${*:-${SSL_CERT_DIR:-$SSL_DIR}}
32 else
33         CERTS=$*
34 fi
35
36 IFS=': '
37 for i in $CERTS
38 do
39   (
40   IFS=' '
41   if [ -d $i -a -w $i ]; then
42     cd $i
43     echo "Doing $i"
44     for i in *.pem
45     do
46       if [ $i != '*.pem' ]; then
47         h=`$OPENSSL x509 -hash -noout -in $i`
48         if [ "x$h" = "x" ]; then
49           echo $i does not contain a certificate
50         else
51           if [ -f $h.0 ]; then
52             /bin/rm -f $h.0
53           fi
54           echo "$i => $h.0"
55           ln -s $i $h.0
56         fi
57       fi
58     done
59   fi
60   )
61 done