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 |
| 11 | |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 12 | NAME=aaf.bootstrap |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 13 | FQDN=$(hostname -f) |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 14 | FQI=aaf@aaf.osaaf.org |
| 15 | SUBJECT="/CN=$FQDN/OU=$FQI`cat subject.aaf`" |
| 16 | SIGNER_P12=$1 |
| 17 | SIGNER_KEY=/tmp/aaf_signer.key |
| 18 | SIGNER_CRT=/tmp/aaf_signer.crt |
| 19 | PASSPHRASE=$2 |
| 20 | if [ "PASSPHRASE" = "" ]; then |
| 21 | PASSPHRASE="something easy" |
| 22 | fi |
| 23 | BOOTSTRAP_SAN=/tmp/$NAME.san |
| 24 | BOOTSTRAP_KEY=/tmp/$NAME.key |
| 25 | BOOTSTRAP_CSR=/tmp/$NAME.csr |
| 26 | BOOTSTRAP_CRT=/tmp/$NAME.crt |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 27 | BOOTSTRAP_CHAIN=/tmp/$NAME.chain |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 28 | BOOTSTRAP_P12=$NAME.p12 |
| 29 | |
| 30 | |
| 31 | # If Signer doesn't exist, create Self-Signed CA |
| 32 | if [ ! -e "$SIGNER_P12" ]; then |
| 33 | # Creating Signer CA |
| 34 | openssl req -config openssl.conf -x509 -sha256 -extensions v3_ca \ |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 35 | -newkey rsa:4096 -subj /CN="Signer$(cat subject.aaf)" \ |
| 36 | -keyout $SIGNER_KEY -out $SIGNER_CRT -days 365 -passout stdin << EOF |
| 37 | $PASSPHRASE |
| 38 | EOF |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 39 | |
| 40 | # Move to P12 (Signer) |
| 41 | openssl pkcs12 -name RootCA -export -in $SIGNER_CRT -inkey $SIGNER_KEY -out $SIGNER_P12 -passin stdin -passout stdin << EOF |
| 42 | $PASSPHRASE |
| 43 | $PASSPHRASE |
| 44 | $PASSPHRASE |
| 45 | EOF |
| 46 | |
| 47 | else |
| 48 | # Get Private key from P12 |
| 49 | openssl pkcs12 -in $SIGNER_P12 -nocerts -nodes -passin stdin -passout stdin -out $SIGNER_KEY << EOF |
| 50 | $PASSPHRASE |
| 51 | $PASSPHRASE |
| 52 | EOF |
| 53 | |
| 54 | # Get Cert from P12 |
| 55 | openssl pkcs12 -in $SIGNER_P12 -clcerts -nokeys -passin stdin -out $SIGNER_CRT << EOF |
| 56 | $PASSPHRASE |
| 57 | EOF |
| 58 | |
| 59 | fi |
| 60 | |
| 61 | # SANS |
| 62 | cp san.conf $BOOTSTRAP_SAN |
| 63 | NUM=1 |
| 64 | for D in $FQDN aaf.osaaf.org service.aaf.osaaf.org locate.aaf.osaaf.org oauth.aaf.osaaf.org gui.aaf.osaaf.org cm.aaf.osaaf.org hello.aaf.osaaf.org; do |
| 65 | echo "DNS.$NUM = $D" >> $BOOTSTRAP_SAN |
| 66 | NUM=$((NUM+1)) |
| 67 | done |
| 68 | |
| 69 | # Create CSR |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 70 | openssl req -new -newkey rsa:2048 -nodes -keyout $BOOTSTRAP_KEY \ |
| 71 | -out $BOOTSTRAP_CSR -outform PEM -subj "$SUBJECT" \ |
| 72 | -passout stdin << EOF |
| 73 | $PASSPHRASE |
| 74 | EOF |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 75 | |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 76 | echo Sign it |
| 77 | openssl ca -batch -config openssl.conf -extensions server_cert \ |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 78 | -cert $SIGNER_CRT -keyfile $SIGNER_KEY \ |
| 79 | -policy policy_loose \ |
| 80 | -days 90 \ |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 81 | -passin stdin \ |
| 82 | -out $BOOTSTRAP_CRT \ |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 83 | -extfile $BOOTSTRAP_SAN \ |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 84 | -infiles $BOOTSTRAP_CSR << EOF |
| 85 | $PASSPHRASE |
| 86 | EOF |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 87 | |
| 88 | # Make a P12 |
| 89 | # Add THIS Intermediate CA into chain |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 90 | cat $BOOTSTRAP_CRT |
| 91 | cp $BOOTSTRAP_CRT $BOOTSTRAP_CHAIN |
| 92 | cat $SIGNER_CRT >> $BOOTSTRAP_CHAIN |
Instrumental | cc596dd | 2018-08-23 09:52:14 -0500 | [diff] [blame] | 93 | |
| 94 | # Note: Openssl will pickup and load all Certs in the Chain file |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 95 | 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] | 96 | $PASSPHRASE |
| 97 | $PASSPHRASE |
| 98 | $PASSPHRASE |
| 99 | EOF |
| 100 | |
| 101 | # Cleanup |
Instrumental | b8a8129 | 2018-08-23 16:32:45 -0500 | [diff] [blame] | 102 | rm -f $BOOTSTRAP_SAN $BOOTSTRAP_KEY $BOOTSTRAP_CSR $BOOTSTRAP_CRT $BOOTSTRAP_CHAIN $SIGNER_KEY $SIGNER_CRT |