blob: 915f7b526acc16f3886db6bb57f5f32d3bd59b8d [file] [log] [blame]
wbonde91513e2015-06-03 14:52:18 -04001# coding: utf-8
2from __future__ import unicode_literals
3
4import unittest
5import sys
6import os
7from collections import OrderedDict
8from datetime import datetime
9
wbondaf1f5a82015-07-17 12:13:15 -040010from asn1crypto import x509, core, pem
11
12from .unittest_data import DataDecorator, data
wbonde91513e2015-06-03 14:52:18 -040013
14if sys.version_info < (3,):
15 byte_cls = str
16else:
17 byte_cls = bytes
18
19
20tests_root = os.path.dirname(__file__)
21fixtures_dir = os.path.join(tests_root, 'fixtures')
22
23
wbondaf1f5a82015-07-17 12:13:15 -040024@DataDecorator
wbonde91513e2015-06-03 14:52:18 -040025class X509Tests(unittest.TestCase):
26
wbondaf1f5a82015-07-17 12:13:15 -040027 def _load_cert(self, relative_path):
28 with open(os.path.join(fixtures_dir, relative_path), 'rb') as f:
29 cert_bytes = f.read()
30 if pem.detect(cert_bytes):
31 _, _, cert_bytes = pem.unarmor(cert_bytes)
32 return x509.Certificate.load(cert_bytes)
wbond8bb77d02015-07-13 17:44:29 -040033
wbondaf1f5a82015-07-17 12:13:15 -040034 #pylint: disable=C0326
35 @staticmethod
36 def critical_extensions_info():
37 return (
38 ('keys/test-der.crt', []),
39 ('keys/test-inter-der.crt', []),
40 ('keys/test-third-der.crt', []),
41 ('geotrust_certs/GeoTrust_Universal_CA.crt', ['basic_constraints', 'key_usage']),
42 ('geotrust_certs/GeoTrust_Primary_CA.crt', ['basic_constraints', 'key_usage']),
43 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', ['basic_constraints', 'key_usage']),
44 ('geotrust_certs/codex.crt', ['key_usage']),
45 ('lets_encrypt/isrgrootx1.pem', ['key_usage', 'basic_constraints']),
46 ('lets_encrypt/letsencryptauthorityx1.pem', ['key_usage', 'basic_constraints']),
47 ('lets_encrypt/letsencryptauthorityx2.pem', ['key_usage', 'basic_constraints']),
48 ('globalsign_example_keys/IssuingCA-der.cer', ['basic_constraints', 'key_usage']),
49 ('globalsign_example_keys/rootCA.cer', ['basic_constraints', 'key_usage']),
50 ('globalsign_example_keys/SSL1.cer', ['key_usage', 'extended_key_usage', 'basic_constraints']),
51 ('globalsign_example_keys/SSL2.cer', ['key_usage', 'extended_key_usage', 'basic_constraints']),
52 ('globalsign_example_keys/SSL3.cer', ['key_usage', 'extended_key_usage', 'basic_constraints']),
wbond8bb77d02015-07-13 17:44:29 -040053 )
wbondaf1f5a82015-07-17 12:13:15 -040054
55 @data('critical_extensions_info')
56 def critical_extensions(self, relative_path, critical_extensions):
57 cert = self._load_cert(relative_path)
58 self.assertEqual(critical_extensions, cert.critical_extensions)
59
60 #pylint: disable=C0326
61 @staticmethod
62 def key_identifier_value_info():
63 return (
64 ('keys/test-der.crt', b'\xbeB\x85=\xcc\xff\xe3\xf9(\x02\x8f~XV\xb4\xfd\x03\\\xeaK'),
65 ('keys/test-inter-der.crt', b'\xd2\n\xfd.%\xd1\xb7!\xd7P~\xbb\xa4}\xbf4\xefR^\x02'),
66 ('keys/test-third-der.crt', b'D8\xe0\xe0&\x85\xbf\x98\x86\xdc\x1b\xe1\x1d\xf520\xbe\xab\xac\r'),
67 ('geotrust_certs/GeoTrust_Universal_CA.crt', b'\xda\xbb.\xaa\xb0\x0c\xb8\x88&Qt\\m\x03\xd3\xc0\xd8\x8fz\xd6'),
68 ('geotrust_certs/GeoTrust_Primary_CA.crt', b',\xd5PA\x97\x15\x8b\xf0\x8f6a[J\xfbk\xd9\x99\xc93\x92'),
69 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', b'\xde\xcf\\P\xb7\xae\x02\x1f\x15\x17\xaa\x16\xe8\r\xb5(\x9djZ\xf3'),
70 ('geotrust_certs/codex.crt', None),
71 ('lets_encrypt/isrgrootx1.pem', b'y\xb4Y\xe6{\xb6\xe5\xe4\x01s\x80\x08\x88\xc8\x1aX\xf6\xe9\x9bn'),
72 ('lets_encrypt/letsencryptauthorityx1.pem', b'\xa8Jjc\x04}\xdd\xba\xe6\xd19\xb7\xa6Ee\xef\xf3\xa8\xec\xa1'),
73 ('lets_encrypt/letsencryptauthorityx2.pem', b'\xc5\xb1\xabNL\xb1\xcdd0\x93~\xc1\x84\x99\x05\xab\xe6\x03\xe2%'),
74 ('globalsign_example_keys/IssuingCA-der.cer', b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91"),
75 ('globalsign_example_keys/rootCA.cer', b'd|\\\xe1\xe0`8NH\x9f\x05\xbcUc~?\xaeM\xf7\x1e'),
76 ('globalsign_example_keys/SSL1.cer', b'\x94a\x04\x92\x04L\xe6\xffh\xa8\x96\xafy\xd2\xf32\x84\xae[\xcf'),
77 ('globalsign_example_keys/SSL2.cer', b'\xd2\xb7\x15\x7fd0\x07(p\x83\xca(\xfa\x88\x96\xde\x9e\xfc\x8a='),
78 ('globalsign_example_keys/SSL3.cer', b'G\xde\xa4\xe7\xea`\xe7\xee6\xc8\xf1\xd5\xb0F\x07\x07\x9eBh\xce'),
wbond8bb77d02015-07-13 17:44:29 -040079 )
wbond8bb77d02015-07-13 17:44:29 -040080
wbondaf1f5a82015-07-17 12:13:15 -040081 @data('key_identifier_value_info')
82 def key_identifier_value(self, relative_path, key_identifier_value):
83 cert = self._load_cert(relative_path)
84 value = cert.key_identifier_value
85 self.assertEqual(key_identifier_value, value.native if value else None)
wbond8bb77d02015-07-13 17:44:29 -040086
wbondaf1f5a82015-07-17 12:13:15 -040087 #pylint: disable=C0326
88 @staticmethod
89 def key_usage_value_info():
90 return (
91 ('keys/test-der.crt', None),
92 ('keys/test-inter-der.crt', None),
93 ('keys/test-third-der.crt', None),
94 (
95 'geotrust_certs/GeoTrust_Universal_CA.crt',
wbond8bb77d02015-07-13 17:44:29 -040096 OrderedDict([
wbondaf1f5a82015-07-17 12:13:15 -040097 ('digital_signature', True),
98 ('non_repudiation', False),
99 ('key_encipherment', False),
100 ('data_encipherment', False),
101 ('key_agreement', False),
102 ('key_cert_sign', True),
103 ('crl_sign', True),
104 ('encipher_only', False),
105 ('decipher_only', False),
wbond8bb77d02015-07-13 17:44:29 -0400106 ])
wbondaf1f5a82015-07-17 12:13:15 -0400107 ),
108 (
109 'geotrust_certs/GeoTrust_Primary_CA.crt',
wbond8bb77d02015-07-13 17:44:29 -0400110 OrderedDict([
wbondaf1f5a82015-07-17 12:13:15 -0400111 ('digital_signature', True),
112 ('non_repudiation', True),
113 ('key_encipherment', False),
114 ('data_encipherment', False),
115 ('key_agreement', False),
116 ('key_cert_sign', False),
117 ('crl_sign', False),
118 ('encipher_only', False),
119 ('decipher_only', False),
wbond8bb77d02015-07-13 17:44:29 -0400120 ])
wbondaf1f5a82015-07-17 12:13:15 -0400121 ),
122 (
123 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt',
wbond8bb77d02015-07-13 17:44:29 -0400124 OrderedDict([
wbondaf1f5a82015-07-17 12:13:15 -0400125 ('digital_signature', True),
126 ('non_repudiation', True),
127 ('key_encipherment', False),
128 ('data_encipherment', False),
129 ('key_agreement', False),
130 ('key_cert_sign', False),
131 ('crl_sign', False),
132 ('encipher_only', False),
133 ('decipher_only', False),
134 ])
135 ),
136 (
137 'geotrust_certs/codex.crt',
138 OrderedDict([
139 ('digital_signature', True),
140 ('non_repudiation', False),
141 ('key_encipherment', True),
142 ('data_encipherment', False),
143 ('key_agreement', False),
144 ('key_cert_sign', False),
145 ('crl_sign', False),
146 ('encipher_only', False),
147 ('decipher_only', False),
148 ])
149 ),
150 (
151 'lets_encrypt/isrgrootx1.pem',
152 OrderedDict([
153 ('digital_signature', True),
154 ('non_repudiation', True),
155 ('key_encipherment', False),
156 ('data_encipherment', False),
157 ('key_agreement', False),
158 ('key_cert_sign', False),
159 ('crl_sign', False),
160 ('encipher_only', False),
161 ('decipher_only', False),
162 ])
163 ),
164 (
165 'lets_encrypt/letsencryptauthorityx1.pem',
166 OrderedDict([
167 ('digital_signature', True),
168 ('non_repudiation', False),
169 ('key_encipherment', False),
170 ('data_encipherment', False),
171 ('key_agreement', False),
172 ('key_cert_sign', True),
173 ('crl_sign', True),
174 ('encipher_only', False),
175 ('decipher_only', False),
176 ])
177 ),
178 (
179 'lets_encrypt/letsencryptauthorityx2.pem',
180 OrderedDict([
181 ('digital_signature', True),
182 ('non_repudiation', False),
183 ('key_encipherment', False),
184 ('data_encipherment', False),
185 ('key_agreement', False),
186 ('key_cert_sign', True),
187 ('crl_sign', True),
188 ('encipher_only', False),
189 ('decipher_only', False),
190 ])
191 ),
192 (
193 'globalsign_example_keys/IssuingCA-der.cer',
194 OrderedDict([
195 ('digital_signature', True),
196 ('non_repudiation', True),
197 ('key_encipherment', False),
198 ('data_encipherment', False),
199 ('key_agreement', False),
200 ('key_cert_sign', False),
201 ('crl_sign', False),
202 ('encipher_only', False),
203 ('decipher_only', False),
204 ])
205 ),
206 (
207 'globalsign_example_keys/rootCA.cer',
208 OrderedDict([
209 ('digital_signature', True),
210 ('non_repudiation', True),
211 ('key_encipherment', False),
212 ('data_encipherment', False),
213 ('key_agreement', False),
214 ('key_cert_sign', False),
215 ('crl_sign', False),
216 ('encipher_only', False),
217 ('decipher_only', False),
218 ])
219 ),
220 (
221 'globalsign_example_keys/SSL1.cer',
222 OrderedDict([
223 ('digital_signature', True),
224 ('non_repudiation', False),
225 ('key_encipherment', True),
226 ('data_encipherment', False),
227 ('key_agreement', False),
228 ('key_cert_sign', False),
229 ('crl_sign', False),
230 ('encipher_only', False),
231 ('decipher_only', False),
232 ])
233 ),
234 (
235 'globalsign_example_keys/SSL2.cer',
236 OrderedDict([
237 ('digital_signature', True),
238 ('non_repudiation', False),
239 ('key_encipherment', True),
240 ('data_encipherment', False),
241 ('key_agreement', False),
242 ('key_cert_sign', False),
243 ('crl_sign', False),
244 ('encipher_only', False),
245 ('decipher_only', False),
246 ])
247 ),
248 (
249 'globalsign_example_keys/SSL3.cer',
250 OrderedDict([
251 ('digital_signature', True),
252 ('non_repudiation', False),
253 ('key_encipherment', True),
254 ('data_encipherment', False),
255 ('key_agreement', False),
256 ('key_cert_sign', False),
257 ('crl_sign', False),
258 ('encipher_only', False),
259 ('decipher_only', False),
260 ])
261 ),
262 )
263
264 @data('key_usage_value_info')
265 def key_usage_value(self, relative_path, key_usage_value):
266 cert = self._load_cert(relative_path)
267 value = cert.key_usage_value
268 self.assertEqual(key_usage_value, value.native if value else None)
269
270 #pylint: disable=C0326
271 @staticmethod
272 def subject_alt_name_value_info():
273 return (
274 ('keys/test-der.crt', None),
275 ('keys/test-inter-der.crt', None),
276 ('keys/test-third-der.crt', None),
277 ('geotrust_certs/GeoTrust_Universal_CA.crt', None),
278 ('geotrust_certs/GeoTrust_Primary_CA.crt', None),
279 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', [OrderedDict([('common_name', 'SymantecPKI-1-538')])]),
280 ('geotrust_certs/codex.crt', ['dev.codexns.io', 'rc.codexns.io', 'packagecontrol.io', 'wbond.net', 'codexns.io']),
281 ('lets_encrypt/isrgrootx1.pem', None),
282 ('lets_encrypt/letsencryptauthorityx1.pem', None),
283 ('lets_encrypt/letsencryptauthorityx2.pem', None),
284 ('globalsign_example_keys/IssuingCA-der.cer', None),
285 ('globalsign_example_keys/rootCA.cer', None),
286 ('globalsign_example_keys/SSL1.cer', ['anything.example.com']),
287 ('globalsign_example_keys/SSL2.cer', ['anything.example.com']),
288 ('globalsign_example_keys/SSL3.cer', None),
289 )
290
291 @data('subject_alt_name_value_info')
292 def subject_alt_name_value(self, relative_path, subject_alt_name_value):
293 cert = self._load_cert(relative_path)
294 value = cert.subject_alt_name_value
295 self.assertEqual(subject_alt_name_value, value.native if value else None)
296
297 #pylint: disable=C0326
298 @staticmethod
299 def basic_constraints_value_info():
300 return (
301 ('keys/test-der.crt', {'ca': True, 'path_len_constraint': None}),
302 ('keys/test-inter-der.crt', {'ca': True, 'path_len_constraint': None}),
303 ('keys/test-third-der.crt', None),
304 ('geotrust_certs/GeoTrust_Universal_CA.crt', {'ca': True, 'path_len_constraint': None}),
305 ('geotrust_certs/GeoTrust_Primary_CA.crt', {'ca': True, 'path_len_constraint': None}),
306 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', {'ca': True, 'path_len_constraint': 0}),
307 ('geotrust_certs/codex.crt', {'ca': False, 'path_len_constraint': None}),
308 ('lets_encrypt/isrgrootx1.pem', {'ca': True, 'path_len_constraint': None}),
309 ('lets_encrypt/letsencryptauthorityx1.pem', {'ca': True, 'path_len_constraint': 0}),
310 ('lets_encrypt/letsencryptauthorityx2.pem', {'ca': True, 'path_len_constraint': 0}),
311 ('globalsign_example_keys/IssuingCA-der.cer', {'ca': True, 'path_len_constraint': None}),
312 ('globalsign_example_keys/rootCA.cer', {'ca': True, 'path_len_constraint': None}),
313 ('globalsign_example_keys/SSL1.cer', {'ca': False, 'path_len_constraint': None}),
314 ('globalsign_example_keys/SSL2.cer', {'ca': False, 'path_len_constraint': None}),
315 ('globalsign_example_keys/SSL3.cer', {'ca': False, 'path_len_constraint': None}),
316 )
317
318 @data('basic_constraints_value_info')
319 def basic_constraints_value(self, relative_path, basic_constraints_value):
320 cert = self._load_cert(relative_path)
321 value = cert.basic_constraints_value
322 self.assertEqual(basic_constraints_value, value.native if value else None)
323
324 #pylint: disable=C0326
325 @staticmethod
326 def name_constraints_value_info():
327 return (
328 ('keys/test-der.crt', None),
329 ('keys/test-inter-der.crt', None),
330 ('keys/test-third-der.crt', None),
331 ('geotrust_certs/GeoTrust_Universal_CA.crt', None),
332 ('geotrust_certs/GeoTrust_Primary_CA.crt', None),
333 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', None),
334 ('geotrust_certs/codex.crt', None),
335 ('lets_encrypt/isrgrootx1.pem', None),
336 ('lets_encrypt/letsencryptauthorityx1.pem', None),
337 ('lets_encrypt/letsencryptauthorityx2.pem', None),
338 (
339 'globalsign_example_keys/IssuingCA-der.cer',
340 OrderedDict([
wbond8bb77d02015-07-13 17:44:29 -0400341 (
wbondaf1f5a82015-07-17 12:13:15 -0400342 'permitted_subtrees',
wbond8bb77d02015-07-13 17:44:29 -0400343 [
344 OrderedDict([
wbondaf1f5a82015-07-17 12:13:15 -0400345 ('base', 'onlythis.com'),
346 ('minimum', 0),
347 ('maximum', None)
348 ]),
349 OrderedDict([
350 (
351 'base',
352 OrderedDict([
353 ('country_name', 'US'),
354 ('state_or_province_name', 'MA'),
355 ('locality_name', 'Boston'),
356 ('organization_name', 'Example LLC')
357 ])
358 ),
359 ('minimum', 0),
360 ('maximum', None)
wbond8bb77d02015-07-13 17:44:29 -0400361 ])
362 ]
wbondaf1f5a82015-07-17 12:13:15 -0400363 ),
364 (
365 'excluded_subtrees',
366 [
367 OrderedDict([
368 ('base', b'\x00\x00\x00\x00\x00\x00\x00\x00'),
369 ('minimum', 0),
370 ('maximum', None)
371 ]),
372 OrderedDict([
373 ('base', b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
374 ('minimum', 0),
375 ('maximum', None)
376 ])
377 ]
378 ),
wbond8bb77d02015-07-13 17:44:29 -0400379 ])
wbondaf1f5a82015-07-17 12:13:15 -0400380 ),
381 ('globalsign_example_keys/rootCA.cer', None),
382 ('globalsign_example_keys/SSL1.cer', None),
383 ('globalsign_example_keys/SSL2.cer', None),
384 ('globalsign_example_keys/SSL3.cer', None),
wbond8bb77d02015-07-13 17:44:29 -0400385 )
wbondaf1f5a82015-07-17 12:13:15 -0400386
387 @data('name_constraints_value_info')
388 def name_constraints_value(self, relative_path, name_constraints_value):
389 cert = self._load_cert(relative_path)
390 value = cert.name_constraints_value
391 self.assertEqual(name_constraints_value, value.native if value else None)
392
393 #pylint: disable=C0326
394 @staticmethod
395 def crl_distribution_points_value_info():
396 return (
397 ('keys/test-der.crt', None),
398 ('keys/test-inter-der.crt', None),
399 ('keys/test-third-der.crt', None),
400 ('geotrust_certs/GeoTrust_Universal_CA.crt', None),
401 ('geotrust_certs/GeoTrust_Primary_CA.crt', None),
402 (
403 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt',
404 [
405 OrderedDict([
406 ('distribution_point', ['http://g1.symcb.com/GeoTrustPCA.crl']),
407 ('reasons', None),
408 ('crl_issuer', None)
409 ])
410 ]
411 ),
412 (
413 'geotrust_certs/codex.crt',
414 [
415 OrderedDict([
416 ('distribution_point', ['http://gm.symcb.com/gm.crl']),
417 ('reasons', None),
418 ('crl_issuer', None)
419 ])
420 ]
421 ),
422 ('lets_encrypt/isrgrootx1.pem', None),
423 (
424 'lets_encrypt/letsencryptauthorityx1.pem',
425 [
426 OrderedDict([
427 ('distribution_point', ['http://crl.root-x1.letsencrypt.org']),
428 ('reasons', None),
429 ('crl_issuer', None)
430 ])
431 ]
432 ),
433 (
434 'lets_encrypt/letsencryptauthorityx2.pem',
435 [
436 OrderedDict([
437 ('distribution_point', ['http://crl.root-x1.letsencrypt.org']),
438 ('reasons', None),
439 ('crl_issuer', None)
440 ])
441 ]
442 ),
443 (
444 'globalsign_example_keys/IssuingCA-der.cer',
445 [
446 OrderedDict([
447 ('distribution_point', ['http://crl.globalsign.com/gs/trustrootcatg2.crl']),
448 ('reasons', None),
449 ('crl_issuer', None)
450 ])
451 ]),
452 (
453 'globalsign_example_keys/rootCA.cer',
454 [
455 OrderedDict([
456 ('distribution_point', ['http://crl.globalsign.com/gs/trustrootcatg2.crl']),
457 ('reasons', None),
458 ('crl_issuer', None)
459 ])
460 ]),
461 ('globalsign_example_keys/SSL1.cer', None),
462 ('globalsign_example_keys/SSL2.cer', None),
463 ('globalsign_example_keys/SSL3.cer', None),
464 )
465
466 @data('crl_distribution_points_value_info')
467 def crl_distribution_points_value(self, relative_path, crl_distribution_points_value):
468 cert = self._load_cert(relative_path)
469 value = cert.crl_distribution_points_value
470 self.assertEqual(crl_distribution_points_value, value.native if value else None)
471
472 #pylint: disable=C0326
473 @staticmethod
474 def certificate_policies_value_info():
475 return (
476 ('keys/test-der.crt', None),
477 ('keys/test-inter-der.crt', None),
478 ('keys/test-third-der.crt', None),
479 ('geotrust_certs/GeoTrust_Universal_CA.crt', None),
480 ('geotrust_certs/GeoTrust_Primary_CA.crt', None),
481 (
482 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt',
483 [
484 OrderedDict([
485 ('policy_identifier', 'any_policy'),
486 (
487 'policy_qualifiers',
488 [
489 OrderedDict([
490 ('policy_qualifier_id', 'certification_practice_statement'),
491 ('qualifier', 'https://www.geotrust.com/resources/cps')
492 ])
493 ]
494 )
495 ])
496 ]
497 ),
498 (
499 'geotrust_certs/codex.crt',
500 [
501 OrderedDict([
502 ('policy_identifier', '1.3.6.1.4.1.14370.1.6'),
503 (
504 'policy_qualifiers',
505 [
506 OrderedDict([
507 ('policy_qualifier_id', 'certification_practice_statement'),
508 ('qualifier', 'https://www.geotrust.com/resources/repository/legal')
509 ]),
510 OrderedDict([
511 ('policy_qualifier_id', 'user_notice'),
512 (
513 'qualifier',
514 OrderedDict([
515 ('notice_ref', None),
516 ('explicit_text', 'https://www.geotrust.com/resources/repository/legal')
517 ])
518 )
519 ])
520 ]
521 )
522 ])
523 ]
524 ),
525 ('lets_encrypt/isrgrootx1.pem', None),
526 (
527 'lets_encrypt/letsencryptauthorityx1.pem',
528 [
529 OrderedDict([
530 ('policy_identifier', '2.23.140.1.2.1'),
531 ('policy_qualifiers', None)
532 ]),
533 OrderedDict([
534 ('policy_identifier', '1.3.6.1.4.1.44947.1.1.1'),
535 (
536 'policy_qualifiers',
537 [
538 OrderedDict([
539 ('policy_qualifier_id', 'certification_practice_statement'),
540 ('qualifier', 'http://cps.root-x1.letsencrypt.org')
541 ])
542 ]
543 )
544 ])
545 ]
546 ),
547 (
548 'lets_encrypt/letsencryptauthorityx2.pem',
549 [
550 OrderedDict([
551 ('policy_identifier', '2.23.140.1.2.1'),
552 ('policy_qualifiers', None)
553 ]),
554 OrderedDict([
555 ('policy_identifier', '1.3.6.1.4.1.44947.1.1.1'),
556 (
557 'policy_qualifiers',
558 [
559 OrderedDict([
560 ('policy_qualifier_id', 'certification_practice_statement'),
561 ('qualifier', 'http://cps.root-x1.letsencrypt.org')
562 ])
563 ]
564 )
565 ])
566 ]
567 ),
568 (
569 'globalsign_example_keys/IssuingCA-der.cer',
570 [
571 OrderedDict([
572 ('policy_identifier', '1.3.6.1.4.1.4146.1.60'),
573 (
574 'policy_qualifiers',
575 [
576 OrderedDict([
577 ('policy_qualifier_id', 'certification_practice_statement'),
578 ('qualifier', 'https://www.globalsign.com/repository/')
579 ])
580 ]
581 )
582 ])
583 ]
584 ),
585 ('globalsign_example_keys/rootCA.cer', None),
586 (
587 'globalsign_example_keys/SSL1.cer',
588 [
589 OrderedDict([
590 ('policy_identifier', '1.3.6.1.4.1.4146.1.60'),
591 (
592 'policy_qualifiers',
593 [
594 OrderedDict([
595 ('policy_qualifier_id', 'certification_practice_statement'),
596 ('qualifier', 'https://www.globalsign.com/repository/')
597 ])
598 ]
599 )
600 ])
601 ]
602 ),
603 (
604 'globalsign_example_keys/SSL2.cer',
605 [
606 OrderedDict([
607 ('policy_identifier', '1.3.6.1.4.1.4146.1.60'),
608 (
609 'policy_qualifiers',
610 [
611 OrderedDict([
612 ('policy_qualifier_id', 'certification_practice_statement'),
613 ('qualifier', 'https://www.globalsign.com/repository/')
614 ])
615 ]
616 )
617 ])
618 ]
619 ),
620 (
621 'globalsign_example_keys/SSL3.cer',
622 [
623 OrderedDict([
624 ('policy_identifier', '1.3.6.1.4.1.4146.1.60'),
625 (
626 'policy_qualifiers',
627 [
628 OrderedDict([
629 ('policy_qualifier_id', 'certification_practice_statement'),
630 ('qualifier', 'https://www.globalsign.com/repository/')
631 ])
632 ]
633 )
634 ])
635 ]
636 ),
637 )
638
639 @data('certificate_policies_value_info')
640 def certificate_policies_value(self, relative_path, certificate_policies_value):
641 cert = self._load_cert(relative_path)
642 value = cert.certificate_policies_value
643 self.assertEqual(certificate_policies_value, value.native if value else None)
644
645 #pylint: disable=C0326
646 @staticmethod
647 def policy_mappings_value_info():
648 return (
649 ('keys/test-der.crt', None),
650 ('keys/test-inter-der.crt', None),
651 ('keys/test-third-der.crt', None),
652 ('geotrust_certs/GeoTrust_Universal_CA.crt', None),
653 ('geotrust_certs/GeoTrust_Primary_CA.crt', None),
654 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', None),
655 ('geotrust_certs/codex.crt', None),
656 ('lets_encrypt/isrgrootx1.pem', None),
657 ('lets_encrypt/letsencryptauthorityx1.pem', None),
658 ('lets_encrypt/letsencryptauthorityx2.pem', None),
659 ('globalsign_example_keys/IssuingCA-der.cer', None),
660 ('globalsign_example_keys/rootCA.cer', None),
661 ('globalsign_example_keys/SSL1.cer', None),
662 ('globalsign_example_keys/SSL2.cer', None),
663 ('globalsign_example_keys/SSL3.cer', None),
664 )
665
666 @data('policy_mappings_value_info')
667 def policy_mappings_value(self, relative_path, policy_mappings_value):
668 cert = self._load_cert(relative_path)
669 value = cert.policy_mappings_value
670 self.assertEqual(policy_mappings_value, value.native if value else None)
671
672 #pylint: disable=C0326
673 @staticmethod
674 def authority_key_identifier_value_info():
675 return (
676 (
677 'keys/test-der.crt',
wbond08c60fa2015-07-13 23:02:13 -0400678 OrderedDict([
wbondaf1f5a82015-07-17 12:13:15 -0400679 ('key_identifier', b'\xbeB\x85=\xcc\xff\xe3\xf9(\x02\x8f~XV\xb4\xfd\x03\\\xeaK'),
680 (
681 'authority_cert_issuer',
682 [
683 OrderedDict([
684 ('country_name', 'US'),
685 ('state_or_province_name', 'Massachusetts'),
686 ('locality_name', 'Newbury'),
687 ('organization_name', 'Codex Non Sufficit LC'),
688 ('organizational_unit_name', 'Testing'),
689 ('common_name', 'Will Bond'),
690 ('email_address', 'will@codexns.io')
691 ])
692 ]
693 ),
694 ('authority_cert_serial_number', 13683582341504654466)
wbond08c60fa2015-07-13 23:02:13 -0400695 ])
wbondaf1f5a82015-07-17 12:13:15 -0400696 ),
697 (
698 'keys/test-inter-der.crt',
699 OrderedDict([
700 ('key_identifier', b'\xbeB\x85=\xcc\xff\xe3\xf9(\x02\x8f~XV\xb4\xfd\x03\\\xeaK'),
701 ('authority_cert_issuer', None),
702 ('authority_cert_serial_number', None)
703 ])
704 ),
705 (
706 'keys/test-third-der.crt',
707 OrderedDict([
708 ('key_identifier', b'\xd2\n\xfd.%\xd1\xb7!\xd7P~\xbb\xa4}\xbf4\xefR^\x02'),
709 ('authority_cert_issuer', None),
710 ('authority_cert_serial_number', None)
711 ])
712 ),
713 (
714 'geotrust_certs/GeoTrust_Universal_CA.crt',
715 OrderedDict([
716 ('key_identifier', b'\xda\xbb.\xaa\xb0\x0c\xb8\x88&Qt\\m\x03\xd3\xc0\xd8\x8fz\xd6'),
717 ('authority_cert_issuer', None),
718 ('authority_cert_serial_number', None)
719 ])
720 ),
721 (
722 'geotrust_certs/GeoTrust_Primary_CA.crt',
723 None
724 ),
725 (
726 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt',
727 OrderedDict([
728 ('key_identifier', b',\xd5PA\x97\x15\x8b\xf0\x8f6a[J\xfbk\xd9\x99\xc93\x92'),
729 ('authority_cert_issuer', None),
730 ('authority_cert_serial_number', None)
731 ])
732 ),
733 (
734 'geotrust_certs/codex.crt',
735 OrderedDict([
736 ('key_identifier', b'\xde\xcf\\P\xb7\xae\x02\x1f\x15\x17\xaa\x16\xe8\r\xb5(\x9djZ\xf3'),
737 ('authority_cert_issuer', None),
738 ('authority_cert_serial_number', None)
739 ])
740 ),
741 (
742 'lets_encrypt/isrgrootx1.pem',
743 None
744 ),
745 (
746 'lets_encrypt/letsencryptauthorityx1.pem',
747 OrderedDict([
748 ('key_identifier', b'y\xb4Y\xe6{\xb6\xe5\xe4\x01s\x80\x08\x88\xc8\x1aX\xf6\xe9\x9bn'),
749 ('authority_cert_issuer', None),
750 ('authority_cert_serial_number', None)
751 ])
752 ),
753 (
754 'lets_encrypt/letsencryptauthorityx2.pem',
755 OrderedDict([
756 ('key_identifier', b'y\xb4Y\xe6{\xb6\xe5\xe4\x01s\x80\x08\x88\xc8\x1aX\xf6\xe9\x9bn'),
757 ('authority_cert_issuer', None),
758 ('authority_cert_serial_number', None)
759 ])
760 ),
761 (
762 'globalsign_example_keys/IssuingCA-der.cer',
763 OrderedDict([
764 ('key_identifier', b'd|\\\xe1\xe0`8NH\x9f\x05\xbcUc~?\xaeM\xf7\x1e'),
765 ('authority_cert_issuer', None),
766 ('authority_cert_serial_number', None)
767 ])
768 ),
769 (
770 'globalsign_example_keys/rootCA.cer',
771 None
772 ),
773 (
774 'globalsign_example_keys/SSL1.cer',
775 OrderedDict([
776 ('key_identifier', b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91"),
777 ('authority_cert_issuer', None),
778 ('authority_cert_serial_number', None)
779 ])
780 ),
781 (
782 'globalsign_example_keys/SSL2.cer',
783 OrderedDict([
784 ('key_identifier', b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91"),
785 ('authority_cert_issuer', None),
786 ('authority_cert_serial_number', None)
787 ])
788 ),
789 (
790 'globalsign_example_keys/SSL3.cer',
791 OrderedDict([
792 ('key_identifier', b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91"),
793 ('authority_cert_issuer', None),
794 ('authority_cert_serial_number', None)
795 ])
796 ),
wbond08c60fa2015-07-13 23:02:13 -0400797 )
wbondaf1f5a82015-07-17 12:13:15 -0400798
799 @data('authority_key_identifier_value_info')
800 def authority_key_identifier_value(self, relative_path, authority_key_identifier_value):
801 cert = self._load_cert(relative_path)
802 value = cert.authority_key_identifier_value
803 self.assertEqual(authority_key_identifier_value, value.native if value else None)
804
805 #pylint: disable=C0326
806 @staticmethod
807 def policy_constraints_value_info():
808 return (
809 ('keys/test-der.crt', None),
810 ('keys/test-inter-der.crt', None),
811 ('keys/test-third-der.crt', None),
812 ('geotrust_certs/GeoTrust_Universal_CA.crt', None),
813 ('geotrust_certs/GeoTrust_Primary_CA.crt', None),
814 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', None),
815 ('geotrust_certs/codex.crt', None),
816 ('lets_encrypt/isrgrootx1.pem', None),
817 ('lets_encrypt/letsencryptauthorityx1.pem', None),
818 ('lets_encrypt/letsencryptauthorityx2.pem', None),
819 ('globalsign_example_keys/IssuingCA-der.cer', None),
820 ('globalsign_example_keys/rootCA.cer', None),
821 ('globalsign_example_keys/SSL1.cer', None),
822 ('globalsign_example_keys/SSL2.cer', None),
823 ('globalsign_example_keys/SSL3.cer', None),
824 )
825
826 @data('policy_constraints_value_info')
827 def policy_constraints_value(self, relative_path, policy_constraints_value):
828 cert = self._load_cert(relative_path)
829 value = cert.policy_constraints_value
830 self.assertEqual(policy_constraints_value, value.native if value else None)
831
832 #pylint: disable=C0326
833 @staticmethod
834 def extended_key_usage_value_info():
835 return (
836 ('keys/test-der.crt', None),
837 ('keys/test-inter-der.crt', None),
838 ('keys/test-third-der.crt', None),
839 ('geotrust_certs/GeoTrust_Universal_CA.crt', None),
840 ('geotrust_certs/GeoTrust_Primary_CA.crt', None),
841 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', None),
842 ('geotrust_certs/codex.crt', ['server_auth', 'client_auth']),
843 ('lets_encrypt/isrgrootx1.pem', None),
844 ('lets_encrypt/letsencryptauthorityx1.pem', None),
845 ('lets_encrypt/letsencryptauthorityx2.pem', None),
846 ('globalsign_example_keys/IssuingCA-der.cer', None),
847 ('globalsign_example_keys/rootCA.cer', None),
848 ('globalsign_example_keys/SSL1.cer', ['server_auth', 'client_auth']),
849 ('globalsign_example_keys/SSL2.cer', ['server_auth', 'client_auth']),
850 ('globalsign_example_keys/SSL3.cer', ['server_auth', 'client_auth']),
851 )
852
853 @data('extended_key_usage_value_info')
854 def extended_key_usage_value(self, relative_path, extended_key_usage_value):
855 cert = self._load_cert(relative_path)
856 value = cert.extended_key_usage_value
857 self.assertEqual(extended_key_usage_value, value.native if value else None)
858
859 #pylint: disable=C0326
860 @staticmethod
861 def authority_information_access_value_info():
862 return (
863 ('keys/test-der.crt', None),
864 ('keys/test-inter-der.crt', None),
865 ('keys/test-third-der.crt', None),
866 ('geotrust_certs/GeoTrust_Universal_CA.crt', None),
867 ('geotrust_certs/GeoTrust_Primary_CA.crt', None),
868 (
869 'geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt',
870 [
871 OrderedDict([
872 ('access_method', 'ocsp'),
873 ('access_location', 'http://g2.symcb.com')
874 ])
875 ]
876 ),
877 (
878 'geotrust_certs/codex.crt',
879 [
880 OrderedDict([
881 ('access_method', 'ocsp'),
882 ('access_location', 'http://gm.symcd.com')
883 ]),
884 OrderedDict([
885 ('access_method', 'ca_issuers'),
886 ('access_location', 'http://gm.symcb.com/gm.crt')
887 ]),
888 ]
889 ),
890 ('lets_encrypt/isrgrootx1.pem', None),
891 (
892 'lets_encrypt/letsencryptauthorityx1.pem',
893 [
894 OrderedDict([
895 ('access_method', 'ocsp'),
896 ('access_location', 'http://ocsp.root-x1.letsencrypt.org/')
897 ]),
898 OrderedDict([
899 ('access_method', 'ca_issuers'),
900 ('access_location', 'http://cert.root-x1.letsencrypt.org/')
901 ])
902 ]
903 ),
904 (
905 'lets_encrypt/letsencryptauthorityx2.pem',
906 [
907 OrderedDict([
908 ('access_method', 'ocsp'),
909 ('access_location', 'http://ocsp.root-x1.letsencrypt.org/')
910 ]),
911 OrderedDict([
912 ('access_method', 'ca_issuers'),
913 ('access_location', 'http://cert.root-x1.letsencrypt.org/')
914 ])
915 ]
916 ),
917 ('globalsign_example_keys/IssuingCA-der.cer', None),
918 ('globalsign_example_keys/rootCA.cer', None),
919 (
920 'globalsign_example_keys/SSL1.cer',
921 [
922 OrderedDict([
923 ('access_method', 'ocsp'),
924 ('access_location', 'http://ocsp.exampleovca.com/')
925 ]),
926 OrderedDict([
927 ('access_method', 'ca_issuers'),
928 ('access_location', 'http://secure.globalsign.com/cacert/trustrootcatg2.crt')
929 ])
930 ]
931 ),
932 (
933 'globalsign_example_keys/SSL2.cer',
934 [
935 OrderedDict([
936 ('access_method', 'ocsp'),
937 ('access_location', 'http://ocsp.exampleovca.com/')
938 ]),
939 OrderedDict([
940 ('access_method', 'ca_issuers'),
941 ('access_location', 'http://secure.globalsign.com/cacert/trustrootcatg2.crt')
942 ])
943 ]
944 ),
945 (
946 'globalsign_example_keys/SSL3.cer',
947 [
948 OrderedDict([
949 ('access_method', 'ocsp'),
950 ('access_location', 'http://ocsp.exampleovca.com/')
951 ]),
952 OrderedDict([
953 ('access_method', 'ca_issuers'),
954 ('access_location', 'http://secure.globalsign.com/cacert/trustrootcatg2.crt')
955 ])
956 ]
957 ),
958 )
959
960 @data('authority_information_access_value_info')
961 def authority_information_access_value(self, relative_path, authority_information_access_value):
962 cert = self._load_cert(relative_path)
963 value = cert.authority_information_access_value
964 self.assertEqual(authority_information_access_value, value.native if value else None)
965
966 #pylint: disable=C0326
967 @staticmethod
968 def ocsp_no_check_value_info():
969 return (
970 ('keys/test-der.crt', None),
971 ('keys/test-inter-der.crt', None),
972 ('keys/test-third-der.crt', None),
973 ('geotrust_certs/GeoTrust_Universal_CA.crt', None),
974 ('geotrust_certs/GeoTrust_Primary_CA.crt', None),
975 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', None),
976 ('geotrust_certs/codex.crt', None),
977 ('lets_encrypt/isrgrootx1.pem', None),
978 ('lets_encrypt/letsencryptauthorityx1.pem', None),
979 ('lets_encrypt/letsencryptauthorityx2.pem', None),
980 ('globalsign_example_keys/IssuingCA-der.cer', None),
981 ('globalsign_example_keys/rootCA.cer', None),
982 ('globalsign_example_keys/SSL1.cer', None),
983 ('globalsign_example_keys/SSL2.cer', None),
984 ('globalsign_example_keys/SSL3.cer', None),
985 )
986
987 @data('ocsp_no_check_value_info')
988 def ocsp_no_check_value(self, relative_path, ocsp_no_check_value):
989 cert = self._load_cert(relative_path)
990 value = cert.ocsp_no_check_value
991 self.assertEqual(ocsp_no_check_value, value.native if value else None)
992
993 #pylint: disable=C0326
994 @staticmethod
995 def serial_number_info():
996 return (
997 ('keys/test-der.crt', 13683582341504654466),
998 ('keys/test-inter-der.crt', 1590137),
999 ('keys/test-third-der.crt', 2474902313),
1000 ('geotrust_certs/GeoTrust_Universal_CA.crt', 1),
1001 ('geotrust_certs/GeoTrust_Primary_CA.crt', 32798226551256963324313806436981982369),
1002 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', 146934555852773531829332059263122711876),
1003 ('geotrust_certs/codex.crt', 130338219198307073574879940486642352162),
1004 ('lets_encrypt/isrgrootx1.pem', 172886928669790476064670243504169061120),
1005 ('lets_encrypt/letsencryptauthorityx1.pem', 307817870430047279283060309415759825539),
1006 ('lets_encrypt/letsencryptauthorityx2.pem', 199666138109676817050168330923544141416),
1007 ('globalsign_example_keys/IssuingCA-der.cer', 43543335419752),
1008 ('globalsign_example_keys/rootCA.cer', 342514332211132),
1009 ('globalsign_example_keys/SSL1.cer', 425155524522),
1010 ('globalsign_example_keys/SSL2.cer', 425155524522),
1011 ('globalsign_example_keys/SSL3.cer', 425155524522),
1012 )
1013
1014 @data('serial_number_info')
1015 def serial_number(self, relative_path, serial_number):
1016 cert = self._load_cert(relative_path)
1017 self.assertEqual(serial_number, cert.serial_number)
1018
1019 #pylint: disable=C0326
1020 @staticmethod
1021 def key_identifier_info():
1022 return (
1023 ('keys/test-der.crt', b'\xbeB\x85=\xcc\xff\xe3\xf9(\x02\x8f~XV\xb4\xfd\x03\\\xeaK'),
1024 ('keys/test-inter-der.crt', b'\xd2\n\xfd.%\xd1\xb7!\xd7P~\xbb\xa4}\xbf4\xefR^\x02'),
1025 ('keys/test-third-der.crt', b'D8\xe0\xe0&\x85\xbf\x98\x86\xdc\x1b\xe1\x1d\xf520\xbe\xab\xac\r'),
1026 ('geotrust_certs/GeoTrust_Universal_CA.crt', b'\xda\xbb.\xaa\xb0\x0c\xb8\x88&Qt\\m\x03\xd3\xc0\xd8\x8fz\xd6'),
1027 ('geotrust_certs/GeoTrust_Primary_CA.crt', b',\xd5PA\x97\x15\x8b\xf0\x8f6a[J\xfbk\xd9\x99\xc93\x92'),
1028 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', b'\xde\xcf\\P\xb7\xae\x02\x1f\x15\x17\xaa\x16\xe8\r\xb5(\x9djZ\xf3'),
1029 ('geotrust_certs/codex.crt', None),
1030 ('lets_encrypt/isrgrootx1.pem', b'y\xb4Y\xe6{\xb6\xe5\xe4\x01s\x80\x08\x88\xc8\x1aX\xf6\xe9\x9bn'),
1031 ('lets_encrypt/letsencryptauthorityx1.pem', b'\xa8Jjc\x04}\xdd\xba\xe6\xd19\xb7\xa6Ee\xef\xf3\xa8\xec\xa1'),
1032 ('lets_encrypt/letsencryptauthorityx2.pem', b'\xc5\xb1\xabNL\xb1\xcdd0\x93~\xc1\x84\x99\x05\xab\xe6\x03\xe2%'),
1033 ('globalsign_example_keys/IssuingCA-der.cer', b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91"),
1034 ('globalsign_example_keys/rootCA.cer', b'd|\\\xe1\xe0`8NH\x9f\x05\xbcUc~?\xaeM\xf7\x1e'),
1035 ('globalsign_example_keys/SSL1.cer', b'\x94a\x04\x92\x04L\xe6\xffh\xa8\x96\xafy\xd2\xf32\x84\xae[\xcf'),
1036 ('globalsign_example_keys/SSL2.cer', b'\xd2\xb7\x15\x7fd0\x07(p\x83\xca(\xfa\x88\x96\xde\x9e\xfc\x8a='),
1037 ('globalsign_example_keys/SSL3.cer', b'G\xde\xa4\xe7\xea`\xe7\xee6\xc8\xf1\xd5\xb0F\x07\x07\x9eBh\xce'),
1038 )
1039
1040 @data('key_identifier_info')
1041 def key_identifier(self, relative_path, key_identifier):
1042 cert = self._load_cert(relative_path)
1043 self.assertEqual(key_identifier, cert.key_identifier)
1044
1045 #pylint: disable=C0326
1046 @staticmethod
1047 def issuer_serial_info():
1048 return (
1049 ('keys/test-der.crt', b'\xdd\x8a\x19x\xae`\x19=\xa7\xf8\x00\xb9\xfbx\xf8\xedu\xb8!\xf8\x8c\xdb\x1f\x99\'7w\x93\xb4\xa4\'\xa0:13683582341504654466'),
1050 ('keys/test-inter-der.crt', b'\xdd\x8a\x19x\xae`\x19=\xa7\xf8\x00\xb9\xfbx\xf8\xedu\xb8!\xf8\x8c\xdb\x1f\x99\'7w\x93\xb4\xa4\'\xa0:1590137'),
1051 ('keys/test-third-der.crt', b'\xed{\x9b\xbf\x9b\xdbd\xa4\xea\xf2#+H\x96\xcd\x80\x99\xf6\xecCM\x94\x07\x02\xe2\x18\xf3\x83\x8c8%\x01:2474902313'),
1052 ('geotrust_certs/GeoTrust_Universal_CA.crt', b'\xa1\x848\xf2\xe5w\xee\xec\xce\xfefJC+\xdf\x97\x7f\xd2Y\xe3\xdc\xa0D7~\x07\xd9\x9dzL@g:1'),
1053 ('geotrust_certs/GeoTrust_Primary_CA.crt', b'\xdcg\x0c\x80\x03\xb3D\xa0v\xe2\xee\xec\x8b\xd6\x82\x01\xf0\x13\x0cwT\xb4\x8f\x80\x0eT\x9d\xbf\xbf\xa4\x11\x80:32798226551256963324313806436981982369'),
1054 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', b'\xdcg\x0c\x80\x03\xb3D\xa0v\xe2\xee\xec\x8b\xd6\x82\x01\xf0\x13\x0cwT\xb4\x8f\x80\x0eT\x9d\xbf\xbf\xa4\x11\x80:146934555852773531829332059263122711876'),
1055 ('geotrust_certs/codex.crt', b'x\x12\xe0\x15\x00d;\xc3\xb9/\xf6\x13\n\xd8\xe2\xddY\xf7\xaf*=C\x01<\x86\xf5\x9f_\xab;e\xd1:130338219198307073574879940486642352162'),
1056 ('lets_encrypt/isrgrootx1.pem', b'\xf6\xdb/\xbd\x9d\xd8]\x92Y\xdd\xb3\xc6\xde}{/\xec?>\x0c\xef\x17a\xbc\xbf3 W\x1e-0\xf8:172886928669790476064670243504169061120'),
1057 ('lets_encrypt/letsencryptauthorityx1.pem', b'\xf6\xdb/\xbd\x9d\xd8]\x92Y\xdd\xb3\xc6\xde}{/\xec?>\x0c\xef\x17a\xbc\xbf3 W\x1e-0\xf8:307817870430047279283060309415759825539'),
1058 ('lets_encrypt/letsencryptauthorityx2.pem', b'\xf6\xdb/\xbd\x9d\xd8]\x92Y\xdd\xb3\xc6\xde}{/\xec?>\x0c\xef\x17a\xbc\xbf3 W\x1e-0\xf8:199666138109676817050168330923544141416'),
1059 ('globalsign_example_keys/IssuingCA-der.cer', b'\xd2\xe7\xca\x10\xc1\x91\x92Y^A\x11\xd3Rz\xd5\x93\x19wk\x11\xef\xaa\x9c\xad\x10\x8ak\x8a\x08-\x0c\xff:43543335419752'),
1060 ('globalsign_example_keys/rootCA.cer', b'\xd2\xe7\xca\x10\xc1\x91\x92Y^A\x11\xd3Rz\xd5\x93\x19wk\x11\xef\xaa\x9c\xad\x10\x8ak\x8a\x08-\x0c\xff:342514332211132'),
1061 ('globalsign_example_keys/SSL1.cer', b'_\xc0S\xb1\xeb}\xe3\x8e\xe4{\xdb\xd7\xe2\xd9}=3\x97|\x0c\x1e\xecz\xcc\x92u\x1f\xf0\x1d\xbc\x9f\xe4:425155524522'),
1062 ('globalsign_example_keys/SSL2.cer', b'_\xc0S\xb1\xeb}\xe3\x8e\xe4{\xdb\xd7\xe2\xd9}=3\x97|\x0c\x1e\xecz\xcc\x92u\x1f\xf0\x1d\xbc\x9f\xe4:425155524522'),
1063 ('globalsign_example_keys/SSL3.cer', b'_\xc0S\xb1\xeb}\xe3\x8e\xe4{\xdb\xd7\xe2\xd9}=3\x97|\x0c\x1e\xecz\xcc\x92u\x1f\xf0\x1d\xbc\x9f\xe4:425155524522'),
1064 )
1065
1066 @data('issuer_serial_info')
1067 def issuer_serial(self, relative_path, issuer_serial):
1068 cert = self._load_cert(relative_path)
1069 self.assertEqual(issuer_serial, cert.issuer_serial)
1070
1071 #pylint: disable=C0326
1072 @staticmethod
1073 def authority_key_identifier_info():
1074 return (
1075 ('keys/test-der.crt', b'\xbeB\x85=\xcc\xff\xe3\xf9(\x02\x8f~XV\xb4\xfd\x03\\\xeaK'),
1076 ('keys/test-inter-der.crt', b'\xbeB\x85=\xcc\xff\xe3\xf9(\x02\x8f~XV\xb4\xfd\x03\\\xeaK'),
1077 ('keys/test-third-der.crt', b'\xd2\n\xfd.%\xd1\xb7!\xd7P~\xbb\xa4}\xbf4\xefR^\x02'),
1078 ('geotrust_certs/GeoTrust_Universal_CA.crt', b'\xda\xbb.\xaa\xb0\x0c\xb8\x88&Qt\\m\x03\xd3\xc0\xd8\x8fz\xd6'),
1079 ('geotrust_certs/GeoTrust_Primary_CA.crt', None),
1080 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', b',\xd5PA\x97\x15\x8b\xf0\x8f6a[J\xfbk\xd9\x99\xc93\x92'),
1081 ('geotrust_certs/codex.crt', b'\xde\xcf\\P\xb7\xae\x02\x1f\x15\x17\xaa\x16\xe8\r\xb5(\x9djZ\xf3'),
1082 ('lets_encrypt/isrgrootx1.pem', None),
1083 ('lets_encrypt/letsencryptauthorityx1.pem', b'y\xb4Y\xe6{\xb6\xe5\xe4\x01s\x80\x08\x88\xc8\x1aX\xf6\xe9\x9bn'),
1084 ('lets_encrypt/letsencryptauthorityx2.pem', b'y\xb4Y\xe6{\xb6\xe5\xe4\x01s\x80\x08\x88\xc8\x1aX\xf6\xe9\x9bn'),
1085 ('globalsign_example_keys/IssuingCA-der.cer', b'd|\\\xe1\xe0`8NH\x9f\x05\xbcUc~?\xaeM\xf7\x1e'),
1086 ('globalsign_example_keys/rootCA.cer', None),
1087 ('globalsign_example_keys/SSL1.cer', b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91"),
1088 ('globalsign_example_keys/SSL2.cer', b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91"),
1089 ('globalsign_example_keys/SSL3.cer', b"'\xf8/\xe9]\xd7\r\xf4\xa8\xea\x87\x99=\xfd\x8e\xb3\x9e@\xd0\x91"),
1090 )
1091
1092 @data('authority_key_identifier_info')
1093 def authority_key_identifier(self, relative_path, authority_key_identifier):
1094 cert = self._load_cert(relative_path)
1095 self.assertEqual(authority_key_identifier, cert.authority_key_identifier)
1096
1097 #pylint: disable=C0326
1098 @staticmethod
1099 def authority_issuer_serial_info():
1100 return (
1101 ('keys/test-der.crt', b'\xdd\x8a\x19x\xae`\x19=\xa7\xf8\x00\xb9\xfbx\xf8\xedu\xb8!\xf8\x8c\xdb\x1f\x99\'7w\x93\xb4\xa4\'\xa0:13683582341504654466'),
1102 ('keys/test-inter-der.crt', None),
1103 ('keys/test-third-der.crt', None),
1104 ('geotrust_certs/GeoTrust_Universal_CA.crt', None),
1105 ('geotrust_certs/GeoTrust_Primary_CA.crt', None),
1106 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', None),
1107 ('geotrust_certs/codex.crt', None),
1108 ('lets_encrypt/isrgrootx1.pem', None),
1109 ('lets_encrypt/letsencryptauthorityx1.pem', None),
1110 ('lets_encrypt/letsencryptauthorityx2.pem', None),
1111 ('globalsign_example_keys/IssuingCA-der.cer', None),
1112 ('globalsign_example_keys/rootCA.cer', None),
1113 ('globalsign_example_keys/SSL1.cer', None),
1114 ('globalsign_example_keys/SSL2.cer', None),
1115 ('globalsign_example_keys/SSL3.cer', None),
1116 )
1117
1118 @data('authority_issuer_serial_info')
1119 def authority_issuer_serial(self, relative_path, authority_issuer_serial):
1120 cert = self._load_cert(relative_path)
1121 self.assertEqual(authority_issuer_serial, cert.authority_issuer_serial)
1122
1123 #pylint: disable=C0326
1124 @staticmethod
1125 def ocsp_urls_info():
1126 return (
1127 ('keys/test-der.crt', []),
1128 ('keys/test-inter-der.crt', []),
1129 ('keys/test-third-der.crt', []),
1130 ('geotrust_certs/GeoTrust_Universal_CA.crt', []),
1131 ('geotrust_certs/GeoTrust_Primary_CA.crt', []),
1132 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', ['http://g2.symcb.com']),
1133 ('geotrust_certs/codex.crt', ['http://gm.symcd.com']),
1134 ('lets_encrypt/isrgrootx1.pem', []),
1135 ('lets_encrypt/letsencryptauthorityx1.pem', ['http://ocsp.root-x1.letsencrypt.org/']),
1136 ('lets_encrypt/letsencryptauthorityx2.pem', ['http://ocsp.root-x1.letsencrypt.org/']),
1137 ('globalsign_example_keys/IssuingCA-der.cer', []),
1138 ('globalsign_example_keys/rootCA.cer', []),
1139 ('globalsign_example_keys/SSL1.cer', ['http://ocsp.exampleovca.com/']),
1140 ('globalsign_example_keys/SSL2.cer', ['http://ocsp.exampleovca.com/']),
1141 ('globalsign_example_keys/SSL3.cer', ['http://ocsp.exampleovca.com/']),
1142 )
1143
1144 @data('ocsp_urls_info')
1145 def ocsp_urls(self, relative_path, ocsp_url):
1146 cert = self._load_cert(relative_path)
1147 self.assertEqual(ocsp_url, cert.ocsp_urls)
1148
1149 #pylint: disable=C0326
1150 @staticmethod
1151 def crl_urls_info():
1152 return (
1153 ('keys/test-der.crt', []),
1154 ('keys/test-inter-der.crt', []),
1155 ('keys/test-third-der.crt', []),
1156 ('geotrust_certs/GeoTrust_Universal_CA.crt', []),
1157 ('geotrust_certs/GeoTrust_Primary_CA.crt', []),
1158 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', ['http://g1.symcb.com/GeoTrustPCA.crl']),
1159 ('geotrust_certs/codex.crt', ['http://gm.symcb.com/gm.crl']),
1160 ('lets_encrypt/isrgrootx1.pem', []),
1161 ('lets_encrypt/letsencryptauthorityx1.pem', ['http://crl.root-x1.letsencrypt.org']),
1162 ('lets_encrypt/letsencryptauthorityx2.pem', ['http://crl.root-x1.letsencrypt.org']),
1163 ('globalsign_example_keys/IssuingCA-der.cer', ['http://crl.globalsign.com/gs/trustrootcatg2.crl']),
1164 ('globalsign_example_keys/rootCA.cer', ['http://crl.globalsign.com/gs/trustrootcatg2.crl']),
1165 ('globalsign_example_keys/SSL1.cer', []),
1166 ('globalsign_example_keys/SSL2.cer', []),
1167 ('globalsign_example_keys/SSL3.cer', []),
1168 )
1169
1170 @data('crl_urls_info')
1171 def crl_urls(self, relative_path, crl_url):
1172 cert = self._load_cert(relative_path)
1173 self.assertEqual(crl_url, cert.crl_urls)
1174
1175 #pylint: disable=C0326
1176 @staticmethod
1177 def valid_domains_info():
1178 return (
1179 ('keys/test-der.crt', []),
1180 ('keys/test-inter-der.crt', []),
1181 ('keys/test-third-der.crt', []),
1182 ('geotrust_certs/GeoTrust_Universal_CA.crt', []),
1183 ('geotrust_certs/GeoTrust_Primary_CA.crt', []),
1184 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', []),
1185 ('geotrust_certs/codex.crt', ['codexns.io', 'dev.codexns.io', 'rc.codexns.io', 'packagecontrol.io', 'wbond.net']),
1186 ('lets_encrypt/isrgrootx1.pem', []),
1187 ('lets_encrypt/letsencryptauthorityx1.pem', []),
1188 ('lets_encrypt/letsencryptauthorityx2.pem', []),
1189 ('globalsign_example_keys/IssuingCA-der.cer', []),
1190 ('globalsign_example_keys/rootCA.cer', []),
1191 ('globalsign_example_keys/SSL1.cer', ['anything.example.com']),
1192 ('globalsign_example_keys/SSL2.cer', ['*.google.com', 'anything.example.com']),
1193 ('globalsign_example_keys/SSL3.cer', ['*.google.com']),
1194 )
1195
1196 @data('valid_domains_info')
1197 def valid_domains(self, relative_path, valid_domains):
1198 cert = self._load_cert(relative_path)
1199 self.assertEqual(valid_domains, cert.valid_domains)
1200
1201 #pylint: disable=C0326
1202 @staticmethod
1203 def valid_ips_info():
1204 return (
1205 ('keys/test-der.crt', []),
1206 ('keys/test-inter-der.crt', []),
1207 ('keys/test-third-der.crt', []),
1208 ('geotrust_certs/GeoTrust_Universal_CA.crt', []),
1209 ('geotrust_certs/GeoTrust_Primary_CA.crt', []),
1210 ('geotrust_certs/GeoTrust_EV_SSL_CA_-_G4.crt', []),
1211 ('geotrust_certs/codex.crt', []),
1212 ('lets_encrypt/isrgrootx1.pem', []),
1213 ('lets_encrypt/letsencryptauthorityx1.pem', []),
1214 ('lets_encrypt/letsencryptauthorityx2.pem', []),
1215 ('globalsign_example_keys/IssuingCA-der.cer', []),
1216 ('globalsign_example_keys/rootCA.cer', []),
1217 ('globalsign_example_keys/SSL1.cer', []),
1218 ('globalsign_example_keys/SSL2.cer', []),
1219 ('globalsign_example_keys/SSL3.cer', []),
1220 )
1221
1222 @data('valid_ips_info')
1223 def valid_ips(self, relative_path, crl_url):
1224 cert = self._load_cert(relative_path)
1225 self.assertEqual(crl_url, cert.valid_ips)
wbond8bb77d02015-07-13 17:44:29 -04001226
wbonde91513e2015-06-03 14:52:18 -04001227 def test_parse_certificate(self):
wbondaf1f5a82015-07-17 12:13:15 -04001228 cert = self._load_cert('keys/test-der.crt')
wbonde91513e2015-06-03 14:52:18 -04001229
1230 tbs_certificate = cert['tbs_certificate']
1231 signature = tbs_certificate['signature']
1232 issuer = tbs_certificate['issuer']
1233 validity = tbs_certificate['validity']
1234 subject = tbs_certificate['subject']
1235 subject_public_key_info = tbs_certificate['subject_public_key_info']
1236 subject_public_key_algorithm = subject_public_key_info['algorithm']
1237 subject_public_key = subject_public_key_info['public_key'].parsed
1238 extensions = tbs_certificate['extensions']
1239
1240 self.assertEqual(
1241 'v3',
1242 tbs_certificate['version'].native
1243 )
1244 self.assertEqual(
1245 13683582341504654466,
1246 tbs_certificate['serial_number'].native
1247 )
1248 self.assertEqual(
1249 'sha256_rsa',
1250 signature['algorithm'].native
1251 )
1252 self.assertEqual(
1253 None,
1254 signature['parameters'].native
1255 )
1256 self.assertEqual(
1257 OrderedDict([
1258 ('country_name', 'US'),
1259 ('state_or_province_name', 'Massachusetts'),
1260 ('locality_name', 'Newbury'),
1261 ('organization_name', 'Codex Non Sufficit LC'),
1262 ('organizational_unit_name', 'Testing'),
1263 ('common_name', 'Will Bond'),
1264 ('email_address', 'will@codexns.io'),
1265 ]),
1266 issuer.native
1267 )
1268 self.assertEqual(
1269 datetime(2015, 5, 6, 14, 37, 16, tzinfo=core.timezone.utc),
1270 validity['not_before'].native
1271 )
1272 self.assertEqual(
1273 datetime(2025, 5, 3, 14, 37, 16, tzinfo=core.timezone.utc),
1274 validity['not_after'].native
1275 )
1276 self.assertEqual(
1277 OrderedDict([
1278 ('country_name', 'US'),
1279 ('state_or_province_name', 'Massachusetts'),
1280 ('locality_name', 'Newbury'),
1281 ('organization_name', 'Codex Non Sufficit LC'),
1282 ('organizational_unit_name', 'Testing'),
1283 ('common_name', 'Will Bond'),
1284 ('email_address', 'will@codexns.io'),
1285 ]),
1286 subject.native
1287 )
1288 self.assertEqual(
1289 'rsa',
1290 subject_public_key_algorithm['algorithm'].native
1291 )
1292 self.assertEqual(
1293 None,
1294 subject_public_key_algorithm['parameters'].native
1295 )
1296 self.assertEqual(
1297 23903990516906431865559598284199534387004799030432486061102966678620221767754702651554142956492614440585611990224871381291841413369032752409360196079700921141819811294444393525264295297988924243231844876926173670633422654261873814968313363171188082579071492839040415373948505938897419917635370450127498164824808630475648771544810334682447182123219422360569466851807131368135806769502898151721274383486320505905826683946456552230958810028663378886363555981449715929872558073101554364803925363048965464124465016494920967179276744892632783712377912841537032383450409486298694116013299423220523450956288827030007092359007,
1298 subject_public_key['modulus'].native
1299 )
1300 self.assertEqual(
1301 65537,
1302 subject_public_key['public_exponent'].native
1303 )
1304 self.assertEqual(
1305 None,
1306 tbs_certificate['issuer_unique_id'].native
1307 )
1308 self.assertIsInstance(
1309 tbs_certificate['issuer_unique_id'],
1310 core.NoValue
1311 )
1312 self.assertEqual(
1313 None,
1314 tbs_certificate['subject_unique_id'].native
1315 )
1316 self.assertIsInstance(
1317 tbs_certificate['subject_unique_id'],
1318 core.NoValue
1319 )
1320
1321 self.maxDiff = None
1322 for extension in extensions:
1323 self.assertIsInstance(
1324 extension,
1325 x509.Extension
1326 )
1327 self.assertEqual(
1328 [
1329 OrderedDict([
1330 ('extn_id', 'key_identifier'),
1331 ('critical', False),
1332 ('extn_value', b'\xBE\x42\x85\x3D\xCC\xFF\xE3\xF9\x28\x02\x8F\x7E\x58\x56\xB4\xFD\x03\x5C\xEA\x4B'),
1333 ]),
1334 OrderedDict([
1335 ('extn_id', 'authority_key_identifier'),
1336 ('critical', False),
1337 (
1338 'extn_value',
1339 OrderedDict([
1340 ('key_identifier', b'\xBE\x42\x85\x3D\xCC\xFF\xE3\xF9\x28\x02\x8F\x7E\x58\x56\xB4\xFD\x03\x5C\xEA\x4B'),
1341 (
1342 'authority_cert_issuer',
1343 [
1344 OrderedDict([
1345 ('country_name', 'US'),
1346 ('state_or_province_name', 'Massachusetts'),
1347 ('locality_name', 'Newbury'),
1348 ('organization_name', 'Codex Non Sufficit LC'),
1349 ('organizational_unit_name', 'Testing'),
1350 ('common_name', 'Will Bond'),
1351 ('email_address', 'will@codexns.io'),
1352 ])
1353 ]
1354 ),
1355 ('authority_cert_serial_number', 13683582341504654466),
1356 ])
1357 ),
1358 ]),
1359 OrderedDict([
1360 ('extn_id', 'basic_constraints'),
1361 ('critical', False),
1362 (
1363 'extn_value',
1364 OrderedDict([
1365 ('ca', True),
1366 ('path_len_constraint', None)
1367 ])
1368 ),
1369 ]),
1370 ],
1371 extensions.native
1372 )
1373
1374 def test_parse_dsa_certificate(self):
wbondaf1f5a82015-07-17 12:13:15 -04001375 cert = self._load_cert('keys/test-dsa-der.crt')
wbonde91513e2015-06-03 14:52:18 -04001376
1377 tbs_certificate = cert['tbs_certificate']
1378 signature = tbs_certificate['signature']
1379 issuer = tbs_certificate['issuer']
1380 validity = tbs_certificate['validity']
1381 subject = tbs_certificate['subject']
1382 subject_public_key_info = tbs_certificate['subject_public_key_info']
1383 subject_public_key_algorithm = subject_public_key_info['algorithm']
1384 subject_public_key = subject_public_key_info['public_key'].parsed
1385 extensions = tbs_certificate['extensions']
1386
1387 self.assertEqual(
1388 'v3',
1389 tbs_certificate['version'].native
1390 )
1391 self.assertEqual(
1392 14308214745771946523,
1393 tbs_certificate['serial_number'].native
1394 )
1395 self.assertEqual(
1396 'sha256_dsa',
1397 signature['algorithm'].native
1398 )
1399 self.assertEqual(
1400 None,
1401 signature['parameters'].native
1402 )
1403 self.assertEqual(
1404 OrderedDict([
1405 ('country_name', 'US'),
1406 ('state_or_province_name', 'Massachusetts'),
1407 ('locality_name', 'Newbury'),
1408 ('organization_name', 'Codex Non Sufficit LC'),
1409 ('organizational_unit_name', 'Testing'),
1410 ('common_name', 'Will Bond'),
1411 ('email_address', 'will@codexns.io'),
1412 ]),
1413 issuer.native
1414 )
1415 self.assertEqual(
1416 datetime(2015, 5, 20, 13, 9, 2, tzinfo=core.timezone.utc),
1417 validity['not_before'].native
1418 )
1419 self.assertEqual(
1420 datetime(2025, 5, 17, 13, 9, 2, tzinfo=core.timezone.utc),
1421 validity['not_after'].native
1422 )
1423 self.assertEqual(
1424 OrderedDict([
1425 ('country_name', 'US'),
1426 ('state_or_province_name', 'Massachusetts'),
1427 ('locality_name', 'Newbury'),
1428 ('organization_name', 'Codex Non Sufficit LC'),
1429 ('organizational_unit_name', 'Testing'),
1430 ('common_name', 'Will Bond'),
1431 ('email_address', 'will@codexns.io'),
1432 ]),
1433 subject.native
1434 )
1435 self.assertEqual(
1436 'dsa',
1437 subject_public_key_algorithm['algorithm'].native
1438 )
1439 self.assertEqual(
1440 OrderedDict([
1441 ('p', 4511743893397705393934377497936985478231822206263141826261443300639402520800626925517264115785551703273809312112372693877437137848393530691841757974971843334497076835630893064661599193178307024379015589119302113551197423138934242435710226975119594589912289060014025377813473273600967729027125618396732574594753039493158066887433778053086408525146692226448554390096911703556213619406958876388642882534250747780313634767409586007581976273681005928967585750017105562145167146445061803488570714706090280814293902464230717946651489964409785146803791743658888866280873858000476717727810363942159874283767926511678640730707887895260274767195555813448140889391762755466967436731106514029224490921857229134393798015954890071206959203407845438863870686180087606429828973298318856683615900474921310376145478859687052812749087809700610549251964102790514588562086548577933609968589710807989944739877028770343142449461177732058649962678857),
1442 ('q', 71587850165936478337655415373676526523562874562337607790945426056266440596923),
1443 ('g', 761437146067908309288345767887973163494473925243194806582679580640442238588269326525839153095505341738937595419375068472941615006110237832663093084973431440436421580371384720052414080562019831325744042316268714195397974084616335082272743706567701546951285088540646372701485690904535540223121118329044403681933304838754517522024738251994717369464179515923093116622352823578284891812676662979104509631349201801577889230316128523885862472086364717411346341249139971907827526291913249445756671582283459372536334490171231311487207683108274785825764378203622999309355578169139646003751751448501475767709869676880946562283552431757983801739671783678927397420797147373441051876558068212062253171347849380506793433921881336652424898488378657239798694995315456959568806256079056461448199493507273882763491729787817044805150879660784158902456811649964987582162907020243296662602990514615480712948126671999033658064244112238138589732202),
1444 ]),
1445 subject_public_key_algorithm['parameters'].native
1446 )
1447 self.assertEqual(
1448 934231235067929794039535952071098031636053793876274937162425423023735221571983693370780054696865229184537343792766496068557051933738826401423094028670222490622041397241325320965905259541032379046252395145258594355589801644789631904099105867133976990593761395721476198083091062806327384261369876465927159169400428623265291958463077792777155465482611741502621885386691681062128487785344975981628995609792181581218570320181053055516069553767918513262908069925035292416868414952256645902605335068760774106734518308281769128146479819566784704033671969858507248124850451414380441279385481154336362988505436125981975735568289420374790767927084033441728922597082155884801013899630856890463962357814273014111039522903328923758417820349377075487103441305806369234738881875734407495707878637895190993370257589211331043479113328811265005530361001980539377903738453549980082795009589559114091215518866106998956304437954236070776810740036,
1449 subject_public_key.native
1450 )
1451 self.assertEqual(
1452 None,
1453 tbs_certificate['issuer_unique_id'].native
1454 )
1455 self.assertIsInstance(
1456 tbs_certificate['issuer_unique_id'],
1457 core.NoValue
1458 )
1459 self.assertEqual(
1460 None,
1461 tbs_certificate['subject_unique_id'].native
1462 )
1463 self.assertIsInstance(
1464 tbs_certificate['subject_unique_id'],
1465 core.NoValue
1466 )
1467
1468 self.maxDiff = None
1469 for extension in extensions:
1470 self.assertIsInstance(
1471 extension,
1472 x509.Extension
1473 )
1474 self.assertEqual(
1475 [
1476 OrderedDict([
1477 ('extn_id', 'key_identifier'),
1478 ('critical', False),
1479 ('extn_value', b'\x81\xA3\x37\x86\xF9\x99\x28\xF2\x74\x70\x60\x87\xF2\xD3\x7E\x8D\x19\x61\xA8\xBE'),
1480 ]),
1481 OrderedDict([
1482 ('extn_id', 'authority_key_identifier'),
1483 ('critical', False),
1484 (
1485 'extn_value',
1486 OrderedDict([
1487 ('key_identifier', b'\x81\xA3\x37\x86\xF9\x99\x28\xF2\x74\x70\x60\x87\xF2\xD3\x7E\x8D\x19\x61\xA8\xBE'),
1488 ('authority_cert_issuer', None),
1489 ('authority_cert_serial_number', None),
1490 ])
1491 ),
1492 ]),
1493 OrderedDict([
1494 ('extn_id', 'basic_constraints'),
1495 ('critical', False),
1496 (
1497 'extn_value',
1498 OrderedDict([
1499 ('ca', True),
1500 ('path_len_constraint', None)
1501 ])
1502 ),
1503 ]),
1504 ],
1505 extensions.native
1506 )
1507
1508 def test_parse_ec_certificate(self):
wbondaf1f5a82015-07-17 12:13:15 -04001509 cert = self._load_cert('keys/test-ec-der.crt')
wbonde91513e2015-06-03 14:52:18 -04001510
1511 tbs_certificate = cert['tbs_certificate']
1512 signature = tbs_certificate['signature']
1513 issuer = tbs_certificate['issuer']
1514 validity = tbs_certificate['validity']
1515 subject = tbs_certificate['subject']
1516 subject_public_key_info = tbs_certificate['subject_public_key_info']
1517 subject_public_key_algorithm = subject_public_key_info['algorithm']
1518 public_key_params = subject_public_key_info['algorithm']['parameters'].chosen
1519 field_id = public_key_params['field_id']
1520 curve = public_key_params['curve']
1521 subject_public_key = subject_public_key_info['public_key'].parsed
1522 extensions = tbs_certificate['extensions']
1523
1524 self.assertEqual(
1525 'v3',
1526 tbs_certificate['version'].native
1527 )
1528 self.assertEqual(
1529 15854128451240978884,
1530 tbs_certificate['serial_number'].native
1531 )
1532 self.assertEqual(
1533 'sha256_ecdsa',
1534 signature['algorithm'].native
1535 )
1536 self.assertEqual(
1537 None,
1538 signature['parameters'].native
1539 )
1540 self.assertEqual(
1541 OrderedDict([
1542 ('country_name', 'US'),
1543 ('state_or_province_name', 'Massachusetts'),
1544 ('locality_name', 'Newbury'),
1545 ('organization_name', 'Codex Non Sufficit LC'),
1546 ('organizational_unit_name', 'Testing'),
1547 ('common_name', 'Will Bond'),
1548 ('email_address', 'will@codexns.io'),
1549 ]),
1550 issuer.native
1551 )
1552 self.assertEqual(
1553 datetime(2015, 5, 20, 12, 56, 46, tzinfo=core.timezone.utc),
1554 validity['not_before'].native
1555 )
1556 self.assertEqual(
1557 datetime(2025, 5, 17, 12, 56, 46, tzinfo=core.timezone.utc),
1558 validity['not_after'].native
1559 )
1560 self.assertEqual(
1561 OrderedDict([
1562 ('country_name', 'US'),
1563 ('state_or_province_name', 'Massachusetts'),
1564 ('locality_name', 'Newbury'),
1565 ('organization_name', 'Codex Non Sufficit LC'),
1566 ('organizational_unit_name', 'Testing'),
1567 ('common_name', 'Will Bond'),
1568 ('email_address', 'will@codexns.io'),
1569 ]),
1570 subject.native
1571 )
1572 self.assertEqual(
wbond680cba12015-07-01 23:53:54 -04001573 'ec',
wbonde91513e2015-06-03 14:52:18 -04001574 subject_public_key_algorithm['algorithm'].native
1575 )
1576 self.assertEqual(
1577 'ecdpVer1',
1578 public_key_params['version'].native
1579 )
1580 self.assertEqual(
1581 'prime_field',
1582 field_id['field_type'].native
1583 )
1584 self.assertEqual(
1585 115792089210356248762697446949407573530086143415290314195533631308867097853951,
1586 field_id['parameters'].native
1587 )
1588 self.assertEqual(
1589 b'\xFF\xFF\xFF\xFF\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFC',
1590 curve['a'].native
1591 )
1592 self.assertEqual(
1593 b'\x5A\xC6\x35\xD8\xAA\x3A\x93\xE7\xB3\xEB\xBD\x55\x76\x98\x86\xBC\x65\x1D\x06\xB0\xCC\x53\xB0\xF6\x3B\xCE\x3C\x3E\x27\xD2\x60\x4B',
1594 curve['b'].native
1595 )
1596 self.assertEqual(
1597 b'\xC4\x9D\x36\x08\x86\xE7\x04\x93\x6A\x66\x78\xE1\x13\x9D\x26\xB7\x81\x9F\x7E\x90',
1598 curve['seed'].native
1599 )
1600 self.assertEqual(
1601 b'\x04\x6B\x17\xD1\xF2\xE1\x2C\x42\x47\xF8\xBC\xE6\xE5\x63\xA4\x40\xF2\x77\x03\x7D\x81\x2D\xEB\x33\xA0\xF4\xA1\x39\x45\xD8\x98\xC2\x96\x4F\xE3\x42\xE2\xFE\x1A\x7F\x9B\x8E\xE7\xEB\x4A\x7C\x0F\x9E\x16\x2B\xCE\x33\x57\x6B\x31\x5E\xCE\xCB\xB6\x40\x68\x37\xBF\x51\xF5',
1602 public_key_params['base'].native
1603 )
1604 self.assertEqual(
1605 115792089210356248762697446949407573529996955224135760342422259061068512044369,
1606 public_key_params['order'].native
1607 )
1608 self.assertEqual(
1609 1,
1610 public_key_params['cofactor'].native
1611 )
1612 self.assertEqual(
1613 None,
1614 public_key_params['hash'].native
1615 )
1616 self.assertEqual(
1617 b'G\x9f\xcbs$\x1d\xc9\xdd\xd1-\xf1:\x9f\xb7\x04\xde \xd0X\x00\x93T\xf6\x89\xc7/\x87+\xf7\xf9=;4\xed\x9e{\x0e=WB\xdfx\x03\x0b\xcc1\xc6\x03\xd7\x9f`\x01',
1618 subject_public_key.native
1619 )
1620 self.assertEqual(
1621 None,
1622 tbs_certificate['issuer_unique_id'].native
1623 )
1624 self.assertIsInstance(
1625 tbs_certificate['issuer_unique_id'],
1626 core.NoValue
1627 )
1628 self.assertEqual(
1629 None,
1630 tbs_certificate['subject_unique_id'].native
1631 )
1632 self.assertIsInstance(
1633 tbs_certificate['subject_unique_id'],
1634 core.NoValue
1635 )
1636
1637 self.maxDiff = None
1638 for extension in extensions:
1639 self.assertIsInstance(
1640 extension,
1641 x509.Extension
1642 )
1643 self.assertEqual(
1644 [
1645 OrderedDict([
1646 ('extn_id', 'key_identifier'),
1647 ('critical', False),
1648 ('extn_value', b'\x54\xAA\x54\x70\x6C\x34\x1A\x6D\xEB\x5D\x97\xD7\x1E\xFC\xD5\x24\x3C\x8A\x0E\xD7'),
1649 ]),
1650 OrderedDict([
1651 ('extn_id', 'authority_key_identifier'),
1652 ('critical', False),
1653 (
1654 'extn_value',
1655 OrderedDict([
1656 ('key_identifier', b'\x54\xAA\x54\x70\x6C\x34\x1A\x6D\xEB\x5D\x97\xD7\x1E\xFC\xD5\x24\x3C\x8A\x0E\xD7'),
1657 ('authority_cert_issuer', None),
1658 ('authority_cert_serial_number', None),
1659 ])
1660 ),
1661 ]),
1662 OrderedDict([
1663 ('extn_id', 'basic_constraints'),
1664 ('critical', False),
1665 (
1666 'extn_value',
1667 OrderedDict([
1668 ('ca', True),
1669 ('path_len_constraint', None)
1670 ])
1671 ),
1672 ]),
1673 ],
1674 extensions.native
1675 )