blob: 7b75fbc949439ff6f59eb9daa81ca6e33332be10 [file] [log] [blame]
Instrumental31d847e2018-03-26 14:17:19 -07001#
2# Initialize a manual Cert. This is NOT entered in Certman Records
3#
4echo "FQI (Fully Qualified Identity): "
5read FQI
6if [ "$1" = "" -o "$1" = "-local" ]; then
7 echo "Personal Certificate"
8 SUBJECT="/CN=$FQI/OU=V1`cat subject.aaf`"
Instrumental97083ef2018-04-25 15:22:38 -05009 NAME=$FQI
Instrumental31d847e2018-03-26 14:17:19 -070010else
11 echo "Application Certificate"
12 SUBJECT="/CN=$1/OU=$FQI`cat subject.aaf`"
Instrumental97083ef2018-04-25 15:22:38 -050013 FQDN=$1
14 NAME=$FQDN
Instrumental31d847e2018-03-26 14:17:19 -070015 shift
16fi
17echo $SUBJECT
18
19if [ -e $FQI.csr ]; then
20 SIGN_IT=true
21else
22 if [ "$1" = "-local" ]; then
23 echo "IMPORTANT: If for any reason, you kill this process, type 'stty sane'"
24 echo "Enter the PassPhrase for the Key for $FQI: "
25 `stty -echo`
26 read PASSPHRASE
27 `stty echo`
28
29 # remove any previous Private key
Instrumental97083ef2018-04-25 15:22:38 -050030 rm private/$NAME.key
Instrumental31d847e2018-03-26 14:17:19 -070031 # Create j regaular rsa encrypted key
Instrumental97083ef2018-04-25 15:22:38 -050032 openssl req -new -newkey rsa:2048 -sha256 -keyout private/$NAME.key \
33 -out $NAME.csr -outform PEM -subj "$SUBJECT" \
Instrumental31d847e2018-03-26 14:17:19 -070034 -passout stdin << EOF
35$PASSPHRASE
36EOF
Instrumental97083ef2018-04-25 15:22:38 -050037 chmod 400 private/$NAME.key
Instrumental31d847e2018-03-26 14:17:19 -070038 SIGN_IT=true
39 else
Instrumental97083ef2018-04-25 15:22:38 -050040 echo openssl req -newkey rsa:2048 -sha256 -keyout $NAME.key -out $NAME.csr -outform PEM -subj '"'$SUBJECT'"'
41 echo chmod 400 $NAME.key
Instrumental31d847e2018-03-26 14:17:19 -070042 echo "# All done, print result"
Instrumental97083ef2018-04-25 15:22:38 -050043 echo openssl req -verify -text -noout -in $NAME.csr
Instrumental31d847e2018-03-26 14:17:19 -070044 fi
45fi
46
47if [ "$SIGN_IT" = "true" ]; then
48 # Sign it
Instrumental97083ef2018-04-25 15:22:38 -050049 openssl ca -config ../openssl.conf -extensions server_cert -out $NAME.crt \
Instrumental31d847e2018-03-26 14:17:19 -070050 -cert certs/ca.crt -keyfile private/ca.key \
Instrumental924b18d2018-04-05 20:17:18 -050051 -policy policy_loose \
52 -days 360 \
Instrumental97083ef2018-04-25 15:22:38 -050053 -infiles $NAME.csr
Instrumental31d847e2018-03-26 14:17:19 -070054fi
55
56
57
58