blob: 035fa87f7f3c1e25288cccb75f305a62ec429018 [file] [log] [blame]
Paul Kehrer016e08a2014-11-26 09:41:18 -10001X.509
2=====
3
Paul Kehrera9d78c12014-11-26 10:59:03 -10004.. currentmodule:: cryptography.x509
Paul Kehrer016e08a2014-11-26 09:41:18 -10005
Paul Kehrerd26c4db2015-03-15 15:36:24 -05006.. testsetup::
7
8 pem_req_data = b"""
9 -----BEGIN CERTIFICATE REQUEST-----
10 MIIC0zCCAbsCAQAwWTELMAkGA1UEBhMCVVMxETAPBgNVBAgMCElsbGlub2lzMRAw
11 DgYDVQQHDAdDaGljYWdvMREwDwYDVQQKDAhyNTA5IExMQzESMBAGA1UEAwwJaGVs
12 bG8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqhZx+Mo9VRd9
13 vsnWWa6NBCws21rZ0+1B/JGgB4hDsZS7iDE4Bj5z4idheFRtl8bBbdjPknq7BfoF
14 8v15Zq/Zv7i2xMSDL+LUrTBZezRd4bRTGqCm6YJ5EYkhqdcqeZleHCFImguHoq1J
15 Fh0+kObQrTHXw3ZP57a3o1IvyIUA3nNoCBL0QQhwBXaDXOojMKNR+bqB5ve8GS1y
16 Elr0AM/+cJsfaIahNQUgFKx3Eu3GeEOMKYOAG1lycgdQdmTUybLrT3U7vkClTseM
17 xHg1r5En7ALjONIhqRuq3rddYahrP8HXozb3zUy3cJ7P6IeaosuvNzvMXOX9P6HD
18 Ha9urDAJ1wIDAQABoDUwMwYJKoZIhvcNAQkOMSYwJDAiBgNVHREEGzAZggl3b3Js
19 ZC5jb22CDHdoYXRldmVyLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEAS4Ro6h+z52SK
20 YSLCYARpnEu/rmh4jdqndt8naqcNb6uLx9mlKZ2W9on9XDjnSdQD9q+ZP5aZfESw
21 R0+rJhW9ZrNa/g1pt6M24ihclHYDAxYMWxT1z/TXXGM3TmZZ6gfYlNE1kkBuODHa
22 UYsR/1Ht1E1EsmmUimt2n+zQR2K8T9Coa+boaUW/GsTEuz1aaJAkj5ZvTDiIhRG4
23 AOCqFZOLAQmCCNgJnnspD9hDz/Ons085LF5wnYjN4/Nsk5tS6AGs3xjZ3jPoOGGn
24 82WQ9m4dBGoVDZXsobVTaN592JEYwN5iu72zRn7Einb4V4H5y3yD2dD4yWPlt4pk
25 5wFkeYsZEA==
26 -----END CERTIFICATE REQUEST-----
27 """.strip()
28
Paul Kehrerd3dafbd2015-03-15 16:24:18 -050029 pem_data = b"""
30 -----BEGIN CERTIFICATE-----
31 MIIDfDCCAmSgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJVUzEf
32 MB0GA1UEChMWVGVzdCBDZXJ0aWZpY2F0ZXMgMjAxMTEVMBMGA1UEAxMMVHJ1c3Qg
33 QW5jaG9yMB4XDTEwMDEwMTA4MzAwMFoXDTMwMTIzMTA4MzAwMFowQDELMAkGA1UE
34 BhMCVVMxHzAdBgNVBAoTFlRlc3QgQ2VydGlmaWNhdGVzIDIwMTExEDAOBgNVBAMT
35 B0dvb2QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCQWJpHYo37
36 Xfb7oJSPe+WvfTlzIG21WQ7MyMbGtK/m8mejCzR6c+f/pJhEH/OcDSMsXq8h5kXa
37 BGqWK+vSwD/Pzp5OYGptXmGPcthDtAwlrafkGOS4GqIJ8+k9XGKs+vQUXJKsOk47
38 RuzD6PZupq4s16xaLVqYbUC26UcY08GpnoLNHJZS/EmXw1ZZ3d4YZjNlpIpWFNHn
39 UGmdiGKXUPX/9H0fVjIAaQwjnGAbpgyCumWgzIwPpX+ElFOUr3z7BoVnFKhIXze+
40 VmQGSWxZxvWDUN90Ul0tLEpLgk3OVxUB4VUGuf15OJOpgo1xibINPmWt14Vda2N9
41 yrNKloJGZNqLAgMBAAGjfDB6MB8GA1UdIwQYMBaAFOR9X9FclYYILAWuvnW2ZafZ
42 XahmMB0GA1UdDgQWBBRYAYQkG7wrUpRKPaUQchRR9a86yTAOBgNVHQ8BAf8EBAMC
43 AQYwFwYDVR0gBBAwDjAMBgpghkgBZQMCATABMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
44 KoZIhvcNAQELBQADggEBADWHlxbmdTXNwBL/llwhQqwnazK7CC2WsXBBqgNPWj7m
45 tvQ+aLG8/50Qc2Sun7o2VnwF9D18UUe8Gj3uPUYH+oSI1vDdyKcjmMbKRU4rk0eo
46 3UHNDXwqIVc9CQS9smyV+x1HCwL4TTrq+LXLKx/qVij0Yqk+UJfAtrg2jnYKXsCu
47 FMBQQnWCGrwa1g1TphRp/RmYHnMynYFmZrXtzFz+U9XEA7C+gPq4kqDI/iVfIT1s
48 6lBtdB50lrDVwl2oYfAvW/6sC2se2QleZidUmrziVNP4oEeXINokU6T6p//HM1FG
49 QYw2jOvpKcKtWCSAnegEbgsGYzATKjmPJPJ0npHFqzM=
50 -----END CERTIFICATE-----
51 """.strip()
52
53X.509 is an ITU-T standard for a `public key infrastructure`_. X.509v3 is
54defined in :rfc:`5280` (which obsoletes :rfc:`2459` and :rfc:`3280`). X.509
55certificates are commonly used in protocols like `TLS`_.
Paul Kehrerb2de9482014-12-11 14:54:48 -060056
57Loading Certificates
58~~~~~~~~~~~~~~~~~~~~
Paul Kehrer016e08a2014-11-26 09:41:18 -100059
60.. function:: load_pem_x509_certificate(data, backend)
61
62 .. versionadded:: 0.7
63
Paul Kehrere76cd272014-12-14 19:00:51 -060064 Deserialize a certificate from PEM encoded data. PEM certificates are
65 base64 decoded and have delimiters that look like
66 ``-----BEGIN CERTIFICATE-----``.
Paul Kehrer016e08a2014-11-26 09:41:18 -100067
68 :param bytes data: The PEM encoded certificate data.
69
70 :param backend: A backend supporting the
71 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
72 interface.
73
Paul Kehrere76cd272014-12-14 19:00:51 -060074 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -100075
76.. function:: load_der_x509_certificate(data, backend)
77
78 .. versionadded:: 0.7
79
Paul Kehrere76cd272014-12-14 19:00:51 -060080 Deserialize a certificate from DER encoded data. DER is a binary format
Paul Kehrer92aac382014-12-15 16:25:28 -060081 and is commonly found in files with the ``.cer`` extension (although file
82 extensions are not a guarantee of encoding type).
Paul Kehrer016e08a2014-11-26 09:41:18 -100083
84 :param bytes data: The DER encoded certificate data.
85
86 :param backend: A backend supporting the
87 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
88 interface.
89
Paul Kehrere76cd272014-12-14 19:00:51 -060090 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -100091
Paul Kehrer016e08a2014-11-26 09:41:18 -100092.. doctest::
93
Paul Kehrercc8a26e2014-12-16 12:40:16 -060094 >>> from cryptography import x509
Paul Kehrer016e08a2014-11-26 09:41:18 -100095 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc8a26e2014-12-16 12:40:16 -060096 >>> cert = x509.load_pem_x509_certificate(pem_data, default_backend())
Paul Kehrer016e08a2014-11-26 09:41:18 -100097 >>> cert.serial
98 2
99
Paul Kehrera1a1f232015-03-15 15:34:35 -0500100Loading Certificate Signing Requests
101~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600102
Paul Kehrer31e39882015-03-11 11:37:04 -0500103.. function:: load_pem_x509_csr(data, backend)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600104
105 .. versionadded:: 0.9
106
Paul Kehrera1a1f232015-03-15 15:34:35 -0500107 Deserialize a certificate signing request (CSR) from PEM encoded data. PEM
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500108 requests are base64 decoded and have delimiters that look like
Paul Kehrerd3dafbd2015-03-15 16:24:18 -0500109 ``-----BEGIN CERTIFICATE REQUEST-----``. This format is also known as
110 PKCS#10.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600111
112 :param bytes data: The PEM encoded request data.
113
114 :param backend: A backend supporting the
115 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
116 interface.
117
Paul Kehrera1a1f232015-03-15 15:34:35 -0500118 :returns: An instance of
119 :class:`~cryptography.x509.CertificateSigningRequest`.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600120
Paul Kehrer1effb6e2015-03-30 15:05:59 -0500121.. function:: load_der_x509_csr(data, backend)
122
123 .. versionadded:: 0.9
124
125 Deserialize a certificate signing request (CSR) from DER encoded data. DER
126 is a binary format and is not commonly used with CSRs.
127
128 :param bytes data: The DER encoded request data.
129
130 :param backend: A backend supporting the
131 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
132 interface.
133
134 :returns: An instance of
135 :class:`~cryptography.x509.CertificateSigningRequest`.
136
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600137.. doctest::
138
139 >>> from cryptography import x509
140 >>> from cryptography.hazmat.backends import default_backend
141 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500142 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
143 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600144 True
145
Paul Kehrere76cd272014-12-14 19:00:51 -0600146X.509 Certificate Object
147~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerb2de9482014-12-11 14:54:48 -0600148
Paul Kehrere76cd272014-12-14 19:00:51 -0600149.. class:: Certificate
Paul Kehrerb2de9482014-12-11 14:54:48 -0600150
151 .. versionadded:: 0.7
152
153 .. attribute:: version
154
Paul Kehrere76cd272014-12-14 19:00:51 -0600155 :type: :class:`~cryptography.x509.Version`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600156
Paul Kehrere76cd272014-12-14 19:00:51 -0600157 The certificate version as an enumeration. Version 3 certificates are
158 the latest version and also the only type you should see in practice.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600159
Alex Gaynor89c4dc82014-12-16 16:49:33 -0800160 :raises cryptography.x509.InvalidVersion: If the version in the
Alex Gaynor6d7ab4c2014-12-16 16:50:33 -0800161 certificate is not a known
162 :class:`X.509 version <cryptography.x509.Version>`.
Paul Kehrer92aac382014-12-15 16:25:28 -0600163
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600164 .. doctest::
165
166 >>> cert.version
167 <Version.v3: 2>
168
Paul Kehrerb2de9482014-12-11 14:54:48 -0600169 .. method:: fingerprint(algorithm)
170
171 :param algorithm: The
Paul Kehrer601278a2015-02-12 12:51:00 -0600172 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600173 that will be used to generate the fingerprint.
174
175 :return bytes: The fingerprint using the supplied hash algorithm as
176 bytes.
177
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600178 .. doctest::
179
180 >>> from cryptography.hazmat.primitives import hashes
181 >>> cert.fingerprint(hashes.SHA256())
Paul Kehrer78a81502014-12-16 14:47:52 -0600182 '\x86\xd2\x187Gc\xfc\xe7}[+E9\x8d\xb4\x8f\x10\xe5S\xda\x18u\xbe}a\x03\x08[\xac\xa04?'
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600183
Paul Kehrerb2de9482014-12-11 14:54:48 -0600184 .. attribute:: serial
185
186 :type: int
187
188 The serial as a Python integer.
189
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600190 .. doctest::
191
192 >>> cert.serial
193 2
194
Paul Kehrerb2de9482014-12-11 14:54:48 -0600195 .. method:: public_key()
196
197 :type:
Alex Stapletonf79c2312014-12-30 12:50:14 +0000198 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
Paul Kehrer45efdbc2015-02-12 10:58:22 -0600199 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
200 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600201
202 The public key associated with the certificate.
203
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600204 .. doctest::
205
Alex Stapletonf79c2312014-12-30 12:50:14 +0000206 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600207 >>> public_key = cert.public_key()
Alex Stapletonf79c2312014-12-30 12:50:14 +0000208 >>> isinstance(public_key, rsa.RSAPublicKey)
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600209 True
210
Paul Kehrerb2de9482014-12-11 14:54:48 -0600211 .. attribute:: not_valid_before
212
213 :type: :class:`datetime.datetime`
214
Paul Kehrer78a81502014-12-16 14:47:52 -0600215 A naïve datetime representing the beginning of the validity period for
216 the certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600217
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600218 .. doctest::
219
220 >>> cert.not_valid_before
221 datetime.datetime(2010, 1, 1, 8, 30)
222
Paul Kehrerb2de9482014-12-11 14:54:48 -0600223 .. attribute:: not_valid_after
224
225 :type: :class:`datetime.datetime`
226
Paul Kehrer78a81502014-12-16 14:47:52 -0600227 A naïve datetime representing the end of the validity period for the
228 certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600229
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600230 .. doctest::
231
232 >>> cert.not_valid_after
233 datetime.datetime(2030, 12, 31, 8, 30)
234
Paul Kehrer719d5362015-01-01 20:03:52 -0600235 .. attribute:: issuer
236
237 .. versionadded:: 0.8
238
239 :type: :class:`Name`
240
241 The :class:`Name` of the issuer.
242
243 .. attribute:: subject
244
245 .. versionadded:: 0.8
246
247 :type: :class:`Name`
248
249 The :class:`Name` of the subject.
250
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600251 .. attribute:: signature_hash_algorithm
Paul Kehrer56da2a52015-02-11 23:35:07 -0600252
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600253 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrer56da2a52015-02-11 23:35:07 -0600254
Paul Kehrere612ec72015-02-16 14:33:35 -0600255 Returns the
Paul Kehrer71d40c62015-02-19 08:21:04 -0600256 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600257 was used in signing this certificate.
Paul Kehrer56da2a52015-02-11 23:35:07 -0600258
259 .. doctest::
260
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600261 >>> from cryptography.hazmat.primitives import hashes
262 >>> isinstance(cert.signature_hash_algorithm, hashes.SHA256)
263 True
Paul Kehrer719d5362015-01-01 20:03:52 -0600264
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500265 .. attribute:: extensions
266
267 :type: :class:`Extensions`
268
269 The extensions encoded in the certificate.
270
271 :raises cryptography.x509.DuplicateExtension: If more than one
272 extension of the same type is found within the certificate.
273
Paul Kehrerd8fc0be2015-04-21 08:31:10 -0500274 :raises cryptography.x509.UnsupportedExtension: If the certificate
275 contains an extension that is not supported.
276
Paul Kehrerbed07352015-04-21 08:31:10 -0500277 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
278 contains a general name that is not supported.
279
Paul Kehrerfa56a232015-03-17 13:14:03 -0500280 .. doctest::
281
282 >>> for ext in cert.extensions:
283 ... print(ext)
Paul Kehrercbfb1012015-04-10 20:57:20 -0400284 <Extension(oid=<ObjectIdentifier(oid=2.5.29.14, name=subjectKeyIdentifier)>, critical=False, value=<SubjectKeyIdentifier(digest='X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9')>)>
Paul Kehrerb511ba82015-04-15 11:22:48 -0400285 <Extension(oid=<ObjectIdentifier(oid=2.5.29.15, name=keyUsage)>, critical=True, value=<KeyUsage(digital_signature=False, content_commitment=False, key_encipherment=False, data_encipherment=False, key_agreement=False, key_cert_sign=True, crl_sign=True, encipher_only=None, decipher_only=None)>)>
Paul Kehrerfa56a232015-03-17 13:14:03 -0500286 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
287
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500288X.509 CSR (Certificate Signing Request) Object
289~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600290
Paul Kehrera1a1f232015-03-15 15:34:35 -0500291.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600292
293 .. versionadded:: 0.9
294
295 .. method:: public_key()
296
297 :type:
298 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
299 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
300 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
301
302 The public key associated with the request.
303
304 .. doctest::
305
306 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500307 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600308 >>> isinstance(public_key, rsa.RSAPublicKey)
309 True
310
311 .. attribute:: subject
312
313 :type: :class:`Name`
314
315 The :class:`Name` of the subject.
316
317 .. attribute:: signature_hash_algorithm
318
319 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
320
321 Returns the
322 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
323 was used in signing this request.
324
325 .. doctest::
326
327 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500328 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600329 True
330
Paul Kehrer719d5362015-01-01 20:03:52 -0600331.. class:: Name
332
333 .. versionadded:: 0.8
334
Paul Kehrer53d8d492015-02-13 18:47:30 -0600335 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -0600336 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -0600337 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -0600338 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
339 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -0600340
Paul Kehrer53d8d492015-02-13 18:47:30 -0600341 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -0600342
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600343 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -0600344 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600345 >>> for attribute in cert.subject:
346 ... print(attribute)
347 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
348 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')>
349 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -0600350
Paul Kehrere901d642015-02-11 18:50:58 -0600351 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -0600352
Paul Kehrere901d642015-02-11 18:50:58 -0600353 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -0600354
Paul Kehrere901d642015-02-11 18:50:58 -0600355 :returns: A list of :class:`NameAttribute` instances that match the
356 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -0600357
358 .. doctest::
359
Paul Kehrere901d642015-02-11 18:50:58 -0600360 >>> cert.subject.get_attributes_for_oid(x509.OID_COMMON_NAME)
361 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -0600362
Paul Kehrere76cd272014-12-14 19:00:51 -0600363.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -1000364
365 .. versionadded:: 0.7
366
367 An enumeration for X.509 versions.
368
369 .. attribute:: v1
370
371 For version 1 X.509 certificates.
372
373 .. attribute:: v3
374
375 For version 3 X.509 certificates.
376
Paul Kehrer806bfb22015-02-02 17:05:24 -0600377.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600378
379 .. versionadded:: 0.8
380
Paul Kehrer834d22f2015-02-06 11:01:07 -0600381 An X.509 name consists of a list of NameAttribute instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600382
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600383 .. attribute:: oid
384
385 :type: :class:`ObjectIdentifier`
386
387 The attribute OID.
388
389 .. attribute:: value
390
Paul Kehrerd5852cb2015-01-30 08:25:23 -0600391 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600392
393 The value of the attribute.
394
395.. class:: ObjectIdentifier
396
397 .. versionadded:: 0.8
398
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600399 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -0600400 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600401
Paul Kehrerd44f9a62015-02-04 14:47:34 -0600402 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600403
404 :type: :class:`str`
405
Paul Kehrerfedf4f42015-02-06 11:22:07 -0600406 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600407
Paul Kehrer31bdf792015-03-25 14:11:00 -0500408.. _general_name_classes:
409
410General Name Classes
411~~~~~~~~~~~~~~~~~~~~
412
413.. class:: GeneralName
414
415 .. versionadded:: 0.9
416
417 This is the generic interface that all the following classes are registered
418 against.
419
420.. class:: RFC822Name
421
422 .. versionadded:: 0.9
423
424 This corresponds to an email address. For example, ``user@example.com``.
425
426 .. attribute:: value
427
428 :type: :term:`text`
429
430.. class:: DNSName
431
432 .. versionadded:: 0.9
433
434 This corresponds to a domain name. For example, ``cryptography.io``.
435
436 .. attribute:: value
437
438 :type: :term:`text`
439
440.. class:: DirectoryName
441
442 .. versionadded:: 0.9
443
444 This corresponds to a directory name.
445
446 .. attribute:: value
447
448 :type: :class:`Name`
449
450.. class:: UniformResourceIdentifier
451
452 .. versionadded:: 0.9
453
454 This corresponds to a uniform resource identifier. For example,
455 ``https://cryptography.io``.
456
457 .. attribute:: value
458
459 :type: :term:`text`
460
461.. class:: IPAddress
462
463 .. versionadded:: 0.9
464
465 This corresponds to an IP address.
466
467 .. attribute:: value
468
469 :type: :class:`~ipaddress.IPv4Address` or
470 :class:`~ipaddress.IPv6Address`.
471
472.. class:: RegisteredID
473
474 .. versionadded:: 0.9
475
476 This corresponds to a registered ID.
477
478 .. attribute:: value
479
480 :type: :class:`ObjectIdentifier`
481
Paul Kehrer8cf26422015-03-21 09:50:24 -0500482X.509 Extensions
483~~~~~~~~~~~~~~~~
484
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500485.. class:: Extensions
486
487 .. versionadded:: 0.9
488
489 An X.509 Extensions instance is an ordered list of extensions. The object
490 is iterable to get every extension.
491
Paul Kehrerfa56a232015-03-17 13:14:03 -0500492 .. method:: get_extension_for_oid(oid)
493
494 :param oid: An :class:`ObjectIdentifier` instance.
495
496 :returns: An instance of the extension class.
497
498 :raises cryptography.x509.ExtensionNotFound: If the certificate does
499 not have the extension requested.
500
Paul Kehrerfa56a232015-03-17 13:14:03 -0500501 .. doctest::
502
503 >>> cert.extensions.get_extension_for_oid(x509.OID_BASIC_CONSTRAINTS)
504 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
505
Paul Kehrer8cf26422015-03-21 09:50:24 -0500506.. class:: Extension
507
508 .. versionadded:: 0.9
509
Paul Kehrer85894662015-03-22 13:19:31 -0500510 .. attribute:: oid
511
512 :type: :class:`ObjectIdentifier`
513
Paul Kehrer5553d572015-03-23 21:08:01 -0500514 The :ref:`extension OID <extension_oids>`.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500515
516 .. attribute:: critical
517
518 :type: bool
519
Paul Kehrer58b75692015-03-22 23:24:58 -0500520 Determines whether a given extension is critical or not. :rfc:`5280`
521 requires that "A certificate-using system MUST reject the certificate
522 if it encounters a critical extension it does not recognize or a
523 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -0500524
Paul Kehrer85894662015-03-22 13:19:31 -0500525 .. attribute:: value
526
527 Returns an instance of the extension type corresponding to the OID.
528
Paul Kehrercecbbba2015-03-30 14:58:38 -0500529.. class:: KeyUsage
530
531 .. versionadded:: 0.9
532
533 The key usage extension defines the purpose of the key contained in the
534 certificate. The usage restriction might be employed when a key that could
535 be used for more than one operation is to be restricted. It corresponds to
536 :data:`OID_KEY_USAGE`.
537
538 .. attribute:: digital_signature
539
540 :type: bool
541
Paul Kehrer738407b2015-04-01 22:39:02 -0500542 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500543 digital signatures, other than signatures on certificates
544 (``key_cert_sign``) and CRLs (``crl_sign``).
545
546 .. attribute:: content_commitment
547
548 :type: bool
549
Paul Kehrer738407b2015-04-01 22:39:02 -0500550 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500551 digital signatures, other than signatures on certificates
552 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
553 non-repudiation service that protects against the signing entity
554 falsely denying some action. In the case of later conflict, a
555 reliable third party may determine the authenticity of the signed
556 data. This was called ``non_repudiation`` in older revisions of the
557 X.509 specification.
558
559 .. attribute:: key_encipherment
560
561 :type: bool
562
Paul Kehrer738407b2015-04-01 22:39:02 -0500563 This purpose is set to true when the subject public key is used for
564 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500565
566 .. attribute:: data_encipherment
567
568 :type: bool
569
Paul Kehrer738407b2015-04-01 22:39:02 -0500570 This purpose is set to true when the subject public key is used for
571 directly enciphering raw user data without the use of an intermediate
572 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500573
574 .. attribute:: key_agreement
575
576 :type: bool
577
Paul Kehrer738407b2015-04-01 22:39:02 -0500578 This purpose is set to true when the subject public key is used for key
579 agreement. For example, when a Diffie-Hellman key is to be used for
580 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500581
582 .. attribute:: key_cert_sign
583
584 :type: bool
585
Paul Kehrer738407b2015-04-01 22:39:02 -0500586 This purpose is set to true when the subject public key is used for
587 verifying signatures on public key certificates. If this purpose is set
588 to true then ``ca`` must be true in the :class:`BasicConstraints`
589 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500590
591 .. attribute:: crl_sign
592
593 :type: bool
594
Paul Kehrer738407b2015-04-01 22:39:02 -0500595 This purpose is set to true when the subject public key is used for
596 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500597
598 .. attribute:: encipher_only
599
600 :type: bool
601
Paul Kehrer738407b2015-04-01 22:39:02 -0500602 When this purposes is set to true and the ``key_agreement`` purpose is
603 also set, the subject public key may be used only for enciphering data
604 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500605
606 :raises ValueError: This is raised if accessed when ``key_agreement``
607 is false.
608
609 .. attribute:: decipher_only
610
611 :type: bool
612
Paul Kehrer738407b2015-04-01 22:39:02 -0500613 When this purposes is set to true and the ``key_agreement`` purpose is
614 also set, the subject public key may be used only for deciphering data
615 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500616
617 :raises ValueError: This is raised if accessed when ``key_agreement``
618 is false.
619
620
Paul Kehrer8cf26422015-03-21 09:50:24 -0500621.. class:: BasicConstraints
622
623 .. versionadded:: 0.9
624
Paul Kehrer85894662015-03-22 13:19:31 -0500625 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -0500626 certificate is allowed to sign additional certificates and what path
Paul Kehrer85894662015-03-22 13:19:31 -0500627 length restrictions may exist. It corresponds to
628 :data:`OID_BASIC_CONSTRAINTS`.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500629
630 .. attribute:: ca
631
632 :type: bool
633
634 Whether the certificate can sign certificates.
635
636 .. attribute:: path_length
637
Paul Kehrerfd1444c2015-03-21 19:47:05 -0500638 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -0500639
640 The maximum path length for certificates subordinate to this
641 certificate. This attribute only has meaning if ``ca`` is true.
642 If ``ca`` is true then a path length of None means there's no
643 restriction on the number of subordinate CAs in the certificate chain.
644 If it is zero or greater then that number defines the maximum length.
645 For example, a ``path_length`` of 1 means the certificate can sign a
646 subordinate CA, but the subordinate CA is not allowed to create
Paul Kehrerfd1444c2015-03-21 19:47:05 -0500647 subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500648
Paul Kehrerffa2a152015-03-31 08:18:25 -0500649.. class:: ExtendedKeyUsage
650
651 .. versionadded:: 0.9
652
653 This extension indicates one or more purposes for which the certified
654 public key may be used, in addition to or in place of the basic
655 purposes indicated in the key usage extension. The object is
656 iterable to obtain the list of :ref:`extended key usage OIDs <eku_oids>`.
657
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400658.. class:: AuthorityKeyIdentifier
659
660 .. versionadded:: 0.9
661
662 The authority key identifier extension provides a means of identifying the
663 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -0500664 This extension is typically used to assist in determining the appropriate
665 certificate chain. For more information about generation and use of this
666 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400667
668 .. attribute:: key_identifier
669
670 :type: bytes
671
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500672 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -0500673 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500674
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400675 .. attribute:: authority_cert_issuer
676
677 :type: :class:`Name` or None
678
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500679 The :class:`Name` of the issuer's issuer.
680
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400681 .. attribute:: authority_cert_serial_number
682
683 :type: int or None
684
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500685 The serial number of the issuer's issuer.
686
Paul Kehrer1eb82a62015-03-31 20:00:33 -0500687.. class:: SubjectKeyIdentifier
688
689 .. versionadded:: 0.9
690
691 The subject key identifier extension provides a means of identifying
692 certificates that contain a particular public key.
693
694 .. attribute:: digest
695
696 :type: bytes
697
698 The binary value of the identifier.
699
Paul Kehrer31bdf792015-03-25 14:11:00 -0500700.. class:: SubjectAlternativeName
701
702 .. versionadded:: 0.9
703
704 Subject alternative name is an X.509 extension that provides a list of
705 :ref:`general name <general_name_classes>` instances that provide a set
706 of identities for which the certificate is valid. The object is iterable to
707 get every element.
708
709 .. method:: get_values_for_type(type)
710
711 :param type: A :class:`GeneralName` provider. This is one of the
712 :ref:`general name classes <general_name_classes>`.
713
714 :returns: A list of values extracted from the matched general names.
715
Paul Kehrer8cf26422015-03-21 09:50:24 -0500716
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600717Object Identifiers
718~~~~~~~~~~~~~~~~~~
719
Paul Kehrer4bb46492015-02-07 16:59:14 -0600720X.509 elements are frequently identified by :class:`ObjectIdentifier`
721instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600722
Paul Kehrer56da2a52015-02-11 23:35:07 -0600723Name OIDs
724~~~~~~~~~
725
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600726.. data:: OID_COMMON_NAME
727
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -0600728 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
729 name would be encoded here for server certificates. :rfc:`2818` deprecates
730 this practice and names of that type should now be located in a
Paul Kehrer4bb46492015-02-07 16:59:14 -0600731 SubjectAlternativeName extension. This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600732
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600733.. data:: OID_COUNTRY_NAME
734
Paul Kehrer4bb46492015-02-07 16:59:14 -0600735 Corresponds to the dotted string ``"2.5.4.6"``. This OID is typically seen
736 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600737
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600738.. data:: OID_LOCALITY_NAME
739
Paul Kehrer4bb46492015-02-07 16:59:14 -0600740 Corresponds to the dotted string ``"2.5.4.7"``. This OID is typically seen
741 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600742
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600743.. data:: OID_STATE_OR_PROVINCE_NAME
744
Paul Kehrer4bb46492015-02-07 16:59:14 -0600745 Corresponds to the dotted string ``"2.5.4.8"``. This OID is typically seen
746 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600747
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600748.. data:: OID_ORGANIZATION_NAME
749
Paul Kehrer4bb46492015-02-07 16:59:14 -0600750 Corresponds to the dotted string ``"2.5.4.10"``. This OID is typically seen
751 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600752
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600753.. data:: OID_ORGANIZATIONAL_UNIT_NAME
754
Paul Kehrer4bb46492015-02-07 16:59:14 -0600755 Corresponds to the dotted string ``"2.5.4.11"``. This OID is typically seen
756 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600757
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600758.. data:: OID_SERIAL_NUMBER
759
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -0600760 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from the
761 serial number of the certificate itself (which can be obtained with
Paul Kehrer4bb46492015-02-07 16:59:14 -0600762 :func:`Certificate.serial`). This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600763
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600764.. data:: OID_SURNAME
765
Paul Kehrer4bb46492015-02-07 16:59:14 -0600766 Corresponds to the dotted string ``"2.5.4.4"``. This OID is typically seen
767 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600768
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600769.. data:: OID_GIVEN_NAME
770
Paul Kehrer4bb46492015-02-07 16:59:14 -0600771 Corresponds to the dotted string ``"2.5.4.42"``. This OID is typically seen
772 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600773
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600774.. data:: OID_TITLE
775
Paul Kehrer4bb46492015-02-07 16:59:14 -0600776 Corresponds to the dotted string ``"2.5.4.12"``. This OID is typically seen
777 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600778
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600779.. data:: OID_GENERATION_QUALIFIER
780
Paul Kehrer4bb46492015-02-07 16:59:14 -0600781 Corresponds to the dotted string ``"2.5.4.44"``. This OID is typically seen
782 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600783
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600784.. data:: OID_DN_QUALIFIER
785
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -0600786 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
787 disambiguating information to add to the relative distinguished name of an
Paul Kehrer4bb46492015-02-07 16:59:14 -0600788 entry. See :rfc:`2256`. This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600789
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600790.. data:: OID_PSEUDONYM
791
Paul Kehrer4bb46492015-02-07 16:59:14 -0600792 Corresponds to the dotted string ``"2.5.4.65"``. This OID is typically seen
793 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600794
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600795.. data:: OID_DOMAIN_COMPONENT
796
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -0600797 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
Paul Kehrer4bb46492015-02-07 16:59:14 -0600798 holding one component of a domain name. See :rfc:`4519`. This OID is
799 typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600800
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600801.. data:: OID_EMAIL_ADDRESS
802
Paul Kehrer4bb46492015-02-07 16:59:14 -0600803 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``. This OID is
804 typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600805
Paul Kehrer56da2a52015-02-11 23:35:07 -0600806Signature Algorithm OIDs
807~~~~~~~~~~~~~~~~~~~~~~~~
808
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600809.. data:: OID_RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -0600810
811 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
812 an MD5 digest signed by an RSA key.
813
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600814.. data:: OID_RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -0600815
816 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
817 a SHA1 digest signed by an RSA key.
818
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600819.. data:: OID_RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -0600820
821 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
822 a SHA224 digest signed by an RSA key.
823
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600824.. data:: OID_RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -0600825
826 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
827 a SHA256 digest signed by an RSA key.
828
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600829.. data:: OID_RSA_WITH_SHA384
Paul Kehrer56da2a52015-02-11 23:35:07 -0600830
831 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
832 a SHA384 digest signed by an RSA key.
833
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600834.. data:: OID_RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -0600835
836 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
837 a SHA512 digest signed by an RSA key.
838
839.. data:: OID_ECDSA_WITH_SHA224
840
841 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
842 a SHA224 digest signed by an ECDSA key.
843
844.. data:: OID_ECDSA_WITH_SHA256
845
846 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
847 a SHA256 digest signed by an ECDSA key.
848
849.. data:: OID_ECDSA_WITH_SHA384
850
851 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
852 a SHA384 digest signed by an ECDSA key.
853
854.. data:: OID_ECDSA_WITH_SHA512
855
856 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
857 a SHA512 digest signed by an ECDSA key.
858
859.. data:: OID_DSA_WITH_SHA1
860
861 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
862 a SHA1 digest signed by a DSA key.
863
864.. data:: OID_DSA_WITH_SHA224
865
866 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
867 a SHA224 digest signed by a DSA key.
868
869.. data:: OID_DSA_WITH_SHA256
870
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500871 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
Paul Kehrer56da2a52015-02-11 23:35:07 -0600872 a SHA256 digest signed by a DSA key.
873
Paul Kehrerffa2a152015-03-31 08:18:25 -0500874.. _eku_oids:
875
Paul Kehrere1513fa2015-03-30 23:08:17 -0500876Extended Key Usage OIDs
877~~~~~~~~~~~~~~~~~~~~~~~
878
879.. data:: OID_SERVER_AUTH
880
881 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used to
882 denote that a certificate may be used for TLS web server authentication.
883
884.. data:: OID_CLIENT_AUTH
885
886 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used to
887 denote that a certificate may be used for TLS web client authentication.
888
889.. data:: OID_CODE_SIGNING
890
891 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used to
892 denote that a certificate may be used for code signing.
893
894.. data:: OID_EMAIL_PROTECTION
895
896 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used to
897 denote that a certificate may be used for email protection.
898
899.. data:: OID_TIME_STAMPING
900
901 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used to
902 denote that a certificate may be used for time stamping.
903
904.. data:: OID_OCSP_SIGNING
905
906 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used to
907 denote that a certificate may be used for signing OCSP responses.
908
Paul Kehrer5553d572015-03-23 21:08:01 -0500909.. _extension_oids:
910
Paul Kehrer2bb94642015-03-21 09:54:17 -0500911Extension OIDs
912~~~~~~~~~~~~~~
913
914.. data:: OID_BASIC_CONSTRAINTS
915
916 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
Paul Kehrer611d3d32015-03-22 13:31:18 -0500917 :class:`BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -0500918
Paul Kehrercecbbba2015-03-30 14:58:38 -0500919.. data:: OID_KEY_USAGE
920
921 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
922 :class:`KeyUsage` extension type.
923
Paul Kehrer56da2a52015-02-11 23:35:07 -0600924
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600925Exceptions
926~~~~~~~~~~
927
Paul Kehrere76cd272014-12-14 19:00:51 -0600928.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -1000929
930 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000931
Paul Kehrerd5cccf72014-12-15 17:20:33 -0600932 .. attribute:: parsed_version
933
Paul Kehrerbbffc402014-12-17 13:33:55 -0600934 :type: int
935
936 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -0600937
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500938.. class:: DuplicateExtension
939
940 This is raised when more than one X.509 extension of the same type is
941 found within a certificate.
942
943 .. attribute:: oid
944
945 :type: :class:`ObjectIdentifier`
946
947 Returns the OID.
948
949.. class:: UnsupportedExtension
950
951 This is raised when a certificate contains an unsupported extension type.
952
953 .. attribute:: oid
954
955 :type: :class:`ObjectIdentifier`
956
957 Returns the OID.
958
Paul Kehrerfa56a232015-03-17 13:14:03 -0500959.. class:: ExtensionNotFound
960
961 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
962 an extension OID that is not present in the certificate.
963
964 .. attribute:: oid
965
966 :type: :class:`ObjectIdentifier`
967
968 Returns the OID.
969
Paul Kehrer9089c912015-04-20 22:15:20 -0500970.. class:: UnsupportedGeneralNameType
971
972 This is raised when a certificate contains an unsupported general name
973 type in an extension.
974
Paul Kehrerbed07352015-04-21 08:31:10 -0500975 .. attribute:: type
976
Paul Kehrer0a621bf2015-04-22 09:22:56 -0500977 :type: int
978
979 The integer value of the unsupported type. The complete list of
980 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -0500981
Paul Kehrer016e08a2014-11-26 09:41:18 -1000982
983.. _`public key infrastructure`: https://en.wikipedia.org/wiki/Public_key_infrastructure
Paul Kehrera68fd332014-11-27 07:08:40 -1000984.. _`TLS`: https://en.wikipedia.org/wiki/Transport_Layer_Security
Paul Kehrerc7c9a432015-04-19 09:20:13 -0500985.. _`RFC 5280 section 4.2.1.1`: https://tools.ietf.org/html/rfc5280#section-4.2.1.1
Paul Kehrer0a621bf2015-04-22 09:22:56 -0500986.. _`RFC 5280 section 4.2.1.6`: https://tools.ietf.org/html/rfc5280#section-4.2.1.6