Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 that can be used to test SSL client | 7 # This script generates certificates that can be used to test SSL client |
| 8 # authentication. Outputs for automated tests are stored in | 8 # authentication. Outputs for automated tests are stored in |
| 9 # net/data/ssl/certificates, but may be re-generated for manual testing. | 9 # net/data/ssl/certificates, but may be re-generated for manual testing. |
| 10 # | 10 # |
| 11 # This script generates two chains of test client certificates: | 11 # This script generates several chains of test client certificates: |
| 12 # | 12 # |
| 13 # 1. A (end-entity) -> B -> C (self-signed root) | 13 # 1. A (end-entity) -> B -> C (self-signed root) |
| 14 # 2. D (end-entity) -> E -> C (self-signed root) | 14 # 2. D (end-entity) -> E -> C (self-signed root) |
| 15 # 3. F (end-entity) -> E -> C (self-signed root) | |
| 16 # 4. G (end-entity, P-256) -> E -> C (self-signed root) | |
| 15 # | 17 # |
| 16 # In which A, B, C, D, and E all have distinct keypairs. Both client | 18 # In which the certificates all have distinct keypairs. The client |
| 17 # certificates share the same root, but are issued by different | 19 # certificates share the same root, but are issued by different |
| 18 # intermediates. The names of these intermediates are hardcoded within | 20 # intermediates. The names of these intermediates are hardcoded within |
| 19 # unit tests, and thus should not be changed. | 21 # unit tests, and thus should not be changed. |
| 20 | 22 |
| 21 try () { | 23 try () { |
| 22 echo "$@" | 24 echo "$@" |
| 23 "$@" || exit 1 | 25 "$@" || exit 1 |
| 24 } | 26 } |
| 25 | 27 |
| 26 try rm -rf out | 28 try rm -rf out |
| 27 try mkdir out | 29 try mkdir out |
| 28 | 30 |
| 29 echo Create the serial number files and indices. | 31 echo Create the serial number files and indices. |
| 30 serial=1000 | 32 serial=1000 |
| 31 for i in B C E | 33 for i in B C E |
| 32 do | 34 do |
| 33 try /bin/sh -c "echo $serial > out/$i-serial" | 35 try /bin/sh -c "echo $serial > out/$i-serial" |
| 34 serial=$(expr $serial + 1) | 36 serial=$(expr $serial + 1) |
| 35 touch out/$i-index.txt | 37 touch out/$i-index.txt |
| 36 touch out/$i-index.txt.attr | 38 touch out/$i-index.txt.attr |
| 37 done | 39 done |
| 38 | 40 |
| 39 echo Generate the keys. | 41 echo Generate the keys. |
| 40 for i in A B C D E F | 42 for i in A B C D E F |
| 41 do | 43 do |
| 42 try openssl genrsa -out out/$i.key 2048 | 44 try openssl genrsa -out out/$i.key 2048 |
| 43 done | 45 done |
| 44 | 46 |
| 47 try openssl ecparam -name prime256v1 -genkey -noout -out out/G.key | |
| 48 | |
| 45 echo Generate the C CSR | 49 echo Generate the C CSR |
| 46 COMMON_NAME="C Root CA" \ | 50 COMMON_NAME="C Root CA" \ |
| 47 CA_DIR=out \ | 51 CA_DIR=out \ |
| 48 ID=C \ | 52 ID=C \ |
| 49 try openssl req \ | 53 try openssl req \ |
| 50 -new \ | 54 -new \ |
| 51 -key out/C.key \ | 55 -key out/C.key \ |
| 52 -out out/C.csr \ | 56 -out out/C.csr \ |
| 53 -config client-certs.cnf | 57 -config client-certs.cnf |
| 54 | 58 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 CA_DIR=out \ | 101 CA_DIR=out \ |
| 98 ID=C \ | 102 ID=C \ |
| 99 try openssl ca \ | 103 try openssl ca \ |
| 100 -batch \ | 104 -batch \ |
| 101 -extensions ca_cert \ | 105 -extensions ca_cert \ |
| 102 -in out/E.csr \ | 106 -in out/E.csr \ |
| 103 -out out/E.pem \ | 107 -out out/E.pem \ |
| 104 -config client-certs.cnf | 108 -config client-certs.cnf |
| 105 | 109 |
| 106 echo Generate the leaf certs | 110 echo Generate the leaf certs |
| 107 for id in A D F | 111 for id in A D F G |
| 108 do | 112 do |
| 109 COMMON_NAME="Client Cert $id" \ | 113 COMMON_NAME="Client Cert $id" \ |
| 110 ID=$id \ | 114 ID=$id \ |
| 111 try openssl req \ | 115 try openssl req \ |
| 112 -new \ | 116 -new \ |
| 113 -key out/$id.key \ | 117 -key out/$id.key \ |
| 114 -out out/$id.csr \ | 118 -out out/$id.csr \ |
| 115 -config client-certs.cnf | 119 -config client-certs.cnf |
| 116 # Store the private key also in PKCS#8 format. | 120 # Store the private key also in PKCS#8 format. |
| 117 try openssl pkcs8 \ | 121 try openssl pkcs8 \ |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 147 COMMON_NAME="E CA" \ | 151 COMMON_NAME="E CA" \ |
| 148 CA_DIR=out \ | 152 CA_DIR=out \ |
| 149 ID=E \ | 153 ID=E \ |
| 150 try openssl ca \ | 154 try openssl ca \ |
| 151 -batch \ | 155 -batch \ |
| 152 -extensions san_user_cert \ | 156 -extensions san_user_cert \ |
| 153 -in out/F.csr \ | 157 -in out/F.csr \ |
| 154 -out out/F.pem \ | 158 -out out/F.pem \ |
| 155 -config client-certs.cnf | 159 -config client-certs.cnf |
| 156 | 160 |
| 161 echo E signs G | |
| 162 COMMON_NAME="E CA" \ | |
| 163 CA_DIR=out \ | |
| 164 ID=E \ | |
| 165 try openssl ca \ | |
| 166 -batch \ | |
| 167 -extensions user_cert \ | |
| 168 -in out/G.csr \ | |
| 169 -out out/G.pem \ | |
| 170 -config client-certs.cnf | |
| 171 | |
| 157 echo Package the client certs and private keys into PKCS12 files | 172 echo Package the client certs and private keys into PKCS12 files |
| 158 # This is done for easily importing all of the certs needed for clients. | 173 # This is done for easily importing all of the certs needed for clients. |
| 159 try /bin/sh -c "cat out/A.pem out/A.key out/B.pem out/C.pem > out/A-chain.pem" | 174 try /bin/sh -c "cat out/A.pem out/A.key out/B.pem out/C.pem > out/A-chain.pem" |
| 160 try /bin/sh -c "cat out/D.pem out/D.key out/E.pem out/C.pem > out/D-chain.pem" | 175 try /bin/sh -c "cat out/D.pem out/D.key out/E.pem out/C.pem > out/D-chain.pem" |
| 161 try /bin/sh -c "cat out/F.pem out/F.key out/E.pem out/C.pem > out/F-chain.pem" | 176 try /bin/sh -c "cat out/F.pem out/F.key out/E.pem out/C.pem > out/F-chain.pem" |
| 177 try /bin/sh -c "cat out/G.pem out/G.key out/E.pem out/C.pem > out/G-chain.pem" | |
| 162 | 178 |
| 163 try openssl pkcs12 \ | 179 try openssl pkcs12 \ |
| 164 -in out/A-chain.pem \ | 180 -in out/A-chain.pem \ |
| 165 -out client_1.p12 \ | 181 -out client_1.p12 \ |
| 166 -export \ | 182 -export \ |
| 167 -passout pass:chrome | 183 -passout pass:chrome |
| 168 | 184 |
| 169 try openssl pkcs12 \ | 185 try openssl pkcs12 \ |
| 170 -in out/D-chain.pem \ | 186 -in out/D-chain.pem \ |
| 171 -out client_2.p12 \ | 187 -out client_2.p12 \ |
| 172 -export \ | 188 -export \ |
| 173 -passout pass:chrome | 189 -passout pass:chrome |
| 174 | 190 |
| 175 try openssl pkcs12 \ | 191 try openssl pkcs12 \ |
| 176 -in out/F-chain.pem \ | 192 -in out/F-chain.pem \ |
| 177 -out client_3.p12 \ | 193 -out client_3.p12 \ |
| 178 -export \ | 194 -export \ |
| 179 -passout pass:chrome | 195 -passout pass:chrome |
| 180 | 196 |
| 197 try openssl pkcs12 \ | |
| 198 -in out/G-chain.pem \ | |
| 199 -out client_4.p12 \ | |
| 200 -export \ | |
| 201 -passout pass:chrome | |
|
mattm
2016/10/03 22:51:04
I wonder why this script generates the .p12 files
davidben
2016/10/04 18:56:31
No idea. I've found them useful at times, but I've
| |
| 202 | |
| 181 echo Package the client certs for unit tests | 203 echo Package the client certs for unit tests |
|
mattm
2016/10/03 22:51:04
While you're here.. would you mind making this cop
davidben
2016/10/04 18:56:31
Done.
| |
| 182 try cp out/A.pem ../certificates/client_1.pem | 204 try cp out/A.pem ../certificates/client_1.pem |
| 183 try cp out/A.key ../certificates/client_1.key | 205 try cp out/A.key ../certificates/client_1.key |
| 184 try cp out/A.pk8 ../certificates/client_1.pk8 | 206 try cp out/A.pk8 ../certificates/client_1.pk8 |
| 185 try cp out/B.pem ../certificates/client_1_ca.pem | 207 try cp out/B.pem ../certificates/client_1_ca.pem |
| 186 | 208 |
| 187 try cp out/D.pem ../certificates/client_2.pem | 209 try cp out/D.pem ../certificates/client_2.pem |
| 188 try cp out/D.key ../certificates/client_2.key | 210 try cp out/D.key ../certificates/client_2.key |
| 189 try cp out/D.pk8 ../certificates/client_2.pk8 | 211 try cp out/D.pk8 ../certificates/client_2.pk8 |
| 190 try cp out/E.pem ../certificates/client_2_ca.pem | 212 try cp out/E.pem ../certificates/client_2_ca.pem |
| 191 | 213 |
| 192 try cp out/F.pem ../certificates/client_3.pem | 214 try cp out/F.pem ../certificates/client_3.pem |
| 193 try cp out/F.key ../certificates/client_3.key | 215 try cp out/F.key ../certificates/client_3.key |
| 194 try cp out/F.pk8 ../certificates/client_3.pk8 | 216 try cp out/F.pk8 ../certificates/client_3.pk8 |
| 195 try cp out/E.pem ../certificates/client_3_ca.pem | 217 try cp out/E.pem ../certificates/client_3_ca.pem |
| 218 | |
| 219 try cp out/G.pem ../certificates/client_4.pem | |
| 220 try cp out/G.key ../certificates/client_4.key | |
| 221 try cp out/G.pk8 ../certificates/client_4.pk8 | |
| 222 try cp out/E.pem ../certificates/client_4_ca.pem | |
| OLD | NEW |