Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/bin/sh | 1 #!/bin/sh |
| 2 | 2 |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 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 two chains of test certificates: | 7 # This script generates several forms of test certificate chains, used to test |
| 8 # | 8 # how the platform handles path building and revocations. They are designed |
| 9 # 1. A (end-entity) -> B -> C -> D (self-signed root) | 9 # to mirror how the WebPKI has evolved. |
| 10 # 2. A (end-entity) -> B -> C2 -> E (self-signed root) | 10 # |
| 11 # | 11 # Letters annotate which subject & key is used, while numbers indicate |
| 12 # C and C2 have the same subject and keypair. | 12 # the issuer (e.g. C1 and C2 share the same subject & key, but have different |
| 13 # | 13 # issuers). They are ordered from leaf to root. |
| 14 # We use these cert chains in CertVerifyProcChromeOSTest | 14 # |
| 15 # to ensure that multiple verification paths are properly handled. | 15 # Tests for basic path building (e.g. when E is trusted, but D is not) |
| 16 | 16 # 1. A -> B -> C -> D |
| 17 try () { | 17 # 2. A -> B -> C2 -> E |
| 18 echo "$@" | 18 # |
| 19 "$@" || exit 1 | 19 # Tests for basic intermediate revocation (e.g. when the client trusts both |
| 20 } | 20 # E and F). |
| 21 | 21 # Note: To fully test for the cases, it's necessary to massage the structures |
| 22 try rm -rf out | 22 # so that the various library sorting routines 'prefer' the revoked path first, |
| 23 try mkdir out | 23 # such as by modifying the issuance dates. |
| 24 | 24 # The goal is that for both cases, the client will find/use either paths #1 or |
| 25 echo Create the serial number files. | 25 # #2, despite being presented (by the server) with paths #3 or #4. |
| 26 # | |
| 27 # 3. A -> B -> C3 [revoked by F by issuer & serial] -> F | |
| 28 # 4. A -> B2 -> G [revoked by F by SPKI] -> F | |
| 29 # | |
| 30 # Tests for cross-certified hell - such as when roots mutually certify, | |
| 31 # creating a potential 'loop'. | |
| 32 # In this case, a version of J2-signed-by-K exists, as does a version of | |
| 33 # K2-signed-by-J (thus, a loop). In addition, self-signed versions of both J | |
| 34 # and K exist, which reflect what happens when OS stores phase out one root | |
| 35 # while phasing in a new root. | |
| 36 # | |
| 37 # 5. H -> I -> J | |
| 38 # 6. H -> I -> J2 -> K [revoked by SPKI] | |
| 39 # 7. H -> I -> J2 -> K2 [revoked by SPKI] -> J | |
| 40 # 8. H -> I -> J2 -> K2 [revoked by SPKI] -> J2 -> K [revoked by SPKI] | |
|
Ryan Sleevi
2016/01/15 01:12:55
The complexities of these chains are for the inevi
davidben
2016/01/21 02:37:39
[Incidentally, this became so much easier to under
| |
| 41 | |
| 42 # Exit script as soon a something fails. | |
| 43 set -e | |
| 44 | |
| 45 rm -rf out | |
| 46 mkdir out | |
| 47 | |
| 48 # Note: Serial files are created based on subject+key pair, thus cross-signed | |
| 49 # certificates (C2, C3, J2, K2) do *not* have unique serial files generated for | |
| 50 # them. | |
| 51 echo Create the serial and index number files. | |
| 26 serial=1000 | 52 serial=1000 |
| 27 for i in B C C2 D E | 53 for i in B C D E F G I J K |
| 28 do | 54 do |
| 29 try /bin/sh -c "echo $serial > out/$i-serial" | 55 /bin/sh -c "echo ${serial} > out/${i}-serial" |
| 30 serial=$(expr $serial + 1) | 56 touch "out/${i}-index.txt" |
| 31 done | 57 done |
| 32 | 58 |
| 33 echo Generate the keys. | 59 echo Generate the keys. |
| 34 try openssl genrsa -out out/A.key 2048 | 60 for i in A B C D E F G H I J K |
| 35 try openssl genrsa -out out/B.key 2048 | 61 do |
| 36 try openssl genrsa -out out/C.key 2048 | 62 openssl genrsa -out "out/${i}.key" 2048 |
| 37 try openssl genrsa -out out/D.key 2048 | 63 done |
| 38 try openssl genrsa -out out/E.key 2048 | 64 |
| 39 | 65 echo "Generating the self-signed roots" |
| 40 echo Generate the D CSR. | 66 for i in D E F J K |
| 41 CA_COMMON_NAME="D Root CA" \ | 67 do |
| 42 CERTIFICATE=D \ | 68 echo "Generating CSR ${i}" |
| 43 try openssl req \ | 69 CA_COMMON_NAME="${i} Root CA" \ |
| 70 CERTIFICATE="${i}" \ | |
| 71 openssl req \ | |
| 72 -config redundant-ca.cnf \ | |
| 44 -new \ | 73 -new \ |
| 45 -key out/D.key \ | 74 -key "out/${i}.key" \ |
| 46 -out out/D.csr \ | 75 -out "out/${i}.csr" |
| 47 -config redundant-ca.cnf | 76 |
| 48 | 77 echo "Generating self-signed ${i}" |
| 49 echo D signs itself. | 78 CA_COMMON_NAME="${i} Root CA" \ |
| 50 CA_COMMON_NAME="D Root CA" \ | 79 CERTIFICATE="${i}" \ |
| 51 try openssl x509 \ | 80 openssl ca \ |
| 52 -req -days 3650 \ | 81 -config redundant-ca.cnf \ |
| 53 -in out/D.csr \ | 82 -batch \ |
| 83 -startdate 160102000000Z \ | |
| 84 -enddate 260102000000Z \ | |
| 54 -extensions ca_cert \ | 85 -extensions ca_cert \ |
| 55 -extfile redundant-ca.cnf \ | 86 -extfile redundant-ca.cnf \ |
| 56 -signkey out/D.key \ | 87 -selfsign \ |
| 57 -out out/D.pem \ | 88 -in "out/${i}.csr" \ |
| 58 -text | 89 -out "out/${i}.pem" |
| 59 | 90 done |
| 60 echo Generate the E CSR. | 91 |
| 61 CA_COMMON_NAME="E Root CA" \ | 92 echo "Generating intermediate CSRs" |
| 62 CERTIFICATE=E \ | 93 for i in B C G I |
| 63 try openssl req \ | 94 do |
| 95 echo "Generating CSR ${i}" | |
| 96 CA_COMMON_NAME="${i} CA" \ | |
| 97 CERTIFICATE="${i}" \ | |
| 98 openssl req \ | |
| 99 -config redundant-ca.cnf \ | |
| 64 -new \ | 100 -new \ |
| 65 -key out/E.key \ | 101 -key "out/${i}.key" \ |
| 66 -out out/E.csr \ | 102 -out "out/${i}.csr" |
| 67 -config redundant-ca.cnf | 103 done |
| 68 | 104 |
| 69 echo E signs itself. | 105 echo D signs C |
| 70 CA_COMMON_NAME="E Root CA" \ | 106 CA_COMMON_NAME="D CA" \ |
| 71 try openssl x509 \ | 107 CERTIFICATE=D \ |
| 72 -req -days 3650 \ | 108 openssl ca \ |
| 73 -in out/E.csr \ | 109 -config redundant-ca.cnf \ |
| 74 -extensions ca_cert \ | 110 -batch \ |
| 75 -extfile redundant-ca.cnf \ | 111 -startdate 160103000000Z \ |
| 76 -signkey out/E.key \ | 112 -enddate 260102000000Z \ |
| 77 -out out/E.pem \ | 113 -extensions ca_cert \ |
| 78 -text | 114 -extfile redundant-ca.cnf \ |
| 79 | 115 -in out/C.csr \ |
| 80 echo Generate the C2 intermediary CSR. | 116 -out out/C.pem |
| 117 | |
| 118 echo C signs B | |
| 81 CA_COMMON_NAME="C CA" \ | 119 CA_COMMON_NAME="C CA" \ |
| 82 CERTIFICATE=C2 \ | 120 CERTIFICATE=C \ |
| 83 try openssl req \ | 121 openssl ca \ |
| 122 -config redundant-ca.cnf \ | |
| 123 -batch \ | |
| 124 -startdate 160104000000Z \ | |
| 125 -enddate 260102000000Z \ | |
| 126 -extensions ca_cert \ | |
| 127 -extfile redundant-ca.cnf \ | |
| 128 -in out/B.csr \ | |
| 129 -out out/B.pem | |
| 130 | |
| 131 echo E signs C2 | |
| 132 CA_COMMON_NAME="E CA" \ | |
| 133 CERTIFICATE=E \ | |
| 134 openssl ca \ | |
| 135 -config redundant-ca.cnf \ | |
| 136 -batch \ | |
| 137 -startdate 160105000000Z \ | |
| 138 -enddate 260102000000Z \ | |
| 139 -extensions ca_cert \ | |
| 140 -extfile redundant-ca.cnf \ | |
| 141 -in out/C.csr \ | |
| 142 -out out/C2.pem | |
| 143 | |
| 144 # Not necessary for C2 to sign B | |
| 145 # TODO(rsleevi): AKI/SPKI issues? | |
| 146 | |
| 147 echo F signs C3 | |
| 148 CA_COMMON_NAME="F CA" \ | |
| 149 CERTIFICATE=F \ | |
| 150 openssl ca \ | |
| 151 -config redundant-ca.cnf \ | |
| 152 -batch \ | |
| 153 -startdate 160106000000Z \ | |
| 154 -enddate 260102000000Z \ | |
| 155 -extensions ca_cert \ | |
| 156 -extfile redundant-ca.cnf \ | |
| 157 -in out/C.csr \ | |
| 158 -out out/C3.pem | |
| 159 | |
| 160 # Not necessary for C3 to sign B | |
| 161 # TODO(rsleevi): AKI/SPKI issues? | |
|
davidben
2016/01/21 02:37:39
Wouldn't it be equally unnecessary for C2 to sign
Ryan Sleevi
2016/01/21 02:54:05
See line 144 for the same comment
The AKI/SPKI is
| |
| 162 | |
| 163 echo F signs G | |
| 164 CA_COMMON_NAME="F CA" \ | |
| 165 CERTIFICATE=F \ | |
| 166 openssl ca \ | |
| 167 -config redundant-ca.cnf \ | |
| 168 -batch \ | |
| 169 -startdate 160102000000Z \ | |
| 170 -enddate 260102000000Z \ | |
| 171 -extensions ca_cert \ | |
| 172 -extfile redundant-ca.cnf \ | |
| 173 -in out/G.csr \ | |
| 174 -out out/G.pem | |
| 175 | |
| 176 # Note: The startdate for B2 MUST be greater than B's start date. | |
| 177 echo G signs B2 | |
| 178 CA_COMMON_NAME="G CA" \ | |
| 179 CERTIFICATE=G \ | |
| 180 openssl ca \ | |
| 181 -config redundant-ca.cnf \ | |
| 182 -batch \ | |
| 183 -startdate 160105000000Z \ | |
| 184 -enddate 260102000000Z \ | |
| 185 -extensions ca_cert \ | |
| 186 -extfile redundant-ca.cnf \ | |
| 187 -in out/B.csr \ | |
| 188 -out out/B2.pem | |
| 189 | |
| 190 # Note: The startdate for K2 MUST be greater than K's start date. | |
| 191 echo J signs K2 | |
| 192 CA_COMMON_NAME="J CA" \ | |
| 193 CERTIFICATE=J \ | |
| 194 openssl ca \ | |
| 195 -config redundant-ca.cnf \ | |
| 196 -batch \ | |
| 197 -startdate 160104000000Z \ | |
| 198 -enddate 260102000000Z \ | |
| 199 -extensions ca_cert_with_aki \ | |
|
davidben
2016/01/21 02:37:39
Why does this and the one below have AKI, but not
Ryan Sleevi
2016/01/21 02:54:05
Blergh, this was debugging for CAPI and how it han
| |
| 200 -extfile redundant-ca.cnf \ | |
| 201 -in out/K.csr \ | |
| 202 -out out/K2.pem | |
| 203 | |
| 204 # Note: The startdate for J2 MUST be greater than J's start date, | |
| 205 echo K signs J2 | |
| 206 CA_COMMON_NAME="K CA" \ | |
| 207 CERTIFICATE=K \ | |
| 208 openssl ca \ | |
| 209 -config redundant-ca.cnf \ | |
| 210 -batch \ | |
| 211 -startdate 160104000000Z \ | |
| 212 -enddate 260102000000Z \ | |
| 213 -extensions ca_cert_with_aki \ | |
| 214 -extfile redundant-ca.cnf \ | |
| 215 -in out/J.csr \ | |
| 216 -out out/J2.pem | |
| 217 | |
| 218 echo J signs I | |
| 219 CA_COMMON_NAME="J CA" \ | |
| 220 CERTIFICATE=J \ | |
| 221 openssl ca \ | |
| 222 -config redundant-ca.cnf \ | |
| 223 -batch \ | |
| 224 -startdate 160103000000Z \ | |
| 225 -enddate 260102000000Z \ | |
| 226 -extensions ca_cert \ | |
| 227 -extfile redundant-ca.cnf \ | |
| 228 -in out/I.csr \ | |
| 229 -out out/I.pem | |
| 230 | |
| 231 # Not necessary for J2 to sign I | |
| 232 # TODO(rsleevi): AKI/SPKI issues? | |
|
davidben
2016/01/21 02:37:39
(Ditto about what this comment is for)
| |
| 233 | |
| 234 echo "Generating leaf CSRs" | |
| 235 for i in A H | |
| 236 do | |
| 237 echo "Generating leaf ${i}" | |
| 238 openssl req \ | |
| 239 -config ee.cnf \ | |
| 84 -new \ | 240 -new \ |
| 85 -key out/C.key \ | 241 -key "out/${i}.key" \ |
| 86 -out out/C2.csr \ | 242 -out "out/${i}.csr" |
| 87 -config redundant-ca.cnf | 243 done |
| 88 | 244 |
| 89 echo Generate the B and C intermediaries\' CSRs. | 245 echo "Signing leaves" |
| 90 for i in B C | |
| 91 do | |
| 92 CA_COMMON_NAME="$i CA" \ | |
| 93 CERTIFICATE="$i" \ | |
| 94 try openssl req \ | |
| 95 -new \ | |
| 96 -key "out/$i.key" \ | |
| 97 -out "out/$i.csr" \ | |
| 98 -config redundant-ca.cnf | |
| 99 done | |
| 100 | |
| 101 echo D signs the C intermediate. | |
| 102 # Make sure the signer's DB file exists. | |
| 103 touch out/D-index.txt | |
| 104 CA_COMMON_NAME="D Root CA" \ | |
| 105 CERTIFICATE=D \ | |
| 106 try openssl ca \ | |
| 107 -batch \ | |
| 108 -extensions ca_cert \ | |
| 109 -in out/C.csr \ | |
| 110 -out out/C.pem \ | |
| 111 -config redundant-ca.cnf | |
| 112 | |
| 113 echo E signs the C2 intermediate. | |
| 114 # Make sure the signer's DB file exists. | |
| 115 touch out/E-index.txt | |
| 116 CA_COMMON_NAME="E Root CA" \ | |
| 117 CERTIFICATE=E \ | |
| 118 try openssl ca \ | |
| 119 -batch \ | |
| 120 -extensions ca_cert \ | |
| 121 -in out/C2.csr \ | |
| 122 -out out/C2.pem \ | |
| 123 -config redundant-ca.cnf | |
| 124 | |
| 125 echo C signs the B intermediate. | |
| 126 touch out/C-index.txt | |
| 127 CA_COMMON_NAME="C CA" \ | |
| 128 CERTIFICATE=C \ | |
| 129 try openssl ca \ | |
| 130 -batch \ | |
| 131 -extensions ca_cert \ | |
| 132 -in out/B.csr \ | |
| 133 -out out/B.pem \ | |
| 134 -config redundant-ca.cnf | |
| 135 | |
| 136 echo Generate the A end-entity CSR. | |
| 137 try openssl req \ | |
| 138 -new \ | |
| 139 -key out/A.key \ | |
| 140 -out out/A.csr \ | |
| 141 -config ee.cnf | |
| 142 | |
| 143 echo B signs A. | |
| 144 touch out/B-index.txt | |
| 145 CA_COMMON_NAME="B CA" \ | 246 CA_COMMON_NAME="B CA" \ |
| 146 CERTIFICATE=B \ | 247 CERTIFICATE=B \ |
| 147 try openssl ca \ | 248 openssl ca \ |
| 148 -batch \ | 249 -config redundant-ca.cnf \ |
| 149 -extensions user_cert \ | 250 -batch \ |
| 150 -in out/A.csr \ | 251 -days 3650 \ |
| 151 -out out/A.pem \ | 252 -extensions user_cert \ |
| 152 -config redundant-ca.cnf | 253 -extfile redundant-ca.cnf \ |
| 153 | 254 -in out/A.csr \ |
| 154 echo Create multi-root-chain1.pem | 255 -out out/A.pem |
| 155 try /bin/sh -c "cat out/A.key out/A.pem out/B.pem out/C.pem out/D.pem \ | 256 |
| 257 CA_COMMON_NAME="I CA" \ | |
| 258 CERTIFICATE=I \ | |
| 259 openssl ca \ | |
| 260 -config redundant-ca.cnf \ | |
| 261 -batch \ | |
| 262 -days 3650 \ | |
| 263 -extensions user_cert \ | |
| 264 -extfile redundant-ca.cnf \ | |
| 265 -in out/H.csr \ | |
| 266 -out out/H.pem | |
| 267 | |
| 268 echo Creating chain files | |
| 269 /bin/sh -c "cat out/A.key out/A.pem out/B.pem out/C.pem out/D.pem \ | |
| 156 > ../certificates/multi-root-chain1.pem" | 270 > ../certificates/multi-root-chain1.pem" |
| 157 | 271 /bin/sh -c "cat out/A.key out/A.pem out/B.pem out/C2.pem out/E.pem \ |
| 158 echo Create multi-root-chain2.pem | |
| 159 try /bin/sh -c "cat out/A.key out/A.pem out/B.pem out/C2.pem out/E.pem \ | |
| 160 > ../certificates/multi-root-chain2.pem" | 272 > ../certificates/multi-root-chain2.pem" |
| 161 | 273 /bin/sh -c "cat out/A.key out/A.pem out/B.pem out/C3.pem out/F.pem \ |
| 274 > ../certificates/multi-root-chain3.pem" | |
| 275 /bin/sh -c "cat out/A.key out/A.pem out/B2.pem out/G.pem out/F.pem \ | |
| 276 > ../certificates/multi-root-chain4.pem" | |
| 277 /bin/sh -c "cat out/H.key out/H.pem out/I.pem out/J.pem \ | |
| 278 > ../certificates/multi-root-chain5.pem" | |
| 279 /bin/sh -c "cat out/H.key out/H.pem out/I.pem out/J2.pem out/K.pem \ | |
| 280 > ../certificates/multi-root-chain6.pem" | |
| 281 /bin/sh -c "cat out/H.key out/H.pem out/I.pem out/J2.pem out/K2.pem out/J.pem \ | |
| 282 > ../certificates/multi-root-chain7.pem" | |
| 283 /bin/sh -c "cat out/H.key out/H.pem out/I.pem out/J2.pem out/K2.pem out/J2.pem \ | |
| 284 out/K.pem > ../certificates/multi-root-chain8.pem" | |
| 285 | |
| 286 echo Generating CRLSets | |
| 287 # Block C3 (serial number 0x1001), as issued by F, by way of serial number. | |
| 288 python crlsetutil.py -o ../certificates/multi-root-crlset-C3.raw \ | |
| 289 <<CRLSETBYSERIAL | |
| 290 { | |
| 291 "BlockedByHash": { | |
| 292 "out/F.pem": [4097] | |
| 293 } | |
| 294 } | |
| 295 CRLSETBYSERIAL | |
| 296 | |
| 297 # Block G (serial number 0x1002), as issued by F, by way of SPKI | |
| 298 python crlsetutil.py -o ../certificates/multi-root-crlset-G.raw \ | |
| 299 <<CRLSETBYSPKI | |
| 300 { | |
| 301 "BlockedBySPKI": [ "out/G.pem" ] | |
| 302 } | |
| 303 CRLSETBYSPKI | |
| 304 | |
| 305 # Block K (serial number 0x1000 as self-issued, 0x1001 as issued by J) | |
| 306 python crlsetutil.py -o ../certificates/multi-root-crlset-K.raw \ | |
| 307 <<CRLSETLOOPBYSPKI | |
| 308 { | |
| 309 "BlockedBySPKI": [ "out/K.pem" ] | |
| 310 } | |
| 311 CRLSETLOOPBYSPKI | |
| OLD | NEW |