blob: 07a1ed6ae8c5e9d63505c429fcfc17197765cb14 [file] [log] [blame]
Instrumental31d847e2018-03-26 14:17:19 -07001#
2# Initialize a manual Cert. This is NOT entered in Certman Records
Maciej Wejs02c19702018-08-17 13:56:31 +02003# $1 - CN (Common Name)
4# $2 - FQI (Fully Qualified Identity)
5# $3-$n - SANs (Service Alias Names)
Instrumental31d847e2018-03-26 14:17:19 -07006#
Maciej Wejs02c19702018-08-17 13:56:31 +02007
8if [ "$2" = "" ]; then
9 echo "FQI (Fully Qualified Identity): "
10 read FQI
11fi
12
13if [ "$1" = "" -o "$1" = "-local" ]; then
Instrumental31d847e2018-03-26 14:17:19 -070014 echo "Personal Certificate"
15 SUBJECT="/CN=$FQI/OU=V1`cat subject.aaf`"
Instrumental97083ef2018-04-25 15:22:38 -050016 NAME=$FQI
Maciej Wejs02c19702018-08-17 13:56:31 +020017else
Instrumental31d847e2018-03-26 14:17:19 -070018 echo "Application Certificate"
19 SUBJECT="/CN=$1/OU=$FQI`cat subject.aaf`"
Maciej Wejs02c19702018-08-17 13:56:31 +020020 NAME=$1
Instrumental68b23152018-05-01 15:03:25 -050021
Maciej Wejs02c19702018-08-17 13:56:31 +020022 if [ "$3" = "" ]; then
23 echo "Enter any SANS, delimited by spaces: "
24 read SANS
25 else
26 SANS=""
27 while [ ! "$3" = "" ]; do
28 SANS=${SANS}" "$3
29 shift
30 done
31 fi
Instrumental31d847e2018-03-26 14:17:19 -070032fi
Instrumental68b23152018-05-01 15:03:25 -050033
34# Do SANs
35if [ "$SANS" = "" ]; then
36 echo no SANS
Maciej Wejs02c19702018-08-17 13:56:31 +020037 if [ -e $NAME.san ]; then
Instrumental68b23152018-05-01 15:03:25 -050038 rm $NAME.san
39 fi
40 else
Maciej Wejs02c19702018-08-17 13:56:31 +020041 echo some SANS: $SANS
Instrumental68b23152018-05-01 15:03:25 -050042 cp ../san.conf $NAME.san
43 NUM=1
Maciej Wejs02c19702018-08-17 13:56:31 +020044 for D in $SANS; do
Instrumental68b23152018-05-01 15:03:25 -050045 echo "DNS.$NUM = $D" >> $NAME.san
Maciej Wejs02c19702018-08-17 13:56:31 +020046 NUM=$((NUM+1))
Instrumental68b23152018-05-01 15:03:25 -050047 done
48fi
49
Instrumental31d847e2018-03-26 14:17:19 -070050echo $SUBJECT
51
Maciej Wejs02c19702018-08-17 13:56:31 +020052if [ ! -e $NAME.csr ]; then
Instrumental31d847e2018-03-26 14:17:19 -070053 if [ "$1" = "-local" ]; then
54 echo "IMPORTANT: If for any reason, you kill this process, type 'stty sane'"
55 echo "Enter the PassPhrase for the Key for $FQI: "
56 `stty -echo`
57 read PASSPHRASE
58 `stty echo`
Maciej Wejs02c19702018-08-17 13:56:31 +020059
Instrumental31d847e2018-03-26 14:17:19 -070060 # remove any previous Private key
Instrumental97083ef2018-04-25 15:22:38 -050061 rm private/$NAME.key
Maciej Wejs02c19702018-08-17 13:56:31 +020062 # Create regular rsa encrypted key
Instrumental97083ef2018-04-25 15:22:38 -050063 openssl req -new -newkey rsa:2048 -sha256 -keyout private/$NAME.key \
64 -out $NAME.csr -outform PEM -subj "$SUBJECT" \
Instrumental31d847e2018-03-26 14:17:19 -070065 -passout stdin << EOF
66$PASSPHRASE
67EOF
Maciej Wejs02c19702018-08-17 13:56:31 +020068 chmod 400 private/$NAME.key
69 else
70 openssl req -newkey rsa:2048 -sha256 -keyout private/$NAME.key -out $NAME.csr -outform PEM -subj "$SUBJECT"
71 chmod 400 $NAME.key
Instrumental31d847e2018-03-26 14:17:19 -070072 echo "# All done, print result"
Maciej Wejs02c19702018-08-17 13:56:31 +020073 openssl req -verify -text -noout -in $NAME.csr
Instrumental31d847e2018-03-26 14:17:19 -070074 fi
75fi
76
Instrumental31d847e2018-03-26 14:17:19 -070077 # Sign it
Instrumental68b23152018-05-01 15:03:25 -050078 if [ -e $NAME.san ]; then
Maciej Wejs02c19702018-08-17 13:56:31 +020079 openssl ca -config ../openssl.conf -extensions server_cert -out certs/$NAME.crt \
Instrumental68b23152018-05-01 15:03:25 -050080 -cert certs/ca.crt -keyfile private/ca.key \
81 -policy policy_loose \
82 -days 360 \
83 -extfile $NAME.san \
84 -infiles $NAME.csr
Maciej Wejs02c19702018-08-17 13:56:31 +020085 else
86 openssl ca -config ../openssl.conf -extensions server_cert -out certs/$NAME.crt \
Instrumental31d847e2018-03-26 14:17:19 -070087 -cert certs/ca.crt -keyfile private/ca.key \
Instrumental924b18d2018-04-05 20:17:18 -050088 -policy policy_loose \
89 -days 360 \
Instrumental97083ef2018-04-25 15:22:38 -050090 -infiles $NAME.csr
Instrumental68b23152018-05-01 15:03:25 -050091 fi