| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Shell-Script which creates a symbolic hash-link for each CA certificate |
| 4 | # and each CRL in the given directory. |
| 5 | # Copyright (C) 2003 Mario Strasser <[email protected]> |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or modify it |
| 8 | # under the terms of the GNU General Public License as published by the |
| 9 | # Free Software Foundation; either version 2 of the License, or (at your |
| 10 | # option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, but |
| 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 14 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 | # for more details. |
| 16 | # |
| 17 | # $Id$ |
| 18 | # |
| 19 | |
| 20 | OPENSSL="openssl" |
| 21 | |
| 22 | # function to create the hash link |
| 23 | function mk_link() |
| 24 | { |
| 25 | nr=0 |
| 26 | while [ -e $hash$nr ]; do |
| 27 | if [ $file -ef $hash$nr ] || [ -h $file ]; then |
| 28 | break; |
| 29 | fi |
| 30 | nr=`expr $nr + 1` |
| 31 | done |
| 32 | if [ ! $file -ef $hash$nr ] && [ ! -h $file ]; then |
| 33 | ln -s $file $hash$nr |
| 34 | fi |
| 35 | } |
| 36 | |
| 37 | # change to the target directory |
| 38 | if [ $1 ]; then |
| 39 | if [ -d $1 ]; then |
| 40 | cd $1 |
| 41 | else |
| 42 | echo "Error: $1 is not a valid directory!" |
| 43 | exit -1 |
| 44 | fi |
| 45 | fi |
| 46 | # test the presence of openssl |
| 47 | if [ -z "`$OPENSSL version 2> /dev/null`" ] |
| 48 | then |
| 49 | echo "$OPENSSL not found! install openssl first" |
| 50 | exit -1 |
| 51 | fi |
| 52 | # process all files |
| 53 | |
| 54 | ( |
| 55 | IFS=$'\n' |
| 56 | |
| 57 | for file in *; do |
| 58 | hash=`$OPENSSL x509 -inform pem -in $file -noout -hash 2> /dev/null` |
| 59 | if [ ! -z "$hash" ]; then |
| 60 | is_ca=`$OPENSSL x509 -inform pem -in $file -noout -text | grep 'CA:TRUE'` |
| 61 | if [ ! -z "$is_ca" ]; then |
| 62 | hash=$hash. |
| 63 | mk_link |
| 64 | fi |
| 65 | continue |
| 66 | fi |
| 67 | hash=`$OPENSSL x509 -inform der -in $file -noout -hash 2> /dev/null` |
| 68 | if [ ! -z "$hash" ]; then |
| 69 | is_ca=`$OPENSSL x509 -inform der -in $file -noout -text | grep 'CA:TRUE'` |
| 70 | if [ ! -z "$is_ca" ]; then |
| 71 | hash=$hash. |
| 72 | mk_link |
| 73 | fi |
| 74 | continue |
| 75 | fi |
| 76 | hash=`$OPENSSL crl -inform pem -in $file -noout -hash 2> /dev/null` |
| 77 | if [ ! -z "$hash" ]; then |
| 78 | hash=$hash.r |
| 79 | mk_link |
| 80 | continue |
| 81 | fi |
| 82 | hash=`$OPENSSL crl -inform der -in $file -noout -hash 2> /dev/null` |
| 83 | if [ ! -z "$hash" ]; then |
| 84 | hash=$hash.r |
| 85 | mk_link |
| 86 | continue |
| 87 | fi |
| 88 | |
| 89 | # nothing can be done with the file |
| 90 | echo "we got a problem with: $file" |
| 91 | done |
| 92 | ) |
| 93 | |
| 94 | exit 0 |