blob: 145c22c7a5ee3877fd0552cea0b2a5bafafa824e [file] [log] [blame]
Instrumentalcc596dd2018-08-23 09:52:14 -05001#
2# Streamlined AAF Bootstrap initial Cert
3# Removed Variables so it can be run for AutoDeployments
4#
5echo "Bootstrap AAF Certificate"
Instrumentalb8a81292018-08-23 16:32:45 -05006mkdir -p private certs newcerts
7chmod 700 private
8chmod 755 certs newcerts
9touch index.txt
10echo "unique_subject = no" > index.txt.attr
Instrumental0d4ec122018-08-30 14:33:08 -050011if [ ! -e ./serial ]; then
Instrumental93871ff2018-10-15 07:37:28 -050012 echo $(date +%s)_$(shuf -i 0-1000000 -n 1) > ./serial
Instrumental0d4ec122018-08-30 14:33:08 -050013fi
Instrumentalb8a81292018-08-23 16:32:45 -050014
Instrumentalcc596dd2018-08-23 09:52:14 -050015NAME=aaf.bootstrap
Instrumental54883b42018-09-25 07:56:54 -050016FQDN="${HOSTNAME:=$(hostname -f)}"
Instrumentalcc596dd2018-08-23 09:52:14 -050017FQI=aaf@aaf.osaaf.org
18SUBJECT="/CN=$FQDN/OU=$FQI`cat subject.aaf`"
19SIGNER_P12=$1
20SIGNER_KEY=/tmp/aaf_signer.key
21SIGNER_CRT=/tmp/aaf_signer.crt
22PASSPHRASE=$2
23if [ "PASSPHRASE" = "" ]; then
24 PASSPHRASE="something easy"
25fi
26BOOTSTRAP_SAN=/tmp/$NAME.san
27BOOTSTRAP_KEY=/tmp/$NAME.key
28BOOTSTRAP_CSR=/tmp/$NAME.csr
29BOOTSTRAP_CRT=/tmp/$NAME.crt
Instrumentalb8a81292018-08-23 16:32:45 -050030BOOTSTRAP_CHAIN=/tmp/$NAME.chain
Instrumentalcc596dd2018-08-23 09:52:14 -050031BOOTSTRAP_P12=$NAME.p12
Instrumentalbc299c02018-09-25 06:42:31 -050032BOOTSTRAP_ISSUER=$NAME.issuer
Instrumentalcc596dd2018-08-23 09:52:14 -050033
34
35# If Signer doesn't exist, create Self-Signed CA
36if [ ! -e "$SIGNER_P12" ]; then
37 # Creating Signer CA
38 openssl req -config openssl.conf -x509 -sha256 -extensions v3_ca \
Instrumentalb8a81292018-08-23 16:32:45 -050039 -newkey rsa:4096 -subj /CN="Signer$(cat subject.aaf)" \
40 -keyout $SIGNER_KEY -out $SIGNER_CRT -days 365 -passout stdin << EOF
41$PASSPHRASE
42EOF
Instrumentalcc596dd2018-08-23 09:52:14 -050043
44 # Move to P12 (Signer)
45 openssl pkcs12 -name RootCA -export -in $SIGNER_CRT -inkey $SIGNER_KEY -out $SIGNER_P12 -passin stdin -passout stdin << EOF
46$PASSPHRASE
47$PASSPHRASE
48$PASSPHRASE
49EOF
50
51else
52 # Get Private key from P12
53 openssl pkcs12 -in $SIGNER_P12 -nocerts -nodes -passin stdin -passout stdin -out $SIGNER_KEY << EOF
54$PASSPHRASE
55$PASSPHRASE
56EOF
57
58 # Get Cert from P12
59 openssl pkcs12 -in $SIGNER_P12 -clcerts -nokeys -passin stdin -out $SIGNER_CRT << EOF
60$PASSPHRASE
61EOF
62
63fi
64
65# SANS
66cp san.conf $BOOTSTRAP_SAN
Instrumental1e3be602018-10-03 19:40:44 -050067SANS=$FQDN
68if [ "$FQDN" -ne "$HOSTNAME" ]; then
69 SANS="$SANS $HOSTNAME"
70fi
71
72for ROOT in $(cat san_root.aaf); do
73 SANS="$SANS $ROOT"
74 for C in service locate oauth gui cm hello; do
75 SANS="$SANS $C.$ROOT"
76 done
77done
Instrumental65cdc092018-10-15 12:34:59 -050078
79for C in service locate oauth gui cm hello; do
80 SANS="$SANS aaf-$C"
81 SANS="$SANS aaf-$C.onap"
82done
83
Instrumentalcc596dd2018-08-23 09:52:14 -050084NUM=1
Instrumental1e3be602018-10-03 19:40:44 -050085for D in $SANS; do
Instrumentalcc596dd2018-08-23 09:52:14 -050086 echo "DNS.$NUM = $D" >> $BOOTSTRAP_SAN
87 NUM=$((NUM+1))
88done
89
90# Create CSR
Instrumentalb8a81292018-08-23 16:32:45 -050091openssl req -new -newkey rsa:2048 -nodes -keyout $BOOTSTRAP_KEY \
92 -out $BOOTSTRAP_CSR -outform PEM -subj "$SUBJECT" \
93 -passout stdin << EOF
94$PASSPHRASE
95EOF
Instrumentalcc596dd2018-08-23 09:52:14 -050096
Instrumentalb8a81292018-08-23 16:32:45 -050097echo Sign it
98openssl ca -batch -config openssl.conf -extensions server_cert \
Instrumentalcc596dd2018-08-23 09:52:14 -050099 -cert $SIGNER_CRT -keyfile $SIGNER_KEY \
100 -policy policy_loose \
Instrumental08e93402018-10-03 08:38:52 -0500101 -days 365 \
Instrumentalb8a81292018-08-23 16:32:45 -0500102 -passin stdin \
103 -out $BOOTSTRAP_CRT \
Instrumentalcc596dd2018-08-23 09:52:14 -0500104 -extfile $BOOTSTRAP_SAN \
Instrumentalb8a81292018-08-23 16:32:45 -0500105 -infiles $BOOTSTRAP_CSR << EOF
106$PASSPHRASE
107EOF
Instrumentalcc596dd2018-08-23 09:52:14 -0500108
109# Make a P12
110# Add THIS Intermediate CA into chain
Instrumentalb8a81292018-08-23 16:32:45 -0500111cat $BOOTSTRAP_CRT
112cp $BOOTSTRAP_CRT $BOOTSTRAP_CHAIN
113cat $SIGNER_CRT >> $BOOTSTRAP_CHAIN
Instrumental08e93402018-10-03 08:38:52 -0500114cat $BOOTSTRAP_CHAIN
Instrumentalcc596dd2018-08-23 09:52:14 -0500115
116# Note: Openssl will pickup and load all Certs in the Chain file
Instrumental08e93402018-10-03 08:38:52 -0500117#openssl pkcs12 -name $FQI -export -in $BOOTSTRAP_CRT -inkey $BOOTSTRAP_KEY -CAfile $SIGNER_CRT -out $BOOTSTRAP_P12 -passin stdin -passout stdin << EOF
Instrumentalb8a81292018-08-23 16:32:45 -0500118openssl pkcs12 -name $FQI -export -in $BOOTSTRAP_CHAIN -inkey $BOOTSTRAP_KEY -out $BOOTSTRAP_P12 -passin stdin -passout stdin << EOF
Instrumentalcc596dd2018-08-23 09:52:14 -0500119$PASSPHRASE
120$PASSPHRASE
121$PASSPHRASE
122EOF
123
Instrumentalbc299c02018-09-25 06:42:31 -0500124# Make Issuer name
125ISSUER=$(openssl x509 -subject -noout -in $SIGNER_CRT | cut -c 10-)
126for I in ${ISSUER//\// }; do
127 if [ -n "$CADI_X509_ISSUER" ]; then
128 CADI_X509_ISSUER=", $CADI_X509_ISSUER"
129 fi
130 CADI_X509_ISSUER="$I$CADI_X509_ISSUER"
131done
132echo $CADI_X509_ISSUER > $BOOTSTRAP_ISSUER
133
Instrumentalcc596dd2018-08-23 09:52:14 -0500134# Cleanup
Instrumental08e93402018-10-03 08:38:52 -0500135rm -f $BOOTSTRAP_SAN $BOOTSTRAP_KEY $BOOTSTRAP_CSR $BOOTSTRAP_CRT $SIGNER_KEY $SIGNER_CRT $BOOTSTRAP_CHAIN