blob: c7d45c77cb2105d27825d853ff11e7a756785587 [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
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500391X.509 CSR (Certificate Signing Request) Object
392~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600393
Paul Kehrera1a1f232015-03-15 15:34:35 -0500394.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600395
396 .. versionadded:: 0.9
397
398 .. method:: public_key()
399
400 :type:
401 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
402 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
403 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
404
405 The public key associated with the request.
406
407 .. doctest::
408
409 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500410 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600411 >>> isinstance(public_key, rsa.RSAPublicKey)
412 True
413
414 .. attribute:: subject
415
416 :type: :class:`Name`
417
418 The :class:`Name` of the subject.
419
420 .. attribute:: signature_hash_algorithm
421
422 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
423
424 Returns the
425 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
426 was used in signing this request.
427
428 .. doctest::
429
430 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500431 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600432 True
433
Paul Kehrerc4e61942015-08-01 21:21:13 +0100434 .. attribute:: extensions
435
436 :type: :class:`Extensions`
437
438 The extensions encoded in the certificate signing request.
439
440 :raises cryptography.x509.DuplicateExtension: If more than one
Paul Kehrer24283d22015-08-01 21:31:19 +0100441 extension of the same type is found within the certificate signing request.
Paul Kehrerc4e61942015-08-01 21:21:13 +0100442
Paul Kehrer24283d22015-08-01 21:31:19 +0100443 :raises cryptography.x509.UnsupportedExtension: If the certificate signing request
Paul Kehrerc4e61942015-08-01 21:21:13 +0100444 contains an extension that is not supported.
445
446 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
447 contains a general name that is not supported.
448
449 :raises UnicodeError: If an extension contains IDNA encoding that is
450 invalid or not compliant with IDNA 2008.
451
452
Andre Caron476c5df2015-05-18 10:23:28 -0400453 .. method:: public_bytes(encoding)
454
Alex Gaynord0b376b2015-07-05 13:58:12 -0400455 .. versionadded:: 1.0
456
Andre Caron476c5df2015-05-18 10:23:28 -0400457 :param encoding: The
458 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
459 that will be used to serialize the certificate request.
460
461 :return bytes: The data that can be written to a file or sent
462 over the network to be signed by the certificate
463 authority.
464
Erik Trauschke2dcce902015-05-14 16:12:24 -0700465X.509 Revoked Certificate Object
Erik Trauschkec5a8d172015-05-28 10:24:25 -0700466~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Erik Trauschke2dcce902015-05-14 16:12:24 -0700467
468.. class:: RevokedCertificate
469
470 .. versionadded:: 1.0
471
472 .. attribute:: serial_number
473
474 :type: :class:`int`
475
476 An integer representing the serial number of the revoked certificate.
477
478 .. attribute:: revocation_date
479
480 :type: :class:`datetime.datetime`
481
482 A naïve datetime representing the date this certificates was revoked.
483
484 .. attribute:: extensions
485
486 :type: :class:`Extensions`
487
488 The extensions encoded in the revoked certificate.
Andre Caron476c5df2015-05-18 10:23:28 -0400489
Andre Caron0ef595f2015-05-18 13:53:43 -0400490X.509 CSR (Certificate Signing Request) Builder Object
491~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
492
493.. class:: CertificateSigningRequestBuilder
494
Andre Carond259ee52015-06-02 23:47:11 -0400495 .. versionadded:: 1.0
496
497 .. doctest::
498
499 >>> from cryptography import x509
500 >>> from cryptography.hazmat.backends import default_backend
501 >>> from cryptography.hazmat.primitives import hashes
502 >>> from cryptography.hazmat.primitives.asymmetric import rsa
503 >>> private_key = rsa.generate_private_key(
504 ... public_exponent=65537,
505 ... key_size=2048,
506 ... backend=default_backend()
507 ... )
508 >>> builder = x509.CertificateSigningRequestBuilder()
Andre Carona9a51172015-06-06 20:18:44 -0400509 >>> builder = builder.subject_name(x509.Name([
Ian Cordasco4d46eb72015-06-17 12:08:27 -0500510 ... x509.NameAttribute(x509.OID_COMMON_NAME, u'cryptography.io'),
Andre Carond259ee52015-06-02 23:47:11 -0400511 ... ]))
Ian Cordascof06b6be2015-06-21 10:09:18 -0500512 >>> builder = builder.add_extension(
Ian Cordasco0112b022015-06-16 17:51:18 -0500513 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
Andre Caron472fd692015-06-06 20:04:44 -0400514 ... )
Andre Carond259ee52015-06-02 23:47:11 -0400515 >>> request = builder.sign(
Alex Gaynorde9e5842015-06-26 20:11:23 -0400516 ... private_key, hashes.SHA256(), default_backend()
Andre Carond259ee52015-06-02 23:47:11 -0400517 ... )
518 >>> isinstance(request, x509.CertificateSigningRequest)
519 True
520
Andre Carona9a51172015-06-06 20:18:44 -0400521 .. method:: subject_name(name)
Andre Caron0ef595f2015-05-18 13:53:43 -0400522
Andre Caron341ff852015-06-06 20:14:31 -0400523 :param name: The :class:`~cryptography.x509.Name` of the certificate
524 subject.
525 :returns: A new
526 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400527
Ian Cordascof06b6be2015-06-21 10:09:18 -0500528 .. method:: add_extension(extension, critical)
Andre Caron0ef595f2015-05-18 13:53:43 -0400529
Andre Caron341ff852015-06-06 20:14:31 -0400530 :param extension: The :class:`~cryptography.x509.Extension` to add to
531 the request.
Andre Caron472fd692015-06-06 20:04:44 -0400532 :param critical: Set to `True` if the extension must be understood and
533 handled by whoever reads the certificate.
Andre Caron341ff852015-06-06 20:14:31 -0400534 :returns: A new
535 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400536
Alex Gaynorb3b0fbe2015-06-26 19:57:18 -0400537 .. method:: sign(private_key, algorithm, backend)
Andre Caron0ef595f2015-05-18 13:53:43 -0400538
539 :param backend: Backend that will be used to sign the request.
540 Must support the
541 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
542 interface.
543
544 :param private_key: The
Andre Caron24f9bf42015-06-06 20:14:54 -0400545 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
546 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
547 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
Andre Caron0ef595f2015-05-18 13:53:43 -0400548 that will be used to sign the request. When the request is
549 signed by a certificate authority, the private key's associated
550 public key will be stored in the resulting certificate.
551
552 :param algorithm: The
553 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
554 that will be used to generate the request signature.
555
Andre Caron341ff852015-06-06 20:14:31 -0400556 :returns: A new
557 :class:`~cryptography.x509.CertificateSigningRequest`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400558
559
Paul Kehrer719d5362015-01-01 20:03:52 -0600560.. class:: Name
561
562 .. versionadded:: 0.8
563
Paul Kehrer53d8d492015-02-13 18:47:30 -0600564 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -0600565 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -0600566 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -0600567 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
568 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -0600569
Paul Kehrer53d8d492015-02-13 18:47:30 -0600570 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -0600571
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600572 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -0600573 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600574 >>> for attribute in cert.subject:
575 ... print(attribute)
576 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
577 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')>
578 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -0600579
Paul Kehrere901d642015-02-11 18:50:58 -0600580 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -0600581
Paul Kehrere901d642015-02-11 18:50:58 -0600582 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -0600583
Paul Kehrere901d642015-02-11 18:50:58 -0600584 :returns: A list of :class:`NameAttribute` instances that match the
585 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -0600586
587 .. doctest::
588
Paul Kehrere901d642015-02-11 18:50:58 -0600589 >>> cert.subject.get_attributes_for_oid(x509.OID_COMMON_NAME)
590 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -0600591
Paul Kehrere76cd272014-12-14 19:00:51 -0600592.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -1000593
594 .. versionadded:: 0.7
595
596 An enumeration for X.509 versions.
597
598 .. attribute:: v1
599
600 For version 1 X.509 certificates.
601
602 .. attribute:: v3
603
604 For version 3 X.509 certificates.
605
Paul Kehrer806bfb22015-02-02 17:05:24 -0600606.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600607
608 .. versionadded:: 0.8
609
Paul Kehrer834d22f2015-02-06 11:01:07 -0600610 An X.509 name consists of a list of NameAttribute instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600611
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600612 .. attribute:: oid
613
614 :type: :class:`ObjectIdentifier`
615
616 The attribute OID.
617
618 .. attribute:: value
619
Paul Kehrerd5852cb2015-01-30 08:25:23 -0600620 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600621
622 The value of the attribute.
623
624.. class:: ObjectIdentifier
625
626 .. versionadded:: 0.8
627
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600628 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -0600629 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600630
Paul Kehrerd44f9a62015-02-04 14:47:34 -0600631 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600632
633 :type: :class:`str`
634
Paul Kehrerfedf4f42015-02-06 11:22:07 -0600635 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600636
Paul Kehrer31bdf792015-03-25 14:11:00 -0500637.. _general_name_classes:
638
639General Name Classes
640~~~~~~~~~~~~~~~~~~~~
641
642.. class:: GeneralName
643
644 .. versionadded:: 0.9
645
646 This is the generic interface that all the following classes are registered
647 against.
648
649.. class:: RFC822Name
650
651 .. versionadded:: 0.9
652
653 This corresponds to an email address. For example, ``user@example.com``.
654
655 .. attribute:: value
656
657 :type: :term:`text`
658
659.. class:: DNSName
660
661 .. versionadded:: 0.9
662
663 This corresponds to a domain name. For example, ``cryptography.io``.
664
665 .. attribute:: value
666
667 :type: :term:`text`
668
669.. class:: DirectoryName
670
671 .. versionadded:: 0.9
672
673 This corresponds to a directory name.
674
675 .. attribute:: value
676
677 :type: :class:`Name`
678
679.. class:: UniformResourceIdentifier
680
681 .. versionadded:: 0.9
682
683 This corresponds to a uniform resource identifier. For example,
Paul Kehrerb8ef82e2015-04-22 16:04:24 -0500684 ``https://cryptography.io``. The URI is parsed and IDNA decoded (see
685 :rfc:`5895`).
686
687 .. note::
688
689 URIs that do not contain ``://`` in them will not be decoded.
Paul Kehrer31bdf792015-03-25 14:11:00 -0500690
691 .. attribute:: value
692
693 :type: :term:`text`
694
695.. class:: IPAddress
696
697 .. versionadded:: 0.9
698
699 This corresponds to an IP address.
700
701 .. attribute:: value
702
Paul Kehrereb177932015-05-17 18:33:33 -0700703 :type: :class:`~ipaddress.IPv4Address`,
704 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
705 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -0500706
707.. class:: RegisteredID
708
709 .. versionadded:: 0.9
710
711 This corresponds to a registered ID.
712
713 .. attribute:: value
714
715 :type: :class:`ObjectIdentifier`
716
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +0000717.. class:: OtherName
718
719 .. versionadded:: 1.0
720
Joshua Tauberer18b6fc82015-07-05 21:44:51 +0000721 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 +0000722
723 .. attribute:: type_id
724
725 :type: :class:`ObjectIdentifier`
726
727 .. attribute:: value
728
729 :type: `bytes`
730
Paul Kehrer8cf26422015-03-21 09:50:24 -0500731X.509 Extensions
732~~~~~~~~~~~~~~~~
733
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500734.. class:: Extensions
735
736 .. versionadded:: 0.9
737
738 An X.509 Extensions instance is an ordered list of extensions. The object
739 is iterable to get every extension.
740
Paul Kehrerfa56a232015-03-17 13:14:03 -0500741 .. method:: get_extension_for_oid(oid)
742
743 :param oid: An :class:`ObjectIdentifier` instance.
744
745 :returns: An instance of the extension class.
746
747 :raises cryptography.x509.ExtensionNotFound: If the certificate does
748 not have the extension requested.
749
Paul Kehrerfa56a232015-03-17 13:14:03 -0500750 .. doctest::
751
752 >>> cert.extensions.get_extension_for_oid(x509.OID_BASIC_CONSTRAINTS)
753 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
754
Paul Kehrer8cf26422015-03-21 09:50:24 -0500755.. class:: Extension
756
757 .. versionadded:: 0.9
758
Paul Kehrer85894662015-03-22 13:19:31 -0500759 .. attribute:: oid
760
761 :type: :class:`ObjectIdentifier`
762
Paul Kehrer5553d572015-03-23 21:08:01 -0500763 The :ref:`extension OID <extension_oids>`.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500764
765 .. attribute:: critical
766
767 :type: bool
768
Paul Kehrer58b75692015-03-22 23:24:58 -0500769 Determines whether a given extension is critical or not. :rfc:`5280`
770 requires that "A certificate-using system MUST reject the certificate
771 if it encounters a critical extension it does not recognize or a
772 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -0500773
Paul Kehrer85894662015-03-22 13:19:31 -0500774 .. attribute:: value
775
776 Returns an instance of the extension type corresponding to the OID.
777
Paul Kehrercecbbba2015-03-30 14:58:38 -0500778.. class:: KeyUsage
779
780 .. versionadded:: 0.9
781
782 The key usage extension defines the purpose of the key contained in the
783 certificate. The usage restriction might be employed when a key that could
784 be used for more than one operation is to be restricted. It corresponds to
785 :data:`OID_KEY_USAGE`.
786
787 .. attribute:: digital_signature
788
789 :type: bool
790
Paul Kehrer738407b2015-04-01 22:39:02 -0500791 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500792 digital signatures, other than signatures on certificates
793 (``key_cert_sign``) and CRLs (``crl_sign``).
794
795 .. attribute:: content_commitment
796
797 :type: bool
798
Paul Kehrer738407b2015-04-01 22:39:02 -0500799 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500800 digital signatures, other than signatures on certificates
801 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
802 non-repudiation service that protects against the signing entity
803 falsely denying some action. In the case of later conflict, a
804 reliable third party may determine the authenticity of the signed
805 data. This was called ``non_repudiation`` in older revisions of the
806 X.509 specification.
807
808 .. attribute:: key_encipherment
809
810 :type: bool
811
Paul Kehrer738407b2015-04-01 22:39:02 -0500812 This purpose is set to true when the subject public key is used for
813 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500814
815 .. attribute:: data_encipherment
816
817 :type: bool
818
Paul Kehrer738407b2015-04-01 22:39:02 -0500819 This purpose is set to true when the subject public key is used for
820 directly enciphering raw user data without the use of an intermediate
821 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500822
823 .. attribute:: key_agreement
824
825 :type: bool
826
Paul Kehrer738407b2015-04-01 22:39:02 -0500827 This purpose is set to true when the subject public key is used for key
828 agreement. For example, when a Diffie-Hellman key is to be used for
829 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500830
831 .. attribute:: key_cert_sign
832
833 :type: bool
834
Paul Kehrer738407b2015-04-01 22:39:02 -0500835 This purpose is set to true when the subject public key is used for
836 verifying signatures on public key certificates. If this purpose is set
837 to true then ``ca`` must be true in the :class:`BasicConstraints`
838 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500839
840 .. attribute:: crl_sign
841
842 :type: bool
843
Paul Kehrer738407b2015-04-01 22:39:02 -0500844 This purpose is set to true when the subject public key is used for
845 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500846
847 .. attribute:: encipher_only
848
849 :type: bool
850
Paul Kehrer738407b2015-04-01 22:39:02 -0500851 When this purposes is set to true and the ``key_agreement`` purpose is
852 also set, the subject public key may be used only for enciphering data
853 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500854
855 :raises ValueError: This is raised if accessed when ``key_agreement``
856 is false.
857
858 .. attribute:: decipher_only
859
860 :type: bool
861
Paul Kehrer738407b2015-04-01 22:39:02 -0500862 When this purposes is set to true and the ``key_agreement`` purpose is
863 also set, the subject public key may be used only for deciphering data
864 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500865
866 :raises ValueError: This is raised if accessed when ``key_agreement``
867 is false.
868
869
Paul Kehrer8cf26422015-03-21 09:50:24 -0500870.. class:: BasicConstraints
871
872 .. versionadded:: 0.9
873
Paul Kehrer85894662015-03-22 13:19:31 -0500874 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -0500875 certificate is allowed to sign additional certificates and what path
Paul Kehrer85894662015-03-22 13:19:31 -0500876 length restrictions may exist. It corresponds to
877 :data:`OID_BASIC_CONSTRAINTS`.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500878
879 .. attribute:: ca
880
881 :type: bool
882
883 Whether the certificate can sign certificates.
884
885 .. attribute:: path_length
886
Paul Kehrerfd1444c2015-03-21 19:47:05 -0500887 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -0500888
889 The maximum path length for certificates subordinate to this
890 certificate. This attribute only has meaning if ``ca`` is true.
891 If ``ca`` is true then a path length of None means there's no
892 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -0400893 If it is zero or greater then it defines the maximum length for a
894 subordinate CA's certificate chain. For example, a ``path_length`` of 1
895 means the certificate can sign a subordinate CA, but the subordinate CA
896 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500897
Paul Kehrerffa2a152015-03-31 08:18:25 -0500898.. class:: ExtendedKeyUsage
899
900 .. versionadded:: 0.9
901
902 This extension indicates one or more purposes for which the certified
903 public key may be used, in addition to or in place of the basic
904 purposes indicated in the key usage extension. The object is
905 iterable to obtain the list of :ref:`extended key usage OIDs <eku_oids>`.
906
Paul Kehrer4a1038e2015-05-18 10:28:31 -0700907.. class:: OCSPNoCheck
908
Paul Kehrer506a2152015-05-26 08:01:18 -0500909 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -0700910
911 This presence of this extension indicates that an OCSP client can trust a
912 responder for the lifetime of the responder's certificate. CAs issuing
913 such a certificate should realize that a compromise of the responder's key
914 is as serious as the compromise of a CA key used to sign CRLs, at least for
915 the validity period of this certificate. CA's may choose to issue this type
916 of certificate with a very short lifetime and renew it frequently. This
917 extension is only relevant when the certificate is an authorized OCSP
918 responder.
919
Paul Kehrere0017be2015-05-17 20:39:40 -0600920.. class:: NameConstraints
921
922 .. versionadded:: 1.0
923
924 The name constraints extension, which only has meaning in a CA certificate,
925 defines a name space within which all subject names in certificates issued
926 beneath the CA certificate must (or must not) be in. For specific details
927 on the way this extension should be processed see :rfc:`5280`.
928
929 .. attribute:: permitted_subtrees
930
931 :type: list of :class:`GeneralName` objects or None
932
933 The set of permitted name patterns. If a name matches this and an
934 element in ``excluded_subtrees`` it is invalid. At least one of
935 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
936
937 .. attribute:: excluded_subtrees
938
939 :type: list of :class:`GeneralName` objects or None
940
941 Any name matching a restriction in the ``excluded_subtrees`` field is
942 invalid regardless of information appearing in the
943 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
944 ``excluded_subtrees`` will be non-None.
945
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400946.. class:: AuthorityKeyIdentifier
947
948 .. versionadded:: 0.9
949
950 The authority key identifier extension provides a means of identifying the
951 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -0500952 This extension is typically used to assist in determining the appropriate
953 certificate chain. For more information about generation and use of this
954 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400955
956 .. attribute:: key_identifier
957
958 :type: bytes
959
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500960 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -0500961 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500962
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400963 .. attribute:: authority_cert_issuer
964
965 :type: :class:`Name` or None
966
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500967 The :class:`Name` of the issuer's issuer.
968
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400969 .. attribute:: authority_cert_serial_number
970
971 :type: int or None
972
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500973 The serial number of the issuer's issuer.
974
Paul Kehrer1eb82a62015-03-31 20:00:33 -0500975.. class:: SubjectKeyIdentifier
976
977 .. versionadded:: 0.9
978
979 The subject key identifier extension provides a means of identifying
980 certificates that contain a particular public key.
981
982 .. attribute:: digest
983
984 :type: bytes
985
986 The binary value of the identifier.
987
Paul Kehrer31bdf792015-03-25 14:11:00 -0500988.. class:: SubjectAlternativeName
989
990 .. versionadded:: 0.9
991
992 Subject alternative name is an X.509 extension that provides a list of
993 :ref:`general name <general_name_classes>` instances that provide a set
994 of identities for which the certificate is valid. The object is iterable to
995 get every element.
996
997 .. method:: get_values_for_type(type)
998
999 :param type: A :class:`GeneralName` provider. This is one of the
1000 :ref:`general name classes <general_name_classes>`.
1001
1002 :returns: A list of values extracted from the matched general names.
Joshua Taubererd2afad32015-07-06 22:37:53 +00001003 The type of the returned values depends on the :class:`GeneralName`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001004
Paul Kehrer93ae8052015-05-02 23:18:09 -05001005 .. doctest::
1006
1007 >>> from cryptography import x509
1008 >>> from cryptography.hazmat.backends import default_backend
1009 >>> from cryptography.hazmat.primitives import hashes
1010 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001011 >>> # Get the subjectAltName extension from the certificate
Paul Kehrer93ae8052015-05-02 23:18:09 -05001012 >>> ext = cert.extensions.get_extension_for_oid(x509.OID_SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001013 >>> # Get the dNSName entries from the SAN extension
1014 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer93ae8052015-05-02 23:18:09 -05001015 [u'www.cryptography.io', u'cryptography.io']
1016
Paul Kehrer8cf26422015-03-21 09:50:24 -05001017
Paul Kehrer99125c92015-06-07 18:37:10 -05001018.. class:: IssuerAlternativeName
1019
1020 .. versionadded:: 1.0
1021
1022 Issuer alternative name is an X.509 extension that provides a list of
1023 :ref:`general name <general_name_classes>` instances that provide a set
1024 of identities for the certificate issuer. The object is iterable to
1025 get every element.
1026
1027 .. method:: get_values_for_type(type)
1028
1029 :param type: A :class:`GeneralName` provider. This is one of the
1030 :ref:`general name classes <general_name_classes>`.
1031
1032 :returns: A list of values extracted from the matched general names.
1033
1034
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001035.. class:: AuthorityInformationAccess
1036
1037 .. versionadded:: 0.9
1038
1039 The authority information access extension indicates how to access
1040 information and services for the issuer of the certificate in which
1041 the extension appears. Information and services may include online
1042 validation services (such as OCSP) and issuer data. It is an iterable,
1043 containing one or more :class:`AccessDescription` instances.
1044
1045
1046.. class:: AccessDescription
1047
Paul Kehrer5a485522015-05-06 00:29:12 -05001048 .. versionadded:: 0.9
1049
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001050 .. attribute:: access_method
1051
1052 :type: :class:`ObjectIdentifier`
1053
Paul Kehrerf506bca2015-05-02 22:31:47 -05001054 The access method defines what the ``access_location`` means. It must
1055 be either :data:`OID_OCSP` or :data:`OID_CA_ISSUERS`. If it is
1056 :data:`OID_OCSP` the access location will be where to obtain OCSP
1057 information for the certificate. If it is :data:`OID_CA_ISSUERS` the
1058 access location will provide additional information about the issuing
1059 certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001060
1061 .. attribute:: access_location
1062
1063 :type: :class:`GeneralName`
1064
Paul Kehrerf506bca2015-05-02 22:31:47 -05001065 Where to access the information defined by the access method.
1066
Paul Kehrer5a485522015-05-06 00:29:12 -05001067.. class:: CRLDistributionPoints
1068
1069 .. versionadded:: 0.9
1070
1071 The CRL distribution points extension identifies how CRL information is
1072 obtained. It is an iterable, containing one or more
1073 :class:`DistributionPoint` instances.
1074
1075.. class:: DistributionPoint
1076
1077 .. versionadded:: 0.9
1078
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001079 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05001080
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001081 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001082
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001083 This field describes methods to retrieve the CRL. At most one of
1084 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001085
1086 .. attribute:: relative_name
1087
1088 :type: :class:`Name` or None
1089
1090 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001091 issuer. At most one of ``full_name`` or ``relative_name`` will be
1092 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05001093
1094 .. attribute:: crl_issuer
1095
1096 :type: list of :class:`GeneralName` instances or None
1097
1098 Information about the issuer of the CRL.
1099
1100 .. attribute:: reasons
1101
Paul Kehrer3fd02602015-05-09 19:46:13 -05001102 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001103
1104 The reasons a given distribution point may be used for when performing
1105 revocation checks.
1106
1107.. class:: ReasonFlags
1108
1109 .. versionadded:: 0.9
1110
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001111 An enumeration for CRL reasons.
1112
1113 .. attribute:: unspecified
1114
1115 It is unspecified why the certificate was revoked. This reason cannot
1116 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001117
1118 .. attribute:: key_compromise
1119
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001120 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001121
1122 .. attribute:: ca_compromise
1123
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001124 This reason indicates that the CA issuing the certificate was
1125 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001126
1127 .. attribute:: affiliation_changed
1128
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001129 This reason indicates that the subject's name or other information has
1130 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05001131
1132 .. attribute:: superseded
1133
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001134 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05001135
1136 .. attribute:: cessation_of_operation
1137
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001138 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05001139
1140 .. attribute:: certificate_hold
1141
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001142 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05001143
1144 .. attribute:: privilege_withdrawn
1145
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001146 This reason indicates that the privilege granted by this certificate
1147 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05001148
1149 .. attribute:: aa_compromise
1150
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001151 When an attribute authority has been compromised.
1152
1153 .. attribute:: remove_from_crl
1154
1155 This reason indicates that the certificate was on hold and should be
1156 removed from the CRL. This reason cannot be used as a reason flag
1157 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001158
Paul Kehrer16fae762015-05-01 23:14:20 -05001159.. class:: InhibitAnyPolicy
1160
1161 .. versionadded:: 1.0
1162
1163 The inhibit ``anyPolicy`` extension indicates that the special OID
1164 :data:`OID_ANY_POLICY`, is not considered an explicit match for other
1165 :class:`CertificatePolicies` except when it appears in an intermediate
1166 self-issued CA certificate. The value indicates the number of additional
1167 non-self-issued certificates that may appear in the path before
1168 :data:`OID_ANY_POLICY` is no longer permitted. For example, a value
1169 of one indicates that :data:`OID_ANY_POLICY` may be processed in
1170 certificates issued by the subject of this certificate, but not in
1171 additional certificates in the path.
1172
1173 .. attribute:: skip_certs
1174
1175 :type: int
1176
Paul Kehrer0d210922015-04-28 17:31:07 -05001177.. class:: CertificatePolicies
1178
1179 .. versionadded:: 0.9
1180
Paul Kehrer2e879742015-05-02 23:09:56 -05001181 The certificate policies extension is an iterable, containing one or more
1182 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05001183
1184Certificate Policies Classes
1185~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1186
1187These classes may be present within a :class:`CertificatePolicies` instance.
1188
1189.. class:: PolicyInformation
1190
1191 .. versionadded:: 0.9
1192
1193 Contains a policy identifier and an optional list of qualifiers.
1194
1195 .. attribute:: policy_identifier
1196
1197 :type: :class:`ObjectIdentifier`
1198
1199 .. attribute:: policy_qualifiers
1200
1201 :type: list
1202
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001203 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05001204 If the value is text it is a pointer to the practice statement
1205 published by the certificate authority. If it is a user notice it is
1206 meant for display to the relying party when the certificate is
1207 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05001208
Paul Kehrer0d210922015-04-28 17:31:07 -05001209.. class:: UserNotice
1210
1211 .. versionadded:: 0.9
1212
Paul Kehrer2e879742015-05-02 23:09:56 -05001213 User notices are intended for display to a relying party when a certificate
1214 is used. In practice, few if any UIs expose this data and it is a rarely
1215 encoded component.
1216
Paul Kehrer0d210922015-04-28 17:31:07 -05001217 .. attribute:: notice_reference
1218
1219 :type: :class:`NoticeReference` or None
1220
Paul Kehrer2e879742015-05-02 23:09:56 -05001221 The notice reference field names an organization and identifies,
1222 by number, a particular statement prepared by that organization.
1223
Paul Kehrer0d210922015-04-28 17:31:07 -05001224 .. attribute:: explicit_text
1225
Paul Kehrer2e879742015-05-02 23:09:56 -05001226 This field includes an arbitrary textual statement directly in the
1227 certificate.
1228
Paul Kehrer0d210922015-04-28 17:31:07 -05001229 :type: :term:`text`
1230
1231.. class:: NoticeReference
1232
Paul Kehrer2e879742015-05-02 23:09:56 -05001233 Notice reference can name an organization and provide information about
1234 notices related to the certificate. For example, it might identify the
1235 organization name and notice number 1. Application software could
1236 have a notice file containing the current set of notices for the named
1237 organization; the application would then extract the notice text from the
1238 file and display it. In practice this is rarely seen.
1239
Paul Kehrer0d210922015-04-28 17:31:07 -05001240 .. versionadded:: 0.9
1241
1242 .. attribute:: organization
1243
Paul Kehrer66c61702015-05-12 16:39:18 -05001244 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05001245
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05001246 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05001247
Paul Kehrer66c61702015-05-12 16:39:18 -05001248 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05001249
Paul Kehrer66c61702015-05-12 16:39:18 -05001250 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05001251
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001252Object Identifiers
1253~~~~~~~~~~~~~~~~~~
1254
Paul Kehrer4bb46492015-02-07 16:59:14 -06001255X.509 elements are frequently identified by :class:`ObjectIdentifier`
1256instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001257
Paul Kehrer56da2a52015-02-11 23:35:07 -06001258Name OIDs
1259~~~~~~~~~
1260
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001261.. data:: OID_COMMON_NAME
1262
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001263 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
1264 name would be encoded here for server certificates. :rfc:`2818` deprecates
1265 this practice and names of that type should now be located in a
Paul Kehrer4bb46492015-02-07 16:59:14 -06001266 SubjectAlternativeName extension. This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001267
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001268.. data:: OID_COUNTRY_NAME
1269
Paul Kehrer4bb46492015-02-07 16:59:14 -06001270 Corresponds to the dotted string ``"2.5.4.6"``. This OID is typically seen
1271 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001272
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001273.. data:: OID_LOCALITY_NAME
1274
Paul Kehrer4bb46492015-02-07 16:59:14 -06001275 Corresponds to the dotted string ``"2.5.4.7"``. This OID is typically seen
1276 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001277
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001278.. data:: OID_STATE_OR_PROVINCE_NAME
1279
Paul Kehrer4bb46492015-02-07 16:59:14 -06001280 Corresponds to the dotted string ``"2.5.4.8"``. This OID is typically seen
1281 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001282
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001283.. data:: OID_ORGANIZATION_NAME
1284
Paul Kehrer4bb46492015-02-07 16:59:14 -06001285 Corresponds to the dotted string ``"2.5.4.10"``. This OID is typically seen
1286 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001287
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001288.. data:: OID_ORGANIZATIONAL_UNIT_NAME
1289
Paul Kehrer4bb46492015-02-07 16:59:14 -06001290 Corresponds to the dotted string ``"2.5.4.11"``. This OID is typically seen
1291 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001292
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001293.. data:: OID_SERIAL_NUMBER
1294
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001295 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from the
1296 serial number of the certificate itself (which can be obtained with
Paul Kehrer4bb46492015-02-07 16:59:14 -06001297 :func:`Certificate.serial`). This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001298
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001299.. data:: OID_SURNAME
1300
Paul Kehrer4bb46492015-02-07 16:59:14 -06001301 Corresponds to the dotted string ``"2.5.4.4"``. This OID is typically seen
1302 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001303
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001304.. data:: OID_GIVEN_NAME
1305
Paul Kehrer4bb46492015-02-07 16:59:14 -06001306 Corresponds to the dotted string ``"2.5.4.42"``. This OID is typically seen
1307 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001308
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001309.. data:: OID_TITLE
1310
Paul Kehrer4bb46492015-02-07 16:59:14 -06001311 Corresponds to the dotted string ``"2.5.4.12"``. This OID is typically seen
1312 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001313
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001314.. data:: OID_GENERATION_QUALIFIER
1315
Paul Kehrer4bb46492015-02-07 16:59:14 -06001316 Corresponds to the dotted string ``"2.5.4.44"``. This OID is typically seen
1317 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001318
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001319.. data:: OID_DN_QUALIFIER
1320
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001321 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
1322 disambiguating information to add to the relative distinguished name of an
Paul Kehrer4bb46492015-02-07 16:59:14 -06001323 entry. See :rfc:`2256`. This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001324
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001325.. data:: OID_PSEUDONYM
1326
Paul Kehrer4bb46492015-02-07 16:59:14 -06001327 Corresponds to the dotted string ``"2.5.4.65"``. This OID is typically seen
1328 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001329
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001330.. data:: OID_DOMAIN_COMPONENT
1331
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001332 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
Paul Kehrer4bb46492015-02-07 16:59:14 -06001333 holding one component of a domain name. See :rfc:`4519`. This OID is
1334 typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001335
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001336.. data:: OID_EMAIL_ADDRESS
1337
Paul Kehrer4bb46492015-02-07 16:59:14 -06001338 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``. This OID is
1339 typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001340
Paul Kehrer56da2a52015-02-11 23:35:07 -06001341Signature Algorithm OIDs
1342~~~~~~~~~~~~~~~~~~~~~~~~
1343
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001344.. data:: OID_RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06001345
1346 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
1347 an MD5 digest signed by an RSA key.
1348
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001349.. data:: OID_RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06001350
1351 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
1352 a SHA1 digest signed by an RSA key.
1353
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001354.. data:: OID_RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06001355
1356 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
1357 a SHA224 digest signed by an RSA key.
1358
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001359.. data:: OID_RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06001360
1361 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
1362 a SHA256 digest signed by an RSA key.
1363
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001364.. data:: OID_RSA_WITH_SHA384
Paul Kehrer56da2a52015-02-11 23:35:07 -06001365
1366 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
1367 a SHA384 digest signed by an RSA key.
1368
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001369.. data:: OID_RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06001370
1371 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
1372 a SHA512 digest signed by an RSA key.
1373
Alex Gaynor3aadabf2015-06-23 22:06:21 -04001374.. data:: OID_ECDSA_WITH_SHA1
1375
1376 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
1377 digest signed by an ECDSA key.
1378
Paul Kehrer56da2a52015-02-11 23:35:07 -06001379.. data:: OID_ECDSA_WITH_SHA224
1380
1381 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
1382 a SHA224 digest signed by an ECDSA key.
1383
1384.. data:: OID_ECDSA_WITH_SHA256
1385
1386 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
1387 a SHA256 digest signed by an ECDSA key.
1388
1389.. data:: OID_ECDSA_WITH_SHA384
1390
1391 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
1392 a SHA384 digest signed by an ECDSA key.
1393
1394.. data:: OID_ECDSA_WITH_SHA512
1395
1396 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
1397 a SHA512 digest signed by an ECDSA key.
1398
1399.. data:: OID_DSA_WITH_SHA1
1400
1401 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
1402 a SHA1 digest signed by a DSA key.
1403
1404.. data:: OID_DSA_WITH_SHA224
1405
1406 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
1407 a SHA224 digest signed by a DSA key.
1408
1409.. data:: OID_DSA_WITH_SHA256
1410
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001411 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
Paul Kehrer56da2a52015-02-11 23:35:07 -06001412 a SHA256 digest signed by a DSA key.
1413
Paul Kehrerffa2a152015-03-31 08:18:25 -05001414.. _eku_oids:
1415
Paul Kehrere1513fa2015-03-30 23:08:17 -05001416Extended Key Usage OIDs
1417~~~~~~~~~~~~~~~~~~~~~~~
1418
1419.. data:: OID_SERVER_AUTH
1420
1421 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used to
1422 denote that a certificate may be used for TLS web server authentication.
1423
1424.. data:: OID_CLIENT_AUTH
1425
1426 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used to
1427 denote that a certificate may be used for TLS web client authentication.
1428
1429.. data:: OID_CODE_SIGNING
1430
1431 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used to
1432 denote that a certificate may be used for code signing.
1433
1434.. data:: OID_EMAIL_PROTECTION
1435
1436 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used to
1437 denote that a certificate may be used for email protection.
1438
1439.. data:: OID_TIME_STAMPING
1440
1441 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used to
1442 denote that a certificate may be used for time stamping.
1443
1444.. data:: OID_OCSP_SIGNING
1445
1446 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used to
1447 denote that a certificate may be used for signing OCSP responses.
1448
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001449Authority Information Access OIDs
1450~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1451
1452.. data:: OID_OCSP
1453
1454 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
1455 identifier for OCSP data in :class:`AccessDescription` objects.
1456
1457.. data:: OID_CA_ISSUERS
1458
1459 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
1460 identifier for CA issuer data in :class:`AccessDescription` objects.
1461
Paul Kehrer2e879742015-05-02 23:09:56 -05001462Policy Qualifier OIDs
1463~~~~~~~~~~~~~~~~~~~~~
1464
1465.. data:: OID_CPS_QUALIFIER
1466
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001467 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05001468
1469.. data:: OID_CPS_USER_NOTICE
1470
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001471 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05001472
Paul Kehrer16fae762015-05-01 23:14:20 -05001473.. data:: OID_ANY_POLICY
1474
1475 Corresponds to the dotted string ``"2.5.29.32.0"``.
1476
Paul Kehrer5553d572015-03-23 21:08:01 -05001477.. _extension_oids:
1478
Paul Kehrer2bb94642015-03-21 09:54:17 -05001479Extension OIDs
1480~~~~~~~~~~~~~~
1481
1482.. data:: OID_BASIC_CONSTRAINTS
1483
1484 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
Paul Kehrer611d3d32015-03-22 13:31:18 -05001485 :class:`BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05001486
Paul Kehrercecbbba2015-03-30 14:58:38 -05001487.. data:: OID_KEY_USAGE
1488
1489 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
1490 :class:`KeyUsage` extension type.
1491
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001492.. data:: OID_SUBJECT_ALTERNATIVE_NAME
1493
1494 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
1495 :class:`SubjectAlternativeName` extension type.
1496
Paul Kehrer99125c92015-06-07 18:37:10 -05001497.. data:: OID_ISSUER_ALTERNATIVE_NAME
1498
1499 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
1500 :class:`IssuerAlternativeName` extension type.
1501
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001502.. data:: OID_SUBJECT_KEY_IDENTIFIER
1503
1504 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
1505 :class:`SubjectKeyIdentifier` extension type.
1506
Paul Kehrere0017be2015-05-17 20:39:40 -06001507.. data:: OID_NAME_CONSTRAINTS
1508
1509 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
1510 :class:`NameConstraints` extension type.
1511
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001512.. data:: OID_CRL_DISTRIBUTION_POINTS
1513
1514 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
1515 :class:`CRLDistributionPoints` extension type.
1516
1517.. data:: OID_CERTIFICATE_POLICIES
1518
1519 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
1520 :class:`CertificatePolicies` extension type.
1521
1522.. data:: OID_AUTHORITY_KEY_IDENTIFIER
1523
1524 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
1525 :class:`AuthorityKeyIdentifier` extension type.
1526
1527.. data:: OID_EXTENDED_KEY_USAGE
1528
1529 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
1530 :class:`ExtendedKeyUsage` extension type.
1531
1532.. data:: OID_AUTHORITY_INFORMATION_ACCESS
1533
1534 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
1535 for the :class:`AuthorityInformationAccess` extension type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001536
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001537.. data:: OID_OCSP_NO_CHECK
1538
1539 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The identifier
1540 for the :class:`OCSPNoCheck` extension type.
1541
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001542Exceptions
1543~~~~~~~~~~
1544
Paul Kehrere76cd272014-12-14 19:00:51 -06001545.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10001546
1547 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10001548
Paul Kehrerd5cccf72014-12-15 17:20:33 -06001549 .. attribute:: parsed_version
1550
Paul Kehrerbbffc402014-12-17 13:33:55 -06001551 :type: int
1552
1553 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06001554
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001555.. class:: DuplicateExtension
1556
1557 This is raised when more than one X.509 extension of the same type is
1558 found within a certificate.
1559
1560 .. attribute:: oid
1561
1562 :type: :class:`ObjectIdentifier`
1563
1564 Returns the OID.
1565
1566.. class:: UnsupportedExtension
1567
1568 This is raised when a certificate contains an unsupported extension type.
1569
1570 .. attribute:: oid
1571
1572 :type: :class:`ObjectIdentifier`
1573
1574 Returns the OID.
1575
Paul Kehrerfa56a232015-03-17 13:14:03 -05001576.. class:: ExtensionNotFound
1577
1578 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
1579 an extension OID that is not present in the certificate.
1580
1581 .. attribute:: oid
1582
1583 :type: :class:`ObjectIdentifier`
1584
1585 Returns the OID.
1586
Paul Kehrer9089c912015-04-20 22:15:20 -05001587.. class:: UnsupportedGeneralNameType
1588
1589 This is raised when a certificate contains an unsupported general name
1590 type in an extension.
1591
Paul Kehrerbed07352015-04-21 08:31:10 -05001592 .. attribute:: type
1593
Paul Kehrer0a621bf2015-04-22 09:22:56 -05001594 :type: int
1595
1596 The integer value of the unsupported type. The complete list of
1597 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05001598
Paul Kehrer016e08a2014-11-26 09:41:18 -10001599
Paul Kehrerc7c9a432015-04-19 09:20:13 -05001600.. _`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 -05001601.. _`RFC 5280 section 4.2.1.6`: https://tools.ietf.org/html/rfc5280#section-4.2.1.6