blob: 9ef8e1496235fe271abe6206794a5b2f4b7a5c36 [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
211 :return bytes: The fingerprint using the supplied hash algorithm as
212 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 Kehrerfa56a232015-03-17 13:14:03 -0500316 .. doctest::
317
318 >>> for ext in cert.extensions:
319 ... print(ext)
Paul Kehrerd774de92015-05-03 10:52:25 -0500320 <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 -0400321 <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 -0400322 <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 Kehrerfa56a232015-03-17 13:14:03 -0500323 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
324
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500325X.509 CSR (Certificate Signing Request) Object
326~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600327
Paul Kehrera1a1f232015-03-15 15:34:35 -0500328.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600329
330 .. versionadded:: 0.9
331
332 .. method:: public_key()
333
334 :type:
335 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
336 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
337 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
338
339 The public key associated with the request.
340
341 .. doctest::
342
343 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500344 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600345 >>> isinstance(public_key, rsa.RSAPublicKey)
346 True
347
348 .. attribute:: subject
349
350 :type: :class:`Name`
351
352 The :class:`Name` of the subject.
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 request.
361
362 .. doctest::
363
364 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500365 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600366 True
367
Paul Kehrer719d5362015-01-01 20:03:52 -0600368.. class:: Name
369
370 .. versionadded:: 0.8
371
Paul Kehrer53d8d492015-02-13 18:47:30 -0600372 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -0600373 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -0600374 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -0600375 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
376 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -0600377
Paul Kehrer53d8d492015-02-13 18:47:30 -0600378 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -0600379
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600380 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -0600381 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600382 >>> for attribute in cert.subject:
383 ... print(attribute)
384 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
385 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')>
386 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -0600387
Paul Kehrere901d642015-02-11 18:50:58 -0600388 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -0600389
Paul Kehrere901d642015-02-11 18:50:58 -0600390 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -0600391
Paul Kehrere901d642015-02-11 18:50:58 -0600392 :returns: A list of :class:`NameAttribute` instances that match the
393 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -0600394
395 .. doctest::
396
Paul Kehrere901d642015-02-11 18:50:58 -0600397 >>> cert.subject.get_attributes_for_oid(x509.OID_COMMON_NAME)
398 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -0600399
Paul Kehrere76cd272014-12-14 19:00:51 -0600400.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -1000401
402 .. versionadded:: 0.7
403
404 An enumeration for X.509 versions.
405
406 .. attribute:: v1
407
408 For version 1 X.509 certificates.
409
410 .. attribute:: v3
411
412 For version 3 X.509 certificates.
413
Paul Kehrer806bfb22015-02-02 17:05:24 -0600414.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600415
416 .. versionadded:: 0.8
417
Paul Kehrer834d22f2015-02-06 11:01:07 -0600418 An X.509 name consists of a list of NameAttribute instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600419
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600420 .. attribute:: oid
421
422 :type: :class:`ObjectIdentifier`
423
424 The attribute OID.
425
426 .. attribute:: value
427
Paul Kehrerd5852cb2015-01-30 08:25:23 -0600428 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600429
430 The value of the attribute.
431
432.. class:: ObjectIdentifier
433
434 .. versionadded:: 0.8
435
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600436 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -0600437 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600438
Paul Kehrerd44f9a62015-02-04 14:47:34 -0600439 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600440
441 :type: :class:`str`
442
Paul Kehrerfedf4f42015-02-06 11:22:07 -0600443 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600444
Paul Kehrer31bdf792015-03-25 14:11:00 -0500445.. _general_name_classes:
446
447General Name Classes
448~~~~~~~~~~~~~~~~~~~~
449
450.. class:: GeneralName
451
452 .. versionadded:: 0.9
453
454 This is the generic interface that all the following classes are registered
455 against.
456
457.. class:: RFC822Name
458
459 .. versionadded:: 0.9
460
461 This corresponds to an email address. For example, ``user@example.com``.
462
463 .. attribute:: value
464
465 :type: :term:`text`
466
467.. class:: DNSName
468
469 .. versionadded:: 0.9
470
471 This corresponds to a domain name. For example, ``cryptography.io``.
472
473 .. attribute:: value
474
475 :type: :term:`text`
476
477.. class:: DirectoryName
478
479 .. versionadded:: 0.9
480
481 This corresponds to a directory name.
482
483 .. attribute:: value
484
485 :type: :class:`Name`
486
487.. class:: UniformResourceIdentifier
488
489 .. versionadded:: 0.9
490
491 This corresponds to a uniform resource identifier. For example,
Paul Kehrerb8ef82e2015-04-22 16:04:24 -0500492 ``https://cryptography.io``. The URI is parsed and IDNA decoded (see
493 :rfc:`5895`).
494
495 .. note::
496
497 URIs that do not contain ``://`` in them will not be decoded.
Paul Kehrer31bdf792015-03-25 14:11:00 -0500498
499 .. attribute:: value
500
501 :type: :term:`text`
502
503.. class:: IPAddress
504
505 .. versionadded:: 0.9
506
507 This corresponds to an IP address.
508
509 .. attribute:: value
510
511 :type: :class:`~ipaddress.IPv4Address` or
512 :class:`~ipaddress.IPv6Address`.
513
514.. class:: RegisteredID
515
516 .. versionadded:: 0.9
517
518 This corresponds to a registered ID.
519
520 .. attribute:: value
521
522 :type: :class:`ObjectIdentifier`
523
Paul Kehrer8cf26422015-03-21 09:50:24 -0500524X.509 Extensions
525~~~~~~~~~~~~~~~~
526
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500527.. class:: Extensions
528
529 .. versionadded:: 0.9
530
531 An X.509 Extensions instance is an ordered list of extensions. The object
532 is iterable to get every extension.
533
Paul Kehrerfa56a232015-03-17 13:14:03 -0500534 .. method:: get_extension_for_oid(oid)
535
536 :param oid: An :class:`ObjectIdentifier` instance.
537
538 :returns: An instance of the extension class.
539
540 :raises cryptography.x509.ExtensionNotFound: If the certificate does
541 not have the extension requested.
542
Paul Kehrerfa56a232015-03-17 13:14:03 -0500543 .. doctest::
544
545 >>> cert.extensions.get_extension_for_oid(x509.OID_BASIC_CONSTRAINTS)
546 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
547
Paul Kehrer8cf26422015-03-21 09:50:24 -0500548.. class:: Extension
549
550 .. versionadded:: 0.9
551
Paul Kehrer85894662015-03-22 13:19:31 -0500552 .. attribute:: oid
553
554 :type: :class:`ObjectIdentifier`
555
Paul Kehrer5553d572015-03-23 21:08:01 -0500556 The :ref:`extension OID <extension_oids>`.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500557
558 .. attribute:: critical
559
560 :type: bool
561
Paul Kehrer58b75692015-03-22 23:24:58 -0500562 Determines whether a given extension is critical or not. :rfc:`5280`
563 requires that "A certificate-using system MUST reject the certificate
564 if it encounters a critical extension it does not recognize or a
565 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -0500566
Paul Kehrer85894662015-03-22 13:19:31 -0500567 .. attribute:: value
568
569 Returns an instance of the extension type corresponding to the OID.
570
Paul Kehrercecbbba2015-03-30 14:58:38 -0500571.. class:: KeyUsage
572
573 .. versionadded:: 0.9
574
575 The key usage extension defines the purpose of the key contained in the
576 certificate. The usage restriction might be employed when a key that could
577 be used for more than one operation is to be restricted. It corresponds to
578 :data:`OID_KEY_USAGE`.
579
580 .. attribute:: digital_signature
581
582 :type: bool
583
Paul Kehrer738407b2015-04-01 22:39:02 -0500584 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500585 digital signatures, other than signatures on certificates
586 (``key_cert_sign``) and CRLs (``crl_sign``).
587
588 .. attribute:: content_commitment
589
590 :type: bool
591
Paul Kehrer738407b2015-04-01 22:39:02 -0500592 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500593 digital signatures, other than signatures on certificates
594 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
595 non-repudiation service that protects against the signing entity
596 falsely denying some action. In the case of later conflict, a
597 reliable third party may determine the authenticity of the signed
598 data. This was called ``non_repudiation`` in older revisions of the
599 X.509 specification.
600
601 .. attribute:: key_encipherment
602
603 :type: bool
604
Paul Kehrer738407b2015-04-01 22:39:02 -0500605 This purpose is set to true when the subject public key is used for
606 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500607
608 .. attribute:: data_encipherment
609
610 :type: bool
611
Paul Kehrer738407b2015-04-01 22:39:02 -0500612 This purpose is set to true when the subject public key is used for
613 directly enciphering raw user data without the use of an intermediate
614 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500615
616 .. attribute:: key_agreement
617
618 :type: bool
619
Paul Kehrer738407b2015-04-01 22:39:02 -0500620 This purpose is set to true when the subject public key is used for key
621 agreement. For example, when a Diffie-Hellman key is to be used for
622 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500623
624 .. attribute:: key_cert_sign
625
626 :type: bool
627
Paul Kehrer738407b2015-04-01 22:39:02 -0500628 This purpose is set to true when the subject public key is used for
629 verifying signatures on public key certificates. If this purpose is set
630 to true then ``ca`` must be true in the :class:`BasicConstraints`
631 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500632
633 .. attribute:: crl_sign
634
635 :type: bool
636
Paul Kehrer738407b2015-04-01 22:39:02 -0500637 This purpose is set to true when the subject public key is used for
638 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500639
640 .. attribute:: encipher_only
641
642 :type: bool
643
Paul Kehrer738407b2015-04-01 22:39:02 -0500644 When this purposes is set to true and the ``key_agreement`` purpose is
645 also set, the subject public key may be used only for enciphering data
646 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500647
648 :raises ValueError: This is raised if accessed when ``key_agreement``
649 is false.
650
651 .. attribute:: decipher_only
652
653 :type: bool
654
Paul Kehrer738407b2015-04-01 22:39:02 -0500655 When this purposes is set to true and the ``key_agreement`` purpose is
656 also set, the subject public key may be used only for deciphering data
657 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500658
659 :raises ValueError: This is raised if accessed when ``key_agreement``
660 is false.
661
662
Paul Kehrer8cf26422015-03-21 09:50:24 -0500663.. class:: BasicConstraints
664
665 .. versionadded:: 0.9
666
Paul Kehrer85894662015-03-22 13:19:31 -0500667 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -0500668 certificate is allowed to sign additional certificates and what path
Paul Kehrer85894662015-03-22 13:19:31 -0500669 length restrictions may exist. It corresponds to
670 :data:`OID_BASIC_CONSTRAINTS`.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500671
672 .. attribute:: ca
673
674 :type: bool
675
676 Whether the certificate can sign certificates.
677
678 .. attribute:: path_length
679
Paul Kehrerfd1444c2015-03-21 19:47:05 -0500680 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -0500681
682 The maximum path length for certificates subordinate to this
683 certificate. This attribute only has meaning if ``ca`` is true.
684 If ``ca`` is true then a path length of None means there's no
685 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -0400686 If it is zero or greater then it defines the maximum length for a
687 subordinate CA's certificate chain. For example, a ``path_length`` of 1
688 means the certificate can sign a subordinate CA, but the subordinate CA
689 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500690
Paul Kehrerffa2a152015-03-31 08:18:25 -0500691.. class:: ExtendedKeyUsage
692
693 .. versionadded:: 0.9
694
695 This extension indicates one or more purposes for which the certified
696 public key may be used, in addition to or in place of the basic
697 purposes indicated in the key usage extension. The object is
698 iterable to obtain the list of :ref:`extended key usage OIDs <eku_oids>`.
699
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400700.. class:: AuthorityKeyIdentifier
701
702 .. versionadded:: 0.9
703
704 The authority key identifier extension provides a means of identifying the
705 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -0500706 This extension is typically used to assist in determining the appropriate
707 certificate chain. For more information about generation and use of this
708 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400709
710 .. attribute:: key_identifier
711
712 :type: bytes
713
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500714 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -0500715 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500716
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400717 .. attribute:: authority_cert_issuer
718
719 :type: :class:`Name` or None
720
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500721 The :class:`Name` of the issuer's issuer.
722
Paul Kehrer2eb4ed92015-04-11 15:33:45 -0400723 .. attribute:: authority_cert_serial_number
724
725 :type: int or None
726
Paul Kehrer9104b1d2015-04-18 09:23:44 -0500727 The serial number of the issuer's issuer.
728
Paul Kehrer1eb82a62015-03-31 20:00:33 -0500729.. class:: SubjectKeyIdentifier
730
731 .. versionadded:: 0.9
732
733 The subject key identifier extension provides a means of identifying
734 certificates that contain a particular public key.
735
736 .. attribute:: digest
737
738 :type: bytes
739
740 The binary value of the identifier.
741
Paul Kehrer31bdf792015-03-25 14:11:00 -0500742.. class:: SubjectAlternativeName
743
744 .. versionadded:: 0.9
745
746 Subject alternative name is an X.509 extension that provides a list of
747 :ref:`general name <general_name_classes>` instances that provide a set
748 of identities for which the certificate is valid. The object is iterable to
749 get every element.
750
751 .. method:: get_values_for_type(type)
752
753 :param type: A :class:`GeneralName` provider. This is one of the
754 :ref:`general name classes <general_name_classes>`.
755
756 :returns: A list of values extracted from the matched general names.
757
Paul Kehrer93ae8052015-05-02 23:18:09 -0500758 .. doctest::
759
760 >>> from cryptography import x509
761 >>> from cryptography.hazmat.backends import default_backend
762 >>> from cryptography.hazmat.primitives import hashes
763 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -0500764 >>> # Get the subjectAltName extension from the certificate
Paul Kehrer93ae8052015-05-02 23:18:09 -0500765 >>> ext = cert.extensions.get_extension_for_oid(x509.OID_SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -0500766 >>> # Get the dNSName entries from the SAN extension
767 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer93ae8052015-05-02 23:18:09 -0500768 [u'www.cryptography.io', u'cryptography.io']
769
Paul Kehrer8cf26422015-03-21 09:50:24 -0500770
Paul Kehrer3e6d5582015-05-02 21:57:56 -0500771.. class:: AuthorityInformationAccess
772
773 .. versionadded:: 0.9
774
775 The authority information access extension indicates how to access
776 information and services for the issuer of the certificate in which
777 the extension appears. Information and services may include online
778 validation services (such as OCSP) and issuer data. It is an iterable,
779 containing one or more :class:`AccessDescription` instances.
780
781
782.. class:: AccessDescription
783
Paul Kehrer5a485522015-05-06 00:29:12 -0500784 .. versionadded:: 0.9
785
Paul Kehrer3e6d5582015-05-02 21:57:56 -0500786 .. attribute:: access_method
787
788 :type: :class:`ObjectIdentifier`
789
Paul Kehrerf506bca2015-05-02 22:31:47 -0500790 The access method defines what the ``access_location`` means. It must
791 be either :data:`OID_OCSP` or :data:`OID_CA_ISSUERS`. If it is
792 :data:`OID_OCSP` the access location will be where to obtain OCSP
793 information for the certificate. If it is :data:`OID_CA_ISSUERS` the
794 access location will provide additional information about the issuing
795 certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -0500796
797 .. attribute:: access_location
798
799 :type: :class:`GeneralName`
800
Paul Kehrerf506bca2015-05-02 22:31:47 -0500801 Where to access the information defined by the access method.
802
Paul Kehrer5a485522015-05-06 00:29:12 -0500803.. class:: CRLDistributionPoints
804
805 .. versionadded:: 0.9
806
807 The CRL distribution points extension identifies how CRL information is
808 obtained. It is an iterable, containing one or more
809 :class:`DistributionPoint` instances.
810
811.. class:: DistributionPoint
812
813 .. versionadded:: 0.9
814
815 .. attribute:: distribution_point
816
817 :type: list of :class:`GeneralName` instances, :class:`Name`, or None
818
819 This field describes methods to retrieve the CRL.
820
821 .. attribute:: crl_issuer
822
823 :type: list of :class:`GeneralName` instances or None
824
825 Information about the issuer of the CRL.
826
827 .. attribute:: reasons
828
829 :type: :class:`ReasonFlags` or None
830
831 The reasons a given distribution point may be used for when performing
832 revocation checks.
833
834.. class:: ReasonFlags
835
836 .. versionadded:: 0.9
837
838 This class holds reasons a distribution point may be used for when
839 performing revocation checks.
840
841 .. attribute:: key_compromise
842
843 :type: bool
844
845 .. attribute:: ca_compromise
846
847 :type: bool
848
849 .. attribute:: affiliation_changed
850
851 :type: bool
852
853 .. attribute:: superseded
854
855 :type: bool
856
857 .. attribute:: cessation_of_operation
858
859 :type: bool
860
861 .. attribute:: certificate_hold
862
863 :type: bool
864
865 .. attribute:: privilege_withdrawn
866
867 :type: bool
868
869 .. attribute:: aa_compromise
870
871 :type: bool
872
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600873Object Identifiers
874~~~~~~~~~~~~~~~~~~
875
Paul Kehrer4bb46492015-02-07 16:59:14 -0600876X.509 elements are frequently identified by :class:`ObjectIdentifier`
877instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600878
Paul Kehrer56da2a52015-02-11 23:35:07 -0600879Name OIDs
880~~~~~~~~~
881
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600882.. data:: OID_COMMON_NAME
883
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -0600884 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
885 name would be encoded here for server certificates. :rfc:`2818` deprecates
886 this practice and names of that type should now be located in a
Paul Kehrer4bb46492015-02-07 16:59:14 -0600887 SubjectAlternativeName extension. This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600888
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600889.. data:: OID_COUNTRY_NAME
890
Paul Kehrer4bb46492015-02-07 16:59:14 -0600891 Corresponds to the dotted string ``"2.5.4.6"``. This OID is typically seen
892 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600893
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600894.. data:: OID_LOCALITY_NAME
895
Paul Kehrer4bb46492015-02-07 16:59:14 -0600896 Corresponds to the dotted string ``"2.5.4.7"``. This OID is typically seen
897 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600898
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600899.. data:: OID_STATE_OR_PROVINCE_NAME
900
Paul Kehrer4bb46492015-02-07 16:59:14 -0600901 Corresponds to the dotted string ``"2.5.4.8"``. This OID is typically seen
902 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600903
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600904.. data:: OID_ORGANIZATION_NAME
905
Paul Kehrer4bb46492015-02-07 16:59:14 -0600906 Corresponds to the dotted string ``"2.5.4.10"``. This OID is typically seen
907 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600908
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600909.. data:: OID_ORGANIZATIONAL_UNIT_NAME
910
Paul Kehrer4bb46492015-02-07 16:59:14 -0600911 Corresponds to the dotted string ``"2.5.4.11"``. This OID is typically seen
912 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600913
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600914.. data:: OID_SERIAL_NUMBER
915
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -0600916 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from the
917 serial number of the certificate itself (which can be obtained with
Paul Kehrer4bb46492015-02-07 16:59:14 -0600918 :func:`Certificate.serial`). This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600919
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600920.. data:: OID_SURNAME
921
Paul Kehrer4bb46492015-02-07 16:59:14 -0600922 Corresponds to the dotted string ``"2.5.4.4"``. This OID is typically seen
923 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600924
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600925.. data:: OID_GIVEN_NAME
926
Paul Kehrer4bb46492015-02-07 16:59:14 -0600927 Corresponds to the dotted string ``"2.5.4.42"``. This OID is typically seen
928 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600929
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600930.. data:: OID_TITLE
931
Paul Kehrer4bb46492015-02-07 16:59:14 -0600932 Corresponds to the dotted string ``"2.5.4.12"``. This OID is typically seen
933 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600934
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600935.. data:: OID_GENERATION_QUALIFIER
936
Paul Kehrer4bb46492015-02-07 16:59:14 -0600937 Corresponds to the dotted string ``"2.5.4.44"``. This OID is typically seen
938 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600939
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600940.. data:: OID_DN_QUALIFIER
941
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -0600942 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
943 disambiguating information to add to the relative distinguished name of an
Paul Kehrer4bb46492015-02-07 16:59:14 -0600944 entry. See :rfc:`2256`. This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600945
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600946.. data:: OID_PSEUDONYM
947
Paul Kehrer4bb46492015-02-07 16:59:14 -0600948 Corresponds to the dotted string ``"2.5.4.65"``. This OID is typically seen
949 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600950
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600951.. data:: OID_DOMAIN_COMPONENT
952
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -0600953 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
Paul Kehrer4bb46492015-02-07 16:59:14 -0600954 holding one component of a domain name. See :rfc:`4519`. This OID is
955 typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600956
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600957.. data:: OID_EMAIL_ADDRESS
958
Paul Kehrer4bb46492015-02-07 16:59:14 -0600959 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``. This OID is
960 typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600961
Paul Kehrer56da2a52015-02-11 23:35:07 -0600962Signature Algorithm OIDs
963~~~~~~~~~~~~~~~~~~~~~~~~
964
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600965.. data:: OID_RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -0600966
967 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
968 an MD5 digest signed by an RSA key.
969
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600970.. data:: OID_RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -0600971
972 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
973 a SHA1 digest signed by an RSA key.
974
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600975.. data:: OID_RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -0600976
977 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
978 a SHA224 digest signed by an RSA key.
979
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600980.. data:: OID_RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -0600981
982 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
983 a SHA256 digest signed by an RSA key.
984
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600985.. data:: OID_RSA_WITH_SHA384
Paul Kehrer56da2a52015-02-11 23:35:07 -0600986
987 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
988 a SHA384 digest signed by an RSA key.
989
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600990.. data:: OID_RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -0600991
992 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
993 a SHA512 digest signed by an RSA key.
994
995.. data:: OID_ECDSA_WITH_SHA224
996
997 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
998 a SHA224 digest signed by an ECDSA key.
999
1000.. data:: OID_ECDSA_WITH_SHA256
1001
1002 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
1003 a SHA256 digest signed by an ECDSA key.
1004
1005.. data:: OID_ECDSA_WITH_SHA384
1006
1007 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
1008 a SHA384 digest signed by an ECDSA key.
1009
1010.. data:: OID_ECDSA_WITH_SHA512
1011
1012 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
1013 a SHA512 digest signed by an ECDSA key.
1014
1015.. data:: OID_DSA_WITH_SHA1
1016
1017 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
1018 a SHA1 digest signed by a DSA key.
1019
1020.. data:: OID_DSA_WITH_SHA224
1021
1022 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
1023 a SHA224 digest signed by a DSA key.
1024
1025.. data:: OID_DSA_WITH_SHA256
1026
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001027 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
Paul Kehrer56da2a52015-02-11 23:35:07 -06001028 a SHA256 digest signed by a DSA key.
1029
Paul Kehrerffa2a152015-03-31 08:18:25 -05001030.. _eku_oids:
1031
Paul Kehrere1513fa2015-03-30 23:08:17 -05001032Extended Key Usage OIDs
1033~~~~~~~~~~~~~~~~~~~~~~~
1034
1035.. data:: OID_SERVER_AUTH
1036
1037 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used to
1038 denote that a certificate may be used for TLS web server authentication.
1039
1040.. data:: OID_CLIENT_AUTH
1041
1042 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used to
1043 denote that a certificate may be used for TLS web client authentication.
1044
1045.. data:: OID_CODE_SIGNING
1046
1047 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used to
1048 denote that a certificate may be used for code signing.
1049
1050.. data:: OID_EMAIL_PROTECTION
1051
1052 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used to
1053 denote that a certificate may be used for email protection.
1054
1055.. data:: OID_TIME_STAMPING
1056
1057 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used to
1058 denote that a certificate may be used for time stamping.
1059
1060.. data:: OID_OCSP_SIGNING
1061
1062 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used to
1063 denote that a certificate may be used for signing OCSP responses.
1064
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001065Authority Information Access OIDs
1066~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1067
1068.. data:: OID_OCSP
1069
1070 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
1071 identifier for OCSP data in :class:`AccessDescription` objects.
1072
1073.. data:: OID_CA_ISSUERS
1074
1075 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
1076 identifier for CA issuer data in :class:`AccessDescription` objects.
1077
Paul Kehrer5553d572015-03-23 21:08:01 -05001078.. _extension_oids:
1079
Paul Kehrer2bb94642015-03-21 09:54:17 -05001080Extension OIDs
1081~~~~~~~~~~~~~~
1082
1083.. data:: OID_BASIC_CONSTRAINTS
1084
1085 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
Paul Kehrer611d3d32015-03-22 13:31:18 -05001086 :class:`BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05001087
Paul Kehrercecbbba2015-03-30 14:58:38 -05001088.. data:: OID_KEY_USAGE
1089
1090 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
1091 :class:`KeyUsage` extension type.
1092
Paul Kehrer56da2a52015-02-11 23:35:07 -06001093
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001094Exceptions
1095~~~~~~~~~~
1096
Paul Kehrere76cd272014-12-14 19:00:51 -06001097.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10001098
1099 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10001100
Paul Kehrerd5cccf72014-12-15 17:20:33 -06001101 .. attribute:: parsed_version
1102
Paul Kehrerbbffc402014-12-17 13:33:55 -06001103 :type: int
1104
1105 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06001106
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001107.. class:: DuplicateExtension
1108
1109 This is raised when more than one X.509 extension of the same type is
1110 found within a certificate.
1111
1112 .. attribute:: oid
1113
1114 :type: :class:`ObjectIdentifier`
1115
1116 Returns the OID.
1117
1118.. class:: UnsupportedExtension
1119
1120 This is raised when a certificate contains an unsupported extension type.
1121
1122 .. attribute:: oid
1123
1124 :type: :class:`ObjectIdentifier`
1125
1126 Returns the OID.
1127
Paul Kehrerfa56a232015-03-17 13:14:03 -05001128.. class:: ExtensionNotFound
1129
1130 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
1131 an extension OID that is not present in the certificate.
1132
1133 .. attribute:: oid
1134
1135 :type: :class:`ObjectIdentifier`
1136
1137 Returns the OID.
1138
Paul Kehrer9089c912015-04-20 22:15:20 -05001139.. class:: UnsupportedGeneralNameType
1140
1141 This is raised when a certificate contains an unsupported general name
1142 type in an extension.
1143
Paul Kehrerbed07352015-04-21 08:31:10 -05001144 .. attribute:: type
1145
Paul Kehrer0a621bf2015-04-22 09:22:56 -05001146 :type: int
1147
1148 The integer value of the unsupported type. The complete list of
1149 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05001150
Paul Kehrer016e08a2014-11-26 09:41:18 -10001151
1152.. _`public key infrastructure`: https://en.wikipedia.org/wiki/Public_key_infrastructure
Paul Kehrera68fd332014-11-27 07:08:40 -10001153.. _`TLS`: https://en.wikipedia.org/wiki/Transport_Layer_Security
Paul Kehrerc7c9a432015-04-19 09:20:13 -05001154.. _`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 -05001155.. _`RFC 5280 section 4.2.1.6`: https://tools.ietf.org/html/rfc5280#section-4.2.1.6