blob: 8b9761190ffe1a60500bd2cb2a6d8650e2d5b2f7 [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 Kehrerbed07352015-04-21 08:31:10 -0500382 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
383 contains a general name that is not supported.
384
Paul Kehrerb8968812015-05-15 09:01:34 -0700385 :raises UnicodeError: If an extension contains IDNA encoding that is
386 invalid or not compliant with IDNA 2008.
387
Paul Kehrerfa56a232015-03-17 13:14:03 -0500388 .. doctest::
389
390 >>> for ext in cert.extensions:
391 ... print(ext)
Paul Kehrerd774de92015-05-03 10:52:25 -0500392 <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 -0400393 <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 -0400394 <Extension(oid=<ObjectIdentifier(oid=2.5.29.15, name=keyUsage)>, critical=True, value=<KeyUsage(digital_signature=False, content_commitment=False, key_encipherment=False, data_encipherment=False, key_agreement=False, key_cert_sign=True, crl_sign=True, encipher_only=None, decipher_only=None)>)>
Paul Kehrer2008d9c2015-05-12 22:19:56 -0500395 <Extension(oid=<ObjectIdentifier(oid=2.5.29.32, name=certificatePolicies)>, critical=False, value=<CertificatePolicies([<PolicyInformation(policy_identifier=<ObjectIdentifier(oid=2.16.840.1.101.3.2.1.48.1, name=Unknown OID)>, policy_qualifiers=None)>])>)>
Paul Kehrerfa56a232015-03-17 13:14:03 -0500396 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
397
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500398 .. attribute:: signature
399
400 .. versionadded:: 1.2
401
402 :type: bytes
403
404 The bytes of the certificate's signature.
405
Paul Kehrerd2898052015-11-03 22:00:41 +0900406 .. attribute:: tbs_certificate_bytes
Paul Kehrerd91e7c12015-10-01 16:50:42 -0500407
408 .. versionadded:: 1.2
409
410 :type: bytes
411
412 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
413 and then signed by the private key of the certificate's issuer. This
414 data may be used to validate a signature, but use extreme caution as
415 certificate validation is a complex problem that involves much more
416 than just signature checks.
417
Andre Carona8aded62015-05-19 20:11:57 -0400418 .. method:: public_bytes(encoding)
419
Alex Gaynord0b376b2015-07-05 13:58:12 -0400420 .. versionadded:: 1.0
421
Andre Carona8aded62015-05-19 20:11:57 -0400422 :param encoding: The
423 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
424 that will be used to serialize the certificate.
425
426 :return bytes: The data that can be written to a file or sent
427 over the network to be verified by clients.
428
Erik Trauschke2dcce902015-05-14 16:12:24 -0700429X.509 CRL (Certificate Revocation List) Object
430~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
431
432.. class:: CertificateRevocationList
433
434 .. versionadded:: 1.0
435
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700436 A CertificateRevocationList is an object representing a list of revoked
437 certificates. The object is iterable and will yield the RevokedCertificate
438 objects stored in this CRL.
439
440 .. doctest::
Erik Trauschkeb14f7d12015-10-13 09:55:39 -0700441
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700442 >>> len(crl)
443 1
Paul Kehrerdcdf9672015-10-21 20:27:28 -0500444 >>> revoked_certificate = crl[0]
445 >>> type(revoked_certificate)
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700446 <class 'cryptography.hazmat.backends.openssl.x509._RevokedCertificate'>
447 >>> for r in crl:
448 ... print(r.serial_number)
449 0
450
Erik Trauschke2dcce902015-05-14 16:12:24 -0700451 .. method:: fingerprint(algorithm)
452
453 :param algorithm: The
454 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
455 that will be used to generate the fingerprint.
456
457 :return bytes: The fingerprint using the supplied hash algorithm, as
458 bytes.
459
Erik Trauschkedc570402015-09-24 20:24:28 -0700460 .. doctest::
461
462 >>> from cryptography.hazmat.primitives import hashes
463 >>> crl.fingerprint(hashes.SHA256())
464 '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'
465
Erik Trauschke2dcce902015-05-14 16:12:24 -0700466 .. attribute:: signature_hash_algorithm
467
468 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
469
470 Returns the
471 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
472 was used in signing this CRL.
473
Erik Trauschkedc570402015-09-24 20:24:28 -0700474 .. doctest::
475
476 >>> from cryptography.hazmat.primitives import hashes
477 >>> isinstance(crl.signature_hash_algorithm, hashes.SHA256)
478 True
479
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800480 .. attribute:: signature_algorithm_oid
481
482 .. versionadded:: 1.6
483
484 :type: :class:`ObjectIdentifier`
485
486 Returns the :class:`ObjectIdentifier` of the signature algorithm used
487 to sign the CRL. This will be one of the OIDs from
488 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
489
490 .. doctest::
491
492 >>> crl.signature_algorithm_oid
493 <ObjectIdentifier(oid=1.2.840.113549.1.1.11, name=sha256WithRSAEncryption)>
494
Erik Trauschke2dcce902015-05-14 16:12:24 -0700495 .. attribute:: issuer
496
497 :type: :class:`Name`
498
499 The :class:`Name` of the issuer.
500
Erik Trauschkedc570402015-09-24 20:24:28 -0700501 .. doctest::
502
503 >>> crl.issuer
504 <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')>])>
505
Erik Trauschke2dcce902015-05-14 16:12:24 -0700506 .. attribute:: next_update
507
508 :type: :class:`datetime.datetime`
509
510 A naïve datetime representing when the next update to this CRL is
511 expected.
512
Erik Trauschkedc570402015-09-24 20:24:28 -0700513 .. doctest::
514
515 >>> crl.next_update
516 datetime.datetime(2016, 1, 1, 0, 0)
517
Erik Trauschke2dcce902015-05-14 16:12:24 -0700518 .. attribute:: last_update
519
520 :type: :class:`datetime.datetime`
521
522 A naïve datetime representing when the this CRL was last updated.
523
Erik Trauschkedc570402015-09-24 20:24:28 -0700524 .. doctest::
Erik Trauschke2dcce902015-05-14 16:12:24 -0700525
Erik Trauschkedc570402015-09-24 20:24:28 -0700526 >>> crl.last_update
527 datetime.datetime(2015, 1, 1, 0, 0)
Erik Trauschke2dcce902015-05-14 16:12:24 -0700528
529 .. attribute:: extensions
530
531 :type: :class:`Extensions`
532
533 The extensions encoded in the CRL.
534
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800535 .. attribute:: signature
536
537 .. versionadded:: 1.2
538
539 :type: bytes
540
541 The bytes of the CRL's signature.
542
543 .. attribute:: tbs_certlist_bytes
544
545 .. versionadded:: 1.2
546
547 :type: bytes
548
549 The DER encoded bytes payload (as defined by :rfc:`5280`) that is hashed
550 and then signed by the private key of the CRL's issuer. This data may be
551 used to validate a signature, but use extreme caution as CRL validation
552 is a complex problem that involves much more than just signature checks.
553
Paul Kehrer54a837d2015-12-20 23:42:32 -0600554 .. method:: public_bytes(encoding)
555
556 .. versionadded:: 1.2
557
558 :param encoding: The
559 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
560 that will be used to serialize the certificate revocation list.
561
562 :return bytes: The data that can be written to a file or sent
563 over the network and used as part of a certificate verification
564 process.
565
Erik Trauschke6abe2bb2015-11-19 10:27:01 -0800566
Andre Caron9bbfcea2015-05-18 20:55:29 -0400567X.509 Certificate Builder
568~~~~~~~~~~~~~~~~~~~~~~~~~
569
570.. class:: CertificateBuilder
571
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500572 .. versionadded:: 1.0
573
574 .. doctest::
575
576 >>> from cryptography import x509
577 >>> from cryptography.hazmat.backends import default_backend
578 >>> from cryptography.hazmat.primitives import hashes
579 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -0500580 >>> from cryptography.x509.oid import NameOID
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500581 >>> import datetime
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500582 >>> one_day = datetime.timedelta(1, 0, 0)
583 >>> private_key = rsa.generate_private_key(
584 ... public_exponent=65537,
585 ... key_size=2048,
586 ... backend=default_backend()
587 ... )
Cory Benfieldc47b2522015-12-07 15:25:12 +0000588 >>> public_key = private_key.public_key()
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500589 >>> builder = x509.CertificateBuilder()
590 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500591 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500592 ... ]))
593 >>> builder = builder.issuer_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.not_valid_before(datetime.datetime.today() - one_day)
597 >>> builder = builder.not_valid_after(datetime.datetime(2018, 8, 2))
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500598 >>> builder = builder.serial_number(x509.random_serial_number())
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500599 >>> builder = builder.public_key(public_key)
600 >>> builder = builder.add_extension(
Paul Kehrer1bab7bc2017-01-18 13:44:40 +0800601 ... x509.SubjectAlternativeName(
Alex Gaynorcdaf3ff2017-07-30 13:08:51 -0400602 ... [x509.DNSName(b'cryptography.io')]
Paul Kehrer1bab7bc2017-01-18 13:44:40 +0800603 ... ),
604 ... critical=False
605 ... )
606 >>> builder = builder.add_extension(
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500607 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
608 ... )
609 >>> certificate = builder.sign(
610 ... private_key=private_key, algorithm=hashes.SHA256(),
611 ... backend=default_backend()
612 ... )
613 >>> isinstance(certificate, x509.Certificate)
614 True
615
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500616 .. method:: issuer_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400617
618 Sets the issuer's distinguished name.
619
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500620 :param name: The :class:`~cryptography.x509.Name` that describes the
621 issuer (CA).
Andre Caron9bbfcea2015-05-18 20:55:29 -0400622
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500623 .. method:: subject_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400624
625 Sets the subject's distinguished name.
626
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500627 :param name: The :class:`~cryptography.x509.Name` that describes the
Ian Cordasco85fc4d52015-08-01 20:29:31 -0500628 subject.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400629
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500630 .. method:: public_key(public_key)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400631
632 Sets the subject's public key.
633
Ian Cordasco8f571422015-08-02 11:31:08 -0500634 :param public_key: The subject's public key. This can be one of
635 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`,
636 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
637 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400638
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500639 .. method:: serial_number(serial_number)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400640
641 Sets the certificate's serial number (an integer). The CA's policy
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500642 determines how it attributes serial numbers to certificates. This
643 number must uniquely identify the certificate given the issuer.
644 `CABForum Guidelines`_ require entropy in the serial number
645 to provide protection against hash collision attacks. For more
646 information on secure random number generation, see
647 :doc:`/random-numbers`.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400648
649 :param serial_number: Integer number that will be used by the CA to
650 identify this certificate (most notably during certificate
Paul Kehrer8b89bcc2016-09-03 11:31:43 -0500651 revocation checking). Users should consider using
652 :func:`~cryptography.x509.random_serial_number` when possible.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400653
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500654 .. method:: not_valid_before(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400655
656 Sets the certificate's activation time. This is the time from which
657 clients can start trusting the certificate. It may be different from
658 the time at which the certificate was created.
659
Ian Cordasco17c89002015-08-02 21:13:59 -0500660 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400661 activation time for the certificate. The certificate may not be
662 trusted clients if it is used before this time.
663
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500664 .. method:: not_valid_after(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400665
666 Sets the certificate's expiration time. This is the time from which
667 clients should no longer trust the certificate. The CA's policy will
668 determine how long the certificate should remain in use.
669
Ian Cordasco17c89002015-08-02 21:13:59 -0500670 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400671 expiration time for the certificate. The certificate may not be
672 trusted clients if it is used after this time.
673
Ian Cordasco17c89002015-08-02 21:13:59 -0500674 .. method:: add_extension(extension, critical)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400675
676 Adds an X.509 extension to the certificate.
677
Paul Kehrer2c145cc2015-10-02 11:27:21 -0500678 :param extension: An extension conforming to the
679 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400680
Ian Cordasco17c89002015-08-02 21:13:59 -0500681 :param critical: Set to ``True`` if the extension must be understood and
682 handled by whoever reads the certificate.
683
Paul Kehrer9add80e2015-08-03 17:53:14 +0100684 .. method:: sign(private_key, algorithm, backend)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400685
686 Sign the certificate using the CA's private key.
687
Ian Cordascoc5e1c252015-07-31 23:33:35 -0500688 :param private_key: The
689 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
690 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
691 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
692 that will be used to sign the certificate.
693
Andre Caron9bbfcea2015-05-18 20:55:29 -0400694 :param algorithm: The
695 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
696 will be used to generate the signature.
697
Paul Kehrer9add80e2015-08-03 17:53:14 +0100698 :param backend: Backend that will be used to build the certificate.
699 Must support the
700 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
701 interface.
702
Benjamin Peterson9ed312b2015-10-12 20:51:34 -0700703 :returns: :class:`~cryptography.x509.Certificate`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400704
705
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500706X.509 CSR (Certificate Signing Request) Object
707~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600708
Paul Kehrera1a1f232015-03-15 15:34:35 -0500709.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600710
711 .. versionadded:: 0.9
712
713 .. method:: public_key()
714
Alex Gaynor4c2561a2015-10-12 23:53:39 -0400715 The public key associated with the request.
716
717 :returns:
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600718 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
719 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
720 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
721
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600722 .. doctest::
723
724 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500725 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600726 >>> isinstance(public_key, rsa.RSAPublicKey)
727 True
728
729 .. attribute:: subject
730
731 :type: :class:`Name`
732
733 The :class:`Name` of the subject.
734
735 .. attribute:: signature_hash_algorithm
736
737 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
738
739 Returns the
740 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
741 was used in signing this request.
742
743 .. doctest::
744
745 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500746 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600747 True
748
Paul Kehrerc7b29b82016-09-01 09:17:21 +0800749 .. attribute:: signature_algorithm_oid
750
751 .. versionadded:: 1.6
752
753 :type: :class:`ObjectIdentifier`
754
755 Returns the :class:`ObjectIdentifier` of the signature algorithm used
756 to sign the request. This will be one of the OIDs from
757 :class:`~cryptography.x509.oid.SignatureAlgorithmOID`.
758
759 .. doctest::
760
761 >>> csr.signature_algorithm_oid
762 <ObjectIdentifier(oid=1.2.840.113549.1.1.5, name=sha1WithRSAEncryption)>
763
Paul Kehrerc4e61942015-08-01 21:21:13 +0100764 .. attribute:: extensions
765
766 :type: :class:`Extensions`
767
768 The extensions encoded in the certificate signing request.
769
770 :raises cryptography.x509.DuplicateExtension: If more than one
Paul Kehrer24283d22015-08-01 21:31:19 +0100771 extension of the same type is found within the certificate signing request.
Paul Kehrerc4e61942015-08-01 21:21:13 +0100772
Paul Kehrerc4e61942015-08-01 21:21:13 +0100773 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
774 contains a general name that is not supported.
775
776 :raises UnicodeError: If an extension contains IDNA encoding that is
777 invalid or not compliant with IDNA 2008.
778
779
Andre Caron476c5df2015-05-18 10:23:28 -0400780 .. method:: public_bytes(encoding)
781
Alex Gaynord0b376b2015-07-05 13:58:12 -0400782 .. versionadded:: 1.0
783
Andre Caron476c5df2015-05-18 10:23:28 -0400784 :param encoding: The
785 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
786 that will be used to serialize the certificate request.
787
788 :return bytes: The data that can be written to a file or sent
789 over the network to be signed by the certificate
790 authority.
791
Paul Kehrerab209392015-12-01 14:50:31 -0600792 .. attribute:: signature
793
794 .. versionadded:: 1.2
795
796 :type: bytes
797
798 The bytes of the certificate signing request's signature.
799
800 .. attribute:: tbs_certrequest_bytes
801
802 .. versionadded:: 1.2
803
804 :type: bytes
805
806 The DER encoded bytes payload (as defined by :rfc:`2986`) that is
807 hashed and then signed by the private key (corresponding to the public
808 key embedded in the CSR). This data may be used to validate the CSR
809 signature.
810
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100811 .. attribute:: is_signature_valid
Joern Heissler1bd77e22016-01-13 22:51:37 +0100812
813 .. versionadded:: 1.3
814
Joern Heisslerfbda8ce2016-01-18 00:24:44 +0100815 Returns True if the CSR signature is correct, False otherwise.
Joern Heissler1bd77e22016-01-13 22:51:37 +0100816
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600817X.509 Certificate Revocation List Builder
818~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
819
820.. class:: CertificateRevocationListBuilder
821
822 .. versionadded:: 1.2
823
824 .. doctest::
825
826 >>> from cryptography import x509
827 >>> from cryptography.hazmat.backends import default_backend
828 >>> from cryptography.hazmat.primitives import hashes
829 >>> from cryptography.hazmat.primitives.asymmetric import rsa
830 >>> from cryptography.x509.oid import NameOID
831 >>> import datetime
832 >>> one_day = datetime.timedelta(1, 0, 0)
833 >>> private_key = rsa.generate_private_key(
834 ... public_exponent=65537,
835 ... key_size=2048,
836 ... backend=default_backend()
837 ... )
838 >>> builder = x509.CertificateRevocationListBuilder()
839 >>> builder = builder.issuer_name(x509.Name([
840 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io CA'),
841 ... ]))
842 >>> builder = builder.last_update(datetime.datetime.today())
843 >>> builder = builder.next_update(datetime.datetime.today() + one_day)
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600844 >>> revoked_cert = x509.RevokedCertificateBuilder().serial_number(
845 ... 333
846 ... ).revocation_date(
847 ... datetime.datetime.today()
848 ... ).build(default_backend())
849 >>> builder = builder.add_revoked_certificate(revoked_cert)
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600850 >>> crl = builder.sign(
851 ... private_key=private_key, algorithm=hashes.SHA256(),
852 ... backend=default_backend()
853 ... )
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600854 >>> len(crl)
855 1
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600856
857 .. method:: issuer_name(name)
858
859 Sets the issuer's distinguished name.
860
861 :param name: The :class:`~cryptography.x509.Name` that describes the
862 issuer (CA).
863
864 .. method:: last_update(time)
865
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600866 Sets this CRL's activation time. This is the time from which
867 clients can start trusting this CRL. It may be different from
868 the time at which this CRL was created. This is also known as the
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600869 ``thisUpdate`` time.
870
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600871 :param time: The :class:`datetime.datetime` object (in UTC) that marks
872 the activation time for this CRL. The CRL may not be trusted if it
873 is used before this time.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600874
875 .. method:: next_update(time)
876
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600877 Sets this CRL's next update time. This is the time by which
878 a new CRL will be issued. The CA is allowed to issue a new CRL before
879 this date, however clients are not required to check for it.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600880
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600881 :param time: The :class:`datetime.datetime` object (in UTC) that marks
882 the next update time for this CRL.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600883
Paul Kehrer426b48d2015-12-24 20:50:43 -0600884 .. method:: add_extension(extension, critical)
885
886 Adds an X.509 extension to this CRL.
887
888 :param extension: An extension with the
889 :class:`~cryptography.x509.ExtensionType` interface.
890
891 :param critical: Set to ``True`` if the extension must be understood and
892 handled by whoever reads the CRL.
893
Paul Kehrer4c7fd5f2015-12-25 13:40:55 -0600894 .. method:: add_revoked_certificate(revoked_certificate)
895
896 Adds a revoked certificate to this CRL.
897
898 :param revoked_certificate: An instance of
899 :class:`~cryptography.x509.RevokedCertificate`. These can be
900 obtained from an existing CRL or created with
901 :class:`~cryptography.x509.RevokedCertificateBuilder`.
902
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600903 .. method:: sign(private_key, algorithm, backend)
904
Paul Kehrer0325b9d2015-12-24 19:19:59 -0600905 Sign this CRL using the CA's private key.
Paul Kehrerbfac2d12015-12-19 23:32:08 -0600906
907 :param private_key: The
908 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
909 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
910 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
911 that will be used to sign the certificate.
912
913 :param algorithm: The
914 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
915 will be used to generate the signature.
916
917 :param backend: Backend that will be used to build the CRL.
918 Must support the
919 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
920 interface.
921
922 :returns: :class:`~cryptography.x509.CertificateRevocationList`
923
Erik Trauschke2dcce902015-05-14 16:12:24 -0700924X.509 Revoked Certificate Object
Erik Trauschkec5a8d172015-05-28 10:24:25 -0700925~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Erik Trauschke2dcce902015-05-14 16:12:24 -0700926
927.. class:: RevokedCertificate
928
929 .. versionadded:: 1.0
930
931 .. attribute:: serial_number
932
933 :type: :class:`int`
934
935 An integer representing the serial number of the revoked certificate.
936
Erik Trauschkedc570402015-09-24 20:24:28 -0700937 .. doctest::
938
Erik Trauschke3cdabaf2015-10-13 09:42:53 -0700939 >>> revoked_certificate.serial_number
Erik Trauschkedc570402015-09-24 20:24:28 -0700940 0
941
Erik Trauschke2dcce902015-05-14 16:12:24 -0700942 .. attribute:: revocation_date
943
944 :type: :class:`datetime.datetime`
945
946 A naïve datetime representing the date this certificates was revoked.
947
Erik Trauschkedc570402015-09-24 20:24:28 -0700948 .. doctest::
949
Erik Trauschke77f5a252015-10-14 08:06:38 -0700950 >>> revoked_certificate.revocation_date
Erik Trauschkedc570402015-09-24 20:24:28 -0700951 datetime.datetime(2015, 1, 1, 0, 0)
952
Erik Trauschke2dcce902015-05-14 16:12:24 -0700953 .. attribute:: extensions
954
955 :type: :class:`Extensions`
956
957 The extensions encoded in the revoked certificate.
Andre Caron476c5df2015-05-18 10:23:28 -0400958
Erik Trauschkedc570402015-09-24 20:24:28 -0700959 .. doctest::
960
Erik Trauschke77f5a252015-10-14 08:06:38 -0700961 >>> for ext in revoked_certificate.extensions:
Erik Trauschkedc570402015-09-24 20:24:28 -0700962 ... print(ext)
Paul Kehrer23c0bbc2015-12-25 22:35:19 -0600963 <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 -0600964 <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 -0700965
Paul Kehrerc33ffd72015-12-25 10:59:22 -0600966X.509 Revoked Certificate Builder
967~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
968
969.. class:: RevokedCertificateBuilder
970
971 This class is used to create :class:`~cryptography.x509.RevokedCertificate`
972 objects that can be used with the
973 :class:`~cryptography.x509.CertificateRevocationListBuilder`.
974
975 .. versionadded:: 1.2
976
977 .. doctest::
978
979 >>> from cryptography import x509
980 >>> from cryptography.hazmat.backends import default_backend
981 >>> import datetime
982 >>> builder = x509.RevokedCertificateBuilder()
983 >>> builder = builder.revocation_date(datetime.datetime.today())
984 >>> builder = builder.serial_number(3333)
985 >>> revoked_certificate = builder.build(default_backend())
986 >>> isinstance(revoked_certificate, x509.RevokedCertificate)
987 True
988
989 .. method:: serial_number(serial_number)
990
991 Sets the revoked certificate's serial number.
992
993 :param serial_number: Integer number that is used to identify the
994 revoked certificate.
995
996 .. method:: revocation_date(time)
997
998 Sets the certificate's revocation date.
999
1000 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
1001 revocation time for the certificate.
1002
Paul Kehrere5f152b2015-12-25 23:55:47 -06001003 .. method:: add_extension(extension, critical)
1004
1005 Adds an X.509 extension to this revoked certificate.
1006
1007 :param extension: An instance of one of the
1008 :ref:`CRL entry extensions <crl_entry_extensions>`.
1009
1010 :param critical: Set to ``True`` if the extension must be understood and
1011 handled.
1012
Paul Kehrerc33ffd72015-12-25 10:59:22 -06001013 .. method:: build(backend)
1014
1015 Create a revoked certificate object using the provided backend.
1016
1017 :param backend: Backend that will be used to build the revoked
1018 certificate. Must support the
1019 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1020 interface.
1021
1022 :returns: :class:`~cryptography.x509.RevokedCertificate`
1023
Andre Caron0ef595f2015-05-18 13:53:43 -04001024X.509 CSR (Certificate Signing Request) Builder Object
1025~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1026
1027.. class:: CertificateSigningRequestBuilder
1028
Andre Carond259ee52015-06-02 23:47:11 -04001029 .. versionadded:: 1.0
1030
1031 .. doctest::
1032
1033 >>> from cryptography import x509
1034 >>> from cryptography.hazmat.backends import default_backend
1035 >>> from cryptography.hazmat.primitives import hashes
1036 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -05001037 >>> from cryptography.x509.oid import NameOID
Andre Carond259ee52015-06-02 23:47:11 -04001038 >>> private_key = rsa.generate_private_key(
1039 ... public_exponent=65537,
1040 ... key_size=2048,
1041 ... backend=default_backend()
1042 ... )
1043 >>> builder = x509.CertificateSigningRequestBuilder()
Andre Carona9a51172015-06-06 20:18:44 -04001044 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -05001045 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Andre Carond259ee52015-06-02 23:47:11 -04001046 ... ]))
Ian Cordascof06b6be2015-06-21 10:09:18 -05001047 >>> builder = builder.add_extension(
Ian Cordasco0112b022015-06-16 17:51:18 -05001048 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
Andre Caron472fd692015-06-06 20:04:44 -04001049 ... )
Andre Carond259ee52015-06-02 23:47:11 -04001050 >>> request = builder.sign(
Alex Gaynorde9e5842015-06-26 20:11:23 -04001051 ... private_key, hashes.SHA256(), default_backend()
Andre Carond259ee52015-06-02 23:47:11 -04001052 ... )
1053 >>> isinstance(request, x509.CertificateSigningRequest)
1054 True
1055
Andre Carona9a51172015-06-06 20:18:44 -04001056 .. method:: subject_name(name)
Andre Caron0ef595f2015-05-18 13:53:43 -04001057
Andre Caron341ff852015-06-06 20:14:31 -04001058 :param name: The :class:`~cryptography.x509.Name` of the certificate
1059 subject.
1060 :returns: A new
1061 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001062
Ian Cordascof06b6be2015-06-21 10:09:18 -05001063 .. method:: add_extension(extension, critical)
Andre Caron0ef595f2015-05-18 13:53:43 -04001064
Paul Kehrer2c145cc2015-10-02 11:27:21 -05001065 :param extension: An extension conforming to the
1066 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron472fd692015-06-06 20:04:44 -04001067 :param critical: Set to `True` if the extension must be understood and
1068 handled by whoever reads the certificate.
Andre Caron341ff852015-06-06 20:14:31 -04001069 :returns: A new
1070 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001071
Alex Gaynorb3b0fbe2015-06-26 19:57:18 -04001072 .. method:: sign(private_key, algorithm, backend)
Andre Caron0ef595f2015-05-18 13:53:43 -04001073
1074 :param backend: Backend that will be used to sign the request.
1075 Must support the
1076 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1077 interface.
1078
1079 :param private_key: The
Andre Caron24f9bf42015-06-06 20:14:54 -04001080 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
1081 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
1082 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
Andre Caron0ef595f2015-05-18 13:53:43 -04001083 that will be used to sign the request. When the request is
1084 signed by a certificate authority, the private key's associated
1085 public key will be stored in the resulting certificate.
1086
1087 :param algorithm: The
1088 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
1089 that will be used to generate the request signature.
1090
Andre Caron341ff852015-06-06 20:14:31 -04001091 :returns: A new
1092 :class:`~cryptography.x509.CertificateSigningRequest`.
Andre Caron0ef595f2015-05-18 13:53:43 -04001093
1094
Paul Kehrer719d5362015-01-01 20:03:52 -06001095.. class:: Name
1096
1097 .. versionadded:: 0.8
1098
Paul Kehrer53d8d492015-02-13 18:47:30 -06001099 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -06001100 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -06001101 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -06001102 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
1103 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -06001104
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001105 Technically, a Name is a list of *sets* of attributes, called *Relative
1106 Distinguished Names* or *RDNs*, although multi-valued RDNs are rarely
1107 encountered. The iteration order of values within a multi-valued RDN is
1108 undefined. If you need to handle multi-valued RDNs, the ``rdns`` property
1109 gives access to an ordered list of :class:`RelativeDistinguishedName`
1110 objects.
1111
1112 A Name can be initialized with an iterable of :class:`NameAttribute` (the
1113 common case where each RDN has a single attribute) or an iterable of
1114 :class:`RelativeDistinguishedName` objects (in the rare case of
1115 multi-valued RDNs).
1116
Paul Kehrer53d8d492015-02-13 18:47:30 -06001117 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -06001118
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001119 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -06001120 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -06001121 >>> for attribute in cert.subject:
1122 ... print(attribute)
1123 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
1124 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')>
1125 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -06001126
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001127 .. attribute:: rdns
1128
1129 .. versionadded:: 1.6
1130
1131 :type: list of :class:`RelativeDistinguishedName`
1132
Paul Kehrere901d642015-02-11 18:50:58 -06001133 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -06001134
Paul Kehrere901d642015-02-11 18:50:58 -06001135 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -06001136
Paul Kehrere901d642015-02-11 18:50:58 -06001137 :returns: A list of :class:`NameAttribute` instances that match the
1138 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -06001139
1140 .. doctest::
1141
Paul Kehrere27f6582015-08-10 18:33:38 -05001142 >>> cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)
Paul Kehrere901d642015-02-11 18:50:58 -06001143 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -06001144
Paul Kehrer3a15b032016-11-13 14:30:11 -08001145 .. method:: public_bytes(backend)
1146
1147 .. versionadded:: 1.6
1148
1149 :param backend: A backend supporting the
1150 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
1151 interface.
1152
1153 :return bytes: The DER encoded name.
1154
Paul Kehrere76cd272014-12-14 19:00:51 -06001155.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -10001156
1157 .. versionadded:: 0.7
1158
1159 An enumeration for X.509 versions.
1160
1161 .. attribute:: v1
1162
1163 For version 1 X.509 certificates.
1164
1165 .. attribute:: v3
1166
1167 For version 3 X.509 certificates.
1168
Paul Kehrer806bfb22015-02-02 17:05:24 -06001169.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001170
1171 .. versionadded:: 0.8
1172
Fraser Tweedale01ee6f52016-11-12 01:28:56 +10001173 An X.509 name consists of a list of :class:`RelativeDistinguishedName`
1174 instances, which consist of a set of :class:`NameAttribute` instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001175
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001176 .. attribute:: oid
1177
1178 :type: :class:`ObjectIdentifier`
1179
1180 The attribute OID.
1181
1182 .. attribute:: value
1183
Paul Kehrerd5852cb2015-01-30 08:25:23 -06001184 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001185
1186 The value of the attribute.
1187
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001188
1189.. class:: RelativeDistinguishedName(attributes)
1190
1191 .. versionadded:: 1.6
1192
1193 A relative distinguished name is a non-empty set of name attributes. The
1194 object is iterable to get every attribute.
1195
1196 .. method:: get_attributes_for_oid(oid)
1197
1198 :param oid: An :class:`ObjectIdentifier` instance.
1199
1200 :returns: A list of :class:`NameAttribute` instances that match the OID
1201 provided. The list should contain zero or one values.
1202
1203
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001204.. class:: ObjectIdentifier
1205
1206 .. versionadded:: 0.8
1207
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001208 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -06001209 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -06001210
Paul Kehrerd44f9a62015-02-04 14:47:34 -06001211 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001212
1213 :type: :class:`str`
1214
Paul Kehrerfedf4f42015-02-06 11:22:07 -06001215 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001216
Paul Kehrer31bdf792015-03-25 14:11:00 -05001217.. _general_name_classes:
1218
1219General Name Classes
1220~~~~~~~~~~~~~~~~~~~~
1221
1222.. class:: GeneralName
1223
1224 .. versionadded:: 0.9
1225
1226 This is the generic interface that all the following classes are registered
1227 against.
1228
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001229.. class:: RFC822Name(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001230
1231 .. versionadded:: 0.9
1232
1233 This corresponds to an email address. For example, ``user@example.com``.
1234
Paul Kehrer3e15ca52017-08-01 21:21:19 -05001235 ..note::
1236
1237 Starting with version 2.1 unicode input is deprecated. If passing an
1238 internationalized domain name (IDN) you should first IDNA encode the
1239 hostname and then pass the resulting bytes.
1240
1241 .. attribute:: bytes_value
1242
1243 .. versionadded:: 2.1
1244
1245 :type: bytes
1246
Paul Kehrer31bdf792015-03-25 14:11:00 -05001247 .. attribute:: value
1248
Paul Kehrer3e15ca52017-08-01 21:21:19 -05001249 .. deprecated:: 2.1
1250
1251 Deprecated accessor for the idna-decoded value of :attr:`bytes_value`
1252
Paul Kehrer31bdf792015-03-25 14:11:00 -05001253 :type: :term:`text`
1254
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001255.. class:: DNSName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001256
1257 .. versionadded:: 0.9
1258
1259 This corresponds to a domain name. For example, ``cryptography.io``.
1260
Alex Gaynorcdaf3ff2017-07-30 13:08:51 -04001261 .. attribute:: bytes_value
1262
Paul Kehrer908bbd32017-08-01 11:39:21 -05001263 .. versionadded:: 2.1
1264
Alex Gaynorcdaf3ff2017-07-30 13:08:51 -04001265 :type: bytes
1266
Paul Kehrer31bdf792015-03-25 14:11:00 -05001267 .. attribute:: value
1268
Paul Kehrer908bbd32017-08-01 11:39:21 -05001269 .. deprecated:: 2.1
1270
Alex Gaynorcdaf3ff2017-07-30 13:08:51 -04001271 Deprecated accessor for the idna-decoded value of :attr:`bytes_value`
1272
Paul Kehrer31bdf792015-03-25 14:11:00 -05001273 :type: :term:`text`
1274
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001275.. class:: DirectoryName(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001276
1277 .. versionadded:: 0.9
1278
1279 This corresponds to a directory name.
1280
1281 .. attribute:: value
1282
1283 :type: :class:`Name`
1284
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001285.. class:: UniformResourceIdentifier(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001286
1287 .. versionadded:: 0.9
1288
1289 This corresponds to a uniform resource identifier. For example,
Paul Kehrer6c29d742017-08-01 19:27:06 -05001290 ``https://cryptography.io``.
Paul Kehrerb8ef82e2015-04-22 16:04:24 -05001291
Paul Kehrer6c29d742017-08-01 19:27:06 -05001292 ..note::
Paul Kehrerb8ef82e2015-04-22 16:04:24 -05001293
Paul Kehrer6c29d742017-08-01 19:27:06 -05001294 Starting with version 2.1 unicode input is deprecated. If passing an
1295 internationalized domain name (IDN) you should first IDNA encode the
1296 hostname and then pass the resulting bytes.
1297
1298 .. attribute:: bytes_value
1299
1300 .. versionadded:: 2.1
1301
1302 :type: bytes
Paul Kehrer31bdf792015-03-25 14:11:00 -05001303
1304 .. attribute:: value
1305
Paul Kehrer6c29d742017-08-01 19:27:06 -05001306 .. deprecated:: 2.1
1307
1308 Deprecated accessor for the idna-decoded value of :attr:`bytes_value`
1309
Paul Kehrer31bdf792015-03-25 14:11:00 -05001310 :type: :term:`text`
1311
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001312.. class:: IPAddress(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001313
1314 .. versionadded:: 0.9
1315
1316 This corresponds to an IP address.
1317
1318 .. attribute:: value
1319
Paul Kehrereb177932015-05-17 18:33:33 -07001320 :type: :class:`~ipaddress.IPv4Address`,
1321 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
1322 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001323
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001324.. class:: RegisteredID(value)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001325
1326 .. versionadded:: 0.9
1327
1328 This corresponds to a registered ID.
1329
1330 .. attribute:: value
1331
1332 :type: :class:`ObjectIdentifier`
1333
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001334.. class:: OtherName(type_id, value)
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +00001335
1336 .. versionadded:: 1.0
1337
Joshua Tauberer18b6fc82015-07-05 21:44:51 +00001338 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 +00001339
1340 .. attribute:: type_id
1341
1342 :type: :class:`ObjectIdentifier`
1343
1344 .. attribute:: value
1345
1346 :type: `bytes`
1347
Paul Kehrer8cf26422015-03-21 09:50:24 -05001348X.509 Extensions
1349~~~~~~~~~~~~~~~~
1350
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001351.. class:: Extensions
1352
1353 .. versionadded:: 0.9
1354
1355 An X.509 Extensions instance is an ordered list of extensions. The object
1356 is iterable to get every extension.
1357
Paul Kehrerfa56a232015-03-17 13:14:03 -05001358 .. method:: get_extension_for_oid(oid)
1359
1360 :param oid: An :class:`ObjectIdentifier` instance.
1361
1362 :returns: An instance of the extension class.
1363
1364 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1365 not have the extension requested.
1366
Paul Kehrerfa56a232015-03-17 13:14:03 -05001367 .. doctest::
1368
Paul Kehrere27f6582015-08-10 18:33:38 -05001369 >>> from cryptography.x509.oid import ExtensionOID
1370 >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS)
Paul Kehrerfa56a232015-03-17 13:14:03 -05001371 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1372
Phoebe Queen019b7f82015-08-12 03:52:03 +01001373 .. method:: get_extension_for_class(extclass)
1374
Phoebe Queen6a603eb2015-08-12 14:14:49 +01001375 .. versionadded:: 1.1
1376
Phoebe Queen019b7f82015-08-12 03:52:03 +01001377 :param extclass: An extension class.
1378
1379 :returns: An instance of the extension class.
1380
1381 :raises cryptography.x509.ExtensionNotFound: If the certificate does
1382 not have the extension requested.
1383
1384 .. doctest::
1385
1386 >>> from cryptography import x509
1387 >>> cert.extensions.get_extension_for_class(x509.BasicConstraints)
1388 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
1389
Paul Kehrer8cf26422015-03-21 09:50:24 -05001390.. class:: Extension
1391
1392 .. versionadded:: 0.9
1393
Paul Kehrer85894662015-03-22 13:19:31 -05001394 .. attribute:: oid
1395
1396 :type: :class:`ObjectIdentifier`
1397
Paul Kehrere27f6582015-08-10 18:33:38 -05001398 One of the :class:`~cryptography.x509.oid.ExtensionOID` OIDs.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001399
1400 .. attribute:: critical
1401
1402 :type: bool
1403
Paul Kehrer58b75692015-03-22 23:24:58 -05001404 Determines whether a given extension is critical or not. :rfc:`5280`
1405 requires that "A certificate-using system MUST reject the certificate
1406 if it encounters a critical extension it does not recognize or a
1407 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -05001408
Paul Kehrer85894662015-03-22 13:19:31 -05001409 .. attribute:: value
1410
1411 Returns an instance of the extension type corresponding to the OID.
1412
Paul Kehrer14f0bd02015-08-06 11:55:18 +01001413.. class:: ExtensionType
1414
1415 .. versionadded:: 1.0
1416
1417 This is the interface against which all the following extension types are
1418 registered.
1419
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001420.. 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 -05001421
1422 .. versionadded:: 0.9
1423
1424 The key usage extension defines the purpose of the key contained in the
1425 certificate. The usage restriction might be employed when a key that could
Paul Kehrerb33de932015-08-06 23:41:05 +01001426 be used for more than one operation is to be restricted.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001427
Paul Kehrer822f3d32015-08-06 11:47:32 +01001428 .. attribute:: oid
1429
1430 .. versionadded:: 1.0
1431
1432 :type: :class:`ObjectIdentifier`
1433
Paul Kehrere27f6582015-08-10 18:33:38 -05001434 Returns :attr:`~cryptography.x509.oid.ExtensionOID.KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001435
Paul Kehrercecbbba2015-03-30 14:58:38 -05001436 .. attribute:: digital_signature
1437
1438 :type: bool
1439
Paul Kehrer738407b2015-04-01 22:39:02 -05001440 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001441 digital signatures, other than signatures on certificates
1442 (``key_cert_sign``) and CRLs (``crl_sign``).
1443
1444 .. attribute:: content_commitment
1445
1446 :type: bool
1447
Paul Kehrer738407b2015-04-01 22:39:02 -05001448 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -05001449 digital signatures, other than signatures on certificates
1450 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
1451 non-repudiation service that protects against the signing entity
1452 falsely denying some action. In the case of later conflict, a
1453 reliable third party may determine the authenticity of the signed
1454 data. This was called ``non_repudiation`` in older revisions of the
1455 X.509 specification.
1456
1457 .. attribute:: key_encipherment
1458
1459 :type: bool
1460
Paul Kehrer738407b2015-04-01 22:39:02 -05001461 This purpose is set to true when the subject public key is used for
1462 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001463
1464 .. attribute:: data_encipherment
1465
1466 :type: bool
1467
Paul Kehrer738407b2015-04-01 22:39:02 -05001468 This purpose is set to true when the subject public key is used for
1469 directly enciphering raw user data without the use of an intermediate
1470 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001471
1472 .. attribute:: key_agreement
1473
1474 :type: bool
1475
Paul Kehrer738407b2015-04-01 22:39:02 -05001476 This purpose is set to true when the subject public key is used for key
1477 agreement. For example, when a Diffie-Hellman key is to be used for
1478 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001479
1480 .. attribute:: key_cert_sign
1481
1482 :type: bool
1483
Paul Kehrer738407b2015-04-01 22:39:02 -05001484 This purpose is set to true when the subject public key is used for
1485 verifying signatures on public key certificates. If this purpose is set
1486 to true then ``ca`` must be true in the :class:`BasicConstraints`
1487 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001488
1489 .. attribute:: crl_sign
1490
1491 :type: bool
1492
Paul Kehrer738407b2015-04-01 22:39:02 -05001493 This purpose is set to true when the subject public key is used for
1494 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001495
1496 .. attribute:: encipher_only
1497
1498 :type: bool
1499
Paul Kehrer738407b2015-04-01 22:39:02 -05001500 When this purposes is set to true and the ``key_agreement`` purpose is
1501 also set, the subject public key may be used only for enciphering data
1502 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001503
1504 :raises ValueError: This is raised if accessed when ``key_agreement``
1505 is false.
1506
1507 .. attribute:: decipher_only
1508
1509 :type: bool
1510
Paul Kehrer738407b2015-04-01 22:39:02 -05001511 When this purposes is set to true and the ``key_agreement`` purpose is
1512 also set, the subject public key may be used only for deciphering data
1513 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001514
1515 :raises ValueError: This is raised if accessed when ``key_agreement``
1516 is false.
1517
1518
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001519.. class:: BasicConstraints(ca, path_length)
Paul Kehrer8cf26422015-03-21 09:50:24 -05001520
1521 .. versionadded:: 0.9
1522
Paul Kehrer85894662015-03-22 13:19:31 -05001523 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -05001524 certificate is allowed to sign additional certificates and what path
Paul Kehrerb33de932015-08-06 23:41:05 +01001525 length restrictions may exist.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001526
Paul Kehrer822f3d32015-08-06 11:47:32 +01001527 .. attribute:: oid
1528
1529 .. versionadded:: 1.0
1530
1531 :type: :class:`ObjectIdentifier`
1532
Paul Kehrere27f6582015-08-10 18:33:38 -05001533 Returns :attr:`~cryptography.x509.oid.ExtensionOID.BASIC_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001534
Paul Kehrer8cf26422015-03-21 09:50:24 -05001535 .. attribute:: ca
1536
1537 :type: bool
1538
1539 Whether the certificate can sign certificates.
1540
1541 .. attribute:: path_length
1542
Paul Kehrerfd1444c2015-03-21 19:47:05 -05001543 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -05001544
1545 The maximum path length for certificates subordinate to this
1546 certificate. This attribute only has meaning if ``ca`` is true.
1547 If ``ca`` is true then a path length of None means there's no
1548 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -04001549 If it is zero or greater then it defines the maximum length for a
1550 subordinate CA's certificate chain. For example, a ``path_length`` of 1
1551 means the certificate can sign a subordinate CA, but the subordinate CA
1552 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001553
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001554.. class:: ExtendedKeyUsage(usages)
Paul Kehrerffa2a152015-03-31 08:18:25 -05001555
1556 .. versionadded:: 0.9
1557
1558 This extension indicates one or more purposes for which the certified
1559 public key may be used, in addition to or in place of the basic
1560 purposes indicated in the key usage extension. The object is
Paul Kehrere27f6582015-08-10 18:33:38 -05001561 iterable to obtain the list of
1562 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs present.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001563
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001564 :param list usages: A list of
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001565 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs.
1566
Paul Kehrer822f3d32015-08-06 11:47:32 +01001567 .. attribute:: oid
1568
1569 .. versionadded:: 1.0
1570
1571 :type: :class:`ObjectIdentifier`
1572
Paul Kehrere27f6582015-08-10 18:33:38 -05001573 Returns :attr:`~cryptography.x509.oid.ExtensionOID.EXTENDED_KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001574
1575
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001576.. class:: OCSPNoCheck()
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001577
Paul Kehrer506a2152015-05-26 08:01:18 -05001578 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001579
1580 This presence of this extension indicates that an OCSP client can trust a
1581 responder for the lifetime of the responder's certificate. CAs issuing
1582 such a certificate should realize that a compromise of the responder's key
1583 is as serious as the compromise of a CA key used to sign CRLs, at least for
1584 the validity period of this certificate. CA's may choose to issue this type
1585 of certificate with a very short lifetime and renew it frequently. This
1586 extension is only relevant when the certificate is an authorized OCSP
1587 responder.
1588
Paul Kehrer822f3d32015-08-06 11:47:32 +01001589 .. attribute:: oid
1590
1591 .. versionadded:: 1.0
1592
1593 :type: :class:`ObjectIdentifier`
1594
Paul Kehrere27f6582015-08-10 18:33:38 -05001595 Returns :attr:`~cryptography.x509.oid.ExtensionOID.OCSP_NO_CHECK`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001596
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001597.. class:: NameConstraints(permitted_subtrees, excluded_subtrees)
Paul Kehrere0017be2015-05-17 20:39:40 -06001598
1599 .. versionadded:: 1.0
1600
1601 The name constraints extension, which only has meaning in a CA certificate,
1602 defines a name space within which all subject names in certificates issued
1603 beneath the CA certificate must (or must not) be in. For specific details
1604 on the way this extension should be processed see :rfc:`5280`.
1605
Paul Kehrer822f3d32015-08-06 11:47:32 +01001606 .. attribute:: oid
1607
1608 .. versionadded:: 1.0
1609
1610 :type: :class:`ObjectIdentifier`
1611
Paul Kehrere27f6582015-08-10 18:33:38 -05001612 Returns :attr:`~cryptography.x509.oid.ExtensionOID.NAME_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001613
Paul Kehrere0017be2015-05-17 20:39:40 -06001614 .. attribute:: permitted_subtrees
1615
1616 :type: list of :class:`GeneralName` objects or None
1617
1618 The set of permitted name patterns. If a name matches this and an
1619 element in ``excluded_subtrees`` it is invalid. At least one of
1620 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
1621
1622 .. attribute:: excluded_subtrees
1623
1624 :type: list of :class:`GeneralName` objects or None
1625
1626 Any name matching a restriction in the ``excluded_subtrees`` field is
1627 invalid regardless of information appearing in the
1628 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
1629 ``excluded_subtrees`` will be non-None.
1630
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001631.. class:: AuthorityKeyIdentifier(key_identifier, authority_cert_issuer, authority_cert_serial_number)
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001632
1633 .. versionadded:: 0.9
1634
1635 The authority key identifier extension provides a means of identifying the
1636 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001637 This extension is typically used to assist in determining the appropriate
1638 certificate chain. For more information about generation and use of this
1639 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001640
Paul Kehrer822f3d32015-08-06 11:47:32 +01001641 .. attribute:: oid
1642
1643 .. versionadded:: 1.0
1644
1645 :type: :class:`ObjectIdentifier`
1646
Paul Kehrere27f6582015-08-10 18:33:38 -05001647 Returns
1648 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001649
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001650 .. attribute:: key_identifier
1651
1652 :type: bytes
1653
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001654 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001655 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001656
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001657 .. attribute:: authority_cert_issuer
1658
1659 :type: :class:`Name` or None
1660
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001661 The :class:`Name` of the issuer's issuer.
1662
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001663 .. attribute:: authority_cert_serial_number
1664
1665 :type: int or None
1666
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001667 The serial number of the issuer's issuer.
1668
Paul Kehrer253929a2015-08-05 17:30:39 +01001669 .. classmethod:: from_issuer_public_key(public_key)
1670
1671 .. versionadded:: 1.0
1672
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001673 .. note::
1674
1675 This method should be used if the issuer certificate does not
1676 contain a :class:`~cryptography.x509.SubjectKeyIdentifier`.
1677 Otherwise, use
1678 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier`.
1679
Paul Kehrer253929a2015-08-05 17:30:39 +01001680 Creates a new AuthorityKeyIdentifier instance using the public key
1681 provided to generate the appropriate digest. This should be the
Paul Kehrer26ac47f2015-08-08 15:20:52 -05001682 **issuer's public key**. The resulting object will contain
1683 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1684 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1685 and
1686 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1687 will be None.
1688 The generated ``key_identifier`` is the SHA1 hash of the ``subjectPublicKey``
1689 ASN.1 bit string. This is the first recommendation in :rfc:`5280`
Paul Kehrer253929a2015-08-05 17:30:39 +01001690 section 4.2.1.2.
1691
Paul Kehrercc671822015-08-08 15:41:54 -05001692 :param public_key: One of
1693 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1694 ,
1695 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1696 , or
1697 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
Paul Kehrer253929a2015-08-05 17:30:39 +01001698
1699 .. doctest::
1700
1701 >>> from cryptography import x509
1702 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001703 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1704 >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key())
Paul Kehrer253929a2015-08-05 17:30:39 +01001705 <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 Kehrer61ff3562016-03-11 22:51:27 -04001707 .. classmethod:: from_issuer_subject_key_identifier(ski)
1708
1709 .. versionadded:: 1.3
1710
Paul Kehrer2d8e5742016-03-12 09:27:55 -04001711 .. note::
1712 This method should be used if the issuer certificate contains a
1713 :class:`~cryptography.x509.SubjectKeyIdentifier`. Otherwise, use
1714 :meth:`~cryptography.x509.AuthorityKeyIdentifier.from_issuer_public_key`.
1715
Paul Kehrer61ff3562016-03-11 22:51:27 -04001716 Creates a new AuthorityKeyIdentifier instance using the
1717 SubjectKeyIdentifier from the issuer certificate. The resulting object
1718 will contain
1719 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1720 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1721 and
1722 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1723 will be None.
1724
1725 :param ski: The
1726 :class:`~cryptography.x509.SubjectKeyIdentifier` from the issuer
1727 certificate.
1728
1729 .. doctest::
1730
1731 >>> from cryptography import x509
1732 >>> from cryptography.hazmat.backends import default_backend
1733 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1734 >>> ski = issuer_cert.extensions.get_extension_for_class(x509.SubjectKeyIdentifier)
1735 >>> x509.AuthorityKeyIdentifier.from_issuer_subject_key_identifier(ski)
1736 <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)>
1737
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001738.. class:: SubjectKeyIdentifier(digest)
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001739
1740 .. versionadded:: 0.9
1741
1742 The subject key identifier extension provides a means of identifying
1743 certificates that contain a particular public key.
1744
Paul Kehrer822f3d32015-08-06 11:47:32 +01001745 .. attribute:: oid
1746
1747 .. versionadded:: 1.0
1748
1749 :type: :class:`ObjectIdentifier`
1750
Paul Kehrere27f6582015-08-10 18:33:38 -05001751 Returns
1752 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001753
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001754 .. attribute:: digest
1755
1756 :type: bytes
1757
1758 The binary value of the identifier.
1759
Paul Kehrerd4a7f062015-08-05 18:32:18 +01001760 .. classmethod:: from_public_key(public_key)
Paul Kehrerf22f6122015-08-05 12:57:13 +01001761
1762 .. versionadded:: 1.0
1763
1764 Creates a new SubjectKeyIdentifier instance using the public key
1765 provided to generate the appropriate digest. This should be the public
Paul Kehrereb9ec002015-08-08 10:03:02 -05001766 key that is in the certificate. The generated digest is the SHA1 hash
1767 of the ``subjectPublicKey`` ASN.1 bit string. This is the first
1768 recommendation in :rfc:`5280` section 4.2.1.2.
Paul Kehrerf22f6122015-08-05 12:57:13 +01001769
1770 :param public_key: One of
1771 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1772 ,
1773 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1774 , or
1775 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
1776
Paul Kehrer253929a2015-08-05 17:30:39 +01001777 .. doctest::
1778
1779 >>> from cryptography import x509
1780 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001781 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
1782 >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key())
1783 <SubjectKeyIdentifier(digest='\xdb\xaa\xf0\x06\x11\xdbD\xfe\xbf\x93\x03\x8av\x88WP7\xa6\x91\xf7')>
Paul Kehrer253929a2015-08-05 17:30:39 +01001784
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001785.. class:: SubjectAlternativeName(general_names)
Paul Kehrer31bdf792015-03-25 14:11:00 -05001786
1787 .. versionadded:: 0.9
1788
1789 Subject alternative name is an X.509 extension that provides a list of
1790 :ref:`general name <general_name_classes>` instances that provide a set
1791 of identities for which the certificate is valid. The object is iterable to
1792 get every element.
1793
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001794 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001795
Paul Kehrer822f3d32015-08-06 11:47:32 +01001796 .. attribute:: oid
1797
1798 .. versionadded:: 1.0
1799
1800 :type: :class:`ObjectIdentifier`
1801
Paul Kehrere27f6582015-08-10 18:33:38 -05001802 Returns
1803 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001804
Paul Kehrer31bdf792015-03-25 14:11:00 -05001805 .. method:: get_values_for_type(type)
1806
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03001807 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer31bdf792015-03-25 14:11:00 -05001808 :ref:`general name classes <general_name_classes>`.
1809
1810 :returns: A list of values extracted from the matched general names.
Joshua Taubererd2afad32015-07-06 22:37:53 +00001811 The type of the returned values depends on the :class:`GeneralName`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001812
Paul Kehrer93ae8052015-05-02 23:18:09 -05001813 .. doctest::
1814
1815 >>> from cryptography import x509
1816 >>> from cryptography.hazmat.backends import default_backend
1817 >>> from cryptography.hazmat.primitives import hashes
1818 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001819 >>> # Get the subjectAltName extension from the certificate
Paul Kehrere27f6582015-08-10 18:33:38 -05001820 >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001821 >>> # Get the dNSName entries from the SAN extension
1822 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer93ae8052015-05-02 23:18:09 -05001823 [u'www.cryptography.io', u'cryptography.io']
1824
Paul Kehrer8cf26422015-03-21 09:50:24 -05001825
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001826.. class:: IssuerAlternativeName(general_names)
Paul Kehrer99125c92015-06-07 18:37:10 -05001827
1828 .. versionadded:: 1.0
1829
1830 Issuer alternative name is an X.509 extension that provides a list of
1831 :ref:`general name <general_name_classes>` instances that provide a set
1832 of identities for the certificate issuer. The object is iterable to
1833 get every element.
1834
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001835 :param list general_names: A list of :class:`GeneralName` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001836
Paul Kehrer822f3d32015-08-06 11:47:32 +01001837 .. attribute:: oid
1838
1839 .. versionadded:: 1.0
1840
1841 :type: :class:`ObjectIdentifier`
1842
Paul Kehrere27f6582015-08-10 18:33:38 -05001843 Returns
1844 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUER_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001845
Paul Kehrer99125c92015-06-07 18:37:10 -05001846 .. method:: get_values_for_type(type)
1847
Gabriel Orisaka617fe4b2016-07-31 10:49:59 -03001848 :param type: A :class:`GeneralName` instance. This is one of the
Paul Kehrer99125c92015-06-07 18:37:10 -05001849 :ref:`general name classes <general_name_classes>`.
1850
1851 :returns: A list of values extracted from the matched general names.
1852
1853
Alex Gaynor6a0718f2017-06-04 13:36:58 -04001854.. class:: PrecertificateSignedCertificateTimestamps(scts)
1855
1856 .. versionadded:: 2.0
1857
1858 This extension contains
1859 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
1860 instances which were issued for the pre-certificate corresponding to this
1861 certificate. These can be used to verify that the certificate is included
1862 in a public Certificate Transparency log.
1863
1864 It is an iterable containing one or more
1865 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
1866 objects.
1867
1868 :param list scts: A ``list`` of
1869 :class:`~cryptography.x509.certificate_transparency.SignedCertificateTimestamp`
1870 objects.
1871
1872 .. attribute:: oid
1873
1874 :type: :class:`ObjectIdentifier`
1875
1876 Returns
1877 :attr:`~cryptography.x509.oid.ExtensionOID.PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS`.
1878
1879
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001880.. class:: AuthorityInformationAccess(descriptions)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001881
1882 .. versionadded:: 0.9
1883
1884 The authority information access extension indicates how to access
1885 information and services for the issuer of the certificate in which
1886 the extension appears. Information and services may include online
1887 validation services (such as OCSP) and issuer data. It is an iterable,
Paul Kehrere27f6582015-08-10 18:33:38 -05001888 containing one or more :class:`~cryptography.x509.AccessDescription`
1889 instances.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001890
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001891 :param list descriptions: A list of :class:`AccessDescription` objects.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001892
Paul Kehrer822f3d32015-08-06 11:47:32 +01001893 .. attribute:: oid
1894
1895 .. versionadded:: 1.0
1896
1897 :type: :class:`ObjectIdentifier`
1898
Paul Kehrere27f6582015-08-10 18:33:38 -05001899 Returns
1900 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_INFORMATION_ACCESS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001901
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001902
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001903.. class:: AccessDescription(access_method, access_location)
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001904
Paul Kehrer5a485522015-05-06 00:29:12 -05001905 .. versionadded:: 0.9
1906
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001907 .. attribute:: access_method
1908
1909 :type: :class:`ObjectIdentifier`
1910
Paul Kehrerf506bca2015-05-02 22:31:47 -05001911 The access method defines what the ``access_location`` means. It must
Paul Kehrere27f6582015-08-10 18:33:38 -05001912 be either
1913 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` or
1914 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`.
1915 If it is
1916 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP`
1917 the access location will be where to obtain OCSP
1918 information for the certificate. If it is
1919 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`
1920 the access location will provide additional information about the
1921 issuing certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001922
1923 .. attribute:: access_location
1924
1925 :type: :class:`GeneralName`
1926
Paul Kehrerf506bca2015-05-02 22:31:47 -05001927 Where to access the information defined by the access method.
1928
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001929.. class:: CRLDistributionPoints(distribution_points)
Paul Kehrer5a485522015-05-06 00:29:12 -05001930
1931 .. versionadded:: 0.9
1932
1933 The CRL distribution points extension identifies how CRL information is
1934 obtained. It is an iterable, containing one or more
1935 :class:`DistributionPoint` instances.
1936
Paul Kehrer1cb9e552015-10-28 09:37:29 +09001937 :param list distribution_points: A list of :class:`DistributionPoint`
1938 instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001939
Paul Kehrer822f3d32015-08-06 11:47:32 +01001940 .. attribute:: oid
1941
1942 .. versionadded:: 1.0
1943
1944 :type: :class:`ObjectIdentifier`
1945
Paul Kehrere27f6582015-08-10 18:33:38 -05001946 Returns
1947 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_DISTRIBUTION_POINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001948
Paul Kehrer47c32ba2015-10-28 09:12:07 +09001949.. class:: DistributionPoint(full_name, relative_name, reasons, crl_issuer)
Paul Kehrer5a485522015-05-06 00:29:12 -05001950
1951 .. versionadded:: 0.9
1952
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001953 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05001954
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001955 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001956
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001957 This field describes methods to retrieve the CRL. At most one of
1958 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001959
1960 .. attribute:: relative_name
1961
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001962 :type: :class:`RelativeDistinguishedName` or None
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001963
1964 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001965 issuer. At most one of ``full_name`` or ``relative_name`` will be
1966 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05001967
Fraser Tweedale02467dd2016-11-07 15:54:04 +10001968 .. versionchanged:: 1.6
1969 Changed from :class:`Name` to :class:`RelativeDistinguishedName`.
1970
Paul Kehrer5a485522015-05-06 00:29:12 -05001971 .. attribute:: crl_issuer
1972
1973 :type: list of :class:`GeneralName` instances or None
1974
1975 Information about the issuer of the CRL.
1976
1977 .. attribute:: reasons
1978
Paul Kehrer3fd02602015-05-09 19:46:13 -05001979 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001980
1981 The reasons a given distribution point may be used for when performing
1982 revocation checks.
1983
1984.. class:: ReasonFlags
1985
1986 .. versionadded:: 0.9
1987
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001988 An enumeration for CRL reasons.
1989
1990 .. attribute:: unspecified
1991
1992 It is unspecified why the certificate was revoked. This reason cannot
1993 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001994
1995 .. attribute:: key_compromise
1996
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001997 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001998
1999 .. attribute:: ca_compromise
2000
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002001 This reason indicates that the CA issuing the certificate was
2002 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05002003
2004 .. attribute:: affiliation_changed
2005
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002006 This reason indicates that the subject's name or other information has
2007 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05002008
2009 .. attribute:: superseded
2010
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002011 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05002012
2013 .. attribute:: cessation_of_operation
2014
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002015 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05002016
2017 .. attribute:: certificate_hold
2018
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002019 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05002020
2021 .. attribute:: privilege_withdrawn
2022
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002023 This reason indicates that the privilege granted by this certificate
2024 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05002025
2026 .. attribute:: aa_compromise
2027
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05002028 When an attribute authority has been compromised.
2029
2030 .. attribute:: remove_from_crl
2031
2032 This reason indicates that the certificate was on hold and should be
2033 removed from the CRL. This reason cannot be used as a reason flag
2034 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05002035
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002036.. class:: InhibitAnyPolicy(skip_certs)
Paul Kehrer16fae762015-05-01 23:14:20 -05002037
2038 .. versionadded:: 1.0
2039
2040 The inhibit ``anyPolicy`` extension indicates that the special OID
Paul Kehrere27f6582015-08-10 18:33:38 -05002041 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY`, is not
2042 considered an explicit match for other :class:`CertificatePolicies` except
2043 when it appears in an intermediate self-issued CA certificate. The value
2044 indicates the number of additional non-self-issued certificates that may
2045 appear in the path before
2046 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` is no
2047 longer permitted. For example, a value of one indicates that
2048 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` may be
2049 processed in certificates issued by the subject of this certificate, but
2050 not in additional certificates in the path.
Paul Kehrer16fae762015-05-01 23:14:20 -05002051
Paul Kehrer822f3d32015-08-06 11:47:32 +01002052 .. attribute:: oid
2053
2054 .. versionadded:: 1.0
2055
2056 :type: :class:`ObjectIdentifier`
2057
Paul Kehrere27f6582015-08-10 18:33:38 -05002058 Returns
2059 :attr:`~cryptography.x509.oid.ExtensionOID.INHIBIT_ANY_POLICY`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002060
Paul Kehrer16fae762015-05-01 23:14:20 -05002061 .. attribute:: skip_certs
2062
2063 :type: int
2064
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002065.. class:: PolicyConstraints
2066
2067 .. versionadded:: 1.3
2068
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002069 The policy constraints extension is used to inhibit policy mapping or
2070 require that each certificate in a chain contain an acceptable policy
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002071 identifier. For more information about the use of this extension see
2072 :rfc:`5280`.
2073
Paul Kehrer159b3b52016-02-26 08:27:22 -06002074 .. attribute:: oid
2075
2076 :type: :class:`ObjectIdentifier`
2077
2078 Returns :attr:`~cryptography.x509.oid.ExtensionOID.POLICY_CONSTRAINTS`.
2079
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002080 .. attribute:: require_explicit_policy
2081
2082 :type: int or None
2083
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002084 If this field is not None, the value indicates the number of additional
2085 certificates that may appear in the chain before an explicit policy is
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002086 required for the entire path. When an explicit policy is required, it
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002087 is necessary for all certificates in the chain to contain an acceptable
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002088 policy identifier in the certificate policies extension. An
2089 acceptable policy identifier is the identifier of a policy required
2090 by the user of the certification path or the identifier of a policy
2091 that has been declared equivalent through policy mapping.
2092
2093 .. attribute:: inhibit_policy_mapping
2094
2095 :type: int or None
2096
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002097 If this field is not None, the value indicates the number of additional
2098 certificates that may appear in the chain before policy mapping is no
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002099 longer permitted. For example, a value of one indicates that policy
2100 mapping may be processed in certificates issued by the subject of this
Paul Kehrer648c0fb2016-02-26 16:10:36 -06002101 certificate, but not in additional certificates in the chain.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002102
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002103.. class:: CRLNumber(crl_number)
2104
2105 .. versionadded:: 1.2
2106
Paul Kehrere32b9942015-12-22 22:26:53 -06002107 The CRL number is a CRL extension that conveys a monotonically increasing
2108 sequence number for a given CRL scope and CRL issuer. This extension allows
2109 users to easily determine when a particular CRL supersedes another CRL.
2110 :rfc:`5280` requires that this extension be present in conforming CRLs.
Paul Kehrer3b95cd72015-12-22 21:40:20 -06002111
2112 .. attribute:: oid
2113
2114 :type: :class:`ObjectIdentifier`
2115
2116 Returns
2117 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_NUMBER`.
2118
2119 .. attribute:: crl_number
2120
2121 :type: int
2122
Paul Kehrer14fd6972015-12-30 10:58:25 -06002123.. class:: UnrecognizedExtension
2124
2125 .. versionadded:: 1.2
2126
Alex Gaynord08ddd52017-05-20 09:01:54 -07002127 A generic extension class used to hold the raw value of extensions that
2128 ``cryptography`` does not know how to parse.
Paul Kehrer14fd6972015-12-30 10:58:25 -06002129
2130 .. attribute:: oid
2131
2132 :type: :class:`ObjectIdentifier`
2133
2134 Returns the OID associated with this extension.
2135
2136 .. attribute:: value
2137
2138 :type: byte
2139
2140 Returns the DER encoded bytes payload of the extension.
2141
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002142.. class:: CertificatePolicies(policies)
Paul Kehrer0d210922015-04-28 17:31:07 -05002143
2144 .. versionadded:: 0.9
2145
Paul Kehrer2e879742015-05-02 23:09:56 -05002146 The certificate policies extension is an iterable, containing one or more
2147 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05002148
Paul Kehrer1cb9e552015-10-28 09:37:29 +09002149 :param list policies: A list of :class:`PolicyInformation` instances.
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002150
Paul Kehrer822f3d32015-08-06 11:47:32 +01002151 .. attribute:: oid
2152
2153 .. versionadded:: 1.0
2154
2155 :type: :class:`ObjectIdentifier`
2156
Paul Kehrere27f6582015-08-10 18:33:38 -05002157 Returns
2158 :attr:`~cryptography.x509.oid.ExtensionOID.CERTIFICATE_POLICIES`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01002159
Paul Kehrer0d210922015-04-28 17:31:07 -05002160Certificate Policies Classes
2161~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2162
2163These classes may be present within a :class:`CertificatePolicies` instance.
2164
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002165.. class:: PolicyInformation(policy_identifier, policy_qualifiers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002166
2167 .. versionadded:: 0.9
2168
2169 Contains a policy identifier and an optional list of qualifiers.
2170
2171 .. attribute:: policy_identifier
2172
2173 :type: :class:`ObjectIdentifier`
2174
2175 .. attribute:: policy_qualifiers
2176
2177 :type: list
2178
Paul Kehrerba35b3b2015-05-10 13:07:59 -05002179 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002180 If the value is text it is a pointer to the practice statement
2181 published by the certificate authority. If it is a user notice it is
2182 meant for display to the relying party when the certificate is
2183 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05002184
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002185.. class:: UserNotice(notice_reference, explicit_text)
Paul Kehrer0d210922015-04-28 17:31:07 -05002186
2187 .. versionadded:: 0.9
2188
Paul Kehrer2e879742015-05-02 23:09:56 -05002189 User notices are intended for display to a relying party when a certificate
2190 is used. In practice, few if any UIs expose this data and it is a rarely
2191 encoded component.
2192
Paul Kehrer0d210922015-04-28 17:31:07 -05002193 .. attribute:: notice_reference
2194
2195 :type: :class:`NoticeReference` or None
2196
Paul Kehrer2e879742015-05-02 23:09:56 -05002197 The notice reference field names an organization and identifies,
2198 by number, a particular statement prepared by that organization.
2199
Paul Kehrer0d210922015-04-28 17:31:07 -05002200 .. attribute:: explicit_text
2201
Paul Kehrer2e879742015-05-02 23:09:56 -05002202 This field includes an arbitrary textual statement directly in the
2203 certificate.
2204
Paul Kehrer0d210922015-04-28 17:31:07 -05002205 :type: :term:`text`
2206
Paul Kehrer47c32ba2015-10-28 09:12:07 +09002207.. class:: NoticeReference(organization, notice_numbers)
Paul Kehrer0d210922015-04-28 17:31:07 -05002208
Paul Kehrer2e879742015-05-02 23:09:56 -05002209 Notice reference can name an organization and provide information about
2210 notices related to the certificate. For example, it might identify the
2211 organization name and notice number 1. Application software could
2212 have a notice file containing the current set of notices for the named
2213 organization; the application would then extract the notice text from the
2214 file and display it. In practice this is rarely seen.
2215
Paul Kehrer0d210922015-04-28 17:31:07 -05002216 .. versionadded:: 0.9
2217
2218 .. attribute:: organization
2219
Paul Kehrer66c61702015-05-12 16:39:18 -05002220 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05002221
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05002222 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05002223
Paul Kehrer66c61702015-05-12 16:39:18 -05002224 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05002225
Paul Kehrer66c61702015-05-12 16:39:18 -05002226 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05002227
Paul Kehrere5f152b2015-12-25 23:55:47 -06002228.. _crl_entry_extensions:
2229
Paul Kehrer49bb7562015-12-25 16:17:40 -06002230CRL Entry Extensions
2231~~~~~~~~~~~~~~~~~~~~
2232
2233These extensions are only valid within a :class:`RevokedCertificate` object.
2234
2235.. class:: CertificateIssuer(general_names)
2236
2237 .. versionadded:: 1.2
2238
2239 The certificate issuer is an extension that is only valid inside
2240 :class:`~cryptography.x509.RevokedCertificate` objects. If the
2241 ``indirectCRL`` property of the parent CRL's IssuingDistributionPoint
2242 extension is set, then this extension identifies the certificate issuer
2243 associated with the revoked certificate. The object is iterable to get
2244 every element.
2245
2246 :param list general_names: A list of :class:`GeneralName` instances.
2247
2248 .. attribute:: oid
2249
2250 :type: :class:`ObjectIdentifier`
2251
2252 Returns
2253 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CERTIFICATE_ISSUER`.
2254
2255 .. method:: get_values_for_type(type)
2256
2257 :param type: A :class:`GeneralName` instance. This is one of the
2258 :ref:`general name classes <general_name_classes>`.
2259
2260 :returns: A list of values extracted from the matched general names.
2261 The type of the returned values depends on the :class:`GeneralName`.
2262
Paul Kehrer7058ece2015-12-25 22:28:29 -06002263.. class:: CRLReason(reason)
2264
2265 .. versionadded:: 1.2
2266
2267 CRL reason (also known as ``reasonCode``) is an extension that is only
2268 valid inside :class:`~cryptography.x509.RevokedCertificate` objects. It
2269 identifies a reason for the certificate revocation.
2270
2271 :param reason: A value from the
2272 :class:`~cryptography.x509.oid.CRLEntryExtensionOID` enum.
2273
2274 .. attribute:: oid
2275
2276 :type: :class:`ObjectIdentifier`
2277
2278 Returns
2279 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.CRL_REASON`.
2280
2281 .. attribute:: reason
2282
2283 :type: An element from :class:`~cryptography.x509.ReasonFlags`
2284
Paul Kehrer23c0bbc2015-12-25 22:35:19 -06002285.. class:: InvalidityDate(invalidity_date)
2286
2287 .. versionadded:: 1.2
2288
2289 Invalidity date is an extension that is only valid inside
2290 :class:`~cryptography.x509.RevokedCertificate` objects. It provides
2291 the date on which it is known or suspected that the private key was
2292 compromised or that the certificate otherwise became invalid.
2293 This date may be earlier than the revocation date in the CRL entry,
2294 which is the date at which the CA processed the revocation.
2295
2296 :param invalidity_date: The :class:`datetime.datetime` when it is known
2297 or suspected that the private key was compromised.
2298
2299 .. attribute:: oid
2300
2301 :type: :class:`ObjectIdentifier`
2302
2303 Returns
2304 :attr:`~cryptography.x509.oid.CRLEntryExtensionOID.INVALIDITY_DATE`.
2305
2306 .. attribute:: invalidity_date
2307
2308 :type: :class:`datetime.datetime`
2309
Paul Kehrer49bb7562015-12-25 16:17:40 -06002310
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002311Object Identifiers
2312~~~~~~~~~~~~~~~~~~
2313
Paul Kehrer4bb46492015-02-07 16:59:14 -06002314X.509 elements are frequently identified by :class:`ObjectIdentifier`
2315instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002316
Paul Kehrere27f6582015-08-10 18:33:38 -05002317.. currentmodule:: cryptography.x509.oid
Paul Kehrer56da2a52015-02-11 23:35:07 -06002318
Paul Kehrere27f6582015-08-10 18:33:38 -05002319.. class:: NameOID
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002320
Paul Kehrere27f6582015-08-10 18:33:38 -05002321 These OIDs are typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06002322
Paul Kehrere27f6582015-08-10 18:33:38 -05002323 .. versionadded:: 1.0
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002324
Paul Kehrere27f6582015-08-10 18:33:38 -05002325 .. attribute:: COMMON_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002326
Paul Kehrere27f6582015-08-10 18:33:38 -05002327 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
2328 name would be encoded here for server certificates. :rfc:`2818`
2329 deprecates this practice and names of that type should now be located
2330 in a :class:`~cryptography.x509.SubjectAlternativeName` extension.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002331
Paul Kehrere27f6582015-08-10 18:33:38 -05002332 .. attribute:: COUNTRY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002333
Paul Kehrere27f6582015-08-10 18:33:38 -05002334 Corresponds to the dotted string ``"2.5.4.6"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002335
Paul Kehrere27f6582015-08-10 18:33:38 -05002336 .. attribute:: LOCALITY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002337
Paul Kehrere27f6582015-08-10 18:33:38 -05002338 Corresponds to the dotted string ``"2.5.4.7"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002339
Paul Kehrere27f6582015-08-10 18:33:38 -05002340 .. attribute:: STATE_OR_PROVINCE_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002341
Paul Kehrere27f6582015-08-10 18:33:38 -05002342 Corresponds to the dotted string ``"2.5.4.8"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002343
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002344 .. attribute:: STREET_ADDRESS
2345
2346 .. versionadded:: 1.6
2347
2348 Corresponds to the dotted string ``"2.5.4.9"``.
2349
Paul Kehrere27f6582015-08-10 18:33:38 -05002350 .. attribute:: ORGANIZATION_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002351
Paul Kehrere27f6582015-08-10 18:33:38 -05002352 Corresponds to the dotted string ``"2.5.4.10"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002353
Paul Kehrere27f6582015-08-10 18:33:38 -05002354 .. attribute:: ORGANIZATIONAL_UNIT_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002355
Paul Kehrere27f6582015-08-10 18:33:38 -05002356 Corresponds to the dotted string ``"2.5.4.11"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002357
Paul Kehrere27f6582015-08-10 18:33:38 -05002358 .. attribute:: SERIAL_NUMBER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002359
Paul Kehrere27f6582015-08-10 18:33:38 -05002360 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from
2361 the serial number of the certificate itself (which can be obtained with
Chelsea Winfreee295f3a2016-06-02 21:15:54 -07002362 :func:`~cryptography.x509.Certificate.serial_number`).
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002363
Paul Kehrere27f6582015-08-10 18:33:38 -05002364 .. attribute:: SURNAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002365
Paul Kehrere27f6582015-08-10 18:33:38 -05002366 Corresponds to the dotted string ``"2.5.4.4"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002367
Paul Kehrere27f6582015-08-10 18:33:38 -05002368 .. attribute:: GIVEN_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06002369
Paul Kehrere27f6582015-08-10 18:33:38 -05002370 Corresponds to the dotted string ``"2.5.4.42"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002371
Paul Kehrere27f6582015-08-10 18:33:38 -05002372 .. attribute:: TITLE
Paul Kehrer858b9b72015-02-05 09:50:31 -06002373
Paul Kehrere27f6582015-08-10 18:33:38 -05002374 Corresponds to the dotted string ``"2.5.4.12"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002375
Paul Kehrere27f6582015-08-10 18:33:38 -05002376 .. attribute:: GENERATION_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002377
Paul Kehrere27f6582015-08-10 18:33:38 -05002378 Corresponds to the dotted string ``"2.5.4.44"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002379
Paul Kehrerc7ab9312016-11-12 05:00:42 -08002380 .. attribute:: X500_UNIQUE_IDENTIFIER
Paul Kehrerc3b8ff62016-11-11 17:38:59 -08002381
2382 .. versionadded:: 1.6
2383
2384 Corresponds to the dotted string ``"2.5.4.45"``.
2385
Paul Kehrere27f6582015-08-10 18:33:38 -05002386 .. attribute:: DN_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06002387
Paul Kehrere27f6582015-08-10 18:33:38 -05002388 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
2389 disambiguating information to add to the relative distinguished name of an
2390 entry. See :rfc:`2256`.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002391
Paul Kehrere27f6582015-08-10 18:33:38 -05002392 .. attribute:: PSEUDONYM
Paul Kehrer858b9b72015-02-05 09:50:31 -06002393
Paul Kehrere27f6582015-08-10 18:33:38 -05002394 Corresponds to the dotted string ``"2.5.4.65"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002395
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002396 .. attribute:: USER_ID
2397
2398 .. versionadded:: 1.6
2399
2400 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.1"``.
2401
Paul Kehrere27f6582015-08-10 18:33:38 -05002402 .. attribute:: DOMAIN_COMPONENT
Paul Kehrer858b9b72015-02-05 09:50:31 -06002403
Paul Kehrere27f6582015-08-10 18:33:38 -05002404 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
2405 holding one component of a domain name. See :rfc:`4519`.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002406
Paul Kehrere27f6582015-08-10 18:33:38 -05002407 .. attribute:: EMAIL_ADDRESS
Paul Kehrer56da2a52015-02-11 23:35:07 -06002408
Paul Kehrere27f6582015-08-10 18:33:38 -05002409 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002410
Alex Gaynor1d3f2bf2015-12-19 12:15:09 -05002411 .. attribute:: JURISDICTION_COUNTRY_NAME
2412
2413 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.3"``.
2414
Alex Gaynor45e507f2015-12-19 13:44:23 -05002415 .. attribute:: JURISDICTION_LOCALITY_NAME
2416
2417 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.1"``.
2418
2419 .. attribute:: JURISDICTION_STATE_OR_PROVINCE_NAME
2420
2421 Corresponds to the dotted string ``"1.3.6.1.4.1.311.60.2.1.2"``.
2422
Alex Gaynora2293c82015-12-19 20:49:15 -05002423 .. attribute:: BUSINESS_CATEGORY
2424
2425 Corresponds to the dotted string ``"2.5.4.15"``.
2426
Paul Kehrer36d5cd62016-11-19 22:05:26 +08002427 .. attribute:: POSTAL_ADDRESS
2428
2429 .. versionadded:: 1.6
2430
2431 Corresponds to the dotted string ``"2.5.4.16"``.
2432
2433 .. attribute:: POSTAL_CODE
2434
2435 .. versionadded:: 1.6
2436
2437 Corresponds to the dotted string ``"2.5.4.17"``.
2438
Paul Kehrer56da2a52015-02-11 23:35:07 -06002439
Paul Kehrere27f6582015-08-10 18:33:38 -05002440.. class:: SignatureAlgorithmOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002441
Paul Kehrere27f6582015-08-10 18:33:38 -05002442 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002443
Paul Kehrere27f6582015-08-10 18:33:38 -05002444 .. attribute:: RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06002445
Paul Kehrere27f6582015-08-10 18:33:38 -05002446 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
2447 an MD5 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002448
Paul Kehrere27f6582015-08-10 18:33:38 -05002449 .. attribute:: RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002450
Paul Kehrere27f6582015-08-10 18:33:38 -05002451 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
2452 a SHA1 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002453
Paul Kehrere27f6582015-08-10 18:33:38 -05002454 .. attribute:: RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002455
Paul Kehrere27f6582015-08-10 18:33:38 -05002456 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
2457 a SHA224 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002458
Paul Kehrere27f6582015-08-10 18:33:38 -05002459 .. attribute:: RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002460
Paul Kehrere27f6582015-08-10 18:33:38 -05002461 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
2462 a SHA256 digest signed by an RSA key.
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002463
Paul Kehrere27f6582015-08-10 18:33:38 -05002464 .. attribute:: RSA_WITH_SHA384
Alex Gaynor3aadabf2015-06-23 22:06:21 -04002465
Paul Kehrere27f6582015-08-10 18:33:38 -05002466 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
2467 a SHA384 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002468
Paul Kehrere27f6582015-08-10 18:33:38 -05002469 .. attribute:: RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06002470
Paul Kehrere27f6582015-08-10 18:33:38 -05002471 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
2472 a SHA512 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002473
Paul Kehrere27f6582015-08-10 18:33:38 -05002474 .. attribute:: ECDSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06002475
Paul Kehrere27f6582015-08-10 18:33:38 -05002476 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
2477 digest signed by an ECDSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002478
Paul Kehrere27f6582015-08-10 18:33:38 -05002479 .. attribute:: ECDSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06002480
Paul Kehrere27f6582015-08-10 18:33:38 -05002481 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
2482 a SHA224 digest signed by an ECDSA key.
2483
2484 .. attribute:: ECDSA_WITH_SHA256
2485
2486 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
2487 a SHA256 digest signed by an ECDSA key.
2488
2489 .. attribute:: ECDSA_WITH_SHA384
2490
2491 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
2492 a SHA384 digest signed by an ECDSA key.
2493
2494 .. attribute:: ECDSA_WITH_SHA512
2495
2496 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
2497 a SHA512 digest signed by an ECDSA key.
2498
2499 .. attribute:: DSA_WITH_SHA1
2500
2501 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
2502 a SHA1 digest signed by a DSA key.
2503
2504 .. attribute:: DSA_WITH_SHA224
2505
2506 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
2507 a SHA224 digest signed by a DSA key.
2508
2509 .. attribute:: DSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06002510
Paul Kehrere27f6582015-08-10 18:33:38 -05002511 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
2512 a SHA256 digest signed by a DSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002513
Paul Kehrer56da2a52015-02-11 23:35:07 -06002514
Paul Kehrere27f6582015-08-10 18:33:38 -05002515.. class:: ExtendedKeyUsageOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06002516
Paul Kehrere27f6582015-08-10 18:33:38 -05002517 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06002518
Paul Kehrere27f6582015-08-10 18:33:38 -05002519 .. attribute:: SERVER_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002520
Paul Kehrere27f6582015-08-10 18:33:38 -05002521 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used
2522 to denote that a certificate may be used for TLS web server
2523 authentication.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002524
Paul Kehrere27f6582015-08-10 18:33:38 -05002525 .. attribute:: CLIENT_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06002526
Paul Kehrere27f6582015-08-10 18:33:38 -05002527 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used
2528 to denote that a certificate may be used for TLS web client
2529 authentication.
Paul Kehrerffa2a152015-03-31 08:18:25 -05002530
Paul Kehrere27f6582015-08-10 18:33:38 -05002531 .. attribute:: CODE_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002532
Paul Kehrere27f6582015-08-10 18:33:38 -05002533 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used
2534 to denote that a certificate may be used for code signing.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002535
Paul Kehrere27f6582015-08-10 18:33:38 -05002536 .. attribute:: EMAIL_PROTECTION
Paul Kehrere1513fa2015-03-30 23:08:17 -05002537
Paul Kehrere27f6582015-08-10 18:33:38 -05002538 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used
2539 to denote that a certificate may be used for email protection.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002540
Paul Kehrere27f6582015-08-10 18:33:38 -05002541 .. attribute:: TIME_STAMPING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002542
Paul Kehrere27f6582015-08-10 18:33:38 -05002543 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used
2544 to denote that a certificate may be used for time stamping.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002545
Paul Kehrere27f6582015-08-10 18:33:38 -05002546 .. attribute:: OCSP_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05002547
Paul Kehrere27f6582015-08-10 18:33:38 -05002548 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used
2549 to denote that a certificate may be used for signing OCSP responses.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002550
Alex Gaynorb7912ee2017-07-03 10:07:02 -04002551 .. attribute:: ANY_EXTENDED_KEY_USAGE
2552
2553 .. versionadded:: 2.0
2554
2555 Corresponds to the dotted string ``"2.5.29.37.0"``. This is used to
2556 denote that a certificate may be used for _any_ purposes.
2557
Paul Kehrere1513fa2015-03-30 23:08:17 -05002558
Paul Kehrere27f6582015-08-10 18:33:38 -05002559.. class:: AuthorityInformationAccessOID
Paul Kehrere1513fa2015-03-30 23:08:17 -05002560
Paul Kehrere27f6582015-08-10 18:33:38 -05002561 .. versionadded:: 1.0
Paul Kehrere1513fa2015-03-30 23:08:17 -05002562
Paul Kehrere27f6582015-08-10 18:33:38 -05002563 .. attribute:: OCSP
Paul Kehrere1513fa2015-03-30 23:08:17 -05002564
Paul Kehrere27f6582015-08-10 18:33:38 -05002565 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
2566 identifier for OCSP data in
2567 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrere1513fa2015-03-30 23:08:17 -05002568
Paul Kehrere27f6582015-08-10 18:33:38 -05002569 .. attribute:: CA_ISSUERS
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002570
Paul Kehrere27f6582015-08-10 18:33:38 -05002571 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
2572 identifier for CA issuer data in
2573 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002574
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002575
Paul Kehrere27f6582015-08-10 18:33:38 -05002576.. class:: CertificatePoliciesOID
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002577
Paul Kehrere27f6582015-08-10 18:33:38 -05002578 .. versionadded:: 1.0
Paul Kehrer3e6d5582015-05-02 21:57:56 -05002579
Paul Kehrere27f6582015-08-10 18:33:38 -05002580 .. attribute:: CPS_QUALIFIER
Paul Kehrer2e879742015-05-02 23:09:56 -05002581
Paul Kehrere27f6582015-08-10 18:33:38 -05002582 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002583
Paul Kehrere27f6582015-08-10 18:33:38 -05002584 .. attribute:: CPS_USER_NOTICE
Paul Kehrer2e879742015-05-02 23:09:56 -05002585
Paul Kehrere27f6582015-08-10 18:33:38 -05002586 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05002587
Paul Kehrere27f6582015-08-10 18:33:38 -05002588 .. attribute:: ANY_POLICY
Paul Kehrer2e879742015-05-02 23:09:56 -05002589
Paul Kehrere27f6582015-08-10 18:33:38 -05002590 Corresponds to the dotted string ``"2.5.29.32.0"``.
Paul Kehrer16fae762015-05-01 23:14:20 -05002591
Paul Kehrer16fae762015-05-01 23:14:20 -05002592
Paul Kehrere27f6582015-08-10 18:33:38 -05002593.. class:: ExtensionOID
Paul Kehrer5553d572015-03-23 21:08:01 -05002594
Paul Kehrere27f6582015-08-10 18:33:38 -05002595 .. versionadded:: 1.0
Paul Kehrer2bb94642015-03-21 09:54:17 -05002596
Paul Kehrere27f6582015-08-10 18:33:38 -05002597 .. attribute:: BASIC_CONSTRAINTS
Paul Kehrer2bb94642015-03-21 09:54:17 -05002598
Paul Kehrere27f6582015-08-10 18:33:38 -05002599 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
2600 :class:`~cryptography.x509.BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05002601
Paul Kehrere27f6582015-08-10 18:33:38 -05002602 .. attribute:: KEY_USAGE
Paul Kehrercecbbba2015-03-30 14:58:38 -05002603
Paul Kehrere27f6582015-08-10 18:33:38 -05002604 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
2605 :class:`~cryptography.x509.KeyUsage` extension type.
Paul Kehrercecbbba2015-03-30 14:58:38 -05002606
Paul Kehrere27f6582015-08-10 18:33:38 -05002607 .. attribute:: SUBJECT_ALTERNATIVE_NAME
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002608
Paul Kehrere27f6582015-08-10 18:33:38 -05002609 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
2610 :class:`~cryptography.x509.SubjectAlternativeName` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002611
Paul Kehrere27f6582015-08-10 18:33:38 -05002612 .. attribute:: ISSUER_ALTERNATIVE_NAME
Paul Kehrer99125c92015-06-07 18:37:10 -05002613
Paul Kehrere27f6582015-08-10 18:33:38 -05002614 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
2615 :class:`~cryptography.x509.IssuerAlternativeName` extension type.
Paul Kehrer99125c92015-06-07 18:37:10 -05002616
Paul Kehrere27f6582015-08-10 18:33:38 -05002617 .. attribute:: SUBJECT_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002618
Paul Kehrere27f6582015-08-10 18:33:38 -05002619 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
2620 :class:`~cryptography.x509.SubjectKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002621
Paul Kehrere27f6582015-08-10 18:33:38 -05002622 .. attribute:: NAME_CONSTRAINTS
Paul Kehrere0017be2015-05-17 20:39:40 -06002623
Paul Kehrere27f6582015-08-10 18:33:38 -05002624 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
2625 :class:`~cryptography.x509.NameConstraints` extension type.
Paul Kehrere0017be2015-05-17 20:39:40 -06002626
Paul Kehrere27f6582015-08-10 18:33:38 -05002627 .. attribute:: CRL_DISTRIBUTION_POINTS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002628
Paul Kehrere27f6582015-08-10 18:33:38 -05002629 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
2630 :class:`~cryptography.x509.CRLDistributionPoints` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002631
Paul Kehrere27f6582015-08-10 18:33:38 -05002632 .. attribute:: CERTIFICATE_POLICIES
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002633
Paul Kehrere27f6582015-08-10 18:33:38 -05002634 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
2635 :class:`~cryptography.x509.CertificatePolicies` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002636
Paul Kehrere27f6582015-08-10 18:33:38 -05002637 .. attribute:: AUTHORITY_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002638
Paul Kehrere27f6582015-08-10 18:33:38 -05002639 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
2640 :class:`~cryptography.x509.AuthorityKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002641
Paul Kehrere27f6582015-08-10 18:33:38 -05002642 .. attribute:: EXTENDED_KEY_USAGE
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002643
Paul Kehrere27f6582015-08-10 18:33:38 -05002644 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
2645 :class:`~cryptography.x509.ExtendedKeyUsage` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002646
Paul Kehrere27f6582015-08-10 18:33:38 -05002647 .. attribute:: AUTHORITY_INFORMATION_ACCESS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05002648
Paul Kehrere27f6582015-08-10 18:33:38 -05002649 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
2650 for the :class:`~cryptography.x509.AuthorityInformationAccess` extension
2651 type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06002652
Paul Kehrere27f6582015-08-10 18:33:38 -05002653 .. attribute:: INHIBIT_ANY_POLICY
Paul Kehrerb33de932015-08-06 23:41:05 +01002654
Paul Kehrere27f6582015-08-10 18:33:38 -05002655 Corresponds to the dotted string ``"2.5.29.54"``. The identifier
2656 for the :class:`~cryptography.x509.InhibitAnyPolicy` extension type.
Paul Kehrerb33de932015-08-06 23:41:05 +01002657
Paul Kehrere27f6582015-08-10 18:33:38 -05002658 .. attribute:: OCSP_NO_CHECK
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002659
Paul Kehrere27f6582015-08-10 18:33:38 -05002660 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The
2661 identifier for the :class:`~cryptography.x509.OCSPNoCheck` extension
2662 type.
Paul Kehrer4a1038e2015-05-18 10:28:31 -07002663
Paul Kehrer51f39cb2015-12-21 21:17:39 -06002664 .. attribute:: CRL_NUMBER
2665
2666 Corresponds to the dotted string ``"2.5.29.20"``. The identifier for
2667 the ``CRLNumber`` extension type. This extension only has meaning
2668 for certificate revocation lists.
2669
Alex Gaynor9bab0ed2017-03-20 09:50:52 -04002670 .. attribute:: PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS
2671
2672 .. versionadded:: 1.9
2673
2674 Corresponds to the dotted string ``"1.3.6.1.4.1.11129.2.4.2"``.
2675
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002676 .. attribute:: POLICY_CONSTRAINTS
2677
2678 Corresponds to the dotted string ``"2.5.29.36"``. The identifier for the
Paul Kehrer20f0df52016-02-26 08:37:13 -06002679 :class:`~cryptography.x509.PolicyConstraints` extension type.
Paul Kehrer7e8fe9d2015-05-18 09:53:47 -07002680
2681
Paul Kehrerc6242dc2015-12-25 16:36:46 -06002682.. class:: CRLEntryExtensionOID
2683
2684 .. versionadded:: 1.2
2685
2686 .. attribute:: CERTIFICATE_ISSUER
2687
2688 Corresponds to the dotted string ``"2.5.29.29"``.
2689
2690 .. attribute:: CRL_REASON
2691
2692 Corresponds to the dotted string ``"2.5.29.21"``.
2693
2694 .. attribute:: INVALIDITY_DATE
2695
2696 Corresponds to the dotted string ``"2.5.29.24"``.
2697
Paul Kehrer8b89bcc2016-09-03 11:31:43 -05002698Helper Functions
2699~~~~~~~~~~~~~~~~
2700.. currentmodule:: cryptography.x509
2701
2702.. function:: random_serial_number()
2703
2704 .. versionadded:: 1.6
2705
2706 Generates a random serial number suitable for use when constructing
2707 certificates.
2708
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002709Exceptions
2710~~~~~~~~~~
Paul Kehrere27f6582015-08-10 18:33:38 -05002711.. currentmodule:: cryptography.x509
Paul Kehrer912d3fb2015-01-29 11:19:22 -06002712
Paul Kehrere76cd272014-12-14 19:00:51 -06002713.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10002714
2715 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10002716
Paul Kehrerd5cccf72014-12-15 17:20:33 -06002717 .. attribute:: parsed_version
2718
Paul Kehrerbbffc402014-12-17 13:33:55 -06002719 :type: int
2720
2721 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06002722
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05002723.. class:: DuplicateExtension
2724
2725 This is raised when more than one X.509 extension of the same type is
2726 found within a certificate.
2727
2728 .. attribute:: oid
2729
2730 :type: :class:`ObjectIdentifier`
2731
2732 Returns the OID.
2733
Paul Kehrerfa56a232015-03-17 13:14:03 -05002734.. class:: ExtensionNotFound
2735
2736 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
2737 an extension OID that is not present in the certificate.
2738
2739 .. attribute:: oid
2740
2741 :type: :class:`ObjectIdentifier`
2742
2743 Returns the OID.
2744
Paul Kehrer9089c912015-04-20 22:15:20 -05002745.. class:: UnsupportedGeneralNameType
2746
2747 This is raised when a certificate contains an unsupported general name
2748 type in an extension.
2749
Paul Kehrerbed07352015-04-21 08:31:10 -05002750 .. attribute:: type
2751
Paul Kehrer0a621bf2015-04-22 09:22:56 -05002752 :type: int
2753
2754 The integer value of the unsupported type. The complete list of
2755 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05002756
Paul Kehrer016e08a2014-11-26 09:41:18 -10002757
Paul Kehrerc7c9a432015-04-19 09:20:13 -05002758.. _`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 -05002759.. _`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 -05002760.. _`CABForum Guidelines`: https://cabforum.org/baseline-requirements-documents/