Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 1 | # |
| 2 | # Streamlined AAF Bootstrap initial Cert |
| 3 | # Removed Variables so it can be run for AutoDeployments |
| 4 | # |
| 5 | echo "Bootstrap AAF Certificate" |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 6 | mkdir -p private certs newcerts |
| 7 | chmod 700 private |
| 8 | chmod 755 certs newcerts |
| 9 | touch index.txt |
| 10 | echo "unique_subject = no" > index.txt.attr |
Instrumental | 0d4ec12 | 2018-08-30 14:33:08 -0500 | [diff] [blame] | 11 | if [ ! -e ./serial ]; then |
Instrumental | 93871ff | 2018-10-15 07:37:28 -0500 | [diff] [blame] | 12 | echo $(date +%s)_$(shuf -i 0-1000000 -n 1) > ./serial |
Instrumental | 0d4ec12 | 2018-08-30 14:33:08 -0500 | [diff] [blame] | 13 | fi |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 14 | |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 15 | NAME=aaf.bootstrap |
Instrumental | 54883b4 | 2018-09-25 07:56:54 -0500 | [diff] [blame] | 16 | FQDN="${HOSTNAME:=$(hostname -f)}" |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 17 | FQI=aaf@aaf.osaaf.org |
| 18 | SUBJECT="/CN=$FQDN/OU=$FQI`cat subject.aaf`" |
| 19 | SIGNER_P12=$1 |
| 20 | SIGNER_KEY=/tmp/aaf_signer.key |
| 21 | SIGNER_CRT=/tmp/aaf_signer.crt |
| 22 | PASSPHRASE=$2 |
| 23 | if [ "PASSPHRASE" = "" ]; then |
| 24 | PASSPHRASE="something easy" |
| 25 | fi |
| 26 | BOOTSTRAP_SAN=/tmp/$NAME.san |
| 27 | BOOTSTRAP_KEY=/tmp/$NAME.key |
| 28 | BOOTSTRAP_CSR=/tmp/$NAME.csr |
| 29 | BOOTSTRAP_CRT=/tmp/$NAME.crt |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 30 | BOOTSTRAP_CHAIN=/tmp/$NAME.chain |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 31 | BOOTSTRAP_P12=$NAME.p12 |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 32 | BOOTSTRAP_ISSUER=$NAME.issuer |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 33 | |
| 34 | |
| 35 | # If Signer doesn't exist, create Self-Signed CA |
| 36 | if [ ! -e "$SIGNER_P12" ]; then |
| 37 | # Creating Signer CA |
| 38 | openssl req -config openssl.conf -x509 -sha256 -extensions v3_ca \ |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 39 | -newkey rsa:4096 -subj /CN="Signer$(cat subject.aaf)" \ |
| 40 | -keyout $SIGNER_KEY -out $SIGNER_CRT -days 365 -passout stdin << EOF |
| 41 | $PASSPHRASE |
| 42 | EOF |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 43 | |
| 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 |
| 49 | EOF |
| 50 | |
| 51 | else |
| 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 |
| 56 | EOF |
| 57 | |
| 58 | # Get Cert from P12 |
| 59 | openssl pkcs12 -in $SIGNER_P12 -clcerts -nokeys -passin stdin -out $SIGNER_CRT << EOF |
| 60 | $PASSPHRASE |
| 61 | EOF |
| 62 | |
| 63 | fi |
| 64 | |
| 65 | # SANS |
| 66 | cp san.conf $BOOTSTRAP_SAN |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 67 | SANS=$FQDN |
| 68 | if [ "$FQDN" -ne "$HOSTNAME" ]; then |
| 69 | SANS="$SANS $HOSTNAME" |
| 70 | fi |
| 71 | |
| 72 | for 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 |
| 77 | done |
Instrumental | 65cdc09 | 2018-10-15 12:34:59 -0500 | [diff] [blame] | 78 | |
| 79 | for C in service locate oauth gui cm hello; do |
| 80 | SANS="$SANS aaf-$C" |
| 81 | SANS="$SANS aaf-$C.onap" |
| 82 | done |
| 83 | |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 84 | NUM=1 |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 85 | for D in $SANS; do |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 86 | echo "DNS.$NUM = $D" >> $BOOTSTRAP_SAN |
| 87 | NUM=$((NUM+1)) |
| 88 | done |
| 89 | |
| 90 | # Create CSR |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 91 | openssl req -new -newkey rsa:2048 -nodes -keyout $BOOTSTRAP_KEY \ |
| 92 | -out $BOOTSTRAP_CSR -outform PEM -subj "$SUBJECT" \ |
| 93 | -passout stdin << EOF |
| 94 | $PASSPHRASE |
| 95 | EOF |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 96 | |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 97 | echo Sign it |
| 98 | openssl ca -batch -config openssl.conf -extensions server_cert \ |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 99 | -cert $SIGNER_CRT -keyfile $SIGNER_KEY \ |
| 100 | -policy policy_loose \ |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 101 | -days 365 \ |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 102 | -passin stdin \ |
| 103 | -out $BOOTSTRAP_CRT \ |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 104 | -extfile $BOOTSTRAP_SAN \ |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 105 | -infiles $BOOTSTRAP_CSR << EOF |
| 106 | $PASSPHRASE |
| 107 | EOF |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 108 | |
| 109 | # Make a P12 |
| 110 | # Add THIS Intermediate CA into chain |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 111 | cat $BOOTSTRAP_CRT |
| 112 | cp $BOOTSTRAP_CRT $BOOTSTRAP_CHAIN |
| 113 | cat $SIGNER_CRT >> $BOOTSTRAP_CHAIN |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 114 | cat $BOOTSTRAP_CHAIN |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 115 | |
| 116 | # Note: Openssl will pickup and load all Certs in the Chain file |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 117 | #openssl pkcs12 -name $FQI -export -in $BOOTSTRAP_CRT -inkey $BOOTSTRAP_KEY -CAfile $SIGNER_CRT -out $BOOTSTRAP_P12 -passin stdin -passout stdin << EOF |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 118 | openssl pkcs12 -name $FQI -export -in $BOOTSTRAP_CHAIN -inkey $BOOTSTRAP_KEY -out $BOOTSTRAP_P12 -passin stdin -passout stdin << EOF |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 119 | $PASSPHRASE |
| 120 | $PASSPHRASE |
| 121 | $PASSPHRASE |
| 122 | EOF |
| 123 | |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 124 | # Make Issuer name |
| 125 | ISSUER=$(openssl x509 -subject -noout -in $SIGNER_CRT | cut -c 10-) |
| 126 | for 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" |
| 131 | done |
| 132 | echo $CADI_X509_ISSUER > $BOOTSTRAP_ISSUER |
| 133 | |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 134 | # Cleanup |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 135 | rm -f $BOOTSTRAP_SAN $BOOTSTRAP_KEY $BOOTSTRAP_CSR $BOOTSTRAP_CRT $SIGNER_KEY $SIGNER_CRT $BOOTSTRAP_CHAIN |