blob: 079fef920418c67a314b45727fbc01ccd5ec08c0 [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 Kehrer056c9dd2018-05-12 15:17:06 -0400274 b'\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 Kehrerbed07352015-04-21 08:31:10 -0500382 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
383 contains a general name that is not supported.
384
Paul Kehrerb8968812015-05-15 09:01:34 -0700385 :raises UnicodeError: If an extension contains IDNA encoding that is
386 invalid or not compliant with IDNA 2008.
387
Paul Kehrerfa56a232015-03-17 13:14:03 -0500388 .. doctest::
389
390 >>> for ext in cert.extensions:
391 ... print(ext)
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400392 <Extension(oid=<ObjectIdentifier(oid=2.5.29.35, name=authorityKeyIdentifier)>, critical=False, value=<AuthorityKeyIdentifier(key_identifier=b'\xe4}_\xd1\\\x95\x86\x08,\x05\xae\xbeu\xb6e\xa7\xd9]\xa8f', authority_cert_issuer=None, authority_cert_serial_number=None)>)>
393 <Extension(oid=<ObjectIdentifier(oid=2.5.29.14, name=subjectKeyIdentifier)>, critical=False, value=<SubjectKeyIdentifier(digest=b'X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9')>)>
Paul Kehrerb511ba82015-04-15 11:22:48 -0400394 <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 -0500395 <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 -0500396 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
397
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500398 .. attribute:: signature
399
400 .. versionadded:: 1.2
401
402 :type: bytes
403
404 The bytes of the certificate's signature.
405
Paul Kehrerd2898052015-11-03 22:00:41 +0900406 .. attribute:: tbs_certificate_bytes
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500407
408 .. versionadded:: 1.2
409
410 :type: bytes
411
412 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
413 and then signed by the private key of the certificate's issuer. This
414 data may be used to validate a signature, but use extreme caution as
415 certificate validation is a complex problem that involves much more
416 than just signature checks.
417
Andre Carona8aded62015-05-19 20:11:57 -0400418 .. method:: public_bytes(encoding)
419
Alex Gaynord0b376b2015-07-05 13:58:12 -0400420 .. versionadded:: 1.0
421
Andre Carona8aded62015-05-19 20:11:57 -0400422 :param encoding: The
423 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
424 that will be used to serialize the certificate.
425
426 :return bytes: The data that can be written to a file or sent
427 over the network to be verified by clients.
428
Erik Trauschke2dcce902015-05-14 16:12:24 -0700429X.509 CRL (Certificate Revocation List) Object
430~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
431
432.. class:: CertificateRevocationList
433
434 .. versionadded:: 1.0
435
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700436 A CertificateRevocationList is an object representing a list of revoked
437 certificates. The object is iterable and will yield the RevokedCertificate
438 objects stored in this CRL.
439
440 .. doctest::
Erik Trauschkeb14f7d12015-10-13 09:55:39 -0700441
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700442 >>> len(crl)
443 1
Paul Kehrerdcdf9672015-10-21 20:27:28 -0500444 >>> revoked_certificate = crl[0]
445 >>> type(revoked_certificate)
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700446 <class 'cryptography.hazmat.backends.openssl.x509._RevokedCertificate'>
447 >>> for r in crl:
448 ... print(r.serial_number)
449 0
450
Erik Trauschke2dcce902015-05-14 16:12:24 -0700451 .. method:: fingerprint(algorithm)
452
453 :param algorithm: The
454 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
455 that will be used to generate the fingerprint.
456
457 :return bytes: The fingerprint using the supplied hash algorithm, as
458 bytes.
459
Erik Trauschkedc570402015-09-24 20:24:28 -0700460 .. doctest::
461
462 >>> from cryptography.hazmat.primitives import hashes
463 >>> crl.fingerprint(hashes.SHA256())
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400464 b'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'
Erik Trauschkedc570402015-09-24 20:24:28 -0700465
Paul Kehrer5d187402018-07-16 20:49:51 +0530466 .. method:: get_revoked_certificate_by_serial_number(serial_number)
467
468 .. versionadded:: 2.3
469
470 :param serial_number: The serial as a Python integer.
471 :returns: :class:`~cryptography.x509.RevokedCertificate` if the
472 ``serial_number`` is present in the CRL or ``None`` if it
473 is not.
474
Erik Trauschke2dcce902015-05-14 16:12:24 -0700475 .. attribute:: signature_hash_algorithm
476
477 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
478
479 Returns the
480 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
481 was used in signing this CRL.
482
Erik Trauschkedc570402015-09-24 20:24:28 -0700483 .. doctest::
484
485 >>> from cryptography.hazmat.primitives import hashes
486 >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
487 True
488
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800489 .. attribute:: signature_algorithm_oid
490
491 .. versionadded:: 1.6
492
493 :type: :class:`ObjectIdentifier`
494
495 Returns the :class:`ObjectIdentifier` of the signature algorithm used
496 to sign the CRL. This will be one of the OIDs from
497 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
498
499 .. doctest::
500
501 >>> crl.signature_algorithm_oid
502 <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
503
Erik Trauschke2dcce902015-05-14 16:12:24 -0700504 .. attribute:: issuer
505
506 :type: :class:`Name`
507
508 The :class:`Name` of the issuer.
509
Erik Trauschkedc570402015-09-24 20:24:28 -0700510 .. doctest::
511
512 >>> crl.issuer
Paul Kehrer056c9dd2018-05-12 15:17:06 -0400513 <Name([<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>, <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='cryptography.io')>])>
Erik Trauschkedc570402015-09-24 20:24:28 -0700514
Erik Trauschke2dcce902015-05-14 16:12:24 -0700515 .. attribute:: next_update
516
517 :type: :class:`datetime.datetime`
518
519 A naïve datetime representing when the next update to this CRL is
520 expected.
521
Erik Trauschkedc570402015-09-24 20:24:28 -0700522 .. doctest::
523
524 >>> crl.next_update
525 datetime.datetime(2016, 1, 1, 0, 0)
526
Erik Trauschke2dcce902015-05-14 16:12:24 -0700527 .. attribute:: last_update
528
529 :type: :class:`datetime.datetime`
530
531 A naïve datetime representing when the this CRL was last updated.
532
Erik Trauschkedc570402015-09-24 20:24:28 -0700533 .. doctest::
Erik Trauschke2dcce902015-05-14 16:12:24 -0700534
Erik Trauschkedc570402015-09-24 20:24:28 -0700535 >>> crl.last_update
536 datetime.datetime(2015, 1, 1, 0, 0)
Erik Trauschke2dcce902015-05-14 16:12:24 -0700537
538 .. attribute:: extensions
539
540 :type: :class:`Extensions`
541
542 The extensions encoded in the CRL.
543
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800544 .. attribute:: signature
545
546 .. versionadded:: 1.2
547
548 :type: bytes
549
550 The bytes of the CRL's signature.
551
552 .. attribute:: tbs_certlist_bytes
553
554 .. versionadded:: 1.2
555
556 :type: bytes
557
558 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
559 and then signed by the private key of the CRL's issuer. This data may be
560 used to validate a signature, but use extreme caution as CRL validation
561 is a complex problem that involves much more than just signature checks.
562
Paul Kehrer54a837d2015-12-20 23:42:32 -0600563 .. method:: public_bytes(encoding)
564
565 .. versionadded:: 1.2
566
567 :param encoding: The
568 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
569 that will be used to serialize the certificate revocation list.
570
571 :return bytes: The data that can be written to a file or sent
572 over the network and used as part of a certificate verification
573 process.
574
Vincent Pelletier6c02ee82017-08-12 22:05:00 +0900575 .. method:: is_signature_valid(public_key)
576
577 .. versionadded:: 2.1
578
Paul Kehrerf944c402017-08-12 08:52:55 -0500579 .. warning::
580
581 Checking the validity of the signature on the CRL is insufficient
582 to know if the CRL should be trusted. More details are available
583 in :rfc:`5280`.
584
Vincent Pelletier6c02ee82017-08-12 22:05:00 +0900585 Returns True if the CRL signature is correct for given public key,
586 False otherwise.
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800587
Andre Caron9bbfcea2015-05-18 20:55:29 -0400588X.509 Certificate Builder
589~~~~~~~~~~~~~~~~~~~~~~~~~
590
591.. class:: CertificateBuilder
592
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500593 .. versionadded:: 1.0
594
595 .. doctest::
596
597 >>> from cryptography import x509
598 >>> from cryptography.hazmat.backends import default_backend
599 >>> from cryptography.hazmat.primitives import hashes
600 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -0500601 >>> from cryptography.x509.oid import NameOID
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500602 >>> import datetime
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500603 >>> one_day = datetime.timedelta(1, 0, 0)
604 >>> private_key = rsa.generate_private_key(
605 ... public_exponent=65537,
606 ... key_size=2048,
607 ... backend=default_backend()
608 ... )
Cory Benfieldc47b2522015-12-07 15:25:12 +0000609 >>> public_key = private_key.public_key()
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500610 >>> builder = x509.CertificateBuilder()
611 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500612 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500613 ... ]))
614 >>> builder = builder.issuer_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500615 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500616 ... ]))
617 >>> builder = builder.not_valid_before(datetime.datetime.today() - one_day)
Alex Gaynorcdd35852018-08-05 18:17:35 -0400618 >>> builder = builder.not_valid_after(datetime.datetime.today() + (one_day * 30))
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500619 >>> builder = builder.serial_number(x509.random_serial_number())
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500620 >>> builder = builder.public_key(public_key)
621 >>> builder = builder.add_extension(
Paul Kehrer1bab7bc2017-01-18 13:44:40 +0800622 ... x509.SubjectAlternativeName(
Paul Kehrered321052017-10-11 08:11:44 +0800623 ... [x509.DNSName(u'cryptography.io')]
Paul Kehrer1bab7bc2017-01-18 13:44:40 +0800624 ... ),
625 ... critical=False
626 ... )
627 >>> builder = builder.add_extension(
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500628 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
629 ... )
630 >>> certificate = builder.sign(
631 ... private_key=private_key, algorithm=hashes.SHA256(),
632 ... backend=default_backend()
633 ... )
634 >>> isinstance(certificate, x509.Certificate)
635 True
636
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500637 .. method:: issuer_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400638
639 Sets the issuer's distinguished name.
640
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500641 :param name: The :class:`~cryptography.x509.Name` that describes the
642 issuer (CA).
Andre Caron9bbfcea2015-05-18 20:55:29 -0400643
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500644 .. method:: subject_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400645
646 Sets the subject's distinguished name.
647
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500648 :param name: The :class:`~cryptography.x509.Name` that describes the
Ian Cordasco85fc4d52015-08-01 20:29:31 -0500649 subject.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400650
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500651 .. method:: public_key(public_key)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400652
653 Sets the subject's public key.
654
Ian Cordasco8f571422015-08-02 11:31:08 -0500655 :param public_key: The subject's public key. This can be one of
656 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`,
657 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
658 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400659
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500660 .. method:: serial_number(serial_number)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400661
662 Sets the certificate's serial number (an integer). The CA's policy
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500663 determines how it attributes serial numbers to certificates. This
664 number must uniquely identify the certificate given the issuer.
665 `CABForum Guidelines`_ require entropy in the serial number
666 to provide protection against hash collision attacks. For more
667 information on secure random number generation, see
668 :doc:`/random-numbers`.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400669
670 :param serial_number: Integer number that will be used by the CA to
671 identify this certificate (most notably during certificate
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500672 revocation checking). Users should consider using
673 :func:`~cryptography.x509.random_serial_number` when possible.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400674
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500675 .. method:: not_valid_before(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400676
677 Sets the certificate's activation time. This is the time from which
678 clients can start trusting the certificate. It may be different from
679 the time at which the certificate was created.
680
Ian Cordasco17c89002015-08-02 21:13:59 -0500681 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400682 activation time for the certificate. The certificate may not be
683 trusted clients if it is used before this time.
684
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500685 .. method:: not_valid_after(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400686
687 Sets the certificate's expiration time. This is the time from which
688 clients should no longer trust the certificate. The CA's policy will
689 determine how long the certificate should remain in use.
690
Ian Cordasco17c89002015-08-02 21:13:59 -0500691 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400692 expiration time for the certificate. The certificate may not be
693 trusted clients if it is used after this time.
694
Ian Cordasco17c89002015-08-02 21:13:59 -0500695 .. method:: add_extension(extension, critical)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400696
697 Adds an X.509 extension to the certificate.
698
Paul Kehrer2c145cc2015-10-02 11:27:21 -0500699 :param extension: An extension conforming to the
700 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400701
Ian Cordasco17c89002015-08-02 21:13:59 -0500702 :param critical: Set to ``True`` if the extension must be understood and
703 handled by whoever reads the certificate.
704
Paul Kehrer9add80e2015-08-03 17:53:14 +0100705 .. method:: sign(private_key, algorithm, backend)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400706
707 Sign the certificate using the CA's private key.
708
Ian Cordascoc5e1c252015-07-31 23:33:35 -0500709 :param private_key: The
710 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
711 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
712 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
713 that will be used to sign the certificate.
714
Andre Caron9bbfcea2015-05-18 20:55:29 -0400715 :param algorithm: The
716 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
717 will be used to generate the signature.
718
Paul Kehrer9add80e2015-08-03 17:53:14 +0100719 :param backend: Backend that will be used to build the certificate.
720 Must support the
721 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
722 interface.
723
Benjamin Peterson9ed312b2015-10-12 20:51:34 -0700724 :returns: :class:`~cryptography.x509.Certificate`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400725
726
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500727X.509 CSR (Certificate Signing Request) Object
728~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600729
Paul Kehrera1a1f232015-03-15 15:34:35 -0500730.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600731
732 .. versionadded:: 0.9
733
734 .. method:: public_key()
735
Alex Gaynor4c2561a2015-10-12 23:53:39 -0400736 The public key associated with the request.
737
738 :returns:
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600739 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
740 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
741 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
742
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600743 .. doctest::
744
745 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500746 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600747 >>> isinstance(public_key, rsa.RSAPublicKey)
748 True
749
750 .. attribute:: subject
751
752 :type: :class:`Name`
753
754 The :class:`Name` of the subject.
755
756 .. attribute:: signature_hash_algorithm
757
758 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
759
760 Returns the
761 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
762 was used in signing this request.
763
764 .. doctest::
765
766 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500767 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600768 True
769
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800770 .. attribute:: signature_algorithm_oid
771
772 .. versionadded:: 1.6
773
774 :type: :class:`ObjectIdentifier`
775
776 Returns the :class:`ObjectIdentifier` of the signature algorithm used
777 to sign the request. This will be one of the OIDs from
778 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
779
780 .. doctest::
781
782 >>> csr.signature_algorithm_oid
783 <ObjectIdentifier(oid=1.2.840.113549.1.1.5, name=sha1WithRSAEncryption)>
784
Paul Kehrerc4e61942015-08-01 21:21:13 +0100785 .. attribute:: extensions
786
787 :type: :class:`Extensions`
788
789 The extensions encoded in the certificate signing request.
790
791 :raises cryptography.x509.DuplicateExtension: If more than one
Paul Kehrer24283d22015-08-01 21:31:19 +0100792 extension of the same type is found within the certificate signing request.
Paul Kehrerc4e61942015-08-01 21:21:13 +0100793
Paul Kehrerc4e61942015-08-01 21:21:13 +0100794 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
795 contains a general name that is not supported.
796
797 :raises UnicodeError: If an extension contains IDNA encoding that is
798 invalid or not compliant with IDNA 2008.
799
800
Andre Caron476c5df2015-05-18 10:23:28 -0400801 .. method:: public_bytes(encoding)
802
Alex Gaynord0b376b2015-07-05 13:58:12 -0400803 .. versionadded:: 1.0
804
Andre Caron476c5df2015-05-18 10:23:28 -0400805 :param encoding: The
806 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
807 that will be used to serialize the certificate request.
808
809 :return bytes: The data that can be written to a file or sent
810 over the network to be signed by the certificate
811 authority.
812
Paul Kehrerab209392015-12-01 14:50:31 -0600813 .. attribute:: signature
814
815 .. versionadded:: 1.2
816
817 :type: bytes
818
819 The bytes of the certificate signing request's signature.
820
821 .. attribute:: tbs_certrequest_bytes
822
823 .. versionadded:: 1.2
824
825 :type: bytes
826
827 The DER encoded bytes payload (as defined by :rfc:`2986`) that is
828 hashed and then signed by the private key (corresponding to the public
829 key embedded in the CSR). This data may be used to validate the CSR
830 signature.
831
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100832 .. attribute:: is_signature_valid
Joern Heissler1bd77e22016-01-13 22:51:37 +0100833
834 .. versionadded:: 1.3
835
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100836 Returns True if the CSR signature is correct, False otherwise.
Joern Heissler1bd77e22016-01-13 22:51:37 +0100837
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600838X.509 Certificate Revocation List Builder
839~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
840
841.. class:: CertificateRevocationListBuilder
842
843 .. versionadded:: 1.2
844
845 .. doctest::
846
847 >>> from cryptography import x509
848 >>> from cryptography.hazmat.backends import default_backend
849 >>> from cryptography.hazmat.primitives import hashes
850 >>> from cryptography.hazmat.primitives.asymmetric import rsa
851 >>> from cryptography.x509.oid import NameOID
852 >>> import datetime
853 >>> one_day = datetime.timedelta(1, 0, 0)
854 >>> private_key = rsa.generate_private_key(
855 ... public_exponent=65537,
856 ... key_size=2048,
857 ... backend=default_backend()
858 ... )
859 >>> builder = x509.CertificateRevocationListBuilder()
860 >>> builder = builder.issuer_name(x509.Name([
861 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io CA'),
862 ... ]))
863 >>> builder = builder.last_update(datetime.datetime.today())
864 >>> builder = builder.next_update(datetime.datetime.today() + one_day)
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600865 >>> revoked_cert = x509.RevokedCertificateBuilder().serial_number(
866 ... 333
867 ... ).revocation_date(
868 ... datetime.datetime.today()
869 ... ).build(default_backend())
870 >>> builder = builder.add_revoked_certificate(revoked_cert)
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600871 >>> crl = builder.sign(
872 ... private_key=private_key, algorithm=hashes.SHA256(),
873 ... backend=default_backend()
874 ... )
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600875 >>> len(crl)
876 1
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600877
878 .. method:: issuer_name(name)
879
880 Sets the issuer's distinguished name.
881
882 :param name: The :class:`~cryptography.x509.Name` that describes the
883 issuer (CA).
884
885 .. method:: last_update(time)
886
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600887 Sets this CRL's activation time. This is the time from which
888 clients can start trusting this CRL. It may be different from
889 the time at which this CRL was created. This is also known as the
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600890 ``thisUpdate`` time.
891
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600892 :param time: The :class:`datetime.datetime` object (in UTC) that marks
893 the activation time for this CRL. The CRL may not be trusted if it
894 is used before this time.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600895
896 .. method:: next_update(time)
897
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600898 Sets this CRL's next update time. This is the time by which
899 a new CRL will be issued. The CA is allowed to issue a new CRL before
900 this date, however clients are not required to check for it.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600901
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600902 :param time: The :class:`datetime.datetime` object (in UTC) that marks
903 the next update time for this CRL.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600904
Paul Kehrer426b48d2015-12-24 20:50:43 -0600905 .. method:: add_extension(extension, critical)
906
907 Adds an X.509 extension to this CRL.
908
909 :param extension: An extension with the
910 :class:`~cryptography.x509.ExtensionType` interface.
911
912 :param critical: Set to ``True`` if the extension must be understood and
913 handled by whoever reads the CRL.
914
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600915 .. method:: add_revoked_certificate(revoked_certificate)
916
917 Adds a revoked certificate to this CRL.
918
919 :param revoked_certificate: An instance of
920 :class:`~cryptography.x509.RevokedCertificate`. These can be
921 obtained from an existing CRL or created with
922 :class:`~cryptography.x509.RevokedCertificateBuilder`.
923
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600924 .. method:: sign(private_key, algorithm, backend)
925
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600926 Sign this CRL using the CA's private key.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600927
928 :param private_key: The
929 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
930 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
931 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
932 that will be used to sign the certificate.
933
934 :param algorithm: The
935 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
936 will be used to generate the signature.
937
938 :param backend: Backend that will be used to build the CRL.
939 Must support the
940 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
941 interface.
942
943 :returns: :class:`~cryptography.x509.CertificateRevocationList`
944
Erik Trauschke2dcce902015-05-14 16:12:24 -0700945X.509 Revoked Certificate Object
Erik Trauschkec5a8d172015-05-28 10:24:25 -0700946~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Erik Trauschke2dcce902015-05-14 16:12:24 -0700947
948.. class:: RevokedCertificate
949
950 .. versionadded:: 1.0
951
952 .. attribute:: serial_number
953
954 :type: :class:`int`
955
956 An integer representing the serial number of the revoked certificate.
957
Erik Trauschkedc570402015-09-24 20:24:28 -0700958 .. doctest::
959
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700960 >>> revoked_certificate.serial_number
Erik Trauschkedc570402015-09-24 20:24:28 -0700961 0
962
Erik Trauschke2dcce902015-05-14 16:12:24 -0700963 .. attribute:: revocation_date
964
965 :type: :class:`datetime.datetime`
966
967 A naïve datetime representing the date this certificates was revoked.
968
Erik Trauschkedc570402015-09-24 20:24:28 -0700969 .. doctest::
970
Erik Trauschke77f5a252015-10-14 08:06:38 -0700971 >>> revoked_certificate.revocation_date
Erik Trauschkedc570402015-09-24 20:24:28 -0700972 datetime.datetime(2015, 1, 1, 0, 0)
973
Erik Trauschke2dcce902015-05-14 16:12:24 -0700974 .. attribute:: extensions
975
976 :type: :class:`Extensions`
977
978 The extensions encoded in the revoked certificate.
Andre Caron476c5df2015-05-18 10:23:28 -0400979
Erik Trauschkedc570402015-09-24 20:24:28 -0700980 .. doctest::
981
Erik Trauschke77f5a252015-10-14 08:06:38 -0700982 >>> for ext in revoked_certificate.extensions:
Erik Trauschkedc570402015-09-24 20:24:28 -0700983 ... print(ext)
Paul Kehrer23c0bbc2015-12-25 22:35:19 -0600984 <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 -0600985 <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 -0700986
Paul Kehrerc33ffd72015-12-25 10:59:22 -0600987X.509 Revoked Certificate Builder
988~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
989
990.. class:: RevokedCertificateBuilder
991
992 This class is used to create :class:`~cryptography.x509.RevokedCertificate`
993 objects that can be used with the
994 :class:`~cryptography.x509.CertificateRevocationListBuilder`.
995
996 .. versionadded:: 1.2
997
998 .. doctest::
999
1000 >>> from cryptography import x509
1001 >>> from cryptography.hazmat.backends import default_backend
1002 >>> import datetime
1003 >>> builder = x509.RevokedCertificateBuilder()
1004 >>> builder = builder.revocation_date(datetime.datetime.today())
1005 >>> builder = builder.serial_number(3333)
1006 >>> revoked_certificate = builder.build(default_backend())
1007 >>> isinstance(revoked_certificate, x509.RevokedCertificate)
1008 True
1009
1010 .. method:: serial_number(serial_number)
1011
1012 Sets the revoked certificate's serial number.
1013
1014 :param serial_number: Integer number that is used to identify the
1015 revoked certificate.
1016
1017 .. method:: revocation_date(time)
1018
1019 Sets the certificate's revocation date.
1020
1021 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
1022 revocation time for the certificate.
1023
Paul Kehrere5f152b2015-12-25 23:55:47 -06001024 .. method:: add_extension(extension, critical)
1025
1026 Adds an X.509 extension to this revoked certificate.
1027
1028 :param extension: An instance of one of the
1029 :ref:`CRL entry extensions <crl_entry_extensions>`.
1030
1031 :param critical: Set to ``True`` if the extension must be understood and
1032 handled.
1033
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001034 .. method:: build(backend)
1035
1036 Create a revoked certificate object using the provided backend.
1037
1038 :param backend: Backend that will be used to build the revoked
1039 certificate. Must support the
1040 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1041 interface.
1042
1043 :returns: :class:`~cryptography.x509.RevokedCertificate`
1044
Andre Caron0ef595f2015-05-18 13:53:43 -04001045X.509 CSR (Certificate Signing Request) Builder Object
1046~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1047
1048.. class:: CertificateSigningRequestBuilder
1049
Andre Carond259ee52015-06-02 23:47:11 -04001050 .. versionadded:: 1.0
1051
1052 .. doctest::
1053
1054 >>> from cryptography import x509
1055 >>> from cryptography.hazmat.backends import default_backend
1056 >>> from cryptography.hazmat.primitives import hashes
1057 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -05001058 >>> from cryptography.x509.oid import NameOID
Andre Carond259ee52015-06-02 23:47:11 -04001059 >>> private_key = rsa.generate_private_key(
1060 ... public_exponent=65537,
1061 ... key_size=2048,
1062 ... backend=default_backend()
1063 ... )
1064 >>> builder = x509.CertificateSigningRequestBuilder()
Andre Carona9a51172015-06-06 20:18:44 -04001065 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -05001066 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Andre Carond259ee52015-06-02 23:47:11 -04001067 ... ]))
Ian Cordascof06b6be2015-06-21 10:09:18 -05001068 >>> builder = builder.add_extension(
Ian Cordasco0112b022015-06-16 17:51:18 -05001069 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
Andre Caron472fd692015-06-06 20:04:44 -04001070 ... )
Andre Carond259ee52015-06-02 23:47:11 -04001071 >>> request = builder.sign(
Alex Gaynorde9e5842015-06-26 20:11:23 -04001072 ... private_key, hashes.SHA256(), default_backend()
Andre Carond259ee52015-06-02 23:47:11 -04001073 ... )
1074 >>> isinstance(request, x509.CertificateSigningRequest)
1075 True
1076
Andre Carona9a51172015-06-06 20:18:44 -04001077 .. method:: subject_name(name)
Andre Caron0ef595f2015-05-18 13:53:43 -04001078
Andre Caron341ff852015-06-06 20:14:31 -04001079 :param name: The :class:`~cryptography.x509.Name` of the certificate
1080 subject.
1081 :returns: A new
1082 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001083
Ian Cordascof06b6be2015-06-21 10:09:18 -05001084 .. method:: add_extension(extension, critical)
Andre Caron0ef595f2015-05-18 13:53:43 -04001085
Paul Kehrer2c145cc2015-10-02 11:27:21 -05001086 :param extension: An extension conforming to the
1087 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron472fd692015-06-06 20:04:44 -04001088 :param critical: Set to `True` if the extension must be understood and
1089 handled by whoever reads the certificate.
Andre Caron341ff852015-06-06 20:14:31 -04001090 :returns: A new
1091 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001092
Alex Gaynorb3b0fbe2015-06-26 19:57:18 -04001093 .. method:: sign(private_key, algorithm, backend)
Andre Caron0ef595f2015-05-18 13:53:43 -04001094
1095 :param backend: Backend that will be used to sign the request.
1096 Must support the
1097 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1098 interface.
1099
1100 :param private_key: The
Andre Caron24f9bf42015-06-06 20:14:54 -04001101 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
1102 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
1103 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
Andre Caron0ef595f2015-05-18 13:53:43 -04001104 that will be used to sign the request. When the request is
1105 signed by a certificate authority, the private key's associated
1106 public key will be stored in the resulting certificate.
1107
1108 :param algorithm: The
1109 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
1110 that will be used to generate the request signature.
1111
Andre Caron341ff852015-06-06 20:14:31 -04001112 :returns: A new
1113 :class:`~cryptography.x509.CertificateSigningRequest`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001114
1115
Paul Kehrer719d5362015-01-01 20:03:52 -06001116.. class:: Name
1117
1118 .. versionadded:: 0.8
1119
Paul Kehrer53d8d492015-02-13 18:47:30 -06001120 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -06001121 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -06001122 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -06001123 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
1124 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -06001125
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001126 Technically, a Name is a list of *sets* of attributes, called *Relative
1127 Distinguished Names* or *RDNs*, although multi-valued RDNs are rarely
1128 encountered. The iteration order of values within a multi-valued RDN is
Marti Raudsepp9e1873a2018-07-09 16:11:18 +03001129 preserved. If you need to handle multi-valued RDNs, the ``rdns`` property
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001130 gives access to an ordered list of :class:`RelativeDistinguishedName`
1131 objects.
1132
1133 A Name can be initialized with an iterable of :class:`NameAttribute` (the
1134 common case where each RDN has a single attribute) or an iterable of
1135 :class:`RelativeDistinguishedName` objects (in the rare case of
1136 multi-valued RDNs).
1137
Paul Kehrer53d8d492015-02-13 18:47:30 -06001138 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -06001139
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001140 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -06001141 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001142 >>> for attribute in cert.subject:
1143 ... print(attribute)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001144 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>
1145 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='Test Certificates 2011')>
1146 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -06001147
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001148 .. attribute:: rdns
1149
1150 .. versionadded:: 1.6
1151
1152 :type: list of :class:`RelativeDistinguishedName`
1153
Paul Kehrere901d642015-02-11 18:50:58 -06001154 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -06001155
Paul Kehrere901d642015-02-11 18:50:58 -06001156 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -06001157
Paul Kehrere901d642015-02-11 18:50:58 -06001158 :returns: A list of :class:`NameAttribute` instances that match the
1159 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -06001160
1161 .. doctest::
1162
Paul Kehrere27f6582015-08-10 18:33:38 -05001163 >>> cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001164 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -06001165
Paul Kehrer3a15b032016-11-13 14:30:11 -08001166 .. method:: public_bytes(backend)
1167
1168 .. versionadded:: 1.6
1169
1170 :param backend: A backend supporting the
1171 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1172 interface.
1173
1174 :return bytes: The DER encoded name.
1175
Paul Kehrere76cd272014-12-14 19:00:51 -06001176.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -10001177
1178 .. versionadded:: 0.7
1179
1180 An enumeration for X.509 versions.
1181
1182 .. attribute:: v1
1183
1184 For version 1 X.509 certificates.
1185
1186 .. attribute:: v3
1187
1188 For version 3 X.509 certificates.
1189
Paul Kehrer806bfb22015-02-02 17:05:24 -06001190.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001191
1192 .. versionadded:: 0.8
1193
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001194 An X.509 name consists of a list of :class:`RelativeDistinguishedName`
1195 instances, which consist of a set of :class:`NameAttribute` instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001196
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001197 .. attribute:: oid
1198
1199 :type: :class:`ObjectIdentifier`
1200
1201 The attribute OID.
1202
1203 .. attribute:: value
1204
Paul Kehrerd5852cb2015-01-30 08:25:23 -06001205 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001206
1207 The value of the attribute.
1208
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001209
1210.. class:: RelativeDistinguishedName(attributes)
1211
1212 .. versionadded:: 1.6
1213
1214 A relative distinguished name is a non-empty set of name attributes. The
Marti Raudsepp9e1873a2018-07-09 16:11:18 +03001215 object is iterable to get every attribute, preserving the original order.
1216 Passing duplicate attributes to the constructor raises ``ValueError``.
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001217
1218 .. method:: get_attributes_for_oid(oid)
1219
1220 :param oid: An :class:`ObjectIdentifier` instance.
1221
1222 :returns: A list of :class:`NameAttribute` instances that match the OID
1223 provided. The list should contain zero or one values.
1224
1225
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001226.. class:: ObjectIdentifier
1227
1228 .. versionadded:: 0.8
1229
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001230 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -06001231 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001232
Paul Kehrerd44f9a62015-02-04 14:47:34 -06001233 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001234
1235 :type: :class:`str`
1236
Paul Kehrerfedf4f42015-02-06 11:22:07 -06001237 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001238
Paul Kehrer31bdf792015-03-25 14:11:00 -05001239.. _general_name_classes:
1240
1241General Name Classes
1242~~~~~~~~~~~~~~~~~~~~
1243
1244.. class:: GeneralName
1245
1246 .. versionadded:: 0.9
1247
1248 This is the generic interface that all the following classes are registered
1249 against.
1250
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001251.. class:: RFC822Name(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001252
1253 .. versionadded:: 0.9
1254
Paul Kehrere885bd62017-10-11 20:29:23 +08001255 .. versionchanged:: 2.1
Paul Kehrer3e15ca52017-08-01 21:21:19 -05001256
Paul Kehrere885bd62017-10-11 20:29:23 +08001257 .. warning::
1258
1259 Starting with version 2.1 :term:`U-label` input is deprecated. If
1260 passing an internationalized domain name (IDN) you should first IDNA
1261 encode the value and then pass the result as a string. Accessing
1262 ``value`` will return the :term:`A-label` encoded form even if you pass
1263 a U-label. This breaks backwards compatibility, but only for
1264 internationalized domain names.
1265
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001266
1267 This corresponds to an email address. For example, ``user@example.com``.
1268
Paul Kehrere885bd62017-10-11 20:29:23 +08001269 :param value: The email address. If the address contains an
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001270 internationalized domain name then it must be encoded to an
Paul Kehrere885bd62017-10-11 20:29:23 +08001271 :term:`A-label` string before being passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001272
Paul Kehrer31bdf792015-03-25 14:11:00 -05001273 .. attribute:: value
1274
1275 :type: :term:`text`
1276
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001277.. class:: DNSName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001278
1279 .. versionadded:: 0.9
1280
Paul Kehrere885bd62017-10-11 20:29:23 +08001281 .. versionchanged:: 2.1
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001282
Paul Kehrere885bd62017-10-11 20:29:23 +08001283 .. warning::
1284
1285 Starting with version 2.1 :term:`U-label` input is deprecated. If
1286 passing an internationalized domain name (IDN) you should first IDNA
1287 encode the value and then pass the result as a string. Accessing
1288 ``value`` will return the :term:`A-label` encoded form even if you pass
1289 a U-label. This breaks backwards compatibility, but only for
1290 internationalized domain names.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001291
Paul Kehrer31bdf792015-03-25 14:11:00 -05001292 This corresponds to a domain name. For example, ``cryptography.io``.
1293
Paul Kehrere885bd62017-10-11 20:29:23 +08001294 :param value: The domain name. If it is an internationalized domain
1295 name then it must be encoded to an :term:`A-label` string before being
1296 passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001297
Paul Kehrere885bd62017-10-11 20:29:23 +08001298 :type: :term:`text`
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001299
Paul Kehrer31bdf792015-03-25 14:11:00 -05001300 .. attribute:: value
1301
1302 :type: :term:`text`
1303
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001304.. class:: DirectoryName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001305
1306 .. versionadded:: 0.9
1307
1308 This corresponds to a directory name.
1309
1310 .. attribute:: value
1311
1312 :type: :class:`Name`
1313
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001314.. class:: UniformResourceIdentifier(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001315
1316 .. versionadded:: 0.9
1317
Paul Kehrere885bd62017-10-11 20:29:23 +08001318 .. versionchanged:: 2.1
Paul Kehrerb8ef82e2015-04-22 16:04:24 -05001319
Paul Kehrere885bd62017-10-11 20:29:23 +08001320 .. warning::
1321
1322 Starting with version 2.1 :term:`U-label` input is deprecated. If
1323 passing an internationalized domain name (IDN) you should first IDNA
1324 encode the value and then pass the result as a string. Accessing
1325 ``value`` will return the :term:`A-label` encoded form even if you pass
1326 a U-label. This breaks backwards compatibility, but only for
1327 internationalized domain names.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001328
1329 This corresponds to a uniform resource identifier. For example,
1330 ``https://cryptography.io``.
1331
Paul Kehrere885bd62017-10-11 20:29:23 +08001332 :param value: The URI. If it contains an internationalized domain
1333 name then it must be encoded to an :term:`A-label` string before
1334 being passed.
Paul Kehrer1b86dc52017-09-20 23:42:34 +08001335
Paul Kehrer31bdf792015-03-25 14:11:00 -05001336 .. attribute:: value
1337
1338 :type: :term:`text`
1339
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001340.. class:: IPAddress(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001341
1342 .. versionadded:: 0.9
1343
1344 This corresponds to an IP address.
1345
1346 .. attribute:: value
1347
Paul Kehrereb177932015-05-17 18:33:33 -07001348 :type: :class:`~ipaddress.IPv4Address`,
1349 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
1350 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001351
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001352.. class:: RegisteredID(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001353
1354 .. versionadded:: 0.9
1355
1356 This corresponds to a registered ID.
1357
1358 .. attribute:: value
1359
1360 :type: :class:`ObjectIdentifier`
1361
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001362.. class:: OtherName(type_id, value)
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001363
1364 .. versionadded:: 1.0
1365
Joshua Tauberer18b6fc82015-07-05 21:44:51 +00001366 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 +00001367
1368 .. attribute:: type_id
1369
1370 :type: :class:`ObjectIdentifier`
1371
1372 .. attribute:: value
1373
1374 :type: `bytes`
1375
Paul Kehrer8cf26422015-03-21 09:50:24 -05001376X.509 Extensions
1377~~~~~~~~~~~~~~~~
1378
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001379.. class:: Extensions
1380
1381 .. versionadded:: 0.9
1382
1383 An X.509 Extensions instance is an ordered list of extensions. The object
1384 is iterable to get every extension.
1385
Paul Kehrerfa56a232015-03-17 13:14:03 -05001386 .. method:: get_extension_for_oid(oid)
1387
1388 :param oid: An :class:`ObjectIdentifier` instance.
1389
1390 :returns: An instance of the extension class.
1391
1392 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1393 not have the extension requested.
1394
Paul Kehrerfa56a232015-03-17 13:14:03 -05001395 .. doctest::
1396
Paul Kehrere27f6582015-08-10 18:33:38 -05001397 >>> from cryptography.x509.oid import ExtensionOID
1398 >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS)
Paul Kehrerfa56a232015-03-17 13:14:03 -05001399 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1400
Phoebe Queen019b7f82015-08-12 03:52:03 +01001401 .. method:: get_extension_for_class(extclass)
1402
Phoebe Queen6a603eb2015-08-12 14:14:49 +01001403 .. versionadded:: 1.1
1404
Phoebe Queen019b7f82015-08-12 03:52:03 +01001405 :param extclass: An extension class.
1406
1407 :returns: An instance of the extension class.
1408
1409 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1410 not have the extension requested.
1411
1412 .. doctest::
1413
1414 >>> from cryptography import x509
1415 >>> cert.extensions.get_extension_for_class(x509.BasicConstraints)
1416 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1417
Paul Kehrer8cf26422015-03-21 09:50:24 -05001418.. class:: Extension
1419
1420 .. versionadded:: 0.9
1421
Paul Kehrer85894662015-03-22 13:19:31 -05001422 .. attribute:: oid
1423
1424 :type: :class:`ObjectIdentifier`
1425
Paul Kehrere27f6582015-08-10 18:33:38 -05001426 One of the :class:`~cryptography.x509.oid.ExtensionOID` OIDs.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001427
1428 .. attribute:: critical
1429
1430 :type: bool
1431
Paul Kehrer58b75692015-03-22 23:24:58 -05001432 Determines whether a given extension is critical or not. :rfc:`5280`
1433 requires that "A certificate-using system MUST reject the certificate
1434 if it encounters a critical extension it does not recognize or a
1435 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -05001436
Paul Kehrer85894662015-03-22 13:19:31 -05001437 .. attribute:: value
1438
1439 Returns an instance of the extension type corresponding to the OID.
1440
Paul Kehrer14f0bd02015-08-06 11:55:18 +01001441.. class:: ExtensionType
1442
1443 .. versionadded:: 1.0
1444
1445 This is the interface against which all the following extension types are
1446 registered.
1447
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001448.. 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 -05001449
1450 .. versionadded:: 0.9
1451
1452 The key usage extension defines the purpose of the key contained in the
1453 certificate. The usage restriction might be employed when a key that could
Paul Kehrerb33de932015-08-06 23:41:05 +01001454 be used for more than one operation is to be restricted.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001455
Paul Kehrer822f3d32015-08-06 11:47:32 +01001456 .. attribute:: oid
1457
1458 .. versionadded:: 1.0
1459
1460 :type: :class:`ObjectIdentifier`
1461
Paul Kehrere27f6582015-08-10 18:33:38 -05001462 Returns :attr:`~cryptography.x509.oid.ExtensionOID.KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001463
Paul Kehrercecbbba2015-03-30 14:58:38 -05001464 .. attribute:: digital_signature
1465
1466 :type: bool
1467
Paul Kehrer738407b2015-04-01 22:39:02 -05001468 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001469 digital signatures, other than signatures on certificates
1470 (``key_cert_sign``) and CRLs (``crl_sign``).
1471
1472 .. attribute:: content_commitment
1473
1474 :type: bool
1475
Paul Kehrer738407b2015-04-01 22:39:02 -05001476 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001477 digital signatures, other than signatures on certificates
1478 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
1479 non-repudiation service that protects against the signing entity
1480 falsely denying some action. In the case of later conflict, a
1481 reliable third party may determine the authenticity of the signed
1482 data. This was called ``non_repudiation`` in older revisions of the
1483 X.509 specification.
1484
1485 .. attribute:: key_encipherment
1486
1487 :type: bool
1488
Paul Kehrer738407b2015-04-01 22:39:02 -05001489 This purpose is set to true when the subject public key is used for
1490 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001491
1492 .. attribute:: data_encipherment
1493
1494 :type: bool
1495
Paul Kehrer738407b2015-04-01 22:39:02 -05001496 This purpose is set to true when the subject public key is used for
1497 directly enciphering raw user data without the use of an intermediate
1498 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001499
1500 .. attribute:: key_agreement
1501
1502 :type: bool
1503
Paul Kehrer738407b2015-04-01 22:39:02 -05001504 This purpose is set to true when the subject public key is used for key
1505 agreement. For example, when a Diffie-Hellman key is to be used for
1506 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001507
1508 .. attribute:: key_cert_sign
1509
1510 :type: bool
1511
Paul Kehrer738407b2015-04-01 22:39:02 -05001512 This purpose is set to true when the subject public key is used for
1513 verifying signatures on public key certificates. If this purpose is set
1514 to true then ``ca`` must be true in the :class:`BasicConstraints`
1515 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001516
1517 .. attribute:: crl_sign
1518
1519 :type: bool
1520
Paul Kehrer738407b2015-04-01 22:39:02 -05001521 This purpose is set to true when the subject public key is used for
1522 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001523
1524 .. attribute:: encipher_only
1525
1526 :type: bool
1527
Paul Kehrer738407b2015-04-01 22:39:02 -05001528 When this purposes is set to true and the ``key_agreement`` purpose is
1529 also set, the subject public key may be used only for enciphering data
1530 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001531
1532 :raises ValueError: This is raised if accessed when ``key_agreement``
1533 is false.
1534
1535 .. attribute:: decipher_only
1536
1537 :type: bool
1538
Paul Kehrer738407b2015-04-01 22:39:02 -05001539 When this purposes is set to true and the ``key_agreement`` purpose is
1540 also set, the subject public key may be used only for deciphering data
1541 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001542
1543 :raises ValueError: This is raised if accessed when ``key_agreement``
1544 is false.
1545
1546
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001547.. class:: BasicConstraints(ca, path_length)
Paul Kehrer8cf26422015-03-21 09:50:24 -05001548
1549 .. versionadded:: 0.9
1550
Paul Kehrer85894662015-03-22 13:19:31 -05001551 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -05001552 certificate is allowed to sign additional certificates and what path
Paul Kehrerb33de932015-08-06 23:41:05 +01001553 length restrictions may exist.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001554
Paul Kehrer822f3d32015-08-06 11:47:32 +01001555 .. attribute:: oid
1556
1557 .. versionadded:: 1.0
1558
1559 :type: :class:`ObjectIdentifier`
1560
Paul Kehrere27f6582015-08-10 18:33:38 -05001561 Returns :attr:`~cryptography.x509.oid.ExtensionOID.BASIC_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001562
Paul Kehrer8cf26422015-03-21 09:50:24 -05001563 .. attribute:: ca
1564
1565 :type: bool
1566
1567 Whether the certificate can sign certificates.
1568
1569 .. attribute:: path_length
1570
Paul Kehrerfd1444c2015-03-21 19:47:05 -05001571 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -05001572
1573 The maximum path length for certificates subordinate to this
1574 certificate. This attribute only has meaning if ``ca`` is true.
1575 If ``ca`` is true then a path length of None means there's no
1576 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -04001577 If it is zero or greater then it defines the maximum length for a
1578 subordinate CA's certificate chain. For example, a ``path_length`` of 1
1579 means the certificate can sign a subordinate CA, but the subordinate CA
1580 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001581
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001582.. class:: ExtendedKeyUsage(usages)
Paul Kehrerffa2a152015-03-31 08:18:25 -05001583
1584 .. versionadded:: 0.9
1585
1586 This extension indicates one or more purposes for which the certified
1587 public key may be used, in addition to or in place of the basic
1588 purposes indicated in the key usage extension. The object is
Paul Kehrere27f6582015-08-10 18:33:38 -05001589 iterable to obtain the list of
1590 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs present.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001591
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001592 :param list usages: A list of
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001593 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs.
1594
Paul Kehrer822f3d32015-08-06 11:47:32 +01001595 .. attribute:: oid
1596
1597 .. versionadded:: 1.0
1598
1599 :type: :class:`ObjectIdentifier`
1600
Paul Kehrere27f6582015-08-10 18:33:38 -05001601 Returns :attr:`~cryptography.x509.oid.ExtensionOID.EXTENDED_KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001602
1603
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001604.. class:: OCSPNoCheck()
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001605
Paul Kehrer506a2152015-05-26 08:01:18 -05001606 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001607
1608 This presence of this extension indicates that an OCSP client can trust a
1609 responder for the lifetime of the responder's certificate. CAs issuing
1610 such a certificate should realize that a compromise of the responder's key
1611 is as serious as the compromise of a CA key used to sign CRLs, at least for
1612 the validity period of this certificate. CA's may choose to issue this type
1613 of certificate with a very short lifetime and renew it frequently. This
1614 extension is only relevant when the certificate is an authorized OCSP
1615 responder.
1616
Paul Kehrer822f3d32015-08-06 11:47:32 +01001617 .. attribute:: oid
1618
1619 .. versionadded:: 1.0
1620
1621 :type: :class:`ObjectIdentifier`
1622
Paul Kehrere27f6582015-08-10 18:33:38 -05001623 Returns :attr:`~cryptography.x509.oid.ExtensionOID.OCSP_NO_CHECK`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001624
Paul Kehrer5d669662017-09-11 09:16:34 +08001625
1626.. class:: TLSFeature(features)
1627
1628 .. versionadded:: 2.1
1629
1630 The TLS Feature extension is defined in :rfc:`7633` and is used in
1631 certificates for OCSP Must-Staple. The object is iterable to get every
1632 element.
1633
1634 :param list features: A list of features to enable from the
1635 :class:`~cryptography.x509.TLSFeatureType` enum. At this time only
1636 ``status_request`` or ``status_request_v2`` are allowed.
1637
1638 .. attribute:: oid
1639
1640 :type: :class:`ObjectIdentifier`
1641
1642 Returns :attr:`~cryptography.x509.oid.ExtensionOID.TLS_FEATURE`.
1643
1644.. class:: TLSFeatureType
1645
1646 .. versionadded:: 2.1
1647
1648 An enumeration of TLS Feature types.
1649
1650 .. attribute:: status_request
1651
1652 This feature type is defined in :rfc:`6066` and, when embedded in
1653 an X.509 certificate, signals to the client that it should require
1654 a stapled OCSP response in the TLS handshake. Commonly known as OCSP
1655 Must-Staple in certificates.
1656
1657 .. attribute:: status_request_v2
1658
1659 This feature type is defined in :rfc:`6961`. This value is not
1660 commonly used and if you want to enable OCSP Must-Staple you should
1661 use ``status_request``.
1662
1663
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001664.. class:: NameConstraints(permitted_subtrees, excluded_subtrees)
Paul Kehrere0017be2015-05-17 20:39:40 -06001665
1666 .. versionadded:: 1.0
1667
1668 The name constraints extension, which only has meaning in a CA certificate,
1669 defines a name space within which all subject names in certificates issued
1670 beneath the CA certificate must (or must not) be in. For specific details
1671 on the way this extension should be processed see :rfc:`5280`.
1672
Paul Kehrer822f3d32015-08-06 11:47:32 +01001673 .. attribute:: oid
1674
1675 .. versionadded:: 1.0
1676
1677 :type: :class:`ObjectIdentifier`
1678
Paul Kehrere27f6582015-08-10 18:33:38 -05001679 Returns :attr:`~cryptography.x509.oid.ExtensionOID.NAME_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001680
Paul Kehrere0017be2015-05-17 20:39:40 -06001681 .. attribute:: permitted_subtrees
1682
1683 :type: list of :class:`GeneralName` objects or None
1684
1685 The set of permitted name patterns. If a name matches this and an
1686 element in ``excluded_subtrees`` it is invalid. At least one of
1687 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
1688
1689 .. attribute:: excluded_subtrees
1690
1691 :type: list of :class:`GeneralName` objects or None
1692
1693 Any name matching a restriction in the ``excluded_subtrees`` field is
1694 invalid regardless of information appearing in the
1695 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
1696 ``excluded_subtrees`` will be non-None.
1697
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001698.. class:: AuthorityKeyIdentifier(key_identifier, authority_cert_issuer, authority_cert_serial_number)
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001699
1700 .. versionadded:: 0.9
1701
1702 The authority key identifier extension provides a means of identifying the
1703 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001704 This extension is typically used to assist in determining the appropriate
1705 certificate chain. For more information about generation and use of this
1706 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001707
Paul Kehrer822f3d32015-08-06 11:47:32 +01001708 .. attribute:: oid
1709
1710 .. versionadded:: 1.0
1711
1712 :type: :class:`ObjectIdentifier`
1713
Paul Kehrere27f6582015-08-10 18:33:38 -05001714 Returns
1715 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001716
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001717 .. attribute:: key_identifier
1718
1719 :type: bytes
1720
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001721 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001722 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001723
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001724 .. attribute:: authority_cert_issuer
1725
Thom Dixon488c0482018-05-18 03:55:29 -07001726 :type: A list of :class:`GeneralName` instances or None
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001727
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001728 The :class:`Name` of the issuer's issuer.
1729
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001730 .. attribute:: authority_cert_serial_number
1731
1732 :type: int or None
1733
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001734 The serial number of the issuer's issuer.
1735
Paul Kehrer253929a2015-08-05 17:30:39 +01001736 .. classmethod:: from_issuer_public_key(public_key)
1737
1738 .. versionadded:: 1.0
1739
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001740 .. note::
1741
1742 This method should be used if the issuer certificate does not
1743 contain a :class:`~cryptography.x509.SubjectKeyIdentifier`.
1744 Otherwise, use
1745 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier`.
1746
Paul Kehrer253929a2015-08-05 17:30:39 +01001747 Creates a new AuthorityKeyIdentifier instance using the public key
1748 provided to generate the appropriate digest. This should be the
Paul Kehrer26ac47f2015-08-08 15:20:52 -05001749 **issuer's public key**. The resulting object will contain
1750 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1751 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1752 and
1753 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1754 will be None.
1755 The generated ``key_identifier`` is the SHA1 hash of the ``subjectPublicKey``
1756 ASN.1 bit string. This is the first recommendation in :rfc:`5280`
Paul Kehrer253929a2015-08-05 17:30:39 +01001757 section 4.2.1.2.
1758
Paul Kehrercc671822015-08-08 15:41:54 -05001759 :param public_key: One of
1760 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1761 ,
1762 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1763 , or
1764 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
Paul Kehrer253929a2015-08-05 17:30:39 +01001765
1766 .. doctest::
1767
1768 >>> from cryptography import x509
1769 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001770 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1771 >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key())
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001772 <AuthorityKeyIdentifier(key_identifier=b'X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9', authority_cert_issuer=None, authority_cert_serial_number=None)>
Paul Kehrer253929a2015-08-05 17:30:39 +01001773
Paul Kehrer61ff3562016-03-11 22:51:27 -04001774 .. classmethod:: from_issuer_subject_key_identifier(ski)
1775
1776 .. versionadded:: 1.3
1777
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001778 .. note::
1779 This method should be used if the issuer certificate contains a
1780 :class:`~cryptography.x509.SubjectKeyIdentifier`. Otherwise, use
1781 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_public_key`.
1782
Paul Kehrer61ff3562016-03-11 22:51:27 -04001783 Creates a new AuthorityKeyIdentifier instance using the
1784 SubjectKeyIdentifier from the issuer certificate. The resulting object
1785 will contain
1786 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1787 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1788 and
1789 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1790 will be None.
1791
1792 :param ski: The
1793 :class:`~cryptography.x509.SubjectKeyIdentifier` from the issuer
1794 certificate.
1795
1796 .. doctest::
1797
1798 >>> from cryptography import x509
1799 >>> from cryptography.hazmat.backends import default_backend
1800 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1801 >>> ski = issuer_cert.extensions.get_extension_for_class(x509.SubjectKeyIdentifier)
1802 >>> x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(ski)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001803 <AuthorityKeyIdentifier(key_identifier=b'X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9', authority_cert_issuer=None, authority_cert_serial_number=None)>
Paul Kehrer61ff3562016-03-11 22:51:27 -04001804
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001805.. class:: SubjectKeyIdentifier(digest)
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001806
1807 .. versionadded:: 0.9
1808
1809 The subject key identifier extension provides a means of identifying
1810 certificates that contain a particular public key.
1811
Paul Kehrer822f3d32015-08-06 11:47:32 +01001812 .. attribute:: oid
1813
1814 .. versionadded:: 1.0
1815
1816 :type: :class:`ObjectIdentifier`
1817
Paul Kehrere27f6582015-08-10 18:33:38 -05001818 Returns
1819 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001820
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001821 .. attribute:: digest
1822
1823 :type: bytes
1824
1825 The binary value of the identifier.
1826
Paul Kehrerd4a7f062015-08-05 18:32:18 +01001827 .. classmethod:: from_public_key(public_key)
Paul Kehrerf22f6122015-08-05 12:57:13 +01001828
1829 .. versionadded:: 1.0
1830
1831 Creates a new SubjectKeyIdentifier instance using the public key
1832 provided to generate the appropriate digest. This should be the public
Paul Kehrereb9ec002015-08-08 10:03:02 -05001833 key that is in the certificate. The generated digest is the SHA1 hash
1834 of the ``subjectPublicKey`` ASN.1 bit string. This is the first
1835 recommendation in :rfc:`5280` section 4.2.1.2.
Paul Kehrerf22f6122015-08-05 12:57:13 +01001836
1837 :param public_key: One of
1838 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1839 ,
1840 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1841 , or
1842 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
1843
Paul Kehrer253929a2015-08-05 17:30:39 +01001844 .. doctest::
1845
1846 >>> from cryptography import x509
1847 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001848 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
1849 >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key())
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001850 <SubjectKeyIdentifier(digest=b'\xdb\xaa\xf0\x06\x11\xdbD\xfe\xbf\x93\x03\x8av\x88WP7\xa6\x91\xf7')>
Paul Kehrer253929a2015-08-05 17:30:39 +01001851
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001852.. class:: SubjectAlternativeName(general_names)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001853
1854 .. versionadded:: 0.9
1855
1856 Subject alternative name is an X.509 extension that provides a list of
1857 :ref:`general name <general_name_classes>` instances that provide a set
1858 of identities for which the certificate is valid. The object is iterable to
1859 get every element.
1860
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001861 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001862
Paul Kehrer822f3d32015-08-06 11:47:32 +01001863 .. attribute:: oid
1864
1865 .. versionadded:: 1.0
1866
1867 :type: :class:`ObjectIdentifier`
1868
Paul Kehrere27f6582015-08-10 18:33:38 -05001869 Returns
1870 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001871
Paul Kehrer31bdf792015-03-25 14:11:00 -05001872 .. method:: get_values_for_type(type)
1873
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03001874 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer31bdf792015-03-25 14:11:00 -05001875 :ref:`general name classes <general_name_classes>`.
1876
1877 :returns: A list of values extracted from the matched general names.
Joshua Taubererd2afad32015-07-06 22:37:53 +00001878 The type of the returned values depends on the :class:`GeneralName`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001879
Paul Kehrer93ae8052015-05-02 23:18:09 -05001880 .. doctest::
1881
1882 >>> from cryptography import x509
1883 >>> from cryptography.hazmat.backends import default_backend
1884 >>> from cryptography.hazmat.primitives import hashes
1885 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001886 >>> # Get the subjectAltName extension from the certificate
Paul Kehrere27f6582015-08-10 18:33:38 -05001887 >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001888 >>> # Get the dNSName entries from the SAN extension
1889 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer056c9dd2018-05-12 15:17:06 -04001890 ['www.cryptography.io', 'cryptography.io']
Paul Kehrer93ae8052015-05-02 23:18:09 -05001891
Paul Kehrer8cf26422015-03-21 09:50:24 -05001892
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001893.. class:: IssuerAlternativeName(general_names)
Paul Kehrer99125c92015-06-07 18:37:10 -05001894
1895 .. versionadded:: 1.0
1896
1897 Issuer alternative name is an X.509 extension that provides a list of
1898 :ref:`general name <general_name_classes>` instances that provide a set
1899 of identities for the certificate issuer. The object is iterable to
1900 get every element.
1901
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001902 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001903
Paul Kehrer822f3d32015-08-06 11:47:32 +01001904 .. attribute:: oid
1905
1906 .. versionadded:: 1.0
1907
1908 :type: :class:`ObjectIdentifier`
1909
Paul Kehrere27f6582015-08-10 18:33:38 -05001910 Returns
1911 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUER_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001912
Paul Kehrer99125c92015-06-07 18:37:10 -05001913 .. method:: get_values_for_type(type)
1914
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03001915 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer99125c92015-06-07 18:37:10 -05001916 :ref:`general name classes <general_name_classes>`.
1917
1918 :returns: A list of values extracted from the matched general names.
1919
1920
Alex Gaynor6a0718f2017-06-04 13:36:58 -04001921.. class:: PrecertificateSignedCertificateTimestamps(scts)
1922
1923 .. versionadded:: 2.0
1924
1925 This extension contains
1926 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
1927 instances which were issued for the pre-certificate corresponding to this
1928 certificate. These can be used to verify that the certificate is included
1929 in a public Certificate Transparency log.
1930
1931 It is an iterable containing one or more
1932 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
1933 objects.
1934
1935 :param list scts: A ``list`` of
1936 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
1937 objects.
1938
1939 .. attribute:: oid
1940
1941 :type: :class:`ObjectIdentifier`
1942
1943 Returns
1944 :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS`.
1945
1946
Alex Gaynordd6b78b2018-08-31 18:25:52 -05001947.. class:: PrecertPoison()
1948
1949 .. versionadded:: 2.4
1950
1951 This extension indicates that the certificate should not be treated as a
1952 certificate for the purposes of validation, but is instead for submission
1953 to a certificate transparency log in order to obtain SCTs which will be
1954 embedded in a :class:`PrecertificateSignedCertificateTimestamps` extension
1955 on the final certificate.
1956
1957 .. attribute:: oid
1958
1959 :type: :class:`ObjectIdentifier`
1960
1961 Returns :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_POISON`.
1962
1963
Paul Kehrer5e3cc982017-09-22 21:29:36 +08001964.. class:: DeltaCRLIndicator(crl_number)
1965
1966 .. versionadded:: 2.1
1967
1968 The delta CRL indicator is a CRL extension that identifies a CRL as being
1969 a delta CRL. Delta CRLs contain updates to revocation information
1970 previously distributed, rather than all the information that would appear
1971 in a complete CRL.
1972
1973 :param int crl_number: The CRL number of the complete CRL that the
1974 delta CRL is updating.
1975
1976 .. attribute:: oid
1977
1978 :type: :class:`ObjectIdentifier`
1979
1980 Returns
1981 :attr:`~cryptography.x509.oid.ExtensionOID.DELTA_CRL_INDICATOR`.
1982
1983 .. attribute:: crl_number
1984
1985 :type: int
1986
1987
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001988.. class:: AuthorityInformationAccess(descriptions)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001989
1990 .. versionadded:: 0.9
1991
1992 The authority information access extension indicates how to access
1993 information and services for the issuer of the certificate in which
1994 the extension appears. Information and services may include online
1995 validation services (such as OCSP) and issuer data. It is an iterable,
Paul Kehrere27f6582015-08-10 18:33:38 -05001996 containing one or more :class:`~cryptography.x509.AccessDescription`
1997 instances.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001998
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001999 :param list descriptions: A list of :class:`AccessDescription` objects.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002000
Paul Kehrer822f3d32015-08-06 11:47:32 +01002001 .. attribute:: oid
2002
2003 .. versionadded:: 1.0
2004
2005 :type: :class:`ObjectIdentifier`
2006
Paul Kehrere27f6582015-08-10 18:33:38 -05002007 Returns
2008 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_INFORMATION_ACCESS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002009
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002010
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002011.. class:: AccessDescription(access_method, access_location)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002012
Paul Kehrer5a485522015-05-06 00:29:12 -05002013 .. versionadded:: 0.9
2014
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002015 .. attribute:: access_method
2016
2017 :type: :class:`ObjectIdentifier`
2018
Paul Kehrerf506bca2015-05-02 22:31:47 -05002019 The access method defines what the ``access_location`` means. It must
Paul Kehrere27f6582015-08-10 18:33:38 -05002020 be either
2021 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` or
2022 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`.
2023 If it is
2024 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP`
2025 the access location will be where to obtain OCSP
2026 information for the certificate. If it is
2027 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`
2028 the access location will provide additional information about the
2029 issuing certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002030
2031 .. attribute:: access_location
2032
2033 :type: :class:`GeneralName`
2034
Paul Kehrerf506bca2015-05-02 22:31:47 -05002035 Where to access the information defined by the access method.
2036
Paul Kehrerb76bcf82017-09-24 08:44:12 +08002037.. class:: FreshestCRL(distribution_points)
2038
2039 .. versionadded:: 2.1
2040
2041 The freshest CRL extension (also known as Delta CRL Distribution Point)
2042 identifies how delta CRL information is obtained. It is an iterable,
2043 containing one or more :class:`DistributionPoint` instances.
2044
2045 :param list distribution_points: A list of :class:`DistributionPoint`
2046 instances.
2047
2048 .. attribute:: oid
2049
2050 :type: :class:`ObjectIdentifier`
2051
2052 Returns
2053 :attr:`~cryptography.x509.oid.ExtensionOID.FRESHEST_CRL`.
2054
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002055.. class:: CRLDistributionPoints(distribution_points)
Paul Kehrer5a485522015-05-06 00:29:12 -05002056
2057 .. versionadded:: 0.9
2058
2059 The CRL distribution points extension identifies how CRL information is
2060 obtained. It is an iterable, containing one or more
2061 :class:`DistributionPoint` instances.
2062
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002063 :param list distribution_points: A list of :class:`DistributionPoint`
2064 instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002065
Paul Kehrer822f3d32015-08-06 11:47:32 +01002066 .. attribute:: oid
2067
2068 .. versionadded:: 1.0
2069
2070 :type: :class:`ObjectIdentifier`
2071
Paul Kehrere27f6582015-08-10 18:33:38 -05002072 Returns
2073 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_DISTRIBUTION_POINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002074
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002075.. class:: DistributionPoint(full_name, relative_name, reasons, crl_issuer)
Paul Kehrer5a485522015-05-06 00:29:12 -05002076
2077 .. versionadded:: 0.9
2078
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002079 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05002080
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002081 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05002082
Paul Kehrerf2c072b2015-05-09 17:04:28 -05002083 This field describes methods to retrieve the CRL. At most one of
2084 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002085
2086 .. attribute:: relative_name
2087
Fraser Tweedale02467dd2016-11-07 15:54:04 +10002088 :type: :class:`RelativeDistinguishedName` or None
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002089
2090 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05002091 issuer. At most one of ``full_name`` or ``relative_name`` will be
2092 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05002093
Fraser Tweedale02467dd2016-11-07 15:54:04 +10002094 .. versionchanged:: 1.6
2095 Changed from :class:`Name` to :class:`RelativeDistinguishedName`.
2096
Paul Kehrer5a485522015-05-06 00:29:12 -05002097 .. attribute:: crl_issuer
2098
2099 :type: list of :class:`GeneralName` instances or None
2100
2101 Information about the issuer of the CRL.
2102
2103 .. attribute:: reasons
2104
Paul Kehrer3fd02602015-05-09 19:46:13 -05002105 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05002106
2107 The reasons a given distribution point may be used for when performing
2108 revocation checks.
2109
2110.. class:: ReasonFlags
2111
2112 .. versionadded:: 0.9
2113
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002114 An enumeration for CRL reasons.
2115
2116 .. attribute:: unspecified
2117
2118 It is unspecified why the certificate was revoked. This reason cannot
2119 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05002120
2121 .. attribute:: key_compromise
2122
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002123 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05002124
2125 .. attribute:: ca_compromise
2126
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002127 This reason indicates that the CA issuing the certificate was
2128 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05002129
2130 .. attribute:: affiliation_changed
2131
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002132 This reason indicates that the subject's name or other information has
2133 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05002134
2135 .. attribute:: superseded
2136
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002137 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05002138
2139 .. attribute:: cessation_of_operation
2140
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002141 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05002142
2143 .. attribute:: certificate_hold
2144
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002145 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05002146
2147 .. attribute:: privilege_withdrawn
2148
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002149 This reason indicates that the privilege granted by this certificate
2150 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05002151
2152 .. attribute:: aa_compromise
2153
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002154 When an attribute authority has been compromised.
2155
2156 .. attribute:: remove_from_crl
2157
2158 This reason indicates that the certificate was on hold and should be
2159 removed from the CRL. This reason cannot be used as a reason flag
2160 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05002161
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002162.. class:: InhibitAnyPolicy(skip_certs)
Paul Kehrer16fae762015-05-01 23:14:20 -05002163
2164 .. versionadded:: 1.0
2165
2166 The inhibit ``anyPolicy`` extension indicates that the special OID
Paul Kehrere27f6582015-08-10 18:33:38 -05002167 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY`, is not
2168 considered an explicit match for other :class:`CertificatePolicies` except
2169 when it appears in an intermediate self-issued CA certificate. The value
2170 indicates the number of additional non-self-issued certificates that may
2171 appear in the path before
2172 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` is no
2173 longer permitted. For example, a value of one indicates that
2174 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` may be
2175 processed in certificates issued by the subject of this certificate, but
2176 not in additional certificates in the path.
Paul Kehrer16fae762015-05-01 23:14:20 -05002177
Paul Kehrer822f3d32015-08-06 11:47:32 +01002178 .. attribute:: oid
2179
2180 .. versionadded:: 1.0
2181
2182 :type: :class:`ObjectIdentifier`
2183
Paul Kehrere27f6582015-08-10 18:33:38 -05002184 Returns
2185 :attr:`~cryptography.x509.oid.ExtensionOID.INHIBIT_ANY_POLICY`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002186
Paul Kehrer16fae762015-05-01 23:14:20 -05002187 .. attribute:: skip_certs
2188
2189 :type: int
2190
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002191.. class:: PolicyConstraints
2192
2193 .. versionadded:: 1.3
2194
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002195 The policy constraints extension is used to inhibit policy mapping or
2196 require that each certificate in a chain contain an acceptable policy
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002197 identifier. For more information about the use of this extension see
2198 :rfc:`5280`.
2199
Paul Kehrer159b3b52016-02-26 08:27:22 -06002200 .. attribute:: oid
2201
2202 :type: :class:`ObjectIdentifier`
2203
2204 Returns :attr:`~cryptography.x509.oid.ExtensionOID.POLICY_CONSTRAINTS`.
2205
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002206 .. attribute:: require_explicit_policy
2207
2208 :type: int or None
2209
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002210 If this field is not None, the value indicates the number of additional
2211 certificates that may appear in the chain before an explicit policy is
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002212 required for the entire path. When an explicit policy is required, it
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002213 is necessary for all certificates in the chain to contain an acceptable
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002214 policy identifier in the certificate policies extension. An
2215 acceptable policy identifier is the identifier of a policy required
2216 by the user of the certification path or the identifier of a policy
2217 that has been declared equivalent through policy mapping.
2218
2219 .. attribute:: inhibit_policy_mapping
2220
2221 :type: int or None
2222
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002223 If this field is not None, the value indicates the number of additional
2224 certificates that may appear in the chain before policy mapping is no
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002225 longer permitted. For example, a value of one indicates that policy
2226 mapping may be processed in certificates issued by the subject of this
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002227 certificate, but not in additional certificates in the chain.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002228
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002229.. class:: CRLNumber(crl_number)
2230
2231 .. versionadded:: 1.2
2232
Paul Kehrere32b9942015-12-22 22:26:53 -06002233 The CRL number is a CRL extension that conveys a monotonically increasing
2234 sequence number for a given CRL scope and CRL issuer. This extension allows
2235 users to easily determine when a particular CRL supersedes another CRL.
2236 :rfc:`5280` requires that this extension be present in conforming CRLs.
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002237
2238 .. attribute:: oid
2239
2240 :type: :class:`ObjectIdentifier`
2241
2242 Returns
2243 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_NUMBER`.
2244
2245 .. attribute:: crl_number
2246
2247 :type: int
2248
Paul Kehrer14fd6972015-12-30 10:58:25 -06002249.. class:: UnrecognizedExtension
2250
2251 .. versionadded:: 1.2
2252
Alex Gaynord08ddd52017-05-20 09:01:54 -07002253 A generic extension class used to hold the raw value of extensions that
2254 ``cryptography`` does not know how to parse.
Paul Kehrer14fd6972015-12-30 10:58:25 -06002255
2256 .. attribute:: oid
2257
2258 :type: :class:`ObjectIdentifier`
2259
2260 Returns the OID associated with this extension.
2261
2262 .. attribute:: value
2263
2264 :type: byte
2265
2266 Returns the DER encoded bytes payload of the extension.
2267
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002268.. class:: CertificatePolicies(policies)
Paul Kehrer0d210922015-04-28 17:31:07 -05002269
2270 .. versionadded:: 0.9
2271
Paul Kehrer2e879742015-05-02 23:09:56 -05002272 The certificate policies extension is an iterable, containing one or more
2273 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05002274
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002275 :param list policies: A list of :class:`PolicyInformation` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002276
Paul Kehrer822f3d32015-08-06 11:47:32 +01002277 .. attribute:: oid
2278
2279 .. versionadded:: 1.0
2280
2281 :type: :class:`ObjectIdentifier`
2282
Paul Kehrere27f6582015-08-10 18:33:38 -05002283 Returns
2284 :attr:`~cryptography.x509.oid.ExtensionOID.CERTIFICATE_POLICIES`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002285
Paul Kehrer0d210922015-04-28 17:31:07 -05002286Certificate Policies Classes
2287~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2288
2289These classes may be present within a :class:`CertificatePolicies` instance.
2290
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002291.. class:: PolicyInformation(policy_identifier, policy_qualifiers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002292
2293 .. versionadded:: 0.9
2294
2295 Contains a policy identifier and an optional list of qualifiers.
2296
2297 .. attribute:: policy_identifier
2298
2299 :type: :class:`ObjectIdentifier`
2300
2301 .. attribute:: policy_qualifiers
2302
2303 :type: list
2304
Paul Kehrerba35b3b2015-05-10 13:07:59 -05002305 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002306 If the value is text it is a pointer to the practice statement
2307 published by the certificate authority. If it is a user notice it is
2308 meant for display to the relying party when the certificate is
2309 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05002310
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002311.. class:: UserNotice(notice_reference, explicit_text)
Paul Kehrer0d210922015-04-28 17:31:07 -05002312
2313 .. versionadded:: 0.9
2314
Paul Kehrer2e879742015-05-02 23:09:56 -05002315 User notices are intended for display to a relying party when a certificate
2316 is used. In practice, few if any UIs expose this data and it is a rarely
2317 encoded component.
2318
Paul Kehrer0d210922015-04-28 17:31:07 -05002319 .. attribute:: notice_reference
2320
2321 :type: :class:`NoticeReference` or None
2322
Paul Kehrer2e879742015-05-02 23:09:56 -05002323 The notice reference field names an organization and identifies,
2324 by number, a particular statement prepared by that organization.
2325
Paul Kehrer0d210922015-04-28 17:31:07 -05002326 .. attribute:: explicit_text
2327
Paul Kehrer2e879742015-05-02 23:09:56 -05002328 This field includes an arbitrary textual statement directly in the
2329 certificate.
2330
Paul Kehrer0d210922015-04-28 17:31:07 -05002331 :type: :term:`text`
2332
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002333.. class:: NoticeReference(organization, notice_numbers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002334
Paul Kehrer2e879742015-05-02 23:09:56 -05002335 Notice reference can name an organization and provide information about
2336 notices related to the certificate. For example, it might identify the
2337 organization name and notice number 1. Application software could
2338 have a notice file containing the current set of notices for the named
2339 organization; the application would then extract the notice text from the
2340 file and display it. In practice this is rarely seen.
2341
Paul Kehrer0d210922015-04-28 17:31:07 -05002342 .. versionadded:: 0.9
2343
2344 .. attribute:: organization
2345
Paul Kehrer66c61702015-05-12 16:39:18 -05002346 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05002347
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002348 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05002349
Paul Kehrer66c61702015-05-12 16:39:18 -05002350 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05002351
Paul Kehrer66c61702015-05-12 16:39:18 -05002352 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05002353
Paul Kehrere5f152b2015-12-25 23:55:47 -06002354.. _crl_entry_extensions:
2355
Paul Kehrer49bb7562015-12-25 16:17:40 -06002356CRL Entry Extensions
2357~~~~~~~~~~~~~~~~~~~~
2358
2359These extensions are only valid within a :class:`RevokedCertificate` object.
2360
2361.. class:: CertificateIssuer(general_names)
2362
2363 .. versionadded:: 1.2
2364
2365 The certificate issuer is an extension that is only valid inside
2366 :class:`~cryptography.x509.RevokedCertificate` objects. If the
2367 ``indirectCRL`` property of the parent CRL's IssuingDistributionPoint
2368 extension is set, then this extension identifies the certificate issuer
2369 associated with the revoked certificate. The object is iterable to get
2370 every element.
2371
2372 :param list general_names: A list of :class:`GeneralName` instances.
2373
2374 .. attribute:: oid
2375
2376 :type: :class:`ObjectIdentifier`
2377
2378 Returns
2379 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CERTIFICATE_ISSUER`.
2380
2381 .. method:: get_values_for_type(type)
2382
2383 :param type: A :class:`GeneralName` instance. This is one of the
2384 :ref:`general name classes <general_name_classes>`.
2385
2386 :returns: A list of values extracted from the matched general names.
2387 The type of the returned values depends on the :class:`GeneralName`.
2388
Paul Kehrer7058ece2015-12-25 22:28:29 -06002389.. class:: CRLReason(reason)
2390
2391 .. versionadded:: 1.2
2392
2393 CRL reason (also known as ``reasonCode``) is an extension that is only
2394 valid inside :class:`~cryptography.x509.RevokedCertificate` objects. It
2395 identifies a reason for the certificate revocation.
2396
Paul Kehrerce4d0842017-09-20 22:14:26 +08002397 :param reason: An element from :class:`~cryptography.x509.ReasonFlags`.
Paul Kehrer7058ece2015-12-25 22:28:29 -06002398
2399 .. attribute:: oid
2400
2401 :type: :class:`ObjectIdentifier`
2402
2403 Returns
2404 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CRL_REASON`.
2405
2406 .. attribute:: reason
2407
2408 :type: An element from :class:`~cryptography.x509.ReasonFlags`
2409
Paul Kehrer23c0bbc2015-12-25 22:35:19 -06002410.. class:: InvalidityDate(invalidity_date)
2411
2412 .. versionadded:: 1.2
2413
2414 Invalidity date is an extension that is only valid inside
2415 :class:`~cryptography.x509.RevokedCertificate` objects. It provides
2416 the date on which it is known or suspected that the private key was
2417 compromised or that the certificate otherwise became invalid.
2418 This date may be earlier than the revocation date in the CRL entry,
2419 which is the date at which the CA processed the revocation.
2420
2421 :param invalidity_date: The :class:`datetime.datetime` when it is known
2422 or suspected that the private key was compromised.
2423
2424 .. attribute:: oid
2425
2426 :type: :class:`ObjectIdentifier`
2427
2428 Returns
2429 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.INVALIDITY_DATE`.
2430
2431 .. attribute:: invalidity_date
2432
2433 :type: :class:`datetime.datetime`
2434
Paul Kehrer09403102018-09-09 21:57:21 -05002435OCSP Extensions
2436~~~~~~~~~~~~~~~
2437
2438.. class:: OCSPNonce(nonce)
2439
2440 .. versionadded:: 2.4
2441
2442 OCSP nonce is an extension that is only valid inside
2443 :class:`~cryptography.x509.ocsp.OCSPRequest` and
2444 :class:`~cryptography.x509.ocsp.OCSPResponse` objects. The nonce
2445 cryptographically binds a request and a response to prevent replay attacks.
2446 In practice nonces are rarely used in OCSP due to the desire to precompute
2447 OCSP responses at large scale.
2448
2449 .. attribute:: oid
2450
2451 :type: :class:`ObjectIdentifier`
2452
2453 Returns
2454 :attr:`~cryptography.x509.oid.OCSPExtensionOID.NONCE`.
2455
2456 .. attribute:: nonce
2457
2458 :type: bytes
Paul Kehrer49bb7562015-12-25 16:17:40 -06002459
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002460Object Identifiers
2461~~~~~~~~~~~~~~~~~~
2462
Paul Kehrer4bb46492015-02-07 16:59:14 -06002463X.509 elements are frequently identified by :class:`ObjectIdentifier`
2464instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002465
Paul Kehrere27f6582015-08-10 18:33:38 -05002466.. currentmodule:: cryptography.x509.oid
Paul Kehrer56da2a52015-02-11 23:35:07 -06002467
Paul Kehrere27f6582015-08-10 18:33:38 -05002468.. class:: NameOID
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002469
Paul Kehrere27f6582015-08-10 18:33:38 -05002470 These OIDs are typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06002471
Paul Kehrere27f6582015-08-10 18:33:38 -05002472 .. versionadded:: 1.0
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002473
Paul Kehrere27f6582015-08-10 18:33:38 -05002474 .. attribute:: COMMON_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002475
Paul Kehrere27f6582015-08-10 18:33:38 -05002476 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
2477 name would be encoded here for server certificates. :rfc:`2818`
2478 deprecates this practice and names of that type should now be located
2479 in a :class:`~cryptography.x509.SubjectAlternativeName` extension.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002480
Paul Kehrere27f6582015-08-10 18:33:38 -05002481 .. attribute:: COUNTRY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002482
Paul Kehrere27f6582015-08-10 18:33:38 -05002483 Corresponds to the dotted string ``"2.5.4.6"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002484
Paul Kehrere27f6582015-08-10 18:33:38 -05002485 .. attribute:: LOCALITY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002486
Paul Kehrere27f6582015-08-10 18:33:38 -05002487 Corresponds to the dotted string ``"2.5.4.7"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002488
Paul Kehrere27f6582015-08-10 18:33:38 -05002489 .. attribute:: STATE_OR_PROVINCE_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002490
Paul Kehrere27f6582015-08-10 18:33:38 -05002491 Corresponds to the dotted string ``"2.5.4.8"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002492
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002493 .. attribute:: STREET_ADDRESS
2494
2495 .. versionadded:: 1.6
2496
2497 Corresponds to the dotted string ``"2.5.4.9"``.
2498
Paul Kehrere27f6582015-08-10 18:33:38 -05002499 .. attribute:: ORGANIZATION_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002500
Paul Kehrere27f6582015-08-10 18:33:38 -05002501 Corresponds to the dotted string ``"2.5.4.10"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002502
Paul Kehrere27f6582015-08-10 18:33:38 -05002503 .. attribute:: ORGANIZATIONAL_UNIT_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002504
Paul Kehrere27f6582015-08-10 18:33:38 -05002505 Corresponds to the dotted string ``"2.5.4.11"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002506
Paul Kehrere27f6582015-08-10 18:33:38 -05002507 .. attribute:: SERIAL_NUMBER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002508
Paul Kehrere27f6582015-08-10 18:33:38 -05002509 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from
2510 the serial number of the certificate itself (which can be obtained with
Chelsea Winfreee295f3a2016-06-02 21:15:54 -07002511 :func:`~cryptography.x509.Certificate.serial_number`).
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002512
Paul Kehrere27f6582015-08-10 18:33:38 -05002513 .. attribute:: SURNAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002514
Paul Kehrere27f6582015-08-10 18:33:38 -05002515 Corresponds to the dotted string ``"2.5.4.4"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002516
Paul Kehrere27f6582015-08-10 18:33:38 -05002517 .. attribute:: GIVEN_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002518
Paul Kehrere27f6582015-08-10 18:33:38 -05002519 Corresponds to the dotted string ``"2.5.4.42"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002520
Paul Kehrere27f6582015-08-10 18:33:38 -05002521 .. attribute:: TITLE
Paul Kehrer858b9b72015-02-05 09:50:31 -06002522
Paul Kehrere27f6582015-08-10 18:33:38 -05002523 Corresponds to the dotted string ``"2.5.4.12"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002524
Paul Kehrere27f6582015-08-10 18:33:38 -05002525 .. attribute:: GENERATION_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002526
Paul Kehrere27f6582015-08-10 18:33:38 -05002527 Corresponds to the dotted string ``"2.5.4.44"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002528
Paul Kehrerc7ab9312016-11-12 05:00:42 -08002529 .. attribute:: X500_UNIQUE_IDENTIFIER
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002530
2531 .. versionadded:: 1.6
2532
2533 Corresponds to the dotted string ``"2.5.4.45"``.
2534
Paul Kehrere27f6582015-08-10 18:33:38 -05002535 .. attribute:: DN_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002536
Paul Kehrere27f6582015-08-10 18:33:38 -05002537 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
2538 disambiguating information to add to the relative distinguished name of an
2539 entry. See :rfc:`2256`.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002540
Paul Kehrere27f6582015-08-10 18:33:38 -05002541 .. attribute:: PSEUDONYM
Paul Kehrer858b9b72015-02-05 09:50:31 -06002542
Paul Kehrere27f6582015-08-10 18:33:38 -05002543 Corresponds to the dotted string ``"2.5.4.65"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002544
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002545 .. attribute:: USER_ID
2546
2547 .. versionadded:: 1.6
2548
2549 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.1"``.
2550
Paul Kehrere27f6582015-08-10 18:33:38 -05002551 .. attribute:: DOMAIN_COMPONENT
Paul Kehrer858b9b72015-02-05 09:50:31 -06002552
Paul Kehrere27f6582015-08-10 18:33:38 -05002553 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
2554 holding one component of a domain name. See :rfc:`4519`.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002555
Paul Kehrere27f6582015-08-10 18:33:38 -05002556 .. attribute:: EMAIL_ADDRESS
Paul Kehrer56da2a52015-02-11 23:35:07 -06002557
Paul Kehrere27f6582015-08-10 18:33:38 -05002558 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002559
Alex Gaynor1d3f2bf2015-12-19 12:15:09 -05002560 .. attribute:: JURISDICTION_COUNTRY_NAME
2561
2562 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.3"``.
2563
Alex Gaynor45e507f2015-12-19 13:44:23 -05002564 .. attribute:: JURISDICTION_LOCALITY_NAME
2565
2566 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.1"``.
2567
2568 .. attribute:: JURISDICTION_STATE_OR_PROVINCE_NAME
2569
2570 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.2"``.
2571
Alex Gaynora2293c82015-12-19 20:49:15 -05002572 .. attribute:: BUSINESS_CATEGORY
2573
2574 Corresponds to the dotted string ``"2.5.4.15"``.
2575
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002576 .. attribute:: POSTAL_ADDRESS
2577
2578 .. versionadded:: 1.6
2579
2580 Corresponds to the dotted string ``"2.5.4.16"``.
2581
2582 .. attribute:: POSTAL_CODE
2583
2584 .. versionadded:: 1.6
2585
2586 Corresponds to the dotted string ``"2.5.4.17"``.
2587
Paul Kehrer56da2a52015-02-11 23:35:07 -06002588
Paul Kehrere27f6582015-08-10 18:33:38 -05002589.. class:: SignatureAlgorithmOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002590
Paul Kehrere27f6582015-08-10 18:33:38 -05002591 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002592
Paul Kehrere27f6582015-08-10 18:33:38 -05002593 .. attribute:: RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06002594
Paul Kehrere27f6582015-08-10 18:33:38 -05002595 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
2596 an MD5 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002597
Paul Kehrere27f6582015-08-10 18:33:38 -05002598 .. attribute:: RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002599
Paul Kehrere27f6582015-08-10 18:33:38 -05002600 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
2601 a SHA1 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002602
Paul Kehrere27f6582015-08-10 18:33:38 -05002603 .. attribute:: RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002604
Paul Kehrere27f6582015-08-10 18:33:38 -05002605 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
2606 a SHA224 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002607
Paul Kehrere27f6582015-08-10 18:33:38 -05002608 .. attribute:: RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002609
Paul Kehrere27f6582015-08-10 18:33:38 -05002610 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
2611 a SHA256 digest signed by an RSA key.
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002612
Paul Kehrere27f6582015-08-10 18:33:38 -05002613 .. attribute:: RSA_WITH_SHA384
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002614
Paul Kehrere27f6582015-08-10 18:33:38 -05002615 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
2616 a SHA384 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002617
Paul Kehrere27f6582015-08-10 18:33:38 -05002618 .. attribute:: RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06002619
Paul Kehrere27f6582015-08-10 18:33:38 -05002620 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
2621 a SHA512 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002622
Marti Raudsepp33678062018-06-30 02:27:28 +03002623 .. attribute:: RSASSA_PSS
2624
2625 .. versionadded:: 2.3
2626
2627 Corresponds to the dotted string ``"1.2.840.113549.1.1.10"``. This is
2628 signed by an RSA key using the Probabilistic Signature Scheme (PSS)
2629 padding from RFC 4055. The hash function and padding are defined by
2630 signature algorithm parameters.
2631
Paul Kehrere27f6582015-08-10 18:33:38 -05002632 .. attribute:: ECDSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002633
Paul Kehrere27f6582015-08-10 18:33:38 -05002634 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
2635 digest signed by an ECDSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002636
Paul Kehrere27f6582015-08-10 18:33:38 -05002637 .. attribute:: ECDSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002638
Paul Kehrere27f6582015-08-10 18:33:38 -05002639 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
2640 a SHA224 digest signed by an ECDSA key.
2641
2642 .. attribute:: ECDSA_WITH_SHA256
2643
2644 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
2645 a SHA256 digest signed by an ECDSA key.
2646
2647 .. attribute:: ECDSA_WITH_SHA384
2648
2649 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
2650 a SHA384 digest signed by an ECDSA key.
2651
2652 .. attribute:: ECDSA_WITH_SHA512
2653
2654 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
2655 a SHA512 digest signed by an ECDSA key.
2656
2657 .. attribute:: DSA_WITH_SHA1
2658
2659 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
2660 a SHA1 digest signed by a DSA key.
2661
2662 .. attribute:: DSA_WITH_SHA224
2663
2664 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
2665 a SHA224 digest signed by a DSA key.
2666
2667 .. attribute:: DSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002668
Paul Kehrere27f6582015-08-10 18:33:38 -05002669 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
2670 a SHA256 digest signed by a DSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002671
Paul Kehrer56da2a52015-02-11 23:35:07 -06002672
Paul Kehrere27f6582015-08-10 18:33:38 -05002673.. class:: ExtendedKeyUsageOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002674
Paul Kehrere27f6582015-08-10 18:33:38 -05002675 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002676
Paul Kehrere27f6582015-08-10 18:33:38 -05002677 .. attribute:: SERVER_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002678
Paul Kehrere27f6582015-08-10 18:33:38 -05002679 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used
2680 to denote that a certificate may be used for TLS web server
2681 authentication.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002682
Paul Kehrere27f6582015-08-10 18:33:38 -05002683 .. attribute:: CLIENT_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002684
Paul Kehrere27f6582015-08-10 18:33:38 -05002685 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used
2686 to denote that a certificate may be used for TLS web client
2687 authentication.
Paul Kehrerffa2a152015-03-31 08:18:25 -05002688
Paul Kehrere27f6582015-08-10 18:33:38 -05002689 .. attribute:: CODE_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002690
Paul Kehrere27f6582015-08-10 18:33:38 -05002691 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used
2692 to denote that a certificate may be used for code signing.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002693
Paul Kehrere27f6582015-08-10 18:33:38 -05002694 .. attribute:: EMAIL_PROTECTION
Paul Kehrere1513fa2015-03-30 23:08:17 -05002695
Paul Kehrere27f6582015-08-10 18:33:38 -05002696 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used
2697 to denote that a certificate may be used for email protection.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002698
Paul Kehrere27f6582015-08-10 18:33:38 -05002699 .. attribute:: TIME_STAMPING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002700
Paul Kehrere27f6582015-08-10 18:33:38 -05002701 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used
2702 to denote that a certificate may be used for time stamping.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002703
Paul Kehrere27f6582015-08-10 18:33:38 -05002704 .. attribute:: OCSP_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002705
Paul Kehrere27f6582015-08-10 18:33:38 -05002706 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used
2707 to denote that a certificate may be used for signing OCSP responses.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002708
Alex Gaynorb7912ee2017-07-03 10:07:02 -04002709 .. attribute:: ANY_EXTENDED_KEY_USAGE
2710
2711 .. versionadded:: 2.0
2712
2713 Corresponds to the dotted string ``"2.5.29.37.0"``. This is used to
2714 denote that a certificate may be used for _any_ purposes.
2715
Paul Kehrere1513fa2015-03-30 23:08:17 -05002716
Paul Kehrere27f6582015-08-10 18:33:38 -05002717.. class:: AuthorityInformationAccessOID
Paul Kehrere1513fa2015-03-30 23:08:17 -05002718
Paul Kehrere27f6582015-08-10 18:33:38 -05002719 .. versionadded:: 1.0
Paul Kehrere1513fa2015-03-30 23:08:17 -05002720
Paul Kehrere27f6582015-08-10 18:33:38 -05002721 .. attribute:: OCSP
Paul Kehrere1513fa2015-03-30 23:08:17 -05002722
Paul Kehrere27f6582015-08-10 18:33:38 -05002723 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
2724 identifier for OCSP data in
2725 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002726
Paul Kehrere27f6582015-08-10 18:33:38 -05002727 .. attribute:: CA_ISSUERS
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002728
Paul Kehrere27f6582015-08-10 18:33:38 -05002729 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
2730 identifier for CA issuer data in
2731 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002732
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002733
Paul Kehrere27f6582015-08-10 18:33:38 -05002734.. class:: CertificatePoliciesOID
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002735
Paul Kehrere27f6582015-08-10 18:33:38 -05002736 .. versionadded:: 1.0
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002737
Paul Kehrere27f6582015-08-10 18:33:38 -05002738 .. attribute:: CPS_QUALIFIER
Paul Kehrer2e879742015-05-02 23:09:56 -05002739
Paul Kehrere27f6582015-08-10 18:33:38 -05002740 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002741
Paul Kehrere27f6582015-08-10 18:33:38 -05002742 .. attribute:: CPS_USER_NOTICE
Paul Kehrer2e879742015-05-02 23:09:56 -05002743
Paul Kehrere27f6582015-08-10 18:33:38 -05002744 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002745
Paul Kehrere27f6582015-08-10 18:33:38 -05002746 .. attribute:: ANY_POLICY
Paul Kehrer2e879742015-05-02 23:09:56 -05002747
Paul Kehrere27f6582015-08-10 18:33:38 -05002748 Corresponds to the dotted string ``"2.5.29.32.0"``.
Paul Kehrer16fae762015-05-01 23:14:20 -05002749
Paul Kehrer16fae762015-05-01 23:14:20 -05002750
Paul Kehrere27f6582015-08-10 18:33:38 -05002751.. class:: ExtensionOID
Paul Kehrer5553d572015-03-23 21:08:01 -05002752
Paul Kehrere27f6582015-08-10 18:33:38 -05002753 .. versionadded:: 1.0
Paul Kehrer2bb94642015-03-21 09:54:17 -05002754
Paul Kehrere27f6582015-08-10 18:33:38 -05002755 .. attribute:: BASIC_CONSTRAINTS
Paul Kehrer2bb94642015-03-21 09:54:17 -05002756
Paul Kehrere27f6582015-08-10 18:33:38 -05002757 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
2758 :class:`~cryptography.x509.BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05002759
Paul Kehrere27f6582015-08-10 18:33:38 -05002760 .. attribute:: KEY_USAGE
Paul Kehrercecbbba2015-03-30 14:58:38 -05002761
Paul Kehrere27f6582015-08-10 18:33:38 -05002762 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
2763 :class:`~cryptography.x509.KeyUsage` extension type.
Paul Kehrercecbbba2015-03-30 14:58:38 -05002764
Paul Kehrere27f6582015-08-10 18:33:38 -05002765 .. attribute:: SUBJECT_ALTERNATIVE_NAME
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002766
Paul Kehrere27f6582015-08-10 18:33:38 -05002767 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
2768 :class:`~cryptography.x509.SubjectAlternativeName` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002769
Paul Kehrere27f6582015-08-10 18:33:38 -05002770 .. attribute:: ISSUER_ALTERNATIVE_NAME
Paul Kehrer99125c92015-06-07 18:37:10 -05002771
Paul Kehrere27f6582015-08-10 18:33:38 -05002772 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
2773 :class:`~cryptography.x509.IssuerAlternativeName` extension type.
Paul Kehrer99125c92015-06-07 18:37:10 -05002774
Paul Kehrere27f6582015-08-10 18:33:38 -05002775 .. attribute:: SUBJECT_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002776
Paul Kehrere27f6582015-08-10 18:33:38 -05002777 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
2778 :class:`~cryptography.x509.SubjectKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002779
Paul Kehrere27f6582015-08-10 18:33:38 -05002780 .. attribute:: NAME_CONSTRAINTS
Paul Kehrere0017be2015-05-17 20:39:40 -06002781
Paul Kehrere27f6582015-08-10 18:33:38 -05002782 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
2783 :class:`~cryptography.x509.NameConstraints` extension type.
Paul Kehrere0017be2015-05-17 20:39:40 -06002784
Paul Kehrere27f6582015-08-10 18:33:38 -05002785 .. attribute:: CRL_DISTRIBUTION_POINTS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002786
Paul Kehrere27f6582015-08-10 18:33:38 -05002787 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
2788 :class:`~cryptography.x509.CRLDistributionPoints` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002789
Paul Kehrere27f6582015-08-10 18:33:38 -05002790 .. attribute:: CERTIFICATE_POLICIES
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002791
Paul Kehrere27f6582015-08-10 18:33:38 -05002792 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
2793 :class:`~cryptography.x509.CertificatePolicies` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002794
Paul Kehrere27f6582015-08-10 18:33:38 -05002795 .. attribute:: AUTHORITY_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002796
Paul Kehrere27f6582015-08-10 18:33:38 -05002797 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
2798 :class:`~cryptography.x509.AuthorityKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002799
Paul Kehrere27f6582015-08-10 18:33:38 -05002800 .. attribute:: EXTENDED_KEY_USAGE
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002801
Paul Kehrere27f6582015-08-10 18:33:38 -05002802 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
2803 :class:`~cryptography.x509.ExtendedKeyUsage` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002804
Paul Kehrere27f6582015-08-10 18:33:38 -05002805 .. attribute:: AUTHORITY_INFORMATION_ACCESS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002806
Paul Kehrere27f6582015-08-10 18:33:38 -05002807 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
2808 for the :class:`~cryptography.x509.AuthorityInformationAccess` extension
2809 type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002810
Paul Kehrere27f6582015-08-10 18:33:38 -05002811 .. attribute:: INHIBIT_ANY_POLICY
Paul Kehrerb33de932015-08-06 23:41:05 +01002812
Paul Kehrere27f6582015-08-10 18:33:38 -05002813 Corresponds to the dotted string ``"2.5.29.54"``. The identifier
2814 for the :class:`~cryptography.x509.InhibitAnyPolicy` extension type.
Paul Kehrerb33de932015-08-06 23:41:05 +01002815
Paul Kehrere27f6582015-08-10 18:33:38 -05002816 .. attribute:: OCSP_NO_CHECK
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002817
Paul Kehrere27f6582015-08-10 18:33:38 -05002818 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The
2819 identifier for the :class:`~cryptography.x509.OCSPNoCheck` extension
2820 type.
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002821
Paul Kehrer5d669662017-09-11 09:16:34 +08002822 .. attribute:: TLS_FEATURE
2823
2824 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.24"``. The
2825 identifier for the :class:`~cryptography.x509.TLSFeature` extension
2826 type.
2827
Paul Kehrer51f39cb2015-12-21 21:17:39 -06002828 .. attribute:: CRL_NUMBER
2829
2830 Corresponds to the dotted string ``"2.5.29.20"``. The identifier for
2831 the ``CRLNumber`` extension type. This extension only has meaning
2832 for certificate revocation lists.
2833
Paul Kehrer5e3cc982017-09-22 21:29:36 +08002834 .. attribute:: DELTA_CRL_INDICATOR
2835
2836 .. versionadded:: 2.1
2837
2838 Corresponds to the dotted string ``"2.5.29.27"``. The identifier for
2839 the ``DeltaCRLIndicator`` extension type. This extension only has
2840 meaning for certificate revocation lists.
2841
Alex Gaynor9bab0ed2017-03-20 09:50:52 -04002842 .. attribute:: PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS
2843
2844 .. versionadded:: 1.9
2845
2846 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.2"``.
2847
Alex Gaynordd6b78b2018-08-31 18:25:52 -05002848 .. attribute:: PRECERT_POISON
2849
2850 .. versionadded:: 2.4
2851
2852 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.3"``.
2853
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002854 .. attribute:: POLICY_CONSTRAINTS
2855
2856 Corresponds to the dotted string ``"2.5.29.36"``. The identifier for the
Paul Kehrer20f0df52016-02-26 08:37:13 -06002857 :class:`~cryptography.x509.PolicyConstraints` extension type.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002858
Paul Kehrerb76bcf82017-09-24 08:44:12 +08002859 .. attribute:: FRESHEST_CRL
2860
2861 Corresponds to the dotted string ``"2.5.29.46"``. The identifier for the
2862 :class:`~cryptography.x509.FreshestCRL` extension type.
2863
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002864
Paul Kehrerc6242dc2015-12-25 16:36:46 -06002865.. class:: CRLEntryExtensionOID
2866
2867 .. versionadded:: 1.2
2868
2869 .. attribute:: CERTIFICATE_ISSUER
2870
2871 Corresponds to the dotted string ``"2.5.29.29"``.
2872
2873 .. attribute:: CRL_REASON
2874
2875 Corresponds to the dotted string ``"2.5.29.21"``.
2876
2877 .. attribute:: INVALIDITY_DATE
2878
2879 Corresponds to the dotted string ``"2.5.29.24"``.
2880
Paul Kehrer09403102018-09-09 21:57:21 -05002881
2882.. class:: OCSPExtensionOID
2883
2884 .. versionadded:: 2.4
2885
2886 .. attribute:: NONCE
2887
2888 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.2"``.
2889
Paul Kehrer8b89bcc2016-09-03 11:31:43 -05002890Helper Functions
2891~~~~~~~~~~~~~~~~
2892.. currentmodule:: cryptography.x509
2893
2894.. function:: random_serial_number()
2895
2896 .. versionadded:: 1.6
2897
2898 Generates a random serial number suitable for use when constructing
2899 certificates.
2900
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002901Exceptions
2902~~~~~~~~~~
Paul Kehrere27f6582015-08-10 18:33:38 -05002903.. currentmodule:: cryptography.x509
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002904
Paul Kehrere76cd272014-12-14 19:00:51 -06002905.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10002906
2907 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10002908
Paul Kehrerd5cccf72014-12-15 17:20:33 -06002909 .. attribute:: parsed_version
2910
Paul Kehrerbbffc402014-12-17 13:33:55 -06002911 :type: int
2912
2913 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06002914
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05002915.. class:: DuplicateExtension
2916
2917 This is raised when more than one X.509 extension of the same type is
2918 found within a certificate.
2919
2920 .. attribute:: oid
2921
2922 :type: :class:`ObjectIdentifier`
2923
2924 Returns the OID.
2925
Paul Kehrerfa56a232015-03-17 13:14:03 -05002926.. class:: ExtensionNotFound
2927
2928 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
2929 an extension OID that is not present in the certificate.
2930
2931 .. attribute:: oid
2932
2933 :type: :class:`ObjectIdentifier`
2934
2935 Returns the OID.
2936
Paul Kehrer9089c912015-04-20 22:15:20 -05002937.. class:: UnsupportedGeneralNameType
2938
2939 This is raised when a certificate contains an unsupported general name
2940 type in an extension.
2941
Paul Kehrerbed07352015-04-21 08:31:10 -05002942 .. attribute:: type
2943
Paul Kehrer0a621bf2015-04-22 09:22:56 -05002944 :type: int
2945
2946 The integer value of the unsupported type. The complete list of
2947 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05002948
Paul Kehrer016e08a2014-11-26 09:41:18 -10002949
Paul Kehrerc7c9a432015-04-19 09:20:13 -05002950.. _`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 -05002951.. _`RFC 5280 section 4.2.1.6`: https://tools.ietf.org/html/rfc5280#section-4.2.1.6
Paul Kehrer8b89bcc2016-09-03 11:31:43 -05002952.. _`CABForum Guidelines`: https://cabforum.org/baseline-requirements-documents/