Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: net/data/ssl/scripts/generate-client-certificates.sh

Issue 13866049: Fix client certificate authentication on Mac and Linux introduced in r178732 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refresh key files for certs Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/data/ssl/scripts/client_authentication.cnf ('k') | net/socket/ssl_client_socket_nss.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 2
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 # This script generates certificates for the unittests in 7 # This script generates certificates that can be used to test SSL client
8 # net/base/client_cert_store_unittest.cc. The output files are versioned in 8 # authentication. Outputs for automated tests are stored in
9 # net/data/ssl/certificates (client_1.pem, client_2.pem). 9 # net/data/ssl/certificates, but may be re-generated for manual testing.
10 #
11 # This script generates two chains of test client certificates:
12 #
13 # 1. A (end-entity) -> B -> C (self-signed root)
14 # 2. D (end-entity) -> E -> C (self-signed root)
15 #
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.
10 20
11 try () { 21 try () {
12 echo "$@" 22 echo "$@"
13 $@ || exit 1 23 $@ || exit 1
14 } 24 }
15 25
16 # For each authority below a root ca certificate and one client certificate will
17 # be created.
18 authorities="1 2"
19
20 try rm -rf out 26 try rm -rf out
21 try mkdir out 27 try mkdir out
22 28
23 for id in $authorities 29 echo Create the serial number files and indices.
30 serial = 100
31 for i in B C E
24 do 32 do
25 # Generate a private key for the root cert. 33 try echo $serial > out/$i-serial
26 try openssl genrsa -out out/root_$id.key 2048 34 serial=$(expr $serial + 1)
35 touch out/$i-index.txt
36 touch out/$i-index.txt.attr
37 done
27 38
28 # Create a certificate signing request for the root cert. 39 echo Generate the keys.
29 ID=$id \ 40 for i in A B C D E
30 DISTINGUISHED_NAME=ca_dn \ 41 do
42 try openssl genrsa -out out/$i.key 2048
43 done
44
45 echo Generate the C CSR
46 COMMON_NAME="C Root CA" \
47 CA_DIR=out \
48 ID=C \
31 try openssl req \ 49 try openssl req \
32 -new \ 50 -new \
33 -key out/root_$id.key \ 51 -key out/C.key \
34 -out out/root_$id.csr \ 52 -out out/C.csr \
35 -config client_authentication.cnf 53 -config client-certs.cnf
36 54
37 # Sign the root cert. 55 echo C signs itself.
38 ID=$id \ 56 COMMON_NAME="C Root CA" \
39 DISTINGUISHED_NAME=ca_dn \ 57 CA_DIR=out \
58 ID=C \
40 try openssl x509 \ 59 try openssl x509 \
41 -req -days 3650 \ 60 -req -days 3650 \
42 -in out/root_$id.csr \ 61 -in out/C.csr \
43 -signkey out/root_$id.key \ 62 -extensions ca_cert \
44 -text \ 63 -signkey out/C.key \
45 -out out/root_$id.pem 64 -out out/C.pem
46 -config client_authentication.cnf
47 65
48 # Generate a private key for the client. 66 echo Generate the intermediates
49 try openssl genrsa -out out/client_$id.key 2048 67 COMMON_NAME="B CA" \
50 68 CA_DIR=out \
51 # Create a certificate signing request for the client cert. 69 ID=B \
52 ID=$id \
53 DISTINGUISHED_NAME=client_dn \
54 try openssl req \ 70 try openssl req \
55 -new \ 71 -new \
56 -key out/client_$id.key \ 72 -key out/B.key \
57 -out out/client_$id.csr \ 73 -out out/B.csr \
58 -config client_authentication.cnf 74 -config client-certs.cnf
59 75
60 try touch out/$id-index.txt 76 COMMON_NAME="C CA" \
61 try echo 1 > out/$id-serial 77 CA_DIR=out \
62 78 ID=C \
63 ID=$id \
64 DISTINGUISHED_NAME=client_dn \
65 try openssl ca \ 79 try openssl ca \
66 -batch \ 80 -batch \
67 -in out/client_$id.csr \ 81 -extensions ca_cert \
68 -cert out/root_$id.pem \ 82 -in out/B.csr \
69 -keyfile out/root_$id.key \ 83 -out out/B.pem \
70 -out out/client_$id.pem \ 84 -config client-certs.cnf
71 -config client_authentication.cnf
72 85
73 # Package the client cert and private key into a pkcs12 file. 86 COMMON_NAME="E CA" \
74 try openssl pkcs12 \ 87 CA_DIR=out \
75 -inkey out/client_$id.key \ 88 ID=E \
76 -in out/client_$id.pem \ 89 try openssl req \
77 -out out/client_$id.p12 \ 90 -new \
78 -export \ 91 -key out/E.key \
79 -passout pass:chrome 92 -out out/E.csr \
93 -config client-certs.cnf
94
95 COMMON_NAME="C CA" \
96 CA_DIR=out \
97 ID=C \
98 try openssl ca \
99 -batch \
100 -extensions ca_cert \
101 -in out/E.csr \
102 -out out/E.pem \
103 -config client-certs.cnf
104
105 echo Generate the leaf certs
106 for id in A D
107 do
108 COMMON_NAME="Client Cert $id" \
109 ID=$id \
110 try openssl req \
111 -new \
112 -key out/$id.key \
113 -out out/$id.csr \
114 -config client-certs.cnf
80 done 115 done
116
117 echo B signs A
118 COMMON_NAME="B CA" \
119 CA_DIR=out \
120 ID=B \
121 try openssl ca \
122 -batch \
123 -extensions user_cert \
124 -in out/A.csr \
125 -out out/A.pem \
126 -config client-certs.cnf
127
128 echo E signs D
129 COMMON_NAME="E CA" \
130 CA_DIR=out \
131 ID=E \
132 try openssl ca \
133 -batch \
134 -extensions user_cert \
135 -in out/D.csr \
136 -out out/D.pem \
137 -config client-certs.cnf
138
139 echo Package the client certs and private keys into PKCS12 files
140 # This is done for easily importing all of the certs needed for clients.
141 cat out/A.pem out/A.key out/B.pem out/C.pem > out/A-chain.pem
142 cat out/D.pem out/D.key out/E.pem out/C.pem > out/D-chain.pem
143
144 try openssl pkcs12 \
145 -in out/A-chain.pem \
146 -out client_1.p12 \
147 -export \
148 -passout pass:chrome
149
150 try openssl pkcs12 \
151 -in out/D-chain.pem \
152 -out client_2.p12 \
153 -export \
154 -passout pass:chrome
155
156 echo Package the client certs for unit tests
157 cp out/A.pem client_1.pem
158 cp out/A.key client_1.key
159 cp out/B.pem client_1_ca.pem
160
161 cp out/D.pem client_2.pem
162 cp out/D.key client_2.key
163 cp out/E.pem client_2_ca.pem
OLDNEW
« no previous file with comments | « net/data/ssl/scripts/client_authentication.cnf ('k') | net/socket/ssl_client_socket_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698