3 # ============LICENSE_START====================================================
5 # ===========================================================================
6 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
7 # ===========================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 # ============LICENSE_END====================================================
21 # Streamlined AAF Bootstrap initial Cert
22 # Removed Variables so it can be run for AutoDeployments
24 echo "Bootstrap AAF Certificate"
25 mkdir -p private certs newcerts
27 chmod 755 certs newcerts
29 echo "unique_subject = no" > index.txt.attr
30 if [ ! -e ./serial ]; then
31 echo $(date +%s)_$(shuf -i 0-1000000 -n 1) > ./serial
35 FQDN="${HOSTNAME:=$(hostname -f)}"
37 SUBJECT="/CN=$FQDN/OU=$FQI`cat subject.aaf`"
39 SIGNER_KEY=/tmp/aaf_signer.key
40 SIGNER_CRT=/tmp/aaf_signer.crt
42 if [ "PASSPHRASE" = "" ]; then
43 PASSPHRASE="something easy"
45 BOOTSTRAP_SAN=/tmp/$NAME.san
46 BOOTSTRAP_KEY=/tmp/$NAME.key
47 BOOTSTRAP_CSR=/tmp/$NAME.csr
48 BOOTSTRAP_CRT=/tmp/$NAME.crt
49 BOOTSTRAP_CHAIN=/tmp/$NAME.chain
50 BOOTSTRAP_P12=$NAME.p12
51 BOOTSTRAP_ISSUER=$NAME.issuer
54 # If Signer doesn't exist, create Self-Signed CA
55 if [ ! -e "$SIGNER_P12" ]; then
57 openssl req -config openssl.conf -x509 -sha256 -extensions v3_ca \
58 -newkey rsa:4096 -subj /CN="Signer$(cat subject.aaf)" \
59 -keyout $SIGNER_KEY -out $SIGNER_CRT -days 365 -passout stdin << EOF
63 # Move to P12 (Signer)
64 openssl pkcs12 -name RootCA -export -in $SIGNER_CRT -inkey $SIGNER_KEY -out $SIGNER_P12 -passin stdin -passout stdin << EOF
71 # Get Private key from P12
72 openssl pkcs12 -in $SIGNER_P12 -nocerts -nodes -passin stdin -passout stdin -out $SIGNER_KEY << EOF
78 openssl pkcs12 -in $SIGNER_P12 -clcerts -nokeys -passin stdin -out $SIGNER_CRT << EOF
85 cp san.conf $BOOTSTRAP_SAN
87 if [ "$FQDN" -ne "$HOSTNAME" ]; then
88 SANS="$SANS $HOSTNAME"
91 for ROOT in $(cat san_root.aaf); do
93 for C in service locate oauth token introspect gui cm hello; do
98 for C in service locate oauth token introspect gui cm hello; do
100 SANS="$SANS aaf-$C.onap"
105 echo "DNS.$NUM = $D" >> $BOOTSTRAP_SAN
110 openssl req -new -newkey rsa:2048 -nodes -keyout $BOOTSTRAP_KEY \
111 -out $BOOTSTRAP_CSR -outform PEM -subj "$SUBJECT" \
112 -passout stdin << EOF
117 openssl ca -batch -config openssl.conf -extensions server_cert \
118 -cert $SIGNER_CRT -keyfile $SIGNER_KEY \
119 -policy policy_loose \
122 -out $BOOTSTRAP_CRT \
123 -extfile $BOOTSTRAP_SAN \
124 -infiles $BOOTSTRAP_CSR << EOF
129 # Add THIS Intermediate CA into chain
131 cp $BOOTSTRAP_CRT $BOOTSTRAP_CHAIN
132 cat $SIGNER_CRT >> $BOOTSTRAP_CHAIN
135 # Note: Openssl will pickup and load all Certs in the Chain file
136 #openssl pkcs12 -name $FQI -export -in $BOOTSTRAP_CRT -inkey $BOOTSTRAP_KEY -CAfile $SIGNER_CRT -out $BOOTSTRAP_P12 -passin stdin -passout stdin << EOF
137 openssl pkcs12 -name $FQI -export -in $BOOTSTRAP_CHAIN -inkey $BOOTSTRAP_KEY -out $BOOTSTRAP_P12 -passin stdin -passout stdin << EOF
144 ISSUER=$(openssl x509 -subject -noout -in $SIGNER_CRT | cut -c 10-)
145 for I in ${ISSUER//\// }; do
146 if [ -n "$CADI_X509_ISSUER" ]; then
147 CADI_X509_ISSUER=", $CADI_X509_ISSUER"
149 CADI_X509_ISSUER="$I$CADI_X509_ISSUER"
151 echo $CADI_X509_ISSUER > $BOOTSTRAP_ISSUER
154 rm -f $BOOTSTRAP_SAN $BOOTSTRAP_KEY $BOOTSTRAP_CSR $BOOTSTRAP_CRT $SIGNER_KEY $SIGNER_CRT $BOOTSTRAP_CHAIN