blob: bd88b02323bdfcf8f4d0ca3544ee2c175740e07a [file] [log] [blame]
Alex Gaynor4af5b372015-07-12 10:30:59 -05001X.509 Reference
2===============
Paul Kehrer016e08a2014-11-26 09:41:18 -10003
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
Erik Trauschkedc570402015-09-24 20:24:28 -07008 pem_crl_data = b"""
9 -----BEGIN X509 CRL-----
10 MIIBtDCBnQIBAjANBgkqhkiG9w0BAQsFADAnMQswCQYDVQQGEwJVUzEYMBYGA1UE
11 AwwPY3J5cHRvZ3JhcGh5LmlvGA8yMDE1MDEwMTAwMDAwMFoYDzIwMTYwMTAxMDAw
12 MDAwWjA+MDwCAQAYDzIwMTUwMTAxMDAwMDAwWjAmMBgGA1UdGAQRGA8yMDE1MDEw
13 MTAwMDAwMFowCgYDVR0VBAMKAQEwDQYJKoZIhvcNAQELBQADggEBABRA4ww50Lz5
14 zk1j2+aluC4HPHqb7o06h4pTDcCGeXUKXIGeP5ntGGmIoxa26sNoLeOr8+5b43Gf
15 yWraHertllOwaOpNFEe+YZFaE9femtoDbf+GLMvRx/0wDfd3KxPoXnXKMXb2d1w4
16 RCLgmkYx6JyvS+5ciuLQVIKC+l7jwIUeZFLJMUJ8msM4pFYoGameeZmtjMbd/TNg
17 cVBfmZxNMHuLladJxvSo2esARo0TYPhYsgrREKoHwhpzSxdynjn4bOVkILfguwsN
18 qtEEMZFEv5Kb0GqRp2+Iagv2S6dg9JGvxVdsoGjaB6EbYSZ3Psx4aODasIn11uwo
19 X4B9vUQNXqc=
20 -----END X509 CRL-----
21 """.strip()
22
Paul Kehrerd26c4db2015-03-15 15:36:24 -050023 pem_req_data = b"""
24 -----BEGIN CERTIFICATE REQUEST-----
25 MIIC0zCCAbsCAQAwWTELMAkGA1UEBhMCVVMxETAPBgNVBAgMCElsbGlub2lzMRAw
26 DgYDVQQHDAdDaGljYWdvMREwDwYDVQQKDAhyNTA5IExMQzESMBAGA1UEAwwJaGVs
27 bG8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqhZx+Mo9VRd9
28 vsnWWa6NBCws21rZ0+1B/JGgB4hDsZS7iDE4Bj5z4idheFRtl8bBbdjPknq7BfoF
29 8v15Zq/Zv7i2xMSDL+LUrTBZezRd4bRTGqCm6YJ5EYkhqdcqeZleHCFImguHoq1J
30 Fh0+kObQrTHXw3ZP57a3o1IvyIUA3nNoCBL0QQhwBXaDXOojMKNR+bqB5ve8GS1y
31 Elr0AM/+cJsfaIahNQUgFKx3Eu3GeEOMKYOAG1lycgdQdmTUybLrT3U7vkClTseM
32 xHg1r5En7ALjONIhqRuq3rddYahrP8HXozb3zUy3cJ7P6IeaosuvNzvMXOX9P6HD
33 Ha9urDAJ1wIDAQABoDUwMwYJKoZIhvcNAQkOMSYwJDAiBgNVHREEGzAZggl3b3Js
34 ZC5jb22CDHdoYXRldmVyLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEAS4Ro6h+z52SK
35 YSLCYARpnEu/rmh4jdqndt8naqcNb6uLx9mlKZ2W9on9XDjnSdQD9q+ZP5aZfESw
36 R0+rJhW9ZrNa/g1pt6M24ihclHYDAxYMWxT1z/TXXGM3TmZZ6gfYlNE1kkBuODHa
37 UYsR/1Ht1E1EsmmUimt2n+zQR2K8T9Coa+boaUW/GsTEuz1aaJAkj5ZvTDiIhRG4
38 AOCqFZOLAQmCCNgJnnspD9hDz/Ons085LF5wnYjN4/Nsk5tS6AGs3xjZ3jPoOGGn
39 82WQ9m4dBGoVDZXsobVTaN592JEYwN5iu72zRn7Einb4V4H5y3yD2dD4yWPlt4pk
40 5wFkeYsZEA==
41 -----END CERTIFICATE REQUEST-----
42 """.strip()
43
Paul Kehrerd3dafbd2015-03-15 16:24:18 -050044 pem_data = b"""
45 -----BEGIN CERTIFICATE-----
46 MIIDfDCCAmSgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJVUzEf
47 MB0GA1UEChMWVGVzdCBDZXJ0aWZpY2F0ZXMgMjAxMTEVMBMGA1UEAxMMVHJ1c3Qg
48 QW5jaG9yMB4XDTEwMDEwMTA4MzAwMFoXDTMwMTIzMTA4MzAwMFowQDELMAkGA1UE
49 BhMCVVMxHzAdBgNVBAoTFlRlc3QgQ2VydGlmaWNhdGVzIDIwMTExEDAOBgNVBAMT
50 B0dvb2QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCQWJpHYo37
51 Xfb7oJSPe+WvfTlzIG21WQ7MyMbGtK/m8mejCzR6c+f/pJhEH/OcDSMsXq8h5kXa
52 BGqWK+vSwD/Pzp5OYGptXmGPcthDtAwlrafkGOS4GqIJ8+k9XGKs+vQUXJKsOk47
53 RuzD6PZupq4s16xaLVqYbUC26UcY08GpnoLNHJZS/EmXw1ZZ3d4YZjNlpIpWFNHn
54 UGmdiGKXUPX/9H0fVjIAaQwjnGAbpgyCumWgzIwPpX+ElFOUr3z7BoVnFKhIXze+
55 VmQGSWxZxvWDUN90Ul0tLEpLgk3OVxUB4VUGuf15OJOpgo1xibINPmWt14Vda2N9
56 yrNKloJGZNqLAgMBAAGjfDB6MB8GA1UdIwQYMBaAFOR9X9FclYYILAWuvnW2ZafZ
57 XahmMB0GA1UdDgQWBBRYAYQkG7wrUpRKPaUQchRR9a86yTAOBgNVHQ8BAf8EBAMC
58 AQYwFwYDVR0gBBAwDjAMBgpghkgBZQMCATABMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
59 KoZIhvcNAQELBQADggEBADWHlxbmdTXNwBL/llwhQqwnazK7CC2WsXBBqgNPWj7m
60 tvQ+aLG8/50Qc2Sun7o2VnwF9D18UUe8Gj3uPUYH+oSI1vDdyKcjmMbKRU4rk0eo
61 3UHNDXwqIVc9CQS9smyV+x1HCwL4TTrq+LXLKx/qVij0Yqk+UJfAtrg2jnYKXsCu
62 FMBQQnWCGrwa1g1TphRp/RmYHnMynYFmZrXtzFz+U9XEA7C+gPq4kqDI/iVfIT1s
63 6lBtdB50lrDVwl2oYfAvW/6sC2se2QleZidUmrziVNP4oEeXINokU6T6p//HM1FG
64 QYw2jOvpKcKtWCSAnegEbgsGYzATKjmPJPJ0npHFqzM=
65 -----END CERTIFICATE-----
66 """.strip()
67
Paul Kehrer93ae8052015-05-02 23:18:09 -050068 cryptography_cert_pem = b"""
69 -----BEGIN CERTIFICATE-----
70 MIIFvTCCBKWgAwIBAgICPyAwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMx
71 FjAUBgNVBAoTDUdlb1RydXN0IEluYy4xIDAeBgNVBAMTF1JhcGlkU1NMIFNIQTI1
72 NiBDQSAtIEczMB4XDTE0MTAxNTEyMDkzMloXDTE4MTExNjAxMTUwM1owgZcxEzAR
73 BgNVBAsTCkdUNDg3NDI5NjUxMTAvBgNVBAsTKFNlZSB3d3cucmFwaWRzc2wuY29t
74 L3Jlc291cmNlcy9jcHMgKGMpMTQxLzAtBgNVBAsTJkRvbWFpbiBDb250cm9sIFZh
75 bGlkYXRlZCAtIFJhcGlkU1NMKFIpMRwwGgYDVQQDExN3d3cuY3J5cHRvZ3JhcGh5
76 LmlvMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAom/FebKJIot7Sp3s
77 itG1sicpe3thCssjI+g1JDAS7I3GLVNmbms1DOdIIqwf01gZkzzXBN2+9sOnyRaR
78 PPfCe1jTr3dk2y6rPE559vPa1nZQkhlzlhMhlPyjaT+S7g4Tio4qV2sCBZU01DZJ
79 CaksfohN+5BNVWoJzTbOcrHOEJ+M8B484KlBCiSxqf9cyNQKru4W3bHaCVNVJ8eu
80 6i6KyhzLa0L7yK3LXwwXVs583C0/vwFhccGWsFODqD/9xHUzsBIshE8HKjdjDi7Y
81 3BFQzVUQFjBB50NSZfAA/jcdt1blxJouc7z9T8Oklh+V5DDBowgAsrT4b6Z2Fq6/
82 r7D1GqivLK/ypUQmxq2WXWAUBb/Q6xHgxASxI4Br+CByIUQJsm8L2jzc7k+mF4hW
83 ltAIUkbo8fGiVnat0505YJgxWEDKOLc4Gda6d/7GVd5AvKrz242bUqeaWo6e4MTx
84 diku2Ma3rhdcr044Qvfh9hGyjqNjvhWY/I+VRWgihU7JrYvgwFdJqsQ5eiKT4OHi
85 gsejvWwkZzDtiQ+aQTrzM1FsY2swJBJsLSX4ofohlVRlIJCn/ME+XErj553431Lu
86 YQ5SzMd3nXzN78Vj6qzTfMUUY72UoT1/AcFiUMobgIqrrmwuNxfrkbVE2b6Bga74
87 FsJX63prvrJ41kuHK/16RQBM7fcCAwEAAaOCAWAwggFcMB8GA1UdIwQYMBaAFMOc
88 8/zTRgg0u85Gf6B8W/PiCMtZMFcGCCsGAQUFBwEBBEswSTAfBggrBgEFBQcwAYYT
89 aHR0cDovL2d2LnN5bWNkLmNvbTAmBggrBgEFBQcwAoYaaHR0cDovL2d2LnN5bWNi
90 LmNvbS9ndi5jcnQwDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMB
91 BggrBgEFBQcDAjAvBgNVHREEKDAmghN3d3cuY3J5cHRvZ3JhcGh5Lmlvgg9jcnlw
92 dG9ncmFwaHkuaW8wKwYDVR0fBCQwIjAgoB6gHIYaaHR0cDovL2d2LnN5bWNiLmNv
93 bS9ndi5jcmwwDAYDVR0TAQH/BAIwADBFBgNVHSAEPjA8MDoGCmCGSAGG+EUBBzYw
94 LDAqBggrBgEFBQcCARYeaHR0cHM6Ly93d3cucmFwaWRzc2wuY29tL2xlZ2FsMA0G
95 CSqGSIb3DQEBCwUAA4IBAQAzIYO2jx7h17FBT74tJ2zbV9OKqGb7QF8y3wUtP4xc
96 dH80vprI/Cfji8s86kr77aAvAqjDjaVjHn7UzebhSUivvRPmfzRgyWBacomnXTSt
97 Xlt2dp2nDQuwGyK2vB7dMfKnQAkxwq1sYUXznB8i0IhhCAoXp01QGPKq51YoIlnF
98 7DRMk6iEaL1SJbkIrLsCQyZFDf0xtfW9DqXugMMLoxeCsBhZJQzNyS2ryirrv9LH
99 aK3+6IZjrcyy9bkpz/gzJucyhU+75c4My/mnRCrtItRbCQuiI5pd5poDowm+HH9i
100 GVI9+0lAFwxOUnOnwsoI40iOoxjLMGB+CgFLKCGUcWxP
101 -----END CERTIFICATE-----
102 """.strip()
103
Paul Kehrerb2de9482014-12-11 14:54:48 -0600104Loading Certificates
105~~~~~~~~~~~~~~~~~~~~
Paul Kehrer016e08a2014-11-26 09:41:18 -1000106
107.. function:: load_pem_x509_certificate(data, backend)
108
109 .. versionadded:: 0.7
110
Paul Kehrere76cd272014-12-14 19:00:51 -0600111 Deserialize a certificate from PEM encoded data. PEM certificates are
112 base64 decoded and have delimiters that look like
113 ``-----BEGIN CERTIFICATE-----``.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000114
115 :param bytes data: The PEM encoded certificate data.
116
117 :param backend: A backend supporting the
118 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
119 interface.
120
Paul Kehrere76cd272014-12-14 19:00:51 -0600121 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000122
Alex Gaynor5ce14042016-05-29 13:13:46 -0400123 .. doctest::
124
125 >>> from cryptography import x509
126 >>> from cryptography.hazmat.backends import default_backend
127 >>> cert = x509.load_pem_x509_certificate(pem_data, default_backend())
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700128 >>> cert.serial_number
Alex Gaynor5ce14042016-05-29 13:13:46 -0400129 2
130
Paul Kehrer016e08a2014-11-26 09:41:18 -1000131.. function:: load_der_x509_certificate(data, backend)
132
133 .. versionadded:: 0.7
134
Paul Kehrere76cd272014-12-14 19:00:51 -0600135 Deserialize a certificate from DER encoded data. DER is a binary format
Paul Kehrer92aac382014-12-15 16:25:28 -0600136 and is commonly found in files with the ``.cer`` extension (although file
137 extensions are not a guarantee of encoding type).
Paul Kehrer016e08a2014-11-26 09:41:18 -1000138
139 :param bytes data: The DER encoded certificate data.
140
141 :param backend: A backend supporting the
142 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
143 interface.
144
Paul Kehrere76cd272014-12-14 19:00:51 -0600145 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000146
Erik Trauschkedc570402015-09-24 20:24:28 -0700147Loading Certificate Revocation Lists
148~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149
150.. function:: load_pem_x509_crl(data, backend)
151
152 .. versionadded:: 1.1
153
154 Deserialize a certificate revocation list (CRL) from PEM encoded data. PEM
155 requests are base64 decoded and have delimiters that look like
Erik Trauschke32bbfe02015-10-21 08:04:55 -0700156 ``-----BEGIN X509 CRL-----``.
Erik Trauschkedc570402015-09-24 20:24:28 -0700157
158 :param bytes data: The PEM encoded request data.
159
160 :param backend: A backend supporting the
161 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
162 interface.
163
164 :returns: An instance of
165 :class:`~cryptography.x509.CertificateRevocationList`.
166
Alex Gaynor5ce14042016-05-29 13:13:46 -0400167 .. doctest::
168
169 >>> from cryptography import x509
170 >>> from cryptography.hazmat.backends import default_backend
171 >>> from cryptography.hazmat.primitives import hashes
172 >>> crl = x509.load_pem_x509_crl(pem_crl_data, default_backend())
173 >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
174 True
175
Erik Trauschkedc570402015-09-24 20:24:28 -0700176.. function:: load_der_x509_crl(data, backend)
177
178 .. versionadded:: 1.1
179
180 Deserialize a certificate revocation list (CRL) from DER encoded data. DER
181 is a binary format.
182
183 :param bytes data: The DER encoded request data.
184
185 :param backend: A backend supporting the
186 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
187 interface.
188
189 :returns: An instance of
190 :class:`~cryptography.x509.CertificateRevocationList`.
191
Paul Kehrera1a1f232015-03-15 15:34:35 -0500192Loading Certificate Signing Requests
193~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600194
Paul Kehrer31e39882015-03-11 11:37:04 -0500195.. function:: load_pem_x509_csr(data, backend)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600196
197 .. versionadded:: 0.9
198
Paul Kehrera1a1f232015-03-15 15:34:35 -0500199 Deserialize a certificate signing request (CSR) from PEM encoded data. PEM
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500200 requests are base64 decoded and have delimiters that look like
Paul Kehrerd3dafbd2015-03-15 16:24:18 -0500201 ``-----BEGIN CERTIFICATE REQUEST-----``. This format is also known as
202 PKCS#10.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600203
204 :param bytes data: The PEM encoded request data.
205
206 :param backend: A backend supporting the
207 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
208 interface.
209
Paul Kehrera1a1f232015-03-15 15:34:35 -0500210 :returns: An instance of
211 :class:`~cryptography.x509.CertificateSigningRequest`.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600212
Alex Gaynor5ce14042016-05-29 13:13:46 -0400213 .. doctest::
214
215 >>> from cryptography import x509
216 >>> from cryptography.hazmat.backends import default_backend
217 >>> from cryptography.hazmat.primitives import hashes
218 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
219 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
220 True
221
Paul Kehrer1effb6e2015-03-30 15:05:59 -0500222.. function:: load_der_x509_csr(data, backend)
223
224 .. versionadded:: 0.9
225
226 Deserialize a certificate signing request (CSR) from DER encoded data. DER
227 is a binary format and is not commonly used with CSRs.
228
229 :param bytes data: The DER encoded request data.
230
231 :param backend: A backend supporting the
232 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
233 interface.
234
235 :returns: An instance of
236 :class:`~cryptography.x509.CertificateSigningRequest`.
237
Paul Kehrere76cd272014-12-14 19:00:51 -0600238X.509 Certificate Object
239~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerb2de9482014-12-11 14:54:48 -0600240
Paul Kehrere76cd272014-12-14 19:00:51 -0600241.. class:: Certificate
Paul Kehrerb2de9482014-12-11 14:54:48 -0600242
243 .. versionadded:: 0.7
244
245 .. attribute:: version
246
Paul Kehrere76cd272014-12-14 19:00:51 -0600247 :type: :class:`~cryptography.x509.Version`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600248
Paul Kehrere76cd272014-12-14 19:00:51 -0600249 The certificate version as an enumeration. Version 3 certificates are
250 the latest version and also the only type you should see in practice.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600251
Alex Gaynor89c4dc82014-12-16 16:49:33 -0800252 :raises cryptography.x509.InvalidVersion: If the version in the
Alex Gaynor6d7ab4c2014-12-16 16:50:33 -0800253 certificate is not a known
254 :class:`X.509 version <cryptography.x509.Version>`.
Paul Kehrer92aac382014-12-15 16:25:28 -0600255
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600256 .. doctest::
257
258 >>> cert.version
259 <Version.v3: 2>
260
Paul Kehrerb2de9482014-12-11 14:54:48 -0600261 .. method:: fingerprint(algorithm)
262
263 :param algorithm: The
Paul Kehrer601278a2015-02-12 12:51:00 -0600264 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600265 that will be used to generate the fingerprint.
266
Erik Trauschke2dcce902015-05-14 16:12:24 -0700267 :return bytes: The fingerprint using the supplied hash algorithm, as
Paul Kehrerb2de9482014-12-11 14:54:48 -0600268 bytes.
269
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600270 .. doctest::
271
272 >>> from cryptography.hazmat.primitives import hashes
273 >>> cert.fingerprint(hashes.SHA256())
Paul Kehrer78a81502014-12-16 14:47:52 -0600274 '\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 -0600275
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700276 .. attribute:: serial_number
Paul Kehrerb2de9482014-12-11 14:54:48 -0600277
278 :type: int
279
280 The serial as a Python integer.
281
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600282 .. doctest::
283
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700284 >>> cert.serial_number
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600285 2
286
Paul Kehrerb2de9482014-12-11 14:54:48 -0600287 .. method:: public_key()
288
Alex Gaynor4c2561a2015-10-12 23:53:39 -0400289 The public key associated with the certificate.
290
291 :returns:
Alex Stapletonf79c2312014-12-30 12:50:14 +0000292 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
Paul Kehrer45efdbc2015-02-12 10:58:22 -0600293 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
294 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600295
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600296 .. doctest::
297
Alex Stapletonf79c2312014-12-30 12:50:14 +0000298 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600299 >>> public_key = cert.public_key()
Alex Stapletonf79c2312014-12-30 12:50:14 +0000300 >>> isinstance(public_key, rsa.RSAPublicKey)
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600301 True
302
Paul Kehrerb2de9482014-12-11 14:54:48 -0600303 .. attribute:: not_valid_before
304
305 :type: :class:`datetime.datetime`
306
Paul Kehrer78a81502014-12-16 14:47:52 -0600307 A naïve datetime representing the beginning of the validity period for
308 the certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600309
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600310 .. doctest::
311
312 >>> cert.not_valid_before
313 datetime.datetime(2010, 1, 1, 8, 30)
314
Paul Kehrerb2de9482014-12-11 14:54:48 -0600315 .. attribute:: not_valid_after
316
317 :type: :class:`datetime.datetime`
318
Paul Kehrer78a81502014-12-16 14:47:52 -0600319 A naïve datetime representing the end of the validity period for the
320 certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600321
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600322 .. doctest::
323
324 >>> cert.not_valid_after
325 datetime.datetime(2030, 12, 31, 8, 30)
326
Paul Kehrer719d5362015-01-01 20:03:52 -0600327 .. attribute:: issuer
328
329 .. versionadded:: 0.8
330
331 :type: :class:`Name`
332
333 The :class:`Name` of the issuer.
334
335 .. attribute:: subject
336
337 .. versionadded:: 0.8
338
339 :type: :class:`Name`
340
341 The :class:`Name` of the subject.
342
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600343 .. attribute:: signature_hash_algorithm
Paul Kehrer56da2a52015-02-11 23:35:07 -0600344
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600345 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrer56da2a52015-02-11 23:35:07 -0600346
Paul Kehrere612ec72015-02-16 14:33:35 -0600347 Returns the
Paul Kehrer71d40c62015-02-19 08:21:04 -0600348 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600349 was used in signing this certificate.
Paul Kehrer56da2a52015-02-11 23:35:07 -0600350
351 .. doctest::
352
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600353 >>> from cryptography.hazmat.primitives import hashes
354 >>> isinstance(cert.signature_hash_algorithm, hashes.SHA256)
355 True
Paul Kehrer719d5362015-01-01 20:03:52 -0600356
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800357 .. attribute:: signature_algorithm_oid
358
359 .. versionadded:: 1.6
360
361 :type: :class:`ObjectIdentifier`
362
363 Returns the :class:`ObjectIdentifier` of the signature algorithm used
364 to sign the certificate. This will be one of the OIDs from
365 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
366
367
368 .. doctest::
369
370 >>> cert.signature_algorithm_oid
371 <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
372
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500373 .. attribute:: extensions
374
375 :type: :class:`Extensions`
376
377 The extensions encoded in the certificate.
378
379 :raises cryptography.x509.DuplicateExtension: If more than one
380 extension of the same type is found within the certificate.
381
Paul Kehrerd8fc0be2015-04-21 08:31:10 -0500382 :raises cryptography.x509.UnsupportedExtension: If the certificate
383 contains an extension that is not supported.
384
Paul Kehrerbed07352015-04-21 08:31:10 -0500385 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
386 contains a general name that is not supported.
387
Paul Kehrerb8968812015-05-15 09:01:34 -0700388 :raises UnicodeError: If an extension contains IDNA encoding that is
389 invalid or not compliant with IDNA 2008.
390
Paul Kehrerfa56a232015-03-17 13:14:03 -0500391 .. doctest::
392
393 >>> for ext in cert.extensions:
394 ... print(ext)
Paul Kehrerd774de92015-05-03 10:52:25 -0500395 <Extension(oid=<ObjectIdentifier(oid=2.5.29.35, name=authorityKeyIdentifier)>, critical=False, value=<AuthorityKeyIdentifier(key_identifier='\xe4}_\xd1\\\x95\x86\x08,\x05\xae\xbeu\xb6e\xa7\xd9]\xa8f', authority_cert_issuer=None, authority_cert_serial_number=None)>)>
Paul Kehrercbfb1012015-04-10 20:57:20 -0400396 <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 -0400397 <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 Kehrer2008d9c2015-05-12 22:19:56 -0500398 <Extension(oid=<ObjectIdentifier(oid=2.5.29.32, name=certificatePolicies)>, critical=False, value=<CertificatePolicies([<PolicyInformation(policy_identifier=<ObjectIdentifier(oid=2.16.840.1.101.3.2.1.48.1, name=Unknown OID)>, policy_qualifiers=None)>])>)>
Paul Kehrerfa56a232015-03-17 13:14:03 -0500399 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
400
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500401 .. attribute:: signature
402
403 .. versionadded:: 1.2
404
405 :type: bytes
406
407 The bytes of the certificate's signature.
408
Paul Kehrerd2898052015-11-03 22:00:41 +0900409 .. attribute:: tbs_certificate_bytes
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500410
411 .. versionadded:: 1.2
412
413 :type: bytes
414
415 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
416 and then signed by the private key of the certificate's issuer. This
417 data may be used to validate a signature, but use extreme caution as
418 certificate validation is a complex problem that involves much more
419 than just signature checks.
420
Andre Carona8aded62015-05-19 20:11:57 -0400421 .. method:: public_bytes(encoding)
422
Alex Gaynord0b376b2015-07-05 13:58:12 -0400423 .. versionadded:: 1.0
424
Andre Carona8aded62015-05-19 20:11:57 -0400425 :param encoding: The
426 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
427 that will be used to serialize the certificate.
428
429 :return bytes: The data that can be written to a file or sent
430 over the network to be verified by clients.
431
Erik Trauschke2dcce902015-05-14 16:12:24 -0700432X.509 CRL (Certificate Revocation List) Object
433~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
434
435.. class:: CertificateRevocationList
436
437 .. versionadded:: 1.0
438
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700439 A CertificateRevocationList is an object representing a list of revoked
440 certificates. The object is iterable and will yield the RevokedCertificate
441 objects stored in this CRL.
442
443 .. doctest::
Erik Trauschkeb14f7d12015-10-13 09:55:39 -0700444
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700445 >>> len(crl)
446 1
Paul Kehrerdcdf9672015-10-21 20:27:28 -0500447 >>> revoked_certificate = crl[0]
448 >>> type(revoked_certificate)
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700449 <class 'cryptography.hazmat.backends.openssl.x509._RevokedCertificate'>
450 >>> for r in crl:
451 ... print(r.serial_number)
452 0
453
Erik Trauschke2dcce902015-05-14 16:12:24 -0700454 .. method:: fingerprint(algorithm)
455
456 :param algorithm: The
457 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
458 that will be used to generate the fingerprint.
459
460 :return bytes: The fingerprint using the supplied hash algorithm, as
461 bytes.
462
Erik Trauschkedc570402015-09-24 20:24:28 -0700463 .. doctest::
464
465 >>> from cryptography.hazmat.primitives import hashes
466 >>> crl.fingerprint(hashes.SHA256())
467 'e\xcf.\xc4:\x83?1\xdc\xf3\xfc\x95\xd7\xb3\x87\xb3\x8e\xf8\xb93!\x87\x07\x9d\x1b\xb4!\xb9\xe4W\xf4\x1f'
468
Erik Trauschke2dcce902015-05-14 16:12:24 -0700469 .. attribute:: signature_hash_algorithm
470
471 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
472
473 Returns the
474 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
475 was used in signing this CRL.
476
Erik Trauschkedc570402015-09-24 20:24:28 -0700477 .. doctest::
478
479 >>> from cryptography.hazmat.primitives import hashes
480 >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
481 True
482
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800483 .. attribute:: signature_algorithm_oid
484
485 .. versionadded:: 1.6
486
487 :type: :class:`ObjectIdentifier`
488
489 Returns the :class:`ObjectIdentifier` of the signature algorithm used
490 to sign the CRL. This will be one of the OIDs from
491 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
492
493 .. doctest::
494
495 >>> crl.signature_algorithm_oid
496 <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
497
Erik Trauschke2dcce902015-05-14 16:12:24 -0700498 .. attribute:: issuer
499
500 :type: :class:`Name`
501
502 The :class:`Name` of the issuer.
503
Erik Trauschkedc570402015-09-24 20:24:28 -0700504 .. doctest::
505
506 >>> crl.issuer
507 <Name([<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>, <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'cryptography.io')>])>
508
Erik Trauschke2dcce902015-05-14 16:12:24 -0700509 .. attribute:: next_update
510
511 :type: :class:`datetime.datetime`
512
513 A naïve datetime representing when the next update to this CRL is
514 expected.
515
Erik Trauschkedc570402015-09-24 20:24:28 -0700516 .. doctest::
517
518 >>> crl.next_update
519 datetime.datetime(2016, 1, 1, 0, 0)
520
Erik Trauschke2dcce902015-05-14 16:12:24 -0700521 .. attribute:: last_update
522
523 :type: :class:`datetime.datetime`
524
525 A naïve datetime representing when the this CRL was last updated.
526
Erik Trauschkedc570402015-09-24 20:24:28 -0700527 .. doctest::
Erik Trauschke2dcce902015-05-14 16:12:24 -0700528
Erik Trauschkedc570402015-09-24 20:24:28 -0700529 >>> crl.last_update
530 datetime.datetime(2015, 1, 1, 0, 0)
Erik Trauschke2dcce902015-05-14 16:12:24 -0700531
532 .. attribute:: extensions
533
534 :type: :class:`Extensions`
535
536 The extensions encoded in the CRL.
537
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800538 .. attribute:: signature
539
540 .. versionadded:: 1.2
541
542 :type: bytes
543
544 The bytes of the CRL's signature.
545
546 .. attribute:: tbs_certlist_bytes
547
548 .. versionadded:: 1.2
549
550 :type: bytes
551
552 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
553 and then signed by the private key of the CRL's issuer. This data may be
554 used to validate a signature, but use extreme caution as CRL validation
555 is a complex problem that involves much more than just signature checks.
556
Paul Kehrer54a837d2015-12-20 23:42:32 -0600557 .. method:: public_bytes(encoding)
558
559 .. versionadded:: 1.2
560
561 :param encoding: The
562 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
563 that will be used to serialize the certificate revocation list.
564
565 :return bytes: The data that can be written to a file or sent
566 over the network and used as part of a certificate verification
567 process.
568
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800569
Andre Caron9bbfcea2015-05-18 20:55:29 -0400570X.509 Certificate Builder
571~~~~~~~~~~~~~~~~~~~~~~~~~
572
573.. class:: CertificateBuilder
574
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500575 .. versionadded:: 1.0
576
577 .. doctest::
578
579 >>> from cryptography import x509
580 >>> from cryptography.hazmat.backends import default_backend
581 >>> from cryptography.hazmat.primitives import hashes
582 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -0500583 >>> from cryptography.x509.oid import NameOID
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500584 >>> import datetime
585 >>> import uuid
586 >>> one_day = datetime.timedelta(1, 0, 0)
587 >>> private_key = rsa.generate_private_key(
588 ... public_exponent=65537,
589 ... key_size=2048,
590 ... backend=default_backend()
591 ... )
Cory Benfieldc47b2522015-12-07 15:25:12 +0000592 >>> public_key = private_key.public_key()
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500593 >>> builder = x509.CertificateBuilder()
594 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500595 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500596 ... ]))
597 >>> builder = builder.issuer_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500598 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500599 ... ]))
600 >>> builder = builder.not_valid_before(datetime.datetime.today() - one_day)
601 >>> builder = builder.not_valid_after(datetime.datetime(2018, 8, 2))
602 >>> builder = builder.serial_number(int(uuid.uuid4()))
603 >>> builder = builder.public_key(public_key)
604 >>> builder = builder.add_extension(
605 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
606 ... )
607 >>> certificate = builder.sign(
608 ... private_key=private_key, algorithm=hashes.SHA256(),
609 ... backend=default_backend()
610 ... )
611 >>> isinstance(certificate, x509.Certificate)
612 True
613
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500614 .. method:: issuer_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400615
616 Sets the issuer's distinguished name.
617
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500618 :param name: The :class:`~cryptography.x509.Name` that describes the
619 issuer (CA).
Andre Caron9bbfcea2015-05-18 20:55:29 -0400620
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500621 .. method:: subject_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400622
623 Sets the subject's distinguished name.
624
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500625 :param name: The :class:`~cryptography.x509.Name` that describes the
Ian Cordasco85fc4d52015-08-01 20:29:31 -0500626 subject.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400627
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500628 .. method:: public_key(public_key)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400629
630 Sets the subject's public key.
631
Ian Cordasco8f571422015-08-02 11:31:08 -0500632 :param public_key: The subject's public key. This can be one of
633 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`,
634 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
635 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400636
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500637 .. method:: serial_number(serial_number)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400638
639 Sets the certificate's serial number (an integer). The CA's policy
640 determines how it attributes serial numbers to certificates. The only
641 requirement is that this number uniquely identify the certificate given
642 the issuer.
643
644 :param serial_number: Integer number that will be used by the CA to
645 identify this certificate (most notably during certificate
Ian Cordasco17c89002015-08-02 21:13:59 -0500646 revocation checking). Users are encouraged to use a method of
647 generating 20 bytes of entropy, e.g., UUID4. For more information
Ian Cordascob7530a42015-08-02 22:47:06 -0500648 on secure random number generation, see :doc:`/random-numbers`.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400649
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500650 .. method:: not_valid_before(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400651
652 Sets the certificate's activation time. This is the time from which
653 clients can start trusting the certificate. It may be different from
654 the time at which the certificate was created.
655
Ian Cordasco17c89002015-08-02 21:13:59 -0500656 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400657 activation time for the certificate. The certificate may not be
658 trusted clients if it is used before this time.
659
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500660 .. method:: not_valid_after(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400661
662 Sets the certificate's expiration time. This is the time from which
663 clients should no longer trust the certificate. The CA's policy will
664 determine how long the certificate should remain in use.
665
Ian Cordasco17c89002015-08-02 21:13:59 -0500666 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400667 expiration time for the certificate. The certificate may not be
668 trusted clients if it is used after this time.
669
Ian Cordasco17c89002015-08-02 21:13:59 -0500670 .. method:: add_extension(extension, critical)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400671
672 Adds an X.509 extension to the certificate.
673
Paul Kehrer2c145cc2015-10-02 11:27:21 -0500674 :param extension: An extension conforming to the
675 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400676
Ian Cordasco17c89002015-08-02 21:13:59 -0500677 :param critical: Set to ``True`` if the extension must be understood and
678 handled by whoever reads the certificate.
679
Paul Kehrer9add80e2015-08-03 17:53:14 +0100680 .. method:: sign(private_key, algorithm, backend)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400681
682 Sign the certificate using the CA's private key.
683
Ian Cordascoc5e1c252015-07-31 23:33:35 -0500684 :param private_key: The
685 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
686 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
687 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
688 that will be used to sign the certificate.
689
Andre Caron9bbfcea2015-05-18 20:55:29 -0400690 :param algorithm: The
691 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
692 will be used to generate the signature.
693
Paul Kehrer9add80e2015-08-03 17:53:14 +0100694 :param backend: Backend that will be used to build the certificate.
695 Must support the
696 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
697 interface.
698
Benjamin Peterson9ed312b2015-10-12 20:51:34 -0700699 :returns: :class:`~cryptography.x509.Certificate`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400700
701
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500702X.509 CSR (Certificate Signing Request) Object
703~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600704
Paul Kehrera1a1f232015-03-15 15:34:35 -0500705.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600706
707 .. versionadded:: 0.9
708
709 .. method:: public_key()
710
Alex Gaynor4c2561a2015-10-12 23:53:39 -0400711 The public key associated with the request.
712
713 :returns:
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600714 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
715 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
716 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
717
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600718 .. doctest::
719
720 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500721 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600722 >>> isinstance(public_key, rsa.RSAPublicKey)
723 True
724
725 .. attribute:: subject
726
727 :type: :class:`Name`
728
729 The :class:`Name` of the subject.
730
731 .. attribute:: signature_hash_algorithm
732
733 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
734
735 Returns the
736 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
737 was used in signing this request.
738
739 .. doctest::
740
741 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500742 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600743 True
744
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800745 .. attribute:: signature_algorithm_oid
746
747 .. versionadded:: 1.6
748
749 :type: :class:`ObjectIdentifier`
750
751 Returns the :class:`ObjectIdentifier` of the signature algorithm used
752 to sign the request. This will be one of the OIDs from
753 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
754
755 .. doctest::
756
757 >>> csr.signature_algorithm_oid
758 <ObjectIdentifier(oid=1.2.840.113549.1.1.5, name=sha1WithRSAEncryption)>
759
Paul Kehrerc4e61942015-08-01 21:21:13 +0100760 .. attribute:: extensions
761
762 :type: :class:`Extensions`
763
764 The extensions encoded in the certificate signing request.
765
766 :raises cryptography.x509.DuplicateExtension: If more than one
Paul Kehrer24283d22015-08-01 21:31:19 +0100767 extension of the same type is found within the certificate signing request.
Paul Kehrerc4e61942015-08-01 21:21:13 +0100768
Paul Kehrer24283d22015-08-01 21:31:19 +0100769 :raises cryptography.x509.UnsupportedExtension: If the certificate signing request
Paul Kehrerc4e61942015-08-01 21:21:13 +0100770 contains an extension that is not supported.
771
772 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
773 contains a general name that is not supported.
774
775 :raises UnicodeError: If an extension contains IDNA encoding that is
776 invalid or not compliant with IDNA 2008.
777
778
Andre Caron476c5df2015-05-18 10:23:28 -0400779 .. method:: public_bytes(encoding)
780
Alex Gaynord0b376b2015-07-05 13:58:12 -0400781 .. versionadded:: 1.0
782
Andre Caron476c5df2015-05-18 10:23:28 -0400783 :param encoding: The
784 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
785 that will be used to serialize the certificate request.
786
787 :return bytes: The data that can be written to a file or sent
788 over the network to be signed by the certificate
789 authority.
790
Paul Kehrerab209392015-12-01 14:50:31 -0600791 .. attribute:: signature
792
793 .. versionadded:: 1.2
794
795 :type: bytes
796
797 The bytes of the certificate signing request's signature.
798
799 .. attribute:: tbs_certrequest_bytes
800
801 .. versionadded:: 1.2
802
803 :type: bytes
804
805 The DER encoded bytes payload (as defined by :rfc:`2986`) that is
806 hashed and then signed by the private key (corresponding to the public
807 key embedded in the CSR). This data may be used to validate the CSR
808 signature.
809
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100810 .. attribute:: is_signature_valid
Joern Heissler1bd77e22016-01-13 22:51:37 +0100811
812 .. versionadded:: 1.3
813
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100814 Returns True if the CSR signature is correct, False otherwise.
Joern Heissler1bd77e22016-01-13 22:51:37 +0100815
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600816X.509 Certificate Revocation List Builder
817~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
818
819.. class:: CertificateRevocationListBuilder
820
821 .. versionadded:: 1.2
822
823 .. doctest::
824
825 >>> from cryptography import x509
826 >>> from cryptography.hazmat.backends import default_backend
827 >>> from cryptography.hazmat.primitives import hashes
828 >>> from cryptography.hazmat.primitives.asymmetric import rsa
829 >>> from cryptography.x509.oid import NameOID
830 >>> import datetime
831 >>> one_day = datetime.timedelta(1, 0, 0)
832 >>> private_key = rsa.generate_private_key(
833 ... public_exponent=65537,
834 ... key_size=2048,
835 ... backend=default_backend()
836 ... )
837 >>> builder = x509.CertificateRevocationListBuilder()
838 >>> builder = builder.issuer_name(x509.Name([
839 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io CA'),
840 ... ]))
841 >>> builder = builder.last_update(datetime.datetime.today())
842 >>> builder = builder.next_update(datetime.datetime.today() + one_day)
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600843 >>> revoked_cert = x509.RevokedCertificateBuilder().serial_number(
844 ... 333
845 ... ).revocation_date(
846 ... datetime.datetime.today()
847 ... ).build(default_backend())
848 >>> builder = builder.add_revoked_certificate(revoked_cert)
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600849 >>> crl = builder.sign(
850 ... private_key=private_key, algorithm=hashes.SHA256(),
851 ... backend=default_backend()
852 ... )
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600853 >>> len(crl)
854 1
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600855
856 .. method:: issuer_name(name)
857
858 Sets the issuer's distinguished name.
859
860 :param name: The :class:`~cryptography.x509.Name` that describes the
861 issuer (CA).
862
863 .. method:: last_update(time)
864
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600865 Sets this CRL's activation time. This is the time from which
866 clients can start trusting this CRL. It may be different from
867 the time at which this CRL was created. This is also known as the
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600868 ``thisUpdate`` time.
869
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600870 :param time: The :class:`datetime.datetime` object (in UTC) that marks
871 the activation time for this CRL. The CRL may not be trusted if it
872 is used before this time.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600873
874 .. method:: next_update(time)
875
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600876 Sets this CRL's next update time. This is the time by which
877 a new CRL will be issued. The CA is allowed to issue a new CRL before
878 this date, however clients are not required to check for it.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600879
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600880 :param time: The :class:`datetime.datetime` object (in UTC) that marks
881 the next update time for this CRL.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600882
Paul Kehrer426b48d2015-12-24 20:50:43 -0600883 .. method:: add_extension(extension, critical)
884
885 Adds an X.509 extension to this CRL.
886
887 :param extension: An extension with the
888 :class:`~cryptography.x509.ExtensionType` interface.
889
890 :param critical: Set to ``True`` if the extension must be understood and
891 handled by whoever reads the CRL.
892
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600893 .. method:: add_revoked_certificate(revoked_certificate)
894
895 Adds a revoked certificate to this CRL.
896
897 :param revoked_certificate: An instance of
898 :class:`~cryptography.x509.RevokedCertificate`. These can be
899 obtained from an existing CRL or created with
900 :class:`~cryptography.x509.RevokedCertificateBuilder`.
901
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600902 .. method:: sign(private_key, algorithm, backend)
903
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600904 Sign this CRL using the CA's private key.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600905
906 :param private_key: The
907 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
908 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
909 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
910 that will be used to sign the certificate.
911
912 :param algorithm: The
913 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
914 will be used to generate the signature.
915
916 :param backend: Backend that will be used to build the CRL.
917 Must support the
918 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
919 interface.
920
921 :returns: :class:`~cryptography.x509.CertificateRevocationList`
922
Erik Trauschke2dcce902015-05-14 16:12:24 -0700923X.509 Revoked Certificate Object
Erik Trauschkec5a8d172015-05-28 10:24:25 -0700924~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Erik Trauschke2dcce902015-05-14 16:12:24 -0700925
926.. class:: RevokedCertificate
927
928 .. versionadded:: 1.0
929
930 .. attribute:: serial_number
931
932 :type: :class:`int`
933
934 An integer representing the serial number of the revoked certificate.
935
Erik Trauschkedc570402015-09-24 20:24:28 -0700936 .. doctest::
937
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700938 >>> revoked_certificate.serial_number
Erik Trauschkedc570402015-09-24 20:24:28 -0700939 0
940
Erik Trauschke2dcce902015-05-14 16:12:24 -0700941 .. attribute:: revocation_date
942
943 :type: :class:`datetime.datetime`
944
945 A naïve datetime representing the date this certificates was revoked.
946
Erik Trauschkedc570402015-09-24 20:24:28 -0700947 .. doctest::
948
Erik Trauschke77f5a252015-10-14 08:06:38 -0700949 >>> revoked_certificate.revocation_date
Erik Trauschkedc570402015-09-24 20:24:28 -0700950 datetime.datetime(2015, 1, 1, 0, 0)
951
Erik Trauschke2dcce902015-05-14 16:12:24 -0700952 .. attribute:: extensions
953
954 :type: :class:`Extensions`
955
956 The extensions encoded in the revoked certificate.
Andre Caron476c5df2015-05-18 10:23:28 -0400957
Erik Trauschkedc570402015-09-24 20:24:28 -0700958 .. doctest::
959
Erik Trauschke77f5a252015-10-14 08:06:38 -0700960 >>> for ext in revoked_certificate.extensions:
Erik Trauschkedc570402015-09-24 20:24:28 -0700961 ... print(ext)
Paul Kehrer23c0bbc2015-12-25 22:35:19 -0600962 <Extension(oid=<ObjectIdentifier(oid=2.5.29.24, name=invalidityDate)>, critical=False, value=<InvalidityDate(invalidity_date=2015-01-01 00:00:00)>)>
Paul Kehrer7058ece2015-12-25 22:28:29 -0600963 <Extension(oid=<ObjectIdentifier(oid=2.5.29.21, name=cRLReason)>, critical=False, value=<CRLReason(reason=ReasonFlags.key_compromise)>)>
Erik Trauschkedc570402015-09-24 20:24:28 -0700964
Paul Kehrerc33ffd72015-12-25 10:59:22 -0600965X.509 Revoked Certificate Builder
966~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
967
968.. class:: RevokedCertificateBuilder
969
970 This class is used to create :class:`~cryptography.x509.RevokedCertificate`
971 objects that can be used with the
972 :class:`~cryptography.x509.CertificateRevocationListBuilder`.
973
974 .. versionadded:: 1.2
975
976 .. doctest::
977
978 >>> from cryptography import x509
979 >>> from cryptography.hazmat.backends import default_backend
980 >>> import datetime
981 >>> builder = x509.RevokedCertificateBuilder()
982 >>> builder = builder.revocation_date(datetime.datetime.today())
983 >>> builder = builder.serial_number(3333)
984 >>> revoked_certificate = builder.build(default_backend())
985 >>> isinstance(revoked_certificate, x509.RevokedCertificate)
986 True
987
988 .. method:: serial_number(serial_number)
989
990 Sets the revoked certificate's serial number.
991
992 :param serial_number: Integer number that is used to identify the
993 revoked certificate.
994
995 .. method:: revocation_date(time)
996
997 Sets the certificate's revocation date.
998
999 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
1000 revocation time for the certificate.
1001
Paul Kehrere5f152b2015-12-25 23:55:47 -06001002 .. method:: add_extension(extension, critical)
1003
1004 Adds an X.509 extension to this revoked certificate.
1005
1006 :param extension: An instance of one of the
1007 :ref:`CRL entry extensions <crl_entry_extensions>`.
1008
1009 :param critical: Set to ``True`` if the extension must be understood and
1010 handled.
1011
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001012 .. method:: build(backend)
1013
1014 Create a revoked certificate object using the provided backend.
1015
1016 :param backend: Backend that will be used to build the revoked
1017 certificate. Must support the
1018 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1019 interface.
1020
1021 :returns: :class:`~cryptography.x509.RevokedCertificate`
1022
Andre Caron0ef595f2015-05-18 13:53:43 -04001023X.509 CSR (Certificate Signing Request) Builder Object
1024~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1025
1026.. class:: CertificateSigningRequestBuilder
1027
Andre Carond259ee52015-06-02 23:47:11 -04001028 .. versionadded:: 1.0
1029
1030 .. doctest::
1031
1032 >>> from cryptography import x509
1033 >>> from cryptography.hazmat.backends import default_backend
1034 >>> from cryptography.hazmat.primitives import hashes
1035 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -05001036 >>> from cryptography.x509.oid import NameOID
Andre Carond259ee52015-06-02 23:47:11 -04001037 >>> private_key = rsa.generate_private_key(
1038 ... public_exponent=65537,
1039 ... key_size=2048,
1040 ... backend=default_backend()
1041 ... )
1042 >>> builder = x509.CertificateSigningRequestBuilder()
Andre Carona9a51172015-06-06 20:18:44 -04001043 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -05001044 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Andre Carond259ee52015-06-02 23:47:11 -04001045 ... ]))
Ian Cordascof06b6be2015-06-21 10:09:18 -05001046 >>> builder = builder.add_extension(
Ian Cordasco0112b022015-06-16 17:51:18 -05001047 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
Andre Caron472fd692015-06-06 20:04:44 -04001048 ... )
Andre Carond259ee52015-06-02 23:47:11 -04001049 >>> request = builder.sign(
Alex Gaynorde9e5842015-06-26 20:11:23 -04001050 ... private_key, hashes.SHA256(), default_backend()
Andre Carond259ee52015-06-02 23:47:11 -04001051 ... )
1052 >>> isinstance(request, x509.CertificateSigningRequest)
1053 True
1054
Andre Carona9a51172015-06-06 20:18:44 -04001055 .. method:: subject_name(name)
Andre Caron0ef595f2015-05-18 13:53:43 -04001056
Andre Caron341ff852015-06-06 20:14:31 -04001057 :param name: The :class:`~cryptography.x509.Name` of the certificate
1058 subject.
1059 :returns: A new
1060 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001061
Ian Cordascof06b6be2015-06-21 10:09:18 -05001062 .. method:: add_extension(extension, critical)
Andre Caron0ef595f2015-05-18 13:53:43 -04001063
Paul Kehrer2c145cc2015-10-02 11:27:21 -05001064 :param extension: An extension conforming to the
1065 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron472fd692015-06-06 20:04:44 -04001066 :param critical: Set to `True` if the extension must be understood and
1067 handled by whoever reads the certificate.
Andre Caron341ff852015-06-06 20:14:31 -04001068 :returns: A new
1069 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001070
Alex Gaynorb3b0fbe2015-06-26 19:57:18 -04001071 .. method:: sign(private_key, algorithm, backend)
Andre Caron0ef595f2015-05-18 13:53:43 -04001072
1073 :param backend: Backend that will be used to sign the request.
1074 Must support the
1075 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1076 interface.
1077
1078 :param private_key: The
Andre Caron24f9bf42015-06-06 20:14:54 -04001079 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
1080 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
1081 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
Andre Caron0ef595f2015-05-18 13:53:43 -04001082 that will be used to sign the request. When the request is
1083 signed by a certificate authority, the private key's associated
1084 public key will be stored in the resulting certificate.
1085
1086 :param algorithm: The
1087 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
1088 that will be used to generate the request signature.
1089
Andre Caron341ff852015-06-06 20:14:31 -04001090 :returns: A new
1091 :class:`~cryptography.x509.CertificateSigningRequest`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001092
1093
Paul Kehrer719d5362015-01-01 20:03:52 -06001094.. class:: Name
1095
1096 .. versionadded:: 0.8
1097
Paul Kehrer53d8d492015-02-13 18:47:30 -06001098 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -06001099 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -06001100 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -06001101 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
1102 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -06001103
Paul Kehrer53d8d492015-02-13 18:47:30 -06001104 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -06001105
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001106 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -06001107 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001108 >>> for attribute in cert.subject:
1109 ... print(attribute)
1110 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
1111 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')>
1112 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -06001113
Paul Kehrere901d642015-02-11 18:50:58 -06001114 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -06001115
Paul Kehrere901d642015-02-11 18:50:58 -06001116 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -06001117
Paul Kehrere901d642015-02-11 18:50:58 -06001118 :returns: A list of :class:`NameAttribute` instances that match the
1119 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -06001120
1121 .. doctest::
1122
Paul Kehrere27f6582015-08-10 18:33:38 -05001123 >>> cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)
Paul Kehrere901d642015-02-11 18:50:58 -06001124 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -06001125
Paul Kehrere76cd272014-12-14 19:00:51 -06001126.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -10001127
1128 .. versionadded:: 0.7
1129
1130 An enumeration for X.509 versions.
1131
1132 .. attribute:: v1
1133
1134 For version 1 X.509 certificates.
1135
1136 .. attribute:: v3
1137
1138 For version 3 X.509 certificates.
1139
Paul Kehrer806bfb22015-02-02 17:05:24 -06001140.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001141
1142 .. versionadded:: 0.8
1143
Paul Kehrer834d22f2015-02-06 11:01:07 -06001144 An X.509 name consists of a list of NameAttribute instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001145
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001146 .. attribute:: oid
1147
1148 :type: :class:`ObjectIdentifier`
1149
1150 The attribute OID.
1151
1152 .. attribute:: value
1153
Paul Kehrerd5852cb2015-01-30 08:25:23 -06001154 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001155
1156 The value of the attribute.
1157
1158.. class:: ObjectIdentifier
1159
1160 .. versionadded:: 0.8
1161
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001162 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -06001163 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001164
Paul Kehrerd44f9a62015-02-04 14:47:34 -06001165 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001166
1167 :type: :class:`str`
1168
Paul Kehrerfedf4f42015-02-06 11:22:07 -06001169 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001170
Paul Kehrer31bdf792015-03-25 14:11:00 -05001171.. _general_name_classes:
1172
1173General Name Classes
1174~~~~~~~~~~~~~~~~~~~~
1175
1176.. class:: GeneralName
1177
1178 .. versionadded:: 0.9
1179
1180 This is the generic interface that all the following classes are registered
1181 against.
1182
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001183.. class:: RFC822Name(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001184
1185 .. versionadded:: 0.9
1186
1187 This corresponds to an email address. For example, ``user@example.com``.
1188
1189 .. attribute:: value
1190
1191 :type: :term:`text`
1192
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001193.. class:: DNSName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001194
1195 .. versionadded:: 0.9
1196
1197 This corresponds to a domain name. For example, ``cryptography.io``.
1198
1199 .. attribute:: value
1200
1201 :type: :term:`text`
1202
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001203.. class:: DirectoryName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001204
1205 .. versionadded:: 0.9
1206
1207 This corresponds to a directory name.
1208
1209 .. attribute:: value
1210
1211 :type: :class:`Name`
1212
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001213.. class:: UniformResourceIdentifier(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001214
1215 .. versionadded:: 0.9
1216
1217 This corresponds to a uniform resource identifier. For example,
Paul Kehrerb8ef82e2015-04-22 16:04:24 -05001218 ``https://cryptography.io``. The URI is parsed and IDNA decoded (see
1219 :rfc:`5895`).
1220
1221 .. note::
1222
1223 URIs that do not contain ``://`` in them will not be decoded.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001224
1225 .. attribute:: value
1226
1227 :type: :term:`text`
1228
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001229.. class:: IPAddress(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001230
1231 .. versionadded:: 0.9
1232
1233 This corresponds to an IP address.
1234
1235 .. attribute:: value
1236
Paul Kehrereb177932015-05-17 18:33:33 -07001237 :type: :class:`~ipaddress.IPv4Address`,
1238 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
1239 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001240
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001241.. class:: RegisteredID(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001242
1243 .. versionadded:: 0.9
1244
1245 This corresponds to a registered ID.
1246
1247 .. attribute:: value
1248
1249 :type: :class:`ObjectIdentifier`
1250
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001251.. class:: OtherName(type_id, value)
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001252
1253 .. versionadded:: 1.0
1254
Joshua Tauberer18b6fc82015-07-05 21:44:51 +00001255 This corresponds to an ``otherName.`` An ``otherName`` has a type identifier and a value represented in binary DER format.
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001256
1257 .. attribute:: type_id
1258
1259 :type: :class:`ObjectIdentifier`
1260
1261 .. attribute:: value
1262
1263 :type: `bytes`
1264
Paul Kehrer8cf26422015-03-21 09:50:24 -05001265X.509 Extensions
1266~~~~~~~~~~~~~~~~
1267
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001268.. class:: Extensions
1269
1270 .. versionadded:: 0.9
1271
1272 An X.509 Extensions instance is an ordered list of extensions. The object
1273 is iterable to get every extension.
1274
Paul Kehrerfa56a232015-03-17 13:14:03 -05001275 .. method:: get_extension_for_oid(oid)
1276
1277 :param oid: An :class:`ObjectIdentifier` instance.
1278
1279 :returns: An instance of the extension class.
1280
1281 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1282 not have the extension requested.
1283
Paul Kehrerfa56a232015-03-17 13:14:03 -05001284 .. doctest::
1285
Paul Kehrere27f6582015-08-10 18:33:38 -05001286 >>> from cryptography.x509.oid import ExtensionOID
1287 >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS)
Paul Kehrerfa56a232015-03-17 13:14:03 -05001288 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1289
Phoebe Queen019b7f82015-08-12 03:52:03 +01001290 .. method:: get_extension_for_class(extclass)
1291
Phoebe Queen6a603eb2015-08-12 14:14:49 +01001292 .. versionadded:: 1.1
1293
Phoebe Queen019b7f82015-08-12 03:52:03 +01001294 :param extclass: An extension class.
1295
1296 :returns: An instance of the extension class.
1297
1298 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1299 not have the extension requested.
1300
1301 .. doctest::
1302
1303 >>> from cryptography import x509
1304 >>> cert.extensions.get_extension_for_class(x509.BasicConstraints)
1305 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1306
Paul Kehrer8cf26422015-03-21 09:50:24 -05001307.. class:: Extension
1308
1309 .. versionadded:: 0.9
1310
Paul Kehrer85894662015-03-22 13:19:31 -05001311 .. attribute:: oid
1312
1313 :type: :class:`ObjectIdentifier`
1314
Paul Kehrere27f6582015-08-10 18:33:38 -05001315 One of the :class:`~cryptography.x509.oid.ExtensionOID` OIDs.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001316
1317 .. attribute:: critical
1318
1319 :type: bool
1320
Paul Kehrer58b75692015-03-22 23:24:58 -05001321 Determines whether a given extension is critical or not. :rfc:`5280`
1322 requires that "A certificate-using system MUST reject the certificate
1323 if it encounters a critical extension it does not recognize or a
1324 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -05001325
Paul Kehrer85894662015-03-22 13:19:31 -05001326 .. attribute:: value
1327
1328 Returns an instance of the extension type corresponding to the OID.
1329
Paul Kehrer14f0bd02015-08-06 11:55:18 +01001330.. class:: ExtensionType
1331
1332 .. versionadded:: 1.0
1333
1334 This is the interface against which all the following extension types are
1335 registered.
1336
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001337.. class:: KeyUsage(digital_signature, content_commitment, key_encipherment, data_encipherment, key_agreement, key_cert_sign, crl_sign, encipher_only, decipher_only)
Paul Kehrercecbbba2015-03-30 14:58:38 -05001338
1339 .. versionadded:: 0.9
1340
1341 The key usage extension defines the purpose of the key contained in the
1342 certificate. The usage restriction might be employed when a key that could
Paul Kehrerb33de932015-08-06 23:41:05 +01001343 be used for more than one operation is to be restricted.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001344
Paul Kehrer822f3d32015-08-06 11:47:32 +01001345 .. attribute:: oid
1346
1347 .. versionadded:: 1.0
1348
1349 :type: :class:`ObjectIdentifier`
1350
Paul Kehrere27f6582015-08-10 18:33:38 -05001351 Returns :attr:`~cryptography.x509.oid.ExtensionOID.KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001352
Paul Kehrercecbbba2015-03-30 14:58:38 -05001353 .. attribute:: digital_signature
1354
1355 :type: bool
1356
Paul Kehrer738407b2015-04-01 22:39:02 -05001357 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001358 digital signatures, other than signatures on certificates
1359 (``key_cert_sign``) and CRLs (``crl_sign``).
1360
1361 .. attribute:: content_commitment
1362
1363 :type: bool
1364
Paul Kehrer738407b2015-04-01 22:39:02 -05001365 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001366 digital signatures, other than signatures on certificates
1367 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
1368 non-repudiation service that protects against the signing entity
1369 falsely denying some action. In the case of later conflict, a
1370 reliable third party may determine the authenticity of the signed
1371 data. This was called ``non_repudiation`` in older revisions of the
1372 X.509 specification.
1373
1374 .. attribute:: key_encipherment
1375
1376 :type: bool
1377
Paul Kehrer738407b2015-04-01 22:39:02 -05001378 This purpose is set to true when the subject public key is used for
1379 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001380
1381 .. attribute:: data_encipherment
1382
1383 :type: bool
1384
Paul Kehrer738407b2015-04-01 22:39:02 -05001385 This purpose is set to true when the subject public key is used for
1386 directly enciphering raw user data without the use of an intermediate
1387 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001388
1389 .. attribute:: key_agreement
1390
1391 :type: bool
1392
Paul Kehrer738407b2015-04-01 22:39:02 -05001393 This purpose is set to true when the subject public key is used for key
1394 agreement. For example, when a Diffie-Hellman key is to be used for
1395 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001396
1397 .. attribute:: key_cert_sign
1398
1399 :type: bool
1400
Paul Kehrer738407b2015-04-01 22:39:02 -05001401 This purpose is set to true when the subject public key is used for
1402 verifying signatures on public key certificates. If this purpose is set
1403 to true then ``ca`` must be true in the :class:`BasicConstraints`
1404 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001405
1406 .. attribute:: crl_sign
1407
1408 :type: bool
1409
Paul Kehrer738407b2015-04-01 22:39:02 -05001410 This purpose is set to true when the subject public key is used for
1411 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001412
1413 .. attribute:: encipher_only
1414
1415 :type: bool
1416
Paul Kehrer738407b2015-04-01 22:39:02 -05001417 When this purposes is set to true and the ``key_agreement`` purpose is
1418 also set, the subject public key may be used only for enciphering data
1419 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001420
1421 :raises ValueError: This is raised if accessed when ``key_agreement``
1422 is false.
1423
1424 .. attribute:: decipher_only
1425
1426 :type: bool
1427
Paul Kehrer738407b2015-04-01 22:39:02 -05001428 When this purposes is set to true and the ``key_agreement`` purpose is
1429 also set, the subject public key may be used only for deciphering data
1430 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001431
1432 :raises ValueError: This is raised if accessed when ``key_agreement``
1433 is false.
1434
1435
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001436.. class:: BasicConstraints(ca, path_length)
Paul Kehrer8cf26422015-03-21 09:50:24 -05001437
1438 .. versionadded:: 0.9
1439
Paul Kehrer85894662015-03-22 13:19:31 -05001440 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -05001441 certificate is allowed to sign additional certificates and what path
Paul Kehrerb33de932015-08-06 23:41:05 +01001442 length restrictions may exist.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001443
Paul Kehrer822f3d32015-08-06 11:47:32 +01001444 .. attribute:: oid
1445
1446 .. versionadded:: 1.0
1447
1448 :type: :class:`ObjectIdentifier`
1449
Paul Kehrere27f6582015-08-10 18:33:38 -05001450 Returns :attr:`~cryptography.x509.oid.ExtensionOID.BASIC_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001451
Paul Kehrer8cf26422015-03-21 09:50:24 -05001452 .. attribute:: ca
1453
1454 :type: bool
1455
1456 Whether the certificate can sign certificates.
1457
1458 .. attribute:: path_length
1459
Paul Kehrerfd1444c2015-03-21 19:47:05 -05001460 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -05001461
1462 The maximum path length for certificates subordinate to this
1463 certificate. This attribute only has meaning if ``ca`` is true.
1464 If ``ca`` is true then a path length of None means there's no
1465 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -04001466 If it is zero or greater then it defines the maximum length for a
1467 subordinate CA's certificate chain. For example, a ``path_length`` of 1
1468 means the certificate can sign a subordinate CA, but the subordinate CA
1469 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001470
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001471.. class:: ExtendedKeyUsage(usages)
Paul Kehrerffa2a152015-03-31 08:18:25 -05001472
1473 .. versionadded:: 0.9
1474
1475 This extension indicates one or more purposes for which the certified
1476 public key may be used, in addition to or in place of the basic
1477 purposes indicated in the key usage extension. The object is
Paul Kehrere27f6582015-08-10 18:33:38 -05001478 iterable to obtain the list of
1479 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs present.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001480
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001481 :param list usages: A list of
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001482 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs.
1483
Paul Kehrer822f3d32015-08-06 11:47:32 +01001484 .. attribute:: oid
1485
1486 .. versionadded:: 1.0
1487
1488 :type: :class:`ObjectIdentifier`
1489
Paul Kehrere27f6582015-08-10 18:33:38 -05001490 Returns :attr:`~cryptography.x509.oid.ExtensionOID.EXTENDED_KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001491
1492
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001493.. class:: OCSPNoCheck()
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001494
Paul Kehrer506a2152015-05-26 08:01:18 -05001495 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001496
1497 This presence of this extension indicates that an OCSP client can trust a
1498 responder for the lifetime of the responder's certificate. CAs issuing
1499 such a certificate should realize that a compromise of the responder's key
1500 is as serious as the compromise of a CA key used to sign CRLs, at least for
1501 the validity period of this certificate. CA's may choose to issue this type
1502 of certificate with a very short lifetime and renew it frequently. This
1503 extension is only relevant when the certificate is an authorized OCSP
1504 responder.
1505
Paul Kehrer822f3d32015-08-06 11:47:32 +01001506 .. attribute:: oid
1507
1508 .. versionadded:: 1.0
1509
1510 :type: :class:`ObjectIdentifier`
1511
Paul Kehrere27f6582015-08-10 18:33:38 -05001512 Returns :attr:`~cryptography.x509.oid.ExtensionOID.OCSP_NO_CHECK`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001513
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001514.. class:: NameConstraints(permitted_subtrees, excluded_subtrees)
Paul Kehrere0017be2015-05-17 20:39:40 -06001515
1516 .. versionadded:: 1.0
1517
1518 The name constraints extension, which only has meaning in a CA certificate,
1519 defines a name space within which all subject names in certificates issued
1520 beneath the CA certificate must (or must not) be in. For specific details
1521 on the way this extension should be processed see :rfc:`5280`.
1522
Paul Kehrer822f3d32015-08-06 11:47:32 +01001523 .. attribute:: oid
1524
1525 .. versionadded:: 1.0
1526
1527 :type: :class:`ObjectIdentifier`
1528
Paul Kehrere27f6582015-08-10 18:33:38 -05001529 Returns :attr:`~cryptography.x509.oid.ExtensionOID.NAME_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001530
Paul Kehrere0017be2015-05-17 20:39:40 -06001531 .. attribute:: permitted_subtrees
1532
1533 :type: list of :class:`GeneralName` objects or None
1534
1535 The set of permitted name patterns. If a name matches this and an
1536 element in ``excluded_subtrees`` it is invalid. At least one of
1537 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
1538
1539 .. attribute:: excluded_subtrees
1540
1541 :type: list of :class:`GeneralName` objects or None
1542
1543 Any name matching a restriction in the ``excluded_subtrees`` field is
1544 invalid regardless of information appearing in the
1545 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
1546 ``excluded_subtrees`` will be non-None.
1547
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001548.. class:: AuthorityKeyIdentifier(key_identifier, authority_cert_issuer, authority_cert_serial_number)
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001549
1550 .. versionadded:: 0.9
1551
1552 The authority key identifier extension provides a means of identifying the
1553 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001554 This extension is typically used to assist in determining the appropriate
1555 certificate chain. For more information about generation and use of this
1556 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001557
Paul Kehrer822f3d32015-08-06 11:47:32 +01001558 .. attribute:: oid
1559
1560 .. versionadded:: 1.0
1561
1562 :type: :class:`ObjectIdentifier`
1563
Paul Kehrere27f6582015-08-10 18:33:38 -05001564 Returns
1565 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001566
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001567 .. attribute:: key_identifier
1568
1569 :type: bytes
1570
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001571 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001572 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001573
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001574 .. attribute:: authority_cert_issuer
1575
1576 :type: :class:`Name` or None
1577
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001578 The :class:`Name` of the issuer's issuer.
1579
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001580 .. attribute:: authority_cert_serial_number
1581
1582 :type: int or None
1583
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001584 The serial number of the issuer's issuer.
1585
Paul Kehrer253929a2015-08-05 17:30:39 +01001586 .. classmethod:: from_issuer_public_key(public_key)
1587
1588 .. versionadded:: 1.0
1589
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001590 .. note::
1591
1592 This method should be used if the issuer certificate does not
1593 contain a :class:`~cryptography.x509.SubjectKeyIdentifier`.
1594 Otherwise, use
1595 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier`.
1596
Paul Kehrer253929a2015-08-05 17:30:39 +01001597 Creates a new AuthorityKeyIdentifier instance using the public key
1598 provided to generate the appropriate digest. This should be the
Paul Kehrer26ac47f2015-08-08 15:20:52 -05001599 **issuer's public key**. The resulting object will contain
1600 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1601 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1602 and
1603 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1604 will be None.
1605 The generated ``key_identifier`` is the SHA1 hash of the ``subjectPublicKey``
1606 ASN.1 bit string. This is the first recommendation in :rfc:`5280`
Paul Kehrer253929a2015-08-05 17:30:39 +01001607 section 4.2.1.2.
1608
Paul Kehrercc671822015-08-08 15:41:54 -05001609 :param public_key: One of
1610 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1611 ,
1612 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1613 , or
1614 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
Paul Kehrer253929a2015-08-05 17:30:39 +01001615
1616 .. doctest::
1617
1618 >>> from cryptography import x509
1619 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001620 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1621 >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key())
Paul Kehrer253929a2015-08-05 17:30:39 +01001622 <AuthorityKeyIdentifier(key_identifier='X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9', authority_cert_issuer=None, authority_cert_serial_number=None)>
1623
Paul Kehrer61ff3562016-03-11 22:51:27 -04001624 .. classmethod:: from_issuer_subject_key_identifier(ski)
1625
1626 .. versionadded:: 1.3
1627
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001628 .. note::
1629 This method should be used if the issuer certificate contains a
1630 :class:`~cryptography.x509.SubjectKeyIdentifier`. Otherwise, use
1631 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_public_key`.
1632
Paul Kehrer61ff3562016-03-11 22:51:27 -04001633 Creates a new AuthorityKeyIdentifier instance using the
1634 SubjectKeyIdentifier from the issuer certificate. The resulting object
1635 will contain
1636 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1637 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1638 and
1639 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1640 will be None.
1641
1642 :param ski: The
1643 :class:`~cryptography.x509.SubjectKeyIdentifier` from the issuer
1644 certificate.
1645
1646 .. doctest::
1647
1648 >>> from cryptography import x509
1649 >>> from cryptography.hazmat.backends import default_backend
1650 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1651 >>> ski = issuer_cert.extensions.get_extension_for_class(x509.SubjectKeyIdentifier)
1652 >>> x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(ski)
1653 <AuthorityKeyIdentifier(key_identifier='X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9', authority_cert_issuer=None, authority_cert_serial_number=None)>
1654
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001655.. class:: SubjectKeyIdentifier(digest)
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001656
1657 .. versionadded:: 0.9
1658
1659 The subject key identifier extension provides a means of identifying
1660 certificates that contain a particular public key.
1661
Paul Kehrer822f3d32015-08-06 11:47:32 +01001662 .. attribute:: oid
1663
1664 .. versionadded:: 1.0
1665
1666 :type: :class:`ObjectIdentifier`
1667
Paul Kehrere27f6582015-08-10 18:33:38 -05001668 Returns
1669 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001670
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001671 .. attribute:: digest
1672
1673 :type: bytes
1674
1675 The binary value of the identifier.
1676
Paul Kehrerd4a7f062015-08-05 18:32:18 +01001677 .. classmethod:: from_public_key(public_key)
Paul Kehrerf22f6122015-08-05 12:57:13 +01001678
1679 .. versionadded:: 1.0
1680
1681 Creates a new SubjectKeyIdentifier instance using the public key
1682 provided to generate the appropriate digest. This should be the public
Paul Kehrereb9ec002015-08-08 10:03:02 -05001683 key that is in the certificate. The generated digest is the SHA1 hash
1684 of the ``subjectPublicKey`` ASN.1 bit string. This is the first
1685 recommendation in :rfc:`5280` section 4.2.1.2.
Paul Kehrerf22f6122015-08-05 12:57:13 +01001686
1687 :param public_key: One of
1688 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1689 ,
1690 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1691 , or
1692 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
1693
Paul Kehrer253929a2015-08-05 17:30:39 +01001694 .. doctest::
1695
1696 >>> from cryptography import x509
1697 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001698 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
1699 >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key())
1700 <SubjectKeyIdentifier(digest='\xdb\xaa\xf0\x06\x11\xdbD\xfe\xbf\x93\x03\x8av\x88WP7\xa6\x91\xf7')>
Paul Kehrer253929a2015-08-05 17:30:39 +01001701
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001702.. class:: SubjectAlternativeName(general_names)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001703
1704 .. versionadded:: 0.9
1705
1706 Subject alternative name is an X.509 extension that provides a list of
1707 :ref:`general name <general_name_classes>` instances that provide a set
1708 of identities for which the certificate is valid. The object is iterable to
1709 get every element.
1710
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001711 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001712
Paul Kehrer822f3d32015-08-06 11:47:32 +01001713 .. attribute:: oid
1714
1715 .. versionadded:: 1.0
1716
1717 :type: :class:`ObjectIdentifier`
1718
Paul Kehrere27f6582015-08-10 18:33:38 -05001719 Returns
1720 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001721
Paul Kehrer31bdf792015-03-25 14:11:00 -05001722 .. method:: get_values_for_type(type)
1723
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03001724 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer31bdf792015-03-25 14:11:00 -05001725 :ref:`general name classes <general_name_classes>`.
1726
1727 :returns: A list of values extracted from the matched general names.
Joshua Taubererd2afad32015-07-06 22:37:53 +00001728 The type of the returned values depends on the :class:`GeneralName`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001729
Paul Kehrer93ae8052015-05-02 23:18:09 -05001730 .. doctest::
1731
1732 >>> from cryptography import x509
1733 >>> from cryptography.hazmat.backends import default_backend
1734 >>> from cryptography.hazmat.primitives import hashes
1735 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001736 >>> # Get the subjectAltName extension from the certificate
Paul Kehrere27f6582015-08-10 18:33:38 -05001737 >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001738 >>> # Get the dNSName entries from the SAN extension
1739 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer93ae8052015-05-02 23:18:09 -05001740 [u'www.cryptography.io', u'cryptography.io']
1741
Paul Kehrer8cf26422015-03-21 09:50:24 -05001742
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001743.. class:: IssuerAlternativeName(general_names)
Paul Kehrer99125c92015-06-07 18:37:10 -05001744
1745 .. versionadded:: 1.0
1746
1747 Issuer alternative name is an X.509 extension that provides a list of
1748 :ref:`general name <general_name_classes>` instances that provide a set
1749 of identities for the certificate issuer. The object is iterable to
1750 get every element.
1751
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001752 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001753
Paul Kehrer822f3d32015-08-06 11:47:32 +01001754 .. attribute:: oid
1755
1756 .. versionadded:: 1.0
1757
1758 :type: :class:`ObjectIdentifier`
1759
Paul Kehrere27f6582015-08-10 18:33:38 -05001760 Returns
1761 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUER_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001762
Paul Kehrer99125c92015-06-07 18:37:10 -05001763 .. method:: get_values_for_type(type)
1764
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03001765 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer99125c92015-06-07 18:37:10 -05001766 :ref:`general name classes <general_name_classes>`.
1767
1768 :returns: A list of values extracted from the matched general names.
1769
1770
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001771.. class:: AuthorityInformationAccess(descriptions)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001772
1773 .. versionadded:: 0.9
1774
1775 The authority information access extension indicates how to access
1776 information and services for the issuer of the certificate in which
1777 the extension appears. Information and services may include online
1778 validation services (such as OCSP) and issuer data. It is an iterable,
Paul Kehrere27f6582015-08-10 18:33:38 -05001779 containing one or more :class:`~cryptography.x509.AccessDescription`
1780 instances.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001781
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001782 :param list descriptions: A list of :class:`AccessDescription` objects.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001783
Paul Kehrer822f3d32015-08-06 11:47:32 +01001784 .. attribute:: oid
1785
1786 .. versionadded:: 1.0
1787
1788 :type: :class:`ObjectIdentifier`
1789
Paul Kehrere27f6582015-08-10 18:33:38 -05001790 Returns
1791 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_INFORMATION_ACCESS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001792
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001793
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001794.. class:: AccessDescription(access_method, access_location)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001795
Paul Kehrer5a485522015-05-06 00:29:12 -05001796 .. versionadded:: 0.9
1797
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001798 .. attribute:: access_method
1799
1800 :type: :class:`ObjectIdentifier`
1801
Paul Kehrerf506bca2015-05-02 22:31:47 -05001802 The access method defines what the ``access_location`` means. It must
Paul Kehrere27f6582015-08-10 18:33:38 -05001803 be either
1804 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` or
1805 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`.
1806 If it is
1807 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP`
1808 the access location will be where to obtain OCSP
1809 information for the certificate. If it is
1810 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`
1811 the access location will provide additional information about the
1812 issuing certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001813
1814 .. attribute:: access_location
1815
1816 :type: :class:`GeneralName`
1817
Paul Kehrerf506bca2015-05-02 22:31:47 -05001818 Where to access the information defined by the access method.
1819
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001820.. class:: CRLDistributionPoints(distribution_points)
Paul Kehrer5a485522015-05-06 00:29:12 -05001821
1822 .. versionadded:: 0.9
1823
1824 The CRL distribution points extension identifies how CRL information is
1825 obtained. It is an iterable, containing one or more
1826 :class:`DistributionPoint` instances.
1827
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001828 :param list distribution_points: A list of :class:`DistributionPoint`
1829 instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001830
Paul Kehrer822f3d32015-08-06 11:47:32 +01001831 .. attribute:: oid
1832
1833 .. versionadded:: 1.0
1834
1835 :type: :class:`ObjectIdentifier`
1836
Paul Kehrere27f6582015-08-10 18:33:38 -05001837 Returns
1838 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_DISTRIBUTION_POINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001839
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001840.. class:: DistributionPoint(full_name, relative_name, reasons, crl_issuer)
Paul Kehrer5a485522015-05-06 00:29:12 -05001841
1842 .. versionadded:: 0.9
1843
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001844 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05001845
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001846 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001847
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001848 This field describes methods to retrieve the CRL. At most one of
1849 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001850
1851 .. attribute:: relative_name
1852
1853 :type: :class:`Name` or None
1854
1855 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001856 issuer. At most one of ``full_name`` or ``relative_name`` will be
1857 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05001858
1859 .. attribute:: crl_issuer
1860
1861 :type: list of :class:`GeneralName` instances or None
1862
1863 Information about the issuer of the CRL.
1864
1865 .. attribute:: reasons
1866
Paul Kehrer3fd02602015-05-09 19:46:13 -05001867 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001868
1869 The reasons a given distribution point may be used for when performing
1870 revocation checks.
1871
1872.. class:: ReasonFlags
1873
1874 .. versionadded:: 0.9
1875
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001876 An enumeration for CRL reasons.
1877
1878 .. attribute:: unspecified
1879
1880 It is unspecified why the certificate was revoked. This reason cannot
1881 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001882
1883 .. attribute:: key_compromise
1884
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001885 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001886
1887 .. attribute:: ca_compromise
1888
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001889 This reason indicates that the CA issuing the certificate was
1890 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001891
1892 .. attribute:: affiliation_changed
1893
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001894 This reason indicates that the subject's name or other information has
1895 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05001896
1897 .. attribute:: superseded
1898
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001899 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05001900
1901 .. attribute:: cessation_of_operation
1902
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001903 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05001904
1905 .. attribute:: certificate_hold
1906
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001907 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05001908
1909 .. attribute:: privilege_withdrawn
1910
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001911 This reason indicates that the privilege granted by this certificate
1912 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05001913
1914 .. attribute:: aa_compromise
1915
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001916 When an attribute authority has been compromised.
1917
1918 .. attribute:: remove_from_crl
1919
1920 This reason indicates that the certificate was on hold and should be
1921 removed from the CRL. This reason cannot be used as a reason flag
1922 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001923
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001924.. class:: InhibitAnyPolicy(skip_certs)
Paul Kehrer16fae762015-05-01 23:14:20 -05001925
1926 .. versionadded:: 1.0
1927
1928 The inhibit ``anyPolicy`` extension indicates that the special OID
Paul Kehrere27f6582015-08-10 18:33:38 -05001929 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY`, is not
1930 considered an explicit match for other :class:`CertificatePolicies` except
1931 when it appears in an intermediate self-issued CA certificate. The value
1932 indicates the number of additional non-self-issued certificates that may
1933 appear in the path before
1934 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` is no
1935 longer permitted. For example, a value of one indicates that
1936 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` may be
1937 processed in certificates issued by the subject of this certificate, but
1938 not in additional certificates in the path.
Paul Kehrer16fae762015-05-01 23:14:20 -05001939
Paul Kehrer822f3d32015-08-06 11:47:32 +01001940 .. attribute:: oid
1941
1942 .. versionadded:: 1.0
1943
1944 :type: :class:`ObjectIdentifier`
1945
Paul Kehrere27f6582015-08-10 18:33:38 -05001946 Returns
1947 :attr:`~cryptography.x509.oid.ExtensionOID.INHIBIT_ANY_POLICY`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001948
Paul Kehrer16fae762015-05-01 23:14:20 -05001949 .. attribute:: skip_certs
1950
1951 :type: int
1952
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07001953.. class:: PolicyConstraints
1954
1955 .. versionadded:: 1.3
1956
Paul Kehrer648c0fb2016-02-26 16:10:36 -06001957 The policy constraints extension is used to inhibit policy mapping or
1958 require that each certificate in a chain contain an acceptable policy
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07001959 identifier. For more information about the use of this extension see
1960 :rfc:`5280`.
1961
Paul Kehrer159b3b52016-02-26 08:27:22 -06001962 .. attribute:: oid
1963
1964 :type: :class:`ObjectIdentifier`
1965
1966 Returns :attr:`~cryptography.x509.oid.ExtensionOID.POLICY_CONSTRAINTS`.
1967
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07001968 .. attribute:: require_explicit_policy
1969
1970 :type: int or None
1971
Paul Kehrer648c0fb2016-02-26 16:10:36 -06001972 If this field is not None, the value indicates the number of additional
1973 certificates that may appear in the chain before an explicit policy is
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07001974 required for the entire path. When an explicit policy is required, it
Paul Kehrer648c0fb2016-02-26 16:10:36 -06001975 is necessary for all certificates in the chain to contain an acceptable
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07001976 policy identifier in the certificate policies extension. An
1977 acceptable policy identifier is the identifier of a policy required
1978 by the user of the certification path or the identifier of a policy
1979 that has been declared equivalent through policy mapping.
1980
1981 .. attribute:: inhibit_policy_mapping
1982
1983 :type: int or None
1984
Paul Kehrer648c0fb2016-02-26 16:10:36 -06001985 If this field is not None, the value indicates the number of additional
1986 certificates that may appear in the chain before policy mapping is no
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07001987 longer permitted. For example, a value of one indicates that policy
1988 mapping may be processed in certificates issued by the subject of this
Paul Kehrer648c0fb2016-02-26 16:10:36 -06001989 certificate, but not in additional certificates in the chain.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07001990
Paul Kehrer3b95cd72015-12-22 21:40:20 -06001991.. class:: CRLNumber(crl_number)
1992
1993 .. versionadded:: 1.2
1994
Paul Kehrere32b9942015-12-22 22:26:53 -06001995 The CRL number is a CRL extension that conveys a monotonically increasing
1996 sequence number for a given CRL scope and CRL issuer. This extension allows
1997 users to easily determine when a particular CRL supersedes another CRL.
1998 :rfc:`5280` requires that this extension be present in conforming CRLs.
Paul Kehrer3b95cd72015-12-22 21:40:20 -06001999
2000 .. attribute:: oid
2001
2002 :type: :class:`ObjectIdentifier`
2003
2004 Returns
2005 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_NUMBER`.
2006
2007 .. attribute:: crl_number
2008
2009 :type: int
2010
Paul Kehrer14fd6972015-12-30 10:58:25 -06002011.. class:: UnrecognizedExtension
2012
2013 .. versionadded:: 1.2
2014
2015 A generic extension class used to hold the raw value of **non-critical**
2016 extensions that ``cryptography`` does not know how to parse. Extensions
Paul Kehrer1628b5c2015-12-30 14:59:44 -06002017 marked critical will raise
Paul Kehrer14fd6972015-12-30 10:58:25 -06002018 :class:`~cryptography.x509.UnsupportedExtension`.
2019
2020 .. attribute:: oid
2021
2022 :type: :class:`ObjectIdentifier`
2023
2024 Returns the OID associated with this extension.
2025
2026 .. attribute:: value
2027
2028 :type: byte
2029
2030 Returns the DER encoded bytes payload of the extension.
2031
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002032.. class:: CertificatePolicies(policies)
Paul Kehrer0d210922015-04-28 17:31:07 -05002033
2034 .. versionadded:: 0.9
2035
Paul Kehrer2e879742015-05-02 23:09:56 -05002036 The certificate policies extension is an iterable, containing one or more
2037 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05002038
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002039 :param list policies: A list of :class:`PolicyInformation` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002040
Paul Kehrer822f3d32015-08-06 11:47:32 +01002041 .. attribute:: oid
2042
2043 .. versionadded:: 1.0
2044
2045 :type: :class:`ObjectIdentifier`
2046
Paul Kehrere27f6582015-08-10 18:33:38 -05002047 Returns
2048 :attr:`~cryptography.x509.oid.ExtensionOID.CERTIFICATE_POLICIES`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002049
Paul Kehrer0d210922015-04-28 17:31:07 -05002050Certificate Policies Classes
2051~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2052
2053These classes may be present within a :class:`CertificatePolicies` instance.
2054
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002055.. class:: PolicyInformation(policy_identifier, policy_qualifiers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002056
2057 .. versionadded:: 0.9
2058
2059 Contains a policy identifier and an optional list of qualifiers.
2060
2061 .. attribute:: policy_identifier
2062
2063 :type: :class:`ObjectIdentifier`
2064
2065 .. attribute:: policy_qualifiers
2066
2067 :type: list
2068
Paul Kehrerba35b3b2015-05-10 13:07:59 -05002069 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002070 If the value is text it is a pointer to the practice statement
2071 published by the certificate authority. If it is a user notice it is
2072 meant for display to the relying party when the certificate is
2073 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05002074
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002075.. class:: UserNotice(notice_reference, explicit_text)
Paul Kehrer0d210922015-04-28 17:31:07 -05002076
2077 .. versionadded:: 0.9
2078
Paul Kehrer2e879742015-05-02 23:09:56 -05002079 User notices are intended for display to a relying party when a certificate
2080 is used. In practice, few if any UIs expose this data and it is a rarely
2081 encoded component.
2082
Paul Kehrer0d210922015-04-28 17:31:07 -05002083 .. attribute:: notice_reference
2084
2085 :type: :class:`NoticeReference` or None
2086
Paul Kehrer2e879742015-05-02 23:09:56 -05002087 The notice reference field names an organization and identifies,
2088 by number, a particular statement prepared by that organization.
2089
Paul Kehrer0d210922015-04-28 17:31:07 -05002090 .. attribute:: explicit_text
2091
Paul Kehrer2e879742015-05-02 23:09:56 -05002092 This field includes an arbitrary textual statement directly in the
2093 certificate.
2094
Paul Kehrer0d210922015-04-28 17:31:07 -05002095 :type: :term:`text`
2096
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002097.. class:: NoticeReference(organization, notice_numbers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002098
Paul Kehrer2e879742015-05-02 23:09:56 -05002099 Notice reference can name an organization and provide information about
2100 notices related to the certificate. For example, it might identify the
2101 organization name and notice number 1. Application software could
2102 have a notice file containing the current set of notices for the named
2103 organization; the application would then extract the notice text from the
2104 file and display it. In practice this is rarely seen.
2105
Paul Kehrer0d210922015-04-28 17:31:07 -05002106 .. versionadded:: 0.9
2107
2108 .. attribute:: organization
2109
Paul Kehrer66c61702015-05-12 16:39:18 -05002110 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05002111
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002112 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05002113
Paul Kehrer66c61702015-05-12 16:39:18 -05002114 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05002115
Paul Kehrer66c61702015-05-12 16:39:18 -05002116 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05002117
Paul Kehrere5f152b2015-12-25 23:55:47 -06002118.. _crl_entry_extensions:
2119
Paul Kehrer49bb7562015-12-25 16:17:40 -06002120CRL Entry Extensions
2121~~~~~~~~~~~~~~~~~~~~
2122
2123These extensions are only valid within a :class:`RevokedCertificate` object.
2124
2125.. class:: CertificateIssuer(general_names)
2126
2127 .. versionadded:: 1.2
2128
2129 The certificate issuer is an extension that is only valid inside
2130 :class:`~cryptography.x509.RevokedCertificate` objects. If the
2131 ``indirectCRL`` property of the parent CRL's IssuingDistributionPoint
2132 extension is set, then this extension identifies the certificate issuer
2133 associated with the revoked certificate. The object is iterable to get
2134 every element.
2135
2136 :param list general_names: A list of :class:`GeneralName` instances.
2137
2138 .. attribute:: oid
2139
2140 :type: :class:`ObjectIdentifier`
2141
2142 Returns
2143 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CERTIFICATE_ISSUER`.
2144
2145 .. method:: get_values_for_type(type)
2146
2147 :param type: A :class:`GeneralName` instance. This is one of the
2148 :ref:`general name classes <general_name_classes>`.
2149
2150 :returns: A list of values extracted from the matched general names.
2151 The type of the returned values depends on the :class:`GeneralName`.
2152
Paul Kehrer7058ece2015-12-25 22:28:29 -06002153.. class:: CRLReason(reason)
2154
2155 .. versionadded:: 1.2
2156
2157 CRL reason (also known as ``reasonCode``) is an extension that is only
2158 valid inside :class:`~cryptography.x509.RevokedCertificate` objects. It
2159 identifies a reason for the certificate revocation.
2160
2161 :param reason: A value from the
2162 :class:`~cryptography.x509.oid.CRLEntryExtensionOID` enum.
2163
2164 .. attribute:: oid
2165
2166 :type: :class:`ObjectIdentifier`
2167
2168 Returns
2169 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CRL_REASON`.
2170
2171 .. attribute:: reason
2172
2173 :type: An element from :class:`~cryptography.x509.ReasonFlags`
2174
Paul Kehrer23c0bbc2015-12-25 22:35:19 -06002175.. class:: InvalidityDate(invalidity_date)
2176
2177 .. versionadded:: 1.2
2178
2179 Invalidity date is an extension that is only valid inside
2180 :class:`~cryptography.x509.RevokedCertificate` objects. It provides
2181 the date on which it is known or suspected that the private key was
2182 compromised or that the certificate otherwise became invalid.
2183 This date may be earlier than the revocation date in the CRL entry,
2184 which is the date at which the CA processed the revocation.
2185
2186 :param invalidity_date: The :class:`datetime.datetime` when it is known
2187 or suspected that the private key was compromised.
2188
2189 .. attribute:: oid
2190
2191 :type: :class:`ObjectIdentifier`
2192
2193 Returns
2194 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.INVALIDITY_DATE`.
2195
2196 .. attribute:: invalidity_date
2197
2198 :type: :class:`datetime.datetime`
2199
Paul Kehrer49bb7562015-12-25 16:17:40 -06002200
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002201Object Identifiers
2202~~~~~~~~~~~~~~~~~~
2203
Paul Kehrer4bb46492015-02-07 16:59:14 -06002204X.509 elements are frequently identified by :class:`ObjectIdentifier`
2205instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002206
Paul Kehrere27f6582015-08-10 18:33:38 -05002207.. currentmodule:: cryptography.x509.oid
Paul Kehrer56da2a52015-02-11 23:35:07 -06002208
Paul Kehrere27f6582015-08-10 18:33:38 -05002209.. class:: NameOID
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002210
Paul Kehrere27f6582015-08-10 18:33:38 -05002211 These OIDs are typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06002212
Paul Kehrere27f6582015-08-10 18:33:38 -05002213 .. versionadded:: 1.0
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002214
Paul Kehrere27f6582015-08-10 18:33:38 -05002215 .. attribute:: COMMON_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002216
Paul Kehrere27f6582015-08-10 18:33:38 -05002217 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
2218 name would be encoded here for server certificates. :rfc:`2818`
2219 deprecates this practice and names of that type should now be located
2220 in a :class:`~cryptography.x509.SubjectAlternativeName` extension.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002221
Paul Kehrere27f6582015-08-10 18:33:38 -05002222 .. attribute:: COUNTRY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002223
Paul Kehrere27f6582015-08-10 18:33:38 -05002224 Corresponds to the dotted string ``"2.5.4.6"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002225
Paul Kehrere27f6582015-08-10 18:33:38 -05002226 .. attribute:: LOCALITY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002227
Paul Kehrere27f6582015-08-10 18:33:38 -05002228 Corresponds to the dotted string ``"2.5.4.7"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002229
Paul Kehrere27f6582015-08-10 18:33:38 -05002230 .. attribute:: STATE_OR_PROVINCE_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002231
Paul Kehrere27f6582015-08-10 18:33:38 -05002232 Corresponds to the dotted string ``"2.5.4.8"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002233
Paul Kehrere27f6582015-08-10 18:33:38 -05002234 .. attribute:: ORGANIZATION_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002235
Paul Kehrere27f6582015-08-10 18:33:38 -05002236 Corresponds to the dotted string ``"2.5.4.10"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002237
Paul Kehrere27f6582015-08-10 18:33:38 -05002238 .. attribute:: ORGANIZATIONAL_UNIT_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002239
Paul Kehrere27f6582015-08-10 18:33:38 -05002240 Corresponds to the dotted string ``"2.5.4.11"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002241
Paul Kehrere27f6582015-08-10 18:33:38 -05002242 .. attribute:: SERIAL_NUMBER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002243
Paul Kehrere27f6582015-08-10 18:33:38 -05002244 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from
2245 the serial number of the certificate itself (which can be obtained with
Chelsea Winfreee295f3a2016-06-02 21:15:54 -07002246 :func:`~cryptography.x509.Certificate.serial_number`).
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002247
Paul Kehrere27f6582015-08-10 18:33:38 -05002248 .. attribute:: SURNAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002249
Paul Kehrere27f6582015-08-10 18:33:38 -05002250 Corresponds to the dotted string ``"2.5.4.4"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002251
Paul Kehrere27f6582015-08-10 18:33:38 -05002252 .. attribute:: GIVEN_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002253
Paul Kehrere27f6582015-08-10 18:33:38 -05002254 Corresponds to the dotted string ``"2.5.4.42"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002255
Paul Kehrere27f6582015-08-10 18:33:38 -05002256 .. attribute:: TITLE
Paul Kehrer858b9b72015-02-05 09:50:31 -06002257
Paul Kehrere27f6582015-08-10 18:33:38 -05002258 Corresponds to the dotted string ``"2.5.4.12"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002259
Paul Kehrere27f6582015-08-10 18:33:38 -05002260 .. attribute:: GENERATION_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002261
Paul Kehrere27f6582015-08-10 18:33:38 -05002262 Corresponds to the dotted string ``"2.5.4.44"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002263
Paul Kehrere27f6582015-08-10 18:33:38 -05002264 .. attribute:: DN_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002265
Paul Kehrere27f6582015-08-10 18:33:38 -05002266 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
2267 disambiguating information to add to the relative distinguished name of an
2268 entry. See :rfc:`2256`.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002269
Paul Kehrere27f6582015-08-10 18:33:38 -05002270 .. attribute:: PSEUDONYM
Paul Kehrer858b9b72015-02-05 09:50:31 -06002271
Paul Kehrere27f6582015-08-10 18:33:38 -05002272 Corresponds to the dotted string ``"2.5.4.65"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002273
Paul Kehrere27f6582015-08-10 18:33:38 -05002274 .. attribute:: DOMAIN_COMPONENT
Paul Kehrer858b9b72015-02-05 09:50:31 -06002275
Paul Kehrere27f6582015-08-10 18:33:38 -05002276 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
2277 holding one component of a domain name. See :rfc:`4519`.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002278
Paul Kehrere27f6582015-08-10 18:33:38 -05002279 .. attribute:: EMAIL_ADDRESS
Paul Kehrer56da2a52015-02-11 23:35:07 -06002280
Paul Kehrere27f6582015-08-10 18:33:38 -05002281 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002282
Alex Gaynor1d3f2bf2015-12-19 12:15:09 -05002283 .. attribute:: JURISDICTION_COUNTRY_NAME
2284
2285 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.3"``.
2286
Alex Gaynor45e507f2015-12-19 13:44:23 -05002287 .. attribute:: JURISDICTION_LOCALITY_NAME
2288
2289 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.1"``.
2290
2291 .. attribute:: JURISDICTION_STATE_OR_PROVINCE_NAME
2292
2293 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.2"``.
2294
Alex Gaynora2293c82015-12-19 20:49:15 -05002295 .. attribute:: BUSINESS_CATEGORY
2296
2297 Corresponds to the dotted string ``"2.5.4.15"``.
2298
Paul Kehrer56da2a52015-02-11 23:35:07 -06002299
Paul Kehrere27f6582015-08-10 18:33:38 -05002300.. class:: SignatureAlgorithmOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002301
Paul Kehrere27f6582015-08-10 18:33:38 -05002302 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002303
Paul Kehrere27f6582015-08-10 18:33:38 -05002304 .. attribute:: RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06002305
Paul Kehrere27f6582015-08-10 18:33:38 -05002306 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
2307 an MD5 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002308
Paul Kehrere27f6582015-08-10 18:33:38 -05002309 .. attribute:: RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002310
Paul Kehrere27f6582015-08-10 18:33:38 -05002311 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
2312 a SHA1 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002313
Paul Kehrere27f6582015-08-10 18:33:38 -05002314 .. attribute:: RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002315
Paul Kehrere27f6582015-08-10 18:33:38 -05002316 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
2317 a SHA224 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002318
Paul Kehrere27f6582015-08-10 18:33:38 -05002319 .. attribute:: RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002320
Paul Kehrere27f6582015-08-10 18:33:38 -05002321 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
2322 a SHA256 digest signed by an RSA key.
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002323
Paul Kehrere27f6582015-08-10 18:33:38 -05002324 .. attribute:: RSA_WITH_SHA384
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002325
Paul Kehrere27f6582015-08-10 18:33:38 -05002326 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
2327 a SHA384 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002328
Paul Kehrere27f6582015-08-10 18:33:38 -05002329 .. attribute:: RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06002330
Paul Kehrere27f6582015-08-10 18:33:38 -05002331 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
2332 a SHA512 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002333
Paul Kehrere27f6582015-08-10 18:33:38 -05002334 .. attribute:: ECDSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002335
Paul Kehrere27f6582015-08-10 18:33:38 -05002336 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
2337 digest signed by an ECDSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002338
Paul Kehrere27f6582015-08-10 18:33:38 -05002339 .. attribute:: ECDSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002340
Paul Kehrere27f6582015-08-10 18:33:38 -05002341 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
2342 a SHA224 digest signed by an ECDSA key.
2343
2344 .. attribute:: ECDSA_WITH_SHA256
2345
2346 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
2347 a SHA256 digest signed by an ECDSA key.
2348
2349 .. attribute:: ECDSA_WITH_SHA384
2350
2351 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
2352 a SHA384 digest signed by an ECDSA key.
2353
2354 .. attribute:: ECDSA_WITH_SHA512
2355
2356 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
2357 a SHA512 digest signed by an ECDSA key.
2358
2359 .. attribute:: DSA_WITH_SHA1
2360
2361 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
2362 a SHA1 digest signed by a DSA key.
2363
2364 .. attribute:: DSA_WITH_SHA224
2365
2366 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
2367 a SHA224 digest signed by a DSA key.
2368
2369 .. attribute:: DSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002370
Paul Kehrere27f6582015-08-10 18:33:38 -05002371 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
2372 a SHA256 digest signed by a DSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002373
Paul Kehrer56da2a52015-02-11 23:35:07 -06002374
Paul Kehrere27f6582015-08-10 18:33:38 -05002375.. class:: ExtendedKeyUsageOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002376
Paul Kehrere27f6582015-08-10 18:33:38 -05002377 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002378
Paul Kehrere27f6582015-08-10 18:33:38 -05002379 .. attribute:: SERVER_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002380
Paul Kehrere27f6582015-08-10 18:33:38 -05002381 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used
2382 to denote that a certificate may be used for TLS web server
2383 authentication.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002384
Paul Kehrere27f6582015-08-10 18:33:38 -05002385 .. attribute:: CLIENT_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002386
Paul Kehrere27f6582015-08-10 18:33:38 -05002387 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used
2388 to denote that a certificate may be used for TLS web client
2389 authentication.
Paul Kehrerffa2a152015-03-31 08:18:25 -05002390
Paul Kehrere27f6582015-08-10 18:33:38 -05002391 .. attribute:: CODE_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002392
Paul Kehrere27f6582015-08-10 18:33:38 -05002393 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used
2394 to denote that a certificate may be used for code signing.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002395
Paul Kehrere27f6582015-08-10 18:33:38 -05002396 .. attribute:: EMAIL_PROTECTION
Paul Kehrere1513fa2015-03-30 23:08:17 -05002397
Paul Kehrere27f6582015-08-10 18:33:38 -05002398 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used
2399 to denote that a certificate may be used for email protection.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002400
Paul Kehrere27f6582015-08-10 18:33:38 -05002401 .. attribute:: TIME_STAMPING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002402
Paul Kehrere27f6582015-08-10 18:33:38 -05002403 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used
2404 to denote that a certificate may be used for time stamping.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002405
Paul Kehrere27f6582015-08-10 18:33:38 -05002406 .. attribute:: OCSP_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002407
Paul Kehrere27f6582015-08-10 18:33:38 -05002408 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used
2409 to denote that a certificate may be used for signing OCSP responses.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002410
Paul Kehrere1513fa2015-03-30 23:08:17 -05002411
Paul Kehrere27f6582015-08-10 18:33:38 -05002412.. class:: AuthorityInformationAccessOID
Paul Kehrere1513fa2015-03-30 23:08:17 -05002413
Paul Kehrere27f6582015-08-10 18:33:38 -05002414 .. versionadded:: 1.0
Paul Kehrere1513fa2015-03-30 23:08:17 -05002415
Paul Kehrere27f6582015-08-10 18:33:38 -05002416 .. attribute:: OCSP
Paul Kehrere1513fa2015-03-30 23:08:17 -05002417
Paul Kehrere27f6582015-08-10 18:33:38 -05002418 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
2419 identifier for OCSP data in
2420 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002421
Paul Kehrere27f6582015-08-10 18:33:38 -05002422 .. attribute:: CA_ISSUERS
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002423
Paul Kehrere27f6582015-08-10 18:33:38 -05002424 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
2425 identifier for CA issuer data in
2426 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002427
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002428
Paul Kehrere27f6582015-08-10 18:33:38 -05002429.. class:: CertificatePoliciesOID
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002430
Paul Kehrere27f6582015-08-10 18:33:38 -05002431 .. versionadded:: 1.0
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002432
Paul Kehrere27f6582015-08-10 18:33:38 -05002433 .. attribute:: CPS_QUALIFIER
Paul Kehrer2e879742015-05-02 23:09:56 -05002434
Paul Kehrere27f6582015-08-10 18:33:38 -05002435 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002436
Paul Kehrere27f6582015-08-10 18:33:38 -05002437 .. attribute:: CPS_USER_NOTICE
Paul Kehrer2e879742015-05-02 23:09:56 -05002438
Paul Kehrere27f6582015-08-10 18:33:38 -05002439 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002440
Paul Kehrere27f6582015-08-10 18:33:38 -05002441 .. attribute:: ANY_POLICY
Paul Kehrer2e879742015-05-02 23:09:56 -05002442
Paul Kehrere27f6582015-08-10 18:33:38 -05002443 Corresponds to the dotted string ``"2.5.29.32.0"``.
Paul Kehrer16fae762015-05-01 23:14:20 -05002444
Paul Kehrer16fae762015-05-01 23:14:20 -05002445
Paul Kehrere27f6582015-08-10 18:33:38 -05002446.. class:: ExtensionOID
Paul Kehrer5553d572015-03-23 21:08:01 -05002447
Paul Kehrere27f6582015-08-10 18:33:38 -05002448 .. versionadded:: 1.0
Paul Kehrer2bb94642015-03-21 09:54:17 -05002449
Paul Kehrere27f6582015-08-10 18:33:38 -05002450 .. attribute:: BASIC_CONSTRAINTS
Paul Kehrer2bb94642015-03-21 09:54:17 -05002451
Paul Kehrere27f6582015-08-10 18:33:38 -05002452 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
2453 :class:`~cryptography.x509.BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05002454
Paul Kehrere27f6582015-08-10 18:33:38 -05002455 .. attribute:: KEY_USAGE
Paul Kehrercecbbba2015-03-30 14:58:38 -05002456
Paul Kehrere27f6582015-08-10 18:33:38 -05002457 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
2458 :class:`~cryptography.x509.KeyUsage` extension type.
Paul Kehrercecbbba2015-03-30 14:58:38 -05002459
Paul Kehrere27f6582015-08-10 18:33:38 -05002460 .. attribute:: SUBJECT_ALTERNATIVE_NAME
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002461
Paul Kehrere27f6582015-08-10 18:33:38 -05002462 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
2463 :class:`~cryptography.x509.SubjectAlternativeName` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002464
Paul Kehrere27f6582015-08-10 18:33:38 -05002465 .. attribute:: ISSUER_ALTERNATIVE_NAME
Paul Kehrer99125c92015-06-07 18:37:10 -05002466
Paul Kehrere27f6582015-08-10 18:33:38 -05002467 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
2468 :class:`~cryptography.x509.IssuerAlternativeName` extension type.
Paul Kehrer99125c92015-06-07 18:37:10 -05002469
Paul Kehrere27f6582015-08-10 18:33:38 -05002470 .. attribute:: SUBJECT_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002471
Paul Kehrere27f6582015-08-10 18:33:38 -05002472 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
2473 :class:`~cryptography.x509.SubjectKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002474
Paul Kehrere27f6582015-08-10 18:33:38 -05002475 .. attribute:: NAME_CONSTRAINTS
Paul Kehrere0017be2015-05-17 20:39:40 -06002476
Paul Kehrere27f6582015-08-10 18:33:38 -05002477 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
2478 :class:`~cryptography.x509.NameConstraints` extension type.
Paul Kehrere0017be2015-05-17 20:39:40 -06002479
Paul Kehrere27f6582015-08-10 18:33:38 -05002480 .. attribute:: CRL_DISTRIBUTION_POINTS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002481
Paul Kehrere27f6582015-08-10 18:33:38 -05002482 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
2483 :class:`~cryptography.x509.CRLDistributionPoints` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002484
Paul Kehrere27f6582015-08-10 18:33:38 -05002485 .. attribute:: CERTIFICATE_POLICIES
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002486
Paul Kehrere27f6582015-08-10 18:33:38 -05002487 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
2488 :class:`~cryptography.x509.CertificatePolicies` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002489
Paul Kehrere27f6582015-08-10 18:33:38 -05002490 .. attribute:: AUTHORITY_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002491
Paul Kehrere27f6582015-08-10 18:33:38 -05002492 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
2493 :class:`~cryptography.x509.AuthorityKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002494
Paul Kehrere27f6582015-08-10 18:33:38 -05002495 .. attribute:: EXTENDED_KEY_USAGE
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002496
Paul Kehrere27f6582015-08-10 18:33:38 -05002497 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
2498 :class:`~cryptography.x509.ExtendedKeyUsage` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002499
Paul Kehrere27f6582015-08-10 18:33:38 -05002500 .. attribute:: AUTHORITY_INFORMATION_ACCESS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002501
Paul Kehrere27f6582015-08-10 18:33:38 -05002502 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
2503 for the :class:`~cryptography.x509.AuthorityInformationAccess` extension
2504 type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002505
Paul Kehrere27f6582015-08-10 18:33:38 -05002506 .. attribute:: INHIBIT_ANY_POLICY
Paul Kehrerb33de932015-08-06 23:41:05 +01002507
Paul Kehrere27f6582015-08-10 18:33:38 -05002508 Corresponds to the dotted string ``"2.5.29.54"``. The identifier
2509 for the :class:`~cryptography.x509.InhibitAnyPolicy` extension type.
Paul Kehrerb33de932015-08-06 23:41:05 +01002510
Paul Kehrere27f6582015-08-10 18:33:38 -05002511 .. attribute:: OCSP_NO_CHECK
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002512
Paul Kehrere27f6582015-08-10 18:33:38 -05002513 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The
2514 identifier for the :class:`~cryptography.x509.OCSPNoCheck` extension
2515 type.
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002516
Paul Kehrer51f39cb2015-12-21 21:17:39 -06002517 .. attribute:: CRL_NUMBER
2518
2519 Corresponds to the dotted string ``"2.5.29.20"``. The identifier for
2520 the ``CRLNumber`` extension type. This extension only has meaning
2521 for certificate revocation lists.
2522
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002523 .. attribute:: POLICY_CONSTRAINTS
2524
2525 Corresponds to the dotted string ``"2.5.29.36"``. The identifier for the
Paul Kehrer20f0df52016-02-26 08:37:13 -06002526 :class:`~cryptography.x509.PolicyConstraints` extension type.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002527
2528
Paul Kehrerc6242dc2015-12-25 16:36:46 -06002529.. class:: CRLEntryExtensionOID
2530
2531 .. versionadded:: 1.2
2532
2533 .. attribute:: CERTIFICATE_ISSUER
2534
2535 Corresponds to the dotted string ``"2.5.29.29"``.
2536
2537 .. attribute:: CRL_REASON
2538
2539 Corresponds to the dotted string ``"2.5.29.21"``.
2540
2541 .. attribute:: INVALIDITY_DATE
2542
2543 Corresponds to the dotted string ``"2.5.29.24"``.
2544
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002545Exceptions
2546~~~~~~~~~~
Paul Kehrere27f6582015-08-10 18:33:38 -05002547.. currentmodule:: cryptography.x509
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002548
Paul Kehrere76cd272014-12-14 19:00:51 -06002549.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10002550
2551 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10002552
Paul Kehrerd5cccf72014-12-15 17:20:33 -06002553 .. attribute:: parsed_version
2554
Paul Kehrerbbffc402014-12-17 13:33:55 -06002555 :type: int
2556
2557 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06002558
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05002559.. class:: DuplicateExtension
2560
2561 This is raised when more than one X.509 extension of the same type is
2562 found within a certificate.
2563
2564 .. attribute:: oid
2565
2566 :type: :class:`ObjectIdentifier`
2567
2568 Returns the OID.
2569
2570.. class:: UnsupportedExtension
2571
Paul Kehrer58ddc112015-12-30 20:19:00 -06002572 This is raised when a certificate contains an unsupported extension type
Paul Kehrerf5bc3eb2015-12-30 20:54:15 -06002573 that is marked ``critical``.
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05002574
2575 .. attribute:: oid
2576
2577 :type: :class:`ObjectIdentifier`
2578
2579 Returns the OID.
2580
Paul Kehrerfa56a232015-03-17 13:14:03 -05002581.. class:: ExtensionNotFound
2582
2583 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
2584 an extension OID that is not present in the certificate.
2585
2586 .. attribute:: oid
2587
2588 :type: :class:`ObjectIdentifier`
2589
2590 Returns the OID.
2591
Paul Kehrer9089c912015-04-20 22:15:20 -05002592.. class:: UnsupportedGeneralNameType
2593
2594 This is raised when a certificate contains an unsupported general name
2595 type in an extension.
2596
Paul Kehrerbed07352015-04-21 08:31:10 -05002597 .. attribute:: type
2598
Paul Kehrer0a621bf2015-04-22 09:22:56 -05002599 :type: int
2600
2601 The integer value of the unsupported type. The complete list of
2602 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05002603
Paul Kehrer016e08a2014-11-26 09:41:18 -10002604
Paul Kehrerc7c9a432015-04-19 09:20:13 -05002605.. _`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 -05002606.. _`RFC 5280 section 4.2.1.6`: https://tools.ietf.org/html/rfc5280#section-4.2.1.6