blob: 0f55e8e44c22e9ea97a6f831d2142f821db6a50f [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()
Andre Carona9a51172015-06-06 20:18:44 -0400490 >>> builder = builder.subject_name(x509.Name([
Andre Carond259ee52015-06-02 23:47:11 -0400491 ... 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 Carona9a51172015-06-06 20:18:44 -0400506 .. method:: subject_name(name)
Andre Caron0ef595f2015-05-18 13:53:43 -0400507
Andre Caron341ff852015-06-06 20:14:31 -0400508 :param name: The :class:`~cryptography.x509.Name` of the certificate
509 subject.
510 :returns: A new
511 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400512
Andre Caron472fd692015-06-06 20:04:44 -0400513 .. method:: add_extension(extension, critical=False)
Andre Caron0ef595f2015-05-18 13:53:43 -0400514
Andre Caron341ff852015-06-06 20:14:31 -0400515 :param extension: The :class:`~cryptography.x509.Extension` to add to
516 the request.
Andre Caron472fd692015-06-06 20:04:44 -0400517 :param critical: Set to `True` if the extension must be understood and
518 handled by whoever reads the certificate.
Andre Caron341ff852015-06-06 20:14:31 -0400519 :returns: A new
520 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400521
522 .. method:: sign(backend, private_key, algorithm)
523
524 :param backend: Backend that will be used to sign the request.
525 Must support the
526 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
527 interface.
528
529 :param private_key: The
Andre Caron24f9bf42015-06-06 20:14:54 -0400530 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
531 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
532 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
Andre Caron0ef595f2015-05-18 13:53:43 -0400533 that will be used to sign the request. When the request is
534 signed by a certificate authority, the private key's associated
535 public key will be stored in the resulting certificate.
536
537 :param algorithm: The
538 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
539 that will be used to generate the request signature.
540
Andre Caron341ff852015-06-06 20:14:31 -0400541 :returns: A new
542 :class:`~cryptography.x509.CertificateSigningRequest`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400543
544
Paul Kehrer719d5362015-01-01 20:03:52 -0600545.. class:: Name
546
547 .. versionadded:: 0.8
548
Paul Kehrer53d8d492015-02-13 18:47:30 -0600549 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -0600550 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -0600551 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -0600552 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
553 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -0600554
Paul Kehrer53d8d492015-02-13 18:47:30 -0600555 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -0600556
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600557 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -0600558 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600559 >>> for attribute in cert.subject:
560 ... print(attribute)
561 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
562 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')>
563 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -0600564
Paul Kehrere901d642015-02-11 18:50:58 -0600565 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -0600566
Paul Kehrere901d642015-02-11 18:50:58 -0600567 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -0600568
Paul Kehrere901d642015-02-11 18:50:58 -0600569 :returns: A list of :class:`NameAttribute` instances that match the
570 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -0600571
572 .. doctest::
573
Paul Kehrere901d642015-02-11 18:50:58 -0600574 >>> cert.subject.get_attributes_for_oid(x509.OID_COMMON_NAME)
575 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -0600576
Paul Kehrere76cd272014-12-14 19:00:51 -0600577.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -1000578
579 .. versionadded:: 0.7
580
581 An enumeration for X.509 versions.
582
583 .. attribute:: v1
584
585 For version 1 X.509 certificates.
586
587 .. attribute:: v3
588
589 For version 3 X.509 certificates.
590
Paul Kehrer806bfb22015-02-02 17:05:24 -0600591.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600592
593 .. versionadded:: 0.8
594
Paul Kehrer834d22f2015-02-06 11:01:07 -0600595 An X.509 name consists of a list of NameAttribute instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600596
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600597 .. attribute:: oid
598
599 :type: :class:`ObjectIdentifier`
600
601 The attribute OID.
602
603 .. attribute:: value
604
Paul Kehrerd5852cb2015-01-30 08:25:23 -0600605 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600606
607 The value of the attribute.
608
609.. class:: ObjectIdentifier
610
611 .. versionadded:: 0.8
612
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600613 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -0600614 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600615
Paul Kehrerd44f9a62015-02-04 14:47:34 -0600616 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600617
618 :type: :class:`str`
619
Paul Kehrerfedf4f42015-02-06 11:22:07 -0600620 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600621
Paul Kehrer31bdf792015-03-25 14:11:00 -0500622.. _general_name_classes:
623
624General Name Classes
625~~~~~~~~~~~~~~~~~~~~
626
627.. class:: GeneralName
628
629 .. versionadded:: 0.9
630
631 This is the generic interface that all the following classes are registered
632 against.
633
634.. class:: RFC822Name
635
636 .. versionadded:: 0.9
637
638 This corresponds to an email address. For example, ``user@example.com``.
639
640 .. attribute:: value
641
642 :type: :term:`text`
643
644.. class:: DNSName
645
646 .. versionadded:: 0.9
647
648 This corresponds to a domain name. For example, ``cryptography.io``.
649
650 .. attribute:: value
651
652 :type: :term:`text`
653
654.. class:: DirectoryName
655
656 .. versionadded:: 0.9
657
658 This corresponds to a directory name.
659
660 .. attribute:: value
661
662 :type: :class:`Name`
663
664.. class:: UniformResourceIdentifier
665
666 .. versionadded:: 0.9
667
668 This corresponds to a uniform resource identifier. For example,
Paul Kehrerb8ef82e2015-04-22 16:04:24 -0500669 ``https://cryptography.io``. The URI is parsed and IDNA decoded (see
670 :rfc:`5895`).
671
672 .. note::
673
674 URIs that do not contain ``://`` in them will not be decoded.
Paul Kehrer31bdf792015-03-25 14:11:00 -0500675
676 .. attribute:: value
677
678 :type: :term:`text`
679
680.. class:: IPAddress
681
682 .. versionadded:: 0.9
683
684 This corresponds to an IP address.
685
686 .. attribute:: value
687
Paul Kehrereb177932015-05-17 18:33:33 -0700688 :type: :class:`~ipaddress.IPv4Address`,
689 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
690 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -0500691
692.. class:: RegisteredID
693
694 .. versionadded:: 0.9
695
696 This corresponds to a registered ID.
697
698 .. attribute:: value
699
700 :type: :class:`ObjectIdentifier`
701
Paul Kehrer8cf26422015-03-21 09:50:24 -0500702X.509 Extensions
703~~~~~~~~~~~~~~~~
704
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500705.. class:: Extensions
706
707 .. versionadded:: 0.9
708
709 An X.509 Extensions instance is an ordered list of extensions. The object
710 is iterable to get every extension.
711
Paul Kehrerfa56a232015-03-17 13:14:03 -0500712 .. method:: get_extension_for_oid(oid)
713
714 :param oid: An :class:`ObjectIdentifier` instance.
715
716 :returns: An instance of the extension class.
717
718 :raises cryptography.x509.ExtensionNotFound: If the certificate does
719 not have the extension requested.
720
Paul Kehrerfa56a232015-03-17 13:14:03 -0500721 .. doctest::
722
723 >>> cert.extensions.get_extension_for_oid(x509.OID_BASIC_CONSTRAINTS)
724 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
725
Paul Kehrer8cf26422015-03-21 09:50:24 -0500726.. class:: Extension
727
728 .. versionadded:: 0.9
729
Paul Kehrer85894662015-03-22 13:19:31 -0500730 .. attribute:: oid
731
732 :type: :class:`ObjectIdentifier`
733
Paul Kehrer5553d572015-03-23 21:08:01 -0500734 The :ref:`extension OID <extension_oids>`.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500735
736 .. attribute:: critical
737
738 :type: bool
739
Paul Kehrer58b75692015-03-22 23:24:58 -0500740 Determines whether a given extension is critical or not. :rfc:`5280`
741 requires that "A certificate-using system MUST reject the certificate
742 if it encounters a critical extension it does not recognize or a
743 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -0500744
Paul Kehrer85894662015-03-22 13:19:31 -0500745 .. attribute:: value
746
747 Returns an instance of the extension type corresponding to the OID.
748
Paul Kehrercecbbba2015-03-30 14:58:38 -0500749.. class:: KeyUsage
750
751 .. versionadded:: 0.9
752
753 The key usage extension defines the purpose of the key contained in the
754 certificate. The usage restriction might be employed when a key that could
755 be used for more than one operation is to be restricted. It corresponds to
756 :data:`OID_KEY_USAGE`.
757
758 .. attribute:: digital_signature
759
760 :type: bool
761
Paul Kehrer738407b2015-04-01 22:39:02 -0500762 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500763 digital signatures, other than signatures on certificates
764 (``key_cert_sign``) and CRLs (``crl_sign``).
765
766 .. attribute:: content_commitment
767
768 :type: bool
769
Paul Kehrer738407b2015-04-01 22:39:02 -0500770 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500771 digital signatures, other than signatures on certificates
772 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
773 non-repudiation service that protects against the signing entity
774 falsely denying some action. In the case of later conflict, a
775 reliable third party may determine the authenticity of the signed
776 data. This was called ``non_repudiation`` in older revisions of the
777 X.509 specification.
778
779 .. attribute:: key_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 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500785
786 .. attribute:: data_encipherment
787
788 :type: bool
789
Paul Kehrer738407b2015-04-01 22:39:02 -0500790 This purpose is set to true when the subject public key is used for
791 directly enciphering raw user data without the use of an intermediate
792 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500793
794 .. attribute:: key_agreement
795
796 :type: bool
797
Paul Kehrer738407b2015-04-01 22:39:02 -0500798 This purpose is set to true when the subject public key is used for key
799 agreement. For example, when a Diffie-Hellman key is to be used for
800 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500801
802 .. attribute:: key_cert_sign
803
804 :type: bool
805
Paul Kehrer738407b2015-04-01 22:39:02 -0500806 This purpose is set to true when the subject public key is used for
807 verifying signatures on public key certificates. If this purpose is set
808 to true then ``ca`` must be true in the :class:`BasicConstraints`
809 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500810
811 .. attribute:: crl_sign
812
813 :type: bool
814
Paul Kehrer738407b2015-04-01 22:39:02 -0500815 This purpose is set to true when the subject public key is used for
816 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500817
818 .. attribute:: encipher_only
819
820 :type: bool
821
Paul Kehrer738407b2015-04-01 22:39:02 -0500822 When this purposes is set to true and the ``key_agreement`` purpose is
823 also set, the subject public key may be used only for enciphering data
824 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500825
826 :raises ValueError: This is raised if accessed when ``key_agreement``
827 is false.
828
829 .. attribute:: decipher_only
830
831 :type: bool
832
Paul Kehrer738407b2015-04-01 22:39:02 -0500833 When this purposes is set to true and the ``key_agreement`` purpose is
834 also set, the subject public key may be used only for deciphering data
835 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500836
837 :raises ValueError: This is raised if accessed when ``key_agreement``
838 is false.
839
840
Paul Kehrer8cf26422015-03-21 09:50:24 -0500841.. class:: BasicConstraints
842
843 .. versionadded:: 0.9
844
Paul Kehrer85894662015-03-22 13:19:31 -0500845 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -0500846 certificate is allowed to sign additional certificates and what path
Paul Kehrer85894662015-03-22 13:19:31 -0500847 length restrictions may exist. It corresponds to
848 :data:`OID_BASIC_CONSTRAINTS`.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500849
850 .. attribute:: ca
851
852 :type: bool
853
854 Whether the certificate can sign certificates.
855
856 .. attribute:: path_length
857
Paul Kehrerfd1444c2015-03-21 19:47:05 -0500858 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -0500859
860 The maximum path length for certificates subordinate to this
861 certificate. This attribute only has meaning if ``ca`` is true.
862 If ``ca`` is true then a path length of None means there's no
863 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -0400864 If it is zero or greater then it defines the maximum length for a
865 subordinate CA's certificate chain. For example, a ``path_length`` of 1
866 means the certificate can sign a subordinate CA, but the subordinate CA
867 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500868
Paul Kehrerffa2a152015-03-31 08:18:25 -0500869.. class:: ExtendedKeyUsage
870
871 .. versionadded:: 0.9
872
873 This extension indicates one or more purposes for which the certified
874 public key may be used, in addition to or in place of the basic
875 purposes indicated in the key usage extension. The object is
876 iterable to obtain the list of :ref:`extended key usage OIDs <eku_oids>`.
877
Paul Kehrer4a1038e2015-05-18 10:28:31 -0700878.. class:: OCSPNoCheck
879
Paul Kehrer506a2152015-05-26 08:01:18 -0500880 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -0700881
882 This presence of this extension indicates that an OCSP client can trust a
883 responder for the lifetime of the responder's certificate. CAs issuing
884 such a certificate should realize that a compromise of the responder's key
885 is as serious as the compromise of a CA key used to sign CRLs, at least for
886 the validity period of this certificate. CA's may choose to issue this type
887 of certificate with a very short lifetime and renew it frequently. This
888 extension is only relevant when the certificate is an authorized OCSP
889 responder.
890
Paul Kehrere0017be2015-05-17 20:39:40 -0600891.. class:: NameConstraints
892
893 .. versionadded:: 1.0
894
895 The name constraints extension, which only has meaning in a CA certificate,
896 defines a name space within which all subject names in certificates issued
897 beneath the CA certificate must (or must not) be in. For specific details
898 on the way this extension should be processed see :rfc:`5280`.
899
900 .. attribute:: permitted_subtrees
901
902 :type: list of :class:`GeneralName` objects or None
903
904 The set of permitted name patterns. If a name matches this and an
905 element in ``excluded_subtrees`` it is invalid. At least one of
906 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
907
908 .. attribute:: excluded_subtrees
909
910 :type: list of :class:`GeneralName` objects or None
911
912 Any name matching a restriction in the ``excluded_subtrees`` field is
913 invalid regardless of information appearing in the
914 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
915 ``excluded_subtrees`` will be non-None.
916
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400917.. class:: AuthorityKeyIdentifier
918
919 .. versionadded:: 0.9
920
921 The authority key identifier extension provides a means of identifying the
922 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -0500923 This extension is typically used to assist in determining the appropriate
924 certificate chain. For more information about generation and use of this
925 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400926
927 .. attribute:: key_identifier
928
929 :type: bytes
930
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500931 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -0500932 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500933
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400934 .. attribute:: authority_cert_issuer
935
936 :type: :class:`Name` or None
937
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500938 The :class:`Name` of the issuer's issuer.
939
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400940 .. attribute:: authority_cert_serial_number
941
942 :type: int or None
943
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500944 The serial number of the issuer's issuer.
945
Paul Kehrer1eb82a62015-03-31 20:00:33 -0500946.. class:: SubjectKeyIdentifier
947
948 .. versionadded:: 0.9
949
950 The subject key identifier extension provides a means of identifying
951 certificates that contain a particular public key.
952
953 .. attribute:: digest
954
955 :type: bytes
956
957 The binary value of the identifier.
958
Paul Kehrer31bdf792015-03-25 14:11:00 -0500959.. class:: SubjectAlternativeName
960
961 .. versionadded:: 0.9
962
963 Subject alternative name is an X.509 extension that provides a list of
964 :ref:`general name <general_name_classes>` instances that provide a set
965 of identities for which the certificate is valid. The object is iterable to
966 get every element.
967
968 .. method:: get_values_for_type(type)
969
970 :param type: A :class:`GeneralName` provider. This is one of the
971 :ref:`general name classes <general_name_classes>`.
972
973 :returns: A list of values extracted from the matched general names.
974
Paul Kehrer93ae8052015-05-02 23:18:09 -0500975 .. doctest::
976
977 >>> from cryptography import x509
978 >>> from cryptography.hazmat.backends import default_backend
979 >>> from cryptography.hazmat.primitives import hashes
980 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -0500981 >>> # Get the subjectAltName extension from the certificate
Paul Kehrer93ae8052015-05-02 23:18:09 -0500982 >>> ext = cert.extensions.get_extension_for_oid(x509.OID_SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -0500983 >>> # Get the dNSName entries from the SAN extension
984 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer93ae8052015-05-02 23:18:09 -0500985 [u'www.cryptography.io', u'cryptography.io']
986
Paul Kehrer8cf26422015-03-21 09:50:24 -0500987
Paul Kehrer99125c92015-06-07 18:37:10 -0500988.. class:: IssuerAlternativeName
989
990 .. versionadded:: 1.0
991
992 Issuer 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 the certificate issuer. 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.
1003
1004
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001005.. class:: AuthorityInformationAccess
1006
1007 .. versionadded:: 0.9
1008
1009 The authority information access extension indicates how to access
1010 information and services for the issuer of the certificate in which
1011 the extension appears. Information and services may include online
1012 validation services (such as OCSP) and issuer data. It is an iterable,
1013 containing one or more :class:`AccessDescription` instances.
1014
1015
1016.. class:: AccessDescription
1017
Paul Kehrer5a485522015-05-06 00:29:12 -05001018 .. versionadded:: 0.9
1019
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001020 .. attribute:: access_method
1021
1022 :type: :class:`ObjectIdentifier`
1023
Paul Kehrerf506bca2015-05-02 22:31:47 -05001024 The access method defines what the ``access_location`` means. It must
1025 be either :data:`OID_OCSP` or :data:`OID_CA_ISSUERS`. If it is
1026 :data:`OID_OCSP` the access location will be where to obtain OCSP
1027 information for the certificate. If it is :data:`OID_CA_ISSUERS` the
1028 access location will provide additional information about the issuing
1029 certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001030
1031 .. attribute:: access_location
1032
1033 :type: :class:`GeneralName`
1034
Paul Kehrerf506bca2015-05-02 22:31:47 -05001035 Where to access the information defined by the access method.
1036
Paul Kehrer5a485522015-05-06 00:29:12 -05001037.. class:: CRLDistributionPoints
1038
1039 .. versionadded:: 0.9
1040
1041 The CRL distribution points extension identifies how CRL information is
1042 obtained. It is an iterable, containing one or more
1043 :class:`DistributionPoint` instances.
1044
1045.. class:: DistributionPoint
1046
1047 .. versionadded:: 0.9
1048
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001049 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05001050
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001051 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001052
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001053 This field describes methods to retrieve the CRL. At most one of
1054 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001055
1056 .. attribute:: relative_name
1057
1058 :type: :class:`Name` or None
1059
1060 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001061 issuer. At most one of ``full_name`` or ``relative_name`` will be
1062 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05001063
1064 .. attribute:: crl_issuer
1065
1066 :type: list of :class:`GeneralName` instances or None
1067
1068 Information about the issuer of the CRL.
1069
1070 .. attribute:: reasons
1071
Paul Kehrer3fd02602015-05-09 19:46:13 -05001072 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001073
1074 The reasons a given distribution point may be used for when performing
1075 revocation checks.
1076
1077.. class:: ReasonFlags
1078
1079 .. versionadded:: 0.9
1080
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001081 An enumeration for CRL reasons.
1082
1083 .. attribute:: unspecified
1084
1085 It is unspecified why the certificate was revoked. This reason cannot
1086 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001087
1088 .. attribute:: key_compromise
1089
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001090 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001091
1092 .. attribute:: ca_compromise
1093
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001094 This reason indicates that the CA issuing the certificate was
1095 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001096
1097 .. attribute:: affiliation_changed
1098
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001099 This reason indicates that the subject's name or other information has
1100 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05001101
1102 .. attribute:: superseded
1103
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001104 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05001105
1106 .. attribute:: cessation_of_operation
1107
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001108 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05001109
1110 .. attribute:: certificate_hold
1111
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001112 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05001113
1114 .. attribute:: privilege_withdrawn
1115
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001116 This reason indicates that the privilege granted by this certificate
1117 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05001118
1119 .. attribute:: aa_compromise
1120
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001121 When an attribute authority has been compromised.
1122
1123 .. attribute:: remove_from_crl
1124
1125 This reason indicates that the certificate was on hold and should be
1126 removed from the CRL. This reason cannot be used as a reason flag
1127 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001128
Paul Kehrer16fae762015-05-01 23:14:20 -05001129.. class:: InhibitAnyPolicy
1130
1131 .. versionadded:: 1.0
1132
1133 The inhibit ``anyPolicy`` extension indicates that the special OID
1134 :data:`OID_ANY_POLICY`, is not considered an explicit match for other
1135 :class:`CertificatePolicies` except when it appears in an intermediate
1136 self-issued CA certificate. The value indicates the number of additional
1137 non-self-issued certificates that may appear in the path before
1138 :data:`OID_ANY_POLICY` is no longer permitted. For example, a value
1139 of one indicates that :data:`OID_ANY_POLICY` may be processed in
1140 certificates issued by the subject of this certificate, but not in
1141 additional certificates in the path.
1142
1143 .. attribute:: skip_certs
1144
1145 :type: int
1146
Paul Kehrer0d210922015-04-28 17:31:07 -05001147.. class:: CertificatePolicies
1148
1149 .. versionadded:: 0.9
1150
Paul Kehrer2e879742015-05-02 23:09:56 -05001151 The certificate policies extension is an iterable, containing one or more
1152 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05001153
1154Certificate Policies Classes
1155~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1156
1157These classes may be present within a :class:`CertificatePolicies` instance.
1158
1159.. class:: PolicyInformation
1160
1161 .. versionadded:: 0.9
1162
1163 Contains a policy identifier and an optional list of qualifiers.
1164
1165 .. attribute:: policy_identifier
1166
1167 :type: :class:`ObjectIdentifier`
1168
1169 .. attribute:: policy_qualifiers
1170
1171 :type: list
1172
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001173 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05001174 If the value is text it is a pointer to the practice statement
1175 published by the certificate authority. If it is a user notice it is
1176 meant for display to the relying party when the certificate is
1177 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05001178
Paul Kehrer0d210922015-04-28 17:31:07 -05001179.. class:: UserNotice
1180
1181 .. versionadded:: 0.9
1182
Paul Kehrer2e879742015-05-02 23:09:56 -05001183 User notices are intended for display to a relying party when a certificate
1184 is used. In practice, few if any UIs expose this data and it is a rarely
1185 encoded component.
1186
Paul Kehrer0d210922015-04-28 17:31:07 -05001187 .. attribute:: notice_reference
1188
1189 :type: :class:`NoticeReference` or None
1190
Paul Kehrer2e879742015-05-02 23:09:56 -05001191 The notice reference field names an organization and identifies,
1192 by number, a particular statement prepared by that organization.
1193
Paul Kehrer0d210922015-04-28 17:31:07 -05001194 .. attribute:: explicit_text
1195
Paul Kehrer2e879742015-05-02 23:09:56 -05001196 This field includes an arbitrary textual statement directly in the
1197 certificate.
1198
Paul Kehrer0d210922015-04-28 17:31:07 -05001199 :type: :term:`text`
1200
1201.. class:: NoticeReference
1202
Paul Kehrer2e879742015-05-02 23:09:56 -05001203 Notice reference can name an organization and provide information about
1204 notices related to the certificate. For example, it might identify the
1205 organization name and notice number 1. Application software could
1206 have a notice file containing the current set of notices for the named
1207 organization; the application would then extract the notice text from the
1208 file and display it. In practice this is rarely seen.
1209
Paul Kehrer0d210922015-04-28 17:31:07 -05001210 .. versionadded:: 0.9
1211
1212 .. attribute:: organization
1213
Paul Kehrer66c61702015-05-12 16:39:18 -05001214 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05001215
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05001216 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05001217
Paul Kehrer66c61702015-05-12 16:39:18 -05001218 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05001219
Paul Kehrer66c61702015-05-12 16:39:18 -05001220 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05001221
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001222Object Identifiers
1223~~~~~~~~~~~~~~~~~~
1224
Paul Kehrer4bb46492015-02-07 16:59:14 -06001225X.509 elements are frequently identified by :class:`ObjectIdentifier`
1226instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001227
Paul Kehrer56da2a52015-02-11 23:35:07 -06001228Name OIDs
1229~~~~~~~~~
1230
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001231.. data:: OID_COMMON_NAME
1232
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001233 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
1234 name would be encoded here for server certificates. :rfc:`2818` deprecates
1235 this practice and names of that type should now be located in a
Paul Kehrer4bb46492015-02-07 16:59:14 -06001236 SubjectAlternativeName extension. This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001237
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001238.. data:: OID_COUNTRY_NAME
1239
Paul Kehrer4bb46492015-02-07 16:59:14 -06001240 Corresponds to the dotted string ``"2.5.4.6"``. This OID is typically seen
1241 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001242
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001243.. data:: OID_LOCALITY_NAME
1244
Paul Kehrer4bb46492015-02-07 16:59:14 -06001245 Corresponds to the dotted string ``"2.5.4.7"``. This OID is typically seen
1246 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001247
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001248.. data:: OID_STATE_OR_PROVINCE_NAME
1249
Paul Kehrer4bb46492015-02-07 16:59:14 -06001250 Corresponds to the dotted string ``"2.5.4.8"``. This OID is typically seen
1251 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001252
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001253.. data:: OID_ORGANIZATION_NAME
1254
Paul Kehrer4bb46492015-02-07 16:59:14 -06001255 Corresponds to the dotted string ``"2.5.4.10"``. This OID is typically seen
1256 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001257
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001258.. data:: OID_ORGANIZATIONAL_UNIT_NAME
1259
Paul Kehrer4bb46492015-02-07 16:59:14 -06001260 Corresponds to the dotted string ``"2.5.4.11"``. This OID is typically seen
1261 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001262
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001263.. data:: OID_SERIAL_NUMBER
1264
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001265 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from the
1266 serial number of the certificate itself (which can be obtained with
Paul Kehrer4bb46492015-02-07 16:59:14 -06001267 :func:`Certificate.serial`). This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001268
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001269.. data:: OID_SURNAME
1270
Paul Kehrer4bb46492015-02-07 16:59:14 -06001271 Corresponds to the dotted string ``"2.5.4.4"``. This OID is typically seen
1272 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001273
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001274.. data:: OID_GIVEN_NAME
1275
Paul Kehrer4bb46492015-02-07 16:59:14 -06001276 Corresponds to the dotted string ``"2.5.4.42"``. This OID is typically seen
1277 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001278
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001279.. data:: OID_TITLE
1280
Paul Kehrer4bb46492015-02-07 16:59:14 -06001281 Corresponds to the dotted string ``"2.5.4.12"``. This OID is typically seen
1282 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001283
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001284.. data:: OID_GENERATION_QUALIFIER
1285
Paul Kehrer4bb46492015-02-07 16:59:14 -06001286 Corresponds to the dotted string ``"2.5.4.44"``. This OID is typically seen
1287 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001288
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001289.. data:: OID_DN_QUALIFIER
1290
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001291 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
1292 disambiguating information to add to the relative distinguished name of an
Paul Kehrer4bb46492015-02-07 16:59:14 -06001293 entry. See :rfc:`2256`. This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001294
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001295.. data:: OID_PSEUDONYM
1296
Paul Kehrer4bb46492015-02-07 16:59:14 -06001297 Corresponds to the dotted string ``"2.5.4.65"``. This OID is typically seen
1298 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001299
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001300.. data:: OID_DOMAIN_COMPONENT
1301
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001302 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
Paul Kehrer4bb46492015-02-07 16:59:14 -06001303 holding one component of a domain name. See :rfc:`4519`. This OID is
1304 typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001305
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001306.. data:: OID_EMAIL_ADDRESS
1307
Paul Kehrer4bb46492015-02-07 16:59:14 -06001308 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``. This OID is
1309 typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001310
Paul Kehrer56da2a52015-02-11 23:35:07 -06001311Signature Algorithm OIDs
1312~~~~~~~~~~~~~~~~~~~~~~~~
1313
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001314.. data:: OID_RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06001315
1316 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
1317 an MD5 digest signed by an RSA key.
1318
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001319.. data:: OID_RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06001320
1321 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
1322 a SHA1 digest signed by an RSA key.
1323
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001324.. data:: OID_RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06001325
1326 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
1327 a SHA224 digest signed by an RSA key.
1328
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001329.. data:: OID_RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06001330
1331 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
1332 a SHA256 digest signed by an RSA key.
1333
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001334.. data:: OID_RSA_WITH_SHA384
Paul Kehrer56da2a52015-02-11 23:35:07 -06001335
1336 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
1337 a SHA384 digest signed by an RSA key.
1338
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001339.. data:: OID_RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06001340
1341 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
1342 a SHA512 digest signed by an RSA key.
1343
Alex Gaynor3aadabf2015-06-23 22:06:21 -04001344.. data:: OID_ECDSA_WITH_SHA1
1345
1346 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
1347 digest signed by an ECDSA key.
1348
Paul Kehrer56da2a52015-02-11 23:35:07 -06001349.. data:: OID_ECDSA_WITH_SHA224
1350
1351 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
1352 a SHA224 digest signed by an ECDSA key.
1353
1354.. data:: OID_ECDSA_WITH_SHA256
1355
1356 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
1357 a SHA256 digest signed by an ECDSA key.
1358
1359.. data:: OID_ECDSA_WITH_SHA384
1360
1361 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
1362 a SHA384 digest signed by an ECDSA key.
1363
1364.. data:: OID_ECDSA_WITH_SHA512
1365
1366 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
1367 a SHA512 digest signed by an ECDSA key.
1368
1369.. data:: OID_DSA_WITH_SHA1
1370
1371 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
1372 a SHA1 digest signed by a DSA key.
1373
1374.. data:: OID_DSA_WITH_SHA224
1375
1376 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
1377 a SHA224 digest signed by a DSA key.
1378
1379.. data:: OID_DSA_WITH_SHA256
1380
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001381 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
Paul Kehrer56da2a52015-02-11 23:35:07 -06001382 a SHA256 digest signed by a DSA key.
1383
Paul Kehrerffa2a152015-03-31 08:18:25 -05001384.. _eku_oids:
1385
Paul Kehrere1513fa2015-03-30 23:08:17 -05001386Extended Key Usage OIDs
1387~~~~~~~~~~~~~~~~~~~~~~~
1388
1389.. data:: OID_SERVER_AUTH
1390
1391 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used to
1392 denote that a certificate may be used for TLS web server authentication.
1393
1394.. data:: OID_CLIENT_AUTH
1395
1396 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used to
1397 denote that a certificate may be used for TLS web client authentication.
1398
1399.. data:: OID_CODE_SIGNING
1400
1401 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used to
1402 denote that a certificate may be used for code signing.
1403
1404.. data:: OID_EMAIL_PROTECTION
1405
1406 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used to
1407 denote that a certificate may be used for email protection.
1408
1409.. data:: OID_TIME_STAMPING
1410
1411 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used to
1412 denote that a certificate may be used for time stamping.
1413
1414.. data:: OID_OCSP_SIGNING
1415
1416 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used to
1417 denote that a certificate may be used for signing OCSP responses.
1418
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001419Authority Information Access OIDs
1420~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1421
1422.. data:: OID_OCSP
1423
1424 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
1425 identifier for OCSP data in :class:`AccessDescription` objects.
1426
1427.. data:: OID_CA_ISSUERS
1428
1429 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
1430 identifier for CA issuer data in :class:`AccessDescription` objects.
1431
Paul Kehrer2e879742015-05-02 23:09:56 -05001432Policy Qualifier OIDs
1433~~~~~~~~~~~~~~~~~~~~~
1434
1435.. data:: OID_CPS_QUALIFIER
1436
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001437 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05001438
1439.. data:: OID_CPS_USER_NOTICE
1440
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001441 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05001442
Paul Kehrer16fae762015-05-01 23:14:20 -05001443.. data:: OID_ANY_POLICY
1444
1445 Corresponds to the dotted string ``"2.5.29.32.0"``.
1446
Paul Kehrer5553d572015-03-23 21:08:01 -05001447.. _extension_oids:
1448
Paul Kehrer2bb94642015-03-21 09:54:17 -05001449Extension OIDs
1450~~~~~~~~~~~~~~
1451
1452.. data:: OID_BASIC_CONSTRAINTS
1453
1454 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
Paul Kehrer611d3d32015-03-22 13:31:18 -05001455 :class:`BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05001456
Paul Kehrercecbbba2015-03-30 14:58:38 -05001457.. data:: OID_KEY_USAGE
1458
1459 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
1460 :class:`KeyUsage` extension type.
1461
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001462.. data:: OID_SUBJECT_ALTERNATIVE_NAME
1463
1464 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
1465 :class:`SubjectAlternativeName` extension type.
1466
Paul Kehrer99125c92015-06-07 18:37:10 -05001467.. data:: OID_ISSUER_ALTERNATIVE_NAME
1468
1469 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
1470 :class:`IssuerAlternativeName` extension type.
1471
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001472.. data:: OID_SUBJECT_KEY_IDENTIFIER
1473
1474 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
1475 :class:`SubjectKeyIdentifier` extension type.
1476
Paul Kehrere0017be2015-05-17 20:39:40 -06001477.. data:: OID_NAME_CONSTRAINTS
1478
1479 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
1480 :class:`NameConstraints` extension type.
1481
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001482.. data:: OID_CRL_DISTRIBUTION_POINTS
1483
1484 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
1485 :class:`CRLDistributionPoints` extension type.
1486
1487.. data:: OID_CERTIFICATE_POLICIES
1488
1489 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
1490 :class:`CertificatePolicies` extension type.
1491
1492.. data:: OID_AUTHORITY_KEY_IDENTIFIER
1493
1494 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
1495 :class:`AuthorityKeyIdentifier` extension type.
1496
1497.. data:: OID_EXTENDED_KEY_USAGE
1498
1499 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
1500 :class:`ExtendedKeyUsage` extension type.
1501
1502.. data:: OID_AUTHORITY_INFORMATION_ACCESS
1503
1504 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
1505 for the :class:`AuthorityInformationAccess` extension type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001506
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001507.. data:: OID_OCSP_NO_CHECK
1508
1509 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The identifier
1510 for the :class:`OCSPNoCheck` extension type.
1511
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001512Exceptions
1513~~~~~~~~~~
1514
Paul Kehrere76cd272014-12-14 19:00:51 -06001515.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10001516
1517 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10001518
Paul Kehrerd5cccf72014-12-15 17:20:33 -06001519 .. attribute:: parsed_version
1520
Paul Kehrerbbffc402014-12-17 13:33:55 -06001521 :type: int
1522
1523 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06001524
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001525.. class:: DuplicateExtension
1526
1527 This is raised when more than one X.509 extension of the same type is
1528 found within a certificate.
1529
1530 .. attribute:: oid
1531
1532 :type: :class:`ObjectIdentifier`
1533
1534 Returns the OID.
1535
1536.. class:: UnsupportedExtension
1537
1538 This is raised when a certificate contains an unsupported extension type.
1539
1540 .. attribute:: oid
1541
1542 :type: :class:`ObjectIdentifier`
1543
1544 Returns the OID.
1545
Paul Kehrerfa56a232015-03-17 13:14:03 -05001546.. class:: ExtensionNotFound
1547
1548 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
1549 an extension OID that is not present in the certificate.
1550
1551 .. attribute:: oid
1552
1553 :type: :class:`ObjectIdentifier`
1554
1555 Returns the OID.
1556
Paul Kehrer9089c912015-04-20 22:15:20 -05001557.. class:: UnsupportedGeneralNameType
1558
1559 This is raised when a certificate contains an unsupported general name
1560 type in an extension.
1561
Paul Kehrerbed07352015-04-21 08:31:10 -05001562 .. attribute:: type
1563
Paul Kehrer0a621bf2015-04-22 09:22:56 -05001564 :type: int
1565
1566 The integer value of the unsupported type. The complete list of
1567 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05001568
Paul Kehrer016e08a2014-11-26 09:41:18 -10001569
1570.. _`public key infrastructure`: https://en.wikipedia.org/wiki/Public_key_infrastructure
Paul Kehrera68fd332014-11-27 07:08:40 -10001571.. _`TLS`: https://en.wikipedia.org/wiki/Transport_Layer_Security
Paul Kehrerc7c9a432015-04-19 09:20:13 -05001572.. _`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 -05001573.. _`RFC 5280 section 4.2.1.6`: https://tools.ietf.org/html/rfc5280#section-4.2.1.6