3 # Copyright (c) 2012 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 certificates that can be used to test SSL client
8 # authentication. Outputs for automated tests are stored in
9 # net/data/ssl/certificates, but may be re-generated for manual testing.
11 # This script generates two chains of test client certificates:
13 # 1. A (end-entity) -> B -> C (self-signed root)
14 # 2. D (end-entity) -> E -> C (self-signed root)
16 # In which A, B, C, D, and E all have distinct keypairs. Both client
17 # certificates share the same root, but are issued by different
18 # intermediates. The names of these intermediates are hardcoded within
19 # unit tests, and thus should not be changed.
29 echo Create the serial number files and indices.
33 try
/bin
/sh
-c "echo $serial > out/$i-serial"
34 serial
=$
(expr $serial + 1)
35 touch out
/$i-index.txt
36 touch out
/$i-index.txt.attr
39 echo Generate the keys.
42 try openssl genrsa
-out out
/$i.key
2048
45 echo Generate the C CSR
46 COMMON_NAME
="C Root CA" \
53 -config client-certs.cnf
56 COMMON_NAME
="C Root CA" \
63 -extfile client-certs.cnf \
67 echo Generate the intermediates
75 -config client-certs.cnf
85 -config client-certs.cnf
94 -config client-certs.cnf
101 -extensions ca_cert \
104 -config client-certs.cnf
106 echo Generate the leaf certs
109 COMMON_NAME
="Client Cert $id" \
115 -config client-certs.cnf
116 # Store the private key also in PKCS#8 format.
130 -extensions user_cert \
133 -config client-certs.cnf
141 -extensions user_cert \
144 -config client-certs.cnf
146 echo Package the client certs and private keys into PKCS12 files
147 # This is done for easily importing all of the certs needed for clients.
148 try
/bin
/sh
-c "cat out/A.pem out/A.key out/B.pem out/C.pem > out/A-chain.pem"
149 try
/bin
/sh
-c "cat out/D.pem out/D.key out/E.pem out/C.pem > out/D-chain.pem"
152 -in out
/A-chain.pem \
158 -in out
/D-chain.pem \
163 echo Package the client certs
for unit tests
164 try
cp out
/A.pem ..
/certificates
/client_1.pem
165 try
cp out
/A.key ..
/certificates
/client_1.key
166 try
cp out
/A.pk8 ..
/certificates
/client_1.pk8
167 try
cp out
/B.pem ..
/certificates
/client_1_ca.pem
169 try
cp out
/D.pem ..
/certificates
/client_2.pem
170 try
cp out
/D.key ..
/certificates
/client_2.key
171 try
cp out
/D.pk8 ..
/certificates
/client_2.pk8
172 try
cp out
/E.pem ..
/certificates
/client_2_ca.pem