| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | |
| 6 | # immediately bail if any command fails |
| 7 | set -e |
| 8 | |
| 9 | echo "generating CA" |
| 10 | openssl req -new -noenc -x509 \ |
| 11 | -newkey ec \ |
| 12 | -pkeyopt ec_paramgen_curve:P-384 \ |
| 13 | -keyout ca-key.pem \ |
| 14 | -out ca-cert.pem \ |
| 15 | -days 65536 \ |
| 16 | -SHA384 \ |
| 17 | -subj "/C=US/CN=root" \ |
| 18 | -addext "basicConstraints = critical,CA:true" \ |
| 19 | -addext "keyUsage = critical,keyCertSign" |
| 20 | |
| 21 | echo "generating wombat private key and CSR" |
| 22 | openssl req -new -noenc \ |
| 23 | -newkey ec \ |
| 24 | -pkeyopt ec_paramgen_curve:P-384 \ |
| 25 | -keyout wombat-key.pem \ |
| 26 | -out wombat.csr \ |
| 27 | -subj "/C=US/CN=wombat" \ |
| 28 | -addext "subjectAltName = DNS:www.wombat.com" |
| 29 | |
| 30 | echo "generating kangaroo private key and CSR" |
| 31 | openssl req -new -noenc \ |
| 32 | -newkey ec \ |
| 33 | -pkeyopt ec_paramgen_curve:P-384 \ |
| 34 | -keyout kangaroo-key.pem \ |
| 35 | -out kangaroo.csr \ |
| 36 | -subj "/C=US/CN=kangaroo" \ |
| 37 | -addext "subjectAltName = DNS:www.kangaroo.com" |
| 38 | |
| 39 | echo "generating localhost private key and CSR" |
| 40 | openssl req -new -noenc \ |
| 41 | -newkey ec \ |
| 42 | -pkeyopt ec_paramgen_curve:P-384 \ |
| 43 | -keyout localhost-key.pem \ |
| 44 | -out localhost.csr \ |
| 45 | -subj "/C=US/CN=localhost" \ |
| 46 | -addext "subjectAltName = DNS:localhost" |
| 47 | |
| 48 | echo "generating wombat server certificate and signing it" |
| 49 | openssl x509 -days 65536 \ |
| 50 | -req -in wombat.csr \ |
| 51 | -SHA384 \ |
| 52 | -CA ca-cert.pem \ |
| 53 | -CAkey ca-key.pem \ |
| 54 | -CAcreateserial \ |
| 55 | -out wombat-cert.pem \ |
| 56 | -copy_extensions=copyall |
| 57 | |
| 58 | echo "generating kangaroo certificate and signing it" |
| 59 | openssl x509 -days 65536 \ |
| 60 | -req -in kangaroo.csr \ |
| 61 | -SHA384 \ |
| 62 | -CA ca-cert.pem \ |
| 63 | -CAkey ca-key.pem \ |
| 64 | -CAcreateserial \ |
| 65 | -out kangaroo-cert.pem \ |
| 66 | -copy_extensions=copyall |
| 67 | |
| 68 | echo "generating localhost certificate and signing it" |
| 69 | openssl x509 -days 65536 \ |
| 70 | -req -in localhost.csr \ |
| 71 | -SHA384 \ |
| 72 | -CA ca-cert.pem \ |
| 73 | -CAkey ca-key.pem \ |
| 74 | -CAcreateserial \ |
| 75 | -out localhost-cert.pem \ |
| 76 | -copy_extensions=copyall |
| 77 | |
| 78 | touch wombat-chain.pem |
| 79 | cat wombat-cert.pem >> wombat-chain.pem |
| 80 | cat ca-cert.pem >> wombat-chain.pem |
| 81 | |
| 82 | touch kangaroo-chain.pem |
| 83 | cat kangaroo-cert.pem >> kangaroo-chain.pem |
| 84 | cat ca-cert.pem >> kangaroo-chain.pem |
| 85 | |
| 86 | touch localhost-chain.pem |
| 87 | cat localhost-cert.pem >> localhost-chain.pem |
| 88 | cat ca-cert.pem >> localhost-chain.pem |
| 89 | |
| 90 | echo "verifying server certificates" |
| 91 | openssl verify -CAfile ca-cert.pem wombat-cert.pem |
| 92 | openssl verify -CAfile ca-cert.pem kangaroo-cert.pem |
| 93 | openssl verify -CAfile ca-cert.pem localhost-cert.pem |
| 94 | |
| 95 | # certificate signing requests are never used after the certs are generated |
| 96 | rm wombat.csr |
| 97 | rm kangaroo.csr |
| 98 | rm localhost.csr |
| 99 | rm ca-cert.srl |
| 100 | |
| 101 | # the private keys of the CA are never needed after signing |
| 102 | rm ca-key.pem |
| 103 | rm wombat-cert.pem |
| 104 | rm kangaroo-cert.pem |
| 105 | rm localhost-cert.pem |
| 106 |