blob: 87383db1e884b4d4eb6285abfd91fb22338c3d2d [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
8 pem_req_data = b"""
9 -----BEGIN CERTIFICATE REQUEST-----
10 MIIC0zCCAbsCAQAwWTELMAkGA1UEBhMCVVMxETAPBgNVBAgMCElsbGlub2lzMRAw
11 DgYDVQQHDAdDaGljYWdvMREwDwYDVQQKDAhyNTA5IExMQzESMBAGA1UEAwwJaGVs
12 bG8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqhZx+Mo9VRd9
13 vsnWWa6NBCws21rZ0+1B/JGgB4hDsZS7iDE4Bj5z4idheFRtl8bBbdjPknq7BfoF
14 8v15Zq/Zv7i2xMSDL+LUrTBZezRd4bRTGqCm6YJ5EYkhqdcqeZleHCFImguHoq1J
15 Fh0+kObQrTHXw3ZP57a3o1IvyIUA3nNoCBL0QQhwBXaDXOojMKNR+bqB5ve8GS1y
16 Elr0AM/+cJsfaIahNQUgFKx3Eu3GeEOMKYOAG1lycgdQdmTUybLrT3U7vkClTseM
17 xHg1r5En7ALjONIhqRuq3rddYahrP8HXozb3zUy3cJ7P6IeaosuvNzvMXOX9P6HD
18 Ha9urDAJ1wIDAQABoDUwMwYJKoZIhvcNAQkOMSYwJDAiBgNVHREEGzAZggl3b3Js
19 ZC5jb22CDHdoYXRldmVyLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEAS4Ro6h+z52SK
20 YSLCYARpnEu/rmh4jdqndt8naqcNb6uLx9mlKZ2W9on9XDjnSdQD9q+ZP5aZfESw
21 R0+rJhW9ZrNa/g1pt6M24ihclHYDAxYMWxT1z/TXXGM3TmZZ6gfYlNE1kkBuODHa
22 UYsR/1Ht1E1EsmmUimt2n+zQR2K8T9Coa+boaUW/GsTEuz1aaJAkj5ZvTDiIhRG4
23 AOCqFZOLAQmCCNgJnnspD9hDz/Ons085LF5wnYjN4/Nsk5tS6AGs3xjZ3jPoOGGn
24 82WQ9m4dBGoVDZXsobVTaN592JEYwN5iu72zRn7Einb4V4H5y3yD2dD4yWPlt4pk
25 5wFkeYsZEA==
26 -----END CERTIFICATE REQUEST-----
27 """.strip()
28
Paul Kehrerd3dafbd2015-03-15 16:24:18 -050029 pem_data = b"""
30 -----BEGIN CERTIFICATE-----
31 MIIDfDCCAmSgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJVUzEf
32 MB0GA1UEChMWVGVzdCBDZXJ0aWZpY2F0ZXMgMjAxMTEVMBMGA1UEAxMMVHJ1c3Qg
33 QW5jaG9yMB4XDTEwMDEwMTA4MzAwMFoXDTMwMTIzMTA4MzAwMFowQDELMAkGA1UE
34 BhMCVVMxHzAdBgNVBAoTFlRlc3QgQ2VydGlmaWNhdGVzIDIwMTExEDAOBgNVBAMT
35 B0dvb2QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCQWJpHYo37
36 Xfb7oJSPe+WvfTlzIG21WQ7MyMbGtK/m8mejCzR6c+f/pJhEH/OcDSMsXq8h5kXa
37 BGqWK+vSwD/Pzp5OYGptXmGPcthDtAwlrafkGOS4GqIJ8+k9XGKs+vQUXJKsOk47
38 RuzD6PZupq4s16xaLVqYbUC26UcY08GpnoLNHJZS/EmXw1ZZ3d4YZjNlpIpWFNHn
39 UGmdiGKXUPX/9H0fVjIAaQwjnGAbpgyCumWgzIwPpX+ElFOUr3z7BoVnFKhIXze+
40 VmQGSWxZxvWDUN90Ul0tLEpLgk3OVxUB4VUGuf15OJOpgo1xibINPmWt14Vda2N9
41 yrNKloJGZNqLAgMBAAGjfDB6MB8GA1UdIwQYMBaAFOR9X9FclYYILAWuvnW2ZafZ
42 XahmMB0GA1UdDgQWBBRYAYQkG7wrUpRKPaUQchRR9a86yTAOBgNVHQ8BAf8EBAMC
43 AQYwFwYDVR0gBBAwDjAMBgpghkgBZQMCATABMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
44 KoZIhvcNAQELBQADggEBADWHlxbmdTXNwBL/llwhQqwnazK7CC2WsXBBqgNPWj7m
45 tvQ+aLG8/50Qc2Sun7o2VnwF9D18UUe8Gj3uPUYH+oSI1vDdyKcjmMbKRU4rk0eo
46 3UHNDXwqIVc9CQS9smyV+x1HCwL4TTrq+LXLKx/qVij0Yqk+UJfAtrg2jnYKXsCu
47 FMBQQnWCGrwa1g1TphRp/RmYHnMynYFmZrXtzFz+U9XEA7C+gPq4kqDI/iVfIT1s
48 6lBtdB50lrDVwl2oYfAvW/6sC2se2QleZidUmrziVNP4oEeXINokU6T6p//HM1FG
49 QYw2jOvpKcKtWCSAnegEbgsGYzATKjmPJPJ0npHFqzM=
50 -----END CERTIFICATE-----
51 """.strip()
52
Paul Kehrer93ae8052015-05-02 23:18:09 -050053 cryptography_cert_pem = b"""
54 -----BEGIN CERTIFICATE-----
55 MIIFvTCCBKWgAwIBAgICPyAwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMx
56 FjAUBgNVBAoTDUdlb1RydXN0IEluYy4xIDAeBgNVBAMTF1JhcGlkU1NMIFNIQTI1
57 NiBDQSAtIEczMB4XDTE0MTAxNTEyMDkzMloXDTE4MTExNjAxMTUwM1owgZcxEzAR
58 BgNVBAsTCkdUNDg3NDI5NjUxMTAvBgNVBAsTKFNlZSB3d3cucmFwaWRzc2wuY29t
59 L3Jlc291cmNlcy9jcHMgKGMpMTQxLzAtBgNVBAsTJkRvbWFpbiBDb250cm9sIFZh
60 bGlkYXRlZCAtIFJhcGlkU1NMKFIpMRwwGgYDVQQDExN3d3cuY3J5cHRvZ3JhcGh5
61 LmlvMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAom/FebKJIot7Sp3s
62 itG1sicpe3thCssjI+g1JDAS7I3GLVNmbms1DOdIIqwf01gZkzzXBN2+9sOnyRaR
63 PPfCe1jTr3dk2y6rPE559vPa1nZQkhlzlhMhlPyjaT+S7g4Tio4qV2sCBZU01DZJ
64 CaksfohN+5BNVWoJzTbOcrHOEJ+M8B484KlBCiSxqf9cyNQKru4W3bHaCVNVJ8eu
65 6i6KyhzLa0L7yK3LXwwXVs583C0/vwFhccGWsFODqD/9xHUzsBIshE8HKjdjDi7Y
66 3BFQzVUQFjBB50NSZfAA/jcdt1blxJouc7z9T8Oklh+V5DDBowgAsrT4b6Z2Fq6/
67 r7D1GqivLK/ypUQmxq2WXWAUBb/Q6xHgxASxI4Br+CByIUQJsm8L2jzc7k+mF4hW
68 ltAIUkbo8fGiVnat0505YJgxWEDKOLc4Gda6d/7GVd5AvKrz242bUqeaWo6e4MTx
69 diku2Ma3rhdcr044Qvfh9hGyjqNjvhWY/I+VRWgihU7JrYvgwFdJqsQ5eiKT4OHi
70 gsejvWwkZzDtiQ+aQTrzM1FsY2swJBJsLSX4ofohlVRlIJCn/ME+XErj553431Lu
71 YQ5SzMd3nXzN78Vj6qzTfMUUY72UoT1/AcFiUMobgIqrrmwuNxfrkbVE2b6Bga74
72 FsJX63prvrJ41kuHK/16RQBM7fcCAwEAAaOCAWAwggFcMB8GA1UdIwQYMBaAFMOc
73 8/zTRgg0u85Gf6B8W/PiCMtZMFcGCCsGAQUFBwEBBEswSTAfBggrBgEFBQcwAYYT
74 aHR0cDovL2d2LnN5bWNkLmNvbTAmBggrBgEFBQcwAoYaaHR0cDovL2d2LnN5bWNi
75 LmNvbS9ndi5jcnQwDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMB
76 BggrBgEFBQcDAjAvBgNVHREEKDAmghN3d3cuY3J5cHRvZ3JhcGh5Lmlvgg9jcnlw
77 dG9ncmFwaHkuaW8wKwYDVR0fBCQwIjAgoB6gHIYaaHR0cDovL2d2LnN5bWNiLmNv
78 bS9ndi5jcmwwDAYDVR0TAQH/BAIwADBFBgNVHSAEPjA8MDoGCmCGSAGG+EUBBzYw
79 LDAqBggrBgEFBQcCARYeaHR0cHM6Ly93d3cucmFwaWRzc2wuY29tL2xlZ2FsMA0G
80 CSqGSIb3DQEBCwUAA4IBAQAzIYO2jx7h17FBT74tJ2zbV9OKqGb7QF8y3wUtP4xc
81 dH80vprI/Cfji8s86kr77aAvAqjDjaVjHn7UzebhSUivvRPmfzRgyWBacomnXTSt
82 Xlt2dp2nDQuwGyK2vB7dMfKnQAkxwq1sYUXznB8i0IhhCAoXp01QGPKq51YoIlnF
83 7DRMk6iEaL1SJbkIrLsCQyZFDf0xtfW9DqXugMMLoxeCsBhZJQzNyS2ryirrv9LH
84 aK3+6IZjrcyy9bkpz/gzJucyhU+75c4My/mnRCrtItRbCQuiI5pd5poDowm+HH9i
85 GVI9+0lAFwxOUnOnwsoI40iOoxjLMGB+CgFLKCGUcWxP
86 -----END CERTIFICATE-----
87 """.strip()
88
Paul Kehrerb2de9482014-12-11 14:54:48 -060089Loading Certificates
90~~~~~~~~~~~~~~~~~~~~
Paul Kehrer016e08a2014-11-26 09:41:18 -100091
92.. function:: load_pem_x509_certificate(data, backend)
93
94 .. versionadded:: 0.7
95
Paul Kehrere76cd272014-12-14 19:00:51 -060096 Deserialize a certificate from PEM encoded data. PEM certificates are
97 base64 decoded and have delimiters that look like
98 ``-----BEGIN CERTIFICATE-----``.
Paul Kehrer016e08a2014-11-26 09:41:18 -100099
100 :param bytes data: The PEM encoded certificate data.
101
102 :param backend: A backend supporting the
103 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
104 interface.
105
Paul Kehrere76cd272014-12-14 19:00:51 -0600106 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000107
108.. function:: load_der_x509_certificate(data, backend)
109
110 .. versionadded:: 0.7
111
Paul Kehrere76cd272014-12-14 19:00:51 -0600112 Deserialize a certificate from DER encoded data. DER is a binary format
Paul Kehrer92aac382014-12-15 16:25:28 -0600113 and is commonly found in files with the ``.cer`` extension (although file
114 extensions are not a guarantee of encoding type).
Paul Kehrer016e08a2014-11-26 09:41:18 -1000115
116 :param bytes data: The DER encoded certificate data.
117
118 :param backend: A backend supporting the
119 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
120 interface.
121
Paul Kehrere76cd272014-12-14 19:00:51 -0600122 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000123
Paul Kehrer016e08a2014-11-26 09:41:18 -1000124.. doctest::
125
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600126 >>> from cryptography import x509
Paul Kehrer016e08a2014-11-26 09:41:18 -1000127 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600128 >>> cert = x509.load_pem_x509_certificate(pem_data, default_backend())
Paul Kehrer016e08a2014-11-26 09:41:18 -1000129 >>> cert.serial
130 2
131
Paul Kehrera1a1f232015-03-15 15:34:35 -0500132Loading Certificate Signing Requests
133~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600134
Paul Kehrer31e39882015-03-11 11:37:04 -0500135.. function:: load_pem_x509_csr(data, backend)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600136
137 .. versionadded:: 0.9
138
Paul Kehrera1a1f232015-03-15 15:34:35 -0500139 Deserialize a certificate signing request (CSR) from PEM encoded data. PEM
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500140 requests are base64 decoded and have delimiters that look like
Paul Kehrerd3dafbd2015-03-15 16:24:18 -0500141 ``-----BEGIN CERTIFICATE REQUEST-----``. This format is also known as
142 PKCS#10.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600143
144 :param bytes data: The PEM encoded request data.
145
146 :param backend: A backend supporting the
147 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
148 interface.
149
Paul Kehrera1a1f232015-03-15 15:34:35 -0500150 :returns: An instance of
151 :class:`~cryptography.x509.CertificateSigningRequest`.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600152
Paul Kehrer1effb6e2015-03-30 15:05:59 -0500153.. function:: load_der_x509_csr(data, backend)
154
155 .. versionadded:: 0.9
156
157 Deserialize a certificate signing request (CSR) from DER encoded data. DER
158 is a binary format and is not commonly used with CSRs.
159
160 :param bytes data: The DER encoded request data.
161
162 :param backend: A backend supporting the
163 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
164 interface.
165
166 :returns: An instance of
167 :class:`~cryptography.x509.CertificateSigningRequest`.
168
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600169.. doctest::
170
171 >>> from cryptography import x509
172 >>> from cryptography.hazmat.backends import default_backend
173 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500174 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
175 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600176 True
177
Paul Kehrere76cd272014-12-14 19:00:51 -0600178X.509 Certificate Object
179~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerb2de9482014-12-11 14:54:48 -0600180
Paul Kehrere76cd272014-12-14 19:00:51 -0600181.. class:: Certificate
Paul Kehrerb2de9482014-12-11 14:54:48 -0600182
183 .. versionadded:: 0.7
184
185 .. attribute:: version
186
Paul Kehrere76cd272014-12-14 19:00:51 -0600187 :type: :class:`~cryptography.x509.Version`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600188
Paul Kehrere76cd272014-12-14 19:00:51 -0600189 The certificate version as an enumeration. Version 3 certificates are
190 the latest version and also the only type you should see in practice.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600191
Alex Gaynor89c4dc82014-12-16 16:49:33 -0800192 :raises cryptography.x509.InvalidVersion: If the version in the
Alex Gaynor6d7ab4c2014-12-16 16:50:33 -0800193 certificate is not a known
194 :class:`X.509 version <cryptography.x509.Version>`.
Paul Kehrer92aac382014-12-15 16:25:28 -0600195
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600196 .. doctest::
197
198 >>> cert.version
199 <Version.v3: 2>
200
Paul Kehrerb2de9482014-12-11 14:54:48 -0600201 .. method:: fingerprint(algorithm)
202
203 :param algorithm: The
Paul Kehrer601278a2015-02-12 12:51:00 -0600204 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600205 that will be used to generate the fingerprint.
206
Erik Trauschke2dcce902015-05-14 16:12:24 -0700207 :return bytes: The fingerprint using the supplied hash algorithm, as
Paul Kehrerb2de9482014-12-11 14:54:48 -0600208 bytes.
209
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600210 .. doctest::
211
212 >>> from cryptography.hazmat.primitives import hashes
213 >>> cert.fingerprint(hashes.SHA256())
Paul Kehrer78a81502014-12-16 14:47:52 -0600214 '\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 -0600215
Paul Kehrerb2de9482014-12-11 14:54:48 -0600216 .. attribute:: serial
217
218 :type: int
219
220 The serial as a Python integer.
221
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600222 .. doctest::
223
224 >>> cert.serial
225 2
226
Paul Kehrerb2de9482014-12-11 14:54:48 -0600227 .. method:: public_key()
228
229 :type:
Alex Stapletonf79c2312014-12-30 12:50:14 +0000230 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
Paul Kehrer45efdbc2015-02-12 10:58:22 -0600231 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
232 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600233
234 The public key associated with the certificate.
235
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600236 .. doctest::
237
Alex Stapletonf79c2312014-12-30 12:50:14 +0000238 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600239 >>> public_key = cert.public_key()
Alex Stapletonf79c2312014-12-30 12:50:14 +0000240 >>> isinstance(public_key, rsa.RSAPublicKey)
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600241 True
242
Paul Kehrerb2de9482014-12-11 14:54:48 -0600243 .. attribute:: not_valid_before
244
245 :type: :class:`datetime.datetime`
246
Paul Kehrer78a81502014-12-16 14:47:52 -0600247 A naïve datetime representing the beginning of the validity period for
248 the certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600249
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600250 .. doctest::
251
252 >>> cert.not_valid_before
253 datetime.datetime(2010, 1, 1, 8, 30)
254
Paul Kehrerb2de9482014-12-11 14:54:48 -0600255 .. attribute:: not_valid_after
256
257 :type: :class:`datetime.datetime`
258
Paul Kehrer78a81502014-12-16 14:47:52 -0600259 A naïve datetime representing the end of the validity period for the
260 certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600261
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600262 .. doctest::
263
264 >>> cert.not_valid_after
265 datetime.datetime(2030, 12, 31, 8, 30)
266
Paul Kehrer719d5362015-01-01 20:03:52 -0600267 .. attribute:: issuer
268
269 .. versionadded:: 0.8
270
271 :type: :class:`Name`
272
273 The :class:`Name` of the issuer.
274
275 .. attribute:: subject
276
277 .. versionadded:: 0.8
278
279 :type: :class:`Name`
280
281 The :class:`Name` of the subject.
282
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600283 .. attribute:: signature_hash_algorithm
Paul Kehrer56da2a52015-02-11 23:35:07 -0600284
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600285 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrer56da2a52015-02-11 23:35:07 -0600286
Paul Kehrere612ec72015-02-16 14:33:35 -0600287 Returns the
Paul Kehrer71d40c62015-02-19 08:21:04 -0600288 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600289 was used in signing this certificate.
Paul Kehrer56da2a52015-02-11 23:35:07 -0600290
291 .. doctest::
292
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600293 >>> from cryptography.hazmat.primitives import hashes
294 >>> isinstance(cert.signature_hash_algorithm, hashes.SHA256)
295 True
Paul Kehrer719d5362015-01-01 20:03:52 -0600296
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500297 .. attribute:: extensions
298
299 :type: :class:`Extensions`
300
301 The extensions encoded in the certificate.
302
303 :raises cryptography.x509.DuplicateExtension: If more than one
304 extension of the same type is found within the certificate.
305
Paul Kehrerd8fc0be2015-04-21 08:31:10 -0500306 :raises cryptography.x509.UnsupportedExtension: If the certificate
307 contains an extension that is not supported.
308
Paul Kehrerbed07352015-04-21 08:31:10 -0500309 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
310 contains a general name that is not supported.
311
Paul Kehrerb8968812015-05-15 09:01:34 -0700312 :raises UnicodeError: If an extension contains IDNA encoding that is
313 invalid or not compliant with IDNA 2008.
314
Paul Kehrerfa56a232015-03-17 13:14:03 -0500315 .. doctest::
316
317 >>> for ext in cert.extensions:
318 ... print(ext)
Paul Kehrerd774de92015-05-03 10:52:25 -0500319 <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 -0400320 <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 -0400321 <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 -0500322 <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 -0500323 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
324
Andre Carona8aded62015-05-19 20:11:57 -0400325 .. method:: public_bytes(encoding)
326
Alex Gaynord0b376b2015-07-05 13:58:12 -0400327 .. versionadded:: 1.0
328
Andre Carona8aded62015-05-19 20:11:57 -0400329 :param encoding: The
330 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
331 that will be used to serialize the certificate.
332
333 :return bytes: The data that can be written to a file or sent
334 over the network to be verified by clients.
335
Erik Trauschke2dcce902015-05-14 16:12:24 -0700336X.509 CRL (Certificate Revocation List) Object
337~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
338
339.. class:: CertificateRevocationList
340
341 .. versionadded:: 1.0
342
343 .. method:: fingerprint(algorithm)
344
345 :param algorithm: The
346 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
347 that will be used to generate the fingerprint.
348
349 :return bytes: The fingerprint using the supplied hash algorithm, as
350 bytes.
351
352 .. attribute:: signature_hash_algorithm
353
354 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
355
356 Returns the
357 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
358 was used in signing this CRL.
359
360 .. attribute:: issuer
361
362 :type: :class:`Name`
363
364 The :class:`Name` of the issuer.
365
366 .. attribute:: next_update
367
368 :type: :class:`datetime.datetime`
369
370 A naïve datetime representing when the next update to this CRL is
371 expected.
372
373 .. attribute:: last_update
374
375 :type: :class:`datetime.datetime`
376
377 A naïve datetime representing when the this CRL was last updated.
378
Erik Trauschkeabb7b6e2015-05-27 15:07:35 -0700379 .. attribute:: revoked_certificates
Erik Trauschke2dcce902015-05-14 16:12:24 -0700380
381 :type: list of :class:`RevokedCertificate`
382
383 The revoked certificates listed in this CRL.
384
385 .. attribute:: extensions
386
387 :type: :class:`Extensions`
388
389 The extensions encoded in the CRL.
390
Andre Caron9bbfcea2015-05-18 20:55:29 -0400391X.509 Certificate Builder
392~~~~~~~~~~~~~~~~~~~~~~~~~
393
394.. class:: CertificateBuilder
395
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500396 .. versionadded:: 1.0
397
398 .. doctest::
399
400 >>> from cryptography import x509
401 >>> from cryptography.hazmat.backends import default_backend
402 >>> from cryptography.hazmat.primitives import hashes
403 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -0500404 >>> from cryptography.x509.oid import NameOID
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500405 >>> import datetime
406 >>> import uuid
407 >>> one_day = datetime.timedelta(1, 0, 0)
408 >>> private_key = rsa.generate_private_key(
409 ... public_exponent=65537,
410 ... key_size=2048,
411 ... backend=default_backend()
412 ... )
413 >>> public_key = rsa.generate_private_key(
414 ... public_exponent=65537,
415 ... key_size=2048,
416 ... backend=default_backend()
417 ... ).public_key()
418 >>> builder = x509.CertificateBuilder()
419 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500420 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500421 ... ]))
422 >>> builder = builder.issuer_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500423 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Ian Cordasco1517a4b2015-08-02 22:11:19 -0500424 ... ]))
425 >>> builder = builder.not_valid_before(datetime.datetime.today() - one_day)
426 >>> builder = builder.not_valid_after(datetime.datetime(2018, 8, 2))
427 >>> builder = builder.serial_number(int(uuid.uuid4()))
428 >>> builder = builder.public_key(public_key)
429 >>> builder = builder.add_extension(
430 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
431 ... )
432 >>> certificate = builder.sign(
433 ... private_key=private_key, algorithm=hashes.SHA256(),
434 ... backend=default_backend()
435 ... )
436 >>> isinstance(certificate, x509.Certificate)
437 True
438
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500439 .. method:: issuer_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400440
441 Sets the issuer's distinguished name.
442
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500443 :param name: The :class:`~cryptography.x509.Name` that describes the
444 issuer (CA).
Andre Caron9bbfcea2015-05-18 20:55:29 -0400445
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500446 .. method:: subject_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400447
448 Sets the subject's distinguished name.
449
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500450 :param name: The :class:`~cryptography.x509.Name` that describes the
Ian Cordasco85fc4d52015-08-01 20:29:31 -0500451 subject.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400452
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500453 .. method:: public_key(public_key)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400454
455 Sets the subject's public key.
456
Ian Cordasco8f571422015-08-02 11:31:08 -0500457 :param public_key: The subject's public key. This can be one of
458 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`,
459 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
460 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Andre Caron9bbfcea2015-05-18 20:55:29 -0400461
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500462 .. method:: serial_number(serial_number)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400463
464 Sets the certificate's serial number (an integer). The CA's policy
465 determines how it attributes serial numbers to certificates. The only
466 requirement is that this number uniquely identify the certificate given
467 the issuer.
468
469 :param serial_number: Integer number that will be used by the CA to
470 identify this certificate (most notably during certificate
Ian Cordasco17c89002015-08-02 21:13:59 -0500471 revocation checking). Users are encouraged to use a method of
472 generating 20 bytes of entropy, e.g., UUID4. For more information
Ian Cordascob7530a42015-08-02 22:47:06 -0500473 on secure random number generation, see :doc:`/random-numbers`.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400474
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500475 .. method:: not_valid_before(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400476
477 Sets the certificate's activation time. This is the time from which
478 clients can start trusting the certificate. It may be different from
479 the time at which the certificate was created.
480
Ian Cordasco17c89002015-08-02 21:13:59 -0500481 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400482 activation time for the certificate. The certificate may not be
483 trusted clients if it is used before this time.
484
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500485 .. method:: not_valid_after(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400486
487 Sets the certificate's expiration time. This is the time from which
488 clients should no longer trust the certificate. The CA's policy will
489 determine how long the certificate should remain in use.
490
Ian Cordasco17c89002015-08-02 21:13:59 -0500491 :param time: The :class:`datetime.datetime` object (in UTC) that marks the
Andre Caron9bbfcea2015-05-18 20:55:29 -0400492 expiration time for the certificate. The certificate may not be
493 trusted clients if it is used after this time.
494
Ian Cordasco17c89002015-08-02 21:13:59 -0500495 .. method:: add_extension(extension, critical)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400496
497 Adds an X.509 extension to the certificate.
498
Paul Kehrer2c145cc2015-10-02 11:27:21 -0500499 :param extension: An extension conforming to the
500 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400501
Ian Cordasco17c89002015-08-02 21:13:59 -0500502 :param critical: Set to ``True`` if the extension must be understood and
503 handled by whoever reads the certificate.
504
Paul Kehrer9add80e2015-08-03 17:53:14 +0100505 .. method:: sign(private_key, algorithm, backend)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400506
507 Sign the certificate using the CA's private key.
508
Ian Cordascoc5e1c252015-07-31 23:33:35 -0500509 :param private_key: The
510 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
511 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
512 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
513 that will be used to sign the certificate.
514
Andre Caron9bbfcea2015-05-18 20:55:29 -0400515 :param algorithm: The
516 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
517 will be used to generate the signature.
518
Paul Kehrer9add80e2015-08-03 17:53:14 +0100519 :param backend: Backend that will be used to build the certificate.
520 Must support the
521 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
522 interface.
523
Andre Caron9bbfcea2015-05-18 20:55:29 -0400524
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500525X.509 CSR (Certificate Signing Request) Object
526~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600527
Paul Kehrera1a1f232015-03-15 15:34:35 -0500528.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600529
530 .. versionadded:: 0.9
531
532 .. method:: public_key()
533
534 :type:
535 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
536 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
537 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
538
539 The public key associated with the request.
540
541 .. doctest::
542
543 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500544 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600545 >>> isinstance(public_key, rsa.RSAPublicKey)
546 True
547
548 .. attribute:: subject
549
550 :type: :class:`Name`
551
552 The :class:`Name` of the subject.
553
554 .. attribute:: signature_hash_algorithm
555
556 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
557
558 Returns the
559 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
560 was used in signing this request.
561
562 .. doctest::
563
564 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500565 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600566 True
567
Paul Kehrerc4e61942015-08-01 21:21:13 +0100568 .. attribute:: extensions
569
570 :type: :class:`Extensions`
571
572 The extensions encoded in the certificate signing request.
573
574 :raises cryptography.x509.DuplicateExtension: If more than one
Paul Kehrer24283d22015-08-01 21:31:19 +0100575 extension of the same type is found within the certificate signing request.
Paul Kehrerc4e61942015-08-01 21:21:13 +0100576
Paul Kehrer24283d22015-08-01 21:31:19 +0100577 :raises cryptography.x509.UnsupportedExtension: If the certificate signing request
Paul Kehrerc4e61942015-08-01 21:21:13 +0100578 contains an extension that is not supported.
579
580 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
581 contains a general name that is not supported.
582
583 :raises UnicodeError: If an extension contains IDNA encoding that is
584 invalid or not compliant with IDNA 2008.
585
586
Andre Caron476c5df2015-05-18 10:23:28 -0400587 .. method:: public_bytes(encoding)
588
Alex Gaynord0b376b2015-07-05 13:58:12 -0400589 .. versionadded:: 1.0
590
Andre Caron476c5df2015-05-18 10:23:28 -0400591 :param encoding: The
592 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
593 that will be used to serialize the certificate request.
594
595 :return bytes: The data that can be written to a file or sent
596 over the network to be signed by the certificate
597 authority.
598
Erik Trauschke2dcce902015-05-14 16:12:24 -0700599X.509 Revoked Certificate Object
Erik Trauschkec5a8d172015-05-28 10:24:25 -0700600~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Erik Trauschke2dcce902015-05-14 16:12:24 -0700601
602.. class:: RevokedCertificate
603
604 .. versionadded:: 1.0
605
606 .. attribute:: serial_number
607
608 :type: :class:`int`
609
610 An integer representing the serial number of the revoked certificate.
611
612 .. attribute:: revocation_date
613
614 :type: :class:`datetime.datetime`
615
616 A naïve datetime representing the date this certificates was revoked.
617
618 .. attribute:: extensions
619
620 :type: :class:`Extensions`
621
622 The extensions encoded in the revoked certificate.
Andre Caron476c5df2015-05-18 10:23:28 -0400623
Andre Caron0ef595f2015-05-18 13:53:43 -0400624X.509 CSR (Certificate Signing Request) Builder Object
625~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
626
627.. class:: CertificateSigningRequestBuilder
628
Andre Carond259ee52015-06-02 23:47:11 -0400629 .. versionadded:: 1.0
630
631 .. doctest::
632
633 >>> from cryptography import x509
634 >>> from cryptography.hazmat.backends import default_backend
635 >>> from cryptography.hazmat.primitives import hashes
636 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -0500637 >>> from cryptography.x509.oid import NameOID
Andre Carond259ee52015-06-02 23:47:11 -0400638 >>> private_key = rsa.generate_private_key(
639 ... public_exponent=65537,
640 ... key_size=2048,
641 ... backend=default_backend()
642 ... )
643 >>> builder = x509.CertificateSigningRequestBuilder()
Andre Carona9a51172015-06-06 20:18:44 -0400644 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500645 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Andre Carond259ee52015-06-02 23:47:11 -0400646 ... ]))
Ian Cordascof06b6be2015-06-21 10:09:18 -0500647 >>> builder = builder.add_extension(
Ian Cordasco0112b022015-06-16 17:51:18 -0500648 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
Andre Caron472fd692015-06-06 20:04:44 -0400649 ... )
Andre Carond259ee52015-06-02 23:47:11 -0400650 >>> request = builder.sign(
Alex Gaynorde9e5842015-06-26 20:11:23 -0400651 ... private_key, hashes.SHA256(), default_backend()
Andre Carond259ee52015-06-02 23:47:11 -0400652 ... )
653 >>> isinstance(request, x509.CertificateSigningRequest)
654 True
655
Andre Carona9a51172015-06-06 20:18:44 -0400656 .. method:: subject_name(name)
Andre Caron0ef595f2015-05-18 13:53:43 -0400657
Andre Caron341ff852015-06-06 20:14:31 -0400658 :param name: The :class:`~cryptography.x509.Name` of the certificate
659 subject.
660 :returns: A new
661 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400662
Ian Cordascof06b6be2015-06-21 10:09:18 -0500663 .. method:: add_extension(extension, critical)
Andre Caron0ef595f2015-05-18 13:53:43 -0400664
Paul Kehrer2c145cc2015-10-02 11:27:21 -0500665 :param extension: An extension conforming to the
666 :class:`~cryptography.x509.ExtensionType` interface.
Andre Caron472fd692015-06-06 20:04:44 -0400667 :param critical: Set to `True` if the extension must be understood and
668 handled by whoever reads the certificate.
Andre Caron341ff852015-06-06 20:14:31 -0400669 :returns: A new
670 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400671
Alex Gaynorb3b0fbe2015-06-26 19:57:18 -0400672 .. method:: sign(private_key, algorithm, backend)
Andre Caron0ef595f2015-05-18 13:53:43 -0400673
674 :param backend: Backend that will be used to sign the request.
675 Must support the
676 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
677 interface.
678
679 :param private_key: The
Andre Caron24f9bf42015-06-06 20:14:54 -0400680 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
681 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
682 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
Andre Caron0ef595f2015-05-18 13:53:43 -0400683 that will be used to sign the request. When the request is
684 signed by a certificate authority, the private key's associated
685 public key will be stored in the resulting certificate.
686
687 :param algorithm: The
688 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
689 that will be used to generate the request signature.
690
Andre Caron341ff852015-06-06 20:14:31 -0400691 :returns: A new
692 :class:`~cryptography.x509.CertificateSigningRequest`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400693
694
Paul Kehrer719d5362015-01-01 20:03:52 -0600695.. class:: Name
696
697 .. versionadded:: 0.8
698
Paul Kehrer53d8d492015-02-13 18:47:30 -0600699 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -0600700 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -0600701 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -0600702 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
703 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -0600704
Paul Kehrer53d8d492015-02-13 18:47:30 -0600705 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -0600706
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600707 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -0600708 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600709 >>> for attribute in cert.subject:
710 ... print(attribute)
711 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
712 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')>
713 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -0600714
Paul Kehrere901d642015-02-11 18:50:58 -0600715 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -0600716
Paul Kehrere901d642015-02-11 18:50:58 -0600717 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -0600718
Paul Kehrere901d642015-02-11 18:50:58 -0600719 :returns: A list of :class:`NameAttribute` instances that match the
720 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -0600721
722 .. doctest::
723
Paul Kehrere27f6582015-08-10 18:33:38 -0500724 >>> cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)
Paul Kehrere901d642015-02-11 18:50:58 -0600725 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -0600726
Paul Kehrere76cd272014-12-14 19:00:51 -0600727.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -1000728
729 .. versionadded:: 0.7
730
731 An enumeration for X.509 versions.
732
733 .. attribute:: v1
734
735 For version 1 X.509 certificates.
736
737 .. attribute:: v3
738
739 For version 3 X.509 certificates.
740
Paul Kehrer806bfb22015-02-02 17:05:24 -0600741.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600742
743 .. versionadded:: 0.8
744
Paul Kehrer834d22f2015-02-06 11:01:07 -0600745 An X.509 name consists of a list of NameAttribute instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600746
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600747 .. attribute:: oid
748
749 :type: :class:`ObjectIdentifier`
750
751 The attribute OID.
752
753 .. attribute:: value
754
Paul Kehrerd5852cb2015-01-30 08:25:23 -0600755 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600756
757 The value of the attribute.
758
759.. class:: ObjectIdentifier
760
761 .. versionadded:: 0.8
762
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600763 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -0600764 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600765
Paul Kehrerd44f9a62015-02-04 14:47:34 -0600766 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600767
768 :type: :class:`str`
769
Paul Kehrerfedf4f42015-02-06 11:22:07 -0600770 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600771
Paul Kehrer31bdf792015-03-25 14:11:00 -0500772.. _general_name_classes:
773
774General Name Classes
775~~~~~~~~~~~~~~~~~~~~
776
777.. class:: GeneralName
778
779 .. versionadded:: 0.9
780
781 This is the generic interface that all the following classes are registered
782 against.
783
784.. class:: RFC822Name
785
786 .. versionadded:: 0.9
787
788 This corresponds to an email address. For example, ``user@example.com``.
789
790 .. attribute:: value
791
792 :type: :term:`text`
793
794.. class:: DNSName
795
796 .. versionadded:: 0.9
797
798 This corresponds to a domain name. For example, ``cryptography.io``.
799
800 .. attribute:: value
801
802 :type: :term:`text`
803
804.. class:: DirectoryName
805
806 .. versionadded:: 0.9
807
808 This corresponds to a directory name.
809
810 .. attribute:: value
811
812 :type: :class:`Name`
813
814.. class:: UniformResourceIdentifier
815
816 .. versionadded:: 0.9
817
818 This corresponds to a uniform resource identifier. For example,
Paul Kehrerb8ef82e2015-04-22 16:04:24 -0500819 ``https://cryptography.io``. The URI is parsed and IDNA decoded (see
820 :rfc:`5895`).
821
822 .. note::
823
824 URIs that do not contain ``://`` in them will not be decoded.
Paul Kehrer31bdf792015-03-25 14:11:00 -0500825
826 .. attribute:: value
827
828 :type: :term:`text`
829
830.. class:: IPAddress
831
832 .. versionadded:: 0.9
833
834 This corresponds to an IP address.
835
836 .. attribute:: value
837
Paul Kehrereb177932015-05-17 18:33:33 -0700838 :type: :class:`~ipaddress.IPv4Address`,
839 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
840 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -0500841
842.. class:: RegisteredID
843
844 .. versionadded:: 0.9
845
846 This corresponds to a registered ID.
847
848 .. attribute:: value
849
850 :type: :class:`ObjectIdentifier`
851
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +0000852.. class:: OtherName
853
854 .. versionadded:: 1.0
855
Joshua Tauberer18b6fc82015-07-05 21:44:51 +0000856 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 +0000857
858 .. attribute:: type_id
859
860 :type: :class:`ObjectIdentifier`
861
862 .. attribute:: value
863
864 :type: `bytes`
865
Paul Kehrer8cf26422015-03-21 09:50:24 -0500866X.509 Extensions
867~~~~~~~~~~~~~~~~
868
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500869.. class:: Extensions
870
871 .. versionadded:: 0.9
872
873 An X.509 Extensions instance is an ordered list of extensions. The object
874 is iterable to get every extension.
875
Paul Kehrerfa56a232015-03-17 13:14:03 -0500876 .. method:: get_extension_for_oid(oid)
877
878 :param oid: An :class:`ObjectIdentifier` instance.
879
880 :returns: An instance of the extension class.
881
882 :raises cryptography.x509.ExtensionNotFound: If the certificate does
883 not have the extension requested.
884
Paul Kehrerfa56a232015-03-17 13:14:03 -0500885 .. doctest::
886
Paul Kehrere27f6582015-08-10 18:33:38 -0500887 >>> from cryptography.x509.oid import ExtensionOID
888 >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS)
Paul Kehrerfa56a232015-03-17 13:14:03 -0500889 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
890
Phoebe Queen019b7f82015-08-12 03:52:03 +0100891 .. method:: get_extension_for_class(extclass)
892
Phoebe Queen6a603eb2015-08-12 14:14:49 +0100893 .. versionadded:: 1.1
894
Phoebe Queen019b7f82015-08-12 03:52:03 +0100895 :param extclass: An extension class.
896
897 :returns: An instance of the extension class.
898
899 :raises cryptography.x509.ExtensionNotFound: If the certificate does
900 not have the extension requested.
901
902 .. doctest::
903
904 >>> from cryptography import x509
905 >>> cert.extensions.get_extension_for_class(x509.BasicConstraints)
906 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
907
Paul Kehrer8cf26422015-03-21 09:50:24 -0500908.. class:: Extension
909
910 .. versionadded:: 0.9
911
Paul Kehrer85894662015-03-22 13:19:31 -0500912 .. attribute:: oid
913
914 :type: :class:`ObjectIdentifier`
915
Paul Kehrere27f6582015-08-10 18:33:38 -0500916 One of the :class:`~cryptography.x509.oid.ExtensionOID` OIDs.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500917
918 .. attribute:: critical
919
920 :type: bool
921
Paul Kehrer58b75692015-03-22 23:24:58 -0500922 Determines whether a given extension is critical or not. :rfc:`5280`
923 requires that "A certificate-using system MUST reject the certificate
924 if it encounters a critical extension it does not recognize or a
925 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -0500926
Paul Kehrer85894662015-03-22 13:19:31 -0500927 .. attribute:: value
928
929 Returns an instance of the extension type corresponding to the OID.
930
Paul Kehrer14f0bd02015-08-06 11:55:18 +0100931.. class:: ExtensionType
932
933 .. versionadded:: 1.0
934
935 This is the interface against which all the following extension types are
936 registered.
937
Paul Kehrercecbbba2015-03-30 14:58:38 -0500938.. class:: KeyUsage
939
940 .. versionadded:: 0.9
941
942 The key usage extension defines the purpose of the key contained in the
943 certificate. The usage restriction might be employed when a key that could
Paul Kehrerb33de932015-08-06 23:41:05 +0100944 be used for more than one operation is to be restricted.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500945
Paul Kehrer822f3d32015-08-06 11:47:32 +0100946 .. attribute:: oid
947
948 .. versionadded:: 1.0
949
950 :type: :class:`ObjectIdentifier`
951
Paul Kehrere27f6582015-08-10 18:33:38 -0500952 Returns :attr:`~cryptography.x509.oid.ExtensionOID.KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +0100953
Paul Kehrercecbbba2015-03-30 14:58:38 -0500954 .. attribute:: digital_signature
955
956 :type: bool
957
Paul Kehrer738407b2015-04-01 22:39:02 -0500958 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500959 digital signatures, other than signatures on certificates
960 (``key_cert_sign``) and CRLs (``crl_sign``).
961
962 .. attribute:: content_commitment
963
964 :type: bool
965
Paul Kehrer738407b2015-04-01 22:39:02 -0500966 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500967 digital signatures, other than signatures on certificates
968 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
969 non-repudiation service that protects against the signing entity
970 falsely denying some action. In the case of later conflict, a
971 reliable third party may determine the authenticity of the signed
972 data. This was called ``non_repudiation`` in older revisions of the
973 X.509 specification.
974
975 .. attribute:: key_encipherment
976
977 :type: bool
978
Paul Kehrer738407b2015-04-01 22:39:02 -0500979 This purpose is set to true when the subject public key is used for
980 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500981
982 .. attribute:: data_encipherment
983
984 :type: bool
985
Paul Kehrer738407b2015-04-01 22:39:02 -0500986 This purpose is set to true when the subject public key is used for
987 directly enciphering raw user data without the use of an intermediate
988 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500989
990 .. attribute:: key_agreement
991
992 :type: bool
993
Paul Kehrer738407b2015-04-01 22:39:02 -0500994 This purpose is set to true when the subject public key is used for key
995 agreement. For example, when a Diffie-Hellman key is to be used for
996 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500997
998 .. attribute:: key_cert_sign
999
1000 :type: bool
1001
Paul Kehrer738407b2015-04-01 22:39:02 -05001002 This purpose is set to true when the subject public key is used for
1003 verifying signatures on public key certificates. If this purpose is set
1004 to true then ``ca`` must be true in the :class:`BasicConstraints`
1005 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001006
1007 .. attribute:: crl_sign
1008
1009 :type: bool
1010
Paul Kehrer738407b2015-04-01 22:39:02 -05001011 This purpose is set to true when the subject public key is used for
1012 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001013
1014 .. attribute:: encipher_only
1015
1016 :type: bool
1017
Paul Kehrer738407b2015-04-01 22:39:02 -05001018 When this purposes is set to true and the ``key_agreement`` purpose is
1019 also set, the subject public key may be used only for enciphering data
1020 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001021
1022 :raises ValueError: This is raised if accessed when ``key_agreement``
1023 is false.
1024
1025 .. attribute:: decipher_only
1026
1027 :type: bool
1028
Paul Kehrer738407b2015-04-01 22:39:02 -05001029 When this purposes is set to true and the ``key_agreement`` purpose is
1030 also set, the subject public key may be used only for deciphering data
1031 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001032
1033 :raises ValueError: This is raised if accessed when ``key_agreement``
1034 is false.
1035
1036
Paul Kehrer8cf26422015-03-21 09:50:24 -05001037.. class:: BasicConstraints
1038
1039 .. versionadded:: 0.9
1040
Paul Kehrer85894662015-03-22 13:19:31 -05001041 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -05001042 certificate is allowed to sign additional certificates and what path
Paul Kehrerb33de932015-08-06 23:41:05 +01001043 length restrictions may exist.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001044
Paul Kehrer822f3d32015-08-06 11:47:32 +01001045 .. attribute:: oid
1046
1047 .. versionadded:: 1.0
1048
1049 :type: :class:`ObjectIdentifier`
1050
Paul Kehrere27f6582015-08-10 18:33:38 -05001051 Returns :attr:`~cryptography.x509.oid.ExtensionOID.BASIC_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001052
Paul Kehrer8cf26422015-03-21 09:50:24 -05001053 .. attribute:: ca
1054
1055 :type: bool
1056
1057 Whether the certificate can sign certificates.
1058
1059 .. attribute:: path_length
1060
Paul Kehrerfd1444c2015-03-21 19:47:05 -05001061 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -05001062
1063 The maximum path length for certificates subordinate to this
1064 certificate. This attribute only has meaning if ``ca`` is true.
1065 If ``ca`` is true then a path length of None means there's no
1066 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -04001067 If it is zero or greater then it defines the maximum length for a
1068 subordinate CA's certificate chain. For example, a ``path_length`` of 1
1069 means the certificate can sign a subordinate CA, but the subordinate CA
1070 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001071
Paul Kehrerffa2a152015-03-31 08:18:25 -05001072.. class:: ExtendedKeyUsage
1073
1074 .. versionadded:: 0.9
1075
1076 This extension indicates one or more purposes for which the certified
1077 public key may be used, in addition to or in place of the basic
1078 purposes indicated in the key usage extension. The object is
Paul Kehrere27f6582015-08-10 18:33:38 -05001079 iterable to obtain the list of
1080 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs present.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001081
Paul Kehrer822f3d32015-08-06 11:47:32 +01001082 .. attribute:: oid
1083
1084 .. versionadded:: 1.0
1085
1086 :type: :class:`ObjectIdentifier`
1087
Paul Kehrere27f6582015-08-10 18:33:38 -05001088 Returns :attr:`~cryptography.x509.oid.ExtensionOID.EXTENDED_KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001089
1090
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001091.. class:: OCSPNoCheck
1092
Paul Kehrer506a2152015-05-26 08:01:18 -05001093 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001094
1095 This presence of this extension indicates that an OCSP client can trust a
1096 responder for the lifetime of the responder's certificate. CAs issuing
1097 such a certificate should realize that a compromise of the responder's key
1098 is as serious as the compromise of a CA key used to sign CRLs, at least for
1099 the validity period of this certificate. CA's may choose to issue this type
1100 of certificate with a very short lifetime and renew it frequently. This
1101 extension is only relevant when the certificate is an authorized OCSP
1102 responder.
1103
Paul Kehrer822f3d32015-08-06 11:47:32 +01001104 .. attribute:: oid
1105
1106 .. versionadded:: 1.0
1107
1108 :type: :class:`ObjectIdentifier`
1109
Paul Kehrere27f6582015-08-10 18:33:38 -05001110 Returns :attr:`~cryptography.x509.oid.ExtensionOID.OCSP_NO_CHECK`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001111
Paul Kehrere0017be2015-05-17 20:39:40 -06001112.. class:: NameConstraints
1113
1114 .. versionadded:: 1.0
1115
1116 The name constraints extension, which only has meaning in a CA certificate,
1117 defines a name space within which all subject names in certificates issued
1118 beneath the CA certificate must (or must not) be in. For specific details
1119 on the way this extension should be processed see :rfc:`5280`.
1120
Paul Kehrer822f3d32015-08-06 11:47:32 +01001121 .. attribute:: oid
1122
1123 .. versionadded:: 1.0
1124
1125 :type: :class:`ObjectIdentifier`
1126
Paul Kehrere27f6582015-08-10 18:33:38 -05001127 Returns :attr:`~cryptography.x509.oid.ExtensionOID.NAME_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001128
Paul Kehrere0017be2015-05-17 20:39:40 -06001129 .. attribute:: permitted_subtrees
1130
1131 :type: list of :class:`GeneralName` objects or None
1132
1133 The set of permitted name patterns. If a name matches this and an
1134 element in ``excluded_subtrees`` it is invalid. At least one of
1135 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
1136
1137 .. attribute:: excluded_subtrees
1138
1139 :type: list of :class:`GeneralName` objects or None
1140
1141 Any name matching a restriction in the ``excluded_subtrees`` field is
1142 invalid regardless of information appearing in the
1143 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
1144 ``excluded_subtrees`` will be non-None.
1145
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001146.. class:: AuthorityKeyIdentifier
1147
1148 .. versionadded:: 0.9
1149
1150 The authority key identifier extension provides a means of identifying the
1151 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001152 This extension is typically used to assist in determining the appropriate
1153 certificate chain. For more information about generation and use of this
1154 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001155
Paul Kehrer822f3d32015-08-06 11:47:32 +01001156 .. attribute:: oid
1157
1158 .. versionadded:: 1.0
1159
1160 :type: :class:`ObjectIdentifier`
1161
Paul Kehrere27f6582015-08-10 18:33:38 -05001162 Returns
1163 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001164
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001165 .. attribute:: key_identifier
1166
1167 :type: bytes
1168
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001169 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001170 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001171
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001172 .. attribute:: authority_cert_issuer
1173
1174 :type: :class:`Name` or None
1175
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001176 The :class:`Name` of the issuer's issuer.
1177
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001178 .. attribute:: authority_cert_serial_number
1179
1180 :type: int or None
1181
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001182 The serial number of the issuer's issuer.
1183
Paul Kehrer253929a2015-08-05 17:30:39 +01001184 .. classmethod:: from_issuer_public_key(public_key)
1185
1186 .. versionadded:: 1.0
1187
1188 Creates a new AuthorityKeyIdentifier instance using the public key
1189 provided to generate the appropriate digest. This should be the
Paul Kehrer26ac47f2015-08-08 15:20:52 -05001190 **issuer's public key**. The resulting object will contain
1191 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1192 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1193 and
1194 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1195 will be None.
1196 The generated ``key_identifier`` is the SHA1 hash of the ``subjectPublicKey``
1197 ASN.1 bit string. This is the first recommendation in :rfc:`5280`
Paul Kehrer253929a2015-08-05 17:30:39 +01001198 section 4.2.1.2.
1199
Paul Kehrercc671822015-08-08 15:41:54 -05001200 :param public_key: One of
1201 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1202 ,
1203 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1204 , or
1205 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
Paul Kehrer253929a2015-08-05 17:30:39 +01001206
1207 .. doctest::
1208
1209 >>> from cryptography import x509
1210 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001211 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1212 >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key())
Paul Kehrer253929a2015-08-05 17:30:39 +01001213 <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)>
1214
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001215.. class:: SubjectKeyIdentifier
1216
1217 .. versionadded:: 0.9
1218
1219 The subject key identifier extension provides a means of identifying
1220 certificates that contain a particular public key.
1221
Paul Kehrer822f3d32015-08-06 11:47:32 +01001222 .. attribute:: oid
1223
1224 .. versionadded:: 1.0
1225
1226 :type: :class:`ObjectIdentifier`
1227
Paul Kehrere27f6582015-08-10 18:33:38 -05001228 Returns
1229 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001230
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001231 .. attribute:: digest
1232
1233 :type: bytes
1234
1235 The binary value of the identifier.
1236
Paul Kehrerd4a7f062015-08-05 18:32:18 +01001237 .. classmethod:: from_public_key(public_key)
Paul Kehrerf22f6122015-08-05 12:57:13 +01001238
1239 .. versionadded:: 1.0
1240
1241 Creates a new SubjectKeyIdentifier instance using the public key
1242 provided to generate the appropriate digest. This should be the public
Paul Kehrereb9ec002015-08-08 10:03:02 -05001243 key that is in the certificate. The generated digest is the SHA1 hash
1244 of the ``subjectPublicKey`` ASN.1 bit string. This is the first
1245 recommendation in :rfc:`5280` section 4.2.1.2.
Paul Kehrerf22f6122015-08-05 12:57:13 +01001246
1247 :param public_key: One of
1248 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1249 ,
1250 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1251 , or
1252 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
1253
Paul Kehrer253929a2015-08-05 17:30:39 +01001254 .. doctest::
1255
1256 >>> from cryptography import x509
1257 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001258 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
1259 >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key())
1260 <SubjectKeyIdentifier(digest='\xdb\xaa\xf0\x06\x11\xdbD\xfe\xbf\x93\x03\x8av\x88WP7\xa6\x91\xf7')>
Paul Kehrer253929a2015-08-05 17:30:39 +01001261
Paul Kehrer31bdf792015-03-25 14:11:00 -05001262.. class:: SubjectAlternativeName
1263
1264 .. versionadded:: 0.9
1265
1266 Subject alternative name is an X.509 extension that provides a list of
1267 :ref:`general name <general_name_classes>` instances that provide a set
1268 of identities for which the certificate is valid. The object is iterable to
1269 get every element.
1270
Paul Kehrer822f3d32015-08-06 11:47:32 +01001271 .. attribute:: oid
1272
1273 .. versionadded:: 1.0
1274
1275 :type: :class:`ObjectIdentifier`
1276
Paul Kehrere27f6582015-08-10 18:33:38 -05001277 Returns
1278 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001279
Paul Kehrer31bdf792015-03-25 14:11:00 -05001280 .. method:: get_values_for_type(type)
1281
1282 :param type: A :class:`GeneralName` provider. This is one of the
1283 :ref:`general name classes <general_name_classes>`.
1284
1285 :returns: A list of values extracted from the matched general names.
Joshua Taubererd2afad32015-07-06 22:37:53 +00001286 The type of the returned values depends on the :class:`GeneralName`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001287
Paul Kehrer93ae8052015-05-02 23:18:09 -05001288 .. doctest::
1289
1290 >>> from cryptography import x509
1291 >>> from cryptography.hazmat.backends import default_backend
1292 >>> from cryptography.hazmat.primitives import hashes
1293 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001294 >>> # Get the subjectAltName extension from the certificate
Paul Kehrere27f6582015-08-10 18:33:38 -05001295 >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001296 >>> # Get the dNSName entries from the SAN extension
1297 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer93ae8052015-05-02 23:18:09 -05001298 [u'www.cryptography.io', u'cryptography.io']
1299
Paul Kehrer8cf26422015-03-21 09:50:24 -05001300
Paul Kehrer99125c92015-06-07 18:37:10 -05001301.. class:: IssuerAlternativeName
1302
1303 .. versionadded:: 1.0
1304
1305 Issuer alternative name is an X.509 extension that provides a list of
1306 :ref:`general name <general_name_classes>` instances that provide a set
1307 of identities for the certificate issuer. The object is iterable to
1308 get every element.
1309
Paul Kehrer822f3d32015-08-06 11:47:32 +01001310 .. attribute:: oid
1311
1312 .. versionadded:: 1.0
1313
1314 :type: :class:`ObjectIdentifier`
1315
Paul Kehrere27f6582015-08-10 18:33:38 -05001316 Returns
1317 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUER_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001318
Paul Kehrer99125c92015-06-07 18:37:10 -05001319 .. method:: get_values_for_type(type)
1320
1321 :param type: A :class:`GeneralName` provider. This is one of the
1322 :ref:`general name classes <general_name_classes>`.
1323
1324 :returns: A list of values extracted from the matched general names.
1325
1326
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001327.. class:: AuthorityInformationAccess
1328
1329 .. versionadded:: 0.9
1330
1331 The authority information access extension indicates how to access
1332 information and services for the issuer of the certificate in which
1333 the extension appears. Information and services may include online
1334 validation services (such as OCSP) and issuer data. It is an iterable,
Paul Kehrere27f6582015-08-10 18:33:38 -05001335 containing one or more :class:`~cryptography.x509.AccessDescription`
1336 instances.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001337
Paul Kehrer822f3d32015-08-06 11:47:32 +01001338 .. attribute:: oid
1339
1340 .. versionadded:: 1.0
1341
1342 :type: :class:`ObjectIdentifier`
1343
Paul Kehrere27f6582015-08-10 18:33:38 -05001344 Returns
1345 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_INFORMATION_ACCESS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001346
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001347
1348.. class:: AccessDescription
1349
Paul Kehrer5a485522015-05-06 00:29:12 -05001350 .. versionadded:: 0.9
1351
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001352 .. attribute:: access_method
1353
1354 :type: :class:`ObjectIdentifier`
1355
Paul Kehrerf506bca2015-05-02 22:31:47 -05001356 The access method defines what the ``access_location`` means. It must
Paul Kehrere27f6582015-08-10 18:33:38 -05001357 be either
1358 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` or
1359 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`.
1360 If it is
1361 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP`
1362 the access location will be where to obtain OCSP
1363 information for the certificate. If it is
1364 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`
1365 the access location will provide additional information about the
1366 issuing certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001367
1368 .. attribute:: access_location
1369
1370 :type: :class:`GeneralName`
1371
Paul Kehrerf506bca2015-05-02 22:31:47 -05001372 Where to access the information defined by the access method.
1373
Paul Kehrer5a485522015-05-06 00:29:12 -05001374.. class:: CRLDistributionPoints
1375
1376 .. versionadded:: 0.9
1377
1378 The CRL distribution points extension identifies how CRL information is
1379 obtained. It is an iterable, containing one or more
1380 :class:`DistributionPoint` instances.
1381
Paul Kehrer822f3d32015-08-06 11:47:32 +01001382 .. attribute:: oid
1383
1384 .. versionadded:: 1.0
1385
1386 :type: :class:`ObjectIdentifier`
1387
Paul Kehrere27f6582015-08-10 18:33:38 -05001388 Returns
1389 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_DISTRIBUTION_POINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001390
Paul Kehrer5a485522015-05-06 00:29:12 -05001391.. class:: DistributionPoint
1392
1393 .. versionadded:: 0.9
1394
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001395 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05001396
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001397 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001398
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001399 This field describes methods to retrieve the CRL. At most one of
1400 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001401
1402 .. attribute:: relative_name
1403
1404 :type: :class:`Name` or None
1405
1406 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001407 issuer. At most one of ``full_name`` or ``relative_name`` will be
1408 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05001409
1410 .. attribute:: crl_issuer
1411
1412 :type: list of :class:`GeneralName` instances or None
1413
1414 Information about the issuer of the CRL.
1415
1416 .. attribute:: reasons
1417
Paul Kehrer3fd02602015-05-09 19:46:13 -05001418 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001419
1420 The reasons a given distribution point may be used for when performing
1421 revocation checks.
1422
1423.. class:: ReasonFlags
1424
1425 .. versionadded:: 0.9
1426
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001427 An enumeration for CRL reasons.
1428
1429 .. attribute:: unspecified
1430
1431 It is unspecified why the certificate was revoked. This reason cannot
1432 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001433
1434 .. attribute:: key_compromise
1435
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001436 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001437
1438 .. attribute:: ca_compromise
1439
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001440 This reason indicates that the CA issuing the certificate was
1441 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001442
1443 .. attribute:: affiliation_changed
1444
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001445 This reason indicates that the subject's name or other information has
1446 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05001447
1448 .. attribute:: superseded
1449
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001450 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05001451
1452 .. attribute:: cessation_of_operation
1453
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001454 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05001455
1456 .. attribute:: certificate_hold
1457
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001458 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05001459
1460 .. attribute:: privilege_withdrawn
1461
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001462 This reason indicates that the privilege granted by this certificate
1463 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05001464
1465 .. attribute:: aa_compromise
1466
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001467 When an attribute authority has been compromised.
1468
1469 .. attribute:: remove_from_crl
1470
1471 This reason indicates that the certificate was on hold and should be
1472 removed from the CRL. This reason cannot be used as a reason flag
1473 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001474
Paul Kehrer16fae762015-05-01 23:14:20 -05001475.. class:: InhibitAnyPolicy
1476
1477 .. versionadded:: 1.0
1478
1479 The inhibit ``anyPolicy`` extension indicates that the special OID
Paul Kehrere27f6582015-08-10 18:33:38 -05001480 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY`, is not
1481 considered an explicit match for other :class:`CertificatePolicies` except
1482 when it appears in an intermediate self-issued CA certificate. The value
1483 indicates the number of additional non-self-issued certificates that may
1484 appear in the path before
1485 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` is no
1486 longer permitted. For example, a value of one indicates that
1487 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` may be
1488 processed in certificates issued by the subject of this certificate, but
1489 not in additional certificates in the path.
Paul Kehrer16fae762015-05-01 23:14:20 -05001490
Paul Kehrer822f3d32015-08-06 11:47:32 +01001491 .. attribute:: oid
1492
1493 .. versionadded:: 1.0
1494
1495 :type: :class:`ObjectIdentifier`
1496
Paul Kehrere27f6582015-08-10 18:33:38 -05001497 Returns
1498 :attr:`~cryptography.x509.oid.ExtensionOID.INHIBIT_ANY_POLICY`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001499
Paul Kehrer16fae762015-05-01 23:14:20 -05001500 .. attribute:: skip_certs
1501
1502 :type: int
1503
Paul Kehrer0d210922015-04-28 17:31:07 -05001504.. class:: CertificatePolicies
1505
1506 .. versionadded:: 0.9
1507
Paul Kehrer2e879742015-05-02 23:09:56 -05001508 The certificate policies extension is an iterable, containing one or more
1509 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05001510
Paul Kehrer822f3d32015-08-06 11:47:32 +01001511 .. attribute:: oid
1512
1513 .. versionadded:: 1.0
1514
1515 :type: :class:`ObjectIdentifier`
1516
Paul Kehrere27f6582015-08-10 18:33:38 -05001517 Returns
1518 :attr:`~cryptography.x509.oid.ExtensionOID.CERTIFICATE_POLICIES`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001519
Paul Kehrer0d210922015-04-28 17:31:07 -05001520Certificate Policies Classes
1521~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1522
1523These classes may be present within a :class:`CertificatePolicies` instance.
1524
1525.. class:: PolicyInformation
1526
1527 .. versionadded:: 0.9
1528
1529 Contains a policy identifier and an optional list of qualifiers.
1530
1531 .. attribute:: policy_identifier
1532
1533 :type: :class:`ObjectIdentifier`
1534
1535 .. attribute:: policy_qualifiers
1536
1537 :type: list
1538
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001539 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05001540 If the value is text it is a pointer to the practice statement
1541 published by the certificate authority. If it is a user notice it is
1542 meant for display to the relying party when the certificate is
1543 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05001544
Paul Kehrer0d210922015-04-28 17:31:07 -05001545.. class:: UserNotice
1546
1547 .. versionadded:: 0.9
1548
Paul Kehrer2e879742015-05-02 23:09:56 -05001549 User notices are intended for display to a relying party when a certificate
1550 is used. In practice, few if any UIs expose this data and it is a rarely
1551 encoded component.
1552
Paul Kehrer0d210922015-04-28 17:31:07 -05001553 .. attribute:: notice_reference
1554
1555 :type: :class:`NoticeReference` or None
1556
Paul Kehrer2e879742015-05-02 23:09:56 -05001557 The notice reference field names an organization and identifies,
1558 by number, a particular statement prepared by that organization.
1559
Paul Kehrer0d210922015-04-28 17:31:07 -05001560 .. attribute:: explicit_text
1561
Paul Kehrer2e879742015-05-02 23:09:56 -05001562 This field includes an arbitrary textual statement directly in the
1563 certificate.
1564
Paul Kehrer0d210922015-04-28 17:31:07 -05001565 :type: :term:`text`
1566
1567.. class:: NoticeReference
1568
Paul Kehrer2e879742015-05-02 23:09:56 -05001569 Notice reference can name an organization and provide information about
1570 notices related to the certificate. For example, it might identify the
1571 organization name and notice number 1. Application software could
1572 have a notice file containing the current set of notices for the named
1573 organization; the application would then extract the notice text from the
1574 file and display it. In practice this is rarely seen.
1575
Paul Kehrer0d210922015-04-28 17:31:07 -05001576 .. versionadded:: 0.9
1577
1578 .. attribute:: organization
1579
Paul Kehrer66c61702015-05-12 16:39:18 -05001580 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05001581
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05001582 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05001583
Paul Kehrer66c61702015-05-12 16:39:18 -05001584 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05001585
Paul Kehrer66c61702015-05-12 16:39:18 -05001586 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05001587
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001588Object Identifiers
1589~~~~~~~~~~~~~~~~~~
1590
Paul Kehrer4bb46492015-02-07 16:59:14 -06001591X.509 elements are frequently identified by :class:`ObjectIdentifier`
1592instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001593
Paul Kehrere27f6582015-08-10 18:33:38 -05001594.. currentmodule:: cryptography.x509.oid
Paul Kehrer56da2a52015-02-11 23:35:07 -06001595
Paul Kehrere27f6582015-08-10 18:33:38 -05001596.. class:: NameOID
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001597
Paul Kehrere27f6582015-08-10 18:33:38 -05001598 These OIDs are typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001599
Paul Kehrere27f6582015-08-10 18:33:38 -05001600 .. versionadded:: 1.0
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001601
Paul Kehrere27f6582015-08-10 18:33:38 -05001602 .. attribute:: COMMON_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001603
Paul Kehrere27f6582015-08-10 18:33:38 -05001604 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
1605 name would be encoded here for server certificates. :rfc:`2818`
1606 deprecates this practice and names of that type should now be located
1607 in a :class:`~cryptography.x509.SubjectAlternativeName` extension.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001608
Paul Kehrere27f6582015-08-10 18:33:38 -05001609 .. attribute:: COUNTRY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001610
Paul Kehrere27f6582015-08-10 18:33:38 -05001611 Corresponds to the dotted string ``"2.5.4.6"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001612
Paul Kehrere27f6582015-08-10 18:33:38 -05001613 .. attribute:: LOCALITY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001614
Paul Kehrere27f6582015-08-10 18:33:38 -05001615 Corresponds to the dotted string ``"2.5.4.7"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001616
Paul Kehrere27f6582015-08-10 18:33:38 -05001617 .. attribute:: STATE_OR_PROVINCE_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001618
Paul Kehrere27f6582015-08-10 18:33:38 -05001619 Corresponds to the dotted string ``"2.5.4.8"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001620
Paul Kehrere27f6582015-08-10 18:33:38 -05001621 .. attribute:: ORGANIZATION_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001622
Paul Kehrere27f6582015-08-10 18:33:38 -05001623 Corresponds to the dotted string ``"2.5.4.10"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001624
Paul Kehrere27f6582015-08-10 18:33:38 -05001625 .. attribute:: ORGANIZATIONAL_UNIT_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001626
Paul Kehrere27f6582015-08-10 18:33:38 -05001627 Corresponds to the dotted string ``"2.5.4.11"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001628
Paul Kehrere27f6582015-08-10 18:33:38 -05001629 .. attribute:: SERIAL_NUMBER
Paul Kehrer858b9b72015-02-05 09:50:31 -06001630
Paul Kehrere27f6582015-08-10 18:33:38 -05001631 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from
1632 the serial number of the certificate itself (which can be obtained with
1633 :func:`~cryptography.x509.Certificate.serial`).
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001634
Paul Kehrere27f6582015-08-10 18:33:38 -05001635 .. attribute:: SURNAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001636
Paul Kehrere27f6582015-08-10 18:33:38 -05001637 Corresponds to the dotted string ``"2.5.4.4"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001638
Paul Kehrere27f6582015-08-10 18:33:38 -05001639 .. attribute:: GIVEN_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001640
Paul Kehrere27f6582015-08-10 18:33:38 -05001641 Corresponds to the dotted string ``"2.5.4.42"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001642
Paul Kehrere27f6582015-08-10 18:33:38 -05001643 .. attribute:: TITLE
Paul Kehrer858b9b72015-02-05 09:50:31 -06001644
Paul Kehrere27f6582015-08-10 18:33:38 -05001645 Corresponds to the dotted string ``"2.5.4.12"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001646
Paul Kehrere27f6582015-08-10 18:33:38 -05001647 .. attribute:: GENERATION_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06001648
Paul Kehrere27f6582015-08-10 18:33:38 -05001649 Corresponds to the dotted string ``"2.5.4.44"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001650
Paul Kehrere27f6582015-08-10 18:33:38 -05001651 .. attribute:: DN_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06001652
Paul Kehrere27f6582015-08-10 18:33:38 -05001653 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
1654 disambiguating information to add to the relative distinguished name of an
1655 entry. See :rfc:`2256`.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001656
Paul Kehrere27f6582015-08-10 18:33:38 -05001657 .. attribute:: PSEUDONYM
Paul Kehrer858b9b72015-02-05 09:50:31 -06001658
Paul Kehrere27f6582015-08-10 18:33:38 -05001659 Corresponds to the dotted string ``"2.5.4.65"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001660
Paul Kehrere27f6582015-08-10 18:33:38 -05001661 .. attribute:: DOMAIN_COMPONENT
Paul Kehrer858b9b72015-02-05 09:50:31 -06001662
Paul Kehrere27f6582015-08-10 18:33:38 -05001663 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
1664 holding one component of a domain name. See :rfc:`4519`.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001665
Paul Kehrere27f6582015-08-10 18:33:38 -05001666 .. attribute:: EMAIL_ADDRESS
Paul Kehrer56da2a52015-02-11 23:35:07 -06001667
Paul Kehrere27f6582015-08-10 18:33:38 -05001668 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001669
Paul Kehrer56da2a52015-02-11 23:35:07 -06001670
Paul Kehrere27f6582015-08-10 18:33:38 -05001671.. class:: SignatureAlgorithmOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06001672
Paul Kehrere27f6582015-08-10 18:33:38 -05001673 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06001674
Paul Kehrere27f6582015-08-10 18:33:38 -05001675 .. attribute:: RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06001676
Paul Kehrere27f6582015-08-10 18:33:38 -05001677 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
1678 an MD5 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001679
Paul Kehrere27f6582015-08-10 18:33:38 -05001680 .. attribute:: RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06001681
Paul Kehrere27f6582015-08-10 18:33:38 -05001682 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
1683 a SHA1 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001684
Paul Kehrere27f6582015-08-10 18:33:38 -05001685 .. attribute:: RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06001686
Paul Kehrere27f6582015-08-10 18:33:38 -05001687 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
1688 a SHA224 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001689
Paul Kehrere27f6582015-08-10 18:33:38 -05001690 .. attribute:: RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06001691
Paul Kehrere27f6582015-08-10 18:33:38 -05001692 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
1693 a SHA256 digest signed by an RSA key.
Alex Gaynor3aadabf2015-06-23 22:06:21 -04001694
Paul Kehrere27f6582015-08-10 18:33:38 -05001695 .. attribute:: RSA_WITH_SHA384
Alex Gaynor3aadabf2015-06-23 22:06:21 -04001696
Paul Kehrere27f6582015-08-10 18:33:38 -05001697 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
1698 a SHA384 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001699
Paul Kehrere27f6582015-08-10 18:33:38 -05001700 .. attribute:: RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06001701
Paul Kehrere27f6582015-08-10 18:33:38 -05001702 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
1703 a SHA512 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001704
Paul Kehrere27f6582015-08-10 18:33:38 -05001705 .. attribute:: ECDSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06001706
Paul Kehrere27f6582015-08-10 18:33:38 -05001707 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
1708 digest signed by an ECDSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001709
Paul Kehrere27f6582015-08-10 18:33:38 -05001710 .. attribute:: ECDSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06001711
Paul Kehrere27f6582015-08-10 18:33:38 -05001712 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
1713 a SHA224 digest signed by an ECDSA key.
1714
1715 .. attribute:: ECDSA_WITH_SHA256
1716
1717 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
1718 a SHA256 digest signed by an ECDSA key.
1719
1720 .. attribute:: ECDSA_WITH_SHA384
1721
1722 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
1723 a SHA384 digest signed by an ECDSA key.
1724
1725 .. attribute:: ECDSA_WITH_SHA512
1726
1727 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
1728 a SHA512 digest signed by an ECDSA key.
1729
1730 .. attribute:: DSA_WITH_SHA1
1731
1732 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
1733 a SHA1 digest signed by a DSA key.
1734
1735 .. attribute:: DSA_WITH_SHA224
1736
1737 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
1738 a SHA224 digest signed by a DSA key.
1739
1740 .. attribute:: DSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06001741
Paul Kehrere27f6582015-08-10 18:33:38 -05001742 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
1743 a SHA256 digest signed by a DSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001744
Paul Kehrer56da2a52015-02-11 23:35:07 -06001745
Paul Kehrere27f6582015-08-10 18:33:38 -05001746.. class:: ExtendedKeyUsageOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06001747
Paul Kehrere27f6582015-08-10 18:33:38 -05001748 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06001749
Paul Kehrere27f6582015-08-10 18:33:38 -05001750 .. attribute:: SERVER_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06001751
Paul Kehrere27f6582015-08-10 18:33:38 -05001752 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used
1753 to denote that a certificate may be used for TLS web server
1754 authentication.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001755
Paul Kehrere27f6582015-08-10 18:33:38 -05001756 .. attribute:: CLIENT_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06001757
Paul Kehrere27f6582015-08-10 18:33:38 -05001758 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used
1759 to denote that a certificate may be used for TLS web client
1760 authentication.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001761
Paul Kehrere27f6582015-08-10 18:33:38 -05001762 .. attribute:: CODE_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05001763
Paul Kehrere27f6582015-08-10 18:33:38 -05001764 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used
1765 to denote that a certificate may be used for code signing.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001766
Paul Kehrere27f6582015-08-10 18:33:38 -05001767 .. attribute:: EMAIL_PROTECTION
Paul Kehrere1513fa2015-03-30 23:08:17 -05001768
Paul Kehrere27f6582015-08-10 18:33:38 -05001769 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used
1770 to denote that a certificate may be used for email protection.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001771
Paul Kehrere27f6582015-08-10 18:33:38 -05001772 .. attribute:: TIME_STAMPING
Paul Kehrere1513fa2015-03-30 23:08:17 -05001773
Paul Kehrere27f6582015-08-10 18:33:38 -05001774 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used
1775 to denote that a certificate may be used for time stamping.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001776
Paul Kehrere27f6582015-08-10 18:33:38 -05001777 .. attribute:: OCSP_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05001778
Paul Kehrere27f6582015-08-10 18:33:38 -05001779 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used
1780 to denote that a certificate may be used for signing OCSP responses.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001781
Paul Kehrere1513fa2015-03-30 23:08:17 -05001782
Paul Kehrere27f6582015-08-10 18:33:38 -05001783.. class:: AuthorityInformationAccessOID
Paul Kehrere1513fa2015-03-30 23:08:17 -05001784
Paul Kehrere27f6582015-08-10 18:33:38 -05001785 .. versionadded:: 1.0
Paul Kehrere1513fa2015-03-30 23:08:17 -05001786
Paul Kehrere27f6582015-08-10 18:33:38 -05001787 .. attribute:: OCSP
Paul Kehrere1513fa2015-03-30 23:08:17 -05001788
Paul Kehrere27f6582015-08-10 18:33:38 -05001789 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
1790 identifier for OCSP data in
1791 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001792
Paul Kehrere27f6582015-08-10 18:33:38 -05001793 .. attribute:: CA_ISSUERS
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001794
Paul Kehrere27f6582015-08-10 18:33:38 -05001795 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
1796 identifier for CA issuer data in
1797 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001798
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001799
Paul Kehrere27f6582015-08-10 18:33:38 -05001800.. class:: CertificatePoliciesOID
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001801
Paul Kehrere27f6582015-08-10 18:33:38 -05001802 .. versionadded:: 1.0
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001803
Paul Kehrere27f6582015-08-10 18:33:38 -05001804 .. attribute:: CPS_QUALIFIER
Paul Kehrer2e879742015-05-02 23:09:56 -05001805
Paul Kehrere27f6582015-08-10 18:33:38 -05001806 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05001807
Paul Kehrere27f6582015-08-10 18:33:38 -05001808 .. attribute:: CPS_USER_NOTICE
Paul Kehrer2e879742015-05-02 23:09:56 -05001809
Paul Kehrere27f6582015-08-10 18:33:38 -05001810 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05001811
Paul Kehrere27f6582015-08-10 18:33:38 -05001812 .. attribute:: ANY_POLICY
Paul Kehrer2e879742015-05-02 23:09:56 -05001813
Paul Kehrere27f6582015-08-10 18:33:38 -05001814 Corresponds to the dotted string ``"2.5.29.32.0"``.
Paul Kehrer16fae762015-05-01 23:14:20 -05001815
Paul Kehrer16fae762015-05-01 23:14:20 -05001816
Paul Kehrere27f6582015-08-10 18:33:38 -05001817.. class:: ExtensionOID
Paul Kehrer5553d572015-03-23 21:08:01 -05001818
Paul Kehrere27f6582015-08-10 18:33:38 -05001819 .. versionadded:: 1.0
Paul Kehrer2bb94642015-03-21 09:54:17 -05001820
Paul Kehrere27f6582015-08-10 18:33:38 -05001821 .. attribute:: BASIC_CONSTRAINTS
Paul Kehrer2bb94642015-03-21 09:54:17 -05001822
Paul Kehrere27f6582015-08-10 18:33:38 -05001823 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
1824 :class:`~cryptography.x509.BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05001825
Paul Kehrere27f6582015-08-10 18:33:38 -05001826 .. attribute:: KEY_USAGE
Paul Kehrercecbbba2015-03-30 14:58:38 -05001827
Paul Kehrere27f6582015-08-10 18:33:38 -05001828 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
1829 :class:`~cryptography.x509.KeyUsage` extension type.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001830
Paul Kehrere27f6582015-08-10 18:33:38 -05001831 .. attribute:: SUBJECT_ALTERNATIVE_NAME
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001832
Paul Kehrere27f6582015-08-10 18:33:38 -05001833 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
1834 :class:`~cryptography.x509.SubjectAlternativeName` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001835
Paul Kehrere27f6582015-08-10 18:33:38 -05001836 .. attribute:: ISSUER_ALTERNATIVE_NAME
Paul Kehrer99125c92015-06-07 18:37:10 -05001837
Paul Kehrere27f6582015-08-10 18:33:38 -05001838 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
1839 :class:`~cryptography.x509.IssuerAlternativeName` extension type.
Paul Kehrer99125c92015-06-07 18:37:10 -05001840
Paul Kehrere27f6582015-08-10 18:33:38 -05001841 .. attribute:: SUBJECT_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001842
Paul Kehrere27f6582015-08-10 18:33:38 -05001843 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
1844 :class:`~cryptography.x509.SubjectKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001845
Paul Kehrere27f6582015-08-10 18:33:38 -05001846 .. attribute:: NAME_CONSTRAINTS
Paul Kehrere0017be2015-05-17 20:39:40 -06001847
Paul Kehrere27f6582015-08-10 18:33:38 -05001848 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
1849 :class:`~cryptography.x509.NameConstraints` extension type.
Paul Kehrere0017be2015-05-17 20:39:40 -06001850
Paul Kehrere27f6582015-08-10 18:33:38 -05001851 .. attribute:: CRL_DISTRIBUTION_POINTS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001852
Paul Kehrere27f6582015-08-10 18:33:38 -05001853 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
1854 :class:`~cryptography.x509.CRLDistributionPoints` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001855
Paul Kehrere27f6582015-08-10 18:33:38 -05001856 .. attribute:: CERTIFICATE_POLICIES
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001857
Paul Kehrere27f6582015-08-10 18:33:38 -05001858 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
1859 :class:`~cryptography.x509.CertificatePolicies` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001860
Paul Kehrere27f6582015-08-10 18:33:38 -05001861 .. attribute:: AUTHORITY_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001862
Paul Kehrere27f6582015-08-10 18:33:38 -05001863 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
1864 :class:`~cryptography.x509.AuthorityKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001865
Paul Kehrere27f6582015-08-10 18:33:38 -05001866 .. attribute:: EXTENDED_KEY_USAGE
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001867
Paul Kehrere27f6582015-08-10 18:33:38 -05001868 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
1869 :class:`~cryptography.x509.ExtendedKeyUsage` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001870
Paul Kehrere27f6582015-08-10 18:33:38 -05001871 .. attribute:: AUTHORITY_INFORMATION_ACCESS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001872
Paul Kehrere27f6582015-08-10 18:33:38 -05001873 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
1874 for the :class:`~cryptography.x509.AuthorityInformationAccess` extension
1875 type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001876
Paul Kehrere27f6582015-08-10 18:33:38 -05001877 .. attribute:: INHIBIT_ANY_POLICY
Paul Kehrerb33de932015-08-06 23:41:05 +01001878
Paul Kehrere27f6582015-08-10 18:33:38 -05001879 Corresponds to the dotted string ``"2.5.29.54"``. The identifier
1880 for the :class:`~cryptography.x509.InhibitAnyPolicy` extension type.
Paul Kehrerb33de932015-08-06 23:41:05 +01001881
Paul Kehrere27f6582015-08-10 18:33:38 -05001882 .. attribute:: OCSP_NO_CHECK
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001883
Paul Kehrere27f6582015-08-10 18:33:38 -05001884 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The
1885 identifier for the :class:`~cryptography.x509.OCSPNoCheck` extension
1886 type.
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001887
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001888Exceptions
1889~~~~~~~~~~
Paul Kehrere27f6582015-08-10 18:33:38 -05001890.. currentmodule:: cryptography.x509
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001891
Paul Kehrere76cd272014-12-14 19:00:51 -06001892.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10001893
1894 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10001895
Paul Kehrerd5cccf72014-12-15 17:20:33 -06001896 .. attribute:: parsed_version
1897
Paul Kehrerbbffc402014-12-17 13:33:55 -06001898 :type: int
1899
1900 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06001901
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001902.. class:: DuplicateExtension
1903
1904 This is raised when more than one X.509 extension of the same type is
1905 found within a certificate.
1906
1907 .. attribute:: oid
1908
1909 :type: :class:`ObjectIdentifier`
1910
1911 Returns the OID.
1912
1913.. class:: UnsupportedExtension
1914
1915 This is raised when a certificate contains an unsupported extension type.
1916
1917 .. attribute:: oid
1918
1919 :type: :class:`ObjectIdentifier`
1920
1921 Returns the OID.
1922
Paul Kehrerfa56a232015-03-17 13:14:03 -05001923.. class:: ExtensionNotFound
1924
1925 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
1926 an extension OID that is not present in the certificate.
1927
1928 .. attribute:: oid
1929
1930 :type: :class:`ObjectIdentifier`
1931
1932 Returns the OID.
1933
Paul Kehrer9089c912015-04-20 22:15:20 -05001934.. class:: UnsupportedGeneralNameType
1935
1936 This is raised when a certificate contains an unsupported general name
1937 type in an extension.
1938
Paul Kehrerbed07352015-04-21 08:31:10 -05001939 .. attribute:: type
1940
Paul Kehrer0a621bf2015-04-22 09:22:56 -05001941 :type: int
1942
1943 The integer value of the unsupported type. The complete list of
1944 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05001945
Paul Kehrer016e08a2014-11-26 09:41:18 -10001946
Paul Kehrerc7c9a432015-04-19 09:20:13 -05001947.. _`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 -05001948.. _`RFC 5280 section 4.2.1.6`: https://tools.ietf.org/html/rfc5280#section-4.2.1.6