blob: 52117c845b81adf4b8c5fe8484f63a23a8585922 [file] [log] [blame]
Paul Kehrer016e08a2014-11-26 09:41:18 -10001X.509
2=====
3
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 Kehrerd3dafbd2015-03-15 16:24:18 -050089X.509 is an ITU-T standard for a `public key infrastructure`_. X.509v3 is
90defined in :rfc:`5280` (which obsoletes :rfc:`2459` and :rfc:`3280`). X.509
91certificates are commonly used in protocols like `TLS`_.
Paul Kehrerb2de9482014-12-11 14:54:48 -060092
93Loading Certificates
94~~~~~~~~~~~~~~~~~~~~
Paul Kehrer016e08a2014-11-26 09:41:18 -100095
96.. function:: load_pem_x509_certificate(data, backend)
97
98 .. versionadded:: 0.7
99
Paul Kehrere76cd272014-12-14 19:00:51 -0600100 Deserialize a certificate from PEM encoded data. PEM certificates are
101 base64 decoded and have delimiters that look like
102 ``-----BEGIN CERTIFICATE-----``.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000103
104 :param bytes data: The PEM encoded certificate data.
105
106 :param backend: A backend supporting the
107 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
108 interface.
109
Paul Kehrere76cd272014-12-14 19:00:51 -0600110 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000111
112.. function:: load_der_x509_certificate(data, backend)
113
114 .. versionadded:: 0.7
115
Paul Kehrere76cd272014-12-14 19:00:51 -0600116 Deserialize a certificate from DER encoded data. DER is a binary format
Paul Kehrer92aac382014-12-15 16:25:28 -0600117 and is commonly found in files with the ``.cer`` extension (although file
118 extensions are not a guarantee of encoding type).
Paul Kehrer016e08a2014-11-26 09:41:18 -1000119
120 :param bytes data: The DER encoded certificate data.
121
122 :param backend: A backend supporting the
123 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
124 interface.
125
Paul Kehrere76cd272014-12-14 19:00:51 -0600126 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000127
Paul Kehrer016e08a2014-11-26 09:41:18 -1000128.. doctest::
129
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600130 >>> from cryptography import x509
Paul Kehrer016e08a2014-11-26 09:41:18 -1000131 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600132 >>> cert = x509.load_pem_x509_certificate(pem_data, default_backend())
Paul Kehrer016e08a2014-11-26 09:41:18 -1000133 >>> cert.serial
134 2
135
Paul Kehrera1a1f232015-03-15 15:34:35 -0500136Loading Certificate Signing Requests
137~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600138
Paul Kehrer31e39882015-03-11 11:37:04 -0500139.. function:: load_pem_x509_csr(data, backend)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600140
141 .. versionadded:: 0.9
142
Paul Kehrera1a1f232015-03-15 15:34:35 -0500143 Deserialize a certificate signing request (CSR) from PEM encoded data. PEM
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500144 requests are base64 decoded and have delimiters that look like
Paul Kehrerd3dafbd2015-03-15 16:24:18 -0500145 ``-----BEGIN CERTIFICATE REQUEST-----``. This format is also known as
146 PKCS#10.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600147
148 :param bytes data: The PEM encoded request data.
149
150 :param backend: A backend supporting the
151 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
152 interface.
153
Paul Kehrera1a1f232015-03-15 15:34:35 -0500154 :returns: An instance of
155 :class:`~cryptography.x509.CertificateSigningRequest`.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600156
Paul Kehrer1effb6e2015-03-30 15:05:59 -0500157.. function:: load_der_x509_csr(data, backend)
158
159 .. versionadded:: 0.9
160
161 Deserialize a certificate signing request (CSR) from DER encoded data. DER
162 is a binary format and is not commonly used with CSRs.
163
164 :param bytes data: The DER encoded request data.
165
166 :param backend: A backend supporting the
167 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
168 interface.
169
170 :returns: An instance of
171 :class:`~cryptography.x509.CertificateSigningRequest`.
172
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600173.. doctest::
174
175 >>> from cryptography import x509
176 >>> from cryptography.hazmat.backends import default_backend
177 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500178 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
179 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600180 True
181
Paul Kehrere76cd272014-12-14 19:00:51 -0600182X.509 Certificate Object
183~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerb2de9482014-12-11 14:54:48 -0600184
Paul Kehrere76cd272014-12-14 19:00:51 -0600185.. class:: Certificate
Paul Kehrerb2de9482014-12-11 14:54:48 -0600186
187 .. versionadded:: 0.7
188
189 .. attribute:: version
190
Paul Kehrere76cd272014-12-14 19:00:51 -0600191 :type: :class:`~cryptography.x509.Version`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600192
Paul Kehrere76cd272014-12-14 19:00:51 -0600193 The certificate version as an enumeration. Version 3 certificates are
194 the latest version and also the only type you should see in practice.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600195
Alex Gaynor89c4dc82014-12-16 16:49:33 -0800196 :raises cryptography.x509.InvalidVersion: If the version in the
Alex Gaynor6d7ab4c2014-12-16 16:50:33 -0800197 certificate is not a known
198 :class:`X.509 version <cryptography.x509.Version>`.
Paul Kehrer92aac382014-12-15 16:25:28 -0600199
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600200 .. doctest::
201
202 >>> cert.version
203 <Version.v3: 2>
204
Paul Kehrerb2de9482014-12-11 14:54:48 -0600205 .. method:: fingerprint(algorithm)
206
207 :param algorithm: The
Paul Kehrer601278a2015-02-12 12:51:00 -0600208 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600209 that will be used to generate the fingerprint.
210
Erik Trauschke2dcce902015-05-14 16:12:24 -0700211 :return bytes: The fingerprint using the supplied hash algorithm, as
Paul Kehrerb2de9482014-12-11 14:54:48 -0600212 bytes.
213
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600214 .. doctest::
215
216 >>> from cryptography.hazmat.primitives import hashes
217 >>> cert.fingerprint(hashes.SHA256())
Paul Kehrer78a81502014-12-16 14:47:52 -0600218 '\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 -0600219
Paul Kehrerb2de9482014-12-11 14:54:48 -0600220 .. attribute:: serial
221
222 :type: int
223
224 The serial as a Python integer.
225
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600226 .. doctest::
227
228 >>> cert.serial
229 2
230
Paul Kehrerb2de9482014-12-11 14:54:48 -0600231 .. method:: public_key()
232
233 :type:
Alex Stapletonf79c2312014-12-30 12:50:14 +0000234 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
Paul Kehrer45efdbc2015-02-12 10:58:22 -0600235 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
236 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600237
238 The public key associated with the certificate.
239
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600240 .. doctest::
241
Alex Stapletonf79c2312014-12-30 12:50:14 +0000242 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600243 >>> public_key = cert.public_key()
Alex Stapletonf79c2312014-12-30 12:50:14 +0000244 >>> isinstance(public_key, rsa.RSAPublicKey)
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600245 True
246
Paul Kehrerb2de9482014-12-11 14:54:48 -0600247 .. attribute:: not_valid_before
248
249 :type: :class:`datetime.datetime`
250
Paul Kehrer78a81502014-12-16 14:47:52 -0600251 A naïve datetime representing the beginning of the validity period for
252 the certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600253
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600254 .. doctest::
255
256 >>> cert.not_valid_before
257 datetime.datetime(2010, 1, 1, 8, 30)
258
Paul Kehrerb2de9482014-12-11 14:54:48 -0600259 .. attribute:: not_valid_after
260
261 :type: :class:`datetime.datetime`
262
Paul Kehrer78a81502014-12-16 14:47:52 -0600263 A naïve datetime representing the end of the validity period for the
264 certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600265
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600266 .. doctest::
267
268 >>> cert.not_valid_after
269 datetime.datetime(2030, 12, 31, 8, 30)
270
Paul Kehrer719d5362015-01-01 20:03:52 -0600271 .. attribute:: issuer
272
273 .. versionadded:: 0.8
274
275 :type: :class:`Name`
276
277 The :class:`Name` of the issuer.
278
279 .. attribute:: subject
280
281 .. versionadded:: 0.8
282
283 :type: :class:`Name`
284
285 The :class:`Name` of the subject.
286
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600287 .. attribute:: signature_hash_algorithm
Paul Kehrer56da2a52015-02-11 23:35:07 -0600288
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600289 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrer56da2a52015-02-11 23:35:07 -0600290
Paul Kehrere612ec72015-02-16 14:33:35 -0600291 Returns the
Paul Kehrer71d40c62015-02-19 08:21:04 -0600292 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600293 was used in signing this certificate.
Paul Kehrer56da2a52015-02-11 23:35:07 -0600294
295 .. doctest::
296
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600297 >>> from cryptography.hazmat.primitives import hashes
298 >>> isinstance(cert.signature_hash_algorithm, hashes.SHA256)
299 True
Paul Kehrer719d5362015-01-01 20:03:52 -0600300
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500301 .. attribute:: extensions
302
303 :type: :class:`Extensions`
304
305 The extensions encoded in the certificate.
306
307 :raises cryptography.x509.DuplicateExtension: If more than one
308 extension of the same type is found within the certificate.
309
Paul Kehrerd8fc0be2015-04-21 08:31:10 -0500310 :raises cryptography.x509.UnsupportedExtension: If the certificate
311 contains an extension that is not supported.
312
Paul Kehrerbed07352015-04-21 08:31:10 -0500313 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
314 contains a general name that is not supported.
315
Paul Kehrerb8968812015-05-15 09:01:34 -0700316 :raises UnicodeError: If an extension contains IDNA encoding that is
317 invalid or not compliant with IDNA 2008.
318
Paul Kehrerfa56a232015-03-17 13:14:03 -0500319 .. doctest::
320
321 >>> for ext in cert.extensions:
322 ... print(ext)
Paul Kehrerd774de92015-05-03 10:52:25 -0500323 <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 -0400324 <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 -0400325 <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 -0500326 <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 -0500327 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
328
Andre Carona8aded62015-05-19 20:11:57 -0400329 .. method:: public_bytes(encoding)
330
331 :param encoding: The
332 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
333 that will be used to serialize the certificate.
334
335 :return bytes: The data that can be written to a file or sent
336 over the network to be verified by clients.
337
Erik Trauschke2dcce902015-05-14 16:12:24 -0700338X.509 CRL (Certificate Revocation List) Object
339~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
340
341.. class:: CertificateRevocationList
342
343 .. versionadded:: 1.0
344
345 .. method:: fingerprint(algorithm)
346
347 :param algorithm: The
348 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
349 that will be used to generate the fingerprint.
350
351 :return bytes: The fingerprint using the supplied hash algorithm, as
352 bytes.
353
354 .. attribute:: signature_hash_algorithm
355
356 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
357
358 Returns the
359 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
360 was used in signing this CRL.
361
362 .. attribute:: issuer
363
364 :type: :class:`Name`
365
366 The :class:`Name` of the issuer.
367
368 .. attribute:: next_update
369
370 :type: :class:`datetime.datetime`
371
372 A naïve datetime representing when the next update to this CRL is
373 expected.
374
375 .. attribute:: last_update
376
377 :type: :class:`datetime.datetime`
378
379 A naïve datetime representing when the this CRL was last updated.
380
Erik Trauschkeabb7b6e2015-05-27 15:07:35 -0700381 .. attribute:: revoked_certificates
Erik Trauschke2dcce902015-05-14 16:12:24 -0700382
383 :type: list of :class:`RevokedCertificate`
384
385 The revoked certificates listed in this CRL.
386
387 .. attribute:: extensions
388
389 :type: :class:`Extensions`
390
391 The extensions encoded in the CRL.
392
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500393X.509 CSR (Certificate Signing Request) Object
394~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600395
Paul Kehrera1a1f232015-03-15 15:34:35 -0500396.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600397
398 .. versionadded:: 0.9
399
400 .. method:: public_key()
401
402 :type:
403 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
404 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
405 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
406
407 The public key associated with the request.
408
409 .. doctest::
410
411 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500412 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600413 >>> isinstance(public_key, rsa.RSAPublicKey)
414 True
415
416 .. attribute:: subject
417
418 :type: :class:`Name`
419
420 The :class:`Name` of the subject.
421
422 .. attribute:: signature_hash_algorithm
423
424 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
425
426 Returns the
427 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
428 was used in signing this request.
429
430 .. doctest::
431
432 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500433 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600434 True
435
Andre Caron476c5df2015-05-18 10:23:28 -0400436 .. method:: public_bytes(encoding)
437
438 :param encoding: The
439 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
440 that will be used to serialize the certificate request.
441
442 :return bytes: The data that can be written to a file or sent
443 over the network to be signed by the certificate
444 authority.
445
Erik Trauschke2dcce902015-05-14 16:12:24 -0700446X.509 Revoked Certificate Object
Erik Trauschkec5a8d172015-05-28 10:24:25 -0700447~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Erik Trauschke2dcce902015-05-14 16:12:24 -0700448
449.. class:: RevokedCertificate
450
451 .. versionadded:: 1.0
452
453 .. attribute:: serial_number
454
455 :type: :class:`int`
456
457 An integer representing the serial number of the revoked certificate.
458
459 .. attribute:: revocation_date
460
461 :type: :class:`datetime.datetime`
462
463 A naïve datetime representing the date this certificates was revoked.
464
465 .. attribute:: extensions
466
467 :type: :class:`Extensions`
468
469 The extensions encoded in the revoked certificate.
Andre Caron476c5df2015-05-18 10:23:28 -0400470
Andre Caron0ef595f2015-05-18 13:53:43 -0400471X.509 CSR (Certificate Signing Request) Builder Object
472~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
473
474.. class:: CertificateSigningRequestBuilder
475
Andre Carond259ee52015-06-02 23:47:11 -0400476 .. versionadded:: 1.0
477
478 .. doctest::
479
480 >>> from cryptography import x509
481 >>> from cryptography.hazmat.backends import default_backend
482 >>> from cryptography.hazmat.primitives import hashes
483 >>> from cryptography.hazmat.primitives.asymmetric import rsa
484 >>> private_key = rsa.generate_private_key(
485 ... public_exponent=65537,
486 ... key_size=2048,
487 ... backend=default_backend()
488 ... )
489 >>> builder = x509.CertificateSigningRequestBuilder()
490 >>> builder = builder.set_subject_name(x509.Name([
491 ... x509.NameAttribute(x509.OID_COMMON_NAME, 'cryptography.io'),
492 ... ]))
Andre Caron472fd692015-06-06 20:04:44 -0400493 >>> buidlder = builder.add_extension(
494 ... x509.BasicConstraints(False, None), critical=True,
495 ... )
Andre Carond259ee52015-06-02 23:47:11 -0400496 >>> request = builder.sign(
497 ... default_backend(), private_key, hashes.SHA1()
498 ... )
499 >>> isinstance(request, x509.CertificateSigningRequest)
500 True
501
Andre Caron0ef595f2015-05-18 13:53:43 -0400502 .. method:: __init__()
503
504 Creates an empty certificate signing request.
505
Andre Caron0ef595f2015-05-18 13:53:43 -0400506 .. method:: set_subject_name(name)
507
508 :param name: The :class:`Name` of the certificate subject.
Andre Caron6d7e39b2015-05-31 18:10:04 -0400509 :returns: A new `CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400510
Andre Caron472fd692015-06-06 20:04:44 -0400511 .. method:: add_extension(extension, critical=False)
Andre Caron0ef595f2015-05-18 13:53:43 -0400512
513 :param extension: The :class:`Extension` to add to the request.
Andre Caron472fd692015-06-06 20:04:44 -0400514 :param critical: Set to `True` if the extension must be understood and
515 handled by whoever reads the certificate.
Andre Caron6d7e39b2015-05-31 18:10:04 -0400516 :returns: A new `CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400517
518 .. method:: sign(backend, private_key, algorithm)
519
520 :param backend: Backend that will be used to sign the request.
521 Must support the
522 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
523 interface.
524
525 :param private_key: The
526 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`
527 that will be used to sign the request. When the request is
528 signed by a certificate authority, the private key's associated
529 public key will be stored in the resulting certificate.
530
531 :param algorithm: The
532 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
533 that will be used to generate the request signature.
534
535 :type: :class:`CertificateSigningRequest`
536
537
Paul Kehrer719d5362015-01-01 20:03:52 -0600538.. class:: Name
539
540 .. versionadded:: 0.8
541
Paul Kehrer53d8d492015-02-13 18:47:30 -0600542 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -0600543 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -0600544 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -0600545 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
546 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -0600547
Paul Kehrer53d8d492015-02-13 18:47:30 -0600548 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -0600549
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600550 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -0600551 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600552 >>> for attribute in cert.subject:
553 ... print(attribute)
554 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
555 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')>
556 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -0600557
Paul Kehrere901d642015-02-11 18:50:58 -0600558 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -0600559
Paul Kehrere901d642015-02-11 18:50:58 -0600560 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -0600561
Paul Kehrere901d642015-02-11 18:50:58 -0600562 :returns: A list of :class:`NameAttribute` instances that match the
563 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -0600564
565 .. doctest::
566
Paul Kehrere901d642015-02-11 18:50:58 -0600567 >>> cert.subject.get_attributes_for_oid(x509.OID_COMMON_NAME)
568 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -0600569
Paul Kehrere76cd272014-12-14 19:00:51 -0600570.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -1000571
572 .. versionadded:: 0.7
573
574 An enumeration for X.509 versions.
575
576 .. attribute:: v1
577
578 For version 1 X.509 certificates.
579
580 .. attribute:: v3
581
582 For version 3 X.509 certificates.
583
Paul Kehrer806bfb22015-02-02 17:05:24 -0600584.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600585
586 .. versionadded:: 0.8
587
Paul Kehrer834d22f2015-02-06 11:01:07 -0600588 An X.509 name consists of a list of NameAttribute instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600589
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600590 .. attribute:: oid
591
592 :type: :class:`ObjectIdentifier`
593
594 The attribute OID.
595
596 .. attribute:: value
597
Paul Kehrerd5852cb2015-01-30 08:25:23 -0600598 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600599
600 The value of the attribute.
601
602.. class:: ObjectIdentifier
603
604 .. versionadded:: 0.8
605
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600606 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -0600607 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600608
Paul Kehrerd44f9a62015-02-04 14:47:34 -0600609 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600610
611 :type: :class:`str`
612
Paul Kehrerfedf4f42015-02-06 11:22:07 -0600613 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600614
Paul Kehrer31bdf792015-03-25 14:11:00 -0500615.. _general_name_classes:
616
617General Name Classes
618~~~~~~~~~~~~~~~~~~~~
619
620.. class:: GeneralName
621
622 .. versionadded:: 0.9
623
624 This is the generic interface that all the following classes are registered
625 against.
626
627.. class:: RFC822Name
628
629 .. versionadded:: 0.9
630
631 This corresponds to an email address. For example, ``user@example.com``.
632
633 .. attribute:: value
634
635 :type: :term:`text`
636
637.. class:: DNSName
638
639 .. versionadded:: 0.9
640
641 This corresponds to a domain name. For example, ``cryptography.io``.
642
643 .. attribute:: value
644
645 :type: :term:`text`
646
647.. class:: DirectoryName
648
649 .. versionadded:: 0.9
650
651 This corresponds to a directory name.
652
653 .. attribute:: value
654
655 :type: :class:`Name`
656
657.. class:: UniformResourceIdentifier
658
659 .. versionadded:: 0.9
660
661 This corresponds to a uniform resource identifier. For example,
Paul Kehrerb8ef82e2015-04-22 16:04:24 -0500662 ``https://cryptography.io``. The URI is parsed and IDNA decoded (see
663 :rfc:`5895`).
664
665 .. note::
666
667 URIs that do not contain ``://`` in them will not be decoded.
Paul Kehrer31bdf792015-03-25 14:11:00 -0500668
669 .. attribute:: value
670
671 :type: :term:`text`
672
673.. class:: IPAddress
674
675 .. versionadded:: 0.9
676
677 This corresponds to an IP address.
678
679 .. attribute:: value
680
Paul Kehrereb177932015-05-17 18:33:33 -0700681 :type: :class:`~ipaddress.IPv4Address`,
682 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
683 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -0500684
685.. class:: RegisteredID
686
687 .. versionadded:: 0.9
688
689 This corresponds to a registered ID.
690
691 .. attribute:: value
692
693 :type: :class:`ObjectIdentifier`
694
Paul Kehrer8cf26422015-03-21 09:50:24 -0500695X.509 Extensions
696~~~~~~~~~~~~~~~~
697
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500698.. class:: Extensions
699
700 .. versionadded:: 0.9
701
702 An X.509 Extensions instance is an ordered list of extensions. The object
703 is iterable to get every extension.
704
Paul Kehrerfa56a232015-03-17 13:14:03 -0500705 .. method:: get_extension_for_oid(oid)
706
707 :param oid: An :class:`ObjectIdentifier` instance.
708
709 :returns: An instance of the extension class.
710
711 :raises cryptography.x509.ExtensionNotFound: If the certificate does
712 not have the extension requested.
713
Paul Kehrerfa56a232015-03-17 13:14:03 -0500714 .. doctest::
715
716 >>> cert.extensions.get_extension_for_oid(x509.OID_BASIC_CONSTRAINTS)
717 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
718
Paul Kehrer8cf26422015-03-21 09:50:24 -0500719.. class:: Extension
720
721 .. versionadded:: 0.9
722
Paul Kehrer85894662015-03-22 13:19:31 -0500723 .. attribute:: oid
724
725 :type: :class:`ObjectIdentifier`
726
Paul Kehrer5553d572015-03-23 21:08:01 -0500727 The :ref:`extension OID <extension_oids>`.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500728
729 .. attribute:: critical
730
731 :type: bool
732
Paul Kehrer58b75692015-03-22 23:24:58 -0500733 Determines whether a given extension is critical or not. :rfc:`5280`
734 requires that "A certificate-using system MUST reject the certificate
735 if it encounters a critical extension it does not recognize or a
736 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -0500737
Paul Kehrer85894662015-03-22 13:19:31 -0500738 .. attribute:: value
739
740 Returns an instance of the extension type corresponding to the OID.
741
Paul Kehrercecbbba2015-03-30 14:58:38 -0500742.. class:: KeyUsage
743
744 .. versionadded:: 0.9
745
746 The key usage extension defines the purpose of the key contained in the
747 certificate. The usage restriction might be employed when a key that could
748 be used for more than one operation is to be restricted. It corresponds to
749 :data:`OID_KEY_USAGE`.
750
751 .. attribute:: digital_signature
752
753 :type: bool
754
Paul Kehrer738407b2015-04-01 22:39:02 -0500755 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500756 digital signatures, other than signatures on certificates
757 (``key_cert_sign``) and CRLs (``crl_sign``).
758
759 .. attribute:: content_commitment
760
761 :type: bool
762
Paul Kehrer738407b2015-04-01 22:39:02 -0500763 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500764 digital signatures, other than signatures on certificates
765 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
766 non-repudiation service that protects against the signing entity
767 falsely denying some action. In the case of later conflict, a
768 reliable third party may determine the authenticity of the signed
769 data. This was called ``non_repudiation`` in older revisions of the
770 X.509 specification.
771
772 .. attribute:: key_encipherment
773
774 :type: bool
775
Paul Kehrer738407b2015-04-01 22:39:02 -0500776 This purpose is set to true when the subject public key is used for
777 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500778
779 .. attribute:: data_encipherment
780
781 :type: bool
782
Paul Kehrer738407b2015-04-01 22:39:02 -0500783 This purpose is set to true when the subject public key is used for
784 directly enciphering raw user data without the use of an intermediate
785 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500786
787 .. attribute:: key_agreement
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 key
792 agreement. For example, when a Diffie-Hellman key is to be used for
793 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500794
795 .. attribute:: key_cert_sign
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
800 verifying signatures on public key certificates. If this purpose is set
801 to true then ``ca`` must be true in the :class:`BasicConstraints`
802 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500803
804 .. attribute:: crl_sign
805
806 :type: bool
807
Paul Kehrer738407b2015-04-01 22:39:02 -0500808 This purpose is set to true when the subject public key is used for
809 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500810
811 .. attribute:: encipher_only
812
813 :type: bool
814
Paul Kehrer738407b2015-04-01 22:39:02 -0500815 When this purposes is set to true and the ``key_agreement`` purpose is
816 also set, the subject public key may be used only for enciphering data
817 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500818
819 :raises ValueError: This is raised if accessed when ``key_agreement``
820 is false.
821
822 .. attribute:: decipher_only
823
824 :type: bool
825
Paul Kehrer738407b2015-04-01 22:39:02 -0500826 When this purposes is set to true and the ``key_agreement`` purpose is
827 also set, the subject public key may be used only for deciphering data
828 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500829
830 :raises ValueError: This is raised if accessed when ``key_agreement``
831 is false.
832
833
Paul Kehrer8cf26422015-03-21 09:50:24 -0500834.. class:: BasicConstraints
835
836 .. versionadded:: 0.9
837
Paul Kehrer85894662015-03-22 13:19:31 -0500838 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -0500839 certificate is allowed to sign additional certificates and what path
Paul Kehrer85894662015-03-22 13:19:31 -0500840 length restrictions may exist. It corresponds to
841 :data:`OID_BASIC_CONSTRAINTS`.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500842
843 .. attribute:: ca
844
845 :type: bool
846
847 Whether the certificate can sign certificates.
848
849 .. attribute:: path_length
850
Paul Kehrerfd1444c2015-03-21 19:47:05 -0500851 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -0500852
853 The maximum path length for certificates subordinate to this
854 certificate. This attribute only has meaning if ``ca`` is true.
855 If ``ca`` is true then a path length of None means there's no
856 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -0400857 If it is zero or greater then it defines the maximum length for a
858 subordinate CA's certificate chain. For example, a ``path_length`` of 1
859 means the certificate can sign a subordinate CA, but the subordinate CA
860 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500861
Paul Kehrerffa2a152015-03-31 08:18:25 -0500862.. class:: ExtendedKeyUsage
863
864 .. versionadded:: 0.9
865
866 This extension indicates one or more purposes for which the certified
867 public key may be used, in addition to or in place of the basic
868 purposes indicated in the key usage extension. The object is
869 iterable to obtain the list of :ref:`extended key usage OIDs <eku_oids>`.
870
Paul Kehrer4a1038e2015-05-18 10:28:31 -0700871.. class:: OCSPNoCheck
872
Paul Kehrer506a2152015-05-26 08:01:18 -0500873 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -0700874
875 This presence of this extension indicates that an OCSP client can trust a
876 responder for the lifetime of the responder's certificate. CAs issuing
877 such a certificate should realize that a compromise of the responder's key
878 is as serious as the compromise of a CA key used to sign CRLs, at least for
879 the validity period of this certificate. CA's may choose to issue this type
880 of certificate with a very short lifetime and renew it frequently. This
881 extension is only relevant when the certificate is an authorized OCSP
882 responder.
883
Paul Kehrere0017be2015-05-17 20:39:40 -0600884.. class:: NameConstraints
885
886 .. versionadded:: 1.0
887
888 The name constraints extension, which only has meaning in a CA certificate,
889 defines a name space within which all subject names in certificates issued
890 beneath the CA certificate must (or must not) be in. For specific details
891 on the way this extension should be processed see :rfc:`5280`.
892
893 .. attribute:: permitted_subtrees
894
895 :type: list of :class:`GeneralName` objects or None
896
897 The set of permitted name patterns. If a name matches this and an
898 element in ``excluded_subtrees`` it is invalid. At least one of
899 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
900
901 .. attribute:: excluded_subtrees
902
903 :type: list of :class:`GeneralName` objects or None
904
905 Any name matching a restriction in the ``excluded_subtrees`` field is
906 invalid regardless of information appearing in the
907 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
908 ``excluded_subtrees`` will be non-None.
909
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400910.. class:: AuthorityKeyIdentifier
911
912 .. versionadded:: 0.9
913
914 The authority key identifier extension provides a means of identifying the
915 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -0500916 This extension is typically used to assist in determining the appropriate
917 certificate chain. For more information about generation and use of this
918 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400919
920 .. attribute:: key_identifier
921
922 :type: bytes
923
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500924 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -0500925 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500926
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400927 .. attribute:: authority_cert_issuer
928
929 :type: :class:`Name` or None
930
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500931 The :class:`Name` of the issuer's issuer.
932
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400933 .. attribute:: authority_cert_serial_number
934
935 :type: int or None
936
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500937 The serial number of the issuer's issuer.
938
Paul Kehrer1eb82a62015-03-31 20:00:33 -0500939.. class:: SubjectKeyIdentifier
940
941 .. versionadded:: 0.9
942
943 The subject key identifier extension provides a means of identifying
944 certificates that contain a particular public key.
945
946 .. attribute:: digest
947
948 :type: bytes
949
950 The binary value of the identifier.
951
Paul Kehrer31bdf792015-03-25 14:11:00 -0500952.. class:: SubjectAlternativeName
953
954 .. versionadded:: 0.9
955
956 Subject alternative name is an X.509 extension that provides a list of
957 :ref:`general name <general_name_classes>` instances that provide a set
958 of identities for which the certificate is valid. The object is iterable to
959 get every element.
960
961 .. method:: get_values_for_type(type)
962
963 :param type: A :class:`GeneralName` provider. This is one of the
964 :ref:`general name classes <general_name_classes>`.
965
966 :returns: A list of values extracted from the matched general names.
967
Paul Kehrer93ae8052015-05-02 23:18:09 -0500968 .. doctest::
969
970 >>> from cryptography import x509
971 >>> from cryptography.hazmat.backends import default_backend
972 >>> from cryptography.hazmat.primitives import hashes
973 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -0500974 >>> # Get the subjectAltName extension from the certificate
Paul Kehrer93ae8052015-05-02 23:18:09 -0500975 >>> ext = cert.extensions.get_extension_for_oid(x509.OID_SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -0500976 >>> # Get the dNSName entries from the SAN extension
977 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer93ae8052015-05-02 23:18:09 -0500978 [u'www.cryptography.io', u'cryptography.io']
979
Paul Kehrer8cf26422015-03-21 09:50:24 -0500980
Paul Kehrer99125c92015-06-07 18:37:10 -0500981.. class:: IssuerAlternativeName
982
983 .. versionadded:: 1.0
984
985 Issuer alternative name is an X.509 extension that provides a list of
986 :ref:`general name <general_name_classes>` instances that provide a set
987 of identities for the certificate issuer. The object is iterable to
988 get every element.
989
990 .. method:: get_values_for_type(type)
991
992 :param type: A :class:`GeneralName` provider. This is one of the
993 :ref:`general name classes <general_name_classes>`.
994
995 :returns: A list of values extracted from the matched general names.
996
997
Paul Kehrer3e6d5582015-05-02 21:57:56 -0500998.. class:: AuthorityInformationAccess
999
1000 .. versionadded:: 0.9
1001
1002 The authority information access extension indicates how to access
1003 information and services for the issuer of the certificate in which
1004 the extension appears. Information and services may include online
1005 validation services (such as OCSP) and issuer data. It is an iterable,
1006 containing one or more :class:`AccessDescription` instances.
1007
1008
1009.. class:: AccessDescription
1010
Paul Kehrer5a485522015-05-06 00:29:12 -05001011 .. versionadded:: 0.9
1012
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001013 .. attribute:: access_method
1014
1015 :type: :class:`ObjectIdentifier`
1016
Paul Kehrerf506bca2015-05-02 22:31:47 -05001017 The access method defines what the ``access_location`` means. It must
1018 be either :data:`OID_OCSP` or :data:`OID_CA_ISSUERS`. If it is
1019 :data:`OID_OCSP` the access location will be where to obtain OCSP
1020 information for the certificate. If it is :data:`OID_CA_ISSUERS` the
1021 access location will provide additional information about the issuing
1022 certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001023
1024 .. attribute:: access_location
1025
1026 :type: :class:`GeneralName`
1027
Paul Kehrerf506bca2015-05-02 22:31:47 -05001028 Where to access the information defined by the access method.
1029
Paul Kehrer5a485522015-05-06 00:29:12 -05001030.. class:: CRLDistributionPoints
1031
1032 .. versionadded:: 0.9
1033
1034 The CRL distribution points extension identifies how CRL information is
1035 obtained. It is an iterable, containing one or more
1036 :class:`DistributionPoint` instances.
1037
1038.. class:: DistributionPoint
1039
1040 .. versionadded:: 0.9
1041
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001042 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05001043
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001044 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001045
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001046 This field describes methods to retrieve the CRL. At most one of
1047 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001048
1049 .. attribute:: relative_name
1050
1051 :type: :class:`Name` or None
1052
1053 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001054 issuer. At most one of ``full_name`` or ``relative_name`` will be
1055 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05001056
1057 .. attribute:: crl_issuer
1058
1059 :type: list of :class:`GeneralName` instances or None
1060
1061 Information about the issuer of the CRL.
1062
1063 .. attribute:: reasons
1064
Paul Kehrer3fd02602015-05-09 19:46:13 -05001065 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001066
1067 The reasons a given distribution point may be used for when performing
1068 revocation checks.
1069
1070.. class:: ReasonFlags
1071
1072 .. versionadded:: 0.9
1073
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001074 An enumeration for CRL reasons.
1075
1076 .. attribute:: unspecified
1077
1078 It is unspecified why the certificate was revoked. This reason cannot
1079 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001080
1081 .. attribute:: key_compromise
1082
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001083 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001084
1085 .. attribute:: ca_compromise
1086
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001087 This reason indicates that the CA issuing the certificate was
1088 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001089
1090 .. attribute:: affiliation_changed
1091
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001092 This reason indicates that the subject's name or other information has
1093 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05001094
1095 .. attribute:: superseded
1096
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001097 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05001098
1099 .. attribute:: cessation_of_operation
1100
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001101 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05001102
1103 .. attribute:: certificate_hold
1104
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001105 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05001106
1107 .. attribute:: privilege_withdrawn
1108
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001109 This reason indicates that the privilege granted by this certificate
1110 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05001111
1112 .. attribute:: aa_compromise
1113
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001114 When an attribute authority has been compromised.
1115
1116 .. attribute:: remove_from_crl
1117
1118 This reason indicates that the certificate was on hold and should be
1119 removed from the CRL. This reason cannot be used as a reason flag
1120 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001121
Paul Kehrer16fae762015-05-01 23:14:20 -05001122.. class:: InhibitAnyPolicy
1123
1124 .. versionadded:: 1.0
1125
1126 The inhibit ``anyPolicy`` extension indicates that the special OID
1127 :data:`OID_ANY_POLICY`, is not considered an explicit match for other
1128 :class:`CertificatePolicies` except when it appears in an intermediate
1129 self-issued CA certificate. The value indicates the number of additional
1130 non-self-issued certificates that may appear in the path before
1131 :data:`OID_ANY_POLICY` is no longer permitted. For example, a value
1132 of one indicates that :data:`OID_ANY_POLICY` may be processed in
1133 certificates issued by the subject of this certificate, but not in
1134 additional certificates in the path.
1135
1136 .. attribute:: skip_certs
1137
1138 :type: int
1139
Paul Kehrer0d210922015-04-28 17:31:07 -05001140.. class:: CertificatePolicies
1141
1142 .. versionadded:: 0.9
1143
Paul Kehrer2e879742015-05-02 23:09:56 -05001144 The certificate policies extension is an iterable, containing one or more
1145 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05001146
1147Certificate Policies Classes
1148~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1149
1150These classes may be present within a :class:`CertificatePolicies` instance.
1151
1152.. class:: PolicyInformation
1153
1154 .. versionadded:: 0.9
1155
1156 Contains a policy identifier and an optional list of qualifiers.
1157
1158 .. attribute:: policy_identifier
1159
1160 :type: :class:`ObjectIdentifier`
1161
1162 .. attribute:: policy_qualifiers
1163
1164 :type: list
1165
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001166 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05001167 If the value is text it is a pointer to the practice statement
1168 published by the certificate authority. If it is a user notice it is
1169 meant for display to the relying party when the certificate is
1170 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05001171
Paul Kehrer0d210922015-04-28 17:31:07 -05001172.. class:: UserNotice
1173
1174 .. versionadded:: 0.9
1175
Paul Kehrer2e879742015-05-02 23:09:56 -05001176 User notices are intended for display to a relying party when a certificate
1177 is used. In practice, few if any UIs expose this data and it is a rarely
1178 encoded component.
1179
Paul Kehrer0d210922015-04-28 17:31:07 -05001180 .. attribute:: notice_reference
1181
1182 :type: :class:`NoticeReference` or None
1183
Paul Kehrer2e879742015-05-02 23:09:56 -05001184 The notice reference field names an organization and identifies,
1185 by number, a particular statement prepared by that organization.
1186
Paul Kehrer0d210922015-04-28 17:31:07 -05001187 .. attribute:: explicit_text
1188
Paul Kehrer2e879742015-05-02 23:09:56 -05001189 This field includes an arbitrary textual statement directly in the
1190 certificate.
1191
Paul Kehrer0d210922015-04-28 17:31:07 -05001192 :type: :term:`text`
1193
1194.. class:: NoticeReference
1195
Paul Kehrer2e879742015-05-02 23:09:56 -05001196 Notice reference can name an organization and provide information about
1197 notices related to the certificate. For example, it might identify the
1198 organization name and notice number 1. Application software could
1199 have a notice file containing the current set of notices for the named
1200 organization; the application would then extract the notice text from the
1201 file and display it. In practice this is rarely seen.
1202
Paul Kehrer0d210922015-04-28 17:31:07 -05001203 .. versionadded:: 0.9
1204
1205 .. attribute:: organization
1206
Paul Kehrer66c61702015-05-12 16:39:18 -05001207 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05001208
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05001209 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05001210
Paul Kehrer66c61702015-05-12 16:39:18 -05001211 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05001212
Paul Kehrer66c61702015-05-12 16:39:18 -05001213 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05001214
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001215Object Identifiers
1216~~~~~~~~~~~~~~~~~~
1217
Paul Kehrer4bb46492015-02-07 16:59:14 -06001218X.509 elements are frequently identified by :class:`ObjectIdentifier`
1219instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001220
Paul Kehrer56da2a52015-02-11 23:35:07 -06001221Name OIDs
1222~~~~~~~~~
1223
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001224.. data:: OID_COMMON_NAME
1225
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001226 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
1227 name would be encoded here for server certificates. :rfc:`2818` deprecates
1228 this practice and names of that type should now be located in a
Paul Kehrer4bb46492015-02-07 16:59:14 -06001229 SubjectAlternativeName extension. This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001230
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001231.. data:: OID_COUNTRY_NAME
1232
Paul Kehrer4bb46492015-02-07 16:59:14 -06001233 Corresponds to the dotted string ``"2.5.4.6"``. This OID is typically seen
1234 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001235
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001236.. data:: OID_LOCALITY_NAME
1237
Paul Kehrer4bb46492015-02-07 16:59:14 -06001238 Corresponds to the dotted string ``"2.5.4.7"``. This OID is typically seen
1239 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001240
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001241.. data:: OID_STATE_OR_PROVINCE_NAME
1242
Paul Kehrer4bb46492015-02-07 16:59:14 -06001243 Corresponds to the dotted string ``"2.5.4.8"``. This OID is typically seen
1244 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001245
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001246.. data:: OID_ORGANIZATION_NAME
1247
Paul Kehrer4bb46492015-02-07 16:59:14 -06001248 Corresponds to the dotted string ``"2.5.4.10"``. This OID is typically seen
1249 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001250
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001251.. data:: OID_ORGANIZATIONAL_UNIT_NAME
1252
Paul Kehrer4bb46492015-02-07 16:59:14 -06001253 Corresponds to the dotted string ``"2.5.4.11"``. This OID is typically seen
1254 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001255
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001256.. data:: OID_SERIAL_NUMBER
1257
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001258 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from the
1259 serial number of the certificate itself (which can be obtained with
Paul Kehrer4bb46492015-02-07 16:59:14 -06001260 :func:`Certificate.serial`). This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001261
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001262.. data:: OID_SURNAME
1263
Paul Kehrer4bb46492015-02-07 16:59:14 -06001264 Corresponds to the dotted string ``"2.5.4.4"``. This OID is typically seen
1265 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001266
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001267.. data:: OID_GIVEN_NAME
1268
Paul Kehrer4bb46492015-02-07 16:59:14 -06001269 Corresponds to the dotted string ``"2.5.4.42"``. This OID is typically seen
1270 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001271
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001272.. data:: OID_TITLE
1273
Paul Kehrer4bb46492015-02-07 16:59:14 -06001274 Corresponds to the dotted string ``"2.5.4.12"``. This OID is typically seen
1275 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001276
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001277.. data:: OID_GENERATION_QUALIFIER
1278
Paul Kehrer4bb46492015-02-07 16:59:14 -06001279 Corresponds to the dotted string ``"2.5.4.44"``. This OID is typically seen
1280 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001281
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001282.. data:: OID_DN_QUALIFIER
1283
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001284 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
1285 disambiguating information to add to the relative distinguished name of an
Paul Kehrer4bb46492015-02-07 16:59:14 -06001286 entry. See :rfc:`2256`. This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001287
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001288.. data:: OID_PSEUDONYM
1289
Paul Kehrer4bb46492015-02-07 16:59:14 -06001290 Corresponds to the dotted string ``"2.5.4.65"``. 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_DOMAIN_COMPONENT
1294
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001295 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
Paul Kehrer4bb46492015-02-07 16:59:14 -06001296 holding one component of a domain name. See :rfc:`4519`. This OID is
1297 typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001298
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001299.. data:: OID_EMAIL_ADDRESS
1300
Paul Kehrer4bb46492015-02-07 16:59:14 -06001301 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``. This OID is
1302 typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001303
Paul Kehrer56da2a52015-02-11 23:35:07 -06001304Signature Algorithm OIDs
1305~~~~~~~~~~~~~~~~~~~~~~~~
1306
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001307.. data:: OID_RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06001308
1309 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
1310 an MD5 digest signed by an RSA key.
1311
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001312.. data:: OID_RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06001313
1314 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
1315 a SHA1 digest signed by an RSA key.
1316
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001317.. data:: OID_RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06001318
1319 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
1320 a SHA224 digest signed by an RSA key.
1321
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001322.. data:: OID_RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06001323
1324 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
1325 a SHA256 digest signed by an RSA key.
1326
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001327.. data:: OID_RSA_WITH_SHA384
Paul Kehrer56da2a52015-02-11 23:35:07 -06001328
1329 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
1330 a SHA384 digest signed by an RSA key.
1331
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001332.. data:: OID_RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06001333
1334 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
1335 a SHA512 digest signed by an RSA key.
1336
Alex Gaynor3aadabf2015-06-23 22:06:21 -04001337.. data:: OID_ECDSA_WITH_SHA1
1338
1339 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
1340 digest signed by an ECDSA key.
1341
Paul Kehrer56da2a52015-02-11 23:35:07 -06001342.. data:: OID_ECDSA_WITH_SHA224
1343
1344 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
1345 a SHA224 digest signed by an ECDSA key.
1346
1347.. data:: OID_ECDSA_WITH_SHA256
1348
1349 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
1350 a SHA256 digest signed by an ECDSA key.
1351
1352.. data:: OID_ECDSA_WITH_SHA384
1353
1354 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
1355 a SHA384 digest signed by an ECDSA key.
1356
1357.. data:: OID_ECDSA_WITH_SHA512
1358
1359 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
1360 a SHA512 digest signed by an ECDSA key.
1361
1362.. data:: OID_DSA_WITH_SHA1
1363
1364 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
1365 a SHA1 digest signed by a DSA key.
1366
1367.. data:: OID_DSA_WITH_SHA224
1368
1369 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
1370 a SHA224 digest signed by a DSA key.
1371
1372.. data:: OID_DSA_WITH_SHA256
1373
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001374 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
Paul Kehrer56da2a52015-02-11 23:35:07 -06001375 a SHA256 digest signed by a DSA key.
1376
Paul Kehrerffa2a152015-03-31 08:18:25 -05001377.. _eku_oids:
1378
Paul Kehrere1513fa2015-03-30 23:08:17 -05001379Extended Key Usage OIDs
1380~~~~~~~~~~~~~~~~~~~~~~~
1381
1382.. data:: OID_SERVER_AUTH
1383
1384 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used to
1385 denote that a certificate may be used for TLS web server authentication.
1386
1387.. data:: OID_CLIENT_AUTH
1388
1389 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used to
1390 denote that a certificate may be used for TLS web client authentication.
1391
1392.. data:: OID_CODE_SIGNING
1393
1394 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used to
1395 denote that a certificate may be used for code signing.
1396
1397.. data:: OID_EMAIL_PROTECTION
1398
1399 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used to
1400 denote that a certificate may be used for email protection.
1401
1402.. data:: OID_TIME_STAMPING
1403
1404 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used to
1405 denote that a certificate may be used for time stamping.
1406
1407.. data:: OID_OCSP_SIGNING
1408
1409 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used to
1410 denote that a certificate may be used for signing OCSP responses.
1411
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001412Authority Information Access OIDs
1413~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1414
1415.. data:: OID_OCSP
1416
1417 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
1418 identifier for OCSP data in :class:`AccessDescription` objects.
1419
1420.. data:: OID_CA_ISSUERS
1421
1422 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
1423 identifier for CA issuer data in :class:`AccessDescription` objects.
1424
Paul Kehrer2e879742015-05-02 23:09:56 -05001425Policy Qualifier OIDs
1426~~~~~~~~~~~~~~~~~~~~~
1427
1428.. data:: OID_CPS_QUALIFIER
1429
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001430 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05001431
1432.. data:: OID_CPS_USER_NOTICE
1433
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001434 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05001435
Paul Kehrer16fae762015-05-01 23:14:20 -05001436.. data:: OID_ANY_POLICY
1437
1438 Corresponds to the dotted string ``"2.5.29.32.0"``.
1439
Paul Kehrer5553d572015-03-23 21:08:01 -05001440.. _extension_oids:
1441
Paul Kehrer2bb94642015-03-21 09:54:17 -05001442Extension OIDs
1443~~~~~~~~~~~~~~
1444
1445.. data:: OID_BASIC_CONSTRAINTS
1446
1447 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
Paul Kehrer611d3d32015-03-22 13:31:18 -05001448 :class:`BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05001449
Paul Kehrercecbbba2015-03-30 14:58:38 -05001450.. data:: OID_KEY_USAGE
1451
1452 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
1453 :class:`KeyUsage` extension type.
1454
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001455.. data:: OID_SUBJECT_ALTERNATIVE_NAME
1456
1457 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
1458 :class:`SubjectAlternativeName` extension type.
1459
Paul Kehrer99125c92015-06-07 18:37:10 -05001460.. data:: OID_ISSUER_ALTERNATIVE_NAME
1461
1462 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
1463 :class:`IssuerAlternativeName` extension type.
1464
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001465.. data:: OID_SUBJECT_KEY_IDENTIFIER
1466
1467 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
1468 :class:`SubjectKeyIdentifier` extension type.
1469
Paul Kehrere0017be2015-05-17 20:39:40 -06001470.. data:: OID_NAME_CONSTRAINTS
1471
1472 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
1473 :class:`NameConstraints` extension type.
1474
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001475.. data:: OID_CRL_DISTRIBUTION_POINTS
1476
1477 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
1478 :class:`CRLDistributionPoints` extension type.
1479
1480.. data:: OID_CERTIFICATE_POLICIES
1481
1482 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
1483 :class:`CertificatePolicies` extension type.
1484
1485.. data:: OID_AUTHORITY_KEY_IDENTIFIER
1486
1487 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
1488 :class:`AuthorityKeyIdentifier` extension type.
1489
1490.. data:: OID_EXTENDED_KEY_USAGE
1491
1492 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
1493 :class:`ExtendedKeyUsage` extension type.
1494
1495.. data:: OID_AUTHORITY_INFORMATION_ACCESS
1496
1497 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
1498 for the :class:`AuthorityInformationAccess` extension type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001499
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001500.. data:: OID_OCSP_NO_CHECK
1501
1502 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The identifier
1503 for the :class:`OCSPNoCheck` extension type.
1504
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001505Exceptions
1506~~~~~~~~~~
1507
Paul Kehrere76cd272014-12-14 19:00:51 -06001508.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10001509
1510 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10001511
Paul Kehrerd5cccf72014-12-15 17:20:33 -06001512 .. attribute:: parsed_version
1513
Paul Kehrerbbffc402014-12-17 13:33:55 -06001514 :type: int
1515
1516 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06001517
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001518.. class:: DuplicateExtension
1519
1520 This is raised when more than one X.509 extension of the same type is
1521 found within a certificate.
1522
1523 .. attribute:: oid
1524
1525 :type: :class:`ObjectIdentifier`
1526
1527 Returns the OID.
1528
1529.. class:: UnsupportedExtension
1530
1531 This is raised when a certificate contains an unsupported extension type.
1532
1533 .. attribute:: oid
1534
1535 :type: :class:`ObjectIdentifier`
1536
1537 Returns the OID.
1538
Paul Kehrerfa56a232015-03-17 13:14:03 -05001539.. class:: ExtensionNotFound
1540
1541 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
1542 an extension OID that is not present in the certificate.
1543
1544 .. attribute:: oid
1545
1546 :type: :class:`ObjectIdentifier`
1547
1548 Returns the OID.
1549
Paul Kehrer9089c912015-04-20 22:15:20 -05001550.. class:: UnsupportedGeneralNameType
1551
1552 This is raised when a certificate contains an unsupported general name
1553 type in an extension.
1554
Paul Kehrerbed07352015-04-21 08:31:10 -05001555 .. attribute:: type
1556
Paul Kehrer0a621bf2015-04-22 09:22:56 -05001557 :type: int
1558
1559 The integer value of the unsupported type. The complete list of
1560 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05001561
Paul Kehrer016e08a2014-11-26 09:41:18 -10001562
1563.. _`public key infrastructure`: https://en.wikipedia.org/wiki/Public_key_infrastructure
Paul Kehrera68fd332014-11-27 07:08:40 -10001564.. _`TLS`: https://en.wikipedia.org/wiki/Transport_Layer_Security
Paul Kehrerc7c9a432015-04-19 09:20:13 -05001565.. _`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 -05001566.. _`RFC 5280 section 4.2.1.6`: https://tools.ietf.org/html/rfc5280#section-4.2.1.6