Debian Codegraph @

crt/s2n/tests/pems/permutations/generate-certs.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/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 # Usage: ./generate_certs.sh [clean]
7 # Generates all necessary certs for benching
8 # Use argument "clean" to remove all generated certs
9
10 # immediately bail if any command fails
11 set -e
12
13 # Generates certs with given algorithms and bits in $1$2/, ex. ec384/
14 # $1: rsa or ec
15 # $2: number of bits
16 # $3: directory under the `certs/` directory to put certs in
17 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). () {
18
19 key_family=$1
20 signature=$2
21 key_size=$3
22 digest=$4
23 dir_name=$5
24
25 echoscip-shell system . . echo. -e "\n----- generating certs for $key_family $key_size with $digest $signature -----\n"
26 #echo "generating $key_family $key_size cert with $digest $signature"
27
28 # set openssl argument name
29 if [[ $key_family == rsa || $key_family == rsa-pss ]]; then
30 local argname=rsa_keygen_bits:
31 elif [[ $key_family == ec ]]; then
32 local argname=ec_paramgen_curve:P-
33 fi
34
35 # All signature algorithms are the default except for rsa-pss signatures
36 # with rsae keys. For this case we must manually specify things
37 if [[ $key_family == rsa && $signature == pss ]]
38 then
39 local signature_options="-sigopt rsa_padding_mode:pss"
40 else
41 local signature_options=""
42 fi
43
44 # make directory for certs
45 mkdirscip-shell system . . mkdir. -p $dir_name
46 cd $dir_name
47
48 # The "basicConstraints" and "keyUsage" extensions are necessary for CA
49 # certificates that sign other certificates. Normally the openssl x509 tool
50 # will ignore the extensions requests in the .csr, but by using the
51 # copy_extensions=copyall flag we can pass the extensions from the .csr on
52 # to the final public certificate.
53
54 # The advantage of manually specifying the extensions is that there is no
55 # dependency on any openssl config files
56
57 # we pass in the digest here because it is self signed
58 echoscip-shell system . . echo. "generating CA private key and certificate"
59 opensslscip-shell system . . openssl. req -new -noenc -x509 \
60 -newkey $key_family \
61 -pkeyopt $argname$key_size \
62 -keyout ca-key.pem \
63 -out ca-cert.pem \
64 -days 65536 \
65 $signature_options \
66 -$digest \
67 -subj "/C=US/CN=rootscip-shell filesystem . . `/C=US/CN=root`." \
68 -addext "basicConstraints = critical,CA:true" \
69 -addext "keyUsage = critical,keyCertSign"
70
71 echoscip-shell system . . echo. "generating intermediate private key and CSR"
72 opensslscip-shell system . . openssl. req -new -noenc \
73 -newkey $key_family \
74 -pkeyopt $argname$key_size \
75 -keyout intermediate-key.pem \
76 -out intermediate.csr \
77 -subj "/C=US/CN=branchscip-shell filesystem . . `/C=US/CN=branch`." \
78 -addext "basicConstraints = critical,CA:true" \
79 -addext "keyUsage = critical,keyCertSign"
80
81 echoscip-shell system . . echo. "generating server private key and CSR"
82 opensslscip-shell system . . openssl. req -new -noenc \
83 -newkey $key_family \
84 -pkeyopt $argname$key_size \
85 -keyout server-key.pem \
86 -out server.csr \
87 -subj "/C=US/CN=leafscip-shell filesystem . . `/C=US/CN=leaf`." \
88 -addext "subjectAltName = DNS:localhost"
89
90 echoscip-shell system . . echo. "generating client private key and CSR"
91 opensslscip-shell system . . openssl. req -new -noenc \
92 -newkey $key_family \
93 -pkeyopt $argname$key_size \
94 -keyout client-key.pem \
95 -out client.csr \
96 -subj "/C=US/CN=clientscip-shell filesystem . . `/C=US/CN=client`." \
97 -addext "subjectAltName = DNS:localhost"
98
99 echoscip-shell system . . echo. "generating intermediate certificate and signing it"
100 opensslscip-shell system . . openssl. x509 -days 65536 \
101 -req -in intermediate.csr \
102 $signature_options \
103 -$digest \
104 -CA ca-cert.pem \
105 -CAkey ca-key.pem \
106 -CAcreateserial \
107 -out intermediate-cert.pem \
108 -copy_extensions=copyall
109
110 echoscip-shell system . . echo. "generating server certificate and signing it"
111 opensslscip-shell system . . openssl. x509 -days 65536 \
112 -req -in server.csr \
113 $signature_options \
114 -$digest \
115 -CA intermediate-cert.pem \
116 -CAkey intermediate-key.pem \
117 -CAcreateserial -out server-cert.pem \
118 -copy_extensions=copyall
119
120 echoscip-shell system . . echo. "generating client certificate and signing it"
121 opensslscip-shell system . . openssl. x509 -days 65536 \
122 -req -in client.csr \
123 $signature_options \
124 -$digest \
125 -CA ca-cert.pem \
126 -CAkey ca-key.pem \
127 -CAcreateserial -out client-cert.pem \
128 -copy_extensions=copyall
129
130 touchscip-shell system . . touch. server-chain.pem
131 catscip-shell system . . cat. server-cert.pem >> server-chain.pem
132 catscip-shell system . . cat. intermediate-cert.pem >> server-chain.pem
133 catscip-shell system . . cat. ca-cert.pem >> server-chain.pem
134
135 echoscip-shell system . . echo. "verifying server certificates"
136 opensslscip-shell system . . openssl. verify -CAfile ca-cert.pem intermediate-cert.pem
137 opensslscip-shell system . . openssl. verify -CAfile ca-cert.pem -untrusted intermediate-cert.pem server-cert.pem
138
139 echoscip-shell system . . echo. "verifying client certificates"
140 opensslscip-shell system . . openssl. verify -CAfile ca-cert.pem client-cert.pem
141
142 # certificate signing requests are never used after the certs are generated
143 rmscip-shell system . . rm. server.csr
144 rmscip-shell system . . rm. intermediate.csr
145 rmscip-shell system . . rm. client.csr
146
147 # serial files are generated during the signing process, but are not used
148 rmscip-shell system . . rm. ca-cert.srl
149 rmscip-shell system . . rm. intermediate-cert.srl
150
151 # the private keys of the CA and the intermediate CA are never needed after
152 # signing
153 rmscip-shell system . . rm. ca-key.pem
154 rmscip-shell system . . rm. intermediate-key.pem
155
156 # the intermediate and server certs are included in server-chain.pem, so
157 # the individual files can be deleted
158 rmscip-shell system . . rm. intermediate-cert.pem
159 rmscip-shell system . . rm. server-cert.pem
160
161 cd ..
162 }
163
164 if [[ $1 != "clean" ]]
165 then
166 # key signature key_size digest directory
167 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). ec ecdsa 256 SHA256 ec_ecdsa_p256_sha256
168 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). ec ecdsa 256 SHA384 ec_ecdsa_p256_sha384
169 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). ec ecdsa 384 SHA256 ec_ecdsa_p384_sha256
170 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). ec ecdsa 384 SHA384 ec_ecdsa_p384_sha384
171 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). ec ecdsa 521 SHA384 ec_ecdsa_p521_sha384
172 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). ec ecdsa 521 SHA512 ec_ecdsa_p521_sha512
173 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). rsa pkcsv1.5 1024 SHA1 rsae_pkcs_1024_sha1
174 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). rsa pkcsv1.5 2048 SHA1 rsae_pkcs_2048_sha1
175 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). rsa pkcsv1.5 2048 SHA224 rsae_pkcs_2048_sha224
176 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). rsa pkcsv1.5 2048 SHA256 rsae_pkcs_2048_sha256
177 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). rsa pkcsv1.5 2048 SHA384 rsae_pkcs_2048_sha384
178 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). rsa pkcsv1.5 3072 SHA256 rsae_pkcs_3072_sha256
179 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). rsa pkcsv1.5 3072 SHA384 rsae_pkcs_3072_sha384
180 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). rsa pkcsv1.5 4096 SHA384 rsae_pkcs_4096_sha384
181 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). rsa pss 4096 SHA384 rsae_pss_4096_sha384
182 cert-genscip-shell shell shell-project 0.0.0 cert-gen(). rsa-pss pss 2048 SHA256 rsapss_pss_2048_sha256
183
184 else
185 echoscip-shell system . . echo. "cleaning certs"
186 rmscip-shell system . . rm. -rf ecdsa* rsa*
187 fi