blob: 8d5d6a6f011d07cad11fcb2e32b14f75ae286d4d [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
Ian Cordasco8f571422015-08-02 11:31:08 -0500499 :param extension: The extension to add to the certificate. Can be one
500 of :class:`~cryptography.x509.BasicConstraints` or
501 :class:`~cryptography.x509.SubjectAlternativeName`.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400502
Ian Cordasco17c89002015-08-02 21:13:59 -0500503 :param critical: Set to ``True`` if the extension must be understood and
504 handled by whoever reads the certificate.
505
Paul Kehrer9add80e2015-08-03 17:53:14 +0100506 .. method:: sign(private_key, algorithm, backend)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400507
508 Sign the certificate using the CA's private key.
509
Ian Cordascoc5e1c252015-07-31 23:33:35 -0500510 :param private_key: The
511 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
512 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
513 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
514 that will be used to sign the certificate.
515
Andre Caron9bbfcea2015-05-18 20:55:29 -0400516 :param algorithm: The
517 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
518 will be used to generate the signature.
519
Paul Kehrer9add80e2015-08-03 17:53:14 +0100520 :param backend: Backend that will be used to build the certificate.
521 Must support the
522 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
523 interface.
524
Andre Caron9bbfcea2015-05-18 20:55:29 -0400525
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500526X.509 CSR (Certificate Signing Request) Object
527~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600528
Paul Kehrera1a1f232015-03-15 15:34:35 -0500529.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600530
531 .. versionadded:: 0.9
532
533 .. method:: public_key()
534
535 :type:
536 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
537 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
538 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
539
540 The public key associated with the request.
541
542 .. doctest::
543
544 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500545 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600546 >>> isinstance(public_key, rsa.RSAPublicKey)
547 True
548
549 .. attribute:: subject
550
551 :type: :class:`Name`
552
553 The :class:`Name` of the subject.
554
555 .. attribute:: signature_hash_algorithm
556
557 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
558
559 Returns the
560 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
561 was used in signing this request.
562
563 .. doctest::
564
565 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500566 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600567 True
568
Paul Kehrerc4e61942015-08-01 21:21:13 +0100569 .. attribute:: extensions
570
571 :type: :class:`Extensions`
572
573 The extensions encoded in the certificate signing request.
574
575 :raises cryptography.x509.DuplicateExtension: If more than one
Paul Kehrer24283d22015-08-01 21:31:19 +0100576 extension of the same type is found within the certificate signing request.
Paul Kehrerc4e61942015-08-01 21:21:13 +0100577
Paul Kehrer24283d22015-08-01 21:31:19 +0100578 :raises cryptography.x509.UnsupportedExtension: If the certificate signing request
Paul Kehrerc4e61942015-08-01 21:21:13 +0100579 contains an extension that is not supported.
580
581 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
582 contains a general name that is not supported.
583
584 :raises UnicodeError: If an extension contains IDNA encoding that is
585 invalid or not compliant with IDNA 2008.
586
587
Andre Caron476c5df2015-05-18 10:23:28 -0400588 .. method:: public_bytes(encoding)
589
Alex Gaynord0b376b2015-07-05 13:58:12 -0400590 .. versionadded:: 1.0
591
Andre Caron476c5df2015-05-18 10:23:28 -0400592 :param encoding: The
593 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
594 that will be used to serialize the certificate request.
595
596 :return bytes: The data that can be written to a file or sent
597 over the network to be signed by the certificate
598 authority.
599
Erik Trauschke2dcce902015-05-14 16:12:24 -0700600X.509 Revoked Certificate Object
Erik Trauschkec5a8d172015-05-28 10:24:25 -0700601~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Erik Trauschke2dcce902015-05-14 16:12:24 -0700602
603.. class:: RevokedCertificate
604
605 .. versionadded:: 1.0
606
607 .. attribute:: serial_number
608
609 :type: :class:`int`
610
611 An integer representing the serial number of the revoked certificate.
612
613 .. attribute:: revocation_date
614
615 :type: :class:`datetime.datetime`
616
617 A naïve datetime representing the date this certificates was revoked.
618
619 .. attribute:: extensions
620
621 :type: :class:`Extensions`
622
623 The extensions encoded in the revoked certificate.
Andre Caron476c5df2015-05-18 10:23:28 -0400624
Andre Caron0ef595f2015-05-18 13:53:43 -0400625X.509 CSR (Certificate Signing Request) Builder Object
626~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
627
628.. class:: CertificateSigningRequestBuilder
629
Andre Carond259ee52015-06-02 23:47:11 -0400630 .. versionadded:: 1.0
631
632 .. doctest::
633
634 >>> from cryptography import x509
635 >>> from cryptography.hazmat.backends import default_backend
636 >>> from cryptography.hazmat.primitives import hashes
637 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrere27f6582015-08-10 18:33:38 -0500638 >>> from cryptography.x509.oid import NameOID
Andre Carond259ee52015-06-02 23:47:11 -0400639 >>> private_key = rsa.generate_private_key(
640 ... public_exponent=65537,
641 ... key_size=2048,
642 ... backend=default_backend()
643 ... )
644 >>> builder = x509.CertificateSigningRequestBuilder()
Andre Carona9a51172015-06-06 20:18:44 -0400645 >>> builder = builder.subject_name(x509.Name([
Paul Kehrere27f6582015-08-10 18:33:38 -0500646 ... x509.NameAttribute(NameOID.COMMON_NAME, u'cryptography.io'),
Andre Carond259ee52015-06-02 23:47:11 -0400647 ... ]))
Ian Cordascof06b6be2015-06-21 10:09:18 -0500648 >>> builder = builder.add_extension(
Ian Cordasco0112b022015-06-16 17:51:18 -0500649 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
Andre Caron472fd692015-06-06 20:04:44 -0400650 ... )
Andre Carond259ee52015-06-02 23:47:11 -0400651 >>> request = builder.sign(
Alex Gaynorde9e5842015-06-26 20:11:23 -0400652 ... private_key, hashes.SHA256(), default_backend()
Andre Carond259ee52015-06-02 23:47:11 -0400653 ... )
654 >>> isinstance(request, x509.CertificateSigningRequest)
655 True
656
Andre Carona9a51172015-06-06 20:18:44 -0400657 .. method:: subject_name(name)
Andre Caron0ef595f2015-05-18 13:53:43 -0400658
Andre Caron341ff852015-06-06 20:14:31 -0400659 :param name: The :class:`~cryptography.x509.Name` of the certificate
660 subject.
661 :returns: A new
662 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400663
Ian Cordascof06b6be2015-06-21 10:09:18 -0500664 .. method:: add_extension(extension, critical)
Andre Caron0ef595f2015-05-18 13:53:43 -0400665
Andre Caron341ff852015-06-06 20:14:31 -0400666 :param extension: The :class:`~cryptography.x509.Extension` to add to
667 the request.
Andre Caron472fd692015-06-06 20:04:44 -0400668 :param critical: Set to `True` if the extension must be understood and
669 handled by whoever reads the certificate.
Andre Caron341ff852015-06-06 20:14:31 -0400670 :returns: A new
671 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400672
Alex Gaynorb3b0fbe2015-06-26 19:57:18 -0400673 .. method:: sign(private_key, algorithm, backend)
Andre Caron0ef595f2015-05-18 13:53:43 -0400674
675 :param backend: Backend that will be used to sign the request.
676 Must support the
677 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
678 interface.
679
680 :param private_key: The
Andre Caron24f9bf42015-06-06 20:14:54 -0400681 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
682 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
683 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
Andre Caron0ef595f2015-05-18 13:53:43 -0400684 that will be used to sign the request. When the request is
685 signed by a certificate authority, the private key's associated
686 public key will be stored in the resulting certificate.
687
688 :param algorithm: The
689 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
690 that will be used to generate the request signature.
691
Andre Caron341ff852015-06-06 20:14:31 -0400692 :returns: A new
693 :class:`~cryptography.x509.CertificateSigningRequest`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400694
695
Paul Kehrer719d5362015-01-01 20:03:52 -0600696.. class:: Name
697
698 .. versionadded:: 0.8
699
Paul Kehrer53d8d492015-02-13 18:47:30 -0600700 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -0600701 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -0600702 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -0600703 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
704 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -0600705
Paul Kehrer53d8d492015-02-13 18:47:30 -0600706 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -0600707
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600708 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -0600709 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600710 >>> for attribute in cert.subject:
711 ... print(attribute)
712 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
713 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')>
714 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -0600715
Paul Kehrere901d642015-02-11 18:50:58 -0600716 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -0600717
Paul Kehrere901d642015-02-11 18:50:58 -0600718 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -0600719
Paul Kehrere901d642015-02-11 18:50:58 -0600720 :returns: A list of :class:`NameAttribute` instances that match the
721 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -0600722
723 .. doctest::
724
Paul Kehrere27f6582015-08-10 18:33:38 -0500725 >>> cert.subject.get_attributes_for_oid(NameOID.COMMON_NAME)
Paul Kehrere901d642015-02-11 18:50:58 -0600726 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -0600727
Paul Kehrere76cd272014-12-14 19:00:51 -0600728.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -1000729
730 .. versionadded:: 0.7
731
732 An enumeration for X.509 versions.
733
734 .. attribute:: v1
735
736 For version 1 X.509 certificates.
737
738 .. attribute:: v3
739
740 For version 3 X.509 certificates.
741
Paul Kehrer806bfb22015-02-02 17:05:24 -0600742.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600743
744 .. versionadded:: 0.8
745
Paul Kehrer834d22f2015-02-06 11:01:07 -0600746 An X.509 name consists of a list of NameAttribute instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600747
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600748 .. attribute:: oid
749
750 :type: :class:`ObjectIdentifier`
751
752 The attribute OID.
753
754 .. attribute:: value
755
Paul Kehrerd5852cb2015-01-30 08:25:23 -0600756 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600757
758 The value of the attribute.
759
760.. class:: ObjectIdentifier
761
762 .. versionadded:: 0.8
763
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600764 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -0600765 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600766
Paul Kehrerd44f9a62015-02-04 14:47:34 -0600767 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600768
769 :type: :class:`str`
770
Paul Kehrerfedf4f42015-02-06 11:22:07 -0600771 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600772
Paul Kehrer31bdf792015-03-25 14:11:00 -0500773.. _general_name_classes:
774
775General Name Classes
776~~~~~~~~~~~~~~~~~~~~
777
778.. class:: GeneralName
779
780 .. versionadded:: 0.9
781
782 This is the generic interface that all the following classes are registered
783 against.
784
785.. class:: RFC822Name
786
787 .. versionadded:: 0.9
788
789 This corresponds to an email address. For example, ``user@example.com``.
790
791 .. attribute:: value
792
793 :type: :term:`text`
794
795.. class:: DNSName
796
797 .. versionadded:: 0.9
798
799 This corresponds to a domain name. For example, ``cryptography.io``.
800
801 .. attribute:: value
802
803 :type: :term:`text`
804
805.. class:: DirectoryName
806
807 .. versionadded:: 0.9
808
809 This corresponds to a directory name.
810
811 .. attribute:: value
812
813 :type: :class:`Name`
814
815.. class:: UniformResourceIdentifier
816
817 .. versionadded:: 0.9
818
819 This corresponds to a uniform resource identifier. For example,
Paul Kehrerb8ef82e2015-04-22 16:04:24 -0500820 ``https://cryptography.io``. The URI is parsed and IDNA decoded (see
821 :rfc:`5895`).
822
823 .. note::
824
825 URIs that do not contain ``://`` in them will not be decoded.
Paul Kehrer31bdf792015-03-25 14:11:00 -0500826
827 .. attribute:: value
828
829 :type: :term:`text`
830
831.. class:: IPAddress
832
833 .. versionadded:: 0.9
834
835 This corresponds to an IP address.
836
837 .. attribute:: value
838
Paul Kehrereb177932015-05-17 18:33:33 -0700839 :type: :class:`~ipaddress.IPv4Address`,
840 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
841 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -0500842
843.. class:: RegisteredID
844
845 .. versionadded:: 0.9
846
847 This corresponds to a registered ID.
848
849 .. attribute:: value
850
851 :type: :class:`ObjectIdentifier`
852
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +0000853.. class:: OtherName
854
855 .. versionadded:: 1.0
856
Joshua Tauberer18b6fc82015-07-05 21:44:51 +0000857 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 +0000858
859 .. attribute:: type_id
860
861 :type: :class:`ObjectIdentifier`
862
863 .. attribute:: value
864
865 :type: `bytes`
866
Paul Kehrer8cf26422015-03-21 09:50:24 -0500867X.509 Extensions
868~~~~~~~~~~~~~~~~
869
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500870.. class:: Extensions
871
872 .. versionadded:: 0.9
873
874 An X.509 Extensions instance is an ordered list of extensions. The object
875 is iterable to get every extension.
876
Paul Kehrerfa56a232015-03-17 13:14:03 -0500877 .. method:: get_extension_for_oid(oid)
878
879 :param oid: An :class:`ObjectIdentifier` instance.
880
881 :returns: An instance of the extension class.
882
883 :raises cryptography.x509.ExtensionNotFound: If the certificate does
884 not have the extension requested.
885
Paul Kehrerfa56a232015-03-17 13:14:03 -0500886 .. doctest::
887
Paul Kehrere27f6582015-08-10 18:33:38 -0500888 >>> from cryptography.x509.oid import ExtensionOID
889 >>> cert.extensions.get_extension_for_oid(ExtensionOID.BASIC_CONSTRAINTS)
Paul Kehrerfa56a232015-03-17 13:14:03 -0500890 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
891
Paul Kehrer8cf26422015-03-21 09:50:24 -0500892.. class:: Extension
893
894 .. versionadded:: 0.9
895
Paul Kehrer85894662015-03-22 13:19:31 -0500896 .. attribute:: oid
897
898 :type: :class:`ObjectIdentifier`
899
Paul Kehrere27f6582015-08-10 18:33:38 -0500900 One of the :class:`~cryptography.x509.oid.ExtensionOID` OIDs.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500901
902 .. attribute:: critical
903
904 :type: bool
905
Paul Kehrer58b75692015-03-22 23:24:58 -0500906 Determines whether a given extension is critical or not. :rfc:`5280`
907 requires that "A certificate-using system MUST reject the certificate
908 if it encounters a critical extension it does not recognize or a
909 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -0500910
Paul Kehrer85894662015-03-22 13:19:31 -0500911 .. attribute:: value
912
913 Returns an instance of the extension type corresponding to the OID.
914
Paul Kehrer14f0bd02015-08-06 11:55:18 +0100915.. class:: ExtensionType
916
917 .. versionadded:: 1.0
918
919 This is the interface against which all the following extension types are
920 registered.
921
Paul Kehrercecbbba2015-03-30 14:58:38 -0500922.. class:: KeyUsage
923
924 .. versionadded:: 0.9
925
926 The key usage extension defines the purpose of the key contained in the
927 certificate. The usage restriction might be employed when a key that could
Paul Kehrerb33de932015-08-06 23:41:05 +0100928 be used for more than one operation is to be restricted.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500929
Paul Kehrer822f3d32015-08-06 11:47:32 +0100930 .. attribute:: oid
931
932 .. versionadded:: 1.0
933
934 :type: :class:`ObjectIdentifier`
935
Paul Kehrere27f6582015-08-10 18:33:38 -0500936 Returns :attr:`~cryptography.x509.oid.ExtensionOID.KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +0100937
Paul Kehrercecbbba2015-03-30 14:58:38 -0500938 .. attribute:: digital_signature
939
940 :type: bool
941
Paul Kehrer738407b2015-04-01 22:39:02 -0500942 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500943 digital signatures, other than signatures on certificates
944 (``key_cert_sign``) and CRLs (``crl_sign``).
945
946 .. attribute:: content_commitment
947
948 :type: bool
949
Paul Kehrer738407b2015-04-01 22:39:02 -0500950 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500951 digital signatures, other than signatures on certificates
952 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
953 non-repudiation service that protects against the signing entity
954 falsely denying some action. In the case of later conflict, a
955 reliable third party may determine the authenticity of the signed
956 data. This was called ``non_repudiation`` in older revisions of the
957 X.509 specification.
958
959 .. attribute:: key_encipherment
960
961 :type: bool
962
Paul Kehrer738407b2015-04-01 22:39:02 -0500963 This purpose is set to true when the subject public key is used for
964 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500965
966 .. attribute:: data_encipherment
967
968 :type: bool
969
Paul Kehrer738407b2015-04-01 22:39:02 -0500970 This purpose is set to true when the subject public key is used for
971 directly enciphering raw user data without the use of an intermediate
972 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500973
974 .. attribute:: key_agreement
975
976 :type: bool
977
Paul Kehrer738407b2015-04-01 22:39:02 -0500978 This purpose is set to true when the subject public key is used for key
979 agreement. For example, when a Diffie-Hellman key is to be used for
980 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500981
982 .. attribute:: key_cert_sign
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 verifying signatures on public key certificates. If this purpose is set
988 to true then ``ca`` must be true in the :class:`BasicConstraints`
989 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500990
991 .. attribute:: crl_sign
992
993 :type: bool
994
Paul Kehrer738407b2015-04-01 22:39:02 -0500995 This purpose is set to true when the subject public key is used for
996 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500997
998 .. attribute:: encipher_only
999
1000 :type: bool
1001
Paul Kehrer738407b2015-04-01 22:39:02 -05001002 When this purposes is set to true and the ``key_agreement`` purpose is
1003 also set, the subject public key may be used only for enciphering data
1004 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001005
1006 :raises ValueError: This is raised if accessed when ``key_agreement``
1007 is false.
1008
1009 .. attribute:: decipher_only
1010
1011 :type: bool
1012
Paul Kehrer738407b2015-04-01 22:39:02 -05001013 When this purposes is set to true and the ``key_agreement`` purpose is
1014 also set, the subject public key may be used only for deciphering data
1015 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001016
1017 :raises ValueError: This is raised if accessed when ``key_agreement``
1018 is false.
1019
1020
Paul Kehrer8cf26422015-03-21 09:50:24 -05001021.. class:: BasicConstraints
1022
1023 .. versionadded:: 0.9
1024
Paul Kehrer85894662015-03-22 13:19:31 -05001025 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -05001026 certificate is allowed to sign additional certificates and what path
Paul Kehrerb33de932015-08-06 23:41:05 +01001027 length restrictions may exist.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001028
Paul Kehrer822f3d32015-08-06 11:47:32 +01001029 .. attribute:: oid
1030
1031 .. versionadded:: 1.0
1032
1033 :type: :class:`ObjectIdentifier`
1034
Paul Kehrere27f6582015-08-10 18:33:38 -05001035 Returns :attr:`~cryptography.x509.oid.ExtensionOID.BASIC_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001036
Paul Kehrer8cf26422015-03-21 09:50:24 -05001037 .. attribute:: ca
1038
1039 :type: bool
1040
1041 Whether the certificate can sign certificates.
1042
1043 .. attribute:: path_length
1044
Paul Kehrerfd1444c2015-03-21 19:47:05 -05001045 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -05001046
1047 The maximum path length for certificates subordinate to this
1048 certificate. This attribute only has meaning if ``ca`` is true.
1049 If ``ca`` is true then a path length of None means there's no
1050 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -04001051 If it is zero or greater then it defines the maximum length for a
1052 subordinate CA's certificate chain. For example, a ``path_length`` of 1
1053 means the certificate can sign a subordinate CA, but the subordinate CA
1054 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -05001055
Paul Kehrerffa2a152015-03-31 08:18:25 -05001056.. class:: ExtendedKeyUsage
1057
1058 .. versionadded:: 0.9
1059
1060 This extension indicates one or more purposes for which the certified
1061 public key may be used, in addition to or in place of the basic
1062 purposes indicated in the key usage extension. The object is
Paul Kehrere27f6582015-08-10 18:33:38 -05001063 iterable to obtain the list of
1064 :class:`~cryptography.x509.oid.ExtendedKeyUsageOID` OIDs present.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001065
Paul Kehrer822f3d32015-08-06 11:47:32 +01001066 .. attribute:: oid
1067
1068 .. versionadded:: 1.0
1069
1070 :type: :class:`ObjectIdentifier`
1071
Paul Kehrere27f6582015-08-10 18:33:38 -05001072 Returns :attr:`~cryptography.x509.oid.ExtensionOID.EXTENDED_KEY_USAGE`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001073
1074
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001075.. class:: OCSPNoCheck
1076
Paul Kehrer506a2152015-05-26 08:01:18 -05001077 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001078
1079 This presence of this extension indicates that an OCSP client can trust a
1080 responder for the lifetime of the responder's certificate. CAs issuing
1081 such a certificate should realize that a compromise of the responder's key
1082 is as serious as the compromise of a CA key used to sign CRLs, at least for
1083 the validity period of this certificate. CA's may choose to issue this type
1084 of certificate with a very short lifetime and renew it frequently. This
1085 extension is only relevant when the certificate is an authorized OCSP
1086 responder.
1087
Paul Kehrer822f3d32015-08-06 11:47:32 +01001088 .. attribute:: oid
1089
1090 .. versionadded:: 1.0
1091
1092 :type: :class:`ObjectIdentifier`
1093
Paul Kehrere27f6582015-08-10 18:33:38 -05001094 Returns :attr:`~cryptography.x509.oid.ExtensionOID.OCSP_NO_CHECK`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001095
Paul Kehrere0017be2015-05-17 20:39:40 -06001096.. class:: NameConstraints
1097
1098 .. versionadded:: 1.0
1099
1100 The name constraints extension, which only has meaning in a CA certificate,
1101 defines a name space within which all subject names in certificates issued
1102 beneath the CA certificate must (or must not) be in. For specific details
1103 on the way this extension should be processed see :rfc:`5280`.
1104
Paul Kehrer822f3d32015-08-06 11:47:32 +01001105 .. attribute:: oid
1106
1107 .. versionadded:: 1.0
1108
1109 :type: :class:`ObjectIdentifier`
1110
Paul Kehrere27f6582015-08-10 18:33:38 -05001111 Returns :attr:`~cryptography.x509.oid.ExtensionOID.NAME_CONSTRAINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001112
Paul Kehrere0017be2015-05-17 20:39:40 -06001113 .. attribute:: permitted_subtrees
1114
1115 :type: list of :class:`GeneralName` objects or None
1116
1117 The set of permitted name patterns. If a name matches this and an
1118 element in ``excluded_subtrees`` it is invalid. At least one of
1119 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
1120
1121 .. attribute:: excluded_subtrees
1122
1123 :type: list of :class:`GeneralName` objects or None
1124
1125 Any name matching a restriction in the ``excluded_subtrees`` field is
1126 invalid regardless of information appearing in the
1127 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
1128 ``excluded_subtrees`` will be non-None.
1129
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001130.. class:: AuthorityKeyIdentifier
1131
1132 .. versionadded:: 0.9
1133
1134 The authority key identifier extension provides a means of identifying the
1135 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001136 This extension is typically used to assist in determining the appropriate
1137 certificate chain. For more information about generation and use of this
1138 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001139
Paul Kehrer822f3d32015-08-06 11:47:32 +01001140 .. attribute:: oid
1141
1142 .. versionadded:: 1.0
1143
1144 :type: :class:`ObjectIdentifier`
1145
Paul Kehrere27f6582015-08-10 18:33:38 -05001146 Returns
1147 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001148
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001149 .. attribute:: key_identifier
1150
1151 :type: bytes
1152
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001153 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001154 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001155
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001156 .. attribute:: authority_cert_issuer
1157
1158 :type: :class:`Name` or None
1159
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001160 The :class:`Name` of the issuer's issuer.
1161
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001162 .. attribute:: authority_cert_serial_number
1163
1164 :type: int or None
1165
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001166 The serial number of the issuer's issuer.
1167
Paul Kehrer253929a2015-08-05 17:30:39 +01001168 .. classmethod:: from_issuer_public_key(public_key)
1169
1170 .. versionadded:: 1.0
1171
1172 Creates a new AuthorityKeyIdentifier instance using the public key
1173 provided to generate the appropriate digest. This should be the
Paul Kehrer26ac47f2015-08-08 15:20:52 -05001174 **issuer's public key**. The resulting object will contain
1175 :attr:`~cryptography.x509.AuthorityKeyIdentifier.key_identifier`, but
1176 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_issuer`
1177 and
1178 :attr:`~cryptography.x509.AuthorityKeyIdentifier.authority_cert_serial_number`
1179 will be None.
1180 The generated ``key_identifier`` is the SHA1 hash of the ``subjectPublicKey``
1181 ASN.1 bit string. This is the first recommendation in :rfc:`5280`
Paul Kehrer253929a2015-08-05 17:30:39 +01001182 section 4.2.1.2.
1183
Paul Kehrercc671822015-08-08 15:41:54 -05001184 :param public_key: One of
1185 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1186 ,
1187 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1188 , or
1189 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
Paul Kehrer253929a2015-08-05 17:30:39 +01001190
1191 .. doctest::
1192
1193 >>> from cryptography import x509
1194 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001195 >>> issuer_cert = x509.load_pem_x509_certificate(pem_data, default_backend())
1196 >>> x509.AuthorityKeyIdentifier.from_issuer_public_key(issuer_cert.public_key())
Paul Kehrer253929a2015-08-05 17:30:39 +01001197 <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)>
1198
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001199.. class:: SubjectKeyIdentifier
1200
1201 .. versionadded:: 0.9
1202
1203 The subject key identifier extension provides a means of identifying
1204 certificates that contain a particular public key.
1205
Paul Kehrer822f3d32015-08-06 11:47:32 +01001206 .. attribute:: oid
1207
1208 .. versionadded:: 1.0
1209
1210 :type: :class:`ObjectIdentifier`
1211
Paul Kehrere27f6582015-08-10 18:33:38 -05001212 Returns
1213 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001214
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001215 .. attribute:: digest
1216
1217 :type: bytes
1218
1219 The binary value of the identifier.
1220
Paul Kehrerd4a7f062015-08-05 18:32:18 +01001221 .. classmethod:: from_public_key(public_key)
Paul Kehrerf22f6122015-08-05 12:57:13 +01001222
1223 .. versionadded:: 1.0
1224
1225 Creates a new SubjectKeyIdentifier instance using the public key
1226 provided to generate the appropriate digest. This should be the public
Paul Kehrereb9ec002015-08-08 10:03:02 -05001227 key that is in the certificate. The generated digest is the SHA1 hash
1228 of the ``subjectPublicKey`` ASN.1 bit string. This is the first
1229 recommendation in :rfc:`5280` section 4.2.1.2.
Paul Kehrerf22f6122015-08-05 12:57:13 +01001230
1231 :param public_key: One of
1232 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey`
1233 ,
1234 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey`
1235 , or
1236 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`.
1237
Paul Kehrer253929a2015-08-05 17:30:39 +01001238 .. doctest::
1239
1240 >>> from cryptography import x509
1241 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc671822015-08-08 15:41:54 -05001242 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
1243 >>> x509.SubjectKeyIdentifier.from_public_key(csr.public_key())
1244 <SubjectKeyIdentifier(digest='\xdb\xaa\xf0\x06\x11\xdbD\xfe\xbf\x93\x03\x8av\x88WP7\xa6\x91\xf7')>
Paul Kehrer253929a2015-08-05 17:30:39 +01001245
Paul Kehrer31bdf792015-03-25 14:11:00 -05001246.. class:: SubjectAlternativeName
1247
1248 .. versionadded:: 0.9
1249
1250 Subject alternative name is an X.509 extension that provides a list of
1251 :ref:`general name <general_name_classes>` instances that provide a set
1252 of identities for which the certificate is valid. The object is iterable to
1253 get every element.
1254
Paul Kehrer822f3d32015-08-06 11:47:32 +01001255 .. attribute:: oid
1256
1257 .. versionadded:: 1.0
1258
1259 :type: :class:`ObjectIdentifier`
1260
Paul Kehrere27f6582015-08-10 18:33:38 -05001261 Returns
1262 :attr:`~cryptography.x509.oid.ExtensionOID.SUBJECT_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001263
Paul Kehrer31bdf792015-03-25 14:11:00 -05001264 .. method:: get_values_for_type(type)
1265
1266 :param type: A :class:`GeneralName` provider. This is one of the
1267 :ref:`general name classes <general_name_classes>`.
1268
1269 :returns: A list of values extracted from the matched general names.
Joshua Taubererd2afad32015-07-06 22:37:53 +00001270 The type of the returned values depends on the :class:`GeneralName`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001271
Paul Kehrer93ae8052015-05-02 23:18:09 -05001272 .. doctest::
1273
1274 >>> from cryptography import x509
1275 >>> from cryptography.hazmat.backends import default_backend
1276 >>> from cryptography.hazmat.primitives import hashes
1277 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001278 >>> # Get the subjectAltName extension from the certificate
Paul Kehrere27f6582015-08-10 18:33:38 -05001279 >>> ext = cert.extensions.get_extension_for_oid(ExtensionOID.SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001280 >>> # Get the dNSName entries from the SAN extension
1281 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer93ae8052015-05-02 23:18:09 -05001282 [u'www.cryptography.io', u'cryptography.io']
1283
Paul Kehrer8cf26422015-03-21 09:50:24 -05001284
Paul Kehrer99125c92015-06-07 18:37:10 -05001285.. class:: IssuerAlternativeName
1286
1287 .. versionadded:: 1.0
1288
1289 Issuer alternative name is an X.509 extension that provides a list of
1290 :ref:`general name <general_name_classes>` instances that provide a set
1291 of identities for the certificate issuer. The object is iterable to
1292 get every element.
1293
Paul Kehrer822f3d32015-08-06 11:47:32 +01001294 .. attribute:: oid
1295
1296 .. versionadded:: 1.0
1297
1298 :type: :class:`ObjectIdentifier`
1299
Paul Kehrere27f6582015-08-10 18:33:38 -05001300 Returns
1301 :attr:`~cryptography.x509.oid.ExtensionOID.ISSUER_ALTERNATIVE_NAME`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001302
Paul Kehrer99125c92015-06-07 18:37:10 -05001303 .. method:: get_values_for_type(type)
1304
1305 :param type: A :class:`GeneralName` provider. This is one of the
1306 :ref:`general name classes <general_name_classes>`.
1307
1308 :returns: A list of values extracted from the matched general names.
1309
1310
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001311.. class:: AuthorityInformationAccess
1312
1313 .. versionadded:: 0.9
1314
1315 The authority information access extension indicates how to access
1316 information and services for the issuer of the certificate in which
1317 the extension appears. Information and services may include online
1318 validation services (such as OCSP) and issuer data. It is an iterable,
Paul Kehrere27f6582015-08-10 18:33:38 -05001319 containing one or more :class:`~cryptography.x509.AccessDescription`
1320 instances.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001321
Paul Kehrer822f3d32015-08-06 11:47:32 +01001322 .. attribute:: oid
1323
1324 .. versionadded:: 1.0
1325
1326 :type: :class:`ObjectIdentifier`
1327
Paul Kehrere27f6582015-08-10 18:33:38 -05001328 Returns
1329 :attr:`~cryptography.x509.oid.ExtensionOID.AUTHORITY_INFORMATION_ACCESS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001330
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001331
1332.. class:: AccessDescription
1333
Paul Kehrer5a485522015-05-06 00:29:12 -05001334 .. versionadded:: 0.9
1335
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001336 .. attribute:: access_method
1337
1338 :type: :class:`ObjectIdentifier`
1339
Paul Kehrerf506bca2015-05-02 22:31:47 -05001340 The access method defines what the ``access_location`` means. It must
Paul Kehrere27f6582015-08-10 18:33:38 -05001341 be either
1342 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP` or
1343 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`.
1344 If it is
1345 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.OCSP`
1346 the access location will be where to obtain OCSP
1347 information for the certificate. If it is
1348 :attr:`~cryptography.x509.oid.AuthorityInformationAccessOID.CA_ISSUERS`
1349 the access location will provide additional information about the
1350 issuing certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001351
1352 .. attribute:: access_location
1353
1354 :type: :class:`GeneralName`
1355
Paul Kehrerf506bca2015-05-02 22:31:47 -05001356 Where to access the information defined by the access method.
1357
Paul Kehrer5a485522015-05-06 00:29:12 -05001358.. class:: CRLDistributionPoints
1359
1360 .. versionadded:: 0.9
1361
1362 The CRL distribution points extension identifies how CRL information is
1363 obtained. It is an iterable, containing one or more
1364 :class:`DistributionPoint` instances.
1365
Paul Kehrer822f3d32015-08-06 11:47:32 +01001366 .. attribute:: oid
1367
1368 .. versionadded:: 1.0
1369
1370 :type: :class:`ObjectIdentifier`
1371
Paul Kehrere27f6582015-08-10 18:33:38 -05001372 Returns
1373 :attr:`~cryptography.x509.oid.ExtensionOID.CRL_DISTRIBUTION_POINTS`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001374
Paul Kehrer5a485522015-05-06 00:29:12 -05001375.. class:: DistributionPoint
1376
1377 .. versionadded:: 0.9
1378
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001379 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05001380
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001381 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001382
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001383 This field describes methods to retrieve the CRL. At most one of
1384 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001385
1386 .. attribute:: relative_name
1387
1388 :type: :class:`Name` or None
1389
1390 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001391 issuer. At most one of ``full_name`` or ``relative_name`` will be
1392 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05001393
1394 .. attribute:: crl_issuer
1395
1396 :type: list of :class:`GeneralName` instances or None
1397
1398 Information about the issuer of the CRL.
1399
1400 .. attribute:: reasons
1401
Paul Kehrer3fd02602015-05-09 19:46:13 -05001402 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001403
1404 The reasons a given distribution point may be used for when performing
1405 revocation checks.
1406
1407.. class:: ReasonFlags
1408
1409 .. versionadded:: 0.9
1410
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001411 An enumeration for CRL reasons.
1412
1413 .. attribute:: unspecified
1414
1415 It is unspecified why the certificate was revoked. This reason cannot
1416 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001417
1418 .. attribute:: key_compromise
1419
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001420 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001421
1422 .. attribute:: ca_compromise
1423
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001424 This reason indicates that the CA issuing the certificate was
1425 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001426
1427 .. attribute:: affiliation_changed
1428
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001429 This reason indicates that the subject's name or other information has
1430 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05001431
1432 .. attribute:: superseded
1433
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001434 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05001435
1436 .. attribute:: cessation_of_operation
1437
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001438 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05001439
1440 .. attribute:: certificate_hold
1441
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001442 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05001443
1444 .. attribute:: privilege_withdrawn
1445
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001446 This reason indicates that the privilege granted by this certificate
1447 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05001448
1449 .. attribute:: aa_compromise
1450
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001451 When an attribute authority has been compromised.
1452
1453 .. attribute:: remove_from_crl
1454
1455 This reason indicates that the certificate was on hold and should be
1456 removed from the CRL. This reason cannot be used as a reason flag
1457 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001458
Paul Kehrer16fae762015-05-01 23:14:20 -05001459.. class:: InhibitAnyPolicy
1460
1461 .. versionadded:: 1.0
1462
1463 The inhibit ``anyPolicy`` extension indicates that the special OID
Paul Kehrere27f6582015-08-10 18:33:38 -05001464 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY`, is not
1465 considered an explicit match for other :class:`CertificatePolicies` except
1466 when it appears in an intermediate self-issued CA certificate. The value
1467 indicates the number of additional non-self-issued certificates that may
1468 appear in the path before
1469 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` is no
1470 longer permitted. For example, a value of one indicates that
1471 :attr:`~cryptography.x509.oid.CertificatePoliciesOID.ANY_POLICY` may be
1472 processed in certificates issued by the subject of this certificate, but
1473 not in additional certificates in the path.
Paul Kehrer16fae762015-05-01 23:14:20 -05001474
Paul Kehrer822f3d32015-08-06 11:47:32 +01001475 .. attribute:: oid
1476
1477 .. versionadded:: 1.0
1478
1479 :type: :class:`ObjectIdentifier`
1480
Paul Kehrere27f6582015-08-10 18:33:38 -05001481 Returns
1482 :attr:`~cryptography.x509.oid.ExtensionOID.INHIBIT_ANY_POLICY`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001483
Paul Kehrer16fae762015-05-01 23:14:20 -05001484 .. attribute:: skip_certs
1485
1486 :type: int
1487
Paul Kehrer0d210922015-04-28 17:31:07 -05001488.. class:: CertificatePolicies
1489
1490 .. versionadded:: 0.9
1491
Paul Kehrer2e879742015-05-02 23:09:56 -05001492 The certificate policies extension is an iterable, containing one or more
1493 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05001494
Paul Kehrer822f3d32015-08-06 11:47:32 +01001495 .. attribute:: oid
1496
1497 .. versionadded:: 1.0
1498
1499 :type: :class:`ObjectIdentifier`
1500
Paul Kehrere27f6582015-08-10 18:33:38 -05001501 Returns
1502 :attr:`~cryptography.x509.oid.ExtensionOID.CERTIFICATE_POLICIES`.
Paul Kehrer822f3d32015-08-06 11:47:32 +01001503
Paul Kehrer0d210922015-04-28 17:31:07 -05001504Certificate Policies Classes
1505~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1506
1507These classes may be present within a :class:`CertificatePolicies` instance.
1508
1509.. class:: PolicyInformation
1510
1511 .. versionadded:: 0.9
1512
1513 Contains a policy identifier and an optional list of qualifiers.
1514
1515 .. attribute:: policy_identifier
1516
1517 :type: :class:`ObjectIdentifier`
1518
1519 .. attribute:: policy_qualifiers
1520
1521 :type: list
1522
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001523 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05001524 If the value is text it is a pointer to the practice statement
1525 published by the certificate authority. If it is a user notice it is
1526 meant for display to the relying party when the certificate is
1527 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05001528
Paul Kehrer0d210922015-04-28 17:31:07 -05001529.. class:: UserNotice
1530
1531 .. versionadded:: 0.9
1532
Paul Kehrer2e879742015-05-02 23:09:56 -05001533 User notices are intended for display to a relying party when a certificate
1534 is used. In practice, few if any UIs expose this data and it is a rarely
1535 encoded component.
1536
Paul Kehrer0d210922015-04-28 17:31:07 -05001537 .. attribute:: notice_reference
1538
1539 :type: :class:`NoticeReference` or None
1540
Paul Kehrer2e879742015-05-02 23:09:56 -05001541 The notice reference field names an organization and identifies,
1542 by number, a particular statement prepared by that organization.
1543
Paul Kehrer0d210922015-04-28 17:31:07 -05001544 .. attribute:: explicit_text
1545
Paul Kehrer2e879742015-05-02 23:09:56 -05001546 This field includes an arbitrary textual statement directly in the
1547 certificate.
1548
Paul Kehrer0d210922015-04-28 17:31:07 -05001549 :type: :term:`text`
1550
1551.. class:: NoticeReference
1552
Paul Kehrer2e879742015-05-02 23:09:56 -05001553 Notice reference can name an organization and provide information about
1554 notices related to the certificate. For example, it might identify the
1555 organization name and notice number 1. Application software could
1556 have a notice file containing the current set of notices for the named
1557 organization; the application would then extract the notice text from the
1558 file and display it. In practice this is rarely seen.
1559
Paul Kehrer0d210922015-04-28 17:31:07 -05001560 .. versionadded:: 0.9
1561
1562 .. attribute:: organization
1563
Paul Kehrer66c61702015-05-12 16:39:18 -05001564 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05001565
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05001566 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05001567
Paul Kehrer66c61702015-05-12 16:39:18 -05001568 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05001569
Paul Kehrer66c61702015-05-12 16:39:18 -05001570 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05001571
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001572Object Identifiers
1573~~~~~~~~~~~~~~~~~~
1574
Paul Kehrer4bb46492015-02-07 16:59:14 -06001575X.509 elements are frequently identified by :class:`ObjectIdentifier`
1576instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001577
Paul Kehrere27f6582015-08-10 18:33:38 -05001578.. currentmodule:: cryptography.x509.oid
Paul Kehrer56da2a52015-02-11 23:35:07 -06001579
Paul Kehrere27f6582015-08-10 18:33:38 -05001580.. class:: NameOID
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001581
Paul Kehrere27f6582015-08-10 18:33:38 -05001582 These OIDs are typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001583
Paul Kehrere27f6582015-08-10 18:33:38 -05001584 .. versionadded:: 1.0
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001585
Paul Kehrere27f6582015-08-10 18:33:38 -05001586 .. attribute:: COMMON_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001587
Paul Kehrere27f6582015-08-10 18:33:38 -05001588 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
1589 name would be encoded here for server certificates. :rfc:`2818`
1590 deprecates this practice and names of that type should now be located
1591 in a :class:`~cryptography.x509.SubjectAlternativeName` extension.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001592
Paul Kehrere27f6582015-08-10 18:33:38 -05001593 .. attribute:: COUNTRY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001594
Paul Kehrere27f6582015-08-10 18:33:38 -05001595 Corresponds to the dotted string ``"2.5.4.6"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001596
Paul Kehrere27f6582015-08-10 18:33:38 -05001597 .. attribute:: LOCALITY_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001598
Paul Kehrere27f6582015-08-10 18:33:38 -05001599 Corresponds to the dotted string ``"2.5.4.7"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001600
Paul Kehrere27f6582015-08-10 18:33:38 -05001601 .. attribute:: STATE_OR_PROVINCE_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001602
Paul Kehrere27f6582015-08-10 18:33:38 -05001603 Corresponds to the dotted string ``"2.5.4.8"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001604
Paul Kehrere27f6582015-08-10 18:33:38 -05001605 .. attribute:: ORGANIZATION_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001606
Paul Kehrere27f6582015-08-10 18:33:38 -05001607 Corresponds to the dotted string ``"2.5.4.10"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001608
Paul Kehrere27f6582015-08-10 18:33:38 -05001609 .. attribute:: ORGANIZATIONAL_UNIT_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.11"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001612
Paul Kehrere27f6582015-08-10 18:33:38 -05001613 .. attribute:: SERIAL_NUMBER
Paul Kehrer858b9b72015-02-05 09:50:31 -06001614
Paul Kehrere27f6582015-08-10 18:33:38 -05001615 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from
1616 the serial number of the certificate itself (which can be obtained with
1617 :func:`~cryptography.x509.Certificate.serial`).
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001618
Paul Kehrere27f6582015-08-10 18:33:38 -05001619 .. attribute:: SURNAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001620
Paul Kehrere27f6582015-08-10 18:33:38 -05001621 Corresponds to the dotted string ``"2.5.4.4"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001622
Paul Kehrere27f6582015-08-10 18:33:38 -05001623 .. attribute:: GIVEN_NAME
Paul Kehrer858b9b72015-02-05 09:50:31 -06001624
Paul Kehrere27f6582015-08-10 18:33:38 -05001625 Corresponds to the dotted string ``"2.5.4.42"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001626
Paul Kehrere27f6582015-08-10 18:33:38 -05001627 .. attribute:: TITLE
Paul Kehrer858b9b72015-02-05 09:50:31 -06001628
Paul Kehrere27f6582015-08-10 18:33:38 -05001629 Corresponds to the dotted string ``"2.5.4.12"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001630
Paul Kehrere27f6582015-08-10 18:33:38 -05001631 .. attribute:: GENERATION_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06001632
Paul Kehrere27f6582015-08-10 18:33:38 -05001633 Corresponds to the dotted string ``"2.5.4.44"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001634
Paul Kehrere27f6582015-08-10 18:33:38 -05001635 .. attribute:: DN_QUALIFIER
Paul Kehrer858b9b72015-02-05 09:50:31 -06001636
Paul Kehrere27f6582015-08-10 18:33:38 -05001637 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
1638 disambiguating information to add to the relative distinguished name of an
1639 entry. See :rfc:`2256`.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001640
Paul Kehrere27f6582015-08-10 18:33:38 -05001641 .. attribute:: PSEUDONYM
Paul Kehrer858b9b72015-02-05 09:50:31 -06001642
Paul Kehrere27f6582015-08-10 18:33:38 -05001643 Corresponds to the dotted string ``"2.5.4.65"``.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001644
Paul Kehrere27f6582015-08-10 18:33:38 -05001645 .. attribute:: DOMAIN_COMPONENT
Paul Kehrer858b9b72015-02-05 09:50:31 -06001646
Paul Kehrere27f6582015-08-10 18:33:38 -05001647 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
1648 holding one component of a domain name. See :rfc:`4519`.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001649
Paul Kehrere27f6582015-08-10 18:33:38 -05001650 .. attribute:: EMAIL_ADDRESS
Paul Kehrer56da2a52015-02-11 23:35:07 -06001651
Paul Kehrere27f6582015-08-10 18:33:38 -05001652 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001653
Paul Kehrer56da2a52015-02-11 23:35:07 -06001654
Paul Kehrere27f6582015-08-10 18:33:38 -05001655.. class:: SignatureAlgorithmOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06001656
Paul Kehrere27f6582015-08-10 18:33:38 -05001657 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06001658
Paul Kehrere27f6582015-08-10 18:33:38 -05001659 .. attribute:: RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06001660
Paul Kehrere27f6582015-08-10 18:33:38 -05001661 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
1662 an MD5 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001663
Paul Kehrere27f6582015-08-10 18:33:38 -05001664 .. attribute:: RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06001665
Paul Kehrere27f6582015-08-10 18:33:38 -05001666 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
1667 a SHA1 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001668
Paul Kehrere27f6582015-08-10 18:33:38 -05001669 .. attribute:: RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06001670
Paul Kehrere27f6582015-08-10 18:33:38 -05001671 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
1672 a SHA224 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001673
Paul Kehrere27f6582015-08-10 18:33:38 -05001674 .. attribute:: RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06001675
Paul Kehrere27f6582015-08-10 18:33:38 -05001676 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
1677 a SHA256 digest signed by an RSA key.
Alex Gaynor3aadabf2015-06-23 22:06:21 -04001678
Paul Kehrere27f6582015-08-10 18:33:38 -05001679 .. attribute:: RSA_WITH_SHA384
Alex Gaynor3aadabf2015-06-23 22:06:21 -04001680
Paul Kehrere27f6582015-08-10 18:33:38 -05001681 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
1682 a SHA384 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001683
Paul Kehrere27f6582015-08-10 18:33:38 -05001684 .. attribute:: RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06001685
Paul Kehrere27f6582015-08-10 18:33:38 -05001686 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
1687 a SHA512 digest signed by an RSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001688
Paul Kehrere27f6582015-08-10 18:33:38 -05001689 .. attribute:: ECDSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06001690
Paul Kehrere27f6582015-08-10 18:33:38 -05001691 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
1692 digest signed by an ECDSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001693
Paul Kehrere27f6582015-08-10 18:33:38 -05001694 .. attribute:: ECDSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06001695
Paul Kehrere27f6582015-08-10 18:33:38 -05001696 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
1697 a SHA224 digest signed by an ECDSA key.
1698
1699 .. attribute:: ECDSA_WITH_SHA256
1700
1701 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
1702 a SHA256 digest signed by an ECDSA key.
1703
1704 .. attribute:: ECDSA_WITH_SHA384
1705
1706 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
1707 a SHA384 digest signed by an ECDSA key.
1708
1709 .. attribute:: ECDSA_WITH_SHA512
1710
1711 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
1712 a SHA512 digest signed by an ECDSA key.
1713
1714 .. attribute:: DSA_WITH_SHA1
1715
1716 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
1717 a SHA1 digest signed by a DSA key.
1718
1719 .. attribute:: DSA_WITH_SHA224
1720
1721 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
1722 a SHA224 digest signed by a DSA key.
1723
1724 .. attribute:: DSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06001725
Paul Kehrere27f6582015-08-10 18:33:38 -05001726 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
1727 a SHA256 digest signed by a DSA key.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001728
Paul Kehrer56da2a52015-02-11 23:35:07 -06001729
Paul Kehrere27f6582015-08-10 18:33:38 -05001730.. class:: ExtendedKeyUsageOID
Paul Kehrer56da2a52015-02-11 23:35:07 -06001731
Paul Kehrere27f6582015-08-10 18:33:38 -05001732 .. versionadded:: 1.0
Paul Kehrer56da2a52015-02-11 23:35:07 -06001733
Paul Kehrere27f6582015-08-10 18:33:38 -05001734 .. attribute:: SERVER_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06001735
Paul Kehrere27f6582015-08-10 18:33:38 -05001736 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used
1737 to denote that a certificate may be used for TLS web server
1738 authentication.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001739
Paul Kehrere27f6582015-08-10 18:33:38 -05001740 .. attribute:: CLIENT_AUTH
Paul Kehrer56da2a52015-02-11 23:35:07 -06001741
Paul Kehrere27f6582015-08-10 18:33:38 -05001742 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used
1743 to denote that a certificate may be used for TLS web client
1744 authentication.
Paul Kehrerffa2a152015-03-31 08:18:25 -05001745
Paul Kehrere27f6582015-08-10 18:33:38 -05001746 .. attribute:: CODE_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05001747
Paul Kehrere27f6582015-08-10 18:33:38 -05001748 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used
1749 to denote that a certificate may be used for code signing.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001750
Paul Kehrere27f6582015-08-10 18:33:38 -05001751 .. attribute:: EMAIL_PROTECTION
Paul Kehrere1513fa2015-03-30 23:08:17 -05001752
Paul Kehrere27f6582015-08-10 18:33:38 -05001753 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used
1754 to denote that a certificate may be used for email protection.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001755
Paul Kehrere27f6582015-08-10 18:33:38 -05001756 .. attribute:: TIME_STAMPING
Paul Kehrere1513fa2015-03-30 23:08:17 -05001757
Paul Kehrere27f6582015-08-10 18:33:38 -05001758 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used
1759 to denote that a certificate may be used for time stamping.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001760
Paul Kehrere27f6582015-08-10 18:33:38 -05001761 .. attribute:: OCSP_SIGNING
Paul Kehrere1513fa2015-03-30 23:08:17 -05001762
Paul Kehrere27f6582015-08-10 18:33:38 -05001763 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used
1764 to denote that a certificate may be used for signing OCSP responses.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001765
Paul Kehrere1513fa2015-03-30 23:08:17 -05001766
Paul Kehrere27f6582015-08-10 18:33:38 -05001767.. class:: AuthorityInformationAccessOID
Paul Kehrere1513fa2015-03-30 23:08:17 -05001768
Paul Kehrere27f6582015-08-10 18:33:38 -05001769 .. versionadded:: 1.0
Paul Kehrere1513fa2015-03-30 23:08:17 -05001770
Paul Kehrere27f6582015-08-10 18:33:38 -05001771 .. attribute:: OCSP
Paul Kehrere1513fa2015-03-30 23:08:17 -05001772
Paul Kehrere27f6582015-08-10 18:33:38 -05001773 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
1774 identifier for OCSP data in
1775 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrere1513fa2015-03-30 23:08:17 -05001776
Paul Kehrere27f6582015-08-10 18:33:38 -05001777 .. attribute:: CA_ISSUERS
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001778
Paul Kehrere27f6582015-08-10 18:33:38 -05001779 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
1780 identifier for CA issuer data in
1781 :class:`~cryptography.x509.AccessDescription` objects.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001782
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001783
Paul Kehrere27f6582015-08-10 18:33:38 -05001784.. class:: CertificatePoliciesOID
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001785
Paul Kehrere27f6582015-08-10 18:33:38 -05001786 .. versionadded:: 1.0
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001787
Paul Kehrere27f6582015-08-10 18:33:38 -05001788 .. attribute:: CPS_QUALIFIER
Paul Kehrer2e879742015-05-02 23:09:56 -05001789
Paul Kehrere27f6582015-08-10 18:33:38 -05001790 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05001791
Paul Kehrere27f6582015-08-10 18:33:38 -05001792 .. attribute:: CPS_USER_NOTICE
Paul Kehrer2e879742015-05-02 23:09:56 -05001793
Paul Kehrere27f6582015-08-10 18:33:38 -05001794 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05001795
Paul Kehrere27f6582015-08-10 18:33:38 -05001796 .. attribute:: ANY_POLICY
Paul Kehrer2e879742015-05-02 23:09:56 -05001797
Paul Kehrere27f6582015-08-10 18:33:38 -05001798 Corresponds to the dotted string ``"2.5.29.32.0"``.
Paul Kehrer16fae762015-05-01 23:14:20 -05001799
Paul Kehrer16fae762015-05-01 23:14:20 -05001800
Paul Kehrere27f6582015-08-10 18:33:38 -05001801.. class:: ExtensionOID
Paul Kehrer5553d572015-03-23 21:08:01 -05001802
Paul Kehrere27f6582015-08-10 18:33:38 -05001803 .. versionadded:: 1.0
Paul Kehrer2bb94642015-03-21 09:54:17 -05001804
Paul Kehrere27f6582015-08-10 18:33:38 -05001805 .. attribute:: BASIC_CONSTRAINTS
Paul Kehrer2bb94642015-03-21 09:54:17 -05001806
Paul Kehrere27f6582015-08-10 18:33:38 -05001807 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
1808 :class:`~cryptography.x509.BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05001809
Paul Kehrere27f6582015-08-10 18:33:38 -05001810 .. attribute:: KEY_USAGE
Paul Kehrercecbbba2015-03-30 14:58:38 -05001811
Paul Kehrere27f6582015-08-10 18:33:38 -05001812 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
1813 :class:`~cryptography.x509.KeyUsage` extension type.
Paul Kehrercecbbba2015-03-30 14:58:38 -05001814
Paul Kehrere27f6582015-08-10 18:33:38 -05001815 .. attribute:: SUBJECT_ALTERNATIVE_NAME
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001816
Paul Kehrere27f6582015-08-10 18:33:38 -05001817 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
1818 :class:`~cryptography.x509.SubjectAlternativeName` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001819
Paul Kehrere27f6582015-08-10 18:33:38 -05001820 .. attribute:: ISSUER_ALTERNATIVE_NAME
Paul Kehrer99125c92015-06-07 18:37:10 -05001821
Paul Kehrere27f6582015-08-10 18:33:38 -05001822 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
1823 :class:`~cryptography.x509.IssuerAlternativeName` extension type.
Paul Kehrer99125c92015-06-07 18:37:10 -05001824
Paul Kehrere27f6582015-08-10 18:33:38 -05001825 .. attribute:: SUBJECT_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001826
Paul Kehrere27f6582015-08-10 18:33:38 -05001827 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
1828 :class:`~cryptography.x509.SubjectKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001829
Paul Kehrere27f6582015-08-10 18:33:38 -05001830 .. attribute:: NAME_CONSTRAINTS
Paul Kehrere0017be2015-05-17 20:39:40 -06001831
Paul Kehrere27f6582015-08-10 18:33:38 -05001832 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
1833 :class:`~cryptography.x509.NameConstraints` extension type.
Paul Kehrere0017be2015-05-17 20:39:40 -06001834
Paul Kehrere27f6582015-08-10 18:33:38 -05001835 .. attribute:: CRL_DISTRIBUTION_POINTS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001836
Paul Kehrere27f6582015-08-10 18:33:38 -05001837 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
1838 :class:`~cryptography.x509.CRLDistributionPoints` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001839
Paul Kehrere27f6582015-08-10 18:33:38 -05001840 .. attribute:: CERTIFICATE_POLICIES
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001841
Paul Kehrere27f6582015-08-10 18:33:38 -05001842 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
1843 :class:`~cryptography.x509.CertificatePolicies` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001844
Paul Kehrere27f6582015-08-10 18:33:38 -05001845 .. attribute:: AUTHORITY_KEY_IDENTIFIER
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001846
Paul Kehrere27f6582015-08-10 18:33:38 -05001847 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
1848 :class:`~cryptography.x509.AuthorityKeyIdentifier` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001849
Paul Kehrere27f6582015-08-10 18:33:38 -05001850 .. attribute:: EXTENDED_KEY_USAGE
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001851
Paul Kehrere27f6582015-08-10 18:33:38 -05001852 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
1853 :class:`~cryptography.x509.ExtendedKeyUsage` extension type.
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001854
Paul Kehrere27f6582015-08-10 18:33:38 -05001855 .. attribute:: AUTHORITY_INFORMATION_ACCESS
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001856
Paul Kehrere27f6582015-08-10 18:33:38 -05001857 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
1858 for the :class:`~cryptography.x509.AuthorityInformationAccess` extension
1859 type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001860
Paul Kehrere27f6582015-08-10 18:33:38 -05001861 .. attribute:: INHIBIT_ANY_POLICY
Paul Kehrerb33de932015-08-06 23:41:05 +01001862
Paul Kehrere27f6582015-08-10 18:33:38 -05001863 Corresponds to the dotted string ``"2.5.29.54"``. The identifier
1864 for the :class:`~cryptography.x509.InhibitAnyPolicy` extension type.
Paul Kehrerb33de932015-08-06 23:41:05 +01001865
Paul Kehrere27f6582015-08-10 18:33:38 -05001866 .. attribute:: OCSP_NO_CHECK
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001867
Paul Kehrere27f6582015-08-10 18:33:38 -05001868 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The
1869 identifier for the :class:`~cryptography.x509.OCSPNoCheck` extension
1870 type.
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001871
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001872Exceptions
1873~~~~~~~~~~
Paul Kehrere27f6582015-08-10 18:33:38 -05001874.. currentmodule:: cryptography.x509
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001875
Paul Kehrere76cd272014-12-14 19:00:51 -06001876.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10001877
1878 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10001879
Paul Kehrerd5cccf72014-12-15 17:20:33 -06001880 .. attribute:: parsed_version
1881
Paul Kehrerbbffc402014-12-17 13:33:55 -06001882 :type: int
1883
1884 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06001885
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001886.. class:: DuplicateExtension
1887
1888 This is raised when more than one X.509 extension of the same type is
1889 found within a certificate.
1890
1891 .. attribute:: oid
1892
1893 :type: :class:`ObjectIdentifier`
1894
1895 Returns the OID.
1896
1897.. class:: UnsupportedExtension
1898
1899 This is raised when a certificate contains an unsupported extension type.
1900
1901 .. attribute:: oid
1902
1903 :type: :class:`ObjectIdentifier`
1904
1905 Returns the OID.
1906
Paul Kehrerfa56a232015-03-17 13:14:03 -05001907.. class:: ExtensionNotFound
1908
1909 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
1910 an extension OID that is not present in the certificate.
1911
1912 .. attribute:: oid
1913
1914 :type: :class:`ObjectIdentifier`
1915
1916 Returns the OID.
1917
Paul Kehrer9089c912015-04-20 22:15:20 -05001918.. class:: UnsupportedGeneralNameType
1919
1920 This is raised when a certificate contains an unsupported general name
1921 type in an extension.
1922
Paul Kehrerbed07352015-04-21 08:31:10 -05001923 .. attribute:: type
1924
Paul Kehrer0a621bf2015-04-22 09:22:56 -05001925 :type: int
1926
1927 The integer value of the unsupported type. The complete list of
1928 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05001929
Paul Kehrer016e08a2014-11-26 09:41:18 -10001930
Paul Kehrerc7c9a432015-04-19 09:20:13 -05001931.. _`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 -05001932.. _`RFC 5280 section 4.2.1.6`: https://tools.ietf.org/html/rfc5280#section-4.2.1.6