blob: 0fea6167592f76b7fbd7c6228809f509b5f1fa7b [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
123.. function:: load_der_x509_certificate(data, backend)
124
125 .. versionadded:: 0.7
126
Paul Kehrere76cd272014-12-14 19:00:51 -0600127 Deserialize a certificate from DER encoded data. DER is a binary format
Paul Kehrer92aac382014-12-15 16:25:28 -0600128 and is commonly found in files with the ``.cer`` extension (although file
129 extensions are not a guarantee of encoding type).
Paul Kehrer016e08a2014-11-26 09:41:18 -1000130
131 :param bytes data: The DER encoded certificate data.
132
133 :param backend: A backend supporting the
134 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
135 interface.
136
Paul Kehrere76cd272014-12-14 19:00:51 -0600137 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000138
Paul Kehrer016e08a2014-11-26 09:41:18 -1000139.. doctest::
140
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600141 >>> from cryptography import x509
Paul Kehrer016e08a2014-11-26 09:41:18 -1000142 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600143 >>> cert = x509.load_pem_x509_certificate(pem_data, default_backend())
Paul Kehrer016e08a2014-11-26 09:41:18 -1000144 >>> cert.serial
145 2
146
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
167.. function:: load_der_x509_crl(data, backend)
168
169 .. versionadded:: 1.1
170
171 Deserialize a certificate revocation list (CRL) from DER encoded data. DER
172 is a binary format.
173
174 :param bytes data: The DER encoded request data.
175
176 :param backend: A backend supporting the
177 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
178 interface.
179
180 :returns: An instance of
181 :class:`~cryptography.x509.CertificateRevocationList`.
182
183.. doctest::
184
185 >>> from cryptography import x509
186 >>> from cryptography.hazmat.backends import default_backend
187 >>> from cryptography.hazmat.primitives import hashes
188 >>> crl = x509.load_pem_x509_crl(pem_crl_data, default_backend())
189 >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
190 True
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
Paul Kehrer1effb6e2015-03-30 15:05:59 -0500213.. function:: load_der_x509_csr(data, backend)
214
215 .. versionadded:: 0.9
216
217 Deserialize a certificate signing request (CSR) from DER encoded data. DER
218 is a binary format and is not commonly used with CSRs.
219
220 :param bytes data: The DER encoded request data.
221
222 :param backend: A backend supporting the
223 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
224 interface.
225
226 :returns: An instance of
227 :class:`~cryptography.x509.CertificateSigningRequest`.
228
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600229.. doctest::
230
231 >>> from cryptography import x509
232 >>> from cryptography.hazmat.backends import default_backend
233 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500234 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
235 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600236 True
237
Paul Kehrere76cd272014-12-14 19:00:51 -0600238X.509 Certificate Object
239~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerb2de9482014-12-11 14:54:48 -0600240
Paul Kehrere76cd272014-12-14 19:00:51 -0600241.. class:: Certificate
Paul Kehrerb2de9482014-12-11 14:54:48 -0600242
243 .. versionadded:: 0.7
244
245 .. attribute:: version
246
Paul Kehrere76cd272014-12-14 19:00:51 -0600247 :type: :class:`~cryptography.x509.Version`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600248
Paul Kehrere76cd272014-12-14 19:00:51 -0600249 The certificate version as an enumeration. Version 3 certificates are
250 the latest version and also the only type you should see in practice.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600251
Alex Gaynor89c4dc82014-12-16 16:49:33 -0800252 :raises cryptography.x509.InvalidVersion: If the version in the
Alex Gaynor6d7ab4c2014-12-16 16:50:33 -0800253 certificate is not a known
254 :class:`X.509 version <cryptography.x509.Version>`.
Paul Kehrer92aac382014-12-15 16:25:28 -0600255
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600256 .. doctest::
257
258 >>> cert.version
259 <Version.v3: 2>
260
Paul Kehrerb2de9482014-12-11 14:54:48 -0600261 .. method:: fingerprint(algorithm)
262
263 :param algorithm: The
Paul Kehrer601278a2015-02-12 12:51:00 -0600264 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600265 that will be used to generate the fingerprint.
266
Erik Trauschke2dcce902015-05-14 16:12:24 -0700267 :return bytes: The fingerprint using the supplied hash algorithm, as
Paul Kehrerb2de9482014-12-11 14:54:48 -0600268 bytes.
269
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600270 .. doctest::
271
272 >>> from cryptography.hazmat.primitives import hashes
273 >>> cert.fingerprint(hashes.SHA256())
Paul Kehrer78a81502014-12-16 14:47:52 -0600274 '\x86\xd2\x187Gc\xfc\xe7}[+E9\x8d\xb4\x8f\x10\xe5S\xda\x18u\xbe}a\x03\x08[\xac\xa04?'
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600275
Paul Kehrerb2de9482014-12-11 14:54:48 -0600276 .. attribute:: serial
277
278 :type: int
279
280 The serial as a Python integer.
281
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600282 .. doctest::
283
284 >>> cert.serial
285 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 Kehrerfbb7ac82015-03-16 19:26:29 -0500357 .. attribute:: extensions
358
359 :type: :class:`Extensions`
360
361 The extensions encoded in the certificate.
362
363 :raises cryptography.x509.DuplicateExtension: If more than one
364 extension of the same type is found within the certificate.
365
Paul Kehrerd8fc0be2015-04-21 08:31:10 -0500366 :raises cryptography.x509.UnsupportedExtension: If the certificate
367 contains an extension that is not supported.
368
Paul Kehrerbed07352015-04-21 08:31:10 -0500369 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
370 contains a general name that is not supported.
371
Paul Kehrerb8968812015-05-15 09:01:34 -0700372 :raises UnicodeError: If an extension contains IDNA encoding that is
373 invalid or not compliant with IDNA 2008.
374
Paul Kehrerfa56a232015-03-17 13:14:03 -0500375 .. doctest::
376
377 >>> for ext in cert.extensions:
378 ... print(ext)
Paul Kehrerd774de92015-05-03 10:52:25 -0500379 <Extension(oid=<ObjectIdentifier(oid=2.5.29.35, name=authorityKeyIdentifier)>, critical=False, value=<AuthorityKeyIdentifier(key_identifier='\xe4}_\xd1\\\x95\x86\x08,\x05\xae\xbeu\xb6e\xa7\xd9]\xa8f', authority_cert_issuer=None, authority_cert_serial_number=None)>)>
Paul Kehrercbfb1012015-04-10 20:57:20 -0400380 <Extension(oid=<ObjectIdentifier(oid=2.5.29.14, name=subjectKeyIdentifier)>, critical=False, value=<SubjectKeyIdentifier(digest='X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9')>)>
Paul Kehrerb511ba82015-04-15 11:22:48 -0400381 <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 -0500382 <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 -0500383 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
384
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500385 .. attribute:: signature
386
387 .. versionadded:: 1.2
388
389 :type: bytes
390
391 The bytes of the certificate's signature.
392
Paul Kehrerd2898052015-11-03 22:00:41 +0900393 .. attribute:: tbs_certificate_bytes
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500394
395 .. versionadded:: 1.2
396
397 :type: bytes
398
399 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
400 and then signed by the private key of the certificate's issuer. This
401 data may be used to validate a signature, but use extreme caution as
402 certificate validation is a complex problem that involves much more
403 than just signature checks.
404
Andre Carona8aded62015-05-19 20:11:57 -0400405 .. method:: public_bytes(encoding)
406
Alex Gaynord0b376b2015-07-05 13:58:12 -0400407 .. versionadded:: 1.0
408
Andre Carona8aded62015-05-19 20:11:57 -0400409 :param encoding: The
410 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
411 that will be used to serialize the certificate.
412
413 :return bytes: The data that can be written to a file or sent
414 over the network to be verified by clients.
415
Erik Trauschke2dcce902015-05-14 16:12:24 -0700416X.509 CRL (Certificate Revocation List) Object
417~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
418
419.. class:: CertificateRevocationList
420
421 .. versionadded:: 1.0
422
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700423 A CertificateRevocationList is an object representing a list of revoked
424 certificates. The object is iterable and will yield the RevokedCertificate
425 objects stored in this CRL.
426
427 .. doctest::
Erik Trauschkeb14f7d12015-10-13 09:55:39 -0700428
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700429 >>> len(crl)
430 1
Paul Kehrerdcdf9672015-10-21 20:27:28 -0500431 >>> revoked_certificate = crl[0]
432 >>> type(revoked_certificate)
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700433 <class 'cryptography.hazmat.backends.openssl.x509._RevokedCertificate'>
434 >>> for r in crl:
435 ... print(r.serial_number)
436 0
437
Erik Trauschke2dcce902015-05-14 16:12:24 -0700438 .. method:: fingerprint(algorithm)
439
440 :param algorithm: The
441 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
442 that will be used to generate the fingerprint.
443
444 :return bytes: The fingerprint using the supplied hash algorithm, as
445 bytes.
446
Erik Trauschkedc570402015-09-24 20:24:28 -0700447 .. doctest::
448
449 >>> from cryptography.hazmat.primitives import hashes
450 >>> crl.fingerprint(hashes.SHA256())
451 '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'
452
Erik Trauschke2dcce902015-05-14 16:12:24 -0700453 .. attribute:: signature_hash_algorithm
454
455 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
456
457 Returns the
458 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
459 was used in signing this CRL.
460
Erik Trauschkedc570402015-09-24 20:24:28 -0700461 .. doctest::
462
463 >>> from cryptography.hazmat.primitives import hashes
464 >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
465 True
466
Erik Trauschke2dcce902015-05-14 16:12:24 -0700467 .. attribute:: issuer
468
469 :type: :class:`Name`
470
471 The :class:`Name` of the issuer.
472
Erik Trauschkedc570402015-09-24 20:24:28 -0700473 .. doctest::
474
475 >>> crl.issuer
476 <Name([<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>, <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'cryptography.io')>])>
477
Erik Trauschke2dcce902015-05-14 16:12:24 -0700478 .. attribute:: next_update
479
480 :type: :class:`datetime.datetime`
481
482 A naïve datetime representing when the next update to this CRL is
483 expected.
484
Erik Trauschkedc570402015-09-24 20:24:28 -0700485 .. doctest::
486
487 >>> crl.next_update
488 datetime.datetime(2016, 1, 1, 0, 0)
489
Erik Trauschke2dcce902015-05-14 16:12:24 -0700490 .. attribute:: last_update
491
492 :type: :class:`datetime.datetime`
493
494 A naïve datetime representing when the this CRL was last updated.
495
Erik Trauschkedc570402015-09-24 20:24:28 -0700496 .. doctest::
Erik Trauschke2dcce902015-05-14 16:12:24 -0700497
Erik Trauschkedc570402015-09-24 20:24:28 -0700498 >>> crl.last_update
499 datetime.datetime(2015, 1, 1, 0, 0)
Erik Trauschke2dcce902015-05-14 16:12:24 -0700500
501 .. attribute:: extensions
502
503 :type: :class:`Extensions`
504
505 The extensions encoded in the CRL.
506
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800507 .. attribute:: signature
508
509 .. versionadded:: 1.2
510
511 :type: bytes
512
513 The bytes of the CRL's signature.
514
515 .. attribute:: tbs_certlist_bytes
516
517 .. versionadded:: 1.2
518
519 :type: bytes
520
521 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
522 and then signed by the private key of the CRL's issuer. This data may be
523 used to validate a signature, but use extreme caution as CRL validation
524 is a complex problem that involves much more than just signature checks.
525
526
Andre Caron9bbfcea2015-05-18 20:55:29 -0400527X.509 Certificate Builder
528~~~~~~~~~~~~~~~~~~~~~~~~~
529
530.. class:: CertificateBuilder
531
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500532 .. versionadded:: 1.0
533
534 .. doctest::
535
536 >>> from cryptography import x509
537 >>> from cryptography.hazmat.backends import default_backend
538 >>> from cryptography.hazmat.primitives import hashes
539 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -0500540 >>> from cryptography.x509.oid import NameOID
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500541 >>> import datetime
542 >>> import uuid
543 >>> one_day = datetime.timedelta(1, 0, 0)
544 >>> private_key = rsa.generate_private_key(
545 ... public_exponent=65537,
546 ... key_size=2048,
547 ... backend=default_backend()
548 ... )
549 >>> public_key = rsa.generate_private_key(
550 ... public_exponent=65537,
551 ... key_size=2048,
552 ... backend=default_backend()
553 ... ).public_key()
554 >>> builder = x509.CertificateBuilder()
555 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500556 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500557 ... ]))
558 >>> builder = builder.issuer_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500559 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500560 ... ]))
561 >>> builder = builder.not_valid_before(datetime.datetime.today() - one_day)
562 >>> builder = builder.not_valid_after(datetime.datetime(2018, 8, 2))
563 >>> builder = builder.serial_number(int(uuid.uuid4()))
564 >>> builder = builder.public_key(public_key)
565 >>> builder = builder.add_extension(
566 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
567 ... )
568 >>> certificate = builder.sign(
569 ... private_key=private_key, algorithm=hashes.SHA256(),
570 ... backend=default_backend()
571 ... )
572 >>> isinstance(certificate, x509.Certificate)
573 True
574
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500575 .. method:: issuer_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400576
577 Sets the issuer's distinguished name.
578
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500579 :param name: The :class:`~cryptography.x509.Name` that describes the
580 issuer (CA).
Andre Caron9bbfcea2015-05-18 20:55:29 -0400581
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500582 .. method:: subject_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400583
584 Sets the subject's distinguished name.
585
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500586 :param name: The :class:`~cryptography.x509.Name` that describes the
Ian Cordasco85fc4d52015-08-01 20:29:31 -0500587 subject.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400588
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500589 .. method:: public_key(public_key)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400590
591 Sets the subject's public key.
592
Ian Cordasco8f571422015-08-02 11:31:08 -0500593 :param public_key: The subject's public key. This can be one of
594 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`,
595 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
596 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400597
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500598 .. method:: serial_number(serial_number)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400599
600 Sets the certificate's serial number (an integer). The CA's policy
601 determines how it attributes serial numbers to certificates. The only
602 requirement is that this number uniquely identify the certificate given
603 the issuer.
604
605 :param serial_number: Integer number that will be used by the CA to
606 identify this certificate (most notably during certificate
Ian Cordasco17c89002015-08-02 21:13:59 -0500607 revocation checking). Users are encouraged to use a method of
608 generating 20 bytes of entropy, e.g., UUID4. For more information
Ian Cordascob7530a42015-08-02 22:47:06 -0500609 on secure random number generation, see :doc:`/random-numbers`.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400610
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500611 .. method:: not_valid_before(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400612
613 Sets the certificate's activation time. This is the time from which
614 clients can start trusting the certificate. It may be different from
615 the time at which the certificate was created.
616
Ian Cordasco17c89002015-08-02 21:13:59 -0500617 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400618 activation time for the certificate. The certificate may not be
619 trusted clients if it is used before this time.
620
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500621 .. method:: not_valid_after(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400622
623 Sets the certificate's expiration time. This is the time from which
624 clients should no longer trust the certificate. The CA's policy will
625 determine how long the certificate should remain in use.
626
Ian Cordasco17c89002015-08-02 21:13:59 -0500627 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400628 expiration time for the certificate. The certificate may not be
629 trusted clients if it is used after this time.
630
Ian Cordasco17c89002015-08-02 21:13:59 -0500631 .. method:: add_extension(extension, critical)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400632
633 Adds an X.509 extension to the certificate.
634
Paul Kehrer2c145cc2015-10-02 11:27:21 -0500635 :param extension: An extension conforming to the
636 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400637
Ian Cordasco17c89002015-08-02 21:13:59 -0500638 :param critical: Set to ``True`` if the extension must be understood and
639 handled by whoever reads the certificate.
640
Paul Kehrer9add80e2015-08-03 17:53:14 +0100641 .. method:: sign(private_key, algorithm, backend)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400642
643 Sign the certificate using the CA's private key.
644
Ian Cordascoc5e1c252015-07-31 23:33:35 -0500645 :param private_key: The
646 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
647 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
648 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
649 that will be used to sign the certificate.
650
Andre Caron9bbfcea2015-05-18 20:55:29 -0400651 :param algorithm: The
652 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
653 will be used to generate the signature.
654
Paul Kehrer9add80e2015-08-03 17:53:14 +0100655 :param backend: Backend that will be used to build the certificate.
656 Must support the
657 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
658 interface.
659
Benjamin Peterson9ed312b2015-10-12 20:51:34 -0700660 :returns: :class:`~cryptography.x509.Certificate`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400661
662
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500663X.509 CSR (Certificate Signing Request) Object
664~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600665
Paul Kehrera1a1f232015-03-15 15:34:35 -0500666.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600667
668 .. versionadded:: 0.9
669
670 .. method:: public_key()
671
Alex Gaynor4c2561a2015-10-12 23:53:39 -0400672 The public key associated with the request.
673
674 :returns:
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600675 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
676 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
677 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
678
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600679 .. doctest::
680
681 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500682 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600683 >>> isinstance(public_key, rsa.RSAPublicKey)
684 True
685
686 .. attribute:: subject
687
688 :type: :class:`Name`
689
690 The :class:`Name` of the subject.
691
692 .. attribute:: signature_hash_algorithm
693
694 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
695
696 Returns the
697 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
698 was used in signing this request.
699
700 .. doctest::
701
702 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500703 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600704 True
705
Paul Kehrerc4e61942015-08-01 21:21:13 +0100706 .. attribute:: extensions
707
708 :type: :class:`Extensions`
709
710 The extensions encoded in the certificate signing request.
711
712 :raises cryptography.x509.DuplicateExtension: If more than one
Paul Kehrer24283d22015-08-01 21:31:19 +0100713 extension of the same type is found within the certificate signing request.
Paul Kehrerc4e61942015-08-01 21:21:13 +0100714
Paul Kehrer24283d22015-08-01 21:31:19 +0100715 :raises cryptography.x509.UnsupportedExtension: If the certificate signing request
Paul Kehrerc4e61942015-08-01 21:21:13 +0100716 contains an extension that is not supported.
717
718 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
719 contains a general name that is not supported.
720
721 :raises UnicodeError: If an extension contains IDNA encoding that is
722 invalid or not compliant with IDNA 2008.
723
724
Andre Caron476c5df2015-05-18 10:23:28 -0400725 .. method:: public_bytes(encoding)
726
Alex Gaynord0b376b2015-07-05 13:58:12 -0400727 .. versionadded:: 1.0
728
Andre Caron476c5df2015-05-18 10:23:28 -0400729 :param encoding: The
730 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
731 that will be used to serialize the certificate request.
732
733 :return bytes: The data that can be written to a file or sent
734 over the network to be signed by the certificate
735 authority.
736
Paul Kehrerab209392015-12-01 14:50:31 -0600737 .. attribute:: signature
738
739 .. versionadded:: 1.2
740
741 :type: bytes
742
743 The bytes of the certificate signing request's signature.
744
745 .. attribute:: tbs_certrequest_bytes
746
747 .. versionadded:: 1.2
748
749 :type: bytes
750
751 The DER encoded bytes payload (as defined by :rfc:`2986`) that is
752 hashed and then signed by the private key (corresponding to the public
753 key embedded in the CSR). This data may be used to validate the CSR
754 signature.
755
Erik Trauschke2dcce902015-05-14 16:12:24 -0700756X.509 Revoked Certificate Object
Erik Trauschkec5a8d172015-05-28 10:24:25 -0700757~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Erik Trauschke2dcce902015-05-14 16:12:24 -0700758
759.. class:: RevokedCertificate
760
761 .. versionadded:: 1.0
762
763 .. attribute:: serial_number
764
765 :type: :class:`int`
766
767 An integer representing the serial number of the revoked certificate.
768
Erik Trauschkedc570402015-09-24 20:24:28 -0700769 .. doctest::
770
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700771 >>> revoked_certificate.serial_number
Erik Trauschkedc570402015-09-24 20:24:28 -0700772 0
773
Erik Trauschke2dcce902015-05-14 16:12:24 -0700774 .. attribute:: revocation_date
775
776 :type: :class:`datetime.datetime`
777
778 A naïve datetime representing the date this certificates was revoked.
779
Erik Trauschkedc570402015-09-24 20:24:28 -0700780 .. doctest::
781
Erik Trauschke77f5a252015-10-14 08:06:38 -0700782 >>> revoked_certificate.revocation_date
Erik Trauschkedc570402015-09-24 20:24:28 -0700783 datetime.datetime(2015, 1, 1, 0, 0)
784
Erik Trauschke2dcce902015-05-14 16:12:24 -0700785 .. attribute:: extensions
786
787 :type: :class:`Extensions`
788
789 The extensions encoded in the revoked certificate.
Andre Caron476c5df2015-05-18 10:23:28 -0400790
Erik Trauschkedc570402015-09-24 20:24:28 -0700791 .. doctest::
792
Erik Trauschke77f5a252015-10-14 08:06:38 -0700793 >>> for ext in revoked_certificate.extensions:
Erik Trauschkedc570402015-09-24 20:24:28 -0700794 ... print(ext)
795 <Extension(oid=<ObjectIdentifier(oid=2.5.29.24, name=invalidityDate)>, critical=False, value=2015-01-01 00:00:00)>
796 <Extension(oid=<ObjectIdentifier(oid=2.5.29.21, name=cRLReason)>, critical=False, value=ReasonFlags.key_compromise)>
797
Andre Caron0ef595f2015-05-18 13:53:43 -0400798X.509 CSR (Certificate Signing Request) Builder Object
799~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
800
801.. class:: CertificateSigningRequestBuilder
802
Andre Carond259ee52015-06-02 23:47:11 -0400803 .. versionadded:: 1.0
804
805 .. doctest::
806
807 >>> from cryptography import x509
808 >>> from cryptography.hazmat.backends import default_backend
809 >>> from cryptography.hazmat.primitives import hashes
810 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -0500811 >>> from cryptography.x509.oid import NameOID
Andre Carond259ee52015-06-02 23:47:11 -0400812 >>> private_key = rsa.generate_private_key(
813 ... public_exponent=65537,
814 ... key_size=2048,
815 ... backend=default_backend()
816 ... )
817 >>> builder = x509.CertificateSigningRequestBuilder()
Andre Carona9a51172015-06-06 20:18:44 -0400818 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500819 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Andre Carond259ee52015-06-02 23:47:11 -0400820 ... ]))
Ian Cordascof06b6be2015-06-21 10:09:18 -0500821 >>> builder = builder.add_extension(
Ian Cordasco0112b022015-06-16 17:51:18 -0500822 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
Andre Caron472fd692015-06-06 20:04:44 -0400823 ... )
Andre Carond259ee52015-06-02 23:47:11 -0400824 >>> request = builder.sign(
Alex Gaynorde9e5842015-06-26 20:11:23 -0400825 ... private_key, hashes.SHA256(), default_backend()
Andre Carond259ee52015-06-02 23:47:11 -0400826 ... )
827 >>> isinstance(request, x509.CertificateSigningRequest)
828 True
829
Andre Carona9a51172015-06-06 20:18:44 -0400830 .. method:: subject_name(name)
Andre Caron0ef595f2015-05-18 13:53:43 -0400831
Andre Caron341ff852015-06-06 20:14:31 -0400832 :param name: The :class:`~cryptography.x509.Name` of the certificate
833 subject.
834 :returns: A new
835 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400836
Ian Cordascof06b6be2015-06-21 10:09:18 -0500837 .. method:: add_extension(extension, critical)
Andre Caron0ef595f2015-05-18 13:53:43 -0400838
Paul Kehrer2c145cc2015-10-02 11:27:21 -0500839 :param extension: An extension conforming to the
840 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron472fd692015-06-06 20:04:44 -0400841 :param critical: Set to `True` if the extension must be understood and
842 handled by whoever reads the certificate.
Andre Caron341ff852015-06-06 20:14:31 -0400843 :returns: A new
844 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400845
Alex Gaynorb3b0fbe2015-06-26 19:57:18 -0400846 .. method:: sign(private_key, algorithm, backend)
Andre Caron0ef595f2015-05-18 13:53:43 -0400847
848 :param backend: Backend that will be used to sign the request.
849 Must support the
850 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
851 interface.
852
853 :param private_key: The
Andre Caron24f9bf42015-06-06 20:14:54 -0400854 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
855 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
856 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
Andre Caron0ef595f2015-05-18 13:53:43 -0400857 that will be used to sign the request. When the request is
858 signed by a certificate authority, the private key's associated
859 public key will be stored in the resulting certificate.
860
861 :param algorithm: The
862 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
863 that will be used to generate the request signature.
864
Andre Caron341ff852015-06-06 20:14:31 -0400865 :returns: A new
866 :class:`~cryptography.x509.CertificateSigningRequest`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400867
868
Paul Kehrer719d5362015-01-01 20:03:52 -0600869.. class:: Name
870
871 .. versionadded:: 0.8
872
Paul Kehrer53d8d492015-02-13 18:47:30 -0600873 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -0600874 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -0600875 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -0600876 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
877 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -0600878
Paul Kehrer53d8d492015-02-13 18:47:30 -0600879 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -0600880
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600881 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -0600882 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600883 >>> for attribute in cert.subject:
884 ... print(attribute)
885 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
886 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')>
887 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -0600888
Paul Kehrere901d642015-02-11 18:50:58 -0600889 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -0600890
Paul Kehrere901d642015-02-11 18:50:58 -0600891 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -0600892
Paul Kehrere901d642015-02-11 18:50:58 -0600893 :returns: A list of :class:`NameAttribute` instances that match the
894 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -0600895
896 .. doctest::
897
Paul Kehrere27f6582015-08-10 18:33:38 -0500898 >>> cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)
Paul Kehrere901d642015-02-11 18:50:58 -0600899 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -0600900
Paul Kehrere76cd272014-12-14 19:00:51 -0600901.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -1000902
903 .. versionadded:: 0.7
904
905 An enumeration for X.509 versions.
906
907 .. attribute:: v1
908
909 For version 1 X.509 certificates.
910
911 .. attribute:: v3
912
913 For version 3 X.509 certificates.
914
Paul Kehrer806bfb22015-02-02 17:05:24 -0600915.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600916
917 .. versionadded:: 0.8
918
Paul Kehrer834d22f2015-02-06 11:01:07 -0600919 An X.509 name consists of a list of NameAttribute instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600920
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600921 .. attribute:: oid
922
923 :type: :class:`ObjectIdentifier`
924
925 The attribute OID.
926
927 .. attribute:: value
928
Paul Kehrerd5852cb2015-01-30 08:25:23 -0600929 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600930
931 The value of the attribute.
932
933.. class:: ObjectIdentifier
934
935 .. versionadded:: 0.8
936
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600937 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -0600938 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600939
Paul Kehrerd44f9a62015-02-04 14:47:34 -0600940 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600941
942 :type: :class:`str`
943
Paul Kehrerfedf4f42015-02-06 11:22:07 -0600944 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600945
Paul Kehrer31bdf792015-03-25 14:11:00 -0500946.. _general_name_classes:
947
948General Name Classes
949~~~~~~~~~~~~~~~~~~~~
950
951.. class:: GeneralName
952
953 .. versionadded:: 0.9
954
955 This is the generic interface that all the following classes are registered
956 against.
957
Paul Kehrer47c32ba2015-10-28 09:12:07 +0900958.. class:: RFC822Name(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -0500959
960 .. versionadded:: 0.9
961
962 This corresponds to an email address. For example, ``user@example.com``.
963
964 .. attribute:: value
965
966 :type: :term:`text`
967
Paul Kehrer47c32ba2015-10-28 09:12:07 +0900968.. class:: DNSName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -0500969
970 .. versionadded:: 0.9
971
972 This corresponds to a domain name. For example, ``cryptography.io``.
973
974 .. attribute:: value
975
976 :type: :term:`text`
977
Paul Kehrer47c32ba2015-10-28 09:12:07 +0900978.. class:: DirectoryName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -0500979
980 .. versionadded:: 0.9
981
982 This corresponds to a directory name.
983
984 .. attribute:: value
985
986 :type: :class:`Name`
987
Paul Kehrer47c32ba2015-10-28 09:12:07 +0900988.. class:: UniformResourceIdentifier(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -0500989
990 .. versionadded:: 0.9
991
992 This corresponds to a uniform resource identifier. For example,
Paul Kehrerb8ef82e2015-04-22 16:04:24 -0500993 ``https://cryptography.io``. The URI is parsed and IDNA decoded (see
994 :rfc:`5895`).
995
996 .. note::
997
998 URIs that do not contain ``://`` in them will not be decoded.
Paul Kehrer31bdf792015-03-25 14:11:00 -0500999
1000 .. attribute:: value
1001
1002 :type: :term:`text`
1003
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001004.. class:: IPAddress(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001005
1006 .. versionadded:: 0.9
1007
1008 This corresponds to an IP address.
1009
1010 .. attribute:: value
1011
Paul Kehrereb177932015-05-17 18:33:33 -07001012 :type: :class:`~ipaddress.IPv4Address`,
1013 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
1014 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001015
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001016.. class:: RegisteredID(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001017
1018 .. versionadded:: 0.9
1019
1020 This corresponds to a registered ID.
1021
1022 .. attribute:: value
1023
1024 :type: :class:`ObjectIdentifier`
1025
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001026.. class:: OtherName(type_id, value)
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001027
1028 .. versionadded:: 1.0
1029
Joshua Tauberer18b6fc82015-07-05 21:44:51 +00001030 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 +00001031
1032 .. attribute:: type_id
1033
1034 :type: :class:`ObjectIdentifier`
1035
1036 .. attribute:: value
1037
1038 :type: `bytes`
1039
Paul Kehrer8cf26422015-03-21 09:50:24 -05001040X.509 Extensions
1041~~~~~~~~~~~~~~~~
1042
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001043.. class:: Extensions
1044
1045 .. versionadded:: 0.9
1046
1047 An X.509 Extensions instance is an ordered list of extensions. The object
1048 is iterable to get every extension.
1049
Paul Kehrerfa56a232015-03-17 13:14:03 -05001050 .. method:: get_extension_for_oid(oid)
1051
1052 :param oid: An :class:`ObjectIdentifier` instance.
1053
1054 :returns: An instance of the extension class.
1055
1056 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1057 not have the extension requested.
1058
Paul Kehrerfa56a232015-03-17 13:14:03 -05001059 .. doctest::
1060
Paul Kehrere27f6582015-08-10 18:33:38 -05001061 >>> from cryptography.x509.oid import ExtensionOID
1062 >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS)
Paul Kehrerfa56a232015-03-17 13:14:03 -05001063 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1064
Phoebe Queen019b7f82015-08-12 03:52:03 +01001065 .. method:: get_extension_for_class(extclass)
1066
Phoebe Queen6a603eb2015-08-12 14:14:49 +01001067 .. versionadded:: 1.1
1068
Phoebe Queen019b7f82015-08-12 03:52:03 +01001069 :param extclass: An extension class.
1070
1071 :returns: An instance of the extension class.
1072
1073 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1074 not have the extension requested.
1075
1076 .. doctest::
1077
1078 >>> from cryptography import x509
1079 >>> cert.extensions.get_extension_for_class(x509.BasicConstraints)
1080 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1081
Paul Kehrer8cf26422015-03-21 09:50:24 -05001082.. class:: Extension
1083
1084 .. versionadded:: 0.9
1085
Paul Kehrer85894662015-03-22 13:19:31 -05001086 .. attribute:: oid
1087
1088 :type: :class:`ObjectIdentifier`
1089
Paul Kehrere27f6582015-08-10 18:33:38 -05001090 One of the :class:`~cryptography.x509.oid.ExtensionOID` OIDs.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001091
1092 .. attribute:: critical
1093
1094 :type: bool
1095
Paul Kehrer58b75692015-03-22 23:24:58 -05001096 Determines whether a given extension is critical or not. :rfc:`5280`
1097 requires that "A certificate-using system MUST reject the certificate
1098 if it encounters a critical extension it does not recognize or a
1099 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -05001100
Paul Kehrer85894662015-03-22 13:19:31 -05001101 .. attribute:: value
1102
1103 Returns an instance of the extension type corresponding to the OID.
1104
Paul Kehrer14f0bd02015-08-06 11:55:18 +01001105.. class:: ExtensionType
1106
1107 .. versionadded:: 1.0
1108
1109 This is the interface against which all the following extension types are
1110 registered.
1111
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001112.. 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 -05001113
1114 .. versionadded:: 0.9
1115
1116 The key usage extension defines the purpose of the key contained in the
1117 certificate. The usage restriction might be employed when a key that could
Paul Kehrerb33de932015-08-06 23:41:05 +01001118 be used for more than one operation is to be restricted.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001119
Paul Kehrer822f3d32015-08-06 11:47:32 +01001120 .. attribute:: oid
1121
1122 .. versionadded:: 1.0
1123
1124 :type: :class:`ObjectIdentifier`
1125
Paul Kehrere27f6582015-08-10 18:33:38 -05001126 Returns :attr:`~cryptography.x509.oid.ExtensionOID.KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001127
Paul Kehrercecbbba2015-03-30 14:58:38 -05001128 .. attribute:: digital_signature
1129
1130 :type: bool
1131
Paul Kehrer738407b2015-04-01 22:39:02 -05001132 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001133 digital signatures, other than signatures on certificates
1134 (``key_cert_sign``) and CRLs (``crl_sign``).
1135
1136 .. attribute:: content_commitment
1137
1138 :type: bool
1139
Paul Kehrer738407b2015-04-01 22:39:02 -05001140 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001141 digital signatures, other than signatures on certificates
1142 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
1143 non-repudiation service that protects against the signing entity
1144 falsely denying some action. In the case of later conflict, a
1145 reliable third party may determine the authenticity of the signed
1146 data. This was called ``non_repudiation`` in older revisions of the
1147 X.509 specification.
1148
1149 .. attribute:: key_encipherment
1150
1151 :type: bool
1152
Paul Kehrer738407b2015-04-01 22:39:02 -05001153 This purpose is set to true when the subject public key is used for
1154 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001155
1156 .. attribute:: data_encipherment
1157
1158 :type: bool
1159
Paul Kehrer738407b2015-04-01 22:39:02 -05001160 This purpose is set to true when the subject public key is used for
1161 directly enciphering raw user data without the use of an intermediate
1162 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001163
1164 .. attribute:: key_agreement
1165
1166 :type: bool
1167
Paul Kehrer738407b2015-04-01 22:39:02 -05001168 This purpose is set to true when the subject public key is used for key
1169 agreement. For example, when a Diffie-Hellman key is to be used for
1170 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001171
1172 .. attribute:: key_cert_sign
1173
1174 :type: bool
1175
Paul Kehrer738407b2015-04-01 22:39:02 -05001176 This purpose is set to true when the subject public key is used for
1177 verifying signatures on public key certificates. If this purpose is set
1178 to true then ``ca`` must be true in the :class:`BasicConstraints`
1179 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001180
1181 .. attribute:: crl_sign
1182
1183 :type: bool
1184
Paul Kehrer738407b2015-04-01 22:39:02 -05001185 This purpose is set to true when the subject public key is used for
1186 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001187
1188 .. attribute:: encipher_only
1189
1190 :type: bool
1191
Paul Kehrer738407b2015-04-01 22:39:02 -05001192 When this purposes is set to true and the ``key_agreement`` purpose is
1193 also set, the subject public key may be used only for enciphering data
1194 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001195
1196 :raises ValueError: This is raised if accessed when ``key_agreement``
1197 is false.
1198
1199 .. attribute:: decipher_only
1200
1201 :type: bool
1202
Paul Kehrer738407b2015-04-01 22:39:02 -05001203 When this purposes is set to true and the ``key_agreement`` purpose is
1204 also set, the subject public key may be used only for deciphering data
1205 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001206
1207 :raises ValueError: This is raised if accessed when ``key_agreement``
1208 is false.
1209
1210
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001211.. class:: BasicConstraints(ca, path_length)
Paul Kehrer8cf26422015-03-21 09:50:24 -05001212
1213 .. versionadded:: 0.9
1214
Paul Kehrer85894662015-03-22 13:19:31 -05001215 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -05001216 certificate is allowed to sign additional certificates and what path
Paul Kehrerb33de932015-08-06 23:41:05 +01001217 length restrictions may exist.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001218
Paul Kehrer822f3d32015-08-06 11:47:32 +01001219 .. attribute:: oid
1220
1221 .. versionadded:: 1.0
1222
1223 :type: :class:`ObjectIdentifier`
1224
Paul Kehrere27f6582015-08-10 18:33:38 -05001225 Returns :attr:`~cryptography.x509.oid.ExtensionOID.BASIC_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001226
Paul Kehrer8cf26422015-03-21 09:50:24 -05001227 .. attribute:: ca
1228
1229 :type: bool
1230
1231 Whether the certificate can sign certificates.
1232
1233 .. attribute:: path_length
1234
Paul Kehrerfd1444c2015-03-21 19:47:05 -05001235 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -05001236
1237 The maximum path length for certificates subordinate to this
1238 certificate. This attribute only has meaning if ``ca`` is true.
1239 If ``ca`` is true then a path length of None means there's no
1240 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -04001241 If it is zero or greater then it defines the maximum length for a
1242 subordinate CA's certificate chain. For example, a ``path_length`` of 1
1243 means the certificate can sign a subordinate CA, but the subordinate CA
1244 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001245
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001246.. class:: ExtendedKeyUsage(usages)
Paul Kehrerffa2a152015-03-31 08:18:25 -05001247
1248 .. versionadded:: 0.9
1249
1250 This extension indicates one or more purposes for which the certified
1251 public key may be used, in addition to or in place of the basic
1252 purposes indicated in the key usage extension. The object is
Paul Kehrere27f6582015-08-10 18:33:38 -05001253 iterable to obtain the list of
1254 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs present.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001255
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001256 :param list usages: A list of
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001257 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs.
1258
Paul Kehrer822f3d32015-08-06 11:47:32 +01001259 .. attribute:: oid
1260
1261 .. versionadded:: 1.0
1262
1263 :type: :class:`ObjectIdentifier`
1264
Paul Kehrere27f6582015-08-10 18:33:38 -05001265 Returns :attr:`~cryptography.x509.oid.ExtensionOID.EXTENDED_KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001266
1267
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001268.. class:: OCSPNoCheck()
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001269
Paul Kehrer506a2152015-05-26 08:01:18 -05001270 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001271
1272 This presence of this extension indicates that an OCSP client can trust a
1273 responder for the lifetime of the responder's certificate. CAs issuing
1274 such a certificate should realize that a compromise of the responder's key
1275 is as serious as the compromise of a CA key used to sign CRLs, at least for
1276 the validity period of this certificate. CA's may choose to issue this type
1277 of certificate with a very short lifetime and renew it frequently. This
1278 extension is only relevant when the certificate is an authorized OCSP
1279 responder.
1280
Paul Kehrer822f3d32015-08-06 11:47:32 +01001281 .. attribute:: oid
1282
1283 .. versionadded:: 1.0
1284
1285 :type: :class:`ObjectIdentifier`
1286
Paul Kehrere27f6582015-08-10 18:33:38 -05001287 Returns :attr:`~cryptography.x509.oid.ExtensionOID.OCSP_NO_CHECK`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001288
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001289.. class:: NameConstraints(permitted_subtrees, excluded_subtrees)
Paul Kehrere0017be2015-05-17 20:39:40 -06001290
1291 .. versionadded:: 1.0
1292
1293 The name constraints extension, which only has meaning in a CA certificate,
1294 defines a name space within which all subject names in certificates issued
1295 beneath the CA certificate must (or must not) be in. For specific details
1296 on the way this extension should be processed see :rfc:`5280`.
1297
Paul Kehrer822f3d32015-08-06 11:47:32 +01001298 .. attribute:: oid
1299
1300 .. versionadded:: 1.0
1301
1302 :type: :class:`ObjectIdentifier`
1303
Paul Kehrere27f6582015-08-10 18:33:38 -05001304 Returns :attr:`~cryptography.x509.oid.ExtensionOID.NAME_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001305
Paul Kehrere0017be2015-05-17 20:39:40 -06001306 .. attribute:: permitted_subtrees
1307
1308 :type: list of :class:`GeneralName` objects or None
1309
1310 The set of permitted name patterns. If a name matches this and an
1311 element in ``excluded_subtrees`` it is invalid. At least one of
1312 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
1313
1314 .. attribute:: excluded_subtrees
1315
1316 :type: list of :class:`GeneralName` objects or None
1317
1318 Any name matching a restriction in the ``excluded_subtrees`` field is
1319 invalid regardless of information appearing in the
1320 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
1321 ``excluded_subtrees`` will be non-None.
1322
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001323.. class:: AuthorityKeyIdentifier(key_identifier, authority_cert_issuer, authority_cert_serial_number)
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001324
1325 .. versionadded:: 0.9
1326
1327 The authority key identifier extension provides a means of identifying the
1328 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001329 This extension is typically used to assist in determining the appropriate
1330 certificate chain. For more information about generation and use of this
1331 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001332
Paul Kehrer822f3d32015-08-06 11:47:32 +01001333 .. attribute:: oid
1334
1335 .. versionadded:: 1.0
1336
1337 :type: :class:`ObjectIdentifier`
1338
Paul Kehrere27f6582015-08-10 18:33:38 -05001339 Returns
1340 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001341
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001342 .. attribute:: key_identifier
1343
1344 :type: bytes
1345
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001346 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001347 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001348
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001349 .. attribute:: authority_cert_issuer
1350
1351 :type: :class:`Name` or None
1352
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001353 The :class:`Name` of the issuer's issuer.
1354
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001355 .. attribute:: authority_cert_serial_number
1356
1357 :type: int or None
1358
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001359 The serial number of the issuer's issuer.
1360
Paul Kehrer253929a2015-08-05 17:30:39 +01001361 .. classmethod:: from_issuer_public_key(public_key)
1362
1363 .. versionadded:: 1.0
1364
1365 Creates a new AuthorityKeyIdentifier instance using the public key
1366 provided to generate the appropriate digest. This should be the
Paul Kehrer26ac47f2015-08-08 15:20:52 -05001367 **issuer's public key**. The resulting object will contain
1368 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1369 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1370 and
1371 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1372 will be None.
1373 The generated ``key_identifier`` is the SHA1 hash of the ``subjectPublicKey``
1374 ASN.1 bit string. This is the first recommendation in :rfc:`5280`
Paul Kehrer253929a2015-08-05 17:30:39 +01001375 section 4.2.1.2.
1376
Paul Kehrercc671822015-08-08 15:41:54 -05001377 :param public_key: One of
1378 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1379 ,
1380 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1381 , or
1382 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
Paul Kehrer253929a2015-08-05 17:30:39 +01001383
1384 .. doctest::
1385
1386 >>> from cryptography import x509
1387 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001388 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1389 >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key())
Paul Kehrer253929a2015-08-05 17:30:39 +01001390 <AuthorityKeyIdentifier(key_identifier='X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9', authority_cert_issuer=None, authority_cert_serial_number=None)>
1391
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001392.. class:: SubjectKeyIdentifier(digest)
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001393
1394 .. versionadded:: 0.9
1395
1396 The subject key identifier extension provides a means of identifying
1397 certificates that contain a particular public key.
1398
Paul Kehrer822f3d32015-08-06 11:47:32 +01001399 .. attribute:: oid
1400
1401 .. versionadded:: 1.0
1402
1403 :type: :class:`ObjectIdentifier`
1404
Paul Kehrere27f6582015-08-10 18:33:38 -05001405 Returns
1406 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001407
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001408 .. attribute:: digest
1409
1410 :type: bytes
1411
1412 The binary value of the identifier.
1413
Paul Kehrerd4a7f062015-08-05 18:32:18 +01001414 .. classmethod:: from_public_key(public_key)
Paul Kehrerf22f6122015-08-05 12:57:13 +01001415
1416 .. versionadded:: 1.0
1417
1418 Creates a new SubjectKeyIdentifier instance using the public key
1419 provided to generate the appropriate digest. This should be the public
Paul Kehrereb9ec002015-08-08 10:03:02 -05001420 key that is in the certificate. The generated digest is the SHA1 hash
1421 of the ``subjectPublicKey`` ASN.1 bit string. This is the first
1422 recommendation in :rfc:`5280` section 4.2.1.2.
Paul Kehrerf22f6122015-08-05 12:57:13 +01001423
1424 :param public_key: One of
1425 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1426 ,
1427 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1428 , or
1429 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
1430
Paul Kehrer253929a2015-08-05 17:30:39 +01001431 .. doctest::
1432
1433 >>> from cryptography import x509
1434 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001435 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
1436 >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key())
1437 <SubjectKeyIdentifier(digest='\xdb\xaa\xf0\x06\x11\xdbD\xfe\xbf\x93\x03\x8av\x88WP7\xa6\x91\xf7')>
Paul Kehrer253929a2015-08-05 17:30:39 +01001438
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001439.. class:: SubjectAlternativeName(general_names)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001440
1441 .. versionadded:: 0.9
1442
1443 Subject alternative name is an X.509 extension that provides a list of
1444 :ref:`general name <general_name_classes>` instances that provide a set
1445 of identities for which the certificate is valid. The object is iterable to
1446 get every element.
1447
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001448 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001449
Paul Kehrer822f3d32015-08-06 11:47:32 +01001450 .. attribute:: oid
1451
1452 .. versionadded:: 1.0
1453
1454 :type: :class:`ObjectIdentifier`
1455
Paul Kehrere27f6582015-08-10 18:33:38 -05001456 Returns
1457 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001458
Paul Kehrer31bdf792015-03-25 14:11:00 -05001459 .. method:: get_values_for_type(type)
1460
1461 :param type: A :class:`GeneralName` provider. This is one of the
1462 :ref:`general name classes <general_name_classes>`.
1463
1464 :returns: A list of values extracted from the matched general names.
Joshua Taubererd2afad32015-07-06 22:37:53 +00001465 The type of the returned values depends on the :class:`GeneralName`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001466
Paul Kehrer93ae8052015-05-02 23:18:09 -05001467 .. doctest::
1468
1469 >>> from cryptography import x509
1470 >>> from cryptography.hazmat.backends import default_backend
1471 >>> from cryptography.hazmat.primitives import hashes
1472 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001473 >>> # Get the subjectAltName extension from the certificate
Paul Kehrere27f6582015-08-10 18:33:38 -05001474 >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001475 >>> # Get the dNSName entries from the SAN extension
1476 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer93ae8052015-05-02 23:18:09 -05001477 [u'www.cryptography.io', u'cryptography.io']
1478
Paul Kehrer8cf26422015-03-21 09:50:24 -05001479
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001480.. class:: IssuerAlternativeName(general_names)
Paul Kehrer99125c92015-06-07 18:37:10 -05001481
1482 .. versionadded:: 1.0
1483
1484 Issuer alternative name is an X.509 extension that provides a list of
1485 :ref:`general name <general_name_classes>` instances that provide a set
1486 of identities for the certificate issuer. The object is iterable to
1487 get every element.
1488
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001489 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001490
Paul Kehrer822f3d32015-08-06 11:47:32 +01001491 .. attribute:: oid
1492
1493 .. versionadded:: 1.0
1494
1495 :type: :class:`ObjectIdentifier`
1496
Paul Kehrere27f6582015-08-10 18:33:38 -05001497 Returns
1498 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUER_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001499
Paul Kehrer99125c92015-06-07 18:37:10 -05001500 .. method:: get_values_for_type(type)
1501
1502 :param type: A :class:`GeneralName` provider. This is one of the
1503 :ref:`general name classes <general_name_classes>`.
1504
1505 :returns: A list of values extracted from the matched general names.
1506
1507
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001508.. class:: AuthorityInformationAccess(descriptions)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001509
1510 .. versionadded:: 0.9
1511
1512 The authority information access extension indicates how to access
1513 information and services for the issuer of the certificate in which
1514 the extension appears. Information and services may include online
1515 validation services (such as OCSP) and issuer data. It is an iterable,
Paul Kehrere27f6582015-08-10 18:33:38 -05001516 containing one or more :class:`~cryptography.x509.AccessDescription`
1517 instances.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001518
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001519 :param list descriptions: A list of :class:`AccessDescription` objects.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001520
Paul Kehrer822f3d32015-08-06 11:47:32 +01001521 .. attribute:: oid
1522
1523 .. versionadded:: 1.0
1524
1525 :type: :class:`ObjectIdentifier`
1526
Paul Kehrere27f6582015-08-10 18:33:38 -05001527 Returns
1528 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_INFORMATION_ACCESS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001529
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001530
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001531.. class:: AccessDescription(access_method, access_location)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001532
Paul Kehrer5a485522015-05-06 00:29:12 -05001533 .. versionadded:: 0.9
1534
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001535 .. attribute:: access_method
1536
1537 :type: :class:`ObjectIdentifier`
1538
Paul Kehrerf506bca2015-05-02 22:31:47 -05001539 The access method defines what the ``access_location`` means. It must
Paul Kehrere27f6582015-08-10 18:33:38 -05001540 be either
1541 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` or
1542 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`.
1543 If it is
1544 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP`
1545 the access location will be where to obtain OCSP
1546 information for the certificate. If it is
1547 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`
1548 the access location will provide additional information about the
1549 issuing certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001550
1551 .. attribute:: access_location
1552
1553 :type: :class:`GeneralName`
1554
Paul Kehrerf506bca2015-05-02 22:31:47 -05001555 Where to access the information defined by the access method.
1556
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001557.. class:: CRLDistributionPoints(distribution_points)
Paul Kehrer5a485522015-05-06 00:29:12 -05001558
1559 .. versionadded:: 0.9
1560
1561 The CRL distribution points extension identifies how CRL information is
1562 obtained. It is an iterable, containing one or more
1563 :class:`DistributionPoint` instances.
1564
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001565 :param list distribution_points: A list of :class:`DistributionPoint`
1566 instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001567
Paul Kehrer822f3d32015-08-06 11:47:32 +01001568 .. attribute:: oid
1569
1570 .. versionadded:: 1.0
1571
1572 :type: :class:`ObjectIdentifier`
1573
Paul Kehrere27f6582015-08-10 18:33:38 -05001574 Returns
1575 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_DISTRIBUTION_POINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001576
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001577.. class:: DistributionPoint(full_name, relative_name, reasons, crl_issuer)
Paul Kehrer5a485522015-05-06 00:29:12 -05001578
1579 .. versionadded:: 0.9
1580
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001581 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05001582
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001583 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001584
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001585 This field describes methods to retrieve the CRL. At most one of
1586 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001587
1588 .. attribute:: relative_name
1589
1590 :type: :class:`Name` or None
1591
1592 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001593 issuer. At most one of ``full_name`` or ``relative_name`` will be
1594 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05001595
1596 .. attribute:: crl_issuer
1597
1598 :type: list of :class:`GeneralName` instances or None
1599
1600 Information about the issuer of the CRL.
1601
1602 .. attribute:: reasons
1603
Paul Kehrer3fd02602015-05-09 19:46:13 -05001604 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001605
1606 The reasons a given distribution point may be used for when performing
1607 revocation checks.
1608
1609.. class:: ReasonFlags
1610
1611 .. versionadded:: 0.9
1612
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001613 An enumeration for CRL reasons.
1614
1615 .. attribute:: unspecified
1616
1617 It is unspecified why the certificate was revoked. This reason cannot
1618 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001619
1620 .. attribute:: key_compromise
1621
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001622 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001623
1624 .. attribute:: ca_compromise
1625
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001626 This reason indicates that the CA issuing the certificate was
1627 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001628
1629 .. attribute:: affiliation_changed
1630
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001631 This reason indicates that the subject's name or other information has
1632 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05001633
1634 .. attribute:: superseded
1635
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001636 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05001637
1638 .. attribute:: cessation_of_operation
1639
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001640 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05001641
1642 .. attribute:: certificate_hold
1643
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001644 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05001645
1646 .. attribute:: privilege_withdrawn
1647
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001648 This reason indicates that the privilege granted by this certificate
1649 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05001650
1651 .. attribute:: aa_compromise
1652
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001653 When an attribute authority has been compromised.
1654
1655 .. attribute:: remove_from_crl
1656
1657 This reason indicates that the certificate was on hold and should be
1658 removed from the CRL. This reason cannot be used as a reason flag
1659 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001660
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001661.. class:: InhibitAnyPolicy(skip_certs)
Paul Kehrer16fae762015-05-01 23:14:20 -05001662
1663 .. versionadded:: 1.0
1664
1665 The inhibit ``anyPolicy`` extension indicates that the special OID
Paul Kehrere27f6582015-08-10 18:33:38 -05001666 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY`, is not
1667 considered an explicit match for other :class:`CertificatePolicies` except
1668 when it appears in an intermediate self-issued CA certificate. The value
1669 indicates the number of additional non-self-issued certificates that may
1670 appear in the path before
1671 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` is no
1672 longer permitted. For example, a value of one indicates that
1673 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` may be
1674 processed in certificates issued by the subject of this certificate, but
1675 not in additional certificates in the path.
Paul Kehrer16fae762015-05-01 23:14:20 -05001676
Paul Kehrer822f3d32015-08-06 11:47:32 +01001677 .. attribute:: oid
1678
1679 .. versionadded:: 1.0
1680
1681 :type: :class:`ObjectIdentifier`
1682
Paul Kehrere27f6582015-08-10 18:33:38 -05001683 Returns
1684 :attr:`~cryptography.x509.oid.ExtensionOID.INHIBIT_ANY_POLICY`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001685
Paul Kehrer16fae762015-05-01 23:14:20 -05001686 .. attribute:: skip_certs
1687
1688 :type: int
1689
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001690.. class:: CertificatePolicies(policies)
Paul Kehrer0d210922015-04-28 17:31:07 -05001691
1692 .. versionadded:: 0.9
1693
Paul Kehrer2e879742015-05-02 23:09:56 -05001694 The certificate policies extension is an iterable, containing one or more
1695 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05001696
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001697 :param list policies: A list of :class:`PolicyInformation` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001698
Paul Kehrer822f3d32015-08-06 11:47:32 +01001699 .. attribute:: oid
1700
1701 .. versionadded:: 1.0
1702
1703 :type: :class:`ObjectIdentifier`
1704
Paul Kehrere27f6582015-08-10 18:33:38 -05001705 Returns
1706 :attr:`~cryptography.x509.oid.ExtensionOID.CERTIFICATE_POLICIES`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001707
Paul Kehrer0d210922015-04-28 17:31:07 -05001708Certificate Policies Classes
1709~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1710
1711These classes may be present within a :class:`CertificatePolicies` instance.
1712
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001713.. class:: PolicyInformation(policy_identifier, policy_qualifiers)
Paul Kehrer0d210922015-04-28 17:31:07 -05001714
1715 .. versionadded:: 0.9
1716
1717 Contains a policy identifier and an optional list of qualifiers.
1718
1719 .. attribute:: policy_identifier
1720
1721 :type: :class:`ObjectIdentifier`
1722
1723 .. attribute:: policy_qualifiers
1724
1725 :type: list
1726
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001727 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05001728 If the value is text it is a pointer to the practice statement
1729 published by the certificate authority. If it is a user notice it is
1730 meant for display to the relying party when the certificate is
1731 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05001732
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001733.. class:: UserNotice(notice_reference, explicit_text)
Paul Kehrer0d210922015-04-28 17:31:07 -05001734
1735 .. versionadded:: 0.9
1736
Paul Kehrer2e879742015-05-02 23:09:56 -05001737 User notices are intended for display to a relying party when a certificate
1738 is used. In practice, few if any UIs expose this data and it is a rarely
1739 encoded component.
1740
Paul Kehrer0d210922015-04-28 17:31:07 -05001741 .. attribute:: notice_reference
1742
1743 :type: :class:`NoticeReference` or None
1744
Paul Kehrer2e879742015-05-02 23:09:56 -05001745 The notice reference field names an organization and identifies,
1746 by number, a particular statement prepared by that organization.
1747
Paul Kehrer0d210922015-04-28 17:31:07 -05001748 .. attribute:: explicit_text
1749
Paul Kehrer2e879742015-05-02 23:09:56 -05001750 This field includes an arbitrary textual statement directly in the
1751 certificate.
1752
Paul Kehrer0d210922015-04-28 17:31:07 -05001753 :type: :term:`text`
1754
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001755.. class:: NoticeReference(organization, notice_numbers)
Paul Kehrer0d210922015-04-28 17:31:07 -05001756
Paul Kehrer2e879742015-05-02 23:09:56 -05001757 Notice reference can name an organization and provide information about
1758 notices related to the certificate. For example, it might identify the
1759 organization name and notice number 1. Application software could
1760 have a notice file containing the current set of notices for the named
1761 organization; the application would then extract the notice text from the
1762 file and display it. In practice this is rarely seen.
1763
Paul Kehrer0d210922015-04-28 17:31:07 -05001764 .. versionadded:: 0.9
1765
1766 .. attribute:: organization
1767
Paul Kehrer66c61702015-05-12 16:39:18 -05001768 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05001769
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05001770 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05001771
Paul Kehrer66c61702015-05-12 16:39:18 -05001772 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05001773
Paul Kehrer66c61702015-05-12 16:39:18 -05001774 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05001775
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001776Object Identifiers
1777~~~~~~~~~~~~~~~~~~
1778
Paul Kehrer4bb46492015-02-07 16:59:14 -06001779X.509 elements are frequently identified by :class:`ObjectIdentifier`
1780instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001781
Paul Kehrere27f6582015-08-10 18:33:38 -05001782.. currentmodule:: cryptography.x509.oid
Paul Kehrer56da2a52015-02-11 23:35:07 -06001783
Paul Kehrere27f6582015-08-10 18:33:38 -05001784.. class:: NameOID
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001785
Paul Kehrere27f6582015-08-10 18:33:38 -05001786 These OIDs are typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001787
Paul Kehrere27f6582015-08-10 18:33:38 -05001788 .. versionadded:: 1.0
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001789
Paul Kehrere27f6582015-08-10 18:33:38 -05001790 .. attribute:: COMMON_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001791
Paul Kehrere27f6582015-08-10 18:33:38 -05001792 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
1793 name would be encoded here for server certificates. :rfc:`2818`
1794 deprecates this practice and names of that type should now be located
1795 in a :class:`~cryptography.x509.SubjectAlternativeName` extension.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001796
Paul Kehrere27f6582015-08-10 18:33:38 -05001797 .. attribute:: COUNTRY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001798
Paul Kehrere27f6582015-08-10 18:33:38 -05001799 Corresponds to the dotted string ``"2.5.4.6"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001800
Paul Kehrere27f6582015-08-10 18:33:38 -05001801 .. attribute:: LOCALITY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001802
Paul Kehrere27f6582015-08-10 18:33:38 -05001803 Corresponds to the dotted string ``"2.5.4.7"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001804
Paul Kehrere27f6582015-08-10 18:33:38 -05001805 .. attribute:: STATE_OR_PROVINCE_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001806
Paul Kehrere27f6582015-08-10 18:33:38 -05001807 Corresponds to the dotted string ``"2.5.4.8"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001808
Paul Kehrere27f6582015-08-10 18:33:38 -05001809 .. attribute:: ORGANIZATION_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001810
Paul Kehrere27f6582015-08-10 18:33:38 -05001811 Corresponds to the dotted string ``"2.5.4.10"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001812
Paul Kehrere27f6582015-08-10 18:33:38 -05001813 .. attribute:: ORGANIZATIONAL_UNIT_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001814
Paul Kehrere27f6582015-08-10 18:33:38 -05001815 Corresponds to the dotted string ``"2.5.4.11"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001816
Paul Kehrere27f6582015-08-10 18:33:38 -05001817 .. attribute:: SERIAL_NUMBER
Paul Kehrer858b9b72015-02-05 09:50:31 -06001818
Paul Kehrere27f6582015-08-10 18:33:38 -05001819 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from
1820 the serial number of the certificate itself (which can be obtained with
1821 :func:`~cryptography.x509.Certificate.serial`).
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001822
Paul Kehrere27f6582015-08-10 18:33:38 -05001823 .. attribute:: SURNAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001824
Paul Kehrere27f6582015-08-10 18:33:38 -05001825 Corresponds to the dotted string ``"2.5.4.4"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001826
Paul Kehrere27f6582015-08-10 18:33:38 -05001827 .. attribute:: GIVEN_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001828
Paul Kehrere27f6582015-08-10 18:33:38 -05001829 Corresponds to the dotted string ``"2.5.4.42"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001830
Paul Kehrere27f6582015-08-10 18:33:38 -05001831 .. attribute:: TITLE
Paul Kehrer858b9b72015-02-05 09:50:31 -06001832
Paul Kehrere27f6582015-08-10 18:33:38 -05001833 Corresponds to the dotted string ``"2.5.4.12"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001834
Paul Kehrere27f6582015-08-10 18:33:38 -05001835 .. attribute:: GENERATION_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06001836
Paul Kehrere27f6582015-08-10 18:33:38 -05001837 Corresponds to the dotted string ``"2.5.4.44"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001838
Paul Kehrere27f6582015-08-10 18:33:38 -05001839 .. attribute:: DN_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06001840
Paul Kehrere27f6582015-08-10 18:33:38 -05001841 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
1842 disambiguating information to add to the relative distinguished name of an
1843 entry. See :rfc:`2256`.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001844
Paul Kehrere27f6582015-08-10 18:33:38 -05001845 .. attribute:: PSEUDONYM
Paul Kehrer858b9b72015-02-05 09:50:31 -06001846
Paul Kehrere27f6582015-08-10 18:33:38 -05001847 Corresponds to the dotted string ``"2.5.4.65"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001848
Paul Kehrere27f6582015-08-10 18:33:38 -05001849 .. attribute:: DOMAIN_COMPONENT
Paul Kehrer858b9b72015-02-05 09:50:31 -06001850
Paul Kehrere27f6582015-08-10 18:33:38 -05001851 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
1852 holding one component of a domain name. See :rfc:`4519`.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001853
Paul Kehrere27f6582015-08-10 18:33:38 -05001854 .. attribute:: EMAIL_ADDRESS
Paul Kehrer56da2a52015-02-11 23:35:07 -06001855
Paul Kehrere27f6582015-08-10 18:33:38 -05001856 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001857
Paul Kehrer56da2a52015-02-11 23:35:07 -06001858
Paul Kehrere27f6582015-08-10 18:33:38 -05001859.. class:: SignatureAlgorithmOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06001860
Paul Kehrere27f6582015-08-10 18:33:38 -05001861 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06001862
Paul Kehrere27f6582015-08-10 18:33:38 -05001863 .. attribute:: RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06001864
Paul Kehrere27f6582015-08-10 18:33:38 -05001865 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
1866 an MD5 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001867
Paul Kehrere27f6582015-08-10 18:33:38 -05001868 .. attribute:: RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06001869
Paul Kehrere27f6582015-08-10 18:33:38 -05001870 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
1871 a SHA1 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001872
Paul Kehrere27f6582015-08-10 18:33:38 -05001873 .. attribute:: RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06001874
Paul Kehrere27f6582015-08-10 18:33:38 -05001875 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
1876 a SHA224 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001877
Paul Kehrere27f6582015-08-10 18:33:38 -05001878 .. attribute:: RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06001879
Paul Kehrere27f6582015-08-10 18:33:38 -05001880 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
1881 a SHA256 digest signed by an RSA key.
Alex Gaynor3aadabf2015-06-23 22:06:21 -04001882
Paul Kehrere27f6582015-08-10 18:33:38 -05001883 .. attribute:: RSA_WITH_SHA384
Alex Gaynor3aadabf2015-06-23 22:06:21 -04001884
Paul Kehrere27f6582015-08-10 18:33:38 -05001885 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
1886 a SHA384 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001887
Paul Kehrere27f6582015-08-10 18:33:38 -05001888 .. attribute:: RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06001889
Paul Kehrere27f6582015-08-10 18:33:38 -05001890 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
1891 a SHA512 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001892
Paul Kehrere27f6582015-08-10 18:33:38 -05001893 .. attribute:: ECDSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06001894
Paul Kehrere27f6582015-08-10 18:33:38 -05001895 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
1896 digest signed by an ECDSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001897
Paul Kehrere27f6582015-08-10 18:33:38 -05001898 .. attribute:: ECDSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06001899
Paul Kehrere27f6582015-08-10 18:33:38 -05001900 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
1901 a SHA224 digest signed by an ECDSA key.
1902
1903 .. attribute:: ECDSA_WITH_SHA256
1904
1905 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
1906 a SHA256 digest signed by an ECDSA key.
1907
1908 .. attribute:: ECDSA_WITH_SHA384
1909
1910 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
1911 a SHA384 digest signed by an ECDSA key.
1912
1913 .. attribute:: ECDSA_WITH_SHA512
1914
1915 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
1916 a SHA512 digest signed by an ECDSA key.
1917
1918 .. attribute:: DSA_WITH_SHA1
1919
1920 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
1921 a SHA1 digest signed by a DSA key.
1922
1923 .. attribute:: DSA_WITH_SHA224
1924
1925 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
1926 a SHA224 digest signed by a DSA key.
1927
1928 .. attribute:: DSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06001929
Paul Kehrere27f6582015-08-10 18:33:38 -05001930 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
1931 a SHA256 digest signed by a DSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001932
Paul Kehrer56da2a52015-02-11 23:35:07 -06001933
Paul Kehrere27f6582015-08-10 18:33:38 -05001934.. class:: ExtendedKeyUsageOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06001935
Paul Kehrere27f6582015-08-10 18:33:38 -05001936 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06001937
Paul Kehrere27f6582015-08-10 18:33:38 -05001938 .. attribute:: SERVER_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06001939
Paul Kehrere27f6582015-08-10 18:33:38 -05001940 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used
1941 to denote that a certificate may be used for TLS web server
1942 authentication.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001943
Paul Kehrere27f6582015-08-10 18:33:38 -05001944 .. attribute:: CLIENT_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06001945
Paul Kehrere27f6582015-08-10 18:33:38 -05001946 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used
1947 to denote that a certificate may be used for TLS web client
1948 authentication.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001949
Paul Kehrere27f6582015-08-10 18:33:38 -05001950 .. attribute:: CODE_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05001951
Paul Kehrere27f6582015-08-10 18:33:38 -05001952 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used
1953 to denote that a certificate may be used for code signing.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001954
Paul Kehrere27f6582015-08-10 18:33:38 -05001955 .. attribute:: EMAIL_PROTECTION
Paul Kehrere1513fa2015-03-30 23:08:17 -05001956
Paul Kehrere27f6582015-08-10 18:33:38 -05001957 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used
1958 to denote that a certificate may be used for email protection.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001959
Paul Kehrere27f6582015-08-10 18:33:38 -05001960 .. attribute:: TIME_STAMPING
Paul Kehrere1513fa2015-03-30 23:08:17 -05001961
Paul Kehrere27f6582015-08-10 18:33:38 -05001962 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used
1963 to denote that a certificate may be used for time stamping.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001964
Paul Kehrere27f6582015-08-10 18:33:38 -05001965 .. attribute:: OCSP_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05001966
Paul Kehrere27f6582015-08-10 18:33:38 -05001967 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used
1968 to denote that a certificate may be used for signing OCSP responses.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001969
Paul Kehrere1513fa2015-03-30 23:08:17 -05001970
Paul Kehrere27f6582015-08-10 18:33:38 -05001971.. class:: AuthorityInformationAccessOID
Paul Kehrere1513fa2015-03-30 23:08:17 -05001972
Paul Kehrere27f6582015-08-10 18:33:38 -05001973 .. versionadded:: 1.0
Paul Kehrere1513fa2015-03-30 23:08:17 -05001974
Paul Kehrere27f6582015-08-10 18:33:38 -05001975 .. attribute:: OCSP
Paul Kehrere1513fa2015-03-30 23:08:17 -05001976
Paul Kehrere27f6582015-08-10 18:33:38 -05001977 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
1978 identifier for OCSP data in
1979 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001980
Paul Kehrere27f6582015-08-10 18:33:38 -05001981 .. attribute:: CA_ISSUERS
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001982
Paul Kehrere27f6582015-08-10 18:33:38 -05001983 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
1984 identifier for CA issuer data in
1985 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001986
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001987
Paul Kehrere27f6582015-08-10 18:33:38 -05001988.. class:: CertificatePoliciesOID
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001989
Paul Kehrere27f6582015-08-10 18:33:38 -05001990 .. versionadded:: 1.0
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001991
Paul Kehrere27f6582015-08-10 18:33:38 -05001992 .. attribute:: CPS_QUALIFIER
Paul Kehrer2e879742015-05-02 23:09:56 -05001993
Paul Kehrere27f6582015-08-10 18:33:38 -05001994 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05001995
Paul Kehrere27f6582015-08-10 18:33:38 -05001996 .. attribute:: CPS_USER_NOTICE
Paul Kehrer2e879742015-05-02 23:09:56 -05001997
Paul Kehrere27f6582015-08-10 18:33:38 -05001998 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05001999
Paul Kehrere27f6582015-08-10 18:33:38 -05002000 .. attribute:: ANY_POLICY
Paul Kehrer2e879742015-05-02 23:09:56 -05002001
Paul Kehrere27f6582015-08-10 18:33:38 -05002002 Corresponds to the dotted string ``"2.5.29.32.0"``.
Paul Kehrer16fae762015-05-01 23:14:20 -05002003
Paul Kehrer16fae762015-05-01 23:14:20 -05002004
Paul Kehrere27f6582015-08-10 18:33:38 -05002005.. class:: ExtensionOID
Paul Kehrer5553d572015-03-23 21:08:01 -05002006
Paul Kehrere27f6582015-08-10 18:33:38 -05002007 .. versionadded:: 1.0
Paul Kehrer2bb94642015-03-21 09:54:17 -05002008
Paul Kehrere27f6582015-08-10 18:33:38 -05002009 .. attribute:: BASIC_CONSTRAINTS
Paul Kehrer2bb94642015-03-21 09:54:17 -05002010
Paul Kehrere27f6582015-08-10 18:33:38 -05002011 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
2012 :class:`~cryptography.x509.BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05002013
Paul Kehrere27f6582015-08-10 18:33:38 -05002014 .. attribute:: KEY_USAGE
Paul Kehrercecbbba2015-03-30 14:58:38 -05002015
Paul Kehrere27f6582015-08-10 18:33:38 -05002016 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
2017 :class:`~cryptography.x509.KeyUsage` extension type.
Paul Kehrercecbbba2015-03-30 14:58:38 -05002018
Paul Kehrere27f6582015-08-10 18:33:38 -05002019 .. attribute:: SUBJECT_ALTERNATIVE_NAME
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002020
Paul Kehrere27f6582015-08-10 18:33:38 -05002021 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
2022 :class:`~cryptography.x509.SubjectAlternativeName` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002023
Paul Kehrere27f6582015-08-10 18:33:38 -05002024 .. attribute:: ISSUER_ALTERNATIVE_NAME
Paul Kehrer99125c92015-06-07 18:37:10 -05002025
Paul Kehrere27f6582015-08-10 18:33:38 -05002026 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
2027 :class:`~cryptography.x509.IssuerAlternativeName` extension type.
Paul Kehrer99125c92015-06-07 18:37:10 -05002028
Paul Kehrere27f6582015-08-10 18:33:38 -05002029 .. attribute:: SUBJECT_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002030
Paul Kehrere27f6582015-08-10 18:33:38 -05002031 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
2032 :class:`~cryptography.x509.SubjectKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002033
Paul Kehrere27f6582015-08-10 18:33:38 -05002034 .. attribute:: NAME_CONSTRAINTS
Paul Kehrere0017be2015-05-17 20:39:40 -06002035
Paul Kehrere27f6582015-08-10 18:33:38 -05002036 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
2037 :class:`~cryptography.x509.NameConstraints` extension type.
Paul Kehrere0017be2015-05-17 20:39:40 -06002038
Paul Kehrere27f6582015-08-10 18:33:38 -05002039 .. attribute:: CRL_DISTRIBUTION_POINTS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002040
Paul Kehrere27f6582015-08-10 18:33:38 -05002041 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
2042 :class:`~cryptography.x509.CRLDistributionPoints` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002043
Paul Kehrere27f6582015-08-10 18:33:38 -05002044 .. attribute:: CERTIFICATE_POLICIES
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002045
Paul Kehrere27f6582015-08-10 18:33:38 -05002046 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
2047 :class:`~cryptography.x509.CertificatePolicies` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002048
Paul Kehrere27f6582015-08-10 18:33:38 -05002049 .. attribute:: AUTHORITY_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002050
Paul Kehrere27f6582015-08-10 18:33:38 -05002051 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
2052 :class:`~cryptography.x509.AuthorityKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002053
Paul Kehrere27f6582015-08-10 18:33:38 -05002054 .. attribute:: EXTENDED_KEY_USAGE
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002055
Paul Kehrere27f6582015-08-10 18:33:38 -05002056 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
2057 :class:`~cryptography.x509.ExtendedKeyUsage` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002058
Paul Kehrere27f6582015-08-10 18:33:38 -05002059 .. attribute:: AUTHORITY_INFORMATION_ACCESS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002060
Paul Kehrere27f6582015-08-10 18:33:38 -05002061 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
2062 for the :class:`~cryptography.x509.AuthorityInformationAccess` extension
2063 type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002064
Paul Kehrere27f6582015-08-10 18:33:38 -05002065 .. attribute:: INHIBIT_ANY_POLICY
Paul Kehrerb33de932015-08-06 23:41:05 +01002066
Paul Kehrere27f6582015-08-10 18:33:38 -05002067 Corresponds to the dotted string ``"2.5.29.54"``. The identifier
2068 for the :class:`~cryptography.x509.InhibitAnyPolicy` extension type.
Paul Kehrerb33de932015-08-06 23:41:05 +01002069
Paul Kehrere27f6582015-08-10 18:33:38 -05002070 .. attribute:: OCSP_NO_CHECK
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002071
Paul Kehrere27f6582015-08-10 18:33:38 -05002072 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The
2073 identifier for the :class:`~cryptography.x509.OCSPNoCheck` extension
2074 type.
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002075
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002076Exceptions
2077~~~~~~~~~~
Paul Kehrere27f6582015-08-10 18:33:38 -05002078.. currentmodule:: cryptography.x509
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002079
Paul Kehrere76cd272014-12-14 19:00:51 -06002080.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10002081
2082 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10002083
Paul Kehrerd5cccf72014-12-15 17:20:33 -06002084 .. attribute:: parsed_version
2085
Paul Kehrerbbffc402014-12-17 13:33:55 -06002086 :type: int
2087
2088 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06002089
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05002090.. class:: DuplicateExtension
2091
2092 This is raised when more than one X.509 extension of the same type is
2093 found within a certificate.
2094
2095 .. attribute:: oid
2096
2097 :type: :class:`ObjectIdentifier`
2098
2099 Returns the OID.
2100
2101.. class:: UnsupportedExtension
2102
2103 This is raised when a certificate contains an unsupported extension type.
2104
2105 .. attribute:: oid
2106
2107 :type: :class:`ObjectIdentifier`
2108
2109 Returns the OID.
2110
Paul Kehrerfa56a232015-03-17 13:14:03 -05002111.. class:: ExtensionNotFound
2112
2113 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
2114 an extension OID that is not present in the certificate.
2115
2116 .. attribute:: oid
2117
2118 :type: :class:`ObjectIdentifier`
2119
2120 Returns the OID.
2121
Paul Kehrer9089c912015-04-20 22:15:20 -05002122.. class:: UnsupportedGeneralNameType
2123
2124 This is raised when a certificate contains an unsupported general name
2125 type in an extension.
2126
Paul Kehrerbed07352015-04-21 08:31:10 -05002127 .. attribute:: type
2128
Paul Kehrer0a621bf2015-04-22 09:22:56 -05002129 :type: int
2130
2131 The integer value of the unsupported type. The complete list of
2132 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05002133
Paul Kehrer016e08a2014-11-26 09:41:18 -10002134
Paul Kehrerc7c9a432015-04-19 09:20:13 -05002135.. _`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 -05002136.. _`RFC 5280 section 4.2.1.6`: https://tools.ietf.org/html/rfc5280#section-4.2.1.6