2 # Streamlined AAF Bootstrap initial Cert
3 # Removed Variables so it can be run for AutoDeployments
5 echo "Bootstrap AAF Certificate"
6 mkdir -p private certs newcerts
8 chmod 755 certs newcerts
10 echo "unique_subject = no" > index.txt.attr
11 if [ ! -e ./serial ]; then
12 echo $(date +%s) > ./serial
16 FQDN="${HOSTNAME:=$(hostname -f)}"
18 SUBJECT="/CN=$FQDN/OU=$FQI`cat subject.aaf`"
20 SIGNER_KEY=/tmp/aaf_signer.key
21 SIGNER_CRT=/tmp/aaf_signer.crt
23 if [ "PASSPHRASE" = "" ]; then
24 PASSPHRASE="something easy"
26 BOOTSTRAP_SAN=/tmp/$NAME.san
27 BOOTSTRAP_KEY=/tmp/$NAME.key
28 BOOTSTRAP_CSR=/tmp/$NAME.csr
29 BOOTSTRAP_CRT=/tmp/$NAME.crt
30 BOOTSTRAP_CHAIN=/tmp/$NAME.chain
31 BOOTSTRAP_P12=$NAME.p12
32 BOOTSTRAP_ISSUER=$NAME.issuer
35 # If Signer doesn't exist, create Self-Signed CA
36 if [ ! -e "$SIGNER_P12" ]; then
38 openssl req -config openssl.conf -x509 -sha256 -extensions v3_ca \
39 -newkey rsa:4096 -subj /CN="Signer$(cat subject.aaf)" \
40 -keyout $SIGNER_KEY -out $SIGNER_CRT -days 365 -passout stdin << EOF
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
52 # Get Private key from P12
53 openssl pkcs12 -in $SIGNER_P12 -nocerts -nodes -passin stdin -passout stdin -out $SIGNER_KEY << EOF
59 openssl pkcs12 -in $SIGNER_P12 -clcerts -nokeys -passin stdin -out $SIGNER_CRT << EOF
66 cp san.conf $BOOTSTRAP_SAN
68 if [ "$FQDN" -ne "$HOSTNAME" ]; then
69 SANS="$SANS $HOSTNAME"
72 for ROOT in $(cat san_root.aaf); do
74 for C in service locate oauth gui cm hello; do
80 echo "DNS.$NUM = $D" >> $BOOTSTRAP_SAN
85 openssl req -new -newkey rsa:2048 -nodes -keyout $BOOTSTRAP_KEY \
86 -out $BOOTSTRAP_CSR -outform PEM -subj "$SUBJECT" \
92 openssl ca -batch -config openssl.conf -extensions server_cert \
93 -cert $SIGNER_CRT -keyfile $SIGNER_KEY \
94 -policy policy_loose \
98 -extfile $BOOTSTRAP_SAN \
99 -infiles $BOOTSTRAP_CSR << EOF
104 # Add THIS Intermediate CA into chain
106 cp $BOOTSTRAP_CRT $BOOTSTRAP_CHAIN
107 cat $SIGNER_CRT >> $BOOTSTRAP_CHAIN
110 # Note: Openssl will pickup and load all Certs in the Chain file
111 #openssl pkcs12 -name $FQI -export -in $BOOTSTRAP_CRT -inkey $BOOTSTRAP_KEY -CAfile $SIGNER_CRT -out $BOOTSTRAP_P12 -passin stdin -passout stdin << EOF
112 openssl pkcs12 -name $FQI -export -in $BOOTSTRAP_CHAIN -inkey $BOOTSTRAP_KEY -out $BOOTSTRAP_P12 -passin stdin -passout stdin << EOF
119 ISSUER=$(openssl x509 -subject -noout -in $SIGNER_CRT | cut -c 10-)
120 for I in ${ISSUER//\// }; do
121 if [ -n "$CADI_X509_ISSUER" ]; then
122 CADI_X509_ISSUER=", $CADI_X509_ISSUER"
124 CADI_X509_ISSUER="$I$CADI_X509_ISSUER"
126 echo $CADI_X509_ISSUER > $BOOTSTRAP_ISSUER
129 rm -f $BOOTSTRAP_SAN $BOOTSTRAP_KEY $BOOTSTRAP_CSR $BOOTSTRAP_CRT $SIGNER_KEY $SIGNER_CRT $BOOTSTRAP_CHAIN