3 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 # This script generates a set of test (end-entity, intermediate, root)
8 # certificates with (weak, strong), (RSA, DSA, ECDSA) key pairs.
10 key_types
="768-rsa 1024-rsa 2048-rsa prime256v1-ecdsa"
17 generate_key_command
() {
20 echo "dsaparam -genkey"
23 echo "ecparam -genkey"
36 # Create the serial number files.
37 try
echo 1 > out
/2048-rsa-root-serial
38 for key_type
in $key_types
40 try
echo 1 > out
/$key_type-intermediate-serial
43 # Generate one root CA certificate.
44 try openssl genrsa
-out out
/2048-rsa-root.key
2048
46 CA_COMMON_NAME
="2048 RSA Test Root CA" \
54 -key out
/2048-rsa-root.key \
56 -out out
/2048-rsa-root.csr \
59 CA_COMMON_NAME
="2048 RSA Test Root CA" \
64 -in out
/2048-rsa-root.csr \
66 -signkey out
/2048-rsa-root.key \
67 -out out
/2048-rsa-root.pem
69 # Generate private keys of all types and strengths for intermediate CAs and
71 for key_type
in $key_types
73 key_size
=$
(echo "$key_type" |
sed -E 's/-.+//')
74 algo
=$
(echo "$key_type" |
sed -E 's/.+-//')
78 key_size
="-name $key_size"
81 try openssl $
(generate_key_command
$algo) \
82 -out out
/$key_type-intermediate.key
$key_size
85 for key_type
in $key_types
87 key_size
=$
(echo "$key_type" |
sed -E 's/-.+//')
88 algo
=$
(echo "$key_type" |
sed -E 's/.+-//')
92 key_size
="-name $key_size"
95 for signer_key_type
in $key_types
97 try openssl $
(generate_key_command
$algo) \
98 -out out
/$key_type-ee-by-$signer_key_type-intermediate.key
$key_size
102 # The root signs the intermediates.
103 for key_type
in $key_types
105 key_size
=$
(echo "$key_type" |
sed -E 's/-.+//')
106 algo
=$
(echo "$key_type" |
sed -E 's/.+-//')
108 CA_COMMON_NAME
="$key_size $algo Test intermediate CA" \
113 CERT_TYPE
=intermediate \
116 -key out
/$key_type-intermediate.key \
117 -out out
/$key_type-intermediate.csr \
120 # Make sure the signer's DB file exists.
121 touch out
/2048-rsa-root-index.txt
123 CA_COMMON_NAME
="2048 RSA Test Root CA" \
131 -extensions ca_cert \
132 -in out
/$key_type-intermediate.csr \
133 -out out
/$key_type-intermediate.pem \
137 # The intermediates sign the end-entities.
138 for key_type
in $key_types
140 for signer_key_type
in $key_types
142 key_size
=$
(echo "$key_type" |
sed -E 's/-.+//')
143 algo
=$
(echo "$key_type" |
sed -E 's/.+-//')
144 signer_key_size
=$
(echo "$signer_key_type" |
sed -E 's/-.+//')
145 signer_algo
=$
(echo "$signer_key_type" |
sed -E 's/.+-//')
146 touch out
/$signer_key_type-intermediate-index.txt
151 -key out
/$key_type-ee-by-$signer_key_type-intermediate.key \
152 -out out
/$key_type-ee-by-$signer_key_type-intermediate.csr \
155 CA_COMMON_NAME
="$signer_key_size $algo Test intermediate CA" \
158 KEY_SIZE
=$signer_key_size \
160 CERT_TYPE
=intermediate \
163 -in out
/$key_type-ee-by-$signer_key_type-intermediate.csr \
164 -out out
/$key_type-ee-by-$signer_key_type-intermediate.pem \