1# coding: utf-8 2from __future__ import unicode_literals, division, absolute_import, print_function 3 4import unittest 5import sys 6import os 7from datetime import datetime 8 9from asn1crypto import x509, core, pem, util 10 11from .unittest_data import data_decorator, data 12from ._unittest_compat import patch 13 14patch() 15 16if sys.version_info < (3,): 17 byte_cls = str 18else: 19 byte_cls = bytes 20 21 22tests_root = os.path.dirname(__file__) 23fixtures_dir = os.path.join(tests_root, 'fixtures') 24 25 26@data_decorator 27class X509Tests(unittest.TestCase): 28 29 def _load_cert(self, relative_path): 30 with open(os.path.join(fixtures_dir, relative_path), 'rb') as f: 31 cert_bytes = f.read() 32 if pem.detect(cert_bytes): 33 _, _, cert_bytes = pem.unarmor(cert_bytes) 34 return x509.Certificate.load(cert_bytes) 35 36 @staticmethod 37 def is_valid_domain_ip_info(): 38 return ( 39 ( 40 'geotrust_certs/codex.crt', 41 'codexns.io', 42 True 43 ), 44 ( 45 'geotrust_certs/codex.crt', 46 'dev.codexns.io', 47 True 48 ), 49 ( 50 'geotrust_certs/codex.crt', 51 'rc.codexns.io', 52 True 53 ), 54 ( 55 'geotrust_certs/codex.crt', 56 'foo.codexns.io', 57 False 58 ), 59 ( 60 'geotrust_certs/codex.crt', 61 '1.2.3.4', 62 False 63 ), 64 ( 65 'geotrust_certs/codex.crt', 66 '1::1', 67 False 68 ), 69 ) 70 71 @data('is_valid_domain_ip_info') 72 def is_valid_domain_ip(self, cert, domain_ip, result): 73 cert = self._load_cert(cert) 74 self.assertEqual(result, cert.is_valid_domain_ip(domain_ip)) 75 76 @staticmethod 77 def ip_address_info(): 78 return ( 79 ( 80 '127.0.0.1', 81 b'\x04\x04\x7F\x00\x00\x01' 82 ), 83 ( 84 '255.255.255.255', 85 b'\x04\x04\xFF\xFF\xFF\xFF' 86 ), 87 ( 88 '127.0.0.1/28', 89 b'\x04\x08\x7F\x00\x00\x01\xFF\xFF\xFF\xF0' 90 ), 91 ( 92 '255.255.255.255/0', 93 b'\x04\x08\xFF\xFF\xFF\xFF\x00\x00\x00\x00' 94 ), 95 ( 96 'af::ed', 97 b'\x04\x10\x00\xAF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xED' 98 ), 99 ( 100 'af::ed/128', 101 b'\x04\x20\x00\xAF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' 102 b'\xED\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF' 103 ), 104 ( 105 'af::ed/0', 106 b'\x04\x20\x00\xAF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' 107 b'\xED\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' 108 ), 109 ) 110 111 @data('ip_address_info') 112 def ip_address(self, unicode_string, der_bytes): 113 self.assertEqual(der_bytes, x509.IPAddress(unicode_string).dump()) 114 self.assertEqual(unicode_string, x509.IPAddress.load(der_bytes).native) 115 116 def test_dnsname(self): 117 e = x509.DNSName('example.com') 118 self.assertEqual('example.com', e.native) 119 self.assertEqual('example.com', e.__unicode__()) 120 self.assertEqual(b'\x16\x0Bexample.com', e.dump()) 121 122 def test_indef_dnsname(self): 123 e = x509.DNSName.load(b'\x36\x80\x16\x04exam\x16\x07ple.com\x00\x00') 124 self.assertEqual('example.com', e.native) 125 self.assertEqual('example.com', e.__unicode__()) 126 self.assertEqual(b'\x16\x0Bexample.com', e.dump(force=True)) 127 128 def test_dnsname_begin_dot(self): 129 self.assertEqual(b'\x16\x03.gr', x509.DNSName('.gr').dump()) 130 131 @staticmethod 132 def compare_dnsname_info(): 133 return ( 134 ( 135 'google.com', 136 'google.com', 137 True 138 ), 139 ( 140 'google.com', 141 'Google.com', 142 True 143 ), 144 ( 145 'Bücher.ch', 146 b'\x16\x10xn--bcher-kva.ch', 147 True 148 ), 149 ( 150 'google.com', 151 b'\x16\x0AGoogle.com', 152 True 153 ), 154 ( 155 'google.com', 156 b'\x16\x09Google.co', 157 False 158 ), 159 ) 160 161 @data('compare_dnsname_info') 162 def compare_dnsname(self, domain_one, domain_two, equal): 163 one = x509.DNSName(domain_one) 164 if isinstance(domain_two, byte_cls): 165 two = x509.DNSName.load(domain_two) 166 else: 167 two = x509.DNSName(domain_two) 168 if equal: 169 self.assertEqual(one, two) 170 else: 171 self.assertNotEqual(one, two) 172 173 def test_uri(self): 174 u = x509.URI('https://example.com') 175 self.assertEqual('https://example.com', u.native) 176 self.assertEqual('https://example.com', u.__unicode__()) 177 self.assertEqual(b'\x16\x13https://example.com', u.dump()) 178 179 def test_uri_no_normalization(self): 180 u = x509.URI('https://example.com/') 181 self.assertEqual('https://example.com/', u.native) 182 self.assertEqual('https://example.com/', u.__unicode__()) 183 self.assertEqual(b'\x16\x14https://example.com/', u.dump()) 184 u2 = x509.URI('https://example.com') 185 self.assertEqual('https://example.com', u2.native) 186 self.assertEqual('https://example.com', u2.__unicode__()) 187 self.assertEqual(b'\x16\x13https://example.com', u2.dump()) 188 u3 = x509.URI('https://example.com:443/') 189 self.assertEqual('https://example.com:443/', u3.native) 190 self.assertEqual('https://example.com:443/', u3.__unicode__()) 191 self.assertEqual(b'\x16\x18https://example.com:443/', u3.dump()) 192 193 def test_indef_uri(self): 194 u = x509.URI.load(b'\x36\x80\x16\x07https:/\x16\x07/exampl\x16\x05e.com\x00\x00') 195 self.assertEqual('https://example.com', u.native) 196 self.assertEqual('https://example.com', u.__unicode__()) 197 self.assertEqual(b'\x16\x13https://example.com', u.dump(force=True)) 198 199 @staticmethod 200 def compare_uri_info(): 201 return ( 202 ( 203 'http://google.com', 204 'http://google.com', 205 True 206 ), 207 ( 208 'http://google.com/', 209 'http://Google.com', 210 True 211 ), 212 ( 213 'http://google.com:80', 214 'http://google.com', 215 True 216 ), 217 ( 218 'https://google.com', 219 'https://google.com:443/', 220 True 221 ), 222 ( 223 'http://google.com/%41%42%43', 224 'http://google.com/ABC', 225 True 226 ), 227 ( 228 'http://google.com/%41%42%43', 229 'http://google.com/abc', 230 False 231 ), 232 ( 233 'http://google.com/%41%42%43/', 234 'http://google.com/ABC%2F', 235 False 236 ), 237 ) 238 239 @data('compare_uri_info') 240 def compare_uri(self, uri_one, uri_two, equal): 241 one = x509.URI(uri_one) 242 if isinstance(uri_two, byte_cls): 243 two = x509.URI.load(uri_two) 244 else: 245 two = x509.URI(uri_two) 246 if equal: 247 self.assertEqual(one, two) 248 else: 249 self.assertNotEqual(one, two) 250 251 def test_email_address(self): 252 e = x509.EmailAddress('john@example.com') 253 self.assertEqual('john@example.com', e.native) 254 self.assertEqual('john@example.com', e.__unicode__()) 255 self.assertEqual(b'\x16\x10john@example.com', e.dump()) 256 257 def test_indef_email_address(self): 258 e = x509.EmailAddress.load(b'\x36\x80\x16\x07john@ex\x16\x09ample.com\x00\x00') 259 self.assertEqual('john@example.com', e.native) 260 self.assertEqual('john@example.com', e.__unicode__()) 261 self.assertEqual(b'\x16\x10john@example.com', e.dump(force=True)) 262 263 @staticmethod 264 def compare_email_address_info(): 265 return ( 266 ( 267 'john@google.com', 268 'john@google.com', 269 True 270 ), 271 ( 272 'john@google.com', 273 'john@Google.com', 274 True 275 ), 276 ( 277 'john@google.com', 278 'John@google.com', 279 False 280 ), 281 ( 282 'john@Bücher.ch', 283 b'\x16\x15john@xn--bcher-kva.ch', 284 True 285 ), 286 ( 287 'John@Bücher.ch', 288 b'\x16\x15john@xn--bcher-kva.ch', 289 False 290 ), 291 ( 292 'john@google.com', 293 b'\x16\x0Fjohn@Google.com', 294 True 295 ), 296 ( 297 'john@google.com', 298 b'\x16\x0FJohn@google.com', 299 False 300 ), 301 ( 302 'john@google.com', 303 b'\x16\x0Ejohn@Google.co', 304 False 305 ), 306 ) 307 308 @data('compare_email_address_info') 309 def compare_email_address(self, email_one, email_two, equal): 310 one = x509.EmailAddress(email_one) 311 if isinstance(email_two, byte_cls): 312 two = x509.EmailAddress.load(email_two) 313 else: 314 two = x509.EmailAddress(email_two) 315 if equal: 316 self.assertEqual(one, two) 317 else: 318 self.assertNotEqual(one, two) 319 320 @staticmethod 321 def compare_ip_address_info(): 322 return ( 323 ( 324 '127.0.0.1', 325 '127.0.0.1', 326 True 327 ), 328 ( 329 '127.0.0.1', 330 '127.0.0.2', 331 False 332 ), 333 ( 334 '127.0.0.1', 335 '127.0.0.1/32', 336 False 337 ), 338 ( 339 '127.0.0.1/32', 340 b'\x04\x08\x7F\x00\x00\x01\xFF\xFF\xFF\xFF', 341 True 342 ), 343 ( 344 '127.0.0.1', 345 b'\x04\x08\x7F\x00\x00\x01\xFF\xFF\xFF\xFF', 346 False 347 ), 348 ) 349 350 @data('compare_ip_address_info') 351 def compare_ip_address(self, email_one, email_two, equal): 352 one = x509.IPAddress(email_one) 353 if isinstance(email_two, byte_cls): 354 two = x509.IPAddress.load(email_two) 355 else: 356 two = x509.IPAddress(email_two) 357 if equal: 358 self.assertEqual(one, two) 359 else: 360 self.assertNotEqual(one, two) 361 362 def test_dump_generalname(self): 363 data = b'0.\x82\x0fsuscerte.gob.ve\xa0\x1b\x06\x05`\x86^\x02\x02\xa0\x12\x0c\x10RIF-G-20004036-0' 364 alt = x509.GeneralNames.load(data) 365 self.assertEqual(data, alt.dump(force=True)) 366 367 @staticmethod 368 def compare_name_info(): 369 return ( 370 ( 371 True, 372 x509.Name.build({ 373 'common_name': 'Will Bond' 374 }), 375 x509.Name.build({ 376 'common_name': 'will bond' 377 }) 378 ), 379 ( 380 True, 381 x509.Name.build({ 382 'common_name': 'Will Bond' 383 }), 384 x509.Name.build({ 385 'common_name': 'will\tbond' 386 }) 387 ), 388 ( 389 True, 390 x509.Name.build({ 391 'common_name': 'Will Bond' 392 }), 393 x509.Name.build({ 394 'common_name': 'Will Bond \U0001D173\U000E007F' 395 }) 396 ), 397 ( 398 True, 399 x509.Name.build({ 400 '2.5.4.3': 'Will Bond', 401 }), 402 x509.Name.build({ 403 'common_name': 'Will Bond', 404 }), 405 ), 406 ( 407 True, 408 x509.Name.build({ 409 '2.5.4.6': 'US', 410 'common_name': 'Will Bond' 411 }), 412 x509.Name.build({ 413 'country_name': 'US', 414 'common_name': 'Will Bond' 415 }) 416 ), 417 ( 418 False, 419 x509.Name.build({ 420 'common_name': 'Will Bond', 421 '0.9.2342.19200300.100.1.1': 'wbond' 422 }), 423 x509.Name.build({ 424 'common_name': 'Will Bond', 425 }), 426 ), 427 ( 428 False, 429 x509.Name.build({ 430 'country_name': 'US', 431 'common_name': 'Will Bond' 432 }), 433 x509.Name.build({ 434 'country_name': 'US', 435 'state_or_province_name': 'Massachusetts', 436 'common_name': 'Will Bond' 437 }) 438 ), 439 ) 440 441 @data('compare_name_info') 442 def compare_name(self, are_equal, general_name_1, general_name_2): 443 if are_equal: 444 self.assertEqual(general_name_1, general_name_2) 445 else: 446 self.assertNotEqual(general_name_1, general_name_2) 447 448 def test_build_name_printable(self): 449 utf8_name = x509.Name.build( 450 { 451 'country_name': 'US', 452 'state_or_province_name': 'Massachusetts', 453 'common_name': 'Will Bond' 454 } 455 ) 456 self.assertIsInstance(utf8_name.chosen[2][0]['value'].chosen, core.UTF8String) 457 self.assertEqual('common_name', utf8_name.chosen[2][0]['type'].native) 458 printable_name = x509.Name.build( 459 { 460 'country_name': 'US', 461 'state_or_province_name': 'Massachusetts', 462 'common_name': 'Will Bond' 463 }, 464 use_printable=True 465 ) 466 self.assertIsInstance(printable_name.chosen[2][0]['value'].chosen, core.PrintableString) 467 self.assertEqual('common_name', printable_name.chosen[2][0]['type'].native) 468 469 def test_v1_cert(self): 470 cert = self._load_cert('chromium/ndn.ca.crt') 471 tbs_cert = cert['tbs_certificate'] 472 self.assertEqual('v1', tbs_cert['version'].native) 473 self.assertEqual(15832340745319036834, tbs_cert['serial_number'].native) 474 self.assertEqual( 475 'Email Address: support@dreamhost.com; Common Name: New Dream Network Certificate Authority; ' 476 'Organizational Unit: Security; Organization: New Dream Network, LLC; Locality: Los Angeles; ' 477 'State/Province: California; Country: US', 478 tbs_cert['issuer'].human_friendly 479 ) 480 self.assertEqual( 481 'Email Address: support@dreamhost.com; Common Name: New Dream Network Certificate Authority; ' 482 'Organizational Unit: Security; Organization: New Dream Network, LLC; Locality: Los Angeles; ' 483 'State/Province: California; Country: US', 484 tbs_cert['subject'].human_friendly 485 ) 486 487 def test_subject_alt_name_variations(self): 488 cert = self._load_cert('chromium/subjectAltName_sanity_check.pem') 489 alt_names = cert.subject_alt_name_value 490 for general_name in alt_names: 491 self.assertIsInstance(general_name, x509.GeneralName) 492 self.assertIsInstance(alt_names[0].chosen, x509.IPAddress) 493 self.assertEqual(alt_names[0].chosen.native, '127.0.0.2') 494 self.assertIsInstance(alt_names[1].chosen, x509.IPAddress) 495 self.assertEqual(alt_names[1].chosen.native, 'fe80::1') 496 self.assertIsInstance(alt_names[2].chosen, x509.DNSName) 497 self.assertEqual(alt_names[2].chosen.native, 'test.example') 498 self.assertIsInstance(alt_names[3].chosen, x509.EmailAddress) 499 self.assertEqual(alt_names[3].chosen.native, 'test@test.example') 500 self.assertIsInstance(alt_names[4].chosen, x509.AnotherName) 501 self.assertEqual(alt_names[4].chosen.native, util.OrderedDict([('type_id', '1.2.3.4'), ('value', 'ignore me')])) 502 self.assertIsInstance(alt_names[5].chosen, x509.Name) 503 self.assertEqual(alt_names[5].chosen.native, util.OrderedDict([('common_name', '127.0.0.3')])) 504 505 def test_sha1_fingerprint(self): 506 cert = self._load_cert('geotrust_certs/codex.crt') 507 self.assertEqual('78 1C 9F 87 59 93 52 08 D2 21 FA 70 6C C5 F9 76 12 C9 6D 8B', cert.sha1_fingerprint) 508 509 def test_sha256_fingerprint(self): 510 cert = self._load_cert('geotrust_certs/codex.crt') 511 self.assertEqual( 512 'E5 6D 97 3A 22 77 55 E4 85 6F 71 78 DA 4D 69 93 0C E2 87 F8 85 5E BE 1A 8C F7 FE 78 80 EB A5 F0', 513 cert.sha256_fingerprint) 514 515 def test_punycode_common_name(self): 516 cert = self._load_cert('chromium/punycodetest.pem') 517 self.assertEqual('xn--wgv71a119e.com', cert['tbs_certificate']['subject'].native['common_name']) 518 519 @staticmethod 520 def signature_algo_info(): 521 return ( 522 ( 523 'keys/test-der.crt', 524 'rsassa_pkcs1v15', 525 'sha256' 526 ), 527 ( 528 'keys/test-inter-der.crt', 529 'rsassa_pkcs1v15', 530 'sha256' 531 ), 532 ( 533 'keys/test-dsa-der.crt', 534 'dsa', 535 'sha256' 536 ), 537 ( 538 'keys/test-third-der.crt', 539 'rsassa_pkcs1v15', 540 'sha256' 541 ), 542 ( 543 'keys/test-ec-der.crt', 544 'ecdsa', 545 'sha256' 546 ), 547 ( 548 'keys/test-rsapss.crt', 549 'rsassa_pss', 550 'sha256' 551 ), 552 ) 553 554 @data('signature_algo_info') 555 def signature_algo(self, relative_path, signature_algo, hash_algo): 556 cert = self._load_cert(relative_path) 557 self.assertEqual(signature_algo, cert['signature_algorithm'].signature_algo) 558 self.assertEqual(hash_algo, cert['signature_algorithm'].hash_algo) 559 560 @staticmethod 561 def critical_extensions_info(): 562 return ( 563 ( 564 'keys/test-der.crt', 565 set() 566 ), 567 ( 568 'keys/test-inter-der.crt', 569 set() 570 ), 571 ( 572 'keys/test-third-der.crt', 573 set() 574 ), 575 ( 576 'geotrust_certs/GeoTrust_Universal_CA.crt', 577 set(['basic_constraints', 'key_usage']) 578 ), 579 ( 580 'geotrust_certs/GeoTrust_Primary_CA.crt', 581 set(['basic_constraints', 'key_usage']) 582 ), 583 ( 584 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 585 set(['basic_constraints', 'key_usage']) 586 ), 587 ( 588 'geotrust_certs/codex.crt', 589 set(['key_usage']) 590 ), 591 ( 592 'lets_encrypt/isrgrootx1.pem', 593 set(['key_usage', 'basic_constraints']) 594 ), 595 ( 596 'lets_encrypt/letsencryptauthorityx1.pem', 597 set(['key_usage', 'basic_constraints']) 598 ), 599 ( 600 'lets_encrypt/letsencryptauthorityx2.pem', 601 set(['key_usage', 'basic_constraints']) 602 ), 603 ( 604 'globalsign_example_keys/IssuingCA-der.cer', 605 set(['basic_constraints', 'key_usage']) 606 ), 607 ( 608 'globalsign_example_keys/rootCA.cer', 609 set(['basic_constraints', 'key_usage']) 610 ), 611 ( 612 'globalsign_example_keys/SSL1.cer', 613 set(['key_usage', 'extended_key_usage', 'basic_constraints']) 614 ), 615 ( 616 'globalsign_example_keys/SSL2.cer', 617 set(['key_usage', 'extended_key_usage', 'basic_constraints']) 618 ), 619 ( 620 'globalsign_example_keys/SSL3.cer', 621 set(['key_usage', 'extended_key_usage', 'basic_constraints']) 622 ), 623 ( 624 'rfc3739.crt', 625 set(['key_usage']) 626 ), 627 ) 628 629 @data('critical_extensions_info') 630 def critical_extensions(self, relative_path, critical_extensions): 631 cert = self._load_cert(relative_path) 632 self.assertEqual(critical_extensions, cert.critical_extensions) 633 634 @staticmethod 635 def subject_directory_attributes_value_info(): 636 return ( 637 ( 638 'keys/test-der.crt', 639 None 640 ), 641 ( 642 'keys/test-inter-der.crt', 643 None 644 ), 645 ( 646 'keys/test-third-der.crt', 647 None 648 ), 649 ( 650 'geotrust_certs/GeoTrust_Universal_CA.crt', 651 None 652 ), 653 ( 654 'geotrust_certs/GeoTrust_Primary_CA.crt', 655 None 656 ), 657 ( 658 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 659 None 660 ), 661 ( 662 'geotrust_certs/codex.crt', 663 None 664 ), 665 ( 666 'lets_encrypt/isrgrootx1.pem', 667 None 668 ), 669 ( 670 'lets_encrypt/letsencryptauthorityx1.pem', 671 None 672 ), 673 ( 674 'lets_encrypt/letsencryptauthorityx2.pem', 675 None 676 ), 677 ( 678 'globalsign_example_keys/IssuingCA-der.cer', 679 None 680 ), 681 ( 682 'globalsign_example_keys/rootCA.cer', 683 None 684 ), 685 ( 686 'globalsign_example_keys/SSL1.cer', 687 None 688 ), 689 ( 690 'globalsign_example_keys/SSL2.cer', 691 None 692 ), 693 ( 694 'globalsign_example_keys/SSL3.cer', 695 None 696 ), 697 ( 698 'rfc3739.crt', 699 [ 700 util.OrderedDict([('type', 'pda_country_of_citizenship'), ('values', ['DE'])]), 701 util.OrderedDict([('type', 'pda_gender'), ('values', ['F'])]), 702 util.OrderedDict([('type', 'pda_date_of_birth'), ('values', [ 703 datetime(1971, 10, 14, 12, 0, tzinfo=util.timezone.utc)])]), 704 util.OrderedDict([('type', 'pda_place_of_birth'), ('values', ['Darmstadt'])]), 705 ] 706 ), 707 ) 708 709 @data('subject_directory_attributes_value_info') 710 def subject_directory_attributes_value(self, relative_path, sda_value): 711 cert = self._load_cert(relative_path) 712 value = cert.subject_directory_attributes_value 713 self.assertEqual(sda_value, value.native if value else None) 714 715 @staticmethod 716 def key_identifier_value_info(): 717 return ( 718 ( 719 'keys/test-der.crt', 720 b'\xbeB\x85=\xcc\xff\xe3\xf9(\x02\x8f~XV\xb4\xfd\x03\\\xeaK' 721 ), 722 ( 723 'keys/test-inter-der.crt', 724 b'\xd2\n\xfd.%\xd1\xb7!\xd7P~\xbb\xa4}\xbf4\xefR^\x02' 725 ), 726 ( 727 'keys/test-third-der.crt', 728 b'D8\xe0\xe0&\x85\xbf\x98\x86\xdc\x1b\xe1\x1d\xf520\xbe\xab\xac\r' 729 ), 730 ( 731 'geotrust_certs/GeoTrust_Universal_CA.crt', 732 b'\xda\xbb.\xaa\xb0\x0c\xb8\x88&Qt\\m\x03\xd3\xc0\xd8\x8fz\xd6' 733 ), 734 ( 735 'geotrust_certs/GeoTrust_Primary_CA.crt', 736 b',\xd5PA\x97\x15\x8b\xf0\x8f6a[J\xfbk\xd9\x99\xc93\x92' 737 ), 738 ( 739 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 740 b'\xde\xcf\\P\xb7\xae\x02\x1f\x15\x17\xaa\x16\xe8\r\xb5(\x9djZ\xf3' 741 ), 742 ( 743 'geotrust_certs/codex.crt', 744 None 745 ), 746 ( 747 'lets_encrypt/isrgrootx1.pem', 748 b'y\xb4Y\xe6{\xb6\xe5\xe4\x01s\x80\x08\x88\xc8\x1aX\xf6\xe9\x9bn' 749 ), 750 ( 751 'lets_encrypt/letsencryptauthorityx1.pem', 752 b'\xa8Jjc\x04}\xdd\xba\xe6\xd19\xb7\xa6Ee\xef\xf3\xa8\xec\xa1' 753 ), 754 ( 755 'lets_encrypt/letsencryptauthorityx2.pem', 756 b'\xc5\xb1\xabNL\xb1\xcdd0\x93~\xc1\x84\x99\x05\xab\xe6\x03\xe2%' 757 ), 758 ( 759 'globalsign_example_keys/IssuingCA-der.cer', 760 b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91" 761 ), 762 ( 763 'globalsign_example_keys/rootCA.cer', 764 b'd|\\\xe1\xe0`8NH\x9f\x05\xbcUc~?\xaeM\xf7\x1e' 765 ), 766 ( 767 'globalsign_example_keys/SSL1.cer', 768 b'\x94a\x04\x92\x04L\xe6\xffh\xa8\x96\xafy\xd2\xf32\x84\xae[\xcf' 769 ), 770 ( 771 'globalsign_example_keys/SSL2.cer', 772 b'\xd2\xb7\x15\x7fd0\x07(p\x83\xca(\xfa\x88\x96\xde\x9e\xfc\x8a=' 773 ), 774 ( 775 'globalsign_example_keys/SSL3.cer', 776 b'G\xde\xa4\xe7\xea`\xe7\xee6\xc8\xf1\xd5\xb0F\x07\x07\x9eBh\xce' 777 ), 778 ( 779 'rfc3739.crt', 780 None 781 ), 782 ) 783 784 @data('key_identifier_value_info') 785 def key_identifier_value(self, relative_path, key_identifier_value): 786 cert = self._load_cert(relative_path) 787 value = cert.key_identifier_value 788 self.assertEqual(key_identifier_value, value.native if value else None) 789 790 @staticmethod 791 def key_usage_value_info(): 792 return ( 793 ( 794 'keys/test-der.crt', 795 None 796 ), 797 ( 798 'keys/test-inter-der.crt', 799 None 800 ), 801 ( 802 'keys/test-third-der.crt', 803 None 804 ), 805 ( 806 'geotrust_certs/GeoTrust_Universal_CA.crt', 807 set(['digital_signature', 'key_cert_sign', 'crl_sign']) 808 ), 809 ( 810 'geotrust_certs/GeoTrust_Primary_CA.crt', 811 set(['key_cert_sign', 'crl_sign']) 812 ), 813 ( 814 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 815 set(['key_cert_sign', 'crl_sign']) 816 ), 817 ( 818 'geotrust_certs/codex.crt', 819 set(['digital_signature', 'key_encipherment']) 820 ), 821 ( 822 'lets_encrypt/isrgrootx1.pem', 823 set(['key_cert_sign', 'crl_sign']) 824 ), 825 ( 826 'lets_encrypt/letsencryptauthorityx1.pem', 827 set(['digital_signature', 'key_cert_sign', 'crl_sign']) 828 ), 829 ( 830 'lets_encrypt/letsencryptauthorityx2.pem', 831 set(['digital_signature', 'key_cert_sign', 'crl_sign']) 832 ), 833 ( 834 'globalsign_example_keys/IssuingCA-der.cer', 835 set(['key_cert_sign', 'crl_sign']) 836 ), 837 ( 838 'globalsign_example_keys/rootCA.cer', 839 set(['key_cert_sign', 'crl_sign']) 840 ), 841 ( 842 'globalsign_example_keys/SSL1.cer', 843 set(['digital_signature', 'key_encipherment']) 844 ), 845 ( 846 'globalsign_example_keys/SSL2.cer', 847 set(['digital_signature', 'key_encipherment']) 848 ), 849 ( 850 'globalsign_example_keys/SSL3.cer', 851 set(['digital_signature', 'key_encipherment']) 852 ), 853 ( 854 'rfc3739.crt', 855 set(['non_repudiation']) 856 ), 857 ) 858 859 @data('key_usage_value_info') 860 def key_usage_value(self, relative_path, key_usage_value): 861 cert = self._load_cert(relative_path) 862 value = cert.key_usage_value 863 self.assertEqual(key_usage_value, value.native if value else None) 864 865 @staticmethod 866 def subject_alt_name_value_info(): 867 return ( 868 ( 869 'keys/test-der.crt', 870 None 871 ), 872 ( 873 'keys/test-inter-der.crt', 874 None 875 ), 876 ( 877 'keys/test-third-der.crt', 878 None 879 ), 880 ( 881 'geotrust_certs/GeoTrust_Universal_CA.crt', 882 None 883 ), 884 ( 885 'geotrust_certs/GeoTrust_Primary_CA.crt', 886 None 887 ), 888 ( 889 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 890 [ 891 util.OrderedDict([ 892 ('common_name', 'SymantecPKI-1-538') 893 ]) 894 ] 895 ), 896 ( 897 'geotrust_certs/codex.crt', 898 ['dev.codexns.io', 'rc.codexns.io', 'packagecontrol.io', 'wbond.net', 'codexns.io'] 899 ), 900 ( 901 'lets_encrypt/isrgrootx1.pem', 902 None 903 ), 904 ( 905 'lets_encrypt/letsencryptauthorityx1.pem', 906 None 907 ), 908 ( 909 'lets_encrypt/letsencryptauthorityx2.pem', 910 None 911 ), 912 ( 913 'globalsign_example_keys/IssuingCA-der.cer', 914 None 915 ), 916 ( 917 'globalsign_example_keys/rootCA.cer', 918 None 919 ), 920 ( 921 'globalsign_example_keys/SSL1.cer', 922 ['anything.example.com'] 923 ), 924 ( 925 'globalsign_example_keys/SSL2.cer', 926 ['anything.example.com'] 927 ), 928 ( 929 'globalsign_example_keys/SSL3.cer', 930 None 931 ), 932 ( 933 'rfc3739.crt', 934 None, 935 ), 936 ) 937 938 @data('subject_alt_name_value_info') 939 def subject_alt_name_value(self, relative_path, subject_alt_name_value): 940 cert = self._load_cert(relative_path) 941 value = cert.subject_alt_name_value 942 self.assertEqual(subject_alt_name_value, value.native if value else None) 943 944 @staticmethod 945 def basic_constraints_value_info(): 946 return ( 947 ( 948 'keys/test-der.crt', 949 {'ca': True, 'path_len_constraint': None} 950 ), 951 ( 952 'keys/test-inter-der.crt', 953 {'ca': True, 'path_len_constraint': None} 954 ), 955 ( 956 'keys/test-third-der.crt', 957 None 958 ), 959 ( 960 'geotrust_certs/GeoTrust_Universal_CA.crt', 961 {'ca': True, 'path_len_constraint': None} 962 ), 963 ( 964 'geotrust_certs/GeoTrust_Primary_CA.crt', 965 {'ca': True, 'path_len_constraint': None} 966 ), 967 ( 968 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 969 {'ca': True, 'path_len_constraint': 0} 970 ), 971 ( 972 'geotrust_certs/codex.crt', 973 {'ca': False, 'path_len_constraint': None} 974 ), 975 ( 976 'lets_encrypt/isrgrootx1.pem', 977 {'ca': True, 'path_len_constraint': None} 978 ), 979 ( 980 'lets_encrypt/letsencryptauthorityx1.pem', 981 {'ca': True, 'path_len_constraint': 0} 982 ), 983 ( 984 'lets_encrypt/letsencryptauthorityx2.pem', 985 {'ca': True, 'path_len_constraint': 0} 986 ), 987 ( 988 'globalsign_example_keys/IssuingCA-der.cer', 989 {'ca': True, 'path_len_constraint': None} 990 ), 991 ( 992 'globalsign_example_keys/rootCA.cer', 993 {'ca': True, 'path_len_constraint': None} 994 ), 995 ( 996 'globalsign_example_keys/SSL1.cer', 997 {'ca': False, 'path_len_constraint': None} 998 ), 999 ( 1000 'globalsign_example_keys/SSL2.cer', 1001 {'ca': False, 'path_len_constraint': None} 1002 ), 1003 ( 1004 'globalsign_example_keys/SSL3.cer', 1005 {'ca': False, 'path_len_constraint': None} 1006 ), 1007 ( 1008 'rfc3739.crt', 1009 None, 1010 ), 1011 ) 1012 1013 @data('basic_constraints_value_info') 1014 def basic_constraints_value(self, relative_path, basic_constraints_value): 1015 cert = self._load_cert(relative_path) 1016 value = cert.basic_constraints_value 1017 self.assertEqual(basic_constraints_value, value.native if value else None) 1018 1019 @staticmethod 1020 def name_constraints_value_info(): 1021 return ( 1022 ( 1023 'keys/test-der.crt', 1024 None 1025 ), 1026 ( 1027 'keys/test-inter-der.crt', 1028 None 1029 ), 1030 ( 1031 'keys/test-third-der.crt', 1032 None 1033 ), 1034 ( 1035 'geotrust_certs/GeoTrust_Universal_CA.crt', 1036 None 1037 ), 1038 ( 1039 'geotrust_certs/GeoTrust_Primary_CA.crt', 1040 None 1041 ), 1042 ( 1043 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 1044 None 1045 ), 1046 ( 1047 'geotrust_certs/codex.crt', 1048 None 1049 ), 1050 ( 1051 'lets_encrypt/isrgrootx1.pem', 1052 None 1053 ), 1054 ( 1055 'lets_encrypt/letsencryptauthorityx1.pem', 1056 None 1057 ), 1058 ( 1059 'lets_encrypt/letsencryptauthorityx2.pem', 1060 None 1061 ), 1062 ( 1063 'globalsign_example_keys/IssuingCA-der.cer', 1064 util.OrderedDict([ 1065 ( 1066 'permitted_subtrees', 1067 [ 1068 util.OrderedDict([ 1069 ('base', 'onlythis.com'), 1070 ('minimum', 0), 1071 ('maximum', None) 1072 ]), 1073 util.OrderedDict([ 1074 ( 1075 'base', 1076 util.OrderedDict([ 1077 ('country_name', 'US'), 1078 ('state_or_province_name', 'MA'), 1079 ('locality_name', 'Boston'), 1080 ('organization_name', 'Example LLC') 1081 ]) 1082 ), 1083 ('minimum', 0), 1084 ('maximum', None) 1085 ]) 1086 ] 1087 ), 1088 ( 1089 'excluded_subtrees', 1090 [ 1091 util.OrderedDict([ 1092 ('base', '0.0.0.0/0'), 1093 ('minimum', 0), 1094 ('maximum', None) 1095 ]), 1096 util.OrderedDict([ 1097 ('base', '::/0'), 1098 ('minimum', 0), 1099 ('maximum', None) 1100 ]) 1101 ] 1102 ), 1103 ]) 1104 ), 1105 ( 1106 'globalsign_example_keys/rootCA.cer', 1107 None 1108 ), 1109 ( 1110 'globalsign_example_keys/SSL1.cer', 1111 None 1112 ), 1113 ( 1114 'globalsign_example_keys/SSL2.cer', 1115 None 1116 ), 1117 ( 1118 'globalsign_example_keys/SSL3.cer', 1119 None 1120 ), 1121 ( 1122 'rfc3739.crt', 1123 None, 1124 ), 1125 ) 1126 1127 @data('name_constraints_value_info') 1128 def name_constraints_value(self, relative_path, name_constraints_value): 1129 cert = self._load_cert(relative_path) 1130 value = cert.name_constraints_value 1131 self.assertEqual(name_constraints_value, value.native if value else None) 1132 1133 @staticmethod 1134 def crl_distribution_points_value_info(): 1135 return ( 1136 ( 1137 'keys/test-der.crt', 1138 None 1139 ), 1140 ( 1141 'keys/test-inter-der.crt', 1142 None 1143 ), 1144 ( 1145 'keys/test-third-der.crt', 1146 None 1147 ), 1148 ( 1149 'geotrust_certs/GeoTrust_Universal_CA.crt', 1150 None 1151 ), 1152 ( 1153 'geotrust_certs/GeoTrust_Primary_CA.crt', 1154 None 1155 ), 1156 ( 1157 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 1158 [ 1159 util.OrderedDict([ 1160 ('distribution_point', ['http://g1.symcb.com/GeoTrustPCA.crl']), 1161 ('reasons', None), 1162 ('crl_issuer', None) 1163 ]) 1164 ] 1165 ), 1166 ( 1167 'geotrust_certs/codex.crt', 1168 [ 1169 util.OrderedDict([ 1170 ('distribution_point', ['http://gm.symcb.com/gm.crl']), 1171 ('reasons', None), 1172 ('crl_issuer', None) 1173 ]) 1174 ] 1175 ), 1176 ( 1177 'lets_encrypt/isrgrootx1.pem', 1178 None 1179 ), 1180 ( 1181 'lets_encrypt/letsencryptauthorityx1.pem', 1182 [ 1183 util.OrderedDict([ 1184 ('distribution_point', ['http://crl.root-x1.letsencrypt.org']), 1185 ('reasons', None), 1186 ('crl_issuer', None) 1187 ]) 1188 ] 1189 ), 1190 ( 1191 'lets_encrypt/letsencryptauthorityx2.pem', 1192 [ 1193 util.OrderedDict([ 1194 ('distribution_point', ['http://crl.root-x1.letsencrypt.org']), 1195 ('reasons', None), 1196 ('crl_issuer', None) 1197 ]) 1198 ] 1199 ), 1200 ( 1201 'globalsign_example_keys/IssuingCA-der.cer', 1202 [ 1203 util.OrderedDict([ 1204 ('distribution_point', ['http://crl.globalsign.com/gs/trustrootcatg2.crl']), 1205 ('reasons', None), 1206 ('crl_issuer', None) 1207 ]) 1208 ]), 1209 ( 1210 'globalsign_example_keys/rootCA.cer', 1211 [ 1212 util.OrderedDict([ 1213 ('distribution_point', ['http://crl.globalsign.com/gs/trustrootcatg2.crl']), 1214 ('reasons', None), 1215 ('crl_issuer', None) 1216 ]) 1217 ]), 1218 ( 1219 'globalsign_example_keys/SSL1.cer', 1220 None 1221 ), 1222 ( 1223 'globalsign_example_keys/SSL2.cer', 1224 None 1225 ), 1226 ( 1227 'globalsign_example_keys/SSL3.cer', 1228 None 1229 ), 1230 ( 1231 'rfc3739.crt', 1232 None, 1233 ), 1234 ) 1235 1236 @data('crl_distribution_points_value_info') 1237 def crl_distribution_points_value(self, relative_path, crl_distribution_points_value): 1238 cert = self._load_cert(relative_path) 1239 value = cert.crl_distribution_points_value 1240 self.assertEqual(crl_distribution_points_value, value.native if value else None) 1241 1242 @staticmethod 1243 def certificate_policies_value_info(): 1244 return ( 1245 ( 1246 'keys/test-der.crt', 1247 None 1248 ), 1249 ( 1250 'keys/test-inter-der.crt', 1251 None 1252 ), 1253 ( 1254 'keys/test-third-der.crt', 1255 None 1256 ), 1257 ( 1258 'geotrust_certs/GeoTrust_Universal_CA.crt', 1259 None 1260 ), 1261 ( 1262 'geotrust_certs/GeoTrust_Primary_CA.crt', 1263 None 1264 ), 1265 ( 1266 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 1267 [ 1268 util.OrderedDict([ 1269 ('policy_identifier', 'any_policy'), 1270 ( 1271 'policy_qualifiers', 1272 [ 1273 util.OrderedDict([ 1274 ('policy_qualifier_id', 'certification_practice_statement'), 1275 ('qualifier', 'https://www.geotrust.com/resources/cps') 1276 ]) 1277 ] 1278 ) 1279 ]) 1280 ] 1281 ), 1282 ( 1283 'geotrust_certs/codex.crt', 1284 [ 1285 util.OrderedDict([ 1286 ('policy_identifier', '1.3.6.1.4.1.14370.1.6'), 1287 ( 1288 'policy_qualifiers', 1289 [ 1290 util.OrderedDict([ 1291 ('policy_qualifier_id', 'certification_practice_statement'), 1292 ('qualifier', 'https://www.geotrust.com/resources/repository/legal') 1293 ]), 1294 util.OrderedDict([ 1295 ('policy_qualifier_id', 'user_notice'), 1296 ( 1297 'qualifier', 1298 util.OrderedDict([ 1299 ('notice_ref', None), 1300 ('explicit_text', 'https://www.geotrust.com/resources/repository/legal') 1301 ]) 1302 ) 1303 ]) 1304 ] 1305 ) 1306 ]) 1307 ] 1308 ), 1309 ( 1310 'lets_encrypt/isrgrootx1.pem', 1311 None 1312 ), 1313 ( 1314 'lets_encrypt/letsencryptauthorityx1.pem', 1315 [ 1316 util.OrderedDict([ 1317 ('policy_identifier', '2.23.140.1.2.1'), 1318 ('policy_qualifiers', None) 1319 ]), 1320 util.OrderedDict([ 1321 ('policy_identifier', '1.3.6.1.4.1.44947.1.1.1'), 1322 ( 1323 'policy_qualifiers', 1324 [ 1325 util.OrderedDict([ 1326 ('policy_qualifier_id', 'certification_practice_statement'), 1327 ('qualifier', 'http://cps.root-x1.letsencrypt.org') 1328 ]) 1329 ] 1330 ) 1331 ]) 1332 ] 1333 ), 1334 ( 1335 'lets_encrypt/letsencryptauthorityx2.pem', 1336 [ 1337 util.OrderedDict([ 1338 ('policy_identifier', '2.23.140.1.2.1'), 1339 ('policy_qualifiers', None) 1340 ]), 1341 util.OrderedDict([ 1342 ('policy_identifier', '1.3.6.1.4.1.44947.1.1.1'), 1343 ( 1344 'policy_qualifiers', 1345 [ 1346 util.OrderedDict([ 1347 ('policy_qualifier_id', 'certification_practice_statement'), 1348 ('qualifier', 'http://cps.root-x1.letsencrypt.org') 1349 ]) 1350 ] 1351 ) 1352 ]) 1353 ] 1354 ), 1355 ( 1356 'globalsign_example_keys/IssuingCA-der.cer', 1357 [ 1358 util.OrderedDict([ 1359 ('policy_identifier', '1.3.6.1.4.1.4146.1.60'), 1360 ( 1361 'policy_qualifiers', 1362 [ 1363 util.OrderedDict([ 1364 ('policy_qualifier_id', 'certification_practice_statement'), 1365 ('qualifier', 'https://www.globalsign.com/repository/') 1366 ]) 1367 ] 1368 ) 1369 ]) 1370 ] 1371 ), 1372 ( 1373 'globalsign_example_keys/rootCA.cer', 1374 None 1375 ), 1376 ( 1377 'globalsign_example_keys/SSL1.cer', 1378 [ 1379 util.OrderedDict([ 1380 ('policy_identifier', '1.3.6.1.4.1.4146.1.60'), 1381 ( 1382 'policy_qualifiers', 1383 [ 1384 util.OrderedDict([ 1385 ('policy_qualifier_id', 'certification_practice_statement'), 1386 ('qualifier', 'https://www.globalsign.com/repository/') 1387 ]) 1388 ] 1389 ) 1390 ]) 1391 ] 1392 ), 1393 ( 1394 'globalsign_example_keys/SSL2.cer', 1395 [ 1396 util.OrderedDict([ 1397 ('policy_identifier', '1.3.6.1.4.1.4146.1.60'), 1398 ( 1399 'policy_qualifiers', 1400 [ 1401 util.OrderedDict([ 1402 ('policy_qualifier_id', 'certification_practice_statement'), 1403 ('qualifier', 'https://www.globalsign.com/repository/') 1404 ]) 1405 ] 1406 ) 1407 ]) 1408 ] 1409 ), 1410 ( 1411 'globalsign_example_keys/SSL3.cer', 1412 [ 1413 util.OrderedDict([ 1414 ('policy_identifier', '1.3.6.1.4.1.4146.1.60'), 1415 ( 1416 'policy_qualifiers', 1417 [ 1418 util.OrderedDict([ 1419 ('policy_qualifier_id', 'certification_practice_statement'), 1420 ('qualifier', 'https://www.globalsign.com/repository/') 1421 ]) 1422 ] 1423 ) 1424 ]) 1425 ] 1426 ), 1427 ( 1428 'rfc3739.crt', 1429 [ 1430 util.OrderedDict([ 1431 ('policy_identifier', '1.3.36.8.1.1'), 1432 ('policy_qualifiers', None) 1433 ]), 1434 ] 1435 ), 1436 ) 1437 1438 @data('certificate_policies_value_info') 1439 def certificate_policies_value(self, relative_path, certificate_policies_value): 1440 cert = self._load_cert(relative_path) 1441 value = cert.certificate_policies_value 1442 self.assertEqual(certificate_policies_value, value.native if value else None) 1443 1444 @staticmethod 1445 def policy_mappings_value_info(): 1446 return ( 1447 ( 1448 'keys/test-der.crt', 1449 None 1450 ), 1451 ( 1452 'keys/test-inter-der.crt', 1453 None 1454 ), 1455 ( 1456 'keys/test-third-der.crt', 1457 None 1458 ), 1459 ( 1460 'geotrust_certs/GeoTrust_Universal_CA.crt', 1461 None 1462 ), 1463 ( 1464 'geotrust_certs/GeoTrust_Primary_CA.crt', 1465 None 1466 ), 1467 ( 1468 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 1469 None 1470 ), 1471 ( 1472 'geotrust_certs/codex.crt', 1473 None 1474 ), 1475 ( 1476 'lets_encrypt/isrgrootx1.pem', 1477 None 1478 ), 1479 ( 1480 'lets_encrypt/letsencryptauthorityx1.pem', 1481 None 1482 ), 1483 ( 1484 'lets_encrypt/letsencryptauthorityx2.pem', 1485 None 1486 ), 1487 ( 1488 'globalsign_example_keys/IssuingCA-der.cer', 1489 None 1490 ), 1491 ( 1492 'globalsign_example_keys/rootCA.cer', 1493 None 1494 ), 1495 ( 1496 'globalsign_example_keys/SSL1.cer', 1497 None 1498 ), 1499 ( 1500 'globalsign_example_keys/SSL2.cer', 1501 None 1502 ), 1503 ( 1504 'globalsign_example_keys/SSL3.cer', 1505 None 1506 ), 1507 ( 1508 'rfc3739.crt', 1509 None, 1510 ), 1511 ) 1512 1513 @data('policy_mappings_value_info') 1514 def policy_mappings_value(self, relative_path, policy_mappings_value): 1515 cert = self._load_cert(relative_path) 1516 value = cert.policy_mappings_value 1517 self.assertEqual(policy_mappings_value, value.native if value else None) 1518 1519 @staticmethod 1520 def authority_key_identifier_value_info(): 1521 return ( 1522 ( 1523 'keys/test-der.crt', 1524 util.OrderedDict([ 1525 ('key_identifier', b'\xbeB\x85=\xcc\xff\xe3\xf9(\x02\x8f~XV\xb4\xfd\x03\\\xeaK'), 1526 ( 1527 'authority_cert_issuer', 1528 [ 1529 util.OrderedDict([ 1530 ('country_name', 'US'), 1531 ('state_or_province_name', 'Massachusetts'), 1532 ('locality_name', 'Newbury'), 1533 ('organization_name', 'Codex Non Sufficit LC'), 1534 ('organizational_unit_name', 'Testing'), 1535 ('common_name', 'Will Bond'), 1536 ('email_address', 'will@codexns.io') 1537 ]) 1538 ] 1539 ), 1540 ('authority_cert_serial_number', 13683582341504654466) 1541 ]) 1542 ), 1543 ( 1544 'keys/test-inter-der.crt', 1545 util.OrderedDict([ 1546 ('key_identifier', b'\xbeB\x85=\xcc\xff\xe3\xf9(\x02\x8f~XV\xb4\xfd\x03\\\xeaK'), 1547 ('authority_cert_issuer', None), 1548 ('authority_cert_serial_number', None) 1549 ]) 1550 ), 1551 ( 1552 'keys/test-third-der.crt', 1553 util.OrderedDict([ 1554 ('key_identifier', b'\xd2\n\xfd.%\xd1\xb7!\xd7P~\xbb\xa4}\xbf4\xefR^\x02'), 1555 ('authority_cert_issuer', None), 1556 ('authority_cert_serial_number', None) 1557 ]) 1558 ), 1559 ( 1560 'geotrust_certs/GeoTrust_Universal_CA.crt', 1561 util.OrderedDict([ 1562 ('key_identifier', b'\xda\xbb.\xaa\xb0\x0c\xb8\x88&Qt\\m\x03\xd3\xc0\xd8\x8fz\xd6'), 1563 ('authority_cert_issuer', None), 1564 ('authority_cert_serial_number', None) 1565 ]) 1566 ), 1567 ( 1568 'geotrust_certs/GeoTrust_Primary_CA.crt', 1569 None 1570 ), 1571 ( 1572 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 1573 util.OrderedDict([ 1574 ('key_identifier', b',\xd5PA\x97\x15\x8b\xf0\x8f6a[J\xfbk\xd9\x99\xc93\x92'), 1575 ('authority_cert_issuer', None), 1576 ('authority_cert_serial_number', None) 1577 ]) 1578 ), 1579 ( 1580 'geotrust_certs/codex.crt', 1581 util.OrderedDict([ 1582 ('key_identifier', b'\xde\xcf\\P\xb7\xae\x02\x1f\x15\x17\xaa\x16\xe8\r\xb5(\x9djZ\xf3'), 1583 ('authority_cert_issuer', None), 1584 ('authority_cert_serial_number', None) 1585 ]) 1586 ), 1587 ( 1588 'lets_encrypt/isrgrootx1.pem', 1589 None 1590 ), 1591 ( 1592 'lets_encrypt/letsencryptauthorityx1.pem', 1593 util.OrderedDict([ 1594 ('key_identifier', b'y\xb4Y\xe6{\xb6\xe5\xe4\x01s\x80\x08\x88\xc8\x1aX\xf6\xe9\x9bn'), 1595 ('authority_cert_issuer', None), 1596 ('authority_cert_serial_number', None) 1597 ]) 1598 ), 1599 ( 1600 'lets_encrypt/letsencryptauthorityx2.pem', 1601 util.OrderedDict([ 1602 ('key_identifier', b'y\xb4Y\xe6{\xb6\xe5\xe4\x01s\x80\x08\x88\xc8\x1aX\xf6\xe9\x9bn'), 1603 ('authority_cert_issuer', None), 1604 ('authority_cert_serial_number', None) 1605 ]) 1606 ), 1607 ( 1608 'globalsign_example_keys/IssuingCA-der.cer', 1609 util.OrderedDict([ 1610 ('key_identifier', b'd|\\\xe1\xe0`8NH\x9f\x05\xbcUc~?\xaeM\xf7\x1e'), 1611 ('authority_cert_issuer', None), 1612 ('authority_cert_serial_number', None) 1613 ]) 1614 ), 1615 ( 1616 'globalsign_example_keys/rootCA.cer', 1617 None 1618 ), 1619 ( 1620 'globalsign_example_keys/SSL1.cer', 1621 util.OrderedDict([ 1622 ('key_identifier', b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91"), 1623 ('authority_cert_issuer', None), 1624 ('authority_cert_serial_number', None) 1625 ]) 1626 ), 1627 ( 1628 'globalsign_example_keys/SSL2.cer', 1629 util.OrderedDict([ 1630 ('key_identifier', b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91"), 1631 ('authority_cert_issuer', None), 1632 ('authority_cert_serial_number', None) 1633 ]) 1634 ), 1635 ( 1636 'globalsign_example_keys/SSL3.cer', 1637 util.OrderedDict([ 1638 ('key_identifier', b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91"), 1639 ('authority_cert_issuer', None), 1640 ('authority_cert_serial_number', None) 1641 ]) 1642 ), 1643 ( 1644 'rfc3739.crt', 1645 util.OrderedDict([ 1646 ('key_identifier', b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\xfe\xdc\xba\x98"), 1647 ('authority_cert_issuer', None), 1648 ('authority_cert_serial_number', None) 1649 ]) 1650 ), 1651 ) 1652 1653 @data('authority_key_identifier_value_info') 1654 def authority_key_identifier_value(self, relative_path, authority_key_identifier_value): 1655 cert = self._load_cert(relative_path) 1656 value = cert.authority_key_identifier_value 1657 self.assertEqual(authority_key_identifier_value, value.native if value else None) 1658 1659 @staticmethod 1660 def policy_constraints_value_info(): 1661 return ( 1662 ( 1663 'keys/test-der.crt', 1664 None 1665 ), 1666 ( 1667 'keys/test-inter-der.crt', 1668 None 1669 ), 1670 ( 1671 'keys/test-third-der.crt', 1672 None 1673 ), 1674 ( 1675 'geotrust_certs/GeoTrust_Universal_CA.crt', 1676 None 1677 ), 1678 ( 1679 'geotrust_certs/GeoTrust_Primary_CA.crt', 1680 None 1681 ), 1682 ( 1683 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 1684 None 1685 ), 1686 ( 1687 'geotrust_certs/codex.crt', 1688 None 1689 ), 1690 ( 1691 'lets_encrypt/isrgrootx1.pem', 1692 None 1693 ), 1694 ( 1695 'lets_encrypt/letsencryptauthorityx1.pem', 1696 None 1697 ), 1698 ( 1699 'lets_encrypt/letsencryptauthorityx2.pem', 1700 None 1701 ), 1702 ( 1703 'globalsign_example_keys/IssuingCA-der.cer', 1704 None 1705 ), 1706 ( 1707 'globalsign_example_keys/rootCA.cer', 1708 None 1709 ), 1710 ( 1711 'globalsign_example_keys/SSL1.cer', 1712 None 1713 ), 1714 ( 1715 'globalsign_example_keys/SSL2.cer', 1716 None 1717 ), 1718 ( 1719 'globalsign_example_keys/SSL3.cer', 1720 None 1721 ), 1722 ( 1723 'rfc3739.crt', 1724 None, 1725 ), 1726 ) 1727 1728 @data('policy_constraints_value_info') 1729 def policy_constraints_value(self, relative_path, policy_constraints_value): 1730 cert = self._load_cert(relative_path) 1731 value = cert.policy_constraints_value 1732 self.assertEqual(policy_constraints_value, value.native if value else None) 1733 1734 @staticmethod 1735 def extended_key_usage_value_info(): 1736 return ( 1737 ( 1738 'keys/test-der.crt', 1739 None 1740 ), 1741 ( 1742 'keys/test-inter-der.crt', 1743 None 1744 ), 1745 ( 1746 'keys/test-third-der.crt', 1747 None 1748 ), 1749 ( 1750 'geotrust_certs/GeoTrust_Universal_CA.crt', 1751 None 1752 ), 1753 ( 1754 'geotrust_certs/GeoTrust_Primary_CA.crt', 1755 None 1756 ), 1757 ( 1758 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 1759 None 1760 ), 1761 ( 1762 'geotrust_certs/codex.crt', 1763 ['server_auth', 'client_auth']), 1764 ( 1765 'lets_encrypt/isrgrootx1.pem', 1766 None 1767 ), 1768 ( 1769 'lets_encrypt/letsencryptauthorityx1.pem', 1770 None 1771 ), 1772 ( 1773 'lets_encrypt/letsencryptauthorityx2.pem', 1774 None 1775 ), 1776 ( 1777 'globalsign_example_keys/IssuingCA-der.cer', 1778 None 1779 ), 1780 ( 1781 'globalsign_example_keys/rootCA.cer', 1782 None 1783 ), 1784 ( 1785 'globalsign_example_keys/SSL1.cer', 1786 ['server_auth', 'client_auth'] 1787 ), 1788 ( 1789 'globalsign_example_keys/SSL2.cer', 1790 ['server_auth', 'client_auth'] 1791 ), 1792 ( 1793 'globalsign_example_keys/SSL3.cer', 1794 ['server_auth', 'client_auth'] 1795 ), 1796 ( 1797 'rfc3739.crt', 1798 None, 1799 ), 1800 ) 1801 1802 @data('extended_key_usage_value_info') 1803 def extended_key_usage_value(self, relative_path, extended_key_usage_value): 1804 cert = self._load_cert(relative_path) 1805 value = cert.extended_key_usage_value 1806 self.assertEqual(extended_key_usage_value, value.native if value else None) 1807 1808 @staticmethod 1809 def authority_information_access_value_info(): 1810 return ( 1811 ( 1812 'keys/test-der.crt', 1813 None 1814 ), 1815 ( 1816 'keys/test-inter-der.crt', 1817 None 1818 ), 1819 ( 1820 'keys/test-third-der.crt', 1821 None 1822 ), 1823 ( 1824 'geotrust_certs/GeoTrust_Universal_CA.crt', 1825 None 1826 ), 1827 ( 1828 'geotrust_certs/GeoTrust_Primary_CA.crt', 1829 None 1830 ), 1831 ( 1832 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 1833 [ 1834 util.OrderedDict([ 1835 ('access_method', 'ocsp'), 1836 ('access_location', 'http://g2.symcb.com') 1837 ]) 1838 ] 1839 ), 1840 ( 1841 'geotrust_certs/codex.crt', 1842 [ 1843 util.OrderedDict([ 1844 ('access_method', 'ocsp'), 1845 ('access_location', 'http://gm.symcd.com') 1846 ]), 1847 util.OrderedDict([ 1848 ('access_method', 'ca_issuers'), 1849 ('access_location', 'http://gm.symcb.com/gm.crt') 1850 ]), 1851 ] 1852 ), 1853 ( 1854 'lets_encrypt/isrgrootx1.pem', 1855 None 1856 ), 1857 ( 1858 'lets_encrypt/letsencryptauthorityx1.pem', 1859 [ 1860 util.OrderedDict([ 1861 ('access_method', 'ocsp'), 1862 ('access_location', 'http://ocsp.root-x1.letsencrypt.org/') 1863 ]), 1864 util.OrderedDict([ 1865 ('access_method', 'ca_issuers'), 1866 ('access_location', 'http://cert.root-x1.letsencrypt.org/') 1867 ]) 1868 ] 1869 ), 1870 ( 1871 'lets_encrypt/letsencryptauthorityx2.pem', 1872 [ 1873 util.OrderedDict([ 1874 ('access_method', 'ocsp'), 1875 ('access_location', 'http://ocsp.root-x1.letsencrypt.org/') 1876 ]), 1877 util.OrderedDict([ 1878 ('access_method', 'ca_issuers'), 1879 ('access_location', 'http://cert.root-x1.letsencrypt.org/') 1880 ]) 1881 ] 1882 ), 1883 ( 1884 'globalsign_example_keys/IssuingCA-der.cer', 1885 None 1886 ), 1887 ( 1888 'globalsign_example_keys/rootCA.cer', 1889 None 1890 ), 1891 ( 1892 'globalsign_example_keys/SSL1.cer', 1893 [ 1894 util.OrderedDict([ 1895 ('access_method', 'ocsp'), 1896 ('access_location', 'http://ocsp.exampleovca.com/') 1897 ]), 1898 util.OrderedDict([ 1899 ('access_method', 'ca_issuers'), 1900 ('access_location', 'http://secure.globalsign.com/cacert/trustrootcatg2.crt') 1901 ]) 1902 ] 1903 ), 1904 ( 1905 'globalsign_example_keys/SSL2.cer', 1906 [ 1907 util.OrderedDict([ 1908 ('access_method', 'ocsp'), 1909 ('access_location', 'http://ocsp.exampleovca.com/') 1910 ]), 1911 util.OrderedDict([ 1912 ('access_method', 'ca_issuers'), 1913 ('access_location', 'http://secure.globalsign.com/cacert/trustrootcatg2.crt') 1914 ]) 1915 ] 1916 ), 1917 ( 1918 'globalsign_example_keys/SSL3.cer', 1919 [ 1920 util.OrderedDict([ 1921 ('access_method', 'ocsp'), 1922 ('access_location', 'http://ocsp.exampleovca.com/') 1923 ]), 1924 util.OrderedDict([ 1925 ('access_method', 'ca_issuers'), 1926 ('access_location', 'http://secure.globalsign.com/cacert/trustrootcatg2.crt') 1927 ]) 1928 ] 1929 ), 1930 ( 1931 'rfc3739.crt', 1932 None, 1933 ), 1934 ) 1935 1936 @data('authority_information_access_value_info') 1937 def authority_information_access_value(self, relative_path, authority_information_access_value): 1938 cert = self._load_cert(relative_path) 1939 value = cert.authority_information_access_value 1940 self.assertEqual(authority_information_access_value, value.native if value else None) 1941 1942 @staticmethod 1943 def ocsp_no_check_value_info(): 1944 return ( 1945 ( 1946 'keys/test-der.crt', 1947 None 1948 ), 1949 ( 1950 'keys/test-inter-der.crt', 1951 None 1952 ), 1953 ( 1954 'keys/test-third-der.crt', 1955 None 1956 ), 1957 ( 1958 'geotrust_certs/GeoTrust_Universal_CA.crt', 1959 None 1960 ), 1961 ( 1962 'geotrust_certs/GeoTrust_Primary_CA.crt', 1963 None 1964 ), 1965 ( 1966 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 1967 None 1968 ), 1969 ( 1970 'geotrust_certs/codex.crt', 1971 None 1972 ), 1973 ( 1974 'lets_encrypt/isrgrootx1.pem', 1975 None 1976 ), 1977 ( 1978 'lets_encrypt/letsencryptauthorityx1.pem', 1979 None 1980 ), 1981 ( 1982 'lets_encrypt/letsencryptauthorityx2.pem', 1983 None 1984 ), 1985 ( 1986 'globalsign_example_keys/IssuingCA-der.cer', 1987 None 1988 ), 1989 ( 1990 'globalsign_example_keys/rootCA.cer', 1991 None 1992 ), 1993 ( 1994 'globalsign_example_keys/SSL1.cer', 1995 None 1996 ), 1997 ( 1998 'globalsign_example_keys/SSL2.cer', 1999 None 2000 ), 2001 ( 2002 'globalsign_example_keys/SSL3.cer', 2003 None 2004 ), 2005 ( 2006 'rfc3739.crt', 2007 None, 2008 ), 2009 ) 2010 2011 @data('ocsp_no_check_value_info') 2012 def ocsp_no_check_value(self, relative_path, ocsp_no_check_value): 2013 cert = self._load_cert(relative_path) 2014 value = cert.ocsp_no_check_value 2015 self.assertEqual(ocsp_no_check_value, value.native if value else None) 2016 2017 @staticmethod 2018 def private_key_usage_period_value_info(): 2019 return ( 2020 ( 2021 'ocsp-with-pkup.pem', 2022 b'\x80\x0f20170918151736Z\x81\x0f20180101041421Z' 2023 ), 2024 ) 2025 2026 @data('private_key_usage_period_value_info') 2027 def private_key_usage_period_value(self, relative_path, private_key_usage_period_value): 2028 cert = self._load_cert(relative_path) 2029 self.assertEqual(private_key_usage_period_value, cert.private_key_usage_period_value.contents) 2030 2031 @staticmethod 2032 def serial_number_info(): 2033 return ( 2034 ( 2035 'keys/test-der.crt', 2036 13683582341504654466 2037 ), 2038 ( 2039 'keys/test-inter-der.crt', 2040 1590137 2041 ), 2042 ( 2043 'keys/test-third-der.crt', 2044 2474902313 2045 ), 2046 ( 2047 'geotrust_certs/GeoTrust_Universal_CA.crt', 2048 1 2049 ), 2050 ( 2051 'geotrust_certs/GeoTrust_Primary_CA.crt', 2052 32798226551256963324313806436981982369 2053 ), 2054 ( 2055 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 2056 146934555852773531829332059263122711876 2057 ), 2058 ( 2059 'geotrust_certs/codex.crt', 2060 130338219198307073574879940486642352162 2061 ), 2062 ( 2063 'lets_encrypt/isrgrootx1.pem', 2064 172886928669790476064670243504169061120 2065 ), 2066 ( 2067 'lets_encrypt/letsencryptauthorityx1.pem', 2068 307817870430047279283060309415759825539 2069 ), 2070 ( 2071 'lets_encrypt/letsencryptauthorityx2.pem', 2072 199666138109676817050168330923544141416 2073 ), 2074 ( 2075 'globalsign_example_keys/IssuingCA-der.cer', 2076 43543335419752 2077 ), 2078 ( 2079 'globalsign_example_keys/rootCA.cer', 2080 342514332211132 2081 ), 2082 ( 2083 'globalsign_example_keys/SSL1.cer', 2084 425155524522 2085 ), 2086 ( 2087 'globalsign_example_keys/SSL2.cer', 2088 425155524522 2089 ), 2090 ( 2091 'globalsign_example_keys/SSL3.cer', 2092 425155524522 2093 ), 2094 ( 2095 'rfc3739.crt', 2096 1234567890, 2097 ), 2098 ) 2099 2100 @data('serial_number_info') 2101 def serial_number(self, relative_path, serial_number): 2102 cert = self._load_cert(relative_path) 2103 self.assertEqual(serial_number, cert.serial_number) 2104 2105 @staticmethod 2106 def key_identifier_info(): 2107 return ( 2108 ( 2109 'keys/test-der.crt', 2110 b'\xbeB\x85=\xcc\xff\xe3\xf9(\x02\x8f~XV\xb4\xfd\x03\\\xeaK' 2111 ), 2112 ( 2113 'keys/test-inter-der.crt', 2114 b'\xd2\n\xfd.%\xd1\xb7!\xd7P~\xbb\xa4}\xbf4\xefR^\x02' 2115 ), 2116 ( 2117 'keys/test-third-der.crt', 2118 b'D8\xe0\xe0&\x85\xbf\x98\x86\xdc\x1b\xe1\x1d\xf520\xbe\xab\xac\r' 2119 ), 2120 ( 2121 'geotrust_certs/GeoTrust_Universal_CA.crt', 2122 b'\xda\xbb.\xaa\xb0\x0c\xb8\x88&Qt\\m\x03\xd3\xc0\xd8\x8fz\xd6' 2123 ), 2124 ( 2125 'geotrust_certs/GeoTrust_Primary_CA.crt', 2126 b',\xd5PA\x97\x15\x8b\xf0\x8f6a[J\xfbk\xd9\x99\xc93\x92' 2127 ), 2128 ( 2129 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 2130 b'\xde\xcf\\P\xb7\xae\x02\x1f\x15\x17\xaa\x16\xe8\r\xb5(\x9djZ\xf3' 2131 ), 2132 ( 2133 'geotrust_certs/codex.crt', 2134 None 2135 ), 2136 ( 2137 'lets_encrypt/isrgrootx1.pem', 2138 b'y\xb4Y\xe6{\xb6\xe5\xe4\x01s\x80\x08\x88\xc8\x1aX\xf6\xe9\x9bn' 2139 ), 2140 ( 2141 'lets_encrypt/letsencryptauthorityx1.pem', 2142 b'\xa8Jjc\x04}\xdd\xba\xe6\xd19\xb7\xa6Ee\xef\xf3\xa8\xec\xa1' 2143 ), 2144 ( 2145 'lets_encrypt/letsencryptauthorityx2.pem', 2146 b'\xc5\xb1\xabNL\xb1\xcdd0\x93~\xc1\x84\x99\x05\xab\xe6\x03\xe2%' 2147 ), 2148 ( 2149 'globalsign_example_keys/IssuingCA-der.cer', 2150 b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91" 2151 ), 2152 ( 2153 'globalsign_example_keys/rootCA.cer', 2154 b'd|\\\xe1\xe0`8NH\x9f\x05\xbcUc~?\xaeM\xf7\x1e' 2155 ), 2156 ( 2157 'globalsign_example_keys/SSL1.cer', 2158 b'\x94a\x04\x92\x04L\xe6\xffh\xa8\x96\xafy\xd2\xf32\x84\xae[\xcf' 2159 ), 2160 ( 2161 'globalsign_example_keys/SSL2.cer', 2162 b'\xd2\xb7\x15\x7fd0\x07(p\x83\xca(\xfa\x88\x96\xde\x9e\xfc\x8a=' 2163 ), 2164 ( 2165 'globalsign_example_keys/SSL3.cer', 2166 b'G\xde\xa4\xe7\xea`\xe7\xee6\xc8\xf1\xd5\xb0F\x07\x07\x9eBh\xce' 2167 ), 2168 ( 2169 'rfc3739.crt', 2170 None, 2171 ), 2172 ) 2173 2174 @data('key_identifier_info') 2175 def key_identifier(self, relative_path, key_identifier): 2176 cert = self._load_cert(relative_path) 2177 self.assertEqual(key_identifier, cert.key_identifier) 2178 2179 @staticmethod 2180 def issuer_serial_info(): 2181 return ( 2182 ( 2183 'keys/test-der.crt', 2184 b'\xdd\x8a\x19x\xae`\x19=\xa7\xf8\x00\xb9\xfbx\xf8\xedu\xb8!\xf8\x8c' 2185 b'\xdb\x1f\x99\'7w\x93\xb4\xa4\'\xa0:13683582341504654466' 2186 ), 2187 ( 2188 'keys/test-inter-der.crt', 2189 b'\xdd\x8a\x19x\xae`\x19=\xa7\xf8\x00\xb9\xfbx\xf8\xedu\xb8!\xf8\x8c' 2190 b'\xdb\x1f\x99\'7w\x93\xb4\xa4\'\xa0:1590137' 2191 ), 2192 ( 2193 'keys/test-third-der.crt', 2194 b'\xed{\x9b\xbf\x9b\xdbd\xa4\xea\xf2#+H\x96\xcd\x80\x99\xf6\xecCM\x94' 2195 b'\x07\x02\xe2\x18\xf3\x83\x8c8%\x01:2474902313' 2196 ), 2197 ( 2198 'geotrust_certs/GeoTrust_Universal_CA.crt', 2199 b'\xa1\x848\xf2\xe5w\xee\xec\xce\xfefJC+\xdf\x97\x7f\xd2Y\xe3\xdc\xa0D7~\x07\xd9\x9dzL@g:1' 2200 ), 2201 ( 2202 'geotrust_certs/GeoTrust_Primary_CA.crt', 2203 b'\xdcg\x0c\x80\x03\xb3D\xa0v\xe2\xee\xec\x8b\xd6\x82\x01\xf0\x13\x0cwT' 2204 b'\xb4\x8f\x80\x0eT\x9d\xbf\xbf\xa4\x11\x80:32798226551256963324313806436981982369' 2205 ), 2206 ( 2207 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 2208 b'\xdcg\x0c\x80\x03\xb3D\xa0v\xe2\xee\xec\x8b\xd6\x82\x01\xf0\x13\x0cwT' 2209 b'\xb4\x8f\x80\x0eT\x9d\xbf\xbf\xa4\x11\x80:146934555852773531829332059263122711876' 2210 ), 2211 ( 2212 'geotrust_certs/codex.crt', 2213 b'x\x12\xe0\x15\x00d;\xc3\xb9/\xf6\x13\n\xd8\xe2\xddY\xf7\xaf*=C\x01<\x86\xf5\x9f' 2214 b'_\xab;e\xd1:130338219198307073574879940486642352162' 2215 ), 2216 ( 2217 'lets_encrypt/isrgrootx1.pem', 2218 b'\xf6\xdb/\xbd\x9d\xd8]\x92Y\xdd\xb3\xc6\xde}{/\xec?>\x0c\xef\x17a\xbc\xbf3 W\x1e' 2219 b'-0\xf8:172886928669790476064670243504169061120' 2220 ), 2221 ( 2222 'lets_encrypt/letsencryptauthorityx1.pem', 2223 b'\xf6\xdb/\xbd\x9d\xd8]\x92Y\xdd\xb3\xc6\xde}{/\xec?>\x0c\xef\x17a\xbc\xbf3 W\x1e-' 2224 b'0\xf8:307817870430047279283060309415759825539' 2225 ), 2226 ( 2227 'lets_encrypt/letsencryptauthorityx2.pem', 2228 b'\xf6\xdb/\xbd\x9d\xd8]\x92Y\xdd\xb3\xc6\xde}{/\xec?>\x0c\xef\x17a\xbc\xbf3 W\x1e-' 2229 b'0\xf8:199666138109676817050168330923544141416' 2230 ), 2231 ( 2232 'globalsign_example_keys/IssuingCA-der.cer', 2233 b'\xd2\xe7\xca\x10\xc1\x91\x92Y^A\x11\xd3Rz\xd5\x93\x19wk\x11\xef\xaa\x9c\xad\x10' 2234 b'\x8ak\x8a\x08-\x0c\xff:43543335419752' 2235 ), 2236 ( 2237 'globalsign_example_keys/rootCA.cer', 2238 b'\xd2\xe7\xca\x10\xc1\x91\x92Y^A\x11\xd3Rz\xd5\x93\x19wk\x11\xef\xaa\x9c\xad\x10' 2239 b'\x8ak\x8a\x08-\x0c\xff:342514332211132' 2240 ), 2241 ( 2242 'globalsign_example_keys/SSL1.cer', 2243 b'_\xc0S\xb1\xeb}\xe3\x8e\xe4{\xdb\xd7\xe2\xd9}=3\x97|\x0c\x1e\xecz\xcc\x92u\x1f' 2244 b'\xf0\x1d\xbc\x9f\xe4:425155524522' 2245 ), 2246 ( 2247 'globalsign_example_keys/SSL2.cer', 2248 b'_\xc0S\xb1\xeb}\xe3\x8e\xe4{\xdb\xd7\xe2\xd9}=3\x97|\x0c\x1e\xecz\xcc\x92u\x1f' 2249 b'\xf0\x1d\xbc\x9f\xe4:425155524522' 2250 ), 2251 ( 2252 'globalsign_example_keys/SSL3.cer', 2253 b'_\xc0S\xb1\xeb}\xe3\x8e\xe4{\xdb\xd7\xe2\xd9}=3\x97|\x0c\x1e\xecz\xcc\x92u\x1f' 2254 b'\xf0\x1d\xbc\x9f\xe4:425155524522' 2255 ), 2256 ( 2257 'rfc3739.crt', 2258 b"@\xde\x1b\xdb\xdc3a\x89:'D\xaf.G' \xb4<\xb3R8\xca;y\x8e\xfb\xef\x14\xbcE\x05F" 2259 b":1234567890" 2260 ), 2261 ) 2262 2263 @data('issuer_serial_info') 2264 def issuer_serial(self, relative_path, issuer_serial): 2265 cert = self._load_cert(relative_path) 2266 self.assertEqual(issuer_serial, cert.issuer_serial) 2267 2268 @staticmethod 2269 def authority_key_identifier_info(): 2270 return ( 2271 ( 2272 'keys/test-der.crt', 2273 b'\xbeB\x85=\xcc\xff\xe3\xf9(\x02\x8f~XV\xb4\xfd\x03\\\xeaK' 2274 ), 2275 ( 2276 'keys/test-inter-der.crt', 2277 b'\xbeB\x85=\xcc\xff\xe3\xf9(\x02\x8f~XV\xb4\xfd\x03\\\xeaK' 2278 ), 2279 ( 2280 'keys/test-third-der.crt', 2281 b'\xd2\n\xfd.%\xd1\xb7!\xd7P~\xbb\xa4}\xbf4\xefR^\x02' 2282 ), 2283 ( 2284 'geotrust_certs/GeoTrust_Universal_CA.crt', 2285 b'\xda\xbb.\xaa\xb0\x0c\xb8\x88&Qt\\m\x03\xd3\xc0\xd8\x8fz\xd6' 2286 ), 2287 ( 2288 'geotrust_certs/GeoTrust_Primary_CA.crt', 2289 None 2290 ), 2291 ( 2292 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 2293 b',\xd5PA\x97\x15\x8b\xf0\x8f6a[J\xfbk\xd9\x99\xc93\x92' 2294 ), 2295 ( 2296 'geotrust_certs/codex.crt', 2297 b'\xde\xcf\\P\xb7\xae\x02\x1f\x15\x17\xaa\x16\xe8\r\xb5(\x9djZ\xf3' 2298 ), 2299 ( 2300 'lets_encrypt/isrgrootx1.pem', 2301 None 2302 ), 2303 ( 2304 'lets_encrypt/letsencryptauthorityx1.pem', 2305 b'y\xb4Y\xe6{\xb6\xe5\xe4\x01s\x80\x08\x88\xc8\x1aX\xf6\xe9\x9bn' 2306 ), 2307 ( 2308 'lets_encrypt/letsencryptauthorityx2.pem', 2309 b'y\xb4Y\xe6{\xb6\xe5\xe4\x01s\x80\x08\x88\xc8\x1aX\xf6\xe9\x9bn' 2310 ), 2311 ( 2312 'globalsign_example_keys/IssuingCA-der.cer', 2313 b'd|\\\xe1\xe0`8NH\x9f\x05\xbcUc~?\xaeM\xf7\x1e' 2314 ), 2315 ( 2316 'globalsign_example_keys/rootCA.cer', 2317 None 2318 ), 2319 ( 2320 'globalsign_example_keys/SSL1.cer', 2321 b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91" 2322 ), 2323 ( 2324 'globalsign_example_keys/SSL2.cer', 2325 b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91" 2326 ), 2327 ( 2328 'globalsign_example_keys/SSL3.cer', 2329 b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91" 2330 ), 2331 ( 2332 'rfc3739.crt', 2333 b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\xfe\xdc\xba\x98" 2334 ), 2335 ) 2336 2337 @data('authority_key_identifier_info') 2338 def authority_key_identifier(self, relative_path, authority_key_identifier): 2339 cert = self._load_cert(relative_path) 2340 self.assertEqual(authority_key_identifier, cert.authority_key_identifier) 2341 2342 @staticmethod 2343 def authority_issuer_serial_info(): 2344 return ( 2345 ( 2346 'keys/test-der.crt', 2347 b'\xdd\x8a\x19x\xae`\x19=\xa7\xf8\x00\xb9\xfbx\xf8\xedu\xb8!\xf8\x8c' 2348 b'\xdb\x1f\x99\'7w\x93\xb4\xa4\'\xa0:13683582341504654466' 2349 ), 2350 ( 2351 'keys/test-inter-der.crt', 2352 None 2353 ), 2354 ( 2355 'keys/test-third-der.crt', 2356 None 2357 ), 2358 ( 2359 'geotrust_certs/GeoTrust_Universal_CA.crt', 2360 None 2361 ), 2362 ( 2363 'geotrust_certs/GeoTrust_Primary_CA.crt', 2364 None 2365 ), 2366 ( 2367 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 2368 None 2369 ), 2370 ( 2371 'geotrust_certs/codex.crt', 2372 None 2373 ), 2374 ( 2375 'lets_encrypt/isrgrootx1.pem', 2376 None 2377 ), 2378 ( 2379 'lets_encrypt/letsencryptauthorityx1.pem', 2380 None 2381 ), 2382 ( 2383 'lets_encrypt/letsencryptauthorityx2.pem', 2384 None 2385 ), 2386 ( 2387 'globalsign_example_keys/IssuingCA-der.cer', 2388 None 2389 ), 2390 ( 2391 'globalsign_example_keys/rootCA.cer', 2392 None 2393 ), 2394 ( 2395 'globalsign_example_keys/SSL1.cer', 2396 None 2397 ), 2398 ( 2399 'globalsign_example_keys/SSL2.cer', 2400 None 2401 ), 2402 ( 2403 'globalsign_example_keys/SSL3.cer', 2404 None 2405 ), 2406 ( 2407 'rfc3739.crt', 2408 None 2409 ), 2410 ) 2411 2412 @data('authority_issuer_serial_info') 2413 def authority_issuer_serial(self, relative_path, authority_issuer_serial): 2414 cert = self._load_cert(relative_path) 2415 self.assertEqual(authority_issuer_serial, cert.authority_issuer_serial) 2416 2417 @staticmethod 2418 def ocsp_urls_info(): 2419 return ( 2420 ( 2421 'keys/test-der.crt', 2422 [] 2423 ), 2424 ( 2425 'keys/test-inter-der.crt', 2426 [] 2427 ), 2428 ( 2429 'keys/test-third-der.crt', 2430 [] 2431 ), 2432 ( 2433 'geotrust_certs/GeoTrust_Universal_CA.crt', 2434 [] 2435 ), 2436 ( 2437 'geotrust_certs/GeoTrust_Primary_CA.crt', 2438 [] 2439 ), 2440 ( 2441 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 2442 ['http://g2.symcb.com'] 2443 ), 2444 ( 2445 'geotrust_certs/codex.crt', 2446 ['http://gm.symcd.com'] 2447 ), 2448 ( 2449 'lets_encrypt/isrgrootx1.pem', 2450 [] 2451 ), 2452 ( 2453 'lets_encrypt/letsencryptauthorityx1.pem', 2454 ['http://ocsp.root-x1.letsencrypt.org/'] 2455 ), 2456 ( 2457 'lets_encrypt/letsencryptauthorityx2.pem', 2458 ['http://ocsp.root-x1.letsencrypt.org/'] 2459 ), 2460 ( 2461 'globalsign_example_keys/IssuingCA-der.cer', 2462 [] 2463 ), 2464 ( 2465 'globalsign_example_keys/rootCA.cer', 2466 [] 2467 ), 2468 ( 2469 'globalsign_example_keys/SSL1.cer', 2470 ['http://ocsp.exampleovca.com/'] 2471 ), 2472 ( 2473 'globalsign_example_keys/SSL2.cer', 2474 ['http://ocsp.exampleovca.com/'] 2475 ), 2476 ( 2477 'globalsign_example_keys/SSL3.cer', 2478 ['http://ocsp.exampleovca.com/'] 2479 ), 2480 ( 2481 'rfc3739.crt', 2482 [] 2483 ), 2484 ) 2485 2486 @data('ocsp_urls_info') 2487 def ocsp_urls(self, relative_path, ocsp_url): 2488 cert = self._load_cert(relative_path) 2489 self.assertEqual(ocsp_url, cert.ocsp_urls) 2490 2491 @staticmethod 2492 def crl_distribution_points_info(): 2493 return ( 2494 ( 2495 'keys/test-der.crt', 2496 [] 2497 ), 2498 ( 2499 'keys/test-inter-der.crt', 2500 [] 2501 ), 2502 ( 2503 'keys/test-third-der.crt', 2504 [] 2505 ), 2506 ( 2507 'geotrust_certs/GeoTrust_Universal_CA.crt', 2508 [] 2509 ), 2510 ( 2511 'geotrust_certs/GeoTrust_Primary_CA.crt', 2512 [] 2513 ), 2514 ( 2515 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 2516 [ 2517 util.OrderedDict([ 2518 ('distribution_point', ['http://g1.symcb.com/GeoTrustPCA.crl']), 2519 ('reasons', None), 2520 ('crl_issuer', None) 2521 ]) 2522 ] 2523 ), 2524 ( 2525 'geotrust_certs/codex.crt', 2526 [ 2527 util.OrderedDict([ 2528 ('distribution_point', ['http://gm.symcb.com/gm.crl']), 2529 ('reasons', None), 2530 ('crl_issuer', None) 2531 ]) 2532 ] 2533 ), 2534 ( 2535 'lets_encrypt/isrgrootx1.pem', 2536 [] 2537 ), 2538 ( 2539 'lets_encrypt/letsencryptauthorityx1.pem', 2540 [ 2541 util.OrderedDict([ 2542 ('distribution_point', ['http://crl.root-x1.letsencrypt.org']), 2543 ('reasons', None), 2544 ('crl_issuer', None) 2545 ]) 2546 ] 2547 ), 2548 ( 2549 'lets_encrypt/letsencryptauthorityx2.pem', 2550 [ 2551 util.OrderedDict([ 2552 ('distribution_point', ['http://crl.root-x1.letsencrypt.org']), 2553 ('reasons', None), 2554 ('crl_issuer', None) 2555 ]) 2556 ] 2557 ), 2558 ( 2559 'globalsign_example_keys/IssuingCA-der.cer', 2560 [ 2561 util.OrderedDict([ 2562 ('distribution_point', ['http://crl.globalsign.com/gs/trustrootcatg2.crl']), 2563 ('reasons', None), 2564 ('crl_issuer', None) 2565 ]) 2566 ] 2567 ), 2568 ( 2569 'globalsign_example_keys/rootCA.cer', 2570 [ 2571 util.OrderedDict([ 2572 ('distribution_point', ['http://crl.globalsign.com/gs/trustrootcatg2.crl']), 2573 ('reasons', None), 2574 ('crl_issuer', None) 2575 ]) 2576 ] 2577 ), 2578 ( 2579 'globalsign_example_keys/SSL1.cer', 2580 [] 2581 ), 2582 ( 2583 'globalsign_example_keys/SSL2.cer', 2584 [] 2585 ), 2586 ( 2587 'globalsign_example_keys/SSL3.cer', 2588 [] 2589 ), 2590 ( 2591 'rfc3739.crt', 2592 [] 2593 ), 2594 ) 2595 2596 @data('crl_distribution_points_info') 2597 def crl_distribution_points(self, relative_path, crl_distribution_point): 2598 cert = self._load_cert(relative_path) 2599 points = [point.native for point in cert.crl_distribution_points] 2600 self.assertEqual(crl_distribution_point, points) 2601 2602 @staticmethod 2603 def valid_domains_info(): 2604 return ( 2605 ( 2606 'keys/test-der.crt', 2607 [] 2608 ), 2609 ( 2610 'keys/test-inter-der.crt', 2611 [] 2612 ), 2613 ( 2614 'keys/test-third-der.crt', 2615 [] 2616 ), 2617 ( 2618 'geotrust_certs/GeoTrust_Universal_CA.crt', 2619 [] 2620 ), 2621 ( 2622 'geotrust_certs/GeoTrust_Primary_CA.crt', 2623 [] 2624 ), 2625 ( 2626 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 2627 [] 2628 ), 2629 ( 2630 'geotrust_certs/codex.crt', 2631 ['dev.codexns.io', 'rc.codexns.io', 'packagecontrol.io', 'wbond.net', 'codexns.io'] 2632 ), 2633 ( 2634 'lets_encrypt/isrgrootx1.pem', 2635 [] 2636 ), 2637 ( 2638 'lets_encrypt/letsencryptauthorityx1.pem', 2639 [] 2640 ), 2641 ( 2642 'lets_encrypt/letsencryptauthorityx2.pem', 2643 [] 2644 ), 2645 ( 2646 'globalsign_example_keys/IssuingCA-der.cer', 2647 [] 2648 ), 2649 ( 2650 'globalsign_example_keys/rootCA.cer', 2651 [] 2652 ), 2653 ( 2654 'globalsign_example_keys/SSL1.cer', 2655 ['anything.example.com'] 2656 ), 2657 ( 2658 'globalsign_example_keys/SSL2.cer', 2659 ['anything.example.com'] 2660 ), 2661 ( 2662 'globalsign_example_keys/SSL3.cer', 2663 ['*.google.com'] 2664 ), 2665 ( 2666 'rfc3739.crt', 2667 [] 2668 ), 2669 ) 2670 2671 @data('valid_domains_info') 2672 def valid_domains(self, relative_path, valid_domains): 2673 cert = self._load_cert(relative_path) 2674 self.assertEqual(valid_domains, cert.valid_domains) 2675 2676 @staticmethod 2677 def valid_ips_info(): 2678 return ( 2679 ( 2680 'keys/test-der.crt', 2681 [] 2682 ), 2683 ( 2684 'keys/test-inter-der.crt', 2685 [] 2686 ), 2687 ( 2688 'keys/test-third-der.crt', 2689 [] 2690 ), 2691 ( 2692 'geotrust_certs/GeoTrust_Universal_CA.crt', 2693 [] 2694 ), 2695 ( 2696 'geotrust_certs/GeoTrust_Primary_CA.crt', 2697 [] 2698 ), 2699 ( 2700 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 2701 [] 2702 ), 2703 ( 2704 'geotrust_certs/codex.crt', 2705 [] 2706 ), 2707 ( 2708 'lets_encrypt/isrgrootx1.pem', 2709 [] 2710 ), 2711 ( 2712 'lets_encrypt/letsencryptauthorityx1.pem', 2713 [] 2714 ), 2715 ( 2716 'lets_encrypt/letsencryptauthorityx2.pem', 2717 [] 2718 ), 2719 ( 2720 'globalsign_example_keys/IssuingCA-der.cer', 2721 [] 2722 ), 2723 ( 2724 'globalsign_example_keys/rootCA.cer', 2725 [] 2726 ), 2727 ( 2728 'globalsign_example_keys/SSL1.cer', 2729 [] 2730 ), 2731 ( 2732 'globalsign_example_keys/SSL2.cer', 2733 [] 2734 ), 2735 ( 2736 'globalsign_example_keys/SSL3.cer', 2737 [] 2738 ), 2739 ( 2740 'rfc3739.crt', 2741 [] 2742 ), 2743 ) 2744 2745 @data('valid_ips_info') 2746 def valid_ips(self, relative_path, crl_url): 2747 cert = self._load_cert(relative_path) 2748 self.assertEqual(crl_url, cert.valid_ips) 2749 2750 @staticmethod 2751 def self_issued_info(): 2752 return ( 2753 ( 2754 'keys/test-der.crt', 2755 True 2756 ), 2757 ( 2758 'keys/test-inter-der.crt', 2759 False 2760 ), 2761 ( 2762 'keys/test-third-der.crt', 2763 False 2764 ), 2765 ( 2766 'geotrust_certs/GeoTrust_Universal_CA.crt', 2767 True 2768 ), 2769 ( 2770 'geotrust_certs/GeoTrust_Primary_CA.crt', 2771 True 2772 ), 2773 ( 2774 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 2775 False 2776 ), 2777 ( 2778 'geotrust_certs/codex.crt', 2779 False 2780 ), 2781 ( 2782 'lets_encrypt/isrgrootx1.pem', 2783 True 2784 ), 2785 ( 2786 'lets_encrypt/letsencryptauthorityx1.pem', 2787 False 2788 ), 2789 ( 2790 'lets_encrypt/letsencryptauthorityx2.pem', 2791 False 2792 ), 2793 ( 2794 'globalsign_example_keys/IssuingCA-der.cer', 2795 False 2796 ), 2797 ( 2798 'globalsign_example_keys/rootCA.cer', 2799 True 2800 ), 2801 ( 2802 'globalsign_example_keys/SSL1.cer', 2803 False 2804 ), 2805 ( 2806 'globalsign_example_keys/SSL2.cer', 2807 False 2808 ), 2809 ( 2810 'globalsign_example_keys/SSL3.cer', 2811 False 2812 ), 2813 ( 2814 'rfc3739.crt', 2815 False 2816 ), 2817 ) 2818 2819 @data('self_issued_info') 2820 def self_issued(self, relative_path, self_issued): 2821 cert = self._load_cert(relative_path) 2822 self.assertEqual(self_issued, cert.self_issued) 2823 2824 @staticmethod 2825 def self_signed_info(): 2826 return ( 2827 ( 2828 'keys/test-der.crt', 2829 'maybe' 2830 ), 2831 ( 2832 'keys/test-inter-der.crt', 2833 'no' 2834 ), 2835 ( 2836 'keys/test-third-der.crt', 2837 'no' 2838 ), 2839 ( 2840 'geotrust_certs/GeoTrust_Universal_CA.crt', 2841 'maybe' 2842 ), 2843 ( 2844 'geotrust_certs/GeoTrust_Primary_CA.crt', 2845 'maybe' 2846 ), 2847 ( 2848 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 2849 'no' 2850 ), 2851 ( 2852 'geotrust_certs/codex.crt', 2853 'no' 2854 ), 2855 ( 2856 'lets_encrypt/isrgrootx1.pem', 2857 'maybe' 2858 ), 2859 ( 2860 'lets_encrypt/letsencryptauthorityx1.pem', 2861 'no' 2862 ), 2863 ( 2864 'lets_encrypt/letsencryptauthorityx2.pem', 2865 'no' 2866 ), 2867 ( 2868 'globalsign_example_keys/IssuingCA-der.cer', 2869 'no' 2870 ), 2871 ( 2872 'globalsign_example_keys/rootCA.cer', 2873 'maybe' 2874 ), 2875 ( 2876 'globalsign_example_keys/SSL1.cer', 2877 'no' 2878 ), 2879 ( 2880 'globalsign_example_keys/SSL2.cer', 2881 'no' 2882 ), 2883 ( 2884 'globalsign_example_keys/SSL3.cer', 2885 'no' 2886 ), 2887 ( 2888 'rfc3739.crt', 2889 'no' 2890 ), 2891 ) 2892 2893 @data('self_signed_info') 2894 def self_signed(self, relative_path, self_signed): 2895 cert = self._load_cert(relative_path) 2896 self.assertEqual(self_signed, cert.self_signed) 2897 2898 @staticmethod 2899 def cert_list(): 2900 return ( 2901 ( 2902 'keys/test-der.crt', 2903 ), 2904 ( 2905 'keys/test-inter-der.crt', 2906 ), 2907 ( 2908 'keys/test-third-der.crt', 2909 ), 2910 ( 2911 'geotrust_certs/GeoTrust_Universal_CA.crt', 2912 ), 2913 ( 2914 'geotrust_certs/GeoTrust_Primary_CA.crt', 2915 ), 2916 ( 2917 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 2918 ), 2919 ( 2920 'geotrust_certs/codex.crt', 2921 ), 2922 ( 2923 'lets_encrypt/isrgrootx1.pem', 2924 ), 2925 ( 2926 'lets_encrypt/letsencryptauthorityx1.pem', 2927 ), 2928 ( 2929 'lets_encrypt/letsencryptauthorityx2.pem', 2930 ), 2931 ( 2932 'globalsign_example_keys/IssuingCA-der.cer', 2933 ), 2934 ( 2935 'globalsign_example_keys/rootCA.cer', 2936 ), 2937 ( 2938 'globalsign_example_keys/SSL1.cer', 2939 ), 2940 ( 2941 'globalsign_example_keys/SSL2.cer', 2942 ), 2943 ( 2944 'globalsign_example_keys/SSL3.cer', 2945 ), 2946 ) 2947 2948 @data('cert_list') 2949 def name_is_rdn_squence_of_single_child_sets(self, relative_path): 2950 cert = self._load_cert(relative_path) 2951 for child in cert.subject.chosen: 2952 self.assertEqual(1, len(child)) 2953 2954 def test_parse_certificate(self): 2955 cert = self._load_cert('keys/test-der.crt') 2956 2957 tbs_certificate = cert['tbs_certificate'] 2958 signature = tbs_certificate['signature'] 2959 issuer = tbs_certificate['issuer'] 2960 validity = tbs_certificate['validity'] 2961 subject = tbs_certificate['subject'] 2962 subject_public_key_info = tbs_certificate['subject_public_key_info'] 2963 subject_public_key_algorithm = subject_public_key_info['algorithm'] 2964 subject_public_key = subject_public_key_info['public_key'].parsed 2965 extensions = tbs_certificate['extensions'] 2966 2967 self.assertEqual( 2968 'v3', 2969 tbs_certificate['version'].native 2970 ) 2971 self.assertEqual( 2972 13683582341504654466, 2973 tbs_certificate['serial_number'].native 2974 ) 2975 self.assertEqual( 2976 'sha256_rsa', 2977 signature['algorithm'].native 2978 ) 2979 self.assertEqual( 2980 None, 2981 signature['parameters'].native 2982 ) 2983 self.assertEqual( 2984 util.OrderedDict([ 2985 ('country_name', 'US'), 2986 ('state_or_province_name', 'Massachusetts'), 2987 ('locality_name', 'Newbury'), 2988 ('organization_name', 'Codex Non Sufficit LC'), 2989 ('organizational_unit_name', 'Testing'), 2990 ('common_name', 'Will Bond'), 2991 ('email_address', 'will@codexns.io'), 2992 ]), 2993 issuer.native 2994 ) 2995 self.assertEqual( 2996 datetime(2015, 5, 6, 14, 37, 16, tzinfo=util.timezone.utc), 2997 validity['not_before'].native 2998 ) 2999 self.assertEqual( 3000 datetime(2025, 5, 3, 14, 37, 16, tzinfo=util.timezone.utc), 3001 validity['not_after'].native 3002 ) 3003 self.assertEqual( 3004 util.OrderedDict([ 3005 ('country_name', 'US'), 3006 ('state_or_province_name', 'Massachusetts'), 3007 ('locality_name', 'Newbury'), 3008 ('organization_name', 'Codex Non Sufficit LC'), 3009 ('organizational_unit_name', 'Testing'), 3010 ('common_name', 'Will Bond'), 3011 ('email_address', 'will@codexns.io'), 3012 ]), 3013 subject.native 3014 ) 3015 self.assertEqual( 3016 'rsa', 3017 subject_public_key_algorithm['algorithm'].native 3018 ) 3019 self.assertEqual( 3020 None, 3021 subject_public_key_algorithm['parameters'].native 3022 ) 3023 self.assertEqual( 3024 23903990516906431865559598284199534387004799030432486061102966678620221767754702651554142956492614440585611990224871381291841413369032752409360196079700921141819811294444393525264295297988924243231844876926173670633422654261873814968313363171188082579071492839040415373948505938897419917635370450127498164824808630475648771544810334682447182123219422360569466851807131368135806769502898151721274383486320505905826683946456552230958810028663378886363555981449715929872558073101554364803925363048965464124465016494920967179276744892632783712377912841537032383450409486298694116013299423220523450956288827030007092359007, # noqa 3025 subject_public_key['modulus'].native 3026 ) 3027 self.assertEqual( 3028 65537, 3029 subject_public_key['public_exponent'].native 3030 ) 3031 self.assertEqual( 3032 None, 3033 tbs_certificate['issuer_unique_id'].native 3034 ) 3035 self.assertIsInstance( 3036 tbs_certificate['issuer_unique_id'], 3037 core.Void 3038 ) 3039 self.assertEqual( 3040 None, 3041 tbs_certificate['subject_unique_id'].native 3042 ) 3043 self.assertIsInstance( 3044 tbs_certificate['subject_unique_id'], 3045 core.Void 3046 ) 3047 3048 self.maxDiff = None 3049 for extension in extensions: 3050 self.assertIsInstance( 3051 extension, 3052 x509.Extension 3053 ) 3054 self.assertEqual( 3055 [ 3056 util.OrderedDict([ 3057 ('extn_id', 'key_identifier'), 3058 ('critical', False), 3059 ('extn_value', b'\xBE\x42\x85\x3D\xCC\xFF\xE3\xF9\x28\x02\x8F\x7E\x58\x56\xB4\xFD\x03\x5C\xEA\x4B'), 3060 ]), 3061 util.OrderedDict([ 3062 ('extn_id', 'authority_key_identifier'), 3063 ('critical', False), 3064 ( 3065 'extn_value', 3066 util.OrderedDict([ 3067 ( 3068 'key_identifier', 3069 b'\xBE\x42\x85\x3D\xCC\xFF\xE3\xF9\x28\x02\x8F\x7E\x58\x56\xB4\xFD\x03\x5C\xEA\x4B' 3070 ), 3071 ( 3072 'authority_cert_issuer', 3073 [ 3074 util.OrderedDict([ 3075 ('country_name', 'US'), 3076 ('state_or_province_name', 'Massachusetts'), 3077 ('locality_name', 'Newbury'), 3078 ('organization_name', 'Codex Non Sufficit LC'), 3079 ('organizational_unit_name', 'Testing'), 3080 ('common_name', 'Will Bond'), 3081 ('email_address', 'will@codexns.io'), 3082 ]) 3083 ] 3084 ), 3085 ('authority_cert_serial_number', 13683582341504654466), 3086 ]) 3087 ), 3088 ]), 3089 util.OrderedDict([ 3090 ('extn_id', 'basic_constraints'), 3091 ('critical', False), 3092 ( 3093 'extn_value', 3094 util.OrderedDict([ 3095 ('ca', True), 3096 ('path_len_constraint', None) 3097 ]) 3098 ), 3099 ]), 3100 ], 3101 extensions.native 3102 ) 3103 3104 def test_parse_dsa_certificate(self): 3105 cert = self._load_cert('keys/test-dsa-der.crt') 3106 3107 tbs_certificate = cert['tbs_certificate'] 3108 signature = tbs_certificate['signature'] 3109 issuer = tbs_certificate['issuer'] 3110 validity = tbs_certificate['validity'] 3111 subject = tbs_certificate['subject'] 3112 subject_public_key_info = tbs_certificate['subject_public_key_info'] 3113 subject_public_key_algorithm = subject_public_key_info['algorithm'] 3114 subject_public_key = subject_public_key_info['public_key'].parsed 3115 extensions = tbs_certificate['extensions'] 3116 3117 self.assertEqual( 3118 'v3', 3119 tbs_certificate['version'].native 3120 ) 3121 self.assertEqual( 3122 14308214745771946523, 3123 tbs_certificate['serial_number'].native 3124 ) 3125 self.assertEqual( 3126 'sha256_dsa', 3127 signature['algorithm'].native 3128 ) 3129 self.assertEqual( 3130 None, 3131 signature['parameters'].native 3132 ) 3133 self.assertEqual( 3134 util.OrderedDict([ 3135 ('country_name', 'US'), 3136 ('state_or_province_name', 'Massachusetts'), 3137 ('locality_name', 'Newbury'), 3138 ('organization_name', 'Codex Non Sufficit LC'), 3139 ('organizational_unit_name', 'Testing'), 3140 ('common_name', 'Will Bond'), 3141 ('email_address', 'will@codexns.io'), 3142 ]), 3143 issuer.native 3144 ) 3145 self.assertEqual( 3146 datetime(2015, 5, 20, 13, 9, 2, tzinfo=util.timezone.utc), 3147 validity['not_before'].native 3148 ) 3149 self.assertEqual( 3150 datetime(2025, 5, 17, 13, 9, 2, tzinfo=util.timezone.utc), 3151 validity['not_after'].native 3152 ) 3153 self.assertEqual( 3154 util.OrderedDict([ 3155 ('country_name', 'US'), 3156 ('state_or_province_name', 'Massachusetts'), 3157 ('locality_name', 'Newbury'), 3158 ('organization_name', 'Codex Non Sufficit LC'), 3159 ('organizational_unit_name', 'Testing'), 3160 ('common_name', 'Will Bond'), 3161 ('email_address', 'will@codexns.io'), 3162 ]), 3163 subject.native 3164 ) 3165 self.assertEqual( 3166 'dsa', 3167 subject_public_key_algorithm['algorithm'].native 3168 ) 3169 self.assertEqual( 3170 util.OrderedDict([ 3171 ('p', 4511743893397705393934377497936985478231822206263141826261443300639402520800626925517264115785551703273809312112372693877437137848393530691841757974971843334497076835630893064661599193178307024379015589119302113551197423138934242435710226975119594589912289060014025377813473273600967729027125618396732574594753039493158066887433778053086408525146692226448554390096911703556213619406958876388642882534250747780313634767409586007581976273681005928967585750017105562145167146445061803488570714706090280814293902464230717946651489964409785146803791743658888866280873858000476717727810363942159874283767926511678640730707887895260274767195555813448140889391762755466967436731106514029224490921857229134393798015954890071206959203407845438863870686180087606429828973298318856683615900474921310376145478859687052812749087809700610549251964102790514588562086548577933609968589710807989944739877028770343142449461177732058649962678857), # noqa 3172 ('q', 71587850165936478337655415373676526523562874562337607790945426056266440596923), 3173 ('g', 761437146067908309288345767887973163494473925243194806582679580640442238588269326525839153095505341738937595419375068472941615006110237832663093084973431440436421580371384720052414080562019831325744042316268714195397974084616335082272743706567701546951285088540646372701485690904535540223121118329044403681933304838754517522024738251994717369464179515923093116622352823578284891812676662979104509631349201801577889230316128523885862472086364717411346341249139971907827526291913249445756671582283459372536334490171231311487207683108274785825764378203622999309355578169139646003751751448501475767709869676880946562283552431757983801739671783678927397420797147373441051876558068212062253171347849380506793433921881336652424898488378657239798694995315456959568806256079056461448199493507273882763491729787817044805150879660784158902456811649964987582162907020243296662602990514615480712948126671999033658064244112238138589732202), # noqa 3174 ]), 3175 subject_public_key_algorithm['parameters'].native 3176 ) 3177 self.assertEqual( 3178 934231235067929794039535952071098031636053793876274937162425423023735221571983693370780054696865229184537343792766496068557051933738826401423094028670222490622041397241325320965905259541032379046252395145258594355589801644789631904099105867133976990593761395721476198083091062806327384261369876465927159169400428623265291958463077792777155465482611741502621885386691681062128487785344975981628995609792181581218570320181053055516069553767918513262908069925035292416868414952256645902605335068760774106734518308281769128146479819566784704033671969858507248124850451414380441279385481154336362988505436125981975735568289420374790767927084033441728922597082155884801013899630856890463962357814273014111039522903328923758417820349377075487103441305806369234738881875734407495707878637895190993370257589211331043479113328811265005530361001980539377903738453549980082795009589559114091215518866106998956304437954236070776810740036, # noqa 3179 subject_public_key.native 3180 ) 3181 self.assertEqual( 3182 None, 3183 tbs_certificate['issuer_unique_id'].native 3184 ) 3185 self.assertIsInstance( 3186 tbs_certificate['issuer_unique_id'], 3187 core.Void 3188 ) 3189 self.assertEqual( 3190 None, 3191 tbs_certificate['subject_unique_id'].native 3192 ) 3193 self.assertIsInstance( 3194 tbs_certificate['subject_unique_id'], 3195 core.Void 3196 ) 3197 3198 self.maxDiff = None 3199 for extension in extensions: 3200 self.assertIsInstance( 3201 extension, 3202 x509.Extension 3203 ) 3204 self.assertEqual( 3205 [ 3206 util.OrderedDict([ 3207 ('extn_id', 'key_identifier'), 3208 ('critical', False), 3209 ('extn_value', b'\x81\xA3\x37\x86\xF9\x99\x28\xF2\x74\x70\x60\x87\xF2\xD3\x7E\x8D\x19\x61\xA8\xBE'), 3210 ]), 3211 util.OrderedDict([ 3212 ('extn_id', 'authority_key_identifier'), 3213 ('critical', False), 3214 ( 3215 'extn_value', 3216 util.OrderedDict([ 3217 ( 3218 'key_identifier', 3219 b'\x81\xA3\x37\x86\xF9\x99\x28\xF2\x74\x70\x60\x87\xF2\xD3\x7E\x8D\x19\x61\xA8\xBE' 3220 ), 3221 ('authority_cert_issuer', None), 3222 ('authority_cert_serial_number', None), 3223 ]) 3224 ), 3225 ]), 3226 util.OrderedDict([ 3227 ('extn_id', 'basic_constraints'), 3228 ('critical', False), 3229 ( 3230 'extn_value', 3231 util.OrderedDict([ 3232 ('ca', True), 3233 ('path_len_constraint', None) 3234 ]) 3235 ), 3236 ]), 3237 ], 3238 extensions.native 3239 ) 3240 3241 def test_parse_dsa_certificate_inheritance(self): 3242 cert = self._load_cert('DSAParametersInheritedCACert.crt') 3243 3244 tbs_certificate = cert['tbs_certificate'] 3245 signature = tbs_certificate['signature'] 3246 issuer = tbs_certificate['issuer'] 3247 validity = tbs_certificate['validity'] 3248 subject = tbs_certificate['subject'] 3249 subject_public_key_info = tbs_certificate['subject_public_key_info'] 3250 subject_public_key_algorithm = subject_public_key_info['algorithm'] 3251 3252 self.assertEqual( 3253 'v3', 3254 tbs_certificate['version'].native 3255 ) 3256 self.assertEqual( 3257 2, 3258 tbs_certificate['serial_number'].native 3259 ) 3260 self.assertEqual( 3261 'sha1_dsa', 3262 signature['algorithm'].native 3263 ) 3264 self.assertEqual( 3265 None, 3266 signature['parameters'].native 3267 ) 3268 self.assertEqual( 3269 util.OrderedDict([ 3270 ('country_name', 'US'), 3271 ('organization_name', 'Test Certificates 2011'), 3272 ('common_name', 'DSA CA'), 3273 ]), 3274 issuer.native 3275 ) 3276 self.assertEqual( 3277 datetime(2010, 1, 1, 8, 30, tzinfo=util.timezone.utc), 3278 validity['not_before'].native 3279 ) 3280 self.assertEqual( 3281 datetime(2030, 12, 31, 8, 30, tzinfo=util.timezone.utc), 3282 validity['not_after'].native 3283 ) 3284 self.assertEqual( 3285 util.OrderedDict([ 3286 ('country_name', 'US'), 3287 ('organization_name', 'Test Certificates 2011'), 3288 ('common_name', 'DSA Parameters Inherited CA'), 3289 ]), 3290 subject.native 3291 ) 3292 self.assertEqual( 3293 'dsa', 3294 subject_public_key_algorithm['algorithm'].native 3295 ) 3296 self.assertEqual( 3297 None, 3298 subject_public_key_algorithm['parameters'].native 3299 ) 3300 self.assertEqual( 3301 'dsa', 3302 subject_public_key_info.algorithm 3303 ) 3304 self.assertEqual( 3305 None, 3306 subject_public_key_info.hash_algo 3307 ) 3308 3309 def test_parse_ec_certificate(self): 3310 cert = self._load_cert('keys/test-ec-der.crt') 3311 3312 tbs_certificate = cert['tbs_certificate'] 3313 signature = tbs_certificate['signature'] 3314 issuer = tbs_certificate['issuer'] 3315 validity = tbs_certificate['validity'] 3316 subject = tbs_certificate['subject'] 3317 subject_public_key_info = tbs_certificate['subject_public_key_info'] 3318 subject_public_key_algorithm = subject_public_key_info['algorithm'] 3319 public_key_params = subject_public_key_info['algorithm']['parameters'].chosen 3320 field_id = public_key_params['field_id'] 3321 curve = public_key_params['curve'] 3322 subject_public_key = subject_public_key_info['public_key'] 3323 extensions = tbs_certificate['extensions'] 3324 3325 self.assertEqual( 3326 'v3', 3327 tbs_certificate['version'].native 3328 ) 3329 self.assertEqual( 3330 15854128451240978884, 3331 tbs_certificate['serial_number'].native 3332 ) 3333 self.assertEqual( 3334 'sha256_ecdsa', 3335 signature['algorithm'].native 3336 ) 3337 self.assertEqual( 3338 None, 3339 signature['parameters'].native 3340 ) 3341 self.assertEqual( 3342 util.OrderedDict([ 3343 ('country_name', 'US'), 3344 ('state_or_province_name', 'Massachusetts'), 3345 ('locality_name', 'Newbury'), 3346 ('organization_name', 'Codex Non Sufficit LC'), 3347 ('organizational_unit_name', 'Testing'), 3348 ('common_name', 'Will Bond'), 3349 ('email_address', 'will@codexns.io'), 3350 ]), 3351 issuer.native 3352 ) 3353 self.assertEqual( 3354 datetime(2015, 5, 20, 12, 56, 46, tzinfo=util.timezone.utc), 3355 validity['not_before'].native 3356 ) 3357 self.assertEqual( 3358 datetime(2025, 5, 17, 12, 56, 46, tzinfo=util.timezone.utc), 3359 validity['not_after'].native 3360 ) 3361 self.assertEqual( 3362 util.OrderedDict([ 3363 ('country_name', 'US'), 3364 ('state_or_province_name', 'Massachusetts'), 3365 ('locality_name', 'Newbury'), 3366 ('organization_name', 'Codex Non Sufficit LC'), 3367 ('organizational_unit_name', 'Testing'), 3368 ('common_name', 'Will Bond'), 3369 ('email_address', 'will@codexns.io'), 3370 ]), 3371 subject.native 3372 ) 3373 self.assertEqual( 3374 'ec', 3375 subject_public_key_algorithm['algorithm'].native 3376 ) 3377 self.assertEqual( 3378 'ecdpVer1', 3379 public_key_params['version'].native 3380 ) 3381 self.assertEqual( 3382 'prime_field', 3383 field_id['field_type'].native 3384 ) 3385 self.assertEqual( 3386 115792089210356248762697446949407573530086143415290314195533631308867097853951, 3387 field_id['parameters'].native 3388 ) 3389 self.assertEqual( 3390 b'\xFF\xFF\xFF\xFF\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00' 3391 b'\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFC', 3392 curve['a'].native 3393 ) 3394 self.assertEqual( 3395 b'\x5A\xC6\x35\xD8\xAA\x3A\x93\xE7\xB3\xEB\xBD\x55\x76\x98\x86\xBC' 3396 b'\x65\x1D\x06\xB0\xCC\x53\xB0\xF6\x3B\xCE\x3C\x3E\x27\xD2\x60\x4B', 3397 curve['b'].native 3398 ) 3399 self.assertEqual( 3400 b'\xC4\x9D\x36\x08\x86\xE7\x04\x93\x6A\x66\x78\xE1\x13\x9D\x26\xB7\x81\x9F\x7E\x90', 3401 curve['seed'].native 3402 ) 3403 self.assertEqual( 3404 b'\x04\x6B\x17\xD1\xF2\xE1\x2C\x42\x47\xF8\xBC\xE6\xE5\x63\xA4\x40' 3405 b'\xF2\x77\x03\x7D\x81\x2D\xEB\x33\xA0\xF4\xA1\x39\x45\xD8\x98\xC2' 3406 b'\x96\x4F\xE3\x42\xE2\xFE\x1A\x7F\x9B\x8E\xE7\xEB\x4A\x7C\x0F\x9E' 3407 b'\x16\x2B\xCE\x33\x57\x6B\x31\x5E\xCE\xCB\xB6\x40\x68\x37\xBF\x51\xF5', 3408 public_key_params['base'].native 3409 ) 3410 self.assertEqual( 3411 115792089210356248762697446949407573529996955224135760342422259061068512044369, 3412 public_key_params['order'].native 3413 ) 3414 self.assertEqual( 3415 1, 3416 public_key_params['cofactor'].native 3417 ) 3418 self.assertEqual( 3419 None, 3420 public_key_params['hash'].native 3421 ) 3422 self.assertEqual( 3423 b'\x04\x8b]Lq\xf7\xd6\xc6\xa3IcB\\G\x9f\xcbs$\x1d\xc9\xdd\xd1-\xf1:\x9f' 3424 b'\xb7\x04\xde \xd0X\x00\x93T\xf6\x89\xc7/\x87+\xf7\xf9=;4\xed\x9e{\x0e' 3425 b'=WB\xdfx\x03\x0b\xcc1\xc6\x03\xd7\x9f`\x01', 3426 subject_public_key.native 3427 ) 3428 self.assertEqual( 3429 ( 3430 63036330335395236932063564494857090016633168203412940864166337576590847793152, 3431 66640105439272245186116058015235631147470323594355535909132387303736913911809 3432 ), 3433 subject_public_key.to_coords() 3434 ) 3435 self.assertEqual( 3436 None, 3437 tbs_certificate['issuer_unique_id'].native 3438 ) 3439 self.assertIsInstance( 3440 tbs_certificate['issuer_unique_id'], 3441 core.Void 3442 ) 3443 self.assertEqual( 3444 None, 3445 tbs_certificate['subject_unique_id'].native 3446 ) 3447 self.assertIsInstance( 3448 tbs_certificate['subject_unique_id'], 3449 core.Void 3450 ) 3451 3452 self.maxDiff = None 3453 for extension in extensions: 3454 self.assertIsInstance( 3455 extension, 3456 x509.Extension 3457 ) 3458 self.assertEqual( 3459 [ 3460 util.OrderedDict([ 3461 ('extn_id', 'key_identifier'), 3462 ('critical', False), 3463 ('extn_value', b'\x54\xAA\x54\x70\x6C\x34\x1A\x6D\xEB\x5D\x97\xD7\x1E\xFC\xD5\x24\x3C\x8A\x0E\xD7'), 3464 ]), 3465 util.OrderedDict([ 3466 ('extn_id', 'authority_key_identifier'), 3467 ('critical', False), 3468 ( 3469 'extn_value', 3470 util.OrderedDict([ 3471 ( 3472 'key_identifier', 3473 b'\x54\xAA\x54\x70\x6C\x34\x1A\x6D\xEB\x5D\x97\xD7\x1E\xFC\xD5\x24\x3C\x8A\x0E\xD7' 3474 ), 3475 ('authority_cert_issuer', None), 3476 ('authority_cert_serial_number', None), 3477 ]) 3478 ), 3479 ]), 3480 util.OrderedDict([ 3481 ('extn_id', 'basic_constraints'), 3482 ('critical', False), 3483 ( 3484 'extn_value', 3485 util.OrderedDict([ 3486 ('ca', True), 3487 ('path_len_constraint', None) 3488 ]) 3489 ), 3490 ]), 3491 ], 3492 extensions.native 3493 ) 3494 3495 def test_repeated_subject_fields(self): 3496 cert = self._load_cert('self-signed-repeated-subject-fields.der') 3497 self.assertEqual( 3498 cert.subject.native, 3499 util.OrderedDict([ 3500 ('country_name', 'RU'), 3501 ('state_or_province_name', 'Some'), 3502 ('locality_name', 'Any'), 3503 ('organization_name', 'Org'), 3504 ('organizational_unit_name', 'OrgUnit'), 3505 ('common_name', 'zzz.yyy.domain.tld'), 3506 ('email_address', 'no@email'), 3507 ('domain_component', ['zzz', 'yyy', 'domain', 'tld']) 3508 ]) 3509 ) 3510 3511 def test_trusted_certificate(self): 3512 with open(os.path.join(fixtures_dir, 'sender_dummycorp.com.crt'), 'rb') as f: 3513 cert_bytes = f.read() 3514 if pem.detect(cert_bytes): 3515 _, _, cert_bytes = pem.unarmor(cert_bytes) 3516 trusted_cert = x509.TrustedCertificate.load(cert_bytes) 3517 3518 cert = trusted_cert[0] 3519 aux = trusted_cert[1] 3520 3521 self.assertEqual( 3522 cert.subject.native, 3523 util.OrderedDict([ 3524 ('country_name', 'US'), 3525 ('state_or_province_name', 'VA'), 3526 ('locality_name', 'Herndon'), 3527 ('organization_name', 'Internet Gadgets Pty Ltd'), 3528 ('common_name', 'Fake Sender'), 3529 ('email_address', 'sender@dummycorp.com'), 3530 ]) 3531 ) 3532 3533 self.assertEqual( 3534 aux['trust'].native, 3535 ['email_protection'] 3536 ) 3537 3538 self.assertEqual( 3539 aux['reject'].native, 3540 ['client_auth', 'server_auth'] 3541 ) 3542 3543 def test_iri_with_port(self): 3544 with open(os.path.join(fixtures_dir, 'admin.ch.crt'), 'rb') as f: 3545 cert_bytes = f.read() 3546 if pem.detect(cert_bytes): 3547 _, _, cert_bytes = pem.unarmor(cert_bytes) 3548 cert = x509.Certificate.load(cert_bytes) 3549 3550 self.assertEqual( 3551 [dp.native for dp in cert.crl_distribution_points], 3552 [ 3553 util.OrderedDict([ 3554 ('distribution_point', ['http://www.pki.admin.ch/crl/SSLCA01.crl']), 3555 ('reasons', None), 3556 ('crl_issuer', None) 3557 ]), 3558 util.OrderedDict([ 3559 ( 3560 'distribution_point', 3561 [ 3562 'ldap://admindir.admin.ch:389/' 3563 'cn=Swiss Government SSL CA 01,' 3564 'ou=Certification Authorities,' 3565 'ou=Services,' 3566 'o=Admin,' 3567 'c=CH' 3568 ] 3569 ), 3570 ('reasons', None), 3571 ('crl_issuer', None) 3572 ]) 3573 ] 3574 ) 3575 3576 def test_extended_datetime(self): 3577 cert = self._load_cert('9999-years-rsa-cert.pem') 3578 self.assertEqual( 3579 cert['tbs_certificate']['validity']['not_before'].native, 3580 util.extended_datetime(0, 1, 1, 0, 0, 1, tzinfo=util.timezone.utc) 3581 ) 3582 3583 def test_teletex_that_is_really_latin1(self): 3584 self.assertEqual( 3585 '{}', 3586 x509.DirectoryString.load(b'\x14\x02{}').native 3587 ) 3588 3589 def test_strict_teletex(self): 3590 with x509.strict_teletex(): 3591 with self.assertRaises(UnicodeDecodeError): 3592 self.assertEqual( 3593 '{}', 3594 x509.DirectoryString.load(b'\x14\x02{}').native 3595 ) 3596 3597 # Make sure outside of the contextmanager we are back to 3598 # liberal interpretation of TeletexString 3599 self.assertEqual( 3600 '{}', 3601 x509.DirectoryString.load(b'\x14\x02{}').native 3602 ) 3603 3604 def test_validity_after_before(self): 3605 cert = self._load_cert("keys/test-validity.crt") 3606 3607 self.assertEqual(cert.not_valid_after, datetime(2118, 1, 28, 12, 27, 39, tzinfo=util.timezone.utc)) 3608 self.assertEqual(cert.not_valid_before, datetime(2018, 2, 21, 12, 27, 39, tzinfo=util.timezone.utc)) 3609 3610 def test_invalid_email_encoding(self): 3611 cert = self._load_cert("invalid_email_tag.pem") 3612 self.assertEqual('info@keyweb.de', cert.subject.native['email_address']) 3613