Merge "Increase code coverage auth fs"
[aaf/authz.git] / conf / CA / manual.sh
1 #
2 # Initialize a manual Cert.  This is NOT entered in Certman Records
3 #
4 echo "FQI (Fully Qualified Identity): "
5 read FQI
6 if [ "$1" = "" -o "$1" = "-local" ]; then 
7   echo "Personal Certificate"
8   SUBJECT="/CN=$FQI/OU=V1`cat subject.aaf`"
9   NAME=$FQI
10 else 
11   echo "Application Certificate"
12   SUBJECT="/CN=$1/OU=$FQI`cat subject.aaf`"
13   FQDN=$1
14   NAME=$FQDN
15   shift
16
17   echo "Enter any SANS, delimited by spaces: "
18   read SANS
19 fi
20
21 # Do SANs
22 if [ "$SANS" = "" ]; then
23    echo no SANS
24     if [ -e $NAME.san ]; then 
25       rm $NAME.san
26     fi
27   else
28    echo some SANS
29     cp ../san.conf $NAME.san
30     NUM=1
31     for D in $SANS; do 
32         echo "DNS.$NUM = $D" >> $NAME.san
33         NUM=$((NUM+1))
34     done
35 fi
36
37 echo $SUBJECT
38
39 if [ -e $NAME.csr ]; then
40   SIGN_IT=true
41 else 
42   if [ "$1" = "-local" ]; then
43         echo "IMPORTANT: If for any reason, you kill this process, type 'stty sane'"
44         echo "Enter the PassPhrase for the Key for $FQI: "
45         `stty -echo`
46         read PASSPHRASE
47         `stty echo`
48  
49         # remove any previous Private key
50         rm private/$NAME.key
51         # Create j regaular rsa encrypted key
52         openssl req -new -newkey rsa:2048 -sha256 -keyout private/$NAME.key \
53           -out $NAME.csr -outform PEM -subj "$SUBJECT" \
54           -passout stdin  << EOF
55 $PASSPHRASE
56 EOF
57         chmod 400 private/$NAME.key 
58         SIGN_IT=true
59   else 
60         echo openssl req -newkey rsa:2048 -sha256 -keyout $NAME.key -out $NAME.csr -outform PEM -subj '"'$SUBJECT'"'
61         echo chmod 400 $NAME.key
62         echo "# All done, print result"
63         echo openssl req -verify -text -noout -in $NAME.csr
64   fi
65 fi
66
67 if [ "$SIGN_IT" = "true" ]; then
68   # Sign it
69   if [ -e $NAME.san ]; then
70     openssl ca -config ../openssl.conf -extensions server_cert -out $NAME.crt \
71         -cert certs/ca.crt -keyfile private/ca.key \
72         -policy policy_loose \
73         -days 360 \
74         -extfile $NAME.san \
75         -infiles $NAME.csr
76   else 
77     openssl ca -config ../openssl.conf -extensions server_cert -out $NAME.crt \
78         -cert certs/ca.crt -keyfile private/ca.key \
79         -policy policy_loose \
80         -days 360 \
81         -infiles $NAME.csr
82   fi
83 fi
84