blob: 1177dba4bc7c4d23c425525c387549d9383270ce [file] [log] [blame]
Alex Gaynor4af5b372015-07-12 10:30:59 -05001X.509 Reference
2===============
Paul Kehrer016e08a2014-11-26 09:41:18 -10003
Paul Kehrera9d78c12014-11-26 10:59:03 -10004.. currentmodule:: cryptography.x509
Paul Kehrer016e08a2014-11-26 09:41:18 -10005
Paul Kehrerd26c4db2015-03-15 15:36:24 -05006.. testsetup::
7
Erik Trauschkedc570402015-09-24 20:24:28 -07008 pem_crl_data = b"""
9 -----BEGIN X509 CRL-----
10 MIIBtDCBnQIBAjANBgkqhkiG9w0BAQsFADAnMQswCQYDVQQGEwJVUzEYMBYGA1UE
11 AwwPY3J5cHRvZ3JhcGh5LmlvGA8yMDE1MDEwMTAwMDAwMFoYDzIwMTYwMTAxMDAw
12 MDAwWjA+MDwCAQAYDzIwMTUwMTAxMDAwMDAwWjAmMBgGA1UdGAQRGA8yMDE1MDEw
13 MTAwMDAwMFowCgYDVR0VBAMKAQEwDQYJKoZIhvcNAQELBQADggEBABRA4ww50Lz5
14 zk1j2+aluC4HPHqb7o06h4pTDcCGeXUKXIGeP5ntGGmIoxa26sNoLeOr8+5b43Gf
15 yWraHertllOwaOpNFEe+YZFaE9femtoDbf+GLMvRx/0wDfd3KxPoXnXKMXb2d1w4
16 RCLgmkYx6JyvS+5ciuLQVIKC+l7jwIUeZFLJMUJ8msM4pFYoGameeZmtjMbd/TNg
17 cVBfmZxNMHuLladJxvSo2esARo0TYPhYsgrREKoHwhpzSxdynjn4bOVkILfguwsN
18 qtEEMZFEv5Kb0GqRp2+Iagv2S6dg9JGvxVdsoGjaB6EbYSZ3Psx4aODasIn11uwo
19 X4B9vUQNXqc=
20 -----END X509 CRL-----
21 """.strip()
22
Paul Kehrerd26c4db2015-03-15 15:36:24 -050023 pem_req_data = b"""
24 -----BEGIN CERTIFICATE REQUEST-----
25 MIIC0zCCAbsCAQAwWTELMAkGA1UEBhMCVVMxETAPBgNVBAgMCElsbGlub2lzMRAw
26 DgYDVQQHDAdDaGljYWdvMREwDwYDVQQKDAhyNTA5IExMQzESMBAGA1UEAwwJaGVs
27 bG8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqhZx+Mo9VRd9
28 vsnWWa6NBCws21rZ0+1B/JGgB4hDsZS7iDE4Bj5z4idheFRtl8bBbdjPknq7BfoF
29 8v15Zq/Zv7i2xMSDL+LUrTBZezRd4bRTGqCm6YJ5EYkhqdcqeZleHCFImguHoq1J
30 Fh0+kObQrTHXw3ZP57a3o1IvyIUA3nNoCBL0QQhwBXaDXOojMKNR+bqB5ve8GS1y
31 Elr0AM/+cJsfaIahNQUgFKx3Eu3GeEOMKYOAG1lycgdQdmTUybLrT3U7vkClTseM
32 xHg1r5En7ALjONIhqRuq3rddYahrP8HXozb3zUy3cJ7P6IeaosuvNzvMXOX9P6HD
33 Ha9urDAJ1wIDAQABoDUwMwYJKoZIhvcNAQkOMSYwJDAiBgNVHREEGzAZggl3b3Js
34 ZC5jb22CDHdoYXRldmVyLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEAS4Ro6h+z52SK
35 YSLCYARpnEu/rmh4jdqndt8naqcNb6uLx9mlKZ2W9on9XDjnSdQD9q+ZP5aZfESw
36 R0+rJhW9ZrNa/g1pt6M24ihclHYDAxYMWxT1z/TXXGM3TmZZ6gfYlNE1kkBuODHa
37 UYsR/1Ht1E1EsmmUimt2n+zQR2K8T9Coa+boaUW/GsTEuz1aaJAkj5ZvTDiIhRG4
38 AOCqFZOLAQmCCNgJnnspD9hDz/Ons085LF5wnYjN4/Nsk5tS6AGs3xjZ3jPoOGGn
39 82WQ9m4dBGoVDZXsobVTaN592JEYwN5iu72zRn7Einb4V4H5y3yD2dD4yWPlt4pk
40 5wFkeYsZEA==
41 -----END CERTIFICATE REQUEST-----
42 """.strip()
43
Paul Kehrerd3dafbd2015-03-15 16:24:18 -050044 pem_data = b"""
45 -----BEGIN CERTIFICATE-----
46 MIIDfDCCAmSgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJVUzEf
47 MB0GA1UEChMWVGVzdCBDZXJ0aWZpY2F0ZXMgMjAxMTEVMBMGA1UEAxMMVHJ1c3Qg
48 QW5jaG9yMB4XDTEwMDEwMTA4MzAwMFoXDTMwMTIzMTA4MzAwMFowQDELMAkGA1UE
49 BhMCVVMxHzAdBgNVBAoTFlRlc3QgQ2VydGlmaWNhdGVzIDIwMTExEDAOBgNVBAMT
50 B0dvb2QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCQWJpHYo37
51 Xfb7oJSPe+WvfTlzIG21WQ7MyMbGtK/m8mejCzR6c+f/pJhEH/OcDSMsXq8h5kXa
52 BGqWK+vSwD/Pzp5OYGptXmGPcthDtAwlrafkGOS4GqIJ8+k9XGKs+vQUXJKsOk47
53 RuzD6PZupq4s16xaLVqYbUC26UcY08GpnoLNHJZS/EmXw1ZZ3d4YZjNlpIpWFNHn
54 UGmdiGKXUPX/9H0fVjIAaQwjnGAbpgyCumWgzIwPpX+ElFOUr3z7BoVnFKhIXze+
55 VmQGSWxZxvWDUN90Ul0tLEpLgk3OVxUB4VUGuf15OJOpgo1xibINPmWt14Vda2N9
56 yrNKloJGZNqLAgMBAAGjfDB6MB8GA1UdIwQYMBaAFOR9X9FclYYILAWuvnW2ZafZ
57 XahmMB0GA1UdDgQWBBRYAYQkG7wrUpRKPaUQchRR9a86yTAOBgNVHQ8BAf8EBAMC
58 AQYwFwYDVR0gBBAwDjAMBgpghkgBZQMCATABMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
59 KoZIhvcNAQELBQADggEBADWHlxbmdTXNwBL/llwhQqwnazK7CC2WsXBBqgNPWj7m
60 tvQ+aLG8/50Qc2Sun7o2VnwF9D18UUe8Gj3uPUYH+oSI1vDdyKcjmMbKRU4rk0eo
61 3UHNDXwqIVc9CQS9smyV+x1HCwL4TTrq+LXLKx/qVij0Yqk+UJfAtrg2jnYKXsCu
62 FMBQQnWCGrwa1g1TphRp/RmYHnMynYFmZrXtzFz+U9XEA7C+gPq4kqDI/iVfIT1s
63 6lBtdB50lrDVwl2oYfAvW/6sC2se2QleZidUmrziVNP4oEeXINokU6T6p//HM1FG
64 QYw2jOvpKcKtWCSAnegEbgsGYzATKjmPJPJ0npHFqzM=
65 -----END CERTIFICATE-----
66 """.strip()
67
Paul Kehrer93ae8052015-05-02 23:18:09 -050068 cryptography_cert_pem = b"""
69 -----BEGIN CERTIFICATE-----
70 MIIFvTCCBKWgAwIBAgICPyAwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMx
71 FjAUBgNVBAoTDUdlb1RydXN0IEluYy4xIDAeBgNVBAMTF1JhcGlkU1NMIFNIQTI1
72 NiBDQSAtIEczMB4XDTE0MTAxNTEyMDkzMloXDTE4MTExNjAxMTUwM1owgZcxEzAR
73 BgNVBAsTCkdUNDg3NDI5NjUxMTAvBgNVBAsTKFNlZSB3d3cucmFwaWRzc2wuY29t
74 L3Jlc291cmNlcy9jcHMgKGMpMTQxLzAtBgNVBAsTJkRvbWFpbiBDb250cm9sIFZh
75 bGlkYXRlZCAtIFJhcGlkU1NMKFIpMRwwGgYDVQQDExN3d3cuY3J5cHRvZ3JhcGh5
76 LmlvMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAom/FebKJIot7Sp3s
77 itG1sicpe3thCssjI+g1JDAS7I3GLVNmbms1DOdIIqwf01gZkzzXBN2+9sOnyRaR
78 PPfCe1jTr3dk2y6rPE559vPa1nZQkhlzlhMhlPyjaT+S7g4Tio4qV2sCBZU01DZJ
79 CaksfohN+5BNVWoJzTbOcrHOEJ+M8B484KlBCiSxqf9cyNQKru4W3bHaCVNVJ8eu
80 6i6KyhzLa0L7yK3LXwwXVs583C0/vwFhccGWsFODqD/9xHUzsBIshE8HKjdjDi7Y
81 3BFQzVUQFjBB50NSZfAA/jcdt1blxJouc7z9T8Oklh+V5DDBowgAsrT4b6Z2Fq6/
82 r7D1GqivLK/ypUQmxq2WXWAUBb/Q6xHgxASxI4Br+CByIUQJsm8L2jzc7k+mF4hW
83 ltAIUkbo8fGiVnat0505YJgxWEDKOLc4Gda6d/7GVd5AvKrz242bUqeaWo6e4MTx
84 diku2Ma3rhdcr044Qvfh9hGyjqNjvhWY/I+VRWgihU7JrYvgwFdJqsQ5eiKT4OHi
85 gsejvWwkZzDtiQ+aQTrzM1FsY2swJBJsLSX4ofohlVRlIJCn/ME+XErj553431Lu
86 YQ5SzMd3nXzN78Vj6qzTfMUUY72UoT1/AcFiUMobgIqrrmwuNxfrkbVE2b6Bga74
87 FsJX63prvrJ41kuHK/16RQBM7fcCAwEAAaOCAWAwggFcMB8GA1UdIwQYMBaAFMOc
88 8/zTRgg0u85Gf6B8W/PiCMtZMFcGCCsGAQUFBwEBBEswSTAfBggrBgEFBQcwAYYT
89 aHR0cDovL2d2LnN5bWNkLmNvbTAmBggrBgEFBQcwAoYaaHR0cDovL2d2LnN5bWNi
90 LmNvbS9ndi5jcnQwDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMB
91 BggrBgEFBQcDAjAvBgNVHREEKDAmghN3d3cuY3J5cHRvZ3JhcGh5Lmlvgg9jcnlw
92 dG9ncmFwaHkuaW8wKwYDVR0fBCQwIjAgoB6gHIYaaHR0cDovL2d2LnN5bWNiLmNv
93 bS9ndi5jcmwwDAYDVR0TAQH/BAIwADBFBgNVHSAEPjA8MDoGCmCGSAGG+EUBBzYw
94 LDAqBggrBgEFBQcCARYeaHR0cHM6Ly93d3cucmFwaWRzc2wuY29tL2xlZ2FsMA0G
95 CSqGSIb3DQEBCwUAA4IBAQAzIYO2jx7h17FBT74tJ2zbV9OKqGb7QF8y3wUtP4xc
96 dH80vprI/Cfji8s86kr77aAvAqjDjaVjHn7UzebhSUivvRPmfzRgyWBacomnXTSt
97 Xlt2dp2nDQuwGyK2vB7dMfKnQAkxwq1sYUXznB8i0IhhCAoXp01QGPKq51YoIlnF
98 7DRMk6iEaL1SJbkIrLsCQyZFDf0xtfW9DqXugMMLoxeCsBhZJQzNyS2ryirrv9LH
99 aK3+6IZjrcyy9bkpz/gzJucyhU+75c4My/mnRCrtItRbCQuiI5pd5poDowm+HH9i
100 GVI9+0lAFwxOUnOnwsoI40iOoxjLMGB+CgFLKCGUcWxP
101 -----END CERTIFICATE-----
102 """.strip()
103
Paul Kehrerb2de9482014-12-11 14:54:48 -0600104Loading Certificates
105~~~~~~~~~~~~~~~~~~~~
Paul Kehrer016e08a2014-11-26 09:41:18 -1000106
107.. function:: load_pem_x509_certificate(data, backend)
108
109 .. versionadded:: 0.7
110
Paul Kehrere76cd272014-12-14 19:00:51 -0600111 Deserialize a certificate from PEM encoded data. PEM certificates are
112 base64 decoded and have delimiters that look like
113 ``-----BEGIN CERTIFICATE-----``.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000114
115 :param bytes data: The PEM encoded certificate data.
116
117 :param backend: A backend supporting the
118 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
119 interface.
120
Paul Kehrere76cd272014-12-14 19:00:51 -0600121 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000122
Alex Gaynor5ce14042016-05-29 13:13:46 -0400123 .. doctest::
124
125 >>> from cryptography import x509
126 >>> from cryptography.hazmat.backends import default_backend
127 >>> cert = x509.load_pem_x509_certificate(pem_data, default_backend())
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700128 >>> cert.serial_number
Alex Gaynor5ce14042016-05-29 13:13:46 -0400129 2
130
Paul Kehrer016e08a2014-11-26 09:41:18 -1000131.. function:: load_der_x509_certificate(data, backend)
132
133 .. versionadded:: 0.7
134
Paul Kehrere76cd272014-12-14 19:00:51 -0600135 Deserialize a certificate from DER encoded data. DER is a binary format
Paul Kehrer92aac382014-12-15 16:25:28 -0600136 and is commonly found in files with the ``.cer`` extension (although file
137 extensions are not a guarantee of encoding type).
Paul Kehrer016e08a2014-11-26 09:41:18 -1000138
139 :param bytes data: The DER encoded certificate data.
140
141 :param backend: A backend supporting the
142 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
143 interface.
144
Paul Kehrere76cd272014-12-14 19:00:51 -0600145 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000146
Erik Trauschkedc570402015-09-24 20:24:28 -0700147Loading Certificate Revocation Lists
148~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149
150.. function:: load_pem_x509_crl(data, backend)
151
152 .. versionadded:: 1.1
153
154 Deserialize a certificate revocation list (CRL) from PEM encoded data. PEM
155 requests are base64 decoded and have delimiters that look like
Erik Trauschke32bbfe02015-10-21 08:04:55 -0700156 ``-----BEGIN X509 CRL-----``.
Erik Trauschkedc570402015-09-24 20:24:28 -0700157
158 :param bytes data: The PEM encoded request data.
159
160 :param backend: A backend supporting the
161 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
162 interface.
163
164 :returns: An instance of
165 :class:`~cryptography.x509.CertificateRevocationList`.
166
Alex Gaynor5ce14042016-05-29 13:13:46 -0400167 .. doctest::
168
169 >>> from cryptography import x509
170 >>> from cryptography.hazmat.backends import default_backend
171 >>> from cryptography.hazmat.primitives import hashes
172 >>> crl = x509.load_pem_x509_crl(pem_crl_data, default_backend())
173 >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
174 True
175
Erik Trauschkedc570402015-09-24 20:24:28 -0700176.. function:: load_der_x509_crl(data, backend)
177
178 .. versionadded:: 1.1
179
180 Deserialize a certificate revocation list (CRL) from DER encoded data. DER
181 is a binary format.
182
183 :param bytes data: The DER encoded request data.
184
185 :param backend: A backend supporting the
186 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
187 interface.
188
189 :returns: An instance of
190 :class:`~cryptography.x509.CertificateRevocationList`.
191
Paul Kehrera1a1f232015-03-15 15:34:35 -0500192Loading Certificate Signing Requests
193~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600194
Paul Kehrer31e39882015-03-11 11:37:04 -0500195.. function:: load_pem_x509_csr(data, backend)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600196
197 .. versionadded:: 0.9
198
Paul Kehrera1a1f232015-03-15 15:34:35 -0500199 Deserialize a certificate signing request (CSR) from PEM encoded data. PEM
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500200 requests are base64 decoded and have delimiters that look like
Paul Kehrerd3dafbd2015-03-15 16:24:18 -0500201 ``-----BEGIN CERTIFICATE REQUEST-----``. This format is also known as
202 PKCS#10.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600203
204 :param bytes data: The PEM encoded request data.
205
206 :param backend: A backend supporting the
207 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
208 interface.
209
Paul Kehrera1a1f232015-03-15 15:34:35 -0500210 :returns: An instance of
211 :class:`~cryptography.x509.CertificateSigningRequest`.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600212
Alex Gaynor5ce14042016-05-29 13:13:46 -0400213 .. doctest::
214
215 >>> from cryptography import x509
216 >>> from cryptography.hazmat.backends import default_backend
217 >>> from cryptography.hazmat.primitives import hashes
218 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
219 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
220 True
221
Paul Kehrer1effb6e2015-03-30 15:05:59 -0500222.. function:: load_der_x509_csr(data, backend)
223
224 .. versionadded:: 0.9
225
226 Deserialize a certificate signing request (CSR) from DER encoded data. DER
227 is a binary format and is not commonly used with CSRs.
228
229 :param bytes data: The DER encoded request data.
230
231 :param backend: A backend supporting the
232 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
233 interface.
234
235 :returns: An instance of
236 :class:`~cryptography.x509.CertificateSigningRequest`.
237
Paul Kehrere76cd272014-12-14 19:00:51 -0600238X.509 Certificate Object
239~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerb2de9482014-12-11 14:54:48 -0600240
Paul Kehrere76cd272014-12-14 19:00:51 -0600241.. class:: Certificate
Paul Kehrerb2de9482014-12-11 14:54:48 -0600242
243 .. versionadded:: 0.7
244
245 .. attribute:: version
246
Paul Kehrere76cd272014-12-14 19:00:51 -0600247 :type: :class:`~cryptography.x509.Version`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600248
Paul Kehrere76cd272014-12-14 19:00:51 -0600249 The certificate version as an enumeration. Version 3 certificates are
250 the latest version and also the only type you should see in practice.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600251
Alex Gaynor89c4dc82014-12-16 16:49:33 -0800252 :raises cryptography.x509.InvalidVersion: If the version in the
Alex Gaynor6d7ab4c2014-12-16 16:50:33 -0800253 certificate is not a known
254 :class:`X.509 version <cryptography.x509.Version>`.
Paul Kehrer92aac382014-12-15 16:25:28 -0600255
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600256 .. doctest::
257
258 >>> cert.version
259 <Version.v3: 2>
260
Paul Kehrerb2de9482014-12-11 14:54:48 -0600261 .. method:: fingerprint(algorithm)
262
263 :param algorithm: The
Paul Kehrer601278a2015-02-12 12:51:00 -0600264 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600265 that will be used to generate the fingerprint.
266
Erik Trauschke2dcce902015-05-14 16:12:24 -0700267 :return bytes: The fingerprint using the supplied hash algorithm, as
Paul Kehrerb2de9482014-12-11 14:54:48 -0600268 bytes.
269
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600270 .. doctest::
271
272 >>> from cryptography.hazmat.primitives import hashes
273 >>> cert.fingerprint(hashes.SHA256())
Paul Kehrer78a81502014-12-16 14:47:52 -0600274 '\x86\xd2\x187Gc\xfc\xe7}[+E9\x8d\xb4\x8f\x10\xe5S\xda\x18u\xbe}a\x03\x08[\xac\xa04?'
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600275
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700276 .. attribute:: serial_number
Paul Kehrerb2de9482014-12-11 14:54:48 -0600277
278 :type: int
279
280 The serial as a Python integer.
281
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600282 .. doctest::
283
Chelsea Winfreee295f3a2016-06-02 21:15:54 -0700284 >>> cert.serial_number
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600285 2
286
Paul Kehrerb2de9482014-12-11 14:54:48 -0600287 .. method:: public_key()
288
Alex Gaynor4c2561a2015-10-12 23:53:39 -0400289 The public key associated with the certificate.
290
291 :returns:
Alex Stapletonf79c2312014-12-30 12:50:14 +0000292 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
Paul Kehrer45efdbc2015-02-12 10:58:22 -0600293 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
294 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600295
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600296 .. doctest::
297
Alex Stapletonf79c2312014-12-30 12:50:14 +0000298 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600299 >>> public_key = cert.public_key()
Alex Stapletonf79c2312014-12-30 12:50:14 +0000300 >>> isinstance(public_key, rsa.RSAPublicKey)
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600301 True
302
Paul Kehrerb2de9482014-12-11 14:54:48 -0600303 .. attribute:: not_valid_before
304
305 :type: :class:`datetime.datetime`
306
Paul Kehrer78a81502014-12-16 14:47:52 -0600307 A naïve datetime representing the beginning of the validity period for
308 the certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600309
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600310 .. doctest::
311
312 >>> cert.not_valid_before
313 datetime.datetime(2010, 1, 1, 8, 30)
314
Paul Kehrerb2de9482014-12-11 14:54:48 -0600315 .. attribute:: not_valid_after
316
317 :type: :class:`datetime.datetime`
318
Paul Kehrer78a81502014-12-16 14:47:52 -0600319 A naïve datetime representing the end of the validity period for the
320 certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600321
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600322 .. doctest::
323
324 >>> cert.not_valid_after
325 datetime.datetime(2030, 12, 31, 8, 30)
326
Paul Kehrer719d5362015-01-01 20:03:52 -0600327 .. attribute:: issuer
328
329 .. versionadded:: 0.8
330
331 :type: :class:`Name`
332
333 The :class:`Name` of the issuer.
334
335 .. attribute:: subject
336
337 .. versionadded:: 0.8
338
339 :type: :class:`Name`
340
341 The :class:`Name` of the subject.
342
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600343 .. attribute:: signature_hash_algorithm
Paul Kehrer56da2a52015-02-11 23:35:07 -0600344
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600345 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrer56da2a52015-02-11 23:35:07 -0600346
Paul Kehrere612ec72015-02-16 14:33:35 -0600347 Returns the
Paul Kehrer71d40c62015-02-19 08:21:04 -0600348 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600349 was used in signing this certificate.
Paul Kehrer56da2a52015-02-11 23:35:07 -0600350
351 .. doctest::
352
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600353 >>> from cryptography.hazmat.primitives import hashes
354 >>> isinstance(cert.signature_hash_algorithm, hashes.SHA256)
355 True
Paul Kehrer719d5362015-01-01 20:03:52 -0600356
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800357 .. attribute:: signature_algorithm_oid
358
359 .. versionadded:: 1.6
360
361 :type: :class:`ObjectIdentifier`
362
363 Returns the :class:`ObjectIdentifier` of the signature algorithm used
364 to sign the certificate. This will be one of the OIDs from
365 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
366
367
368 .. doctest::
369
370 >>> cert.signature_algorithm_oid
371 <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
372
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500373 .. attribute:: extensions
374
375 :type: :class:`Extensions`
376
377 The extensions encoded in the certificate.
378
379 :raises cryptography.x509.DuplicateExtension: If more than one
380 extension of the same type is found within the certificate.
381
Paul Kehrerd8fc0be2015-04-21 08:31:10 -0500382 :raises cryptography.x509.UnsupportedExtension: If the certificate
383 contains an extension that is not supported.
384
Paul Kehrerbed07352015-04-21 08:31:10 -0500385 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
386 contains a general name that is not supported.
387
Paul Kehrerb8968812015-05-15 09:01:34 -0700388 :raises UnicodeError: If an extension contains IDNA encoding that is
389 invalid or not compliant with IDNA 2008.
390
Paul Kehrerfa56a232015-03-17 13:14:03 -0500391 .. doctest::
392
393 >>> for ext in cert.extensions:
394 ... print(ext)
Paul Kehrerd774de92015-05-03 10:52:25 -0500395 <Extension(oid=<ObjectIdentifier(oid=2.5.29.35, name=authorityKeyIdentifier)>, critical=False, value=<AuthorityKeyIdentifier(key_identifier='\xe4}_\xd1\\\x95\x86\x08,\x05\xae\xbeu\xb6e\xa7\xd9]\xa8f', authority_cert_issuer=None, authority_cert_serial_number=None)>)>
Paul Kehrercbfb1012015-04-10 20:57:20 -0400396 <Extension(oid=<ObjectIdentifier(oid=2.5.29.14, name=subjectKeyIdentifier)>, critical=False, value=<SubjectKeyIdentifier(digest='X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9')>)>
Paul Kehrerb511ba82015-04-15 11:22:48 -0400397 <Extension(oid=<ObjectIdentifier(oid=2.5.29.15, name=keyUsage)>, critical=True, value=<KeyUsage(digital_signature=False, content_commitment=False, key_encipherment=False, data_encipherment=False, key_agreement=False, key_cert_sign=True, crl_sign=True, encipher_only=None, decipher_only=None)>)>
Paul Kehrer2008d9c2015-05-12 22:19:56 -0500398 <Extension(oid=<ObjectIdentifier(oid=2.5.29.32, name=certificatePolicies)>, critical=False, value=<CertificatePolicies([<PolicyInformation(policy_identifier=<ObjectIdentifier(oid=2.16.840.1.101.3.2.1.48.1, name=Unknown OID)>, policy_qualifiers=None)>])>)>
Paul Kehrerfa56a232015-03-17 13:14:03 -0500399 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
400
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500401 .. attribute:: signature
402
403 .. versionadded:: 1.2
404
405 :type: bytes
406
407 The bytes of the certificate's signature.
408
Paul Kehrerd2898052015-11-03 22:00:41 +0900409 .. attribute:: tbs_certificate_bytes
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500410
411 .. versionadded:: 1.2
412
413 :type: bytes
414
415 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
416 and then signed by the private key of the certificate's issuer. This
417 data may be used to validate a signature, but use extreme caution as
418 certificate validation is a complex problem that involves much more
419 than just signature checks.
420
Andre Carona8aded62015-05-19 20:11:57 -0400421 .. method:: public_bytes(encoding)
422
Alex Gaynord0b376b2015-07-05 13:58:12 -0400423 .. versionadded:: 1.0
424
Andre Carona8aded62015-05-19 20:11:57 -0400425 :param encoding: The
426 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
427 that will be used to serialize the certificate.
428
429 :return bytes: The data that can be written to a file or sent
430 over the network to be verified by clients.
431
Erik Trauschke2dcce902015-05-14 16:12:24 -0700432X.509 CRL (Certificate Revocation List) Object
433~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
434
435.. class:: CertificateRevocationList
436
437 .. versionadded:: 1.0
438
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700439 A CertificateRevocationList is an object representing a list of revoked
440 certificates. The object is iterable and will yield the RevokedCertificate
441 objects stored in this CRL.
442
443 .. doctest::
Erik Trauschkeb14f7d12015-10-13 09:55:39 -0700444
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700445 >>> len(crl)
446 1
Paul Kehrerdcdf9672015-10-21 20:27:28 -0500447 >>> revoked_certificate = crl[0]
448 >>> type(revoked_certificate)
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700449 <class 'cryptography.hazmat.backends.openssl.x509._RevokedCertificate'>
450 >>> for r in crl:
451 ... print(r.serial_number)
452 0
453
Erik Trauschke2dcce902015-05-14 16:12:24 -0700454 .. method:: fingerprint(algorithm)
455
456 :param algorithm: The
457 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
458 that will be used to generate the fingerprint.
459
460 :return bytes: The fingerprint using the supplied hash algorithm, as
461 bytes.
462
Erik Trauschkedc570402015-09-24 20:24:28 -0700463 .. doctest::
464
465 >>> from cryptography.hazmat.primitives import hashes
466 >>> crl.fingerprint(hashes.SHA256())
467 'e\xcf.\xc4:\x83?1\xdc\xf3\xfc\x95\xd7\xb3\x87\xb3\x8e\xf8\xb93!\x87\x07\x9d\x1b\xb4!\xb9\xe4W\xf4\x1f'
468
Erik Trauschke2dcce902015-05-14 16:12:24 -0700469 .. attribute:: signature_hash_algorithm
470
471 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
472
473 Returns the
474 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
475 was used in signing this CRL.
476
Erik Trauschkedc570402015-09-24 20:24:28 -0700477 .. doctest::
478
479 >>> from cryptography.hazmat.primitives import hashes
480 >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
481 True
482
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800483 .. attribute:: signature_algorithm_oid
484
485 .. versionadded:: 1.6
486
487 :type: :class:`ObjectIdentifier`
488
489 Returns the :class:`ObjectIdentifier` of the signature algorithm used
490 to sign the CRL. This will be one of the OIDs from
491 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
492
493 .. doctest::
494
495 >>> crl.signature_algorithm_oid
496 <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
497
Erik Trauschke2dcce902015-05-14 16:12:24 -0700498 .. attribute:: issuer
499
500 :type: :class:`Name`
501
502 The :class:`Name` of the issuer.
503
Erik Trauschkedc570402015-09-24 20:24:28 -0700504 .. doctest::
505
506 >>> crl.issuer
507 <Name([<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>, <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'cryptography.io')>])>
508
Erik Trauschke2dcce902015-05-14 16:12:24 -0700509 .. attribute:: next_update
510
511 :type: :class:`datetime.datetime`
512
513 A naïve datetime representing when the next update to this CRL is
514 expected.
515
Erik Trauschkedc570402015-09-24 20:24:28 -0700516 .. doctest::
517
518 >>> crl.next_update
519 datetime.datetime(2016, 1, 1, 0, 0)
520
Erik Trauschke2dcce902015-05-14 16:12:24 -0700521 .. attribute:: last_update
522
523 :type: :class:`datetime.datetime`
524
525 A naïve datetime representing when the this CRL was last updated.
526
Erik Trauschkedc570402015-09-24 20:24:28 -0700527 .. doctest::
Erik Trauschke2dcce902015-05-14 16:12:24 -0700528
Erik Trauschkedc570402015-09-24 20:24:28 -0700529 >>> crl.last_update
530 datetime.datetime(2015, 1, 1, 0, 0)
Erik Trauschke2dcce902015-05-14 16:12:24 -0700531
532 .. attribute:: extensions
533
534 :type: :class:`Extensions`
535
536 The extensions encoded in the CRL.
537
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800538 .. attribute:: signature
539
540 .. versionadded:: 1.2
541
542 :type: bytes
543
544 The bytes of the CRL's signature.
545
546 .. attribute:: tbs_certlist_bytes
547
548 .. versionadded:: 1.2
549
550 :type: bytes
551
552 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
553 and then signed by the private key of the CRL's issuer. This data may be
554 used to validate a signature, but use extreme caution as CRL validation
555 is a complex problem that involves much more than just signature checks.
556
Paul Kehrer54a837d2015-12-20 23:42:32 -0600557 .. method:: public_bytes(encoding)
558
559 .. versionadded:: 1.2
560
561 :param encoding: The
562 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
563 that will be used to serialize the certificate revocation list.
564
565 :return bytes: The data that can be written to a file or sent
566 over the network and used as part of a certificate verification
567 process.
568
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800569
Andre Caron9bbfcea2015-05-18 20:55:29 -0400570X.509 Certificate Builder
571~~~~~~~~~~~~~~~~~~~~~~~~~
572
573.. class:: CertificateBuilder
574
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500575 .. versionadded:: 1.0
576
577 .. doctest::
578
579 >>> from cryptography import x509
580 >>> from cryptography.hazmat.backends import default_backend
581 >>> from cryptography.hazmat.primitives import hashes
582 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -0500583 >>> from cryptography.x509.oid import NameOID
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500584 >>> import datetime
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500585 >>> one_day = datetime.timedelta(1, 0, 0)
586 >>> private_key = rsa.generate_private_key(
587 ... public_exponent=65537,
588 ... key_size=2048,
589 ... backend=default_backend()
590 ... )
Cory Benfieldc47b2522015-12-07 15:25:12 +0000591 >>> public_key = private_key.public_key()
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500592 >>> builder = x509.CertificateBuilder()
593 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500594 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500595 ... ]))
596 >>> builder = builder.issuer_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500597 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500598 ... ]))
599 >>> builder = builder.not_valid_before(datetime.datetime.today() - one_day)
600 >>> builder = builder.not_valid_after(datetime.datetime(2018, 8, 2))
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500601 >>> builder = builder.serial_number(x509.random_serial_number())
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500602 >>> builder = builder.public_key(public_key)
603 >>> builder = builder.add_extension(
Paul Kehrer1bab7bc2017-01-18 13:44:40 +0800604 ... x509.SubjectAlternativeName(
605 ... [x509.DNSName(u'cryptography.io')]
606 ... ),
607 ... critical=False
608 ... )
609 >>> builder = builder.add_extension(
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500610 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
611 ... )
612 >>> certificate = builder.sign(
613 ... private_key=private_key, algorithm=hashes.SHA256(),
614 ... backend=default_backend()
615 ... )
616 >>> isinstance(certificate, x509.Certificate)
617 True
618
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500619 .. method:: issuer_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400620
621 Sets the issuer's distinguished name.
622
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500623 :param name: The :class:`~cryptography.x509.Name` that describes the
624 issuer (CA).
Andre Caron9bbfcea2015-05-18 20:55:29 -0400625
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500626 .. method:: subject_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400627
628 Sets the subject's distinguished name.
629
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500630 :param name: The :class:`~cryptography.x509.Name` that describes the
Ian Cordasco85fc4d52015-08-01 20:29:31 -0500631 subject.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400632
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500633 .. method:: public_key(public_key)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400634
635 Sets the subject's public key.
636
Ian Cordasco8f571422015-08-02 11:31:08 -0500637 :param public_key: The subject's public key. This can be one of
638 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`,
639 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
640 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400641
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500642 .. method:: serial_number(serial_number)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400643
644 Sets the certificate's serial number (an integer). The CA's policy
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500645 determines how it attributes serial numbers to certificates. This
646 number must uniquely identify the certificate given the issuer.
647 `CABForum Guidelines`_ require entropy in the serial number
648 to provide protection against hash collision attacks. For more
649 information on secure random number generation, see
650 :doc:`/random-numbers`.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400651
652 :param serial_number: Integer number that will be used by the CA to
653 identify this certificate (most notably during certificate
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500654 revocation checking). Users should consider using
655 :func:`~cryptography.x509.random_serial_number` when possible.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400656
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500657 .. method:: not_valid_before(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400658
659 Sets the certificate's activation time. This is the time from which
660 clients can start trusting the certificate. It may be different from
661 the time at which the certificate was created.
662
Ian Cordasco17c89002015-08-02 21:13:59 -0500663 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400664 activation time for the certificate. The certificate may not be
665 trusted clients if it is used before this time.
666
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500667 .. method:: not_valid_after(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400668
669 Sets the certificate's expiration time. This is the time from which
670 clients should no longer trust the certificate. The CA's policy will
671 determine how long the certificate should remain in use.
672
Ian Cordasco17c89002015-08-02 21:13:59 -0500673 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400674 expiration time for the certificate. The certificate may not be
675 trusted clients if it is used after this time.
676
Ian Cordasco17c89002015-08-02 21:13:59 -0500677 .. method:: add_extension(extension, critical)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400678
679 Adds an X.509 extension to the certificate.
680
Paul Kehrer2c145cc2015-10-02 11:27:21 -0500681 :param extension: An extension conforming to the
682 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400683
Ian Cordasco17c89002015-08-02 21:13:59 -0500684 :param critical: Set to ``True`` if the extension must be understood and
685 handled by whoever reads the certificate.
686
Paul Kehrer9add80e2015-08-03 17:53:14 +0100687 .. method:: sign(private_key, algorithm, backend)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400688
689 Sign the certificate using the CA's private key.
690
Ian Cordascoc5e1c252015-07-31 23:33:35 -0500691 :param private_key: The
692 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
693 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
694 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
695 that will be used to sign the certificate.
696
Andre Caron9bbfcea2015-05-18 20:55:29 -0400697 :param algorithm: The
698 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
699 will be used to generate the signature.
700
Paul Kehrer9add80e2015-08-03 17:53:14 +0100701 :param backend: Backend that will be used to build the certificate.
702 Must support the
703 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
704 interface.
705
Benjamin Peterson9ed312b2015-10-12 20:51:34 -0700706 :returns: :class:`~cryptography.x509.Certificate`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400707
708
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500709X.509 CSR (Certificate Signing Request) Object
710~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600711
Paul Kehrera1a1f232015-03-15 15:34:35 -0500712.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600713
714 .. versionadded:: 0.9
715
716 .. method:: public_key()
717
Alex Gaynor4c2561a2015-10-12 23:53:39 -0400718 The public key associated with the request.
719
720 :returns:
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600721 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
722 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
723 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
724
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600725 .. doctest::
726
727 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500728 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600729 >>> isinstance(public_key, rsa.RSAPublicKey)
730 True
731
732 .. attribute:: subject
733
734 :type: :class:`Name`
735
736 The :class:`Name` of the subject.
737
738 .. attribute:: signature_hash_algorithm
739
740 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
741
742 Returns the
743 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
744 was used in signing this request.
745
746 .. doctest::
747
748 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500749 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600750 True
751
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800752 .. attribute:: signature_algorithm_oid
753
754 .. versionadded:: 1.6
755
756 :type: :class:`ObjectIdentifier`
757
758 Returns the :class:`ObjectIdentifier` of the signature algorithm used
759 to sign the request. This will be one of the OIDs from
760 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
761
762 .. doctest::
763
764 >>> csr.signature_algorithm_oid
765 <ObjectIdentifier(oid=1.2.840.113549.1.1.5, name=sha1WithRSAEncryption)>
766
Paul Kehrerc4e61942015-08-01 21:21:13 +0100767 .. attribute:: extensions
768
769 :type: :class:`Extensions`
770
771 The extensions encoded in the certificate signing request.
772
773 :raises cryptography.x509.DuplicateExtension: If more than one
Paul Kehrer24283d22015-08-01 21:31:19 +0100774 extension of the same type is found within the certificate signing request.
Paul Kehrerc4e61942015-08-01 21:21:13 +0100775
Paul Kehrer24283d22015-08-01 21:31:19 +0100776 :raises cryptography.x509.UnsupportedExtension: If the certificate signing request
Paul Kehrerc4e61942015-08-01 21:21:13 +0100777 contains an extension that is not supported.
778
779 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
780 contains a general name that is not supported.
781
782 :raises UnicodeError: If an extension contains IDNA encoding that is
783 invalid or not compliant with IDNA 2008.
784
785
Andre Caron476c5df2015-05-18 10:23:28 -0400786 .. method:: public_bytes(encoding)
787
Alex Gaynord0b376b2015-07-05 13:58:12 -0400788 .. versionadded:: 1.0
789
Andre Caron476c5df2015-05-18 10:23:28 -0400790 :param encoding: The
791 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
792 that will be used to serialize the certificate request.
793
794 :return bytes: The data that can be written to a file or sent
795 over the network to be signed by the certificate
796 authority.
797
Paul Kehrerab209392015-12-01 14:50:31 -0600798 .. attribute:: signature
799
800 .. versionadded:: 1.2
801
802 :type: bytes
803
804 The bytes of the certificate signing request's signature.
805
806 .. attribute:: tbs_certrequest_bytes
807
808 .. versionadded:: 1.2
809
810 :type: bytes
811
812 The DER encoded bytes payload (as defined by :rfc:`2986`) that is
813 hashed and then signed by the private key (corresponding to the public
814 key embedded in the CSR). This data may be used to validate the CSR
815 signature.
816
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100817 .. attribute:: is_signature_valid
Joern Heissler1bd77e22016-01-13 22:51:37 +0100818
819 .. versionadded:: 1.3
820
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100821 Returns True if the CSR signature is correct, False otherwise.
Joern Heissler1bd77e22016-01-13 22:51:37 +0100822
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600823X.509 Certificate Revocation List Builder
824~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
825
826.. class:: CertificateRevocationListBuilder
827
828 .. versionadded:: 1.2
829
830 .. doctest::
831
832 >>> from cryptography import x509
833 >>> from cryptography.hazmat.backends import default_backend
834 >>> from cryptography.hazmat.primitives import hashes
835 >>> from cryptography.hazmat.primitives.asymmetric import rsa
836 >>> from cryptography.x509.oid import NameOID
837 >>> import datetime
838 >>> one_day = datetime.timedelta(1, 0, 0)
839 >>> private_key = rsa.generate_private_key(
840 ... public_exponent=65537,
841 ... key_size=2048,
842 ... backend=default_backend()
843 ... )
844 >>> builder = x509.CertificateRevocationListBuilder()
845 >>> builder = builder.issuer_name(x509.Name([
846 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io CA'),
847 ... ]))
848 >>> builder = builder.last_update(datetime.datetime.today())
849 >>> builder = builder.next_update(datetime.datetime.today() + one_day)
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600850 >>> revoked_cert = x509.RevokedCertificateBuilder().serial_number(
851 ... 333
852 ... ).revocation_date(
853 ... datetime.datetime.today()
854 ... ).build(default_backend())
855 >>> builder = builder.add_revoked_certificate(revoked_cert)
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600856 >>> crl = builder.sign(
857 ... private_key=private_key, algorithm=hashes.SHA256(),
858 ... backend=default_backend()
859 ... )
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600860 >>> len(crl)
861 1
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600862
863 .. method:: issuer_name(name)
864
865 Sets the issuer's distinguished name.
866
867 :param name: The :class:`~cryptography.x509.Name` that describes the
868 issuer (CA).
869
870 .. method:: last_update(time)
871
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600872 Sets this CRL's activation time. This is the time from which
873 clients can start trusting this CRL. It may be different from
874 the time at which this CRL was created. This is also known as the
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600875 ``thisUpdate`` time.
876
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600877 :param time: The :class:`datetime.datetime` object (in UTC) that marks
878 the activation time for this CRL. The CRL may not be trusted if it
879 is used before this time.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600880
881 .. method:: next_update(time)
882
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600883 Sets this CRL's next update time. This is the time by which
884 a new CRL will be issued. The CA is allowed to issue a new CRL before
885 this date, however clients are not required to check for it.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600886
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600887 :param time: The :class:`datetime.datetime` object (in UTC) that marks
888 the next update time for this CRL.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600889
Paul Kehrer426b48d2015-12-24 20:50:43 -0600890 .. method:: add_extension(extension, critical)
891
892 Adds an X.509 extension to this CRL.
893
894 :param extension: An extension with the
895 :class:`~cryptography.x509.ExtensionType` interface.
896
897 :param critical: Set to ``True`` if the extension must be understood and
898 handled by whoever reads the CRL.
899
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600900 .. method:: add_revoked_certificate(revoked_certificate)
901
902 Adds a revoked certificate to this CRL.
903
904 :param revoked_certificate: An instance of
905 :class:`~cryptography.x509.RevokedCertificate`. These can be
906 obtained from an existing CRL or created with
907 :class:`~cryptography.x509.RevokedCertificateBuilder`.
908
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600909 .. method:: sign(private_key, algorithm, backend)
910
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600911 Sign this CRL using the CA's private key.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600912
913 :param private_key: The
914 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
915 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
916 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
917 that will be used to sign the certificate.
918
919 :param algorithm: The
920 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
921 will be used to generate the signature.
922
923 :param backend: Backend that will be used to build the CRL.
924 Must support the
925 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
926 interface.
927
928 :returns: :class:`~cryptography.x509.CertificateRevocationList`
929
Erik Trauschke2dcce902015-05-14 16:12:24 -0700930X.509 Revoked Certificate Object
Erik Trauschkec5a8d172015-05-28 10:24:25 -0700931~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Erik Trauschke2dcce902015-05-14 16:12:24 -0700932
933.. class:: RevokedCertificate
934
935 .. versionadded:: 1.0
936
937 .. attribute:: serial_number
938
939 :type: :class:`int`
940
941 An integer representing the serial number of the revoked certificate.
942
Erik Trauschkedc570402015-09-24 20:24:28 -0700943 .. doctest::
944
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700945 >>> revoked_certificate.serial_number
Erik Trauschkedc570402015-09-24 20:24:28 -0700946 0
947
Erik Trauschke2dcce902015-05-14 16:12:24 -0700948 .. attribute:: revocation_date
949
950 :type: :class:`datetime.datetime`
951
952 A naïve datetime representing the date this certificates was revoked.
953
Erik Trauschkedc570402015-09-24 20:24:28 -0700954 .. doctest::
955
Erik Trauschke77f5a252015-10-14 08:06:38 -0700956 >>> revoked_certificate.revocation_date
Erik Trauschkedc570402015-09-24 20:24:28 -0700957 datetime.datetime(2015, 1, 1, 0, 0)
958
Erik Trauschke2dcce902015-05-14 16:12:24 -0700959 .. attribute:: extensions
960
961 :type: :class:`Extensions`
962
963 The extensions encoded in the revoked certificate.
Andre Caron476c5df2015-05-18 10:23:28 -0400964
Erik Trauschkedc570402015-09-24 20:24:28 -0700965 .. doctest::
966
Erik Trauschke77f5a252015-10-14 08:06:38 -0700967 >>> for ext in revoked_certificate.extensions:
Erik Trauschkedc570402015-09-24 20:24:28 -0700968 ... print(ext)
Paul Kehrer23c0bbc2015-12-25 22:35:19 -0600969 <Extension(oid=<ObjectIdentifier(oid=2.5.29.24, name=invalidityDate)>, critical=False, value=<InvalidityDate(invalidity_date=2015-01-01 00:00:00)>)>
Paul Kehrer7058ece2015-12-25 22:28:29 -0600970 <Extension(oid=<ObjectIdentifier(oid=2.5.29.21, name=cRLReason)>, critical=False, value=<CRLReason(reason=ReasonFlags.key_compromise)>)>
Erik Trauschkedc570402015-09-24 20:24:28 -0700971
Paul Kehrerc33ffd72015-12-25 10:59:22 -0600972X.509 Revoked Certificate Builder
973~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
974
975.. class:: RevokedCertificateBuilder
976
977 This class is used to create :class:`~cryptography.x509.RevokedCertificate`
978 objects that can be used with the
979 :class:`~cryptography.x509.CertificateRevocationListBuilder`.
980
981 .. versionadded:: 1.2
982
983 .. doctest::
984
985 >>> from cryptography import x509
986 >>> from cryptography.hazmat.backends import default_backend
987 >>> import datetime
988 >>> builder = x509.RevokedCertificateBuilder()
989 >>> builder = builder.revocation_date(datetime.datetime.today())
990 >>> builder = builder.serial_number(3333)
991 >>> revoked_certificate = builder.build(default_backend())
992 >>> isinstance(revoked_certificate, x509.RevokedCertificate)
993 True
994
995 .. method:: serial_number(serial_number)
996
997 Sets the revoked certificate's serial number.
998
999 :param serial_number: Integer number that is used to identify the
1000 revoked certificate.
1001
1002 .. method:: revocation_date(time)
1003
1004 Sets the certificate's revocation date.
1005
1006 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
1007 revocation time for the certificate.
1008
Paul Kehrere5f152b2015-12-25 23:55:47 -06001009 .. method:: add_extension(extension, critical)
1010
1011 Adds an X.509 extension to this revoked certificate.
1012
1013 :param extension: An instance of one of the
1014 :ref:`CRL entry extensions <crl_entry_extensions>`.
1015
1016 :param critical: Set to ``True`` if the extension must be understood and
1017 handled.
1018
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001019 .. method:: build(backend)
1020
1021 Create a revoked certificate object using the provided backend.
1022
1023 :param backend: Backend that will be used to build the revoked
1024 certificate. Must support the
1025 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1026 interface.
1027
1028 :returns: :class:`~cryptography.x509.RevokedCertificate`
1029
Andre Caron0ef595f2015-05-18 13:53:43 -04001030X.509 CSR (Certificate Signing Request) Builder Object
1031~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1032
1033.. class:: CertificateSigningRequestBuilder
1034
Andre Carond259ee52015-06-02 23:47:11 -04001035 .. versionadded:: 1.0
1036
1037 .. doctest::
1038
1039 >>> from cryptography import x509
1040 >>> from cryptography.hazmat.backends import default_backend
1041 >>> from cryptography.hazmat.primitives import hashes
1042 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -05001043 >>> from cryptography.x509.oid import NameOID
Andre Carond259ee52015-06-02 23:47:11 -04001044 >>> private_key = rsa.generate_private_key(
1045 ... public_exponent=65537,
1046 ... key_size=2048,
1047 ... backend=default_backend()
1048 ... )
1049 >>> builder = x509.CertificateSigningRequestBuilder()
Andre Carona9a51172015-06-06 20:18:44 -04001050 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -05001051 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Andre Carond259ee52015-06-02 23:47:11 -04001052 ... ]))
Ian Cordascof06b6be2015-06-21 10:09:18 -05001053 >>> builder = builder.add_extension(
Ian Cordasco0112b022015-06-16 17:51:18 -05001054 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
Andre Caron472fd692015-06-06 20:04:44 -04001055 ... )
Andre Carond259ee52015-06-02 23:47:11 -04001056 >>> request = builder.sign(
Alex Gaynorde9e5842015-06-26 20:11:23 -04001057 ... private_key, hashes.SHA256(), default_backend()
Andre Carond259ee52015-06-02 23:47:11 -04001058 ... )
1059 >>> isinstance(request, x509.CertificateSigningRequest)
1060 True
1061
Andre Carona9a51172015-06-06 20:18:44 -04001062 .. method:: subject_name(name)
Andre Caron0ef595f2015-05-18 13:53:43 -04001063
Andre Caron341ff852015-06-06 20:14:31 -04001064 :param name: The :class:`~cryptography.x509.Name` of the certificate
1065 subject.
1066 :returns: A new
1067 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001068
Ian Cordascof06b6be2015-06-21 10:09:18 -05001069 .. method:: add_extension(extension, critical)
Andre Caron0ef595f2015-05-18 13:53:43 -04001070
Paul Kehrer2c145cc2015-10-02 11:27:21 -05001071 :param extension: An extension conforming to the
1072 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron472fd692015-06-06 20:04:44 -04001073 :param critical: Set to `True` if the extension must be understood and
1074 handled by whoever reads the certificate.
Andre Caron341ff852015-06-06 20:14:31 -04001075 :returns: A new
1076 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001077
Alex Gaynorb3b0fbe2015-06-26 19:57:18 -04001078 .. method:: sign(private_key, algorithm, backend)
Andre Caron0ef595f2015-05-18 13:53:43 -04001079
1080 :param backend: Backend that will be used to sign the request.
1081 Must support the
1082 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1083 interface.
1084
1085 :param private_key: The
Andre Caron24f9bf42015-06-06 20:14:54 -04001086 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
1087 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
1088 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
Andre Caron0ef595f2015-05-18 13:53:43 -04001089 that will be used to sign the request. When the request is
1090 signed by a certificate authority, the private key's associated
1091 public key will be stored in the resulting certificate.
1092
1093 :param algorithm: The
1094 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
1095 that will be used to generate the request signature.
1096
Andre Caron341ff852015-06-06 20:14:31 -04001097 :returns: A new
1098 :class:`~cryptography.x509.CertificateSigningRequest`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001099
1100
Paul Kehrer719d5362015-01-01 20:03:52 -06001101.. class:: Name
1102
1103 .. versionadded:: 0.8
1104
Paul Kehrer53d8d492015-02-13 18:47:30 -06001105 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -06001106 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -06001107 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -06001108 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
1109 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -06001110
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001111 Technically, a Name is a list of *sets* of attributes, called *Relative
1112 Distinguished Names* or *RDNs*, although multi-valued RDNs are rarely
1113 encountered. The iteration order of values within a multi-valued RDN is
1114 undefined. If you need to handle multi-valued RDNs, the ``rdns`` property
1115 gives access to an ordered list of :class:`RelativeDistinguishedName`
1116 objects.
1117
1118 A Name can be initialized with an iterable of :class:`NameAttribute` (the
1119 common case where each RDN has a single attribute) or an iterable of
1120 :class:`RelativeDistinguishedName` objects (in the rare case of
1121 multi-valued RDNs).
1122
Paul Kehrer53d8d492015-02-13 18:47:30 -06001123 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -06001124
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001125 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -06001126 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001127 >>> for attribute in cert.subject:
1128 ... print(attribute)
1129 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
1130 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')>
1131 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -06001132
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001133 .. attribute:: rdns
1134
1135 .. versionadded:: 1.6
1136
1137 :type: list of :class:`RelativeDistinguishedName`
1138
Paul Kehrere901d642015-02-11 18:50:58 -06001139 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -06001140
Paul Kehrere901d642015-02-11 18:50:58 -06001141 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -06001142
Paul Kehrere901d642015-02-11 18:50:58 -06001143 :returns: A list of :class:`NameAttribute` instances that match the
1144 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -06001145
1146 .. doctest::
1147
Paul Kehrere27f6582015-08-10 18:33:38 -05001148 >>> cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)
Paul Kehrere901d642015-02-11 18:50:58 -06001149 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -06001150
Paul Kehrer3a15b032016-11-13 14:30:11 -08001151 .. method:: public_bytes(backend)
1152
1153 .. versionadded:: 1.6
1154
1155 :param backend: A backend supporting the
1156 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1157 interface.
1158
1159 :return bytes: The DER encoded name.
1160
Paul Kehrere76cd272014-12-14 19:00:51 -06001161.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -10001162
1163 .. versionadded:: 0.7
1164
1165 An enumeration for X.509 versions.
1166
1167 .. attribute:: v1
1168
1169 For version 1 X.509 certificates.
1170
1171 .. attribute:: v3
1172
1173 For version 3 X.509 certificates.
1174
Paul Kehrer806bfb22015-02-02 17:05:24 -06001175.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001176
1177 .. versionadded:: 0.8
1178
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001179 An X.509 name consists of a list of :class:`RelativeDistinguishedName`
1180 instances, which consist of a set of :class:`NameAttribute` instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001181
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001182 .. attribute:: oid
1183
1184 :type: :class:`ObjectIdentifier`
1185
1186 The attribute OID.
1187
1188 .. attribute:: value
1189
Paul Kehrerd5852cb2015-01-30 08:25:23 -06001190 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001191
1192 The value of the attribute.
1193
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001194
1195.. class:: RelativeDistinguishedName(attributes)
1196
1197 .. versionadded:: 1.6
1198
1199 A relative distinguished name is a non-empty set of name attributes. The
1200 object is iterable to get every attribute.
1201
1202 .. method:: get_attributes_for_oid(oid)
1203
1204 :param oid: An :class:`ObjectIdentifier` instance.
1205
1206 :returns: A list of :class:`NameAttribute` instances that match the OID
1207 provided. The list should contain zero or one values.
1208
1209
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001210.. class:: ObjectIdentifier
1211
1212 .. versionadded:: 0.8
1213
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001214 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -06001215 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001216
Paul Kehrerd44f9a62015-02-04 14:47:34 -06001217 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001218
1219 :type: :class:`str`
1220
Paul Kehrerfedf4f42015-02-06 11:22:07 -06001221 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001222
Paul Kehrer31bdf792015-03-25 14:11:00 -05001223.. _general_name_classes:
1224
1225General Name Classes
1226~~~~~~~~~~~~~~~~~~~~
1227
1228.. class:: GeneralName
1229
1230 .. versionadded:: 0.9
1231
1232 This is the generic interface that all the following classes are registered
1233 against.
1234
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001235.. class:: RFC822Name(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001236
1237 .. versionadded:: 0.9
1238
1239 This corresponds to an email address. For example, ``user@example.com``.
1240
1241 .. attribute:: value
1242
1243 :type: :term:`text`
1244
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001245.. class:: DNSName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001246
1247 .. versionadded:: 0.9
1248
1249 This corresponds to a domain name. For example, ``cryptography.io``.
1250
1251 .. attribute:: value
1252
1253 :type: :term:`text`
1254
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001255.. class:: DirectoryName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001256
1257 .. versionadded:: 0.9
1258
1259 This corresponds to a directory name.
1260
1261 .. attribute:: value
1262
1263 :type: :class:`Name`
1264
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001265.. class:: UniformResourceIdentifier(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001266
1267 .. versionadded:: 0.9
1268
1269 This corresponds to a uniform resource identifier. For example,
Paul Kehrerb8ef82e2015-04-22 16:04:24 -05001270 ``https://cryptography.io``. The URI is parsed and IDNA decoded (see
1271 :rfc:`5895`).
1272
1273 .. note::
1274
1275 URIs that do not contain ``://`` in them will not be decoded.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001276
1277 .. attribute:: value
1278
1279 :type: :term:`text`
1280
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001281.. class:: IPAddress(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001282
1283 .. versionadded:: 0.9
1284
1285 This corresponds to an IP address.
1286
1287 .. attribute:: value
1288
Paul Kehrereb177932015-05-17 18:33:33 -07001289 :type: :class:`~ipaddress.IPv4Address`,
1290 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
1291 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001292
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001293.. class:: RegisteredID(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001294
1295 .. versionadded:: 0.9
1296
1297 This corresponds to a registered ID.
1298
1299 .. attribute:: value
1300
1301 :type: :class:`ObjectIdentifier`
1302
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001303.. class:: OtherName(type_id, value)
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001304
1305 .. versionadded:: 1.0
1306
Joshua Tauberer18b6fc82015-07-05 21:44:51 +00001307 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 +00001308
1309 .. attribute:: type_id
1310
1311 :type: :class:`ObjectIdentifier`
1312
1313 .. attribute:: value
1314
1315 :type: `bytes`
1316
Paul Kehrer8cf26422015-03-21 09:50:24 -05001317X.509 Extensions
1318~~~~~~~~~~~~~~~~
1319
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001320.. class:: Extensions
1321
1322 .. versionadded:: 0.9
1323
1324 An X.509 Extensions instance is an ordered list of extensions. The object
1325 is iterable to get every extension.
1326
Paul Kehrerfa56a232015-03-17 13:14:03 -05001327 .. method:: get_extension_for_oid(oid)
1328
1329 :param oid: An :class:`ObjectIdentifier` instance.
1330
1331 :returns: An instance of the extension class.
1332
1333 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1334 not have the extension requested.
1335
Paul Kehrerfa56a232015-03-17 13:14:03 -05001336 .. doctest::
1337
Paul Kehrere27f6582015-08-10 18:33:38 -05001338 >>> from cryptography.x509.oid import ExtensionOID
1339 >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS)
Paul Kehrerfa56a232015-03-17 13:14:03 -05001340 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1341
Phoebe Queen019b7f82015-08-12 03:52:03 +01001342 .. method:: get_extension_for_class(extclass)
1343
Phoebe Queen6a603eb2015-08-12 14:14:49 +01001344 .. versionadded:: 1.1
1345
Phoebe Queen019b7f82015-08-12 03:52:03 +01001346 :param extclass: An extension class.
1347
1348 :returns: An instance of the extension class.
1349
1350 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1351 not have the extension requested.
1352
1353 .. doctest::
1354
1355 >>> from cryptography import x509
1356 >>> cert.extensions.get_extension_for_class(x509.BasicConstraints)
1357 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1358
Paul Kehrer8cf26422015-03-21 09:50:24 -05001359.. class:: Extension
1360
1361 .. versionadded:: 0.9
1362
Paul Kehrer85894662015-03-22 13:19:31 -05001363 .. attribute:: oid
1364
1365 :type: :class:`ObjectIdentifier`
1366
Paul Kehrere27f6582015-08-10 18:33:38 -05001367 One of the :class:`~cryptography.x509.oid.ExtensionOID` OIDs.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001368
1369 .. attribute:: critical
1370
1371 :type: bool
1372
Paul Kehrer58b75692015-03-22 23:24:58 -05001373 Determines whether a given extension is critical or not. :rfc:`5280`
1374 requires that "A certificate-using system MUST reject the certificate
1375 if it encounters a critical extension it does not recognize or a
1376 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -05001377
Paul Kehrer85894662015-03-22 13:19:31 -05001378 .. attribute:: value
1379
1380 Returns an instance of the extension type corresponding to the OID.
1381
Paul Kehrer14f0bd02015-08-06 11:55:18 +01001382.. class:: ExtensionType
1383
1384 .. versionadded:: 1.0
1385
1386 This is the interface against which all the following extension types are
1387 registered.
1388
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001389.. 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 -05001390
1391 .. versionadded:: 0.9
1392
1393 The key usage extension defines the purpose of the key contained in the
1394 certificate. The usage restriction might be employed when a key that could
Paul Kehrerb33de932015-08-06 23:41:05 +01001395 be used for more than one operation is to be restricted.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001396
Paul Kehrer822f3d32015-08-06 11:47:32 +01001397 .. attribute:: oid
1398
1399 .. versionadded:: 1.0
1400
1401 :type: :class:`ObjectIdentifier`
1402
Paul Kehrere27f6582015-08-10 18:33:38 -05001403 Returns :attr:`~cryptography.x509.oid.ExtensionOID.KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001404
Paul Kehrercecbbba2015-03-30 14:58:38 -05001405 .. attribute:: digital_signature
1406
1407 :type: bool
1408
Paul Kehrer738407b2015-04-01 22:39:02 -05001409 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001410 digital signatures, other than signatures on certificates
1411 (``key_cert_sign``) and CRLs (``crl_sign``).
1412
1413 .. attribute:: content_commitment
1414
1415 :type: bool
1416
Paul Kehrer738407b2015-04-01 22:39:02 -05001417 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001418 digital signatures, other than signatures on certificates
1419 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
1420 non-repudiation service that protects against the signing entity
1421 falsely denying some action. In the case of later conflict, a
1422 reliable third party may determine the authenticity of the signed
1423 data. This was called ``non_repudiation`` in older revisions of the
1424 X.509 specification.
1425
1426 .. attribute:: key_encipherment
1427
1428 :type: bool
1429
Paul Kehrer738407b2015-04-01 22:39:02 -05001430 This purpose is set to true when the subject public key is used for
1431 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001432
1433 .. attribute:: data_encipherment
1434
1435 :type: bool
1436
Paul Kehrer738407b2015-04-01 22:39:02 -05001437 This purpose is set to true when the subject public key is used for
1438 directly enciphering raw user data without the use of an intermediate
1439 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001440
1441 .. attribute:: key_agreement
1442
1443 :type: bool
1444
Paul Kehrer738407b2015-04-01 22:39:02 -05001445 This purpose is set to true when the subject public key is used for key
1446 agreement. For example, when a Diffie-Hellman key is to be used for
1447 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001448
1449 .. attribute:: key_cert_sign
1450
1451 :type: bool
1452
Paul Kehrer738407b2015-04-01 22:39:02 -05001453 This purpose is set to true when the subject public key is used for
1454 verifying signatures on public key certificates. If this purpose is set
1455 to true then ``ca`` must be true in the :class:`BasicConstraints`
1456 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001457
1458 .. attribute:: crl_sign
1459
1460 :type: bool
1461
Paul Kehrer738407b2015-04-01 22:39:02 -05001462 This purpose is set to true when the subject public key is used for
1463 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001464
1465 .. attribute:: encipher_only
1466
1467 :type: bool
1468
Paul Kehrer738407b2015-04-01 22:39:02 -05001469 When this purposes is set to true and the ``key_agreement`` purpose is
1470 also set, the subject public key may be used only for enciphering data
1471 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001472
1473 :raises ValueError: This is raised if accessed when ``key_agreement``
1474 is false.
1475
1476 .. attribute:: decipher_only
1477
1478 :type: bool
1479
Paul Kehrer738407b2015-04-01 22:39:02 -05001480 When this purposes is set to true and the ``key_agreement`` purpose is
1481 also set, the subject public key may be used only for deciphering data
1482 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001483
1484 :raises ValueError: This is raised if accessed when ``key_agreement``
1485 is false.
1486
1487
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001488.. class:: BasicConstraints(ca, path_length)
Paul Kehrer8cf26422015-03-21 09:50:24 -05001489
1490 .. versionadded:: 0.9
1491
Paul Kehrer85894662015-03-22 13:19:31 -05001492 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -05001493 certificate is allowed to sign additional certificates and what path
Paul Kehrerb33de932015-08-06 23:41:05 +01001494 length restrictions may exist.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001495
Paul Kehrer822f3d32015-08-06 11:47:32 +01001496 .. attribute:: oid
1497
1498 .. versionadded:: 1.0
1499
1500 :type: :class:`ObjectIdentifier`
1501
Paul Kehrere27f6582015-08-10 18:33:38 -05001502 Returns :attr:`~cryptography.x509.oid.ExtensionOID.BASIC_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001503
Paul Kehrer8cf26422015-03-21 09:50:24 -05001504 .. attribute:: ca
1505
1506 :type: bool
1507
1508 Whether the certificate can sign certificates.
1509
1510 .. attribute:: path_length
1511
Paul Kehrerfd1444c2015-03-21 19:47:05 -05001512 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -05001513
1514 The maximum path length for certificates subordinate to this
1515 certificate. This attribute only has meaning if ``ca`` is true.
1516 If ``ca`` is true then a path length of None means there's no
1517 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -04001518 If it is zero or greater then it defines the maximum length for a
1519 subordinate CA's certificate chain. For example, a ``path_length`` of 1
1520 means the certificate can sign a subordinate CA, but the subordinate CA
1521 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001522
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001523.. class:: ExtendedKeyUsage(usages)
Paul Kehrerffa2a152015-03-31 08:18:25 -05001524
1525 .. versionadded:: 0.9
1526
1527 This extension indicates one or more purposes for which the certified
1528 public key may be used, in addition to or in place of the basic
1529 purposes indicated in the key usage extension. The object is
Paul Kehrere27f6582015-08-10 18:33:38 -05001530 iterable to obtain the list of
1531 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs present.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001532
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001533 :param list usages: A list of
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001534 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs.
1535
Paul Kehrer822f3d32015-08-06 11:47:32 +01001536 .. attribute:: oid
1537
1538 .. versionadded:: 1.0
1539
1540 :type: :class:`ObjectIdentifier`
1541
Paul Kehrere27f6582015-08-10 18:33:38 -05001542 Returns :attr:`~cryptography.x509.oid.ExtensionOID.EXTENDED_KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001543
1544
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001545.. class:: OCSPNoCheck()
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001546
Paul Kehrer506a2152015-05-26 08:01:18 -05001547 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001548
1549 This presence of this extension indicates that an OCSP client can trust a
1550 responder for the lifetime of the responder's certificate. CAs issuing
1551 such a certificate should realize that a compromise of the responder's key
1552 is as serious as the compromise of a CA key used to sign CRLs, at least for
1553 the validity period of this certificate. CA's may choose to issue this type
1554 of certificate with a very short lifetime and renew it frequently. This
1555 extension is only relevant when the certificate is an authorized OCSP
1556 responder.
1557
Paul Kehrer822f3d32015-08-06 11:47:32 +01001558 .. attribute:: oid
1559
1560 .. versionadded:: 1.0
1561
1562 :type: :class:`ObjectIdentifier`
1563
Paul Kehrere27f6582015-08-10 18:33:38 -05001564 Returns :attr:`~cryptography.x509.oid.ExtensionOID.OCSP_NO_CHECK`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001565
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001566.. class:: NameConstraints(permitted_subtrees, excluded_subtrees)
Paul Kehrere0017be2015-05-17 20:39:40 -06001567
1568 .. versionadded:: 1.0
1569
1570 The name constraints extension, which only has meaning in a CA certificate,
1571 defines a name space within which all subject names in certificates issued
1572 beneath the CA certificate must (or must not) be in. For specific details
1573 on the way this extension should be processed see :rfc:`5280`.
1574
Paul Kehrer822f3d32015-08-06 11:47:32 +01001575 .. attribute:: oid
1576
1577 .. versionadded:: 1.0
1578
1579 :type: :class:`ObjectIdentifier`
1580
Paul Kehrere27f6582015-08-10 18:33:38 -05001581 Returns :attr:`~cryptography.x509.oid.ExtensionOID.NAME_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001582
Paul Kehrere0017be2015-05-17 20:39:40 -06001583 .. attribute:: permitted_subtrees
1584
1585 :type: list of :class:`GeneralName` objects or None
1586
1587 The set of permitted name patterns. If a name matches this and an
1588 element in ``excluded_subtrees`` it is invalid. At least one of
1589 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
1590
1591 .. attribute:: excluded_subtrees
1592
1593 :type: list of :class:`GeneralName` objects or None
1594
1595 Any name matching a restriction in the ``excluded_subtrees`` field is
1596 invalid regardless of information appearing in the
1597 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
1598 ``excluded_subtrees`` will be non-None.
1599
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001600.. class:: AuthorityKeyIdentifier(key_identifier, authority_cert_issuer, authority_cert_serial_number)
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001601
1602 .. versionadded:: 0.9
1603
1604 The authority key identifier extension provides a means of identifying the
1605 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001606 This extension is typically used to assist in determining the appropriate
1607 certificate chain. For more information about generation and use of this
1608 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001609
Paul Kehrer822f3d32015-08-06 11:47:32 +01001610 .. attribute:: oid
1611
1612 .. versionadded:: 1.0
1613
1614 :type: :class:`ObjectIdentifier`
1615
Paul Kehrere27f6582015-08-10 18:33:38 -05001616 Returns
1617 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001618
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001619 .. attribute:: key_identifier
1620
1621 :type: bytes
1622
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001623 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001624 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001625
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001626 .. attribute:: authority_cert_issuer
1627
1628 :type: :class:`Name` or None
1629
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001630 The :class:`Name` of the issuer's issuer.
1631
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001632 .. attribute:: authority_cert_serial_number
1633
1634 :type: int or None
1635
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001636 The serial number of the issuer's issuer.
1637
Paul Kehrer253929a2015-08-05 17:30:39 +01001638 .. classmethod:: from_issuer_public_key(public_key)
1639
1640 .. versionadded:: 1.0
1641
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001642 .. note::
1643
1644 This method should be used if the issuer certificate does not
1645 contain a :class:`~cryptography.x509.SubjectKeyIdentifier`.
1646 Otherwise, use
1647 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier`.
1648
Paul Kehrer253929a2015-08-05 17:30:39 +01001649 Creates a new AuthorityKeyIdentifier instance using the public key
1650 provided to generate the appropriate digest. This should be the
Paul Kehrer26ac47f2015-08-08 15:20:52 -05001651 **issuer's public key**. The resulting object will contain
1652 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1653 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1654 and
1655 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1656 will be None.
1657 The generated ``key_identifier`` is the SHA1 hash of the ``subjectPublicKey``
1658 ASN.1 bit string. This is the first recommendation in :rfc:`5280`
Paul Kehrer253929a2015-08-05 17:30:39 +01001659 section 4.2.1.2.
1660
Paul Kehrercc671822015-08-08 15:41:54 -05001661 :param public_key: One of
1662 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1663 ,
1664 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1665 , or
1666 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
Paul Kehrer253929a2015-08-05 17:30:39 +01001667
1668 .. doctest::
1669
1670 >>> from cryptography import x509
1671 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001672 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1673 >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key())
Paul Kehrer253929a2015-08-05 17:30:39 +01001674 <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)>
1675
Paul Kehrer61ff3562016-03-11 22:51:27 -04001676 .. classmethod:: from_issuer_subject_key_identifier(ski)
1677
1678 .. versionadded:: 1.3
1679
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001680 .. note::
1681 This method should be used if the issuer certificate contains a
1682 :class:`~cryptography.x509.SubjectKeyIdentifier`. Otherwise, use
1683 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_public_key`.
1684
Paul Kehrer61ff3562016-03-11 22:51:27 -04001685 Creates a new AuthorityKeyIdentifier instance using the
1686 SubjectKeyIdentifier from the issuer certificate. The resulting object
1687 will contain
1688 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1689 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1690 and
1691 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1692 will be None.
1693
1694 :param ski: The
1695 :class:`~cryptography.x509.SubjectKeyIdentifier` from the issuer
1696 certificate.
1697
1698 .. doctest::
1699
1700 >>> from cryptography import x509
1701 >>> from cryptography.hazmat.backends import default_backend
1702 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1703 >>> ski = issuer_cert.extensions.get_extension_for_class(x509.SubjectKeyIdentifier)
1704 >>> x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(ski)
1705 <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)>
1706
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001707.. class:: SubjectKeyIdentifier(digest)
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001708
1709 .. versionadded:: 0.9
1710
1711 The subject key identifier extension provides a means of identifying
1712 certificates that contain a particular public key.
1713
Paul Kehrer822f3d32015-08-06 11:47:32 +01001714 .. attribute:: oid
1715
1716 .. versionadded:: 1.0
1717
1718 :type: :class:`ObjectIdentifier`
1719
Paul Kehrere27f6582015-08-10 18:33:38 -05001720 Returns
1721 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001722
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001723 .. attribute:: digest
1724
1725 :type: bytes
1726
1727 The binary value of the identifier.
1728
Paul Kehrerd4a7f062015-08-05 18:32:18 +01001729 .. classmethod:: from_public_key(public_key)
Paul Kehrerf22f6122015-08-05 12:57:13 +01001730
1731 .. versionadded:: 1.0
1732
1733 Creates a new SubjectKeyIdentifier instance using the public key
1734 provided to generate the appropriate digest. This should be the public
Paul Kehrereb9ec002015-08-08 10:03:02 -05001735 key that is in the certificate. The generated digest is the SHA1 hash
1736 of the ``subjectPublicKey`` ASN.1 bit string. This is the first
1737 recommendation in :rfc:`5280` section 4.2.1.2.
Paul Kehrerf22f6122015-08-05 12:57:13 +01001738
1739 :param public_key: One of
1740 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1741 ,
1742 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1743 , or
1744 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
1745
Paul Kehrer253929a2015-08-05 17:30:39 +01001746 .. doctest::
1747
1748 >>> from cryptography import x509
1749 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001750 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
1751 >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key())
1752 <SubjectKeyIdentifier(digest='\xdb\xaa\xf0\x06\x11\xdbD\xfe\xbf\x93\x03\x8av\x88WP7\xa6\x91\xf7')>
Paul Kehrer253929a2015-08-05 17:30:39 +01001753
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001754.. class:: SubjectAlternativeName(general_names)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001755
1756 .. versionadded:: 0.9
1757
1758 Subject alternative name is an X.509 extension that provides a list of
1759 :ref:`general name <general_name_classes>` instances that provide a set
1760 of identities for which the certificate is valid. The object is iterable to
1761 get every element.
1762
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001763 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001764
Paul Kehrer822f3d32015-08-06 11:47:32 +01001765 .. attribute:: oid
1766
1767 .. versionadded:: 1.0
1768
1769 :type: :class:`ObjectIdentifier`
1770
Paul Kehrere27f6582015-08-10 18:33:38 -05001771 Returns
1772 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001773
Paul Kehrer31bdf792015-03-25 14:11:00 -05001774 .. method:: get_values_for_type(type)
1775
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03001776 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer31bdf792015-03-25 14:11:00 -05001777 :ref:`general name classes <general_name_classes>`.
1778
1779 :returns: A list of values extracted from the matched general names.
Joshua Taubererd2afad32015-07-06 22:37:53 +00001780 The type of the returned values depends on the :class:`GeneralName`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001781
Paul Kehrer93ae8052015-05-02 23:18:09 -05001782 .. doctest::
1783
1784 >>> from cryptography import x509
1785 >>> from cryptography.hazmat.backends import default_backend
1786 >>> from cryptography.hazmat.primitives import hashes
1787 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001788 >>> # Get the subjectAltName extension from the certificate
Paul Kehrere27f6582015-08-10 18:33:38 -05001789 >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001790 >>> # Get the dNSName entries from the SAN extension
1791 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer93ae8052015-05-02 23:18:09 -05001792 [u'www.cryptography.io', u'cryptography.io']
1793
Paul Kehrer8cf26422015-03-21 09:50:24 -05001794
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001795.. class:: IssuerAlternativeName(general_names)
Paul Kehrer99125c92015-06-07 18:37:10 -05001796
1797 .. versionadded:: 1.0
1798
1799 Issuer alternative name is an X.509 extension that provides a list of
1800 :ref:`general name <general_name_classes>` instances that provide a set
1801 of identities for the certificate issuer. The object is iterable to
1802 get every element.
1803
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001804 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001805
Paul Kehrer822f3d32015-08-06 11:47:32 +01001806 .. attribute:: oid
1807
1808 .. versionadded:: 1.0
1809
1810 :type: :class:`ObjectIdentifier`
1811
Paul Kehrere27f6582015-08-10 18:33:38 -05001812 Returns
1813 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUER_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001814
Paul Kehrer99125c92015-06-07 18:37:10 -05001815 .. method:: get_values_for_type(type)
1816
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03001817 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer99125c92015-06-07 18:37:10 -05001818 :ref:`general name classes <general_name_classes>`.
1819
1820 :returns: A list of values extracted from the matched general names.
1821
1822
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001823.. class:: AuthorityInformationAccess(descriptions)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001824
1825 .. versionadded:: 0.9
1826
1827 The authority information access extension indicates how to access
1828 information and services for the issuer of the certificate in which
1829 the extension appears. Information and services may include online
1830 validation services (such as OCSP) and issuer data. It is an iterable,
Paul Kehrere27f6582015-08-10 18:33:38 -05001831 containing one or more :class:`~cryptography.x509.AccessDescription`
1832 instances.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001833
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001834 :param list descriptions: A list of :class:`AccessDescription` objects.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001835
Paul Kehrer822f3d32015-08-06 11:47:32 +01001836 .. attribute:: oid
1837
1838 .. versionadded:: 1.0
1839
1840 :type: :class:`ObjectIdentifier`
1841
Paul Kehrere27f6582015-08-10 18:33:38 -05001842 Returns
1843 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_INFORMATION_ACCESS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001844
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001845
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001846.. class:: AccessDescription(access_method, access_location)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001847
Paul Kehrer5a485522015-05-06 00:29:12 -05001848 .. versionadded:: 0.9
1849
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001850 .. attribute:: access_method
1851
1852 :type: :class:`ObjectIdentifier`
1853
Paul Kehrerf506bca2015-05-02 22:31:47 -05001854 The access method defines what the ``access_location`` means. It must
Paul Kehrere27f6582015-08-10 18:33:38 -05001855 be either
1856 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` or
1857 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`.
1858 If it is
1859 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP`
1860 the access location will be where to obtain OCSP
1861 information for the certificate. If it is
1862 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`
1863 the access location will provide additional information about the
1864 issuing certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001865
1866 .. attribute:: access_location
1867
1868 :type: :class:`GeneralName`
1869
Paul Kehrerf506bca2015-05-02 22:31:47 -05001870 Where to access the information defined by the access method.
1871
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001872.. class:: CRLDistributionPoints(distribution_points)
Paul Kehrer5a485522015-05-06 00:29:12 -05001873
1874 .. versionadded:: 0.9
1875
1876 The CRL distribution points extension identifies how CRL information is
1877 obtained. It is an iterable, containing one or more
1878 :class:`DistributionPoint` instances.
1879
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001880 :param list distribution_points: A list of :class:`DistributionPoint`
1881 instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001882
Paul Kehrer822f3d32015-08-06 11:47:32 +01001883 .. attribute:: oid
1884
1885 .. versionadded:: 1.0
1886
1887 :type: :class:`ObjectIdentifier`
1888
Paul Kehrere27f6582015-08-10 18:33:38 -05001889 Returns
1890 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_DISTRIBUTION_POINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001891
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001892.. class:: DistributionPoint(full_name, relative_name, reasons, crl_issuer)
Paul Kehrer5a485522015-05-06 00:29:12 -05001893
1894 .. versionadded:: 0.9
1895
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001896 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05001897
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001898 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001899
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001900 This field describes methods to retrieve the CRL. At most one of
1901 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001902
1903 .. attribute:: relative_name
1904
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001905 :type: :class:`RelativeDistinguishedName` or None
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001906
1907 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001908 issuer. At most one of ``full_name`` or ``relative_name`` will be
1909 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05001910
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001911 .. versionchanged:: 1.6
1912 Changed from :class:`Name` to :class:`RelativeDistinguishedName`.
1913
Paul Kehrer5a485522015-05-06 00:29:12 -05001914 .. attribute:: crl_issuer
1915
1916 :type: list of :class:`GeneralName` instances or None
1917
1918 Information about the issuer of the CRL.
1919
1920 .. attribute:: reasons
1921
Paul Kehrer3fd02602015-05-09 19:46:13 -05001922 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001923
1924 The reasons a given distribution point may be used for when performing
1925 revocation checks.
1926
1927.. class:: ReasonFlags
1928
1929 .. versionadded:: 0.9
1930
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001931 An enumeration for CRL reasons.
1932
1933 .. attribute:: unspecified
1934
1935 It is unspecified why the certificate was revoked. This reason cannot
1936 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001937
1938 .. attribute:: key_compromise
1939
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001940 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001941
1942 .. attribute:: ca_compromise
1943
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001944 This reason indicates that the CA issuing the certificate was
1945 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001946
1947 .. attribute:: affiliation_changed
1948
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001949 This reason indicates that the subject's name or other information has
1950 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05001951
1952 .. attribute:: superseded
1953
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001954 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05001955
1956 .. attribute:: cessation_of_operation
1957
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001958 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05001959
1960 .. attribute:: certificate_hold
1961
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001962 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05001963
1964 .. attribute:: privilege_withdrawn
1965
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001966 This reason indicates that the privilege granted by this certificate
1967 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05001968
1969 .. attribute:: aa_compromise
1970
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001971 When an attribute authority has been compromised.
1972
1973 .. attribute:: remove_from_crl
1974
1975 This reason indicates that the certificate was on hold and should be
1976 removed from the CRL. This reason cannot be used as a reason flag
1977 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001978
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001979.. class:: InhibitAnyPolicy(skip_certs)
Paul Kehrer16fae762015-05-01 23:14:20 -05001980
1981 .. versionadded:: 1.0
1982
1983 The inhibit ``anyPolicy`` extension indicates that the special OID
Paul Kehrere27f6582015-08-10 18:33:38 -05001984 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY`, is not
1985 considered an explicit match for other :class:`CertificatePolicies` except
1986 when it appears in an intermediate self-issued CA certificate. The value
1987 indicates the number of additional non-self-issued certificates that may
1988 appear in the path before
1989 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` is no
1990 longer permitted. For example, a value of one indicates that
1991 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` may be
1992 processed in certificates issued by the subject of this certificate, but
1993 not in additional certificates in the path.
Paul Kehrer16fae762015-05-01 23:14:20 -05001994
Paul Kehrer822f3d32015-08-06 11:47:32 +01001995 .. attribute:: oid
1996
1997 .. versionadded:: 1.0
1998
1999 :type: :class:`ObjectIdentifier`
2000
Paul Kehrere27f6582015-08-10 18:33:38 -05002001 Returns
2002 :attr:`~cryptography.x509.oid.ExtensionOID.INHIBIT_ANY_POLICY`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002003
Paul Kehrer16fae762015-05-01 23:14:20 -05002004 .. attribute:: skip_certs
2005
2006 :type: int
2007
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002008.. class:: PolicyConstraints
2009
2010 .. versionadded:: 1.3
2011
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002012 The policy constraints extension is used to inhibit policy mapping or
2013 require that each certificate in a chain contain an acceptable policy
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002014 identifier. For more information about the use of this extension see
2015 :rfc:`5280`.
2016
Paul Kehrer159b3b52016-02-26 08:27:22 -06002017 .. attribute:: oid
2018
2019 :type: :class:`ObjectIdentifier`
2020
2021 Returns :attr:`~cryptography.x509.oid.ExtensionOID.POLICY_CONSTRAINTS`.
2022
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002023 .. attribute:: require_explicit_policy
2024
2025 :type: int or None
2026
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002027 If this field is not None, the value indicates the number of additional
2028 certificates that may appear in the chain before an explicit policy is
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002029 required for the entire path. When an explicit policy is required, it
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002030 is necessary for all certificates in the chain to contain an acceptable
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002031 policy identifier in the certificate policies extension. An
2032 acceptable policy identifier is the identifier of a policy required
2033 by the user of the certification path or the identifier of a policy
2034 that has been declared equivalent through policy mapping.
2035
2036 .. attribute:: inhibit_policy_mapping
2037
2038 :type: int or None
2039
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002040 If this field is not None, the value indicates the number of additional
2041 certificates that may appear in the chain before policy mapping is no
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002042 longer permitted. For example, a value of one indicates that policy
2043 mapping may be processed in certificates issued by the subject of this
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002044 certificate, but not in additional certificates in the chain.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002045
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002046.. class:: CRLNumber(crl_number)
2047
2048 .. versionadded:: 1.2
2049
Paul Kehrere32b9942015-12-22 22:26:53 -06002050 The CRL number is a CRL extension that conveys a monotonically increasing
2051 sequence number for a given CRL scope and CRL issuer. This extension allows
2052 users to easily determine when a particular CRL supersedes another CRL.
2053 :rfc:`5280` requires that this extension be present in conforming CRLs.
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002054
2055 .. attribute:: oid
2056
2057 :type: :class:`ObjectIdentifier`
2058
2059 Returns
2060 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_NUMBER`.
2061
2062 .. attribute:: crl_number
2063
2064 :type: int
2065
Paul Kehrer14fd6972015-12-30 10:58:25 -06002066.. class:: UnrecognizedExtension
2067
2068 .. versionadded:: 1.2
2069
2070 A generic extension class used to hold the raw value of **non-critical**
2071 extensions that ``cryptography`` does not know how to parse. Extensions
Paul Kehrer1628b5c2015-12-30 14:59:44 -06002072 marked critical will raise
Paul Kehrer14fd6972015-12-30 10:58:25 -06002073 :class:`~cryptography.x509.UnsupportedExtension`.
2074
2075 .. attribute:: oid
2076
2077 :type: :class:`ObjectIdentifier`
2078
2079 Returns the OID associated with this extension.
2080
2081 .. attribute:: value
2082
2083 :type: byte
2084
2085 Returns the DER encoded bytes payload of the extension.
2086
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002087.. class:: CertificatePolicies(policies)
Paul Kehrer0d210922015-04-28 17:31:07 -05002088
2089 .. versionadded:: 0.9
2090
Paul Kehrer2e879742015-05-02 23:09:56 -05002091 The certificate policies extension is an iterable, containing one or more
2092 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05002093
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002094 :param list policies: A list of :class:`PolicyInformation` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002095
Paul Kehrer822f3d32015-08-06 11:47:32 +01002096 .. attribute:: oid
2097
2098 .. versionadded:: 1.0
2099
2100 :type: :class:`ObjectIdentifier`
2101
Paul Kehrere27f6582015-08-10 18:33:38 -05002102 Returns
2103 :attr:`~cryptography.x509.oid.ExtensionOID.CERTIFICATE_POLICIES`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002104
Paul Kehrer0d210922015-04-28 17:31:07 -05002105Certificate Policies Classes
2106~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2107
2108These classes may be present within a :class:`CertificatePolicies` instance.
2109
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002110.. class:: PolicyInformation(policy_identifier, policy_qualifiers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002111
2112 .. versionadded:: 0.9
2113
2114 Contains a policy identifier and an optional list of qualifiers.
2115
2116 .. attribute:: policy_identifier
2117
2118 :type: :class:`ObjectIdentifier`
2119
2120 .. attribute:: policy_qualifiers
2121
2122 :type: list
2123
Paul Kehrerba35b3b2015-05-10 13:07:59 -05002124 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002125 If the value is text it is a pointer to the practice statement
2126 published by the certificate authority. If it is a user notice it is
2127 meant for display to the relying party when the certificate is
2128 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05002129
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002130.. class:: UserNotice(notice_reference, explicit_text)
Paul Kehrer0d210922015-04-28 17:31:07 -05002131
2132 .. versionadded:: 0.9
2133
Paul Kehrer2e879742015-05-02 23:09:56 -05002134 User notices are intended for display to a relying party when a certificate
2135 is used. In practice, few if any UIs expose this data and it is a rarely
2136 encoded component.
2137
Paul Kehrer0d210922015-04-28 17:31:07 -05002138 .. attribute:: notice_reference
2139
2140 :type: :class:`NoticeReference` or None
2141
Paul Kehrer2e879742015-05-02 23:09:56 -05002142 The notice reference field names an organization and identifies,
2143 by number, a particular statement prepared by that organization.
2144
Paul Kehrer0d210922015-04-28 17:31:07 -05002145 .. attribute:: explicit_text
2146
Paul Kehrer2e879742015-05-02 23:09:56 -05002147 This field includes an arbitrary textual statement directly in the
2148 certificate.
2149
Paul Kehrer0d210922015-04-28 17:31:07 -05002150 :type: :term:`text`
2151
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002152.. class:: NoticeReference(organization, notice_numbers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002153
Paul Kehrer2e879742015-05-02 23:09:56 -05002154 Notice reference can name an organization and provide information about
2155 notices related to the certificate. For example, it might identify the
2156 organization name and notice number 1. Application software could
2157 have a notice file containing the current set of notices for the named
2158 organization; the application would then extract the notice text from the
2159 file and display it. In practice this is rarely seen.
2160
Paul Kehrer0d210922015-04-28 17:31:07 -05002161 .. versionadded:: 0.9
2162
2163 .. attribute:: organization
2164
Paul Kehrer66c61702015-05-12 16:39:18 -05002165 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05002166
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002167 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05002168
Paul Kehrer66c61702015-05-12 16:39:18 -05002169 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05002170
Paul Kehrer66c61702015-05-12 16:39:18 -05002171 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05002172
Paul Kehrere5f152b2015-12-25 23:55:47 -06002173.. _crl_entry_extensions:
2174
Paul Kehrer49bb7562015-12-25 16:17:40 -06002175CRL Entry Extensions
2176~~~~~~~~~~~~~~~~~~~~
2177
2178These extensions are only valid within a :class:`RevokedCertificate` object.
2179
2180.. class:: CertificateIssuer(general_names)
2181
2182 .. versionadded:: 1.2
2183
2184 The certificate issuer is an extension that is only valid inside
2185 :class:`~cryptography.x509.RevokedCertificate` objects. If the
2186 ``indirectCRL`` property of the parent CRL's IssuingDistributionPoint
2187 extension is set, then this extension identifies the certificate issuer
2188 associated with the revoked certificate. The object is iterable to get
2189 every element.
2190
2191 :param list general_names: A list of :class:`GeneralName` instances.
2192
2193 .. attribute:: oid
2194
2195 :type: :class:`ObjectIdentifier`
2196
2197 Returns
2198 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CERTIFICATE_ISSUER`.
2199
2200 .. method:: get_values_for_type(type)
2201
2202 :param type: A :class:`GeneralName` instance. This is one of the
2203 :ref:`general name classes <general_name_classes>`.
2204
2205 :returns: A list of values extracted from the matched general names.
2206 The type of the returned values depends on the :class:`GeneralName`.
2207
Paul Kehrer7058ece2015-12-25 22:28:29 -06002208.. class:: CRLReason(reason)
2209
2210 .. versionadded:: 1.2
2211
2212 CRL reason (also known as ``reasonCode``) is an extension that is only
2213 valid inside :class:`~cryptography.x509.RevokedCertificate` objects. It
2214 identifies a reason for the certificate revocation.
2215
2216 :param reason: A value from the
2217 :class:`~cryptography.x509.oid.CRLEntryExtensionOID` enum.
2218
2219 .. attribute:: oid
2220
2221 :type: :class:`ObjectIdentifier`
2222
2223 Returns
2224 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CRL_REASON`.
2225
2226 .. attribute:: reason
2227
2228 :type: An element from :class:`~cryptography.x509.ReasonFlags`
2229
Paul Kehrer23c0bbc2015-12-25 22:35:19 -06002230.. class:: InvalidityDate(invalidity_date)
2231
2232 .. versionadded:: 1.2
2233
2234 Invalidity date is an extension that is only valid inside
2235 :class:`~cryptography.x509.RevokedCertificate` objects. It provides
2236 the date on which it is known or suspected that the private key was
2237 compromised or that the certificate otherwise became invalid.
2238 This date may be earlier than the revocation date in the CRL entry,
2239 which is the date at which the CA processed the revocation.
2240
2241 :param invalidity_date: The :class:`datetime.datetime` when it is known
2242 or suspected that the private key was compromised.
2243
2244 .. attribute:: oid
2245
2246 :type: :class:`ObjectIdentifier`
2247
2248 Returns
2249 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.INVALIDITY_DATE`.
2250
2251 .. attribute:: invalidity_date
2252
2253 :type: :class:`datetime.datetime`
2254
Paul Kehrer49bb7562015-12-25 16:17:40 -06002255
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002256Object Identifiers
2257~~~~~~~~~~~~~~~~~~
2258
Paul Kehrer4bb46492015-02-07 16:59:14 -06002259X.509 elements are frequently identified by :class:`ObjectIdentifier`
2260instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002261
Paul Kehrere27f6582015-08-10 18:33:38 -05002262.. currentmodule:: cryptography.x509.oid
Paul Kehrer56da2a52015-02-11 23:35:07 -06002263
Paul Kehrere27f6582015-08-10 18:33:38 -05002264.. class:: NameOID
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002265
Paul Kehrere27f6582015-08-10 18:33:38 -05002266 These OIDs are typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06002267
Paul Kehrere27f6582015-08-10 18:33:38 -05002268 .. versionadded:: 1.0
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002269
Paul Kehrere27f6582015-08-10 18:33:38 -05002270 .. attribute:: COMMON_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002271
Paul Kehrere27f6582015-08-10 18:33:38 -05002272 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
2273 name would be encoded here for server certificates. :rfc:`2818`
2274 deprecates this practice and names of that type should now be located
2275 in a :class:`~cryptography.x509.SubjectAlternativeName` extension.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002276
Paul Kehrere27f6582015-08-10 18:33:38 -05002277 .. attribute:: COUNTRY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002278
Paul Kehrere27f6582015-08-10 18:33:38 -05002279 Corresponds to the dotted string ``"2.5.4.6"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002280
Paul Kehrere27f6582015-08-10 18:33:38 -05002281 .. attribute:: LOCALITY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002282
Paul Kehrere27f6582015-08-10 18:33:38 -05002283 Corresponds to the dotted string ``"2.5.4.7"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002284
Paul Kehrere27f6582015-08-10 18:33:38 -05002285 .. attribute:: STATE_OR_PROVINCE_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002286
Paul Kehrere27f6582015-08-10 18:33:38 -05002287 Corresponds to the dotted string ``"2.5.4.8"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002288
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002289 .. attribute:: STREET_ADDRESS
2290
2291 .. versionadded:: 1.6
2292
2293 Corresponds to the dotted string ``"2.5.4.9"``.
2294
Paul Kehrere27f6582015-08-10 18:33:38 -05002295 .. attribute:: ORGANIZATION_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002296
Paul Kehrere27f6582015-08-10 18:33:38 -05002297 Corresponds to the dotted string ``"2.5.4.10"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002298
Paul Kehrere27f6582015-08-10 18:33:38 -05002299 .. attribute:: ORGANIZATIONAL_UNIT_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002300
Paul Kehrere27f6582015-08-10 18:33:38 -05002301 Corresponds to the dotted string ``"2.5.4.11"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002302
Paul Kehrere27f6582015-08-10 18:33:38 -05002303 .. attribute:: SERIAL_NUMBER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002304
Paul Kehrere27f6582015-08-10 18:33:38 -05002305 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from
2306 the serial number of the certificate itself (which can be obtained with
Chelsea Winfreee295f3a2016-06-02 21:15:54 -07002307 :func:`~cryptography.x509.Certificate.serial_number`).
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002308
Paul Kehrere27f6582015-08-10 18:33:38 -05002309 .. attribute:: SURNAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002310
Paul Kehrere27f6582015-08-10 18:33:38 -05002311 Corresponds to the dotted string ``"2.5.4.4"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002312
Paul Kehrere27f6582015-08-10 18:33:38 -05002313 .. attribute:: GIVEN_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002314
Paul Kehrere27f6582015-08-10 18:33:38 -05002315 Corresponds to the dotted string ``"2.5.4.42"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002316
Paul Kehrere27f6582015-08-10 18:33:38 -05002317 .. attribute:: TITLE
Paul Kehrer858b9b72015-02-05 09:50:31 -06002318
Paul Kehrere27f6582015-08-10 18:33:38 -05002319 Corresponds to the dotted string ``"2.5.4.12"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002320
Paul Kehrere27f6582015-08-10 18:33:38 -05002321 .. attribute:: GENERATION_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002322
Paul Kehrere27f6582015-08-10 18:33:38 -05002323 Corresponds to the dotted string ``"2.5.4.44"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002324
Paul Kehrerc7ab9312016-11-12 05:00:42 -08002325 .. attribute:: X500_UNIQUE_IDENTIFIER
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002326
2327 .. versionadded:: 1.6
2328
2329 Corresponds to the dotted string ``"2.5.4.45"``.
2330
Paul Kehrere27f6582015-08-10 18:33:38 -05002331 .. attribute:: DN_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002332
Paul Kehrere27f6582015-08-10 18:33:38 -05002333 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
2334 disambiguating information to add to the relative distinguished name of an
2335 entry. See :rfc:`2256`.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002336
Paul Kehrere27f6582015-08-10 18:33:38 -05002337 .. attribute:: PSEUDONYM
Paul Kehrer858b9b72015-02-05 09:50:31 -06002338
Paul Kehrere27f6582015-08-10 18:33:38 -05002339 Corresponds to the dotted string ``"2.5.4.65"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002340
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002341 .. attribute:: USER_ID
2342
2343 .. versionadded:: 1.6
2344
2345 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.1"``.
2346
Paul Kehrere27f6582015-08-10 18:33:38 -05002347 .. attribute:: DOMAIN_COMPONENT
Paul Kehrer858b9b72015-02-05 09:50:31 -06002348
Paul Kehrere27f6582015-08-10 18:33:38 -05002349 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
2350 holding one component of a domain name. See :rfc:`4519`.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002351
Paul Kehrere27f6582015-08-10 18:33:38 -05002352 .. attribute:: EMAIL_ADDRESS
Paul Kehrer56da2a52015-02-11 23:35:07 -06002353
Paul Kehrere27f6582015-08-10 18:33:38 -05002354 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002355
Alex Gaynor1d3f2bf2015-12-19 12:15:09 -05002356 .. attribute:: JURISDICTION_COUNTRY_NAME
2357
2358 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.3"``.
2359
Alex Gaynor45e507f2015-12-19 13:44:23 -05002360 .. attribute:: JURISDICTION_LOCALITY_NAME
2361
2362 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.1"``.
2363
2364 .. attribute:: JURISDICTION_STATE_OR_PROVINCE_NAME
2365
2366 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.2"``.
2367
Alex Gaynora2293c82015-12-19 20:49:15 -05002368 .. attribute:: BUSINESS_CATEGORY
2369
2370 Corresponds to the dotted string ``"2.5.4.15"``.
2371
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002372 .. attribute:: POSTAL_ADDRESS
2373
2374 .. versionadded:: 1.6
2375
2376 Corresponds to the dotted string ``"2.5.4.16"``.
2377
2378 .. attribute:: POSTAL_CODE
2379
2380 .. versionadded:: 1.6
2381
2382 Corresponds to the dotted string ``"2.5.4.17"``.
2383
Paul Kehrer56da2a52015-02-11 23:35:07 -06002384
Paul Kehrere27f6582015-08-10 18:33:38 -05002385.. class:: SignatureAlgorithmOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002386
Paul Kehrere27f6582015-08-10 18:33:38 -05002387 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002388
Paul Kehrere27f6582015-08-10 18:33:38 -05002389 .. attribute:: RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06002390
Paul Kehrere27f6582015-08-10 18:33:38 -05002391 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
2392 an MD5 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002393
Paul Kehrere27f6582015-08-10 18:33:38 -05002394 .. attribute:: RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002395
Paul Kehrere27f6582015-08-10 18:33:38 -05002396 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
2397 a SHA1 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002398
Paul Kehrere27f6582015-08-10 18:33:38 -05002399 .. attribute:: RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002400
Paul Kehrere27f6582015-08-10 18:33:38 -05002401 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
2402 a SHA224 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002403
Paul Kehrere27f6582015-08-10 18:33:38 -05002404 .. attribute:: RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002405
Paul Kehrere27f6582015-08-10 18:33:38 -05002406 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
2407 a SHA256 digest signed by an RSA key.
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002408
Paul Kehrere27f6582015-08-10 18:33:38 -05002409 .. attribute:: RSA_WITH_SHA384
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002410
Paul Kehrere27f6582015-08-10 18:33:38 -05002411 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
2412 a SHA384 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002413
Paul Kehrere27f6582015-08-10 18:33:38 -05002414 .. attribute:: RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06002415
Paul Kehrere27f6582015-08-10 18:33:38 -05002416 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
2417 a SHA512 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002418
Paul Kehrere27f6582015-08-10 18:33:38 -05002419 .. attribute:: ECDSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002420
Paul Kehrere27f6582015-08-10 18:33:38 -05002421 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
2422 digest signed by an ECDSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002423
Paul Kehrere27f6582015-08-10 18:33:38 -05002424 .. attribute:: ECDSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002425
Paul Kehrere27f6582015-08-10 18:33:38 -05002426 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
2427 a SHA224 digest signed by an ECDSA key.
2428
2429 .. attribute:: ECDSA_WITH_SHA256
2430
2431 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
2432 a SHA256 digest signed by an ECDSA key.
2433
2434 .. attribute:: ECDSA_WITH_SHA384
2435
2436 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
2437 a SHA384 digest signed by an ECDSA key.
2438
2439 .. attribute:: ECDSA_WITH_SHA512
2440
2441 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
2442 a SHA512 digest signed by an ECDSA key.
2443
2444 .. attribute:: DSA_WITH_SHA1
2445
2446 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
2447 a SHA1 digest signed by a DSA key.
2448
2449 .. attribute:: DSA_WITH_SHA224
2450
2451 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
2452 a SHA224 digest signed by a DSA key.
2453
2454 .. attribute:: DSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002455
Paul Kehrere27f6582015-08-10 18:33:38 -05002456 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
2457 a SHA256 digest signed by a DSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002458
Paul Kehrer56da2a52015-02-11 23:35:07 -06002459
Paul Kehrere27f6582015-08-10 18:33:38 -05002460.. class:: ExtendedKeyUsageOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002461
Paul Kehrere27f6582015-08-10 18:33:38 -05002462 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002463
Paul Kehrere27f6582015-08-10 18:33:38 -05002464 .. attribute:: SERVER_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002465
Paul Kehrere27f6582015-08-10 18:33:38 -05002466 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used
2467 to denote that a certificate may be used for TLS web server
2468 authentication.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002469
Paul Kehrere27f6582015-08-10 18:33:38 -05002470 .. attribute:: CLIENT_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002471
Paul Kehrere27f6582015-08-10 18:33:38 -05002472 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used
2473 to denote that a certificate may be used for TLS web client
2474 authentication.
Paul Kehrerffa2a152015-03-31 08:18:25 -05002475
Paul Kehrere27f6582015-08-10 18:33:38 -05002476 .. attribute:: CODE_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002477
Paul Kehrere27f6582015-08-10 18:33:38 -05002478 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used
2479 to denote that a certificate may be used for code signing.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002480
Paul Kehrere27f6582015-08-10 18:33:38 -05002481 .. attribute:: EMAIL_PROTECTION
Paul Kehrere1513fa2015-03-30 23:08:17 -05002482
Paul Kehrere27f6582015-08-10 18:33:38 -05002483 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used
2484 to denote that a certificate may be used for email protection.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002485
Paul Kehrere27f6582015-08-10 18:33:38 -05002486 .. attribute:: TIME_STAMPING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002487
Paul Kehrere27f6582015-08-10 18:33:38 -05002488 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used
2489 to denote that a certificate may be used for time stamping.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002490
Paul Kehrere27f6582015-08-10 18:33:38 -05002491 .. attribute:: OCSP_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002492
Paul Kehrere27f6582015-08-10 18:33:38 -05002493 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used
2494 to denote that a certificate may be used for signing OCSP responses.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002495
Paul Kehrere1513fa2015-03-30 23:08:17 -05002496
Paul Kehrere27f6582015-08-10 18:33:38 -05002497.. class:: AuthorityInformationAccessOID
Paul Kehrere1513fa2015-03-30 23:08:17 -05002498
Paul Kehrere27f6582015-08-10 18:33:38 -05002499 .. versionadded:: 1.0
Paul Kehrere1513fa2015-03-30 23:08:17 -05002500
Paul Kehrere27f6582015-08-10 18:33:38 -05002501 .. attribute:: OCSP
Paul Kehrere1513fa2015-03-30 23:08:17 -05002502
Paul Kehrere27f6582015-08-10 18:33:38 -05002503 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
2504 identifier for OCSP data in
2505 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002506
Paul Kehrere27f6582015-08-10 18:33:38 -05002507 .. attribute:: CA_ISSUERS
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002508
Paul Kehrere27f6582015-08-10 18:33:38 -05002509 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
2510 identifier for CA issuer data in
2511 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002512
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002513
Paul Kehrere27f6582015-08-10 18:33:38 -05002514.. class:: CertificatePoliciesOID
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002515
Paul Kehrere27f6582015-08-10 18:33:38 -05002516 .. versionadded:: 1.0
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002517
Paul Kehrere27f6582015-08-10 18:33:38 -05002518 .. attribute:: CPS_QUALIFIER
Paul Kehrer2e879742015-05-02 23:09:56 -05002519
Paul Kehrere27f6582015-08-10 18:33:38 -05002520 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002521
Paul Kehrere27f6582015-08-10 18:33:38 -05002522 .. attribute:: CPS_USER_NOTICE
Paul Kehrer2e879742015-05-02 23:09:56 -05002523
Paul Kehrere27f6582015-08-10 18:33:38 -05002524 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002525
Paul Kehrere27f6582015-08-10 18:33:38 -05002526 .. attribute:: ANY_POLICY
Paul Kehrer2e879742015-05-02 23:09:56 -05002527
Paul Kehrere27f6582015-08-10 18:33:38 -05002528 Corresponds to the dotted string ``"2.5.29.32.0"``.
Paul Kehrer16fae762015-05-01 23:14:20 -05002529
Paul Kehrer16fae762015-05-01 23:14:20 -05002530
Paul Kehrere27f6582015-08-10 18:33:38 -05002531.. class:: ExtensionOID
Paul Kehrer5553d572015-03-23 21:08:01 -05002532
Paul Kehrere27f6582015-08-10 18:33:38 -05002533 .. versionadded:: 1.0
Paul Kehrer2bb94642015-03-21 09:54:17 -05002534
Paul Kehrere27f6582015-08-10 18:33:38 -05002535 .. attribute:: BASIC_CONSTRAINTS
Paul Kehrer2bb94642015-03-21 09:54:17 -05002536
Paul Kehrere27f6582015-08-10 18:33:38 -05002537 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
2538 :class:`~cryptography.x509.BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05002539
Paul Kehrere27f6582015-08-10 18:33:38 -05002540 .. attribute:: KEY_USAGE
Paul Kehrercecbbba2015-03-30 14:58:38 -05002541
Paul Kehrere27f6582015-08-10 18:33:38 -05002542 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
2543 :class:`~cryptography.x509.KeyUsage` extension type.
Paul Kehrercecbbba2015-03-30 14:58:38 -05002544
Paul Kehrere27f6582015-08-10 18:33:38 -05002545 .. attribute:: SUBJECT_ALTERNATIVE_NAME
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002546
Paul Kehrere27f6582015-08-10 18:33:38 -05002547 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
2548 :class:`~cryptography.x509.SubjectAlternativeName` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002549
Paul Kehrere27f6582015-08-10 18:33:38 -05002550 .. attribute:: ISSUER_ALTERNATIVE_NAME
Paul Kehrer99125c92015-06-07 18:37:10 -05002551
Paul Kehrere27f6582015-08-10 18:33:38 -05002552 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
2553 :class:`~cryptography.x509.IssuerAlternativeName` extension type.
Paul Kehrer99125c92015-06-07 18:37:10 -05002554
Paul Kehrere27f6582015-08-10 18:33:38 -05002555 .. attribute:: SUBJECT_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002556
Paul Kehrere27f6582015-08-10 18:33:38 -05002557 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
2558 :class:`~cryptography.x509.SubjectKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002559
Paul Kehrere27f6582015-08-10 18:33:38 -05002560 .. attribute:: NAME_CONSTRAINTS
Paul Kehrere0017be2015-05-17 20:39:40 -06002561
Paul Kehrere27f6582015-08-10 18:33:38 -05002562 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
2563 :class:`~cryptography.x509.NameConstraints` extension type.
Paul Kehrere0017be2015-05-17 20:39:40 -06002564
Paul Kehrere27f6582015-08-10 18:33:38 -05002565 .. attribute:: CRL_DISTRIBUTION_POINTS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002566
Paul Kehrere27f6582015-08-10 18:33:38 -05002567 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
2568 :class:`~cryptography.x509.CRLDistributionPoints` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002569
Paul Kehrere27f6582015-08-10 18:33:38 -05002570 .. attribute:: CERTIFICATE_POLICIES
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002571
Paul Kehrere27f6582015-08-10 18:33:38 -05002572 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
2573 :class:`~cryptography.x509.CertificatePolicies` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002574
Paul Kehrere27f6582015-08-10 18:33:38 -05002575 .. attribute:: AUTHORITY_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002576
Paul Kehrere27f6582015-08-10 18:33:38 -05002577 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
2578 :class:`~cryptography.x509.AuthorityKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002579
Paul Kehrere27f6582015-08-10 18:33:38 -05002580 .. attribute:: EXTENDED_KEY_USAGE
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002581
Paul Kehrere27f6582015-08-10 18:33:38 -05002582 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
2583 :class:`~cryptography.x509.ExtendedKeyUsage` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002584
Paul Kehrere27f6582015-08-10 18:33:38 -05002585 .. attribute:: AUTHORITY_INFORMATION_ACCESS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002586
Paul Kehrere27f6582015-08-10 18:33:38 -05002587 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
2588 for the :class:`~cryptography.x509.AuthorityInformationAccess` extension
2589 type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002590
Paul Kehrere27f6582015-08-10 18:33:38 -05002591 .. attribute:: INHIBIT_ANY_POLICY
Paul Kehrerb33de932015-08-06 23:41:05 +01002592
Paul Kehrere27f6582015-08-10 18:33:38 -05002593 Corresponds to the dotted string ``"2.5.29.54"``. The identifier
2594 for the :class:`~cryptography.x509.InhibitAnyPolicy` extension type.
Paul Kehrerb33de932015-08-06 23:41:05 +01002595
Paul Kehrere27f6582015-08-10 18:33:38 -05002596 .. attribute:: OCSP_NO_CHECK
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002597
Paul Kehrere27f6582015-08-10 18:33:38 -05002598 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The
2599 identifier for the :class:`~cryptography.x509.OCSPNoCheck` extension
2600 type.
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002601
Paul Kehrer51f39cb2015-12-21 21:17:39 -06002602 .. attribute:: CRL_NUMBER
2603
2604 Corresponds to the dotted string ``"2.5.29.20"``. The identifier for
2605 the ``CRLNumber`` extension type. This extension only has meaning
2606 for certificate revocation lists.
2607
Alex Gaynor9bab0ed2017-03-20 09:50:52 -04002608 .. attribute:: PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS
2609
2610 .. versionadded:: 1.9
2611
2612 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.2"``.
2613
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002614 .. attribute:: POLICY_CONSTRAINTS
2615
2616 Corresponds to the dotted string ``"2.5.29.36"``. The identifier for the
Paul Kehrer20f0df52016-02-26 08:37:13 -06002617 :class:`~cryptography.x509.PolicyConstraints` extension type.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002618
2619
Paul Kehrerc6242dc2015-12-25 16:36:46 -06002620.. class:: CRLEntryExtensionOID
2621
2622 .. versionadded:: 1.2
2623
2624 .. attribute:: CERTIFICATE_ISSUER
2625
2626 Corresponds to the dotted string ``"2.5.29.29"``.
2627
2628 .. attribute:: CRL_REASON
2629
2630 Corresponds to the dotted string ``"2.5.29.21"``.
2631
2632 .. attribute:: INVALIDITY_DATE
2633
2634 Corresponds to the dotted string ``"2.5.29.24"``.
2635
Paul Kehrer8b89bcc2016-09-03 11:31:43 -05002636Helper Functions
2637~~~~~~~~~~~~~~~~
2638.. currentmodule:: cryptography.x509
2639
2640.. function:: random_serial_number()
2641
2642 .. versionadded:: 1.6
2643
2644 Generates a random serial number suitable for use when constructing
2645 certificates.
2646
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002647Exceptions
2648~~~~~~~~~~
Paul Kehrere27f6582015-08-10 18:33:38 -05002649.. currentmodule:: cryptography.x509
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002650
Paul Kehrere76cd272014-12-14 19:00:51 -06002651.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10002652
2653 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10002654
Paul Kehrerd5cccf72014-12-15 17:20:33 -06002655 .. attribute:: parsed_version
2656
Paul Kehrerbbffc402014-12-17 13:33:55 -06002657 :type: int
2658
2659 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06002660
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05002661.. class:: DuplicateExtension
2662
2663 This is raised when more than one X.509 extension of the same type is
2664 found within a certificate.
2665
2666 .. attribute:: oid
2667
2668 :type: :class:`ObjectIdentifier`
2669
2670 Returns the OID.
2671
2672.. class:: UnsupportedExtension
2673
Paul Kehrer58ddc112015-12-30 20:19:00 -06002674 This is raised when a certificate contains an unsupported extension type
Paul Kehrerf5bc3eb2015-12-30 20:54:15 -06002675 that is marked ``critical``.
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05002676
2677 .. attribute:: oid
2678
2679 :type: :class:`ObjectIdentifier`
2680
2681 Returns the OID.
2682
Paul Kehrerfa56a232015-03-17 13:14:03 -05002683.. class:: ExtensionNotFound
2684
2685 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
2686 an extension OID that is not present in the certificate.
2687
2688 .. attribute:: oid
2689
2690 :type: :class:`ObjectIdentifier`
2691
2692 Returns the OID.
2693
Paul Kehrer9089c912015-04-20 22:15:20 -05002694.. class:: UnsupportedGeneralNameType
2695
2696 This is raised when a certificate contains an unsupported general name
2697 type in an extension.
2698
Paul Kehrerbed07352015-04-21 08:31:10 -05002699 .. attribute:: type
2700
Paul Kehrer0a621bf2015-04-22 09:22:56 -05002701 :type: int
2702
2703 The integer value of the unsupported type. The complete list of
2704 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05002705
Paul Kehrer016e08a2014-11-26 09:41:18 -10002706
Paul Kehrerc7c9a432015-04-19 09:20:13 -05002707.. _`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 -05002708.. _`RFC 5280 section 4.2.1.6`: https://tools.ietf.org/html/rfc5280#section-4.2.1.6
Paul Kehrer8b89bcc2016-09-03 11:31:43 -05002709.. _`CABForum Guidelines`: https://cabforum.org/baseline-requirements-documents/