1#!/usr/bin/env python 2# Copyright 2019 The Chromium Authors 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# https://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15"""This script is called without any arguments to re-generate all of the *.pem 16files in the script's directory. 17 18The https://github.com/google/der-ascii tools must be in the PATH. 19 20These tests assume that the verification time will be 2017-03-09 00:00:00 GMT 21and verified with a max CRL age of 7 days. 22""" 23 24import datetime 25import subprocess 26import os 27 28from OpenSSL import crypto 29 30import base64 31 32 33HEADER = "Generated by %s. Do not edit." % os.path.split(__file__)[1] 34 35NEXT_SERIAL = 0 36 37# 2017-01-01 00:00 GMT 38CERT_DATE = datetime.datetime(2017, 1, 1, 0, 0) 39 40# 2018-01-01 00:00 GMT 41CERT_EXPIRE = CERT_DATE + datetime.timedelta(days=365) 42 43 44def DictUnion(a, b): 45 return dict(a.items() + b.items()) 46 47 48def Der2Ascii(txt): 49 p = subprocess.Popen(['der2ascii'], 50 stdin=subprocess.PIPE, 51 stdout=subprocess.PIPE, 52 stderr=subprocess.PIPE) 53 stdout_data, stderr_data = p.communicate(txt) 54 if p.returncode: 55 raise RuntimeError('der2ascii returned %i: %s' % (p.returncode, 56 stderr_data)) 57 return stdout_data 58 59 60def Ascii2Der(txt): 61 p = subprocess.Popen(['ascii2der'], 62 stdin=subprocess.PIPE, 63 stdout=subprocess.PIPE, 64 stderr=subprocess.PIPE) 65 stdout_data, stderr_data = p.communicate(txt) 66 if p.returncode: 67 raise RuntimeError('ascii2der returned %i: %s' % (p.returncode, 68 stderr_data)) 69 return stdout_data 70 71 72def Ascii2OpensslDer(txt): 73 der = Ascii2Der(txt) 74 return 'DER:' + ''.join(['%02X' % ord(b) for b in der]) 75 76 77def CreateCert(name, signer, pkey=None, crl_dp=None, key_usage=None, 78 is_ca=True, version=2): 79 global NEXT_SERIAL 80 if pkey is None: 81 pkey = crypto.PKey() 82 pkey.generate_key(crypto.TYPE_RSA, 1024) 83 cert = crypto.X509() 84 cert.set_version(version) 85 cert.get_subject().CN = name 86 cert.set_pubkey(pkey) 87 cert.set_serial_number(NEXT_SERIAL) 88 NEXT_SERIAL += 1 89 cert.set_notBefore(CERT_DATE.strftime('%Y%m%d%H%M%SZ')) 90 cert.set_notAfter(CERT_EXPIRE.strftime('%Y%m%d%H%M%SZ')) 91 if version == 2: 92 if crl_dp: 93 cert.add_extensions( 94 [crypto.X509Extension('crlDistributionPoints', False, crl_dp)]) 95 if key_usage: 96 cert.add_extensions( 97 [crypto.X509Extension('keyUsage', False, key_usage)]) 98 if is_ca is not None: 99 cert.add_extensions( 100 [crypto.X509Extension('basicConstraints', True, 101 'CA:%s' % ('TRUE' if is_ca else 'FALSE'))]) 102 if signer: 103 cert.set_issuer(signer['cert'].get_subject()) 104 cert.sign(signer['pkey'], 'sha256') 105 else: 106 cert.set_issuer(cert.get_subject()) 107 cert.sign(pkey, 'sha256') 108 109 result = dict(cert=cert, pkey=pkey) 110 if not signer: 111 signer = result 112 result['signer'] = signer 113 return result 114 115 116ROOT_CA = CreateCert('Test CA', None) 117 118# Multiple versions of the intermediate. All use the same name and private key. 119CA = CreateCert('Test Intermediate CA', ROOT_CA, 120 key_usage='critical, keyCertSign, cRLSign') 121CA_NO_KEYUSAGE = CreateCert('Test Intermediate CA', ROOT_CA, 122 pkey=CA['pkey'], key_usage=None) 123CA_KEYUSAGE_NOCRLSIGN = CreateCert('Test Intermediate CA', ROOT_CA, 124 pkey=CA['pkey'], 125 key_usage='critical, keyCertSign') 126 127# A different CA with a different name and key. 128OTHER_CA = CreateCert('Test Other Intermediate CA', ROOT_CA) 129 130# The target cert, with a simple crlDistributionPoints pointing to an arbitrary 131# URL, other crlDistributionPoints fields not set. 132LEAF = CreateCert('Test Cert', CA, crl_dp='URI:http://example.com/foo.crl', is_ca=False) 133 134# The target cert, with no basicConstraints. 135LEAF_NO_BASIC_CONSTRAINTS = CreateCert('Test Cert', CA, crl_dp='URI:http://example.com/foo.crl', is_ca=None) 136 137# The target cert, no crlDistributionPoints. 138LEAF_NO_CRLDP = CreateCert('Test Cert', CA, is_ca=False) 139 140# V1 target cert 141LEAF_V1 = CreateCert('Test Cert', CA, version=0, is_ca=None) 142 143# The target cert, crlDistributionPoints with crlIssuer and 144# crlDistributionPoints set. 145LEAF_CRLDP_CRLISSUER = CreateCert('Test Cert', CA, is_ca=False, 146 # It doesn't seem like you can set crlIssuers through the one-line openssl 147 # interface, so just do it manually. 148 crl_dp=Ascii2OpensslDer(''' 149 SEQUENCE { 150 SEQUENCE { 151 [0] { 152 [0] { 153 [6 PRIMITIVE] { "http://example.com/foo.crl" } 154 } 155 } 156 [2] { 157 [4] { 158 SEQUENCE { 159 SET { 160 SEQUENCE { 161 # commonName 162 OBJECT_IDENTIFIER { 2.5.4.3 } 163 UTF8String { "Test CRL Issuer CA" } 164 } 165 } 166 } 167 } 168 } 169 } 170 } 171 ''')) 172 173# Self-issued intermediate with a new key signed by the |CA| key. 174CA_NEW_BY_OLD = CreateCert('Test Intermediate CA', CA, 175 key_usage='critical, keyCertSign, cRLSign', 176 crl_dp='URI:http://example.com/foo.crl') 177 178# Target cert signed by |CA_NEW_BY_OLD|'s key. 179LEAF_BY_NEW = CreateCert( 180 'Test Cert', CA_NEW_BY_OLD, crl_dp='URI:http://example.com/foo.crl') 181 182 183def SignAsciiCRL(tbs_inner_txt, signer=CA): 184 tbs_txt = 'SEQUENCE {\n%s\n}' % tbs_inner_txt 185 tbs_der = Ascii2Der(tbs_txt) 186 signature = crypto.sign(signer['pkey'], tbs_der, 'sha256') 187 crl_text = ''' 188SEQUENCE { 189 %s 190 SEQUENCE { 191 # sha256WithRSAEncryption 192 OBJECT_IDENTIFIER { 1.2.840.113549.1.1.11 } 193 NULL {} 194 } 195 BIT_STRING { `00%s` } 196} 197''' % (tbs_txt, signature.encode('hex')) 198 CRL = Ascii2Der(crl_text) 199 200 return CRL 201 202 203def MakePemBlock(der, name): 204 text = Der2Ascii(der).rstrip('\n') 205 b64 = base64.b64encode(der) 206 wrapped = '\n'.join(b64[pos:pos + 64] for pos in xrange(0, len(b64), 64)) 207 return '%s\n-----BEGIN %s-----\n%s\n-----END %s-----' % ( 208 text, name, wrapped, name) 209 210 211def WriteStringToFile(data, path): 212 with open(path, "w") as f: 213 f.write(data) 214 215 216def Store(fname, description, leaf, ca, crl_der, ca2=None): 217 ca_cert_der = crypto.dump_certificate(crypto.FILETYPE_ASN1, ca['cert']) 218 cert_der = crypto.dump_certificate(crypto.FILETYPE_ASN1, leaf['cert']) 219 220 out = '\n\n'.join([ 221 HEADER, 222 description, 223 MakePemBlock(crl_der, 'CRL'), 224 MakePemBlock(ca_cert_der, 'CA CERTIFICATE'), 225 MakePemBlock(cert_der, 'CERTIFICATE')]) 226 227 if ca2: 228 ca_cert_2_der = crypto.dump_certificate(crypto.FILETYPE_ASN1, ca2['cert']) 229 out += '\n\n' + MakePemBlock(ca_cert_2_der, 'CA CERTIFICATE 2') 230 231 open('%s.pem' % fname, 'w').write(out) 232 233 234crl_strings = { 235 'sha256WithRSAEncryption': ''' 236 SEQUENCE { 237 OBJECT_IDENTIFIER { 1.2.840.113549.1.1.11 } 238 NULL {} 239 } 240 ''', 241 242 'sha384WithRSAEncryption': ''' 243 SEQUENCE { 244 OBJECT_IDENTIFIER { 1.2.840.113549.1.1.12 } 245 NULL {} 246 } 247 ''', 248 249 'CA_name': ''' 250 SEQUENCE { 251 SET { 252 SEQUENCE { 253 # commonName 254 OBJECT_IDENTIFIER { 2.5.4.3 } 255 UTF8String { "Test Intermediate CA" } 256 } 257 } 258 } 259 ''', 260 261 'thisUpdate': 'UTCTime { "170302001122Z" }', 262 'nextUpdate': 'UTCTime { "170602001122Z" }', 263 'thisUpdateGeneralized': 'GeneralizedTime { "20170302001122Z" }', 264 'nextUpdateGeneralized': 'GeneralizedTime { "20170602001122Z" }', 265 'thisUpdate_too_old': 'UTCTime { "170301001122Z" }', 266 'thisUpdate_in_future': 'UTCTime { "170310001122Z" }', 267 'nextUpdate_too_old': 'UTCTime { "170308001122Z" }', 268 269 'leaf_revoked': ''' 270 SEQUENCE { 271 SEQUENCE { 272 INTEGER { %i } 273 UTCTime { "170201001122Z" } 274 # no crlEntryExtensions 275 } 276 SEQUENCE { 277 INTEGER { %i } 278 UTCTime { "170201001122Z" } 279 # no crlEntryExtensions 280 } 281 SEQUENCE { 282 INTEGER { %i } 283 UTCTime { "170201001122Z" } 284 # no crlEntryExtensions 285 } 286 } 287 ''' % (LEAF['cert'].get_serial_number() + 100, 288 LEAF['cert'].get_serial_number(), 289 LEAF['cert'].get_serial_number() + 101), 290 291 'leaf_revoked_fake_extension': ''' 292 SEQUENCE { 293 SEQUENCE { 294 INTEGER { %i } 295 UTCTime { "170201001122Z" } 296 # no crlEntryExtensions 297 } 298 SEQUENCE { 299 INTEGER { %i } 300 UTCTime { "170201001122Z" } 301 SEQUENCE { 302 SEQUENCE { 303 OBJECT_IDENTIFIER { 1.2.3.4 } 304 OCTET_STRING { `5678` } 305 } 306 } 307 } 308 SEQUENCE { 309 INTEGER { %i } 310 UTCTime { "170201001122Z" } 311 # no crlEntryExtensions 312 } 313 } 314 ''' % (LEAF['cert'].get_serial_number() + 100, 315 LEAF['cert'].get_serial_number(), 316 LEAF['cert'].get_serial_number() + 101), 317 318 'leaf_revoked_before_fake_critical_extension': ''' 319 SEQUENCE { 320 SEQUENCE { 321 INTEGER { %i } 322 UTCTime { "170201001122Z" } 323 # leaf revocation entry has no crlEntryExtensions 324 } 325 SEQUENCE { 326 INTEGER { %i } 327 UTCTime { "170201001122Z" } 328 # next revocation entry has a critical crlEntryExtension 329 SEQUENCE { 330 SEQUENCE { 331 OBJECT_IDENTIFIER { 1.2.3.4 } 332 BOOLEAN { `ff` } 333 OCTET_STRING { `5678` } 334 } 335 } 336 } 337 } 338 ''' % (LEAF['cert'].get_serial_number(), 339 LEAF['cert'].get_serial_number() + 101), 340 341 'leaf_revoked_generalizedtime': ''' 342 SEQUENCE { 343 SEQUENCE { 344 INTEGER { %i } 345 GeneralizedTime { "20170201001122Z" } 346 # no crlEntryExtensions 347 } 348 SEQUENCE { 349 INTEGER { %i } 350 GeneralizedTime { "20170201001122Z" } 351 # no crlEntryExtensions 352 } 353 SEQUENCE { 354 INTEGER { %i } 355 GeneralizedTime { "20170201001122Z" } 356 # no crlEntryExtensions 357 } 358 } 359 ''' % (LEAF['cert'].get_serial_number() + 100, 360 LEAF['cert'].get_serial_number(), 361 LEAF['cert'].get_serial_number() + 101), 362 363 'fake_extension': ''' 364 SEQUENCE { 365 OBJECT_IDENTIFIER { 1.2.3.4 } 366 OCTET_STRING { `5678` } 367 } 368 ''', 369 370 'fake_critical_extension': ''' 371 SEQUENCE { 372 OBJECT_IDENTIFIER { 1.2.3.4 } 373 BOOLEAN { `ff` } 374 OCTET_STRING { `5678` } 375 } 376 ''', 377 378 # An issuingDistributionPoint with multiple fullName values, one of which 379 # matches the URI in |LEAF|'s crlDistributionPoints extension. 380 'issuingDistributionPoint': ''' 381 SEQUENCE { 382 OBJECT_IDENTIFIER { 2.5.29.28 } 383 BOOLEAN { `ff` } 384 OCTET_STRING { 385 SEQUENCE { 386 [0] { 387 [0] { 388 [1 PRIMITIVE] { "foo@example.com" } 389 [6 PRIMITIVE] { "http://zexample.com/foo.crl" } 390 [6 PRIMITIVE] { "http://example.com/foo.crl" } 391 [6 PRIMITIVE] { "http://aexample.com/foo.crl" } 392 } 393 } 394 } 395 } 396 } 397 ''', 398 399 'issuingDistributionPoint_wrong_uri': ''' 400 SEQUENCE { 401 OBJECT_IDENTIFIER { 2.5.29.28 } 402 BOOLEAN { `ff` } 403 OCTET_STRING { 404 SEQUENCE { 405 [0] { 406 [0] { 407 [6 PRIMITIVE] { "http://example.com/FOO.CRL" } 408 } 409 } 410 } 411 } 412 } 413 ''', 414 415 'issuingDistributionPoint_with_indirectCRL': ''' 416 SEQUENCE { 417 OBJECT_IDENTIFIER { 2.5.29.28 } 418 BOOLEAN { `ff` } 419 OCTET_STRING { 420 SEQUENCE { 421 [0] { 422 [0] { 423 [6 PRIMITIVE] { "http://example.com/foo.crl" } 424 } 425 } 426 [4 PRIMITIVE] { `ff` } 427 } 428 } 429 } 430 ''', 431 432 'issuingDistributionPoint_with_onlyContainsUserCerts': ''' 433 SEQUENCE { 434 OBJECT_IDENTIFIER { 2.5.29.28 } 435 BOOLEAN { `ff` } 436 OCTET_STRING { 437 SEQUENCE { 438 [1 PRIMITIVE] { `ff` } 439 } 440 } 441 } 442 ''', 443 444 'issuingDistributionPoint_with_uri_and_onlyContainsUserCerts': ''' 445 SEQUENCE { 446 OBJECT_IDENTIFIER { 2.5.29.28 } 447 BOOLEAN { `ff` } 448 OCTET_STRING { 449 SEQUENCE { 450 [0] { 451 [0] { 452 [6 PRIMITIVE] { "http://example.com/foo.crl" } 453 } 454 } 455 [1 PRIMITIVE] { `ff` } 456 } 457 } 458 } 459 ''', 460 461 'issuingDistributionPoint_with_uri_and_onlyContainsCACerts': ''' 462 SEQUENCE { 463 OBJECT_IDENTIFIER { 2.5.29.28 } 464 BOOLEAN { `ff` } 465 OCTET_STRING { 466 SEQUENCE { 467 [0] { 468 [0] { 469 [6 PRIMITIVE] { "http://example.com/foo.crl" } 470 } 471 } 472 [2 PRIMITIVE] { `ff` } 473 } 474 } 475 } 476 ''', 477 478 'issuingDistributionPoint_with_onlyContainsCACerts': ''' 479 SEQUENCE { 480 OBJECT_IDENTIFIER { 2.5.29.28 } 481 BOOLEAN { `ff` } 482 OCTET_STRING { 483 SEQUENCE { 484 [2 PRIMITIVE] { `ff` } 485 } 486 } 487 } 488 ''', 489} 490 491 492Store( 493 'good', 494 'Leaf covered by CRLs and not revoked', 495 LEAF, CA, 496 SignAsciiCRL(''' 497 INTEGER { 1 } 498 %(sha256WithRSAEncryption)s 499 %(CA_name)s 500 %(thisUpdate)s 501 %(nextUpdate)s 502 # no revoked certs list 503 # no crlExtensions 504''' % crl_strings)) 505 506 507Store( 508 'good_issuer_name_normalization', 509 'Good, non-revoked, but issuer name in CRL requires case folding', 510 LEAF, CA, 511 SignAsciiCRL(''' 512 INTEGER { 1 } 513 %(sha256WithRSAEncryption)s 514 SEQUENCE { 515 SET { 516 SEQUENCE { 517 # commonName 518 OBJECT_IDENTIFIER { 2.5.4.3 } 519 # Name that requires case folding and type conversion. 520 PrintableString { "tEST iNTERMEDIATE ca" } 521 } 522 } 523 } 524 %(thisUpdate)s 525 %(nextUpdate)s 526 # no revoked certs list 527 # no crlExtensions 528''' % crl_strings)) 529 530 531Store( 532 'good_issuer_no_keyusage', 533 'Leaf covered by CRLs and not revoked, issuer has no keyUsage extension', 534 LEAF, CA_NO_KEYUSAGE, 535 SignAsciiCRL(''' 536 INTEGER { 1 } 537 %(sha256WithRSAEncryption)s 538 %(CA_name)s 539 %(thisUpdate)s 540 %(nextUpdate)s 541 # no revoked certs list 542 # no crlExtensions 543''' % crl_strings, signer=CA_NO_KEYUSAGE)) 544 545 546Store( 547 'good_no_nextupdate', 548 'Leaf covered by CRLs and not revoked, optional nextUpdate field is absent', 549 LEAF, CA, 550 SignAsciiCRL(''' 551 INTEGER { 1 } 552 %(sha256WithRSAEncryption)s 553 %(CA_name)s 554 %(thisUpdate)s 555 # no nextUpdate 556 # no revoked certs list 557 # no crlExtensions 558''' % crl_strings)) 559 560 561Store( 562 'good_fake_extension', 563 'Leaf covered by CRLs and not revoked, CRL has an irrelevant non-critical ' 564 'extension', 565 LEAF, CA, 566 SignAsciiCRL(''' 567 INTEGER { 1 } 568 %(sha256WithRSAEncryption)s 569 %(CA_name)s 570 %(thisUpdate)s 571 %(nextUpdate)s 572 # no revoked certs list 573 [0] { 574 SEQUENCE { 575 %(fake_extension)s 576 } 577 } 578''' % crl_strings)) 579 580 581Store( 582 'good_fake_extension_no_nextupdate', 583 'Leaf covered by CRLs and not revoked, CRL has an irrelevant non-critical ' 584 'extension', 585 LEAF, CA, 586 SignAsciiCRL(''' 587 INTEGER { 1 } 588 %(sha256WithRSAEncryption)s 589 %(CA_name)s 590 %(thisUpdate)s 591 # no nextUpdate 592 # no revoked certs list 593 [0] { 594 SEQUENCE { 595 %(fake_extension)s 596 } 597 } 598''' % crl_strings)) 599 600 601Store( 602 'good_generalizedtime', 603 'Leaf covered by CRLs and not revoked, dates encoded as GeneralizedTime', 604 LEAF, CA, 605 SignAsciiCRL(''' 606 INTEGER { 1 } 607 %(sha256WithRSAEncryption)s 608 %(CA_name)s 609 %(thisUpdateGeneralized)s 610 %(nextUpdateGeneralized)s 611 # no revoked certs list 612 # no crlExtensions 613''' % crl_strings)) 614 615 616Store( 617 'good_no_version', 618 'Leaf covered by CRLs and not revoked, CRL is V1', 619 LEAF, CA, 620 SignAsciiCRL(''' 621 # no version 622 %(sha256WithRSAEncryption)s 623 %(CA_name)s 624 %(thisUpdate)s 625 %(nextUpdate)s 626 # no revoked certs list 627 # no crlExtensions 628''' % crl_strings)) 629 630 631Store( 632 'good_idp_contains_uri', 633 'Leaf covered by CRLs and not revoked, CRL has IDP with URI matching ' 634 'cert DP', 635 LEAF, CA, 636 SignAsciiCRL(''' 637 INTEGER { 1 } 638 %(sha256WithRSAEncryption)s 639 %(CA_name)s 640 %(thisUpdate)s 641 %(nextUpdate)s 642 # no revoked certs list 643 [0] { 644 SEQUENCE { 645 %(issuingDistributionPoint)s 646 } 647 } 648''' % crl_strings)) 649 650 651Store( 652 'good_idp_onlycontainsusercerts', 653 'Leaf covered by CRLs and not revoked, CRL has IDP with ' 654 'onlyContainsUserCerts', 655 LEAF, CA, 656 SignAsciiCRL(''' 657 INTEGER { 1 } 658 %(sha256WithRSAEncryption)s 659 %(CA_name)s 660 %(thisUpdate)s 661 %(nextUpdate)s 662 # no revoked certs list 663 [0] { 664 SEQUENCE { 665 %(issuingDistributionPoint_with_onlyContainsUserCerts)s 666 } 667 } 668''' % crl_strings)) 669 670 671Store( 672 'good_idp_onlycontainsusercerts_no_basic_constraints', 673 'Leaf covered by CRLs and not revoked, CRL has IDP with ' 674 'onlyContainsUserCerts, leaf has no basicConstraints', 675 LEAF_NO_BASIC_CONSTRAINTS, CA, 676 SignAsciiCRL(''' 677 INTEGER { 1 } 678 %(sha256WithRSAEncryption)s 679 %(CA_name)s 680 %(thisUpdate)s 681 %(nextUpdate)s 682 # no revoked certs list 683 [0] { 684 SEQUENCE { 685 %(issuingDistributionPoint_with_onlyContainsUserCerts)s 686 } 687 } 688''' % crl_strings)) 689 690 691Store( 692 'good_idp_onlycontainscacerts', 693 'CA_NEW_BY_OLD covered by CRLs and not revoked, CRL has IDP with ' 694 'onlyContainsCaCerts', 695 CA_NEW_BY_OLD, CA, 696 SignAsciiCRL(''' 697 INTEGER { 1 } 698 %(sha256WithRSAEncryption)s 699 %(CA_name)s 700 %(thisUpdate)s 701 %(nextUpdate)s 702 # no revoked certs list 703 [0] { 704 SEQUENCE { 705 %(issuingDistributionPoint_with_onlyContainsCACerts)s 706 } 707 } 708''' % crl_strings)) 709 710 711Store( 712 'good_idp_uri_and_onlycontainsusercerts', 713 'Leaf covered by CRLs and not revoked, CRL has IDP with URI and ' 714 'onlyContainsUserCerts', 715 LEAF, CA, 716 SignAsciiCRL(''' 717 INTEGER { 1 } 718 %(sha256WithRSAEncryption)s 719 %(CA_name)s 720 %(thisUpdate)s 721 %(nextUpdate)s 722 # no revoked certs list 723 [0] { 724 SEQUENCE { 725 %(issuingDistributionPoint_with_uri_and_onlyContainsUserCerts)s 726 } 727 } 728''' % crl_strings)) 729 730 731Store( 732 'good_idp_uri_and_onlycontainscacerts', 733 'CA_NEW_BY_OLD covered by CRLs and not revoked, CRL has IDP with URI and ' 734 'onlyContainsCACerts', 735 CA_NEW_BY_OLD, CA, 736 SignAsciiCRL(''' 737 INTEGER { 1 } 738 %(sha256WithRSAEncryption)s 739 %(CA_name)s 740 %(thisUpdate)s 741 %(nextUpdate)s 742 # no revoked certs list 743 [0] { 744 SEQUENCE { 745 %(issuingDistributionPoint_with_uri_and_onlyContainsCACerts)s 746 } 747 } 748''' % crl_strings)) 749 750 751Store( 752 'good_no_crldp', 753 'Leaf covered by CRLs and not revoked and has no crlDistributionPoints.\n' 754 'This tests the case where CheckCRL is called with a synthesized ' 755 'distributionPoint.', 756 LEAF_NO_CRLDP, CA, 757 SignAsciiCRL(''' 758 INTEGER { 1 } 759 %(sha256WithRSAEncryption)s 760 %(CA_name)s 761 %(thisUpdate)s 762 %(nextUpdate)s 763 # no revoked certs list 764 # no crlExtensions 765''' % crl_strings)) 766 767 768Store( 769 'good_key_rollover', 770 "Leaf issued by CA's new key but CRL is signed by old key", 771 LEAF_BY_NEW, CA_NEW_BY_OLD, ca2=CA, 772 crl_der=SignAsciiCRL(''' 773 INTEGER { 1 } 774 %(sha256WithRSAEncryption)s 775 %(CA_name)s 776 %(thisUpdate)s 777 %(nextUpdate)s 778 # no revoked certs list 779 # no crlExtensions 780''' % crl_strings)) 781 782 783Store( 784 'revoked', 785 'Leaf is revoked', 786 LEAF, CA, 787 SignAsciiCRL(''' 788 INTEGER { 1 } 789 %(sha256WithRSAEncryption)s 790 %(CA_name)s 791 %(thisUpdate)s 792 %(nextUpdate)s 793 %(leaf_revoked)s 794 # no crlExtensions 795''' % crl_strings)) 796 797 798Store( 799 'revoked_no_nextupdate', 800 'Leaf is revoked, optional nextUpdate field is absent', 801 LEAF, CA, 802 SignAsciiCRL(''' 803 INTEGER { 1 } 804 %(sha256WithRSAEncryption)s 805 %(CA_name)s 806 %(thisUpdate)s 807 # no nextUpdate 808 %(leaf_revoked)s 809 # no crlExtensions 810''' % crl_strings)) 811 812 813Store( 814 'revoked_fake_crlentryextension', 815 'Leaf is revoked, has non-critical crlEntryExtension', 816 LEAF, CA, 817 SignAsciiCRL(''' 818 INTEGER { 1 } 819 %(sha256WithRSAEncryption)s 820 %(CA_name)s 821 %(thisUpdate)s 822 %(nextUpdate)s 823 %(leaf_revoked_fake_extension)s 824 # no crlExtensions 825''' % crl_strings)) 826 827 828Store( 829 'revoked_generalized_revocationdate', 830 'Leaf is revoked, revocationDate is encoded as GeneralizedTime', 831 LEAF, CA, 832 SignAsciiCRL(''' 833 INTEGER { 1 } 834 %(sha256WithRSAEncryption)s 835 %(CA_name)s 836 %(thisUpdate)s 837 %(nextUpdate)s 838 %(leaf_revoked_generalizedtime)s 839 # no crlExtensions 840''' % crl_strings)) 841 842 843Store( 844 'revoked_key_rollover', 845 "Leaf issued by CA's new key but CRL is signed by old key", 846 LEAF_BY_NEW, CA_NEW_BY_OLD, ca2=CA, 847 crl_der=SignAsciiCRL(''' 848 INTEGER { 1 } 849 %(sha256WithRSAEncryption)s 850 %(CA_name)s 851 %(thisUpdate)s 852 %(nextUpdate)s 853 SEQUENCE { 854 SEQUENCE { 855 INTEGER { %(LEAF_SERIAL)i } 856 UTCTime { "170201001122Z" } 857 # no crlEntryExtensions 858 } 859 } 860 # no crlExtensions 861''' % DictUnion(crl_strings, 862 {'LEAF_SERIAL':LEAF_BY_NEW['cert'].get_serial_number()}))) 863 864 865Store( 866 'bad_crldp_has_crlissuer', 867 'Leaf covered by CRLs and not revoked, leaf has crlDistributionPoints ' 868 'with a crlIssuer', 869 LEAF_CRLDP_CRLISSUER, CA, 870 SignAsciiCRL(''' 871 INTEGER { 1 } 872 %(sha256WithRSAEncryption)s 873 %(CA_name)s 874 %(thisUpdate)s 875 %(nextUpdate)s 876 # no revoked certs list 877 # no crlExtensions 878''' % crl_strings)) 879 880 881Store( 882 'bad_fake_critical_extension', 883 'Leaf covered by CRLs and not revoked, but CRL has an unhandled critical ' 884 'extension', 885 LEAF, CA, 886 SignAsciiCRL(''' 887 INTEGER { 1 } 888 %(sha256WithRSAEncryption)s 889 %(CA_name)s 890 %(thisUpdate)s 891 # no nextUpdate 892 # no revoked certs list 893 [0] { 894 SEQUENCE { 895 %(fake_critical_extension)s 896 } 897 } 898''' % crl_strings)) 899 900 901Store( 902 'bad_fake_critical_crlentryextension', 903 'Leaf is revoked, but a later entry has a critical crlEntryExtension', 904 LEAF, CA, 905 SignAsciiCRL(''' 906 INTEGER { 1 } 907 %(sha256WithRSAEncryption)s 908 %(CA_name)s 909 %(thisUpdate)s 910 %(nextUpdate)s 911 %(leaf_revoked_before_fake_critical_extension)s 912 # no crlExtensions 913''' % crl_strings)) 914 915 916Store( 917 'bad_signature', 918 'No revoked certs, but CRL signed by a different key', 919 LEAF, CA, 920 SignAsciiCRL(''' 921 INTEGER { 1 } 922 %(sha256WithRSAEncryption)s 923 %(CA_name)s 924 %(thisUpdate)s 925 %(nextUpdate)s 926 # no revoked certs list 927 # no crlExtensions 928''' % crl_strings, signer=OTHER_CA)) 929 930 931Store( 932 'bad_thisupdate_in_future', 933 'Leaf covered by CRLs and not revoked, but thisUpdate is in the future', 934 LEAF, CA, 935 SignAsciiCRL(''' 936 INTEGER { 1 } 937 %(sha256WithRSAEncryption)s 938 %(CA_name)s 939 %(thisUpdate_in_future)s 940 %(nextUpdate)s 941 # no revoked certs list 942 # no crlExtensions 943''' % crl_strings)) 944 945 946Store( 947 'bad_thisupdate_too_old', 948 'Leaf covered by CRLs and not revoked, but thisUpdate time is more than ' 949 '7 days before verification time', 950 LEAF, CA, 951 SignAsciiCRL(''' 952 INTEGER { 1 } 953 %(sha256WithRSAEncryption)s 954 %(CA_name)s 955 %(thisUpdate_too_old)s 956 %(nextUpdate)s 957 # no revoked certs list 958 # no crlExtensions 959''' % crl_strings)) 960 961 962Store( 963 'bad_nextupdate_too_old', 964 'Leaf covered by CRLs and not revoked, but nextUpdate time is before ' 965 'verification time', 966 LEAF, CA, 967 SignAsciiCRL(''' 968 INTEGER { 1 } 969 %(sha256WithRSAEncryption)s 970 %(CA_name)s 971 %(thisUpdate)s 972 %(nextUpdate_too_old)s 973 # no revoked certs list 974 # no crlExtensions 975''' % crl_strings)) 976 977 978Store( 979 'bad_wrong_issuer', 980 'issuer name in CRL is different', 981 LEAF, CA, 982 SignAsciiCRL(''' 983 INTEGER { 1 } 984 %(sha256WithRSAEncryption)s 985 SEQUENCE { 986 SET { 987 SEQUENCE { 988 # commonName 989 OBJECT_IDENTIFIER { 2.5.4.3 } 990 PrintableString { "Test Unrelated CA" } 991 } 992 } 993 } 994 %(thisUpdate)s 995 %(nextUpdate)s 996 # no revoked certs list 997 # no crlExtensions 998''' % crl_strings)) 999 1000 1001Store( 1002 'bad_key_rollover_signature', 1003 "Leaf issued by CA's new key which is signed by old key, but CRL isn't " 1004 "signed by either", 1005 LEAF_BY_NEW, CA_NEW_BY_OLD, ca2=CA, 1006 crl_der=SignAsciiCRL(''' 1007 INTEGER { 1 } 1008 %(sha256WithRSAEncryption)s 1009 %(CA_name)s 1010 %(thisUpdate)s 1011 %(nextUpdate)s 1012 # no revoked certs list 1013 # no crlExtensions 1014''' % crl_strings, signer=OTHER_CA)) 1015 1016 1017Store( 1018 'bad_idp_contains_wrong_uri', 1019 'Leaf not covered by CRL (IDP with different URI)', 1020 LEAF, CA, 1021 SignAsciiCRL(''' 1022 INTEGER { 1 } 1023 %(sha256WithRSAEncryption)s 1024 %(CA_name)s 1025 %(thisUpdate)s 1026 %(nextUpdate)s 1027 # no revoked certs list 1028 [0] { 1029 SEQUENCE { 1030 %(issuingDistributionPoint_wrong_uri)s 1031 } 1032 } 1033''' % crl_strings)) 1034 1035 1036Store( 1037 'bad_idp_indirectcrl', 1038 'CRL IDP name matches, but has indirectCRL flag set', 1039 LEAF, CA, 1040 SignAsciiCRL(''' 1041 INTEGER { 1 } 1042 %(sha256WithRSAEncryption)s 1043 %(CA_name)s 1044 %(thisUpdate)s 1045 %(nextUpdate)s 1046 # no revoked certs list 1047 [0] { 1048 SEQUENCE { 1049 %(issuingDistributionPoint_with_indirectCRL)s 1050 } 1051 } 1052''' % crl_strings)) 1053 1054 1055Store( 1056 'bad_idp_onlycontainscacerts', 1057 'Leaf not covered by CRLs because IDP has onlyContainsCACerts', 1058 LEAF, CA, 1059 SignAsciiCRL(''' 1060 INTEGER { 1 } 1061 %(sha256WithRSAEncryption)s 1062 %(CA_name)s 1063 %(thisUpdate)s 1064 %(nextUpdate)s 1065 # no revoked certs list 1066 [0] { 1067 SEQUENCE { 1068 %(issuingDistributionPoint_with_onlyContainsCACerts)s 1069 } 1070 } 1071''' % crl_strings)) 1072 1073 1074Store( 1075 'bad_idp_onlycontainscacerts_no_basic_constraints', 1076 'Leaf not covered by CRLs because IDP has onlyContainsCACerts, ' 1077 'leaf has no basicConstraints', 1078 LEAF_NO_BASIC_CONSTRAINTS, CA, 1079 SignAsciiCRL(''' 1080 INTEGER { 1 } 1081 %(sha256WithRSAEncryption)s 1082 %(CA_name)s 1083 %(thisUpdate)s 1084 %(nextUpdate)s 1085 # no revoked certs list 1086 [0] { 1087 SEQUENCE { 1088 %(issuingDistributionPoint_with_onlyContainsCACerts)s 1089 } 1090 } 1091''' % crl_strings)) 1092 1093 1094Store( 1095 'bad_idp_onlycontainsusercerts', 1096 'CA_NEW_BY_OLD not covered by CRLs because IDP has ' 1097 'onlyContainsUserCerts', 1098 CA_NEW_BY_OLD, CA, 1099 SignAsciiCRL(''' 1100 INTEGER { 1 } 1101 %(sha256WithRSAEncryption)s 1102 %(CA_name)s 1103 %(thisUpdate)s 1104 %(nextUpdate)s 1105 # no revoked certs list 1106 [0] { 1107 SEQUENCE { 1108 %(issuingDistributionPoint_with_onlyContainsUserCerts)s 1109 } 1110 } 1111''' % crl_strings)) 1112 1113 1114Store( 1115 'bad_idp_uri_and_onlycontainsusercerts', 1116 'CA_NEW_BY_OLD not covered by CRLs because IDP has ' 1117 'onlyContainsUserCerts (and URI, but the URI matches)', 1118 CA_NEW_BY_OLD, CA, 1119 SignAsciiCRL(''' 1120 INTEGER { 1 } 1121 %(sha256WithRSAEncryption)s 1122 %(CA_name)s 1123 %(thisUpdate)s 1124 %(nextUpdate)s 1125 # no revoked certs list 1126 [0] { 1127 SEQUENCE { 1128 %(issuingDistributionPoint_with_uri_and_onlyContainsUserCerts)s 1129 } 1130 } 1131''' % crl_strings)) 1132 1133 1134Store( 1135 'bad_idp_uri_and_onlycontainscacerts', 1136 'Leaf not covered by CRLs because IDP has ' 1137 'onlyContainsCACerts (and URI, but the URI matches)', 1138 LEAF, CA, 1139 SignAsciiCRL(''' 1140 INTEGER { 1 } 1141 %(sha256WithRSAEncryption)s 1142 %(CA_name)s 1143 %(thisUpdate)s 1144 %(nextUpdate)s 1145 # no revoked certs list 1146 [0] { 1147 SEQUENCE { 1148 %(issuingDistributionPoint_with_uri_and_onlyContainsCACerts)s 1149 } 1150 } 1151''' % crl_strings)) 1152 1153 1154Store( 1155 'invalid_mismatched_signature_algorithm', 1156 'Leaf covered by CRLs and not revoked, but signatureAlgorithm in ' 1157 'CertificateList does not match the one in TBSCertList.', 1158 LEAF, CA, 1159 SignAsciiCRL(''' 1160 INTEGER { 1 } 1161 %(sha384WithRSAEncryption)s 1162 %(CA_name)s 1163 %(thisUpdate)s 1164 %(nextUpdate)s 1165 # no revoked certs list 1166 # no crlExtensions 1167''' % crl_strings)) 1168 1169 1170Store( 1171 'invalid_revoked_empty_sequence', 1172 'revokedCertificates is an empty sequence (should be omitted)', 1173 LEAF, CA, 1174 SignAsciiCRL(''' 1175 INTEGER { 1 } 1176 %(sha256WithRSAEncryption)s 1177 %(CA_name)s 1178 %(thisUpdate)s 1179 %(nextUpdate)s 1180 SEQUENCE { 1181 # no revoked certs. revokedCertificates should be omitted in this case. 1182 } 1183 # no crlExtensions 1184''' % crl_strings)) 1185 1186 1187Store( 1188 'invalid_v1_with_extension', 1189 'CRL is V1 and has crlExtensions', 1190 LEAF, CA, 1191 SignAsciiCRL(''' 1192 # no version 1193 %(sha256WithRSAEncryption)s 1194 %(CA_name)s 1195 %(thisUpdate)s 1196 # no nextUpdate 1197 # no revoked certs list 1198 [0] { 1199 SEQUENCE { 1200 %(fake_extension)s 1201 } 1202 } 1203''' % crl_strings)) 1204 1205 1206Store( 1207 'invalid_v1_with_crlentryextension', 1208 'Leaf is revoked, has non-critical crlEntryExtension, but CRL is V1', 1209 LEAF, CA, 1210 SignAsciiCRL(''' 1211 # no version 1212 %(sha256WithRSAEncryption)s 1213 %(CA_name)s 1214 %(thisUpdate)s 1215 %(nextUpdate)s 1216 %(leaf_revoked_fake_extension)s 1217 # no crlExtensions 1218''' % crl_strings)) 1219 1220 1221Store( 1222 'invalid_v1_explicit', 1223 'CRL has explicit V1 version', 1224 LEAF, CA, 1225 SignAsciiCRL(''' 1226 INTEGER { 0 } 1227 %(sha256WithRSAEncryption)s 1228 %(CA_name)s 1229 %(thisUpdate)s 1230 %(nextUpdate)s 1231 # no revoked certs list 1232 # no crlExtensions 1233''' % crl_strings)) 1234 1235 1236Store( 1237 'invalid_v3', 1238 'CRL has invalid V3 version', 1239 LEAF, CA, 1240 SignAsciiCRL(''' 1241 INTEGER { 2 } 1242 %(sha256WithRSAEncryption)s 1243 %(CA_name)s 1244 %(thisUpdate)s 1245 %(nextUpdate)s 1246 # no revoked certs list 1247 # no crlExtensions 1248''' % crl_strings)) 1249 1250 1251Store( 1252 'invalid_issuer_keyusage_no_crlsign', 1253 'Leaf covered by CRLs and not revoked, issuer has keyUsage extension ' 1254 'without the cRLSign bit set', 1255 LEAF, CA_KEYUSAGE_NOCRLSIGN, 1256 SignAsciiCRL(''' 1257 INTEGER { 1 } 1258 %(sha256WithRSAEncryption)s 1259 %(CA_name)s 1260 %(thisUpdate)s 1261 %(nextUpdate)s 1262 # no revoked certs list 1263 # no crlExtensions 1264''' % crl_strings, signer=CA_KEYUSAGE_NOCRLSIGN)) 1265 1266 1267Store( 1268 'invalid_key_rollover_issuer_keyusage_no_crlsign', 1269 "Leaf issued by CA's new key but CRL is signed by old key, and the old " 1270 "key cert has keyUsage extension without the cRLSign bit set", 1271 LEAF_BY_NEW, CA_NEW_BY_OLD, ca2=CA_KEYUSAGE_NOCRLSIGN, 1272 crl_der=SignAsciiCRL(''' 1273 INTEGER { 1 } 1274 %(sha256WithRSAEncryption)s 1275 %(CA_name)s 1276 %(thisUpdate)s 1277 %(nextUpdate)s 1278 # no revoked certs list 1279 # no crlExtensions 1280''' % crl_strings, signer=CA_KEYUSAGE_NOCRLSIGN)) 1281 1282 1283Store( 1284 'invalid_garbage_version', 1285 'CRL version is garbage', 1286 LEAF, CA, 1287 SignAsciiCRL(''' 1288 OCTET_STRING { `01` } 1289 %(sha256WithRSAEncryption)s 1290 %(CA_name)s 1291 %(thisUpdate)s 1292 %(nextUpdate)s 1293 # no revoked certs list 1294 # no crlExtensions 1295''' % crl_strings)) 1296 1297 1298Store( 1299 'invalid_garbage_tbs_signature_algorithm', 1300 'CRL tbs signature algorithm is garbage', 1301 LEAF, CA, 1302 SignAsciiCRL(''' 1303 INTEGER { 1 } 1304 INTEGER { 1 } 1305 %(CA_name)s 1306 %(thisUpdate)s 1307 %(nextUpdate)s 1308 # no revoked certs list 1309 # no crlExtensions 1310''' % crl_strings)) 1311 1312 1313Store( 1314 'invalid_garbage_issuer_name', 1315 'CRL issuer is garbage', 1316 LEAF, CA, 1317 SignAsciiCRL(''' 1318 INTEGER { 1 } 1319 %(sha256WithRSAEncryption)s 1320 INTEGER { 1 } 1321 %(thisUpdate)s 1322 # no revoked certs list 1323 # no crlExtensions 1324''' % crl_strings)) 1325 1326 1327Store( 1328 'invalid_garbage_thisupdate', 1329 'CRL thisUpdate is garbage', 1330 LEAF, CA, 1331 SignAsciiCRL(''' 1332 INTEGER { 1 } 1333 %(sha256WithRSAEncryption)s 1334 %(CA_name)s 1335 INTEGER { 1 } 1336 %(thisUpdate)s 1337 # no revoked certs list 1338 # no crlExtensions 1339''' % crl_strings)) 1340 1341 1342Store( 1343 'invalid_garbage_after_thisupdate', 1344 'CRL garbage after thisupdate', 1345 LEAF, CA, 1346 SignAsciiCRL(''' 1347 INTEGER { 1 } 1348 %(sha256WithRSAEncryption)s 1349 %(CA_name)s 1350 %(thisUpdate)s 1351 # garbage: 1352 INTEGER { 1 } 1353''' % crl_strings)) 1354 1355 1356Store( 1357 'invalid_garbage_after_nextupdate', 1358 'CRL garbage after nextUpdate', 1359 LEAF, CA, 1360 SignAsciiCRL(''' 1361 INTEGER { 1 } 1362 %(sha256WithRSAEncryption)s 1363 %(CA_name)s 1364 %(thisUpdate)s 1365 %(nextUpdate)s 1366 # garbage: 1367 INTEGER { 1 } 1368''' % crl_strings)) 1369 1370 1371Store( 1372 'invalid_garbage_after_revokedcerts', 1373 'CRL garbage after revokedCertificates', 1374 LEAF, CA, 1375 SignAsciiCRL(''' 1376 INTEGER { 1 } 1377 %(sha256WithRSAEncryption)s 1378 %(CA_name)s 1379 %(thisUpdate)s 1380 # no nextUpdate 1381 %(leaf_revoked)s 1382 # no crlExtensions 1383 # garbage: nextUpdate doesn't go here: 1384 %(nextUpdate)s 1385''' % crl_strings)) 1386 1387 1388Store( 1389 'invalid_garbage_after_extensions', 1390 'CRL garbage after extensions', 1391 LEAF, CA, 1392 SignAsciiCRL(''' 1393 INTEGER { 1 } 1394 %(sha256WithRSAEncryption)s 1395 %(CA_name)s 1396 %(thisUpdate)s 1397 %(nextUpdate)s 1398 # no revoked certs list 1399 [0] { 1400 SEQUENCE { 1401 %(fake_extension)s 1402 } 1403 } 1404 # Garbage: revoked certs sequence doesn't go here: 1405 %(leaf_revoked)s 1406''' % crl_strings)) 1407 1408 1409Store( 1410 'invalid_garbage_tbscertlist', 1411 'CRL garbage tbsCertList', 1412 LEAF, CA, 1413 Ascii2Der(''' 1414SEQUENCE { 1415 OCTET_STRING { `5678` } 1416 SEQUENCE { 1417 # sha256WithRSAEncryption 1418 OBJECT_IDENTIFIER { 1.2.840.113549.1.1.11 } 1419 NULL {} 1420 } 1421 # Actual signatureValue doesn't matter, shouldn't get to verifying signature. 1422 BIT_STRING { `001a` } 1423} 1424''')) 1425 1426 1427Store( 1428 'invalid_garbage_signaturealgorithm', 1429 'CRL garbage signatureAlgorithm', 1430 LEAF, CA, 1431 Ascii2Der(''' 1432SEQUENCE { 1433 SEQUENCE { 1434 INTEGER { 1 } 1435 # tbsCertList contents doesn't matter, parsing shouldn't get this far. 1436 } 1437 OCTET_STRING { `5678` } 1438 # Actual signatureValue doesn't matter, shouldn't get to verifying signature. 1439 BIT_STRING { `001a` } 1440} 1441''')) 1442 1443 1444Store( 1445 'invalid_garbage_signaturevalue', 1446 'CRL garbage signatureValue', 1447 LEAF, CA, 1448 Ascii2Der(''' 1449SEQUENCE { 1450 SEQUENCE { 1451 INTEGER { 1 } 1452 # tbsCertList contents doesn't matter, parsing shouldn't get this far. 1453 } 1454 SEQUENCE { 1455 # sha256WithRSAEncryption 1456 OBJECT_IDENTIFIER { 1.2.840.113549.1.1.11 } 1457 NULL {} 1458 } 1459 # Actual signatureValue contents don't matter, should be BIT_STRING rather 1460 # than OCTET_STRING. 1461 OCTET_STRING { `001a` } 1462} 1463''')) 1464 1465 1466Store( 1467 'invalid_garbage_after_signaturevalue', 1468 'CRL garbage after signatureValue', 1469 LEAF, CA, 1470 Ascii2Der(''' 1471SEQUENCE { 1472 SEQUENCE { 1473 INTEGER { 1 } 1474 # tbsCertList contents doesn't matter, parsing shouldn't get this far. 1475 } 1476 SEQUENCE { 1477 # sha256WithRSAEncryption 1478 OBJECT_IDENTIFIER { 1.2.840.113549.1.1.11 } 1479 NULL {} 1480 } 1481 # Actual signatureValue doesn't matter, shouldn't get to verifying signature. 1482 BIT_STRING { `001a` } 1483 SEQUENCE {} 1484} 1485''')) 1486 1487Store( 1488 'invalid_garbage_revoked_serial_number', 1489 'Leaf is revoked but a following crlentry is garbage', 1490 LEAF, CA, 1491 SignAsciiCRL(''' 1492 INTEGER { 1 } 1493 %(sha256WithRSAEncryption)s 1494 %(CA_name)s 1495 %(thisUpdate)s 1496 %(nextUpdate)s 1497 SEQUENCE { 1498 SEQUENCE { 1499 INTEGER { %(LEAF_SERIAL)i } 1500 UTCTime { "170201001122Z" } 1501 # no crlEntryExtensions 1502 } 1503 SEQUENCE { 1504 OCTET_STRING { `7F`} 1505 UTCTime { "170201001122Z" } 1506 # no crlEntryExtensions 1507 } 1508 } 1509 # no crlExtensions 1510''' % (DictUnion(crl_strings, 1511 {'LEAF_SERIAL':LEAF['cert'].get_serial_number()})))) 1512 1513 1514Store( 1515 'invalid_garbage_revocationdate', 1516 'Leaf is revoked but a following crlentry is garbage', 1517 LEAF, CA, 1518 SignAsciiCRL(''' 1519 INTEGER { 1 } 1520 %(sha256WithRSAEncryption)s 1521 %(CA_name)s 1522 %(thisUpdate)s 1523 %(nextUpdate)s 1524 SEQUENCE { 1525 SEQUENCE { 1526 INTEGER { %(LEAF_SERIAL)i } 1527 UTCTime { "170201001122Z" } 1528 # no crlEntryExtensions 1529 } 1530 SEQUENCE { 1531 INTEGER { 100001 } 1532 OCTET_STRING { "170201001122Z" } 1533 # no crlEntryExtensions 1534 } 1535 } 1536 # no crlExtensions 1537''' % (DictUnion(crl_strings, 1538 {'LEAF_SERIAL':LEAF['cert'].get_serial_number()})))) 1539 1540 1541Store( 1542 'invalid_garbage_after_revocationdate', 1543 'Leaf is revoked but a following crlentry is garbage', 1544 LEAF, CA, 1545 SignAsciiCRL(''' 1546 INTEGER { 1 } 1547 %(sha256WithRSAEncryption)s 1548 %(CA_name)s 1549 %(thisUpdate)s 1550 %(nextUpdate)s 1551 SEQUENCE { 1552 SEQUENCE { 1553 INTEGER { %(LEAF_SERIAL)i } 1554 UTCTime { "170201001122Z" } 1555 # no crlEntryExtensions 1556 } 1557 SEQUENCE { 1558 INTEGER { 100001 } 1559 UTCTime { "170201001122Z" } 1560 INTEGER { 01 } 1561 } 1562 } 1563 # no crlExtensions 1564''' % (DictUnion(crl_strings, 1565 {'LEAF_SERIAL':LEAF['cert'].get_serial_number()})))) 1566 1567 1568Store( 1569 'invalid_garbage_after_crlentryextensions', 1570 'Leaf is revoked but a following crlentry is garbage', 1571 LEAF, CA, 1572 SignAsciiCRL(''' 1573 INTEGER { 1 } 1574 %(sha256WithRSAEncryption)s 1575 %(CA_name)s 1576 %(thisUpdate)s 1577 %(nextUpdate)s 1578 SEQUENCE { 1579 SEQUENCE { 1580 INTEGER { %(LEAF_SERIAL)i } 1581 UTCTime { "170201001122Z" } 1582 # no crlEntryExtensions 1583 } 1584 SEQUENCE { 1585 INTEGER { 100001 } 1586 UTCTime { "170201001122Z" } 1587 SEQUENCE { 1588 SEQUENCE { 1589 OBJECT_IDENTIFIER { 1.2.3.4 } 1590 OCTET_STRING { `5678` } 1591 } 1592 } 1593 INTEGER { 01 } 1594 } 1595 } 1596 # no crlExtensions 1597''' % (DictUnion(crl_strings, 1598 {'LEAF_SERIAL':LEAF['cert'].get_serial_number()})))) 1599 1600 1601Store( 1602 'invalid_garbage_crlentry', 1603 'Leaf is revoked but a following crlentry is garbage', 1604 LEAF, CA, 1605 SignAsciiCRL(''' 1606 INTEGER { 1 } 1607 %(sha256WithRSAEncryption)s 1608 %(CA_name)s 1609 %(thisUpdate)s 1610 %(nextUpdate)s 1611 SEQUENCE { 1612 SEQUENCE { 1613 INTEGER { %(LEAF_SERIAL)i } 1614 UTCTime { "170201001122Z" } 1615 # no crlEntryExtensions 1616 } 1617 INTEGER { 01 } 1618 } 1619 # no crlExtensions 1620''' % (DictUnion(crl_strings, 1621 {'LEAF_SERIAL':LEAF['cert'].get_serial_number()})))) 1622 1623 1624Store( 1625 'invalid_idp_dpname_choice_extra_data', 1626 'IssuingDistributionPoint extension distributionPoint is invalid', 1627 LEAF, CA, 1628 SignAsciiCRL(''' 1629 INTEGER { 1 } 1630 %(sha256WithRSAEncryption)s 1631 %(CA_name)s 1632 %(thisUpdate)s 1633 %(nextUpdate)s 1634 # no revoked certs list 1635 [0] { 1636 SEQUENCE { 1637 SEQUENCE { 1638 OBJECT_IDENTIFIER { 2.5.29.28 } 1639 BOOLEAN { `ff` } 1640 OCTET_STRING { 1641 SEQUENCE { 1642 [0] { 1643 [0] { 1644 [6 PRIMITIVE] { "http://example.com/foo.crl" } 1645 } 1646 [1] { 1647 SET { 1648 SEQUENCE { 1649 # countryName 1650 OBJECT_IDENTIFIER { 2.5.4.6 } 1651 PrintableString { "US" } 1652 } 1653 } 1654 } 1655 } 1656 } 1657 } 1658 } 1659 } 1660 } 1661''' % crl_strings)) 1662 1663 1664Store( 1665 'invalid_idp_empty_sequence', 1666 'IssuingDistributionPoint extension is invalid', 1667 LEAF, CA, 1668 SignAsciiCRL(''' 1669 INTEGER { 1 } 1670 %(sha256WithRSAEncryption)s 1671 %(CA_name)s 1672 %(thisUpdate)s 1673 %(nextUpdate)s 1674 # no revoked certs list 1675 [0] { 1676 SEQUENCE { 1677 SEQUENCE { 1678 OBJECT_IDENTIFIER { 2.5.29.28 } 1679 BOOLEAN { `ff` } 1680 OCTET_STRING { 1681 SEQUENCE { 1682 } 1683 } 1684 } 1685 } 1686 } 1687''' % crl_strings)) 1688 1689 1690Store( 1691 'invalid_idp_onlycontains_user_and_ca_certs', 1692 'IssuingDistributionPoint extension is invalid, cannot specify more than ' 1693 'one of onlyContainsUserCerts and onlyContainsCACerts', 1694 LEAF, CA, 1695 SignAsciiCRL(''' 1696 INTEGER { 1 } 1697 %(sha256WithRSAEncryption)s 1698 %(CA_name)s 1699 %(thisUpdate)s 1700 %(nextUpdate)s 1701 # no revoked certs list 1702 [0] { 1703 SEQUENCE { 1704 SEQUENCE { 1705 OBJECT_IDENTIFIER { 2.5.29.28 } 1706 BOOLEAN { `ff` } 1707 OCTET_STRING { 1708 SEQUENCE { 1709 [1 PRIMITIVE] { `ff` } 1710 [2 PRIMITIVE] { `ff` } 1711 } 1712 } 1713 } 1714 } 1715 } 1716''' % crl_strings)) 1717 1718 1719Store( 1720 'invalid_idp_onlycontainsusercerts_v1_leaf', 1721 'v1 leaf is covered by CRL with onlyContainsUserCerts, which is invalid', 1722 LEAF_V1, CA, 1723 SignAsciiCRL(''' 1724 INTEGER { 1 } 1725 %(sha256WithRSAEncryption)s 1726 %(CA_name)s 1727 %(thisUpdate)s 1728 %(nextUpdate)s 1729 # no revoked certs list 1730 [0] { 1731 SEQUENCE { 1732 %(issuingDistributionPoint_with_onlyContainsUserCerts)s 1733 } 1734 } 1735''' % crl_strings)) 1736