• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#/bin/bash
2
3echo "This script generates the key and certificate chain for deploying"
4echo "the AAOS Debugging Restriction Controller client and service"
5echo
6echo "WARNING: Only use this script if you are using a self-signed CA."
7echo
8echo "Continue (y/N)?"
9read c
10if [[ "$c" != "y" ]]
11then
12    exit -1
13fi
14
15echo "Enter the path of the CA certificate:"
16read ca_cert
17
18echo "Enter path of the CA private key:"
19read ca_key
20
21echo
22echo "Enter the number of days the token signing key should be valid for:"
23echo "  (press return for 365 days)"
24read validity
25
26if [[ -z "$validity" ]] ; then
27  validity=365
28fi
29echo "Using '$validity' days"
30
31echo
32echo "Enter the hostname that identifies the token signer:"
33read hostname
34
35echo
36echo "Generating the token signing key and certificate signing request ..."
37echo "Please fill in the fields when requested."
38date=$(date +%Y-%m-%d)
39folder=$(mktemp -d)
40req="$folder/token_signing-${date}.req"
41key="$folder/token_signing-${date}.key"
42signed="$folder/token_signing-${date}.pem"
43
44config="
45[ server ]
46basicConstraints = critical,CA:false
47keyUsage = nonRepudiation, digitalSignature
48subjectKeyIdentifier = hash
49authorityKeyIdentifier = keyid:always,issuer:always
50subjectAltName = @alt_names
51
52[ alt_names ]
53DNS.1 = $hostname
54"
55
56openssl req -nodes -newkey rsa:2048 -sha256 -keyout "${key}" -out "${req}"
57echo "Signing the certificate ..."
58
59openssl x509 -req \
60    -in "$req" -out "$signed" -CA "$ca_cert" -CAkey "$ca_key" \
61    -sha256 -days "$validity" -set_serial 666 \
62    -extensions server -extfile <(echo "$config")
63
64key_out="token_signing_key-$date.pem"
65cert_chain_out="token_signing_certs-$date.pem"
66cat "$key" > "$key_out"
67cat "$signed" "$ca_cert" > "$cert_chain_out"
68
69
70echo "The token signing key and certificate chain have been created."
71echo "See $key_out and $cert_chain_out."
72echo
73echo "Verifying the certificate chain ..."
74openssl verify -CAfile "$ca_cert" "$cert_chain_out"
75rm -rf "$folder"
76