blob: 2029c08ff41aaf2cd83292b5d20fb309015043c8 [file] [log] [blame]
Alex Gaynor4af5b372015-07-12 10:30:59 -05001X.509 Reference
2===============
Paul Kehrer016e08a2014-11-26 09:41:18 -10003
Paul Kehrera9d78c12014-11-26 10:59:03 -10004.. currentmodule:: cryptography.x509
Paul Kehrer016e08a2014-11-26 09:41:18 -10005
Paul Kehrerd26c4db2015-03-15 15:36:24 -05006.. testsetup::
7
8 pem_req_data = b"""
9 -----BEGIN CERTIFICATE REQUEST-----
10 MIIC0zCCAbsCAQAwWTELMAkGA1UEBhMCVVMxETAPBgNVBAgMCElsbGlub2lzMRAw
11 DgYDVQQHDAdDaGljYWdvMREwDwYDVQQKDAhyNTA5IExMQzESMBAGA1UEAwwJaGVs
12 bG8uY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqhZx+Mo9VRd9
13 vsnWWa6NBCws21rZ0+1B/JGgB4hDsZS7iDE4Bj5z4idheFRtl8bBbdjPknq7BfoF
14 8v15Zq/Zv7i2xMSDL+LUrTBZezRd4bRTGqCm6YJ5EYkhqdcqeZleHCFImguHoq1J
15 Fh0+kObQrTHXw3ZP57a3o1IvyIUA3nNoCBL0QQhwBXaDXOojMKNR+bqB5ve8GS1y
16 Elr0AM/+cJsfaIahNQUgFKx3Eu3GeEOMKYOAG1lycgdQdmTUybLrT3U7vkClTseM
17 xHg1r5En7ALjONIhqRuq3rddYahrP8HXozb3zUy3cJ7P6IeaosuvNzvMXOX9P6HD
18 Ha9urDAJ1wIDAQABoDUwMwYJKoZIhvcNAQkOMSYwJDAiBgNVHREEGzAZggl3b3Js
19 ZC5jb22CDHdoYXRldmVyLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEAS4Ro6h+z52SK
20 YSLCYARpnEu/rmh4jdqndt8naqcNb6uLx9mlKZ2W9on9XDjnSdQD9q+ZP5aZfESw
21 R0+rJhW9ZrNa/g1pt6M24ihclHYDAxYMWxT1z/TXXGM3TmZZ6gfYlNE1kkBuODHa
22 UYsR/1Ht1E1EsmmUimt2n+zQR2K8T9Coa+boaUW/GsTEuz1aaJAkj5ZvTDiIhRG4
23 AOCqFZOLAQmCCNgJnnspD9hDz/Ons085LF5wnYjN4/Nsk5tS6AGs3xjZ3jPoOGGn
24 82WQ9m4dBGoVDZXsobVTaN592JEYwN5iu72zRn7Einb4V4H5y3yD2dD4yWPlt4pk
25 5wFkeYsZEA==
26 -----END CERTIFICATE REQUEST-----
27 """.strip()
28
Paul Kehrerd3dafbd2015-03-15 16:24:18 -050029 pem_data = b"""
30 -----BEGIN CERTIFICATE-----
31 MIIDfDCCAmSgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJVUzEf
32 MB0GA1UEChMWVGVzdCBDZXJ0aWZpY2F0ZXMgMjAxMTEVMBMGA1UEAxMMVHJ1c3Qg
33 QW5jaG9yMB4XDTEwMDEwMTA4MzAwMFoXDTMwMTIzMTA4MzAwMFowQDELMAkGA1UE
34 BhMCVVMxHzAdBgNVBAoTFlRlc3QgQ2VydGlmaWNhdGVzIDIwMTExEDAOBgNVBAMT
35 B0dvb2QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCQWJpHYo37
36 Xfb7oJSPe+WvfTlzIG21WQ7MyMbGtK/m8mejCzR6c+f/pJhEH/OcDSMsXq8h5kXa
37 BGqWK+vSwD/Pzp5OYGptXmGPcthDtAwlrafkGOS4GqIJ8+k9XGKs+vQUXJKsOk47
38 RuzD6PZupq4s16xaLVqYbUC26UcY08GpnoLNHJZS/EmXw1ZZ3d4YZjNlpIpWFNHn
39 UGmdiGKXUPX/9H0fVjIAaQwjnGAbpgyCumWgzIwPpX+ElFOUr3z7BoVnFKhIXze+
40 VmQGSWxZxvWDUN90Ul0tLEpLgk3OVxUB4VUGuf15OJOpgo1xibINPmWt14Vda2N9
41 yrNKloJGZNqLAgMBAAGjfDB6MB8GA1UdIwQYMBaAFOR9X9FclYYILAWuvnW2ZafZ
42 XahmMB0GA1UdDgQWBBRYAYQkG7wrUpRKPaUQchRR9a86yTAOBgNVHQ8BAf8EBAMC
43 AQYwFwYDVR0gBBAwDjAMBgpghkgBZQMCATABMA8GA1UdEwEB/wQFMAMBAf8wDQYJ
44 KoZIhvcNAQELBQADggEBADWHlxbmdTXNwBL/llwhQqwnazK7CC2WsXBBqgNPWj7m
45 tvQ+aLG8/50Qc2Sun7o2VnwF9D18UUe8Gj3uPUYH+oSI1vDdyKcjmMbKRU4rk0eo
46 3UHNDXwqIVc9CQS9smyV+x1HCwL4TTrq+LXLKx/qVij0Yqk+UJfAtrg2jnYKXsCu
47 FMBQQnWCGrwa1g1TphRp/RmYHnMynYFmZrXtzFz+U9XEA7C+gPq4kqDI/iVfIT1s
48 6lBtdB50lrDVwl2oYfAvW/6sC2se2QleZidUmrziVNP4oEeXINokU6T6p//HM1FG
49 QYw2jOvpKcKtWCSAnegEbgsGYzATKjmPJPJ0npHFqzM=
50 -----END CERTIFICATE-----
51 """.strip()
52
Paul Kehrer93ae8052015-05-02 23:18:09 -050053 cryptography_cert_pem = b"""
54 -----BEGIN CERTIFICATE-----
55 MIIFvTCCBKWgAwIBAgICPyAwDQYJKoZIhvcNAQELBQAwRzELMAkGA1UEBhMCVVMx
56 FjAUBgNVBAoTDUdlb1RydXN0IEluYy4xIDAeBgNVBAMTF1JhcGlkU1NMIFNIQTI1
57 NiBDQSAtIEczMB4XDTE0MTAxNTEyMDkzMloXDTE4MTExNjAxMTUwM1owgZcxEzAR
58 BgNVBAsTCkdUNDg3NDI5NjUxMTAvBgNVBAsTKFNlZSB3d3cucmFwaWRzc2wuY29t
59 L3Jlc291cmNlcy9jcHMgKGMpMTQxLzAtBgNVBAsTJkRvbWFpbiBDb250cm9sIFZh
60 bGlkYXRlZCAtIFJhcGlkU1NMKFIpMRwwGgYDVQQDExN3d3cuY3J5cHRvZ3JhcGh5
61 LmlvMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAom/FebKJIot7Sp3s
62 itG1sicpe3thCssjI+g1JDAS7I3GLVNmbms1DOdIIqwf01gZkzzXBN2+9sOnyRaR
63 PPfCe1jTr3dk2y6rPE559vPa1nZQkhlzlhMhlPyjaT+S7g4Tio4qV2sCBZU01DZJ
64 CaksfohN+5BNVWoJzTbOcrHOEJ+M8B484KlBCiSxqf9cyNQKru4W3bHaCVNVJ8eu
65 6i6KyhzLa0L7yK3LXwwXVs583C0/vwFhccGWsFODqD/9xHUzsBIshE8HKjdjDi7Y
66 3BFQzVUQFjBB50NSZfAA/jcdt1blxJouc7z9T8Oklh+V5DDBowgAsrT4b6Z2Fq6/
67 r7D1GqivLK/ypUQmxq2WXWAUBb/Q6xHgxASxI4Br+CByIUQJsm8L2jzc7k+mF4hW
68 ltAIUkbo8fGiVnat0505YJgxWEDKOLc4Gda6d/7GVd5AvKrz242bUqeaWo6e4MTx
69 diku2Ma3rhdcr044Qvfh9hGyjqNjvhWY/I+VRWgihU7JrYvgwFdJqsQ5eiKT4OHi
70 gsejvWwkZzDtiQ+aQTrzM1FsY2swJBJsLSX4ofohlVRlIJCn/ME+XErj553431Lu
71 YQ5SzMd3nXzN78Vj6qzTfMUUY72UoT1/AcFiUMobgIqrrmwuNxfrkbVE2b6Bga74
72 FsJX63prvrJ41kuHK/16RQBM7fcCAwEAAaOCAWAwggFcMB8GA1UdIwQYMBaAFMOc
73 8/zTRgg0u85Gf6B8W/PiCMtZMFcGCCsGAQUFBwEBBEswSTAfBggrBgEFBQcwAYYT
74 aHR0cDovL2d2LnN5bWNkLmNvbTAmBggrBgEFBQcwAoYaaHR0cDovL2d2LnN5bWNi
75 LmNvbS9ndi5jcnQwDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUFBwMB
76 BggrBgEFBQcDAjAvBgNVHREEKDAmghN3d3cuY3J5cHRvZ3JhcGh5Lmlvgg9jcnlw
77 dG9ncmFwaHkuaW8wKwYDVR0fBCQwIjAgoB6gHIYaaHR0cDovL2d2LnN5bWNiLmNv
78 bS9ndi5jcmwwDAYDVR0TAQH/BAIwADBFBgNVHSAEPjA8MDoGCmCGSAGG+EUBBzYw
79 LDAqBggrBgEFBQcCARYeaHR0cHM6Ly93d3cucmFwaWRzc2wuY29tL2xlZ2FsMA0G
80 CSqGSIb3DQEBCwUAA4IBAQAzIYO2jx7h17FBT74tJ2zbV9OKqGb7QF8y3wUtP4xc
81 dH80vprI/Cfji8s86kr77aAvAqjDjaVjHn7UzebhSUivvRPmfzRgyWBacomnXTSt
82 Xlt2dp2nDQuwGyK2vB7dMfKnQAkxwq1sYUXznB8i0IhhCAoXp01QGPKq51YoIlnF
83 7DRMk6iEaL1SJbkIrLsCQyZFDf0xtfW9DqXugMMLoxeCsBhZJQzNyS2ryirrv9LH
84 aK3+6IZjrcyy9bkpz/gzJucyhU+75c4My/mnRCrtItRbCQuiI5pd5poDowm+HH9i
85 GVI9+0lAFwxOUnOnwsoI40iOoxjLMGB+CgFLKCGUcWxP
86 -----END CERTIFICATE-----
87 """.strip()
88
Paul Kehrerb2de9482014-12-11 14:54:48 -060089Loading Certificates
90~~~~~~~~~~~~~~~~~~~~
Paul Kehrer016e08a2014-11-26 09:41:18 -100091
92.. function:: load_pem_x509_certificate(data, backend)
93
94 .. versionadded:: 0.7
95
Paul Kehrere76cd272014-12-14 19:00:51 -060096 Deserialize a certificate from PEM encoded data. PEM certificates are
97 base64 decoded and have delimiters that look like
98 ``-----BEGIN CERTIFICATE-----``.
Paul Kehrer016e08a2014-11-26 09:41:18 -100099
100 :param bytes data: The PEM encoded certificate data.
101
102 :param backend: A backend supporting the
103 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
104 interface.
105
Paul Kehrere76cd272014-12-14 19:00:51 -0600106 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000107
108.. function:: load_der_x509_certificate(data, backend)
109
110 .. versionadded:: 0.7
111
Paul Kehrere76cd272014-12-14 19:00:51 -0600112 Deserialize a certificate from DER encoded data. DER is a binary format
Paul Kehrer92aac382014-12-15 16:25:28 -0600113 and is commonly found in files with the ``.cer`` extension (although file
114 extensions are not a guarantee of encoding type).
Paul Kehrer016e08a2014-11-26 09:41:18 -1000115
116 :param bytes data: The DER encoded certificate data.
117
118 :param backend: A backend supporting the
119 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
120 interface.
121
Paul Kehrere76cd272014-12-14 19:00:51 -0600122 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000123
Paul Kehrer016e08a2014-11-26 09:41:18 -1000124.. doctest::
125
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600126 >>> from cryptography import x509
Paul Kehrer016e08a2014-11-26 09:41:18 -1000127 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600128 >>> cert = x509.load_pem_x509_certificate(pem_data, default_backend())
Paul Kehrer016e08a2014-11-26 09:41:18 -1000129 >>> cert.serial
130 2
131
Paul Kehrera1a1f232015-03-15 15:34:35 -0500132Loading Certificate Signing Requests
133~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600134
Paul Kehrer31e39882015-03-11 11:37:04 -0500135.. function:: load_pem_x509_csr(data, backend)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600136
137 .. versionadded:: 0.9
138
Paul Kehrera1a1f232015-03-15 15:34:35 -0500139 Deserialize a certificate signing request (CSR) from PEM encoded data. PEM
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500140 requests are base64 decoded and have delimiters that look like
Paul Kehrerd3dafbd2015-03-15 16:24:18 -0500141 ``-----BEGIN CERTIFICATE REQUEST-----``. This format is also known as
142 PKCS#10.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600143
144 :param bytes data: The PEM encoded request data.
145
146 :param backend: A backend supporting the
147 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
148 interface.
149
Paul Kehrera1a1f232015-03-15 15:34:35 -0500150 :returns: An instance of
151 :class:`~cryptography.x509.CertificateSigningRequest`.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600152
Paul Kehrer1effb6e2015-03-30 15:05:59 -0500153.. function:: load_der_x509_csr(data, backend)
154
155 .. versionadded:: 0.9
156
157 Deserialize a certificate signing request (CSR) from DER encoded data. DER
158 is a binary format and is not commonly used with CSRs.
159
160 :param bytes data: The DER encoded request data.
161
162 :param backend: A backend supporting the
163 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
164 interface.
165
166 :returns: An instance of
167 :class:`~cryptography.x509.CertificateSigningRequest`.
168
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600169.. doctest::
170
171 >>> from cryptography import x509
172 >>> from cryptography.hazmat.backends import default_backend
173 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500174 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
175 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600176 True
177
Paul Kehrere76cd272014-12-14 19:00:51 -0600178X.509 Certificate Object
179~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerb2de9482014-12-11 14:54:48 -0600180
Paul Kehrere76cd272014-12-14 19:00:51 -0600181.. class:: Certificate
Paul Kehrerb2de9482014-12-11 14:54:48 -0600182
183 .. versionadded:: 0.7
184
185 .. attribute:: version
186
Paul Kehrere76cd272014-12-14 19:00:51 -0600187 :type: :class:`~cryptography.x509.Version`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600188
Paul Kehrere76cd272014-12-14 19:00:51 -0600189 The certificate version as an enumeration. Version 3 certificates are
190 the latest version and also the only type you should see in practice.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600191
Alex Gaynor89c4dc82014-12-16 16:49:33 -0800192 :raises cryptography.x509.InvalidVersion: If the version in the
Alex Gaynor6d7ab4c2014-12-16 16:50:33 -0800193 certificate is not a known
194 :class:`X.509 version <cryptography.x509.Version>`.
Paul Kehrer92aac382014-12-15 16:25:28 -0600195
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600196 .. doctest::
197
198 >>> cert.version
199 <Version.v3: 2>
200
Paul Kehrerb2de9482014-12-11 14:54:48 -0600201 .. method:: fingerprint(algorithm)
202
203 :param algorithm: The
Paul Kehrer601278a2015-02-12 12:51:00 -0600204 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600205 that will be used to generate the fingerprint.
206
Erik Trauschke2dcce902015-05-14 16:12:24 -0700207 :return bytes: The fingerprint using the supplied hash algorithm, as
Paul Kehrerb2de9482014-12-11 14:54:48 -0600208 bytes.
209
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600210 .. doctest::
211
212 >>> from cryptography.hazmat.primitives import hashes
213 >>> cert.fingerprint(hashes.SHA256())
Paul Kehrer78a81502014-12-16 14:47:52 -0600214 '\x86\xd2\x187Gc\xfc\xe7}[+E9\x8d\xb4\x8f\x10\xe5S\xda\x18u\xbe}a\x03\x08[\xac\xa04?'
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600215
Paul Kehrerb2de9482014-12-11 14:54:48 -0600216 .. attribute:: serial
217
218 :type: int
219
220 The serial as a Python integer.
221
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600222 .. doctest::
223
224 >>> cert.serial
225 2
226
Paul Kehrerb2de9482014-12-11 14:54:48 -0600227 .. method:: public_key()
228
229 :type:
Alex Stapletonf79c2312014-12-30 12:50:14 +0000230 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
Paul Kehrer45efdbc2015-02-12 10:58:22 -0600231 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
232 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600233
234 The public key associated with the certificate.
235
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600236 .. doctest::
237
Alex Stapletonf79c2312014-12-30 12:50:14 +0000238 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600239 >>> public_key = cert.public_key()
Alex Stapletonf79c2312014-12-30 12:50:14 +0000240 >>> isinstance(public_key, rsa.RSAPublicKey)
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600241 True
242
Paul Kehrerb2de9482014-12-11 14:54:48 -0600243 .. attribute:: not_valid_before
244
245 :type: :class:`datetime.datetime`
246
Paul Kehrer78a81502014-12-16 14:47:52 -0600247 A naïve datetime representing the beginning of the validity period for
248 the certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600249
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600250 .. doctest::
251
252 >>> cert.not_valid_before
253 datetime.datetime(2010, 1, 1, 8, 30)
254
Paul Kehrerb2de9482014-12-11 14:54:48 -0600255 .. attribute:: not_valid_after
256
257 :type: :class:`datetime.datetime`
258
Paul Kehrer78a81502014-12-16 14:47:52 -0600259 A naïve datetime representing the end of the validity period for the
260 certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600261
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600262 .. doctest::
263
264 >>> cert.not_valid_after
265 datetime.datetime(2030, 12, 31, 8, 30)
266
Paul Kehrer719d5362015-01-01 20:03:52 -0600267 .. attribute:: issuer
268
269 .. versionadded:: 0.8
270
271 :type: :class:`Name`
272
273 The :class:`Name` of the issuer.
274
275 .. attribute:: subject
276
277 .. versionadded:: 0.8
278
279 :type: :class:`Name`
280
281 The :class:`Name` of the subject.
282
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600283 .. attribute:: signature_hash_algorithm
Paul Kehrer56da2a52015-02-11 23:35:07 -0600284
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600285 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrer56da2a52015-02-11 23:35:07 -0600286
Paul Kehrere612ec72015-02-16 14:33:35 -0600287 Returns the
Paul Kehrer71d40c62015-02-19 08:21:04 -0600288 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600289 was used in signing this certificate.
Paul Kehrer56da2a52015-02-11 23:35:07 -0600290
291 .. doctest::
292
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600293 >>> from cryptography.hazmat.primitives import hashes
294 >>> isinstance(cert.signature_hash_algorithm, hashes.SHA256)
295 True
Paul Kehrer719d5362015-01-01 20:03:52 -0600296
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500297 .. attribute:: extensions
298
299 :type: :class:`Extensions`
300
301 The extensions encoded in the certificate.
302
303 :raises cryptography.x509.DuplicateExtension: If more than one
304 extension of the same type is found within the certificate.
305
Paul Kehrerd8fc0be2015-04-21 08:31:10 -0500306 :raises cryptography.x509.UnsupportedExtension: If the certificate
307 contains an extension that is not supported.
308
Paul Kehrerbed07352015-04-21 08:31:10 -0500309 :raises cryptography.x509.UnsupportedGeneralNameType: If an extension
310 contains a general name that is not supported.
311
Paul Kehrerb8968812015-05-15 09:01:34 -0700312 :raises UnicodeError: If an extension contains IDNA encoding that is
313 invalid or not compliant with IDNA 2008.
314
Paul Kehrerfa56a232015-03-17 13:14:03 -0500315 .. doctest::
316
317 >>> for ext in cert.extensions:
318 ... print(ext)
Paul Kehrerd774de92015-05-03 10:52:25 -0500319 <Extension(oid=<ObjectIdentifier(oid=2.5.29.35, name=authorityKeyIdentifier)>, critical=False, value=<AuthorityKeyIdentifier(key_identifier='\xe4}_\xd1\\\x95\x86\x08,\x05\xae\xbeu\xb6e\xa7\xd9]\xa8f', authority_cert_issuer=None, authority_cert_serial_number=None)>)>
Paul Kehrercbfb1012015-04-10 20:57:20 -0400320 <Extension(oid=<ObjectIdentifier(oid=2.5.29.14, name=subjectKeyIdentifier)>, critical=False, value=<SubjectKeyIdentifier(digest='X\x01\x84$\x1b\xbc+R\x94J=\xa5\x10r\x14Q\xf5\xaf:\xc9')>)>
Paul Kehrerb511ba82015-04-15 11:22:48 -0400321 <Extension(oid=<ObjectIdentifier(oid=2.5.29.15, name=keyUsage)>, critical=True, value=<KeyUsage(digital_signature=False, content_commitment=False, key_encipherment=False, data_encipherment=False, key_agreement=False, key_cert_sign=True, crl_sign=True, encipher_only=None, decipher_only=None)>)>
Paul Kehrer2008d9c2015-05-12 22:19:56 -0500322 <Extension(oid=<ObjectIdentifier(oid=2.5.29.32, name=certificatePolicies)>, critical=False, value=<CertificatePolicies([<PolicyInformation(policy_identifier=<ObjectIdentifier(oid=2.16.840.1.101.3.2.1.48.1, name=Unknown OID)>, policy_qualifiers=None)>])>)>
Paul Kehrerfa56a232015-03-17 13:14:03 -0500323 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
324
Andre Carona8aded62015-05-19 20:11:57 -0400325 .. method:: public_bytes(encoding)
326
Alex Gaynord0b376b2015-07-05 13:58:12 -0400327 .. versionadded:: 1.0
328
Andre Carona8aded62015-05-19 20:11:57 -0400329 :param encoding: The
330 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
331 that will be used to serialize the certificate.
332
333 :return bytes: The data that can be written to a file or sent
334 over the network to be verified by clients.
335
Erik Trauschke2dcce902015-05-14 16:12:24 -0700336X.509 CRL (Certificate Revocation List) Object
337~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
338
339.. class:: CertificateRevocationList
340
341 .. versionadded:: 1.0
342
343 .. method:: fingerprint(algorithm)
344
345 :param algorithm: The
346 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
347 that will be used to generate the fingerprint.
348
349 :return bytes: The fingerprint using the supplied hash algorithm, as
350 bytes.
351
352 .. attribute:: signature_hash_algorithm
353
354 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
355
356 Returns the
357 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
358 was used in signing this CRL.
359
360 .. attribute:: issuer
361
362 :type: :class:`Name`
363
364 The :class:`Name` of the issuer.
365
366 .. attribute:: next_update
367
368 :type: :class:`datetime.datetime`
369
370 A naïve datetime representing when the next update to this CRL is
371 expected.
372
373 .. attribute:: last_update
374
375 :type: :class:`datetime.datetime`
376
377 A naïve datetime representing when the this CRL was last updated.
378
Erik Trauschkeabb7b6e2015-05-27 15:07:35 -0700379 .. attribute:: revoked_certificates
Erik Trauschke2dcce902015-05-14 16:12:24 -0700380
381 :type: list of :class:`RevokedCertificate`
382
383 The revoked certificates listed in this CRL.
384
385 .. attribute:: extensions
386
387 :type: :class:`Extensions`
388
389 The extensions encoded in the CRL.
390
Andre Caron9bbfcea2015-05-18 20:55:29 -0400391X.509 Certificate Builder
392~~~~~~~~~~~~~~~~~~~~~~~~~
393
394.. class:: CertificateBuilder
395
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500396 .. method:: issuer_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400397
398 Sets the issuer's distinguished name.
399
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500400 :param name: The :class:`~cryptography.x509.Name` that describes the
401 issuer (CA).
Andre Caron9bbfcea2015-05-18 20:55:29 -0400402
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500403 .. method:: subject_name(name)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400404
405 Sets the subject's distinguished name.
406
Ian Cordascoc9682ad2015-08-01 12:11:13 -0500407 :param name: The :class:`~cryptography.x509.Name` that describes the
Ian Cordasco85fc4d52015-08-01 20:29:31 -0500408 subject.
Andre Caron9bbfcea2015-05-18 20:55:29 -0400409
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500410 .. method:: public_key(public_key)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400411
412 Sets the subject's public key.
413
414 :param public_key: The subject's public key.
415
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500416 .. method:: serial_number(serial_number)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400417
418 Sets the certificate's serial number (an integer). The CA's policy
419 determines how it attributes serial numbers to certificates. The only
420 requirement is that this number uniquely identify the certificate given
421 the issuer.
422
423 :param serial_number: Integer number that will be used by the CA to
424 identify this certificate (most notably during certificate
425 revocation checking).
426
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500427 .. method:: not_valid_before(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400428
429 Sets the certificate's activation time. This is the time from which
430 clients can start trusting the certificate. It may be different from
431 the time at which the certificate was created.
432
433 :param time: The `datetime.datetime` object (in UTC) that marks the
434 activation time for the certificate. The certificate may not be
435 trusted clients if it is used before this time.
436
Ian Cordasco0092a0b2015-07-18 21:46:41 -0500437 .. method:: not_valid_after(time)
Andre Caron9bbfcea2015-05-18 20:55:29 -0400438
439 Sets the certificate's expiration time. This is the time from which
440 clients should no longer trust the certificate. The CA's policy will
441 determine how long the certificate should remain in use.
442
443 :param time: The `datetime.datetime` object (in UTC) that marks the
444 expiration time for the certificate. The certificate may not be
445 trusted clients if it is used after this time.
446
447 .. method:: add_extension(extension)
448
449 Adds an X.509 extension to the certificate.
450
451 :param extension: The :class:`~cryptography.x509.Extension` to add to
452 the certificate.
453
454 .. method:: sign(backend, private_key, algorithm)
455
456 Sign the certificate using the CA's private key.
457
Ian Cordascoc5e1c252015-07-31 23:33:35 -0500458 :param backend: Backend that will be used to build the certificate.
459 Must support the
460 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
461 interface.
462
463 :param private_key: The
464 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
465 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
466 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
467 that will be used to sign the certificate.
468
Andre Caron9bbfcea2015-05-18 20:55:29 -0400469 :param algorithm: The
470 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` that
471 will be used to generate the signature.
472
473
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500474X.509 CSR (Certificate Signing Request) Object
475~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600476
Paul Kehrera1a1f232015-03-15 15:34:35 -0500477.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600478
479 .. versionadded:: 0.9
480
481 .. method:: public_key()
482
483 :type:
484 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
485 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
486 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
487
488 The public key associated with the request.
489
490 .. doctest::
491
492 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500493 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600494 >>> isinstance(public_key, rsa.RSAPublicKey)
495 True
496
497 .. attribute:: subject
498
499 :type: :class:`Name`
500
501 The :class:`Name` of the subject.
502
503 .. attribute:: signature_hash_algorithm
504
505 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
506
507 Returns the
508 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
509 was used in signing this request.
510
511 .. doctest::
512
513 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500514 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600515 True
516
Andre Caron476c5df2015-05-18 10:23:28 -0400517 .. method:: public_bytes(encoding)
518
Alex Gaynord0b376b2015-07-05 13:58:12 -0400519 .. versionadded:: 1.0
520
Andre Caron476c5df2015-05-18 10:23:28 -0400521 :param encoding: The
522 :class:`~cryptography.hazmat.primitives.serialization.Encoding`
523 that will be used to serialize the certificate request.
524
525 :return bytes: The data that can be written to a file or sent
526 over the network to be signed by the certificate
527 authority.
528
Erik Trauschke2dcce902015-05-14 16:12:24 -0700529X.509 Revoked Certificate Object
Erik Trauschkec5a8d172015-05-28 10:24:25 -0700530~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Erik Trauschke2dcce902015-05-14 16:12:24 -0700531
532.. class:: RevokedCertificate
533
534 .. versionadded:: 1.0
535
536 .. attribute:: serial_number
537
538 :type: :class:`int`
539
540 An integer representing the serial number of the revoked certificate.
541
542 .. attribute:: revocation_date
543
544 :type: :class:`datetime.datetime`
545
546 A naïve datetime representing the date this certificates was revoked.
547
548 .. attribute:: extensions
549
550 :type: :class:`Extensions`
551
552 The extensions encoded in the revoked certificate.
Andre Caron476c5df2015-05-18 10:23:28 -0400553
Andre Caron0ef595f2015-05-18 13:53:43 -0400554X.509 CSR (Certificate Signing Request) Builder Object
555~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
556
557.. class:: CertificateSigningRequestBuilder
558
Andre Carond259ee52015-06-02 23:47:11 -0400559 .. versionadded:: 1.0
560
561 .. doctest::
562
563 >>> from cryptography import x509
564 >>> from cryptography.hazmat.backends import default_backend
565 >>> from cryptography.hazmat.primitives import hashes
566 >>> from cryptography.hazmat.primitives.asymmetric import rsa
567 >>> private_key = rsa.generate_private_key(
568 ... public_exponent=65537,
569 ... key_size=2048,
570 ... backend=default_backend()
571 ... )
572 >>> builder = x509.CertificateSigningRequestBuilder()
Andre Carona9a51172015-06-06 20:18:44 -0400573 >>> builder = builder.subject_name(x509.Name([
Ian Cordasco4d46eb72015-06-17 12:08:27 -0500574 ... x509.NameAttribute(x509.OID_COMMON_NAME, u'cryptography.io'),
Andre Carond259ee52015-06-02 23:47:11 -0400575 ... ]))
Ian Cordascof06b6be2015-06-21 10:09:18 -0500576 >>> builder = builder.add_extension(
Ian Cordasco0112b022015-06-16 17:51:18 -0500577 ... x509.BasicConstraints(ca=False, path_length=None), critical=True,
Andre Caron472fd692015-06-06 20:04:44 -0400578 ... )
Andre Carond259ee52015-06-02 23:47:11 -0400579 >>> request = builder.sign(
Alex Gaynorde9e5842015-06-26 20:11:23 -0400580 ... private_key, hashes.SHA256(), default_backend()
Andre Carond259ee52015-06-02 23:47:11 -0400581 ... )
582 >>> isinstance(request, x509.CertificateSigningRequest)
583 True
584
Andre Carona9a51172015-06-06 20:18:44 -0400585 .. method:: subject_name(name)
Andre Caron0ef595f2015-05-18 13:53:43 -0400586
Andre Caron341ff852015-06-06 20:14:31 -0400587 :param name: The :class:`~cryptography.x509.Name` of the certificate
588 subject.
589 :returns: A new
590 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400591
Ian Cordascof06b6be2015-06-21 10:09:18 -0500592 .. method:: add_extension(extension, critical)
Andre Caron0ef595f2015-05-18 13:53:43 -0400593
Andre Caron341ff852015-06-06 20:14:31 -0400594 :param extension: The :class:`~cryptography.x509.Extension` to add to
595 the request.
Andre Caron472fd692015-06-06 20:04:44 -0400596 :param critical: Set to `True` if the extension must be understood and
597 handled by whoever reads the certificate.
Andre Caron341ff852015-06-06 20:14:31 -0400598 :returns: A new
599 :class:`~cryptography.x509.CertificateSigningRequestBuilder`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400600
Alex Gaynorb3b0fbe2015-06-26 19:57:18 -0400601 .. method:: sign(private_key, algorithm, backend)
Andre Caron0ef595f2015-05-18 13:53:43 -0400602
603 :param backend: Backend that will be used to sign the request.
604 Must support the
605 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
606 interface.
607
608 :param private_key: The
Andre Caron24f9bf42015-06-06 20:14:54 -0400609 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey`,
610 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPrivateKey` or
611 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey`
Andre Caron0ef595f2015-05-18 13:53:43 -0400612 that will be used to sign the request. When the request is
613 signed by a certificate authority, the private key's associated
614 public key will be stored in the resulting certificate.
615
616 :param algorithm: The
617 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
618 that will be used to generate the request signature.
619
Andre Caron341ff852015-06-06 20:14:31 -0400620 :returns: A new
621 :class:`~cryptography.x509.CertificateSigningRequest`.
Andre Caron0ef595f2015-05-18 13:53:43 -0400622
623
Paul Kehrer719d5362015-01-01 20:03:52 -0600624.. class:: Name
625
626 .. versionadded:: 0.8
627
Paul Kehrer53d8d492015-02-13 18:47:30 -0600628 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -0600629 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -0600630 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -0600631 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
632 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -0600633
Paul Kehrer53d8d492015-02-13 18:47:30 -0600634 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -0600635
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600636 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -0600637 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600638 >>> for attribute in cert.subject:
639 ... print(attribute)
640 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
641 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')>
642 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -0600643
Paul Kehrere901d642015-02-11 18:50:58 -0600644 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -0600645
Paul Kehrere901d642015-02-11 18:50:58 -0600646 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -0600647
Paul Kehrere901d642015-02-11 18:50:58 -0600648 :returns: A list of :class:`NameAttribute` instances that match the
649 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -0600650
651 .. doctest::
652
Paul Kehrere901d642015-02-11 18:50:58 -0600653 >>> cert.subject.get_attributes_for_oid(x509.OID_COMMON_NAME)
654 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -0600655
Paul Kehrere76cd272014-12-14 19:00:51 -0600656.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -1000657
658 .. versionadded:: 0.7
659
660 An enumeration for X.509 versions.
661
662 .. attribute:: v1
663
664 For version 1 X.509 certificates.
665
666 .. attribute:: v3
667
668 For version 3 X.509 certificates.
669
Paul Kehrer806bfb22015-02-02 17:05:24 -0600670.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600671
672 .. versionadded:: 0.8
673
Paul Kehrer834d22f2015-02-06 11:01:07 -0600674 An X.509 name consists of a list of NameAttribute instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600675
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600676 .. attribute:: oid
677
678 :type: :class:`ObjectIdentifier`
679
680 The attribute OID.
681
682 .. attribute:: value
683
Paul Kehrerd5852cb2015-01-30 08:25:23 -0600684 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600685
686 The value of the attribute.
687
688.. class:: ObjectIdentifier
689
690 .. versionadded:: 0.8
691
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600692 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -0600693 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600694
Paul Kehrerd44f9a62015-02-04 14:47:34 -0600695 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600696
697 :type: :class:`str`
698
Paul Kehrerfedf4f42015-02-06 11:22:07 -0600699 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600700
Paul Kehrer31bdf792015-03-25 14:11:00 -0500701.. _general_name_classes:
702
703General Name Classes
704~~~~~~~~~~~~~~~~~~~~
705
706.. class:: GeneralName
707
708 .. versionadded:: 0.9
709
710 This is the generic interface that all the following classes are registered
711 against.
712
713.. class:: RFC822Name
714
715 .. versionadded:: 0.9
716
717 This corresponds to an email address. For example, ``user@example.com``.
718
719 .. attribute:: value
720
721 :type: :term:`text`
722
723.. class:: DNSName
724
725 .. versionadded:: 0.9
726
727 This corresponds to a domain name. For example, ``cryptography.io``.
728
729 .. attribute:: value
730
731 :type: :term:`text`
732
733.. class:: DirectoryName
734
735 .. versionadded:: 0.9
736
737 This corresponds to a directory name.
738
739 .. attribute:: value
740
741 :type: :class:`Name`
742
743.. class:: UniformResourceIdentifier
744
745 .. versionadded:: 0.9
746
747 This corresponds to a uniform resource identifier. For example,
Paul Kehrerb8ef82e2015-04-22 16:04:24 -0500748 ``https://cryptography.io``. The URI is parsed and IDNA decoded (see
749 :rfc:`5895`).
750
751 .. note::
752
753 URIs that do not contain ``://`` in them will not be decoded.
Paul Kehrer31bdf792015-03-25 14:11:00 -0500754
755 .. attribute:: value
756
757 :type: :term:`text`
758
759.. class:: IPAddress
760
761 .. versionadded:: 0.9
762
763 This corresponds to an IP address.
764
765 .. attribute:: value
766
Paul Kehrereb177932015-05-17 18:33:33 -0700767 :type: :class:`~ipaddress.IPv4Address`,
768 :class:`~ipaddress.IPv6Address`, :class:`~ipaddress.IPv4Network`,
769 or :class:`~ipaddress.IPv6Network`.
Paul Kehrer31bdf792015-03-25 14:11:00 -0500770
771.. class:: RegisteredID
772
773 .. versionadded:: 0.9
774
775 This corresponds to a registered ID.
776
777 .. attribute:: value
778
779 :type: :class:`ObjectIdentifier`
780
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +0000781.. class:: OtherName
782
783 .. versionadded:: 1.0
784
Joshua Tauberer18b6fc82015-07-05 21:44:51 +0000785 This corresponds to an ``otherName.`` An ``otherName`` has a type identifier and a value represented in binary DER format.
Joshua Tauberer2ee5e3c2015-07-04 20:09:46 +0000786
787 .. attribute:: type_id
788
789 :type: :class:`ObjectIdentifier`
790
791 .. attribute:: value
792
793 :type: `bytes`
794
Paul Kehrer8cf26422015-03-21 09:50:24 -0500795X.509 Extensions
796~~~~~~~~~~~~~~~~
797
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500798.. class:: Extensions
799
800 .. versionadded:: 0.9
801
802 An X.509 Extensions instance is an ordered list of extensions. The object
803 is iterable to get every extension.
804
Paul Kehrerfa56a232015-03-17 13:14:03 -0500805 .. method:: get_extension_for_oid(oid)
806
807 :param oid: An :class:`ObjectIdentifier` instance.
808
809 :returns: An instance of the extension class.
810
811 :raises cryptography.x509.ExtensionNotFound: If the certificate does
812 not have the extension requested.
813
Paul Kehrerfa56a232015-03-17 13:14:03 -0500814 .. doctest::
815
816 >>> cert.extensions.get_extension_for_oid(x509.OID_BASIC_CONSTRAINTS)
817 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
818
Paul Kehrer8cf26422015-03-21 09:50:24 -0500819.. class:: Extension
820
821 .. versionadded:: 0.9
822
Paul Kehrer85894662015-03-22 13:19:31 -0500823 .. attribute:: oid
824
825 :type: :class:`ObjectIdentifier`
826
Paul Kehrer5553d572015-03-23 21:08:01 -0500827 The :ref:`extension OID <extension_oids>`.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500828
829 .. attribute:: critical
830
831 :type: bool
832
Paul Kehrer58b75692015-03-22 23:24:58 -0500833 Determines whether a given extension is critical or not. :rfc:`5280`
834 requires that "A certificate-using system MUST reject the certificate
835 if it encounters a critical extension it does not recognize or a
836 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -0500837
Paul Kehrer85894662015-03-22 13:19:31 -0500838 .. attribute:: value
839
840 Returns an instance of the extension type corresponding to the OID.
841
Paul Kehrercecbbba2015-03-30 14:58:38 -0500842.. class:: KeyUsage
843
844 .. versionadded:: 0.9
845
846 The key usage extension defines the purpose of the key contained in the
847 certificate. The usage restriction might be employed when a key that could
848 be used for more than one operation is to be restricted. It corresponds to
849 :data:`OID_KEY_USAGE`.
850
851 .. attribute:: digital_signature
852
853 :type: bool
854
Paul Kehrer738407b2015-04-01 22:39:02 -0500855 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500856 digital signatures, other than signatures on certificates
857 (``key_cert_sign``) and CRLs (``crl_sign``).
858
859 .. attribute:: content_commitment
860
861 :type: bool
862
Paul Kehrer738407b2015-04-01 22:39:02 -0500863 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500864 digital signatures, other than signatures on certificates
865 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
866 non-repudiation service that protects against the signing entity
867 falsely denying some action. In the case of later conflict, a
868 reliable third party may determine the authenticity of the signed
869 data. This was called ``non_repudiation`` in older revisions of the
870 X.509 specification.
871
872 .. attribute:: key_encipherment
873
874 :type: bool
875
Paul Kehrer738407b2015-04-01 22:39:02 -0500876 This purpose is set to true when the subject public key is used for
877 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500878
879 .. attribute:: data_encipherment
880
881 :type: bool
882
Paul Kehrer738407b2015-04-01 22:39:02 -0500883 This purpose is set to true when the subject public key is used for
884 directly enciphering raw user data without the use of an intermediate
885 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500886
887 .. attribute:: key_agreement
888
889 :type: bool
890
Paul Kehrer738407b2015-04-01 22:39:02 -0500891 This purpose is set to true when the subject public key is used for key
892 agreement. For example, when a Diffie-Hellman key is to be used for
893 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500894
895 .. attribute:: key_cert_sign
896
897 :type: bool
898
Paul Kehrer738407b2015-04-01 22:39:02 -0500899 This purpose is set to true when the subject public key is used for
900 verifying signatures on public key certificates. If this purpose is set
901 to true then ``ca`` must be true in the :class:`BasicConstraints`
902 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500903
904 .. attribute:: crl_sign
905
906 :type: bool
907
Paul Kehrer738407b2015-04-01 22:39:02 -0500908 This purpose is set to true when the subject public key is used for
909 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500910
911 .. attribute:: encipher_only
912
913 :type: bool
914
Paul Kehrer738407b2015-04-01 22:39:02 -0500915 When this purposes is set to true and the ``key_agreement`` purpose is
916 also set, the subject public key may be used only for enciphering data
917 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500918
919 :raises ValueError: This is raised if accessed when ``key_agreement``
920 is false.
921
922 .. attribute:: decipher_only
923
924 :type: bool
925
Paul Kehrer738407b2015-04-01 22:39:02 -0500926 When this purposes is set to true and the ``key_agreement`` purpose is
927 also set, the subject public key may be used only for deciphering data
928 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500929
930 :raises ValueError: This is raised if accessed when ``key_agreement``
931 is false.
932
933
Paul Kehrer8cf26422015-03-21 09:50:24 -0500934.. class:: BasicConstraints
935
936 .. versionadded:: 0.9
937
Paul Kehrer85894662015-03-22 13:19:31 -0500938 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -0500939 certificate is allowed to sign additional certificates and what path
Paul Kehrer85894662015-03-22 13:19:31 -0500940 length restrictions may exist. It corresponds to
941 :data:`OID_BASIC_CONSTRAINTS`.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500942
943 .. attribute:: ca
944
945 :type: bool
946
947 Whether the certificate can sign certificates.
948
949 .. attribute:: path_length
950
Paul Kehrerfd1444c2015-03-21 19:47:05 -0500951 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -0500952
953 The maximum path length for certificates subordinate to this
954 certificate. This attribute only has meaning if ``ca`` is true.
955 If ``ca`` is true then a path length of None means there's no
956 restriction on the number of subordinate CAs in the certificate chain.
Alex Gaynor99c5f152015-05-03 10:01:04 -0400957 If it is zero or greater then it defines the maximum length for a
958 subordinate CA's certificate chain. For example, a ``path_length`` of 1
959 means the certificate can sign a subordinate CA, but the subordinate CA
960 is not allowed to create subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500961
Paul Kehrerffa2a152015-03-31 08:18:25 -0500962.. class:: ExtendedKeyUsage
963
964 .. versionadded:: 0.9
965
966 This extension indicates one or more purposes for which the certified
967 public key may be used, in addition to or in place of the basic
968 purposes indicated in the key usage extension. The object is
969 iterable to obtain the list of :ref:`extended key usage OIDs <eku_oids>`.
970
Paul Kehrer4a1038e2015-05-18 10:28:31 -0700971.. class:: OCSPNoCheck
972
Paul Kehrer506a2152015-05-26 08:01:18 -0500973 .. versionadded:: 1.0
Paul Kehrer4a1038e2015-05-18 10:28:31 -0700974
975 This presence of this extension indicates that an OCSP client can trust a
976 responder for the lifetime of the responder's certificate. CAs issuing
977 such a certificate should realize that a compromise of the responder's key
978 is as serious as the compromise of a CA key used to sign CRLs, at least for
979 the validity period of this certificate. CA's may choose to issue this type
980 of certificate with a very short lifetime and renew it frequently. This
981 extension is only relevant when the certificate is an authorized OCSP
982 responder.
983
Paul Kehrere0017be2015-05-17 20:39:40 -0600984.. class:: NameConstraints
985
986 .. versionadded:: 1.0
987
988 The name constraints extension, which only has meaning in a CA certificate,
989 defines a name space within which all subject names in certificates issued
990 beneath the CA certificate must (or must not) be in. For specific details
991 on the way this extension should be processed see :rfc:`5280`.
992
993 .. attribute:: permitted_subtrees
994
995 :type: list of :class:`GeneralName` objects or None
996
997 The set of permitted name patterns. If a name matches this and an
998 element in ``excluded_subtrees`` it is invalid. At least one of
999 ``permitted_subtrees`` and ``excluded_subtrees`` will be non-None.
1000
1001 .. attribute:: excluded_subtrees
1002
1003 :type: list of :class:`GeneralName` objects or None
1004
1005 Any name matching a restriction in the ``excluded_subtrees`` field is
1006 invalid regardless of information appearing in the
1007 ``permitted_subtrees``. At least one of ``permitted_subtrees`` and
1008 ``excluded_subtrees`` will be non-None.
1009
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001010.. class:: AuthorityKeyIdentifier
1011
1012 .. versionadded:: 0.9
1013
1014 The authority key identifier extension provides a means of identifying the
1015 public key corresponding to the private key used to sign a certificate.
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001016 This extension is typically used to assist in determining the appropriate
1017 certificate chain. For more information about generation and use of this
1018 extension see `RFC 5280 section 4.2.1.1`_.
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001019
1020 .. attribute:: key_identifier
1021
1022 :type: bytes
1023
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001024 A value derived from the public key used to verify the certificate's
Paul Kehrer8c8cd722015-04-19 09:15:04 -05001025 signature.
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001026
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001027 .. attribute:: authority_cert_issuer
1028
1029 :type: :class:`Name` or None
1030
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001031 The :class:`Name` of the issuer's issuer.
1032
Paul Kehrer2eb4ed92015-04-11 15:33:45 -04001033 .. attribute:: authority_cert_serial_number
1034
1035 :type: int or None
1036
Paul Kehrer9104b1d2015-04-18 09:23:44 -05001037 The serial number of the issuer's issuer.
1038
Paul Kehrer1eb82a62015-03-31 20:00:33 -05001039.. class:: SubjectKeyIdentifier
1040
1041 .. versionadded:: 0.9
1042
1043 The subject key identifier extension provides a means of identifying
1044 certificates that contain a particular public key.
1045
1046 .. attribute:: digest
1047
1048 :type: bytes
1049
1050 The binary value of the identifier.
1051
Paul Kehrer31bdf792015-03-25 14:11:00 -05001052.. class:: SubjectAlternativeName
1053
1054 .. versionadded:: 0.9
1055
1056 Subject alternative name is an X.509 extension that provides a list of
1057 :ref:`general name <general_name_classes>` instances that provide a set
1058 of identities for which the certificate is valid. The object is iterable to
1059 get every element.
1060
1061 .. method:: get_values_for_type(type)
1062
1063 :param type: A :class:`GeneralName` provider. This is one of the
1064 :ref:`general name classes <general_name_classes>`.
1065
1066 :returns: A list of values extracted from the matched general names.
Joshua Taubererd2afad32015-07-06 22:37:53 +00001067 The type of the returned values depends on the :class:`GeneralName`.
Paul Kehrer31bdf792015-03-25 14:11:00 -05001068
Paul Kehrer93ae8052015-05-02 23:18:09 -05001069 .. doctest::
1070
1071 >>> from cryptography import x509
1072 >>> from cryptography.hazmat.backends import default_backend
1073 >>> from cryptography.hazmat.primitives import hashes
1074 >>> cert = x509.load_pem_x509_certificate(cryptography_cert_pem, default_backend())
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001075 >>> # Get the subjectAltName extension from the certificate
Paul Kehrer93ae8052015-05-02 23:18:09 -05001076 >>> ext = cert.extensions.get_extension_for_oid(x509.OID_SUBJECT_ALTERNATIVE_NAME)
Paul Kehrerd0cd5072015-05-02 23:27:00 -05001077 >>> # Get the dNSName entries from the SAN extension
1078 >>> ext.value.get_values_for_type(x509.DNSName)
Paul Kehrer93ae8052015-05-02 23:18:09 -05001079 [u'www.cryptography.io', u'cryptography.io']
1080
Paul Kehrer8cf26422015-03-21 09:50:24 -05001081
Paul Kehrer99125c92015-06-07 18:37:10 -05001082.. class:: IssuerAlternativeName
1083
1084 .. versionadded:: 1.0
1085
1086 Issuer alternative name is an X.509 extension that provides a list of
1087 :ref:`general name <general_name_classes>` instances that provide a set
1088 of identities for the certificate issuer. The object is iterable to
1089 get every element.
1090
1091 .. method:: get_values_for_type(type)
1092
1093 :param type: A :class:`GeneralName` provider. This is one of the
1094 :ref:`general name classes <general_name_classes>`.
1095
1096 :returns: A list of values extracted from the matched general names.
1097
1098
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001099.. class:: AuthorityInformationAccess
1100
1101 .. versionadded:: 0.9
1102
1103 The authority information access extension indicates how to access
1104 information and services for the issuer of the certificate in which
1105 the extension appears. Information and services may include online
1106 validation services (such as OCSP) and issuer data. It is an iterable,
1107 containing one or more :class:`AccessDescription` instances.
1108
1109
1110.. class:: AccessDescription
1111
Paul Kehrer5a485522015-05-06 00:29:12 -05001112 .. versionadded:: 0.9
1113
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001114 .. attribute:: access_method
1115
1116 :type: :class:`ObjectIdentifier`
1117
Paul Kehrerf506bca2015-05-02 22:31:47 -05001118 The access method defines what the ``access_location`` means. It must
1119 be either :data:`OID_OCSP` or :data:`OID_CA_ISSUERS`. If it is
1120 :data:`OID_OCSP` the access location will be where to obtain OCSP
1121 information for the certificate. If it is :data:`OID_CA_ISSUERS` the
1122 access location will provide additional information about the issuing
1123 certificate.
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001124
1125 .. attribute:: access_location
1126
1127 :type: :class:`GeneralName`
1128
Paul Kehrerf506bca2015-05-02 22:31:47 -05001129 Where to access the information defined by the access method.
1130
Paul Kehrer5a485522015-05-06 00:29:12 -05001131.. class:: CRLDistributionPoints
1132
1133 .. versionadded:: 0.9
1134
1135 The CRL distribution points extension identifies how CRL information is
1136 obtained. It is an iterable, containing one or more
1137 :class:`DistributionPoint` instances.
1138
1139.. class:: DistributionPoint
1140
1141 .. versionadded:: 0.9
1142
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001143 .. attribute:: full_name
Paul Kehrer5a485522015-05-06 00:29:12 -05001144
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001145 :type: list of :class:`GeneralName` instances or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001146
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001147 This field describes methods to retrieve the CRL. At most one of
1148 ``full_name`` or ``relative_name`` will be non-None.
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001149
1150 .. attribute:: relative_name
1151
1152 :type: :class:`Name` or None
1153
1154 This field describes methods to retrieve the CRL relative to the CRL
Paul Kehrerf2c072b2015-05-09 17:04:28 -05001155 issuer. At most one of ``full_name`` or ``relative_name`` will be
1156 non-None.
Paul Kehrer5a485522015-05-06 00:29:12 -05001157
1158 .. attribute:: crl_issuer
1159
1160 :type: list of :class:`GeneralName` instances or None
1161
1162 Information about the issuer of the CRL.
1163
1164 .. attribute:: reasons
1165
Paul Kehrer3fd02602015-05-09 19:46:13 -05001166 :type: frozenset of :class:`ReasonFlags` or None
Paul Kehrer5a485522015-05-06 00:29:12 -05001167
1168 The reasons a given distribution point may be used for when performing
1169 revocation checks.
1170
1171.. class:: ReasonFlags
1172
1173 .. versionadded:: 0.9
1174
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001175 An enumeration for CRL reasons.
1176
1177 .. attribute:: unspecified
1178
1179 It is unspecified why the certificate was revoked. This reason cannot
1180 be used as a reason flag in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001181
1182 .. attribute:: key_compromise
1183
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001184 This reason indicates that the private key was compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001185
1186 .. attribute:: ca_compromise
1187
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001188 This reason indicates that the CA issuing the certificate was
1189 compromised.
Paul Kehrer5a485522015-05-06 00:29:12 -05001190
1191 .. attribute:: affiliation_changed
1192
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001193 This reason indicates that the subject's name or other information has
1194 changed.
Paul Kehrer5a485522015-05-06 00:29:12 -05001195
1196 .. attribute:: superseded
1197
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001198 This reason indicates that a certificate has been superseded.
Paul Kehrer5a485522015-05-06 00:29:12 -05001199
1200 .. attribute:: cessation_of_operation
1201
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001202 This reason indicates that the certificate is no longer required.
Paul Kehrer5a485522015-05-06 00:29:12 -05001203
1204 .. attribute:: certificate_hold
1205
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001206 This reason indicates that the certificate is on hold.
Paul Kehrer5a485522015-05-06 00:29:12 -05001207
1208 .. attribute:: privilege_withdrawn
1209
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001210 This reason indicates that the privilege granted by this certificate
1211 have been withdrawn.
Paul Kehrer5a485522015-05-06 00:29:12 -05001212
1213 .. attribute:: aa_compromise
1214
Paul Kehrer4e8dacd2015-05-09 10:38:23 -05001215 When an attribute authority has been compromised.
1216
1217 .. attribute:: remove_from_crl
1218
1219 This reason indicates that the certificate was on hold and should be
1220 removed from the CRL. This reason cannot be used as a reason flag
1221 in a :class:`DistributionPoint`.
Paul Kehrer5a485522015-05-06 00:29:12 -05001222
Paul Kehrer16fae762015-05-01 23:14:20 -05001223.. class:: InhibitAnyPolicy
1224
1225 .. versionadded:: 1.0
1226
1227 The inhibit ``anyPolicy`` extension indicates that the special OID
1228 :data:`OID_ANY_POLICY`, is not considered an explicit match for other
1229 :class:`CertificatePolicies` except when it appears in an intermediate
1230 self-issued CA certificate. The value indicates the number of additional
1231 non-self-issued certificates that may appear in the path before
1232 :data:`OID_ANY_POLICY` is no longer permitted. For example, a value
1233 of one indicates that :data:`OID_ANY_POLICY` may be processed in
1234 certificates issued by the subject of this certificate, but not in
1235 additional certificates in the path.
1236
1237 .. attribute:: skip_certs
1238
1239 :type: int
1240
Paul Kehrer0d210922015-04-28 17:31:07 -05001241.. class:: CertificatePolicies
1242
1243 .. versionadded:: 0.9
1244
Paul Kehrer2e879742015-05-02 23:09:56 -05001245 The certificate policies extension is an iterable, containing one or more
1246 :class:`PolicyInformation` instances.
Paul Kehrer0d210922015-04-28 17:31:07 -05001247
1248Certificate Policies Classes
1249~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1250
1251These classes may be present within a :class:`CertificatePolicies` instance.
1252
1253.. class:: PolicyInformation
1254
1255 .. versionadded:: 0.9
1256
1257 Contains a policy identifier and an optional list of qualifiers.
1258
1259 .. attribute:: policy_identifier
1260
1261 :type: :class:`ObjectIdentifier`
1262
1263 .. attribute:: policy_qualifiers
1264
1265 :type: list
1266
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001267 A list consisting of :term:`text` and/or :class:`UserNotice` objects.
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05001268 If the value is text it is a pointer to the practice statement
1269 published by the certificate authority. If it is a user notice it is
1270 meant for display to the relying party when the certificate is
1271 used.
Paul Kehrer2e879742015-05-02 23:09:56 -05001272
Paul Kehrer0d210922015-04-28 17:31:07 -05001273.. class:: UserNotice
1274
1275 .. versionadded:: 0.9
1276
Paul Kehrer2e879742015-05-02 23:09:56 -05001277 User notices are intended for display to a relying party when a certificate
1278 is used. In practice, few if any UIs expose this data and it is a rarely
1279 encoded component.
1280
Paul Kehrer0d210922015-04-28 17:31:07 -05001281 .. attribute:: notice_reference
1282
1283 :type: :class:`NoticeReference` or None
1284
Paul Kehrer2e879742015-05-02 23:09:56 -05001285 The notice reference field names an organization and identifies,
1286 by number, a particular statement prepared by that organization.
1287
Paul Kehrer0d210922015-04-28 17:31:07 -05001288 .. attribute:: explicit_text
1289
Paul Kehrer2e879742015-05-02 23:09:56 -05001290 This field includes an arbitrary textual statement directly in the
1291 certificate.
1292
Paul Kehrer0d210922015-04-28 17:31:07 -05001293 :type: :term:`text`
1294
1295.. class:: NoticeReference
1296
Paul Kehrer2e879742015-05-02 23:09:56 -05001297 Notice reference can name an organization and provide information about
1298 notices related to the certificate. For example, it might identify the
1299 organization name and notice number 1. Application software could
1300 have a notice file containing the current set of notices for the named
1301 organization; the application would then extract the notice text from the
1302 file and display it. In practice this is rarely seen.
1303
Paul Kehrer0d210922015-04-28 17:31:07 -05001304 .. versionadded:: 0.9
1305
1306 .. attribute:: organization
1307
Paul Kehrer66c61702015-05-12 16:39:18 -05001308 :type: :term:`text`
Paul Kehrer0d210922015-04-28 17:31:07 -05001309
Paul Kehrer3f8ddeb2015-05-11 00:25:36 -05001310 .. attribute:: notice_numbers
Paul Kehrer0d210922015-04-28 17:31:07 -05001311
Paul Kehrer66c61702015-05-12 16:39:18 -05001312 :type: list
Paul Kehrer0d210922015-04-28 17:31:07 -05001313
Paul Kehrer66c61702015-05-12 16:39:18 -05001314 A list of integers.
Paul Kehrer0d210922015-04-28 17:31:07 -05001315
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001316Object Identifiers
1317~~~~~~~~~~~~~~~~~~
1318
Paul Kehrer4bb46492015-02-07 16:59:14 -06001319X.509 elements are frequently identified by :class:`ObjectIdentifier`
1320instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001321
Paul Kehrer56da2a52015-02-11 23:35:07 -06001322Name OIDs
1323~~~~~~~~~
1324
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001325.. data:: OID_COMMON_NAME
1326
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001327 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
1328 name would be encoded here for server certificates. :rfc:`2818` deprecates
1329 this practice and names of that type should now be located in a
Paul Kehrer4bb46492015-02-07 16:59:14 -06001330 SubjectAlternativeName extension. This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001331
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001332.. data:: OID_COUNTRY_NAME
1333
Paul Kehrer4bb46492015-02-07 16:59:14 -06001334 Corresponds to the dotted string ``"2.5.4.6"``. This OID is typically seen
1335 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001336
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001337.. data:: OID_LOCALITY_NAME
1338
Paul Kehrer4bb46492015-02-07 16:59:14 -06001339 Corresponds to the dotted string ``"2.5.4.7"``. This OID is typically seen
1340 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001341
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001342.. data:: OID_STATE_OR_PROVINCE_NAME
1343
Paul Kehrer4bb46492015-02-07 16:59:14 -06001344 Corresponds to the dotted string ``"2.5.4.8"``. This OID is typically seen
1345 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001346
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001347.. data:: OID_ORGANIZATION_NAME
1348
Paul Kehrer4bb46492015-02-07 16:59:14 -06001349 Corresponds to the dotted string ``"2.5.4.10"``. This OID is typically seen
1350 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001351
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001352.. data:: OID_ORGANIZATIONAL_UNIT_NAME
1353
Paul Kehrer4bb46492015-02-07 16:59:14 -06001354 Corresponds to the dotted string ``"2.5.4.11"``. This OID is typically seen
1355 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001356
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001357.. data:: OID_SERIAL_NUMBER
1358
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001359 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from the
1360 serial number of the certificate itself (which can be obtained with
Paul Kehrer4bb46492015-02-07 16:59:14 -06001361 :func:`Certificate.serial`). This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001362
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001363.. data:: OID_SURNAME
1364
Paul Kehrer4bb46492015-02-07 16:59:14 -06001365 Corresponds to the dotted string ``"2.5.4.4"``. This OID is typically seen
1366 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001367
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001368.. data:: OID_GIVEN_NAME
1369
Paul Kehrer4bb46492015-02-07 16:59:14 -06001370 Corresponds to the dotted string ``"2.5.4.42"``. This OID is typically seen
1371 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001372
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001373.. data:: OID_TITLE
1374
Paul Kehrer4bb46492015-02-07 16:59:14 -06001375 Corresponds to the dotted string ``"2.5.4.12"``. This OID is typically seen
1376 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001377
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001378.. data:: OID_GENERATION_QUALIFIER
1379
Paul Kehrer4bb46492015-02-07 16:59:14 -06001380 Corresponds to the dotted string ``"2.5.4.44"``. This OID is typically seen
1381 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001382
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001383.. data:: OID_DN_QUALIFIER
1384
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001385 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
1386 disambiguating information to add to the relative distinguished name of an
Paul Kehrer4bb46492015-02-07 16:59:14 -06001387 entry. See :rfc:`2256`. This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001388
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001389.. data:: OID_PSEUDONYM
1390
Paul Kehrer4bb46492015-02-07 16:59:14 -06001391 Corresponds to the dotted string ``"2.5.4.65"``. This OID is typically seen
1392 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001393
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001394.. data:: OID_DOMAIN_COMPONENT
1395
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -06001396 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
Paul Kehrer4bb46492015-02-07 16:59:14 -06001397 holding one component of a domain name. See :rfc:`4519`. This OID is
1398 typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001399
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001400.. data:: OID_EMAIL_ADDRESS
1401
Paul Kehrer4bb46492015-02-07 16:59:14 -06001402 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``. This OID is
1403 typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -06001404
Paul Kehrer56da2a52015-02-11 23:35:07 -06001405Signature Algorithm OIDs
1406~~~~~~~~~~~~~~~~~~~~~~~~
1407
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001408.. data:: OID_RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -06001409
1410 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
1411 an MD5 digest signed by an RSA key.
1412
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001413.. data:: OID_RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -06001414
1415 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
1416 a SHA1 digest signed by an RSA key.
1417
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001418.. data:: OID_RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -06001419
1420 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
1421 a SHA224 digest signed by an RSA key.
1422
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001423.. data:: OID_RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -06001424
1425 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
1426 a SHA256 digest signed by an RSA key.
1427
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001428.. data:: OID_RSA_WITH_SHA384
Paul Kehrer56da2a52015-02-11 23:35:07 -06001429
1430 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
1431 a SHA384 digest signed by an RSA key.
1432
Paul Kehrer1a7ba872015-02-19 18:09:05 -06001433.. data:: OID_RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -06001434
1435 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
1436 a SHA512 digest signed by an RSA key.
1437
Alex Gaynor3aadabf2015-06-23 22:06:21 -04001438.. data:: OID_ECDSA_WITH_SHA1
1439
1440 Corresponds to the dotted string ``"1.2.840.10045.4.1"``. This is a SHA1
1441 digest signed by an ECDSA key.
1442
Paul Kehrer56da2a52015-02-11 23:35:07 -06001443.. data:: OID_ECDSA_WITH_SHA224
1444
1445 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
1446 a SHA224 digest signed by an ECDSA key.
1447
1448.. data:: OID_ECDSA_WITH_SHA256
1449
1450 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
1451 a SHA256 digest signed by an ECDSA key.
1452
1453.. data:: OID_ECDSA_WITH_SHA384
1454
1455 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
1456 a SHA384 digest signed by an ECDSA key.
1457
1458.. data:: OID_ECDSA_WITH_SHA512
1459
1460 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
1461 a SHA512 digest signed by an ECDSA key.
1462
1463.. data:: OID_DSA_WITH_SHA1
1464
1465 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
1466 a SHA1 digest signed by a DSA key.
1467
1468.. data:: OID_DSA_WITH_SHA224
1469
1470 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
1471 a SHA224 digest signed by a DSA key.
1472
1473.. data:: OID_DSA_WITH_SHA256
1474
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001475 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
Paul Kehrer56da2a52015-02-11 23:35:07 -06001476 a SHA256 digest signed by a DSA key.
1477
Paul Kehrerffa2a152015-03-31 08:18:25 -05001478.. _eku_oids:
1479
Paul Kehrere1513fa2015-03-30 23:08:17 -05001480Extended Key Usage OIDs
1481~~~~~~~~~~~~~~~~~~~~~~~
1482
1483.. data:: OID_SERVER_AUTH
1484
1485 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used to
1486 denote that a certificate may be used for TLS web server authentication.
1487
1488.. data:: OID_CLIENT_AUTH
1489
1490 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used to
1491 denote that a certificate may be used for TLS web client authentication.
1492
1493.. data:: OID_CODE_SIGNING
1494
1495 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used to
1496 denote that a certificate may be used for code signing.
1497
1498.. data:: OID_EMAIL_PROTECTION
1499
1500 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used to
1501 denote that a certificate may be used for email protection.
1502
1503.. data:: OID_TIME_STAMPING
1504
1505 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used to
1506 denote that a certificate may be used for time stamping.
1507
1508.. data:: OID_OCSP_SIGNING
1509
1510 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used to
1511 denote that a certificate may be used for signing OCSP responses.
1512
Paul Kehrer3e6d5582015-05-02 21:57:56 -05001513Authority Information Access OIDs
1514~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1515
1516.. data:: OID_OCSP
1517
1518 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1"``. Used as the
1519 identifier for OCSP data in :class:`AccessDescription` objects.
1520
1521.. data:: OID_CA_ISSUERS
1522
1523 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.2"``. Used as the
1524 identifier for CA issuer data in :class:`AccessDescription` objects.
1525
Paul Kehrer2e879742015-05-02 23:09:56 -05001526Policy Qualifier OIDs
1527~~~~~~~~~~~~~~~~~~~~~
1528
1529.. data:: OID_CPS_QUALIFIER
1530
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001531 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.1"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05001532
1533.. data:: OID_CPS_USER_NOTICE
1534
Paul Kehrerba35b3b2015-05-10 13:07:59 -05001535 Corresponds to the dotted string ``"1.3.6.1.5.5.7.2.2"``.
Paul Kehrer2e879742015-05-02 23:09:56 -05001536
Paul Kehrer16fae762015-05-01 23:14:20 -05001537.. data:: OID_ANY_POLICY
1538
1539 Corresponds to the dotted string ``"2.5.29.32.0"``.
1540
Paul Kehrer5553d572015-03-23 21:08:01 -05001541.. _extension_oids:
1542
Paul Kehrer2bb94642015-03-21 09:54:17 -05001543Extension OIDs
1544~~~~~~~~~~~~~~
1545
1546.. data:: OID_BASIC_CONSTRAINTS
1547
1548 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
Paul Kehrer611d3d32015-03-22 13:31:18 -05001549 :class:`BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -05001550
Paul Kehrercecbbba2015-03-30 14:58:38 -05001551.. data:: OID_KEY_USAGE
1552
1553 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
1554 :class:`KeyUsage` extension type.
1555
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001556.. data:: OID_SUBJECT_ALTERNATIVE_NAME
1557
1558 Corresponds to the dotted string ``"2.5.29.17"``. The identifier for the
1559 :class:`SubjectAlternativeName` extension type.
1560
Paul Kehrer99125c92015-06-07 18:37:10 -05001561.. data:: OID_ISSUER_ALTERNATIVE_NAME
1562
1563 Corresponds to the dotted string ``"2.5.29.18"``. The identifier for the
1564 :class:`IssuerAlternativeName` extension type.
1565
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001566.. data:: OID_SUBJECT_KEY_IDENTIFIER
1567
1568 Corresponds to the dotted string ``"2.5.29.14"``. The identifier for the
1569 :class:`SubjectKeyIdentifier` extension type.
1570
Paul Kehrere0017be2015-05-17 20:39:40 -06001571.. data:: OID_NAME_CONSTRAINTS
1572
1573 Corresponds to the dotted string ``"2.5.29.30"``. The identifier for the
1574 :class:`NameConstraints` extension type.
1575
Paul Kehrerd4f632e2015-05-12 08:25:42 -05001576.. data:: OID_CRL_DISTRIBUTION_POINTS
1577
1578 Corresponds to the dotted string ``"2.5.29.31"``. The identifier for the
1579 :class:`CRLDistributionPoints` extension type.
1580
1581.. data:: OID_CERTIFICATE_POLICIES
1582
1583 Corresponds to the dotted string ``"2.5.29.32"``. The identifier for the
1584 :class:`CertificatePolicies` extension type.
1585
1586.. data:: OID_AUTHORITY_KEY_IDENTIFIER
1587
1588 Corresponds to the dotted string ``"2.5.29.35"``. The identifier for the
1589 :class:`AuthorityKeyIdentifier` extension type.
1590
1591.. data:: OID_EXTENDED_KEY_USAGE
1592
1593 Corresponds to the dotted string ``"2.5.29.37"``. The identifier for the
1594 :class:`ExtendedKeyUsage` extension type.
1595
1596.. data:: OID_AUTHORITY_INFORMATION_ACCESS
1597
1598 Corresponds to the dotted string ``"1.3.6.1.5.5.7.1.1"``. The identifier
1599 for the :class:`AuthorityInformationAccess` extension type.
Paul Kehrer56da2a52015-02-11 23:35:07 -06001600
Paul Kehrer4a1038e2015-05-18 10:28:31 -07001601.. data:: OID_OCSP_NO_CHECK
1602
1603 Corresponds to the dotted string ``"1.3.6.1.5.5.7.48.1.5"``. The identifier
1604 for the :class:`OCSPNoCheck` extension type.
1605
Paul Kehrer912d3fb2015-01-29 11:19:22 -06001606Exceptions
1607~~~~~~~~~~
1608
Paul Kehrere76cd272014-12-14 19:00:51 -06001609.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -10001610
1611 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -10001612
Paul Kehrerd5cccf72014-12-15 17:20:33 -06001613 .. attribute:: parsed_version
1614
Paul Kehrerbbffc402014-12-17 13:33:55 -06001615 :type: int
1616
1617 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -06001618
Paul Kehrerfbb7ac82015-03-16 19:26:29 -05001619.. class:: DuplicateExtension
1620
1621 This is raised when more than one X.509 extension of the same type is
1622 found within a certificate.
1623
1624 .. attribute:: oid
1625
1626 :type: :class:`ObjectIdentifier`
1627
1628 Returns the OID.
1629
1630.. class:: UnsupportedExtension
1631
1632 This is raised when a certificate contains an unsupported extension type.
1633
1634 .. attribute:: oid
1635
1636 :type: :class:`ObjectIdentifier`
1637
1638 Returns the OID.
1639
Paul Kehrerfa56a232015-03-17 13:14:03 -05001640.. class:: ExtensionNotFound
1641
1642 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
1643 an extension OID that is not present in the certificate.
1644
1645 .. attribute:: oid
1646
1647 :type: :class:`ObjectIdentifier`
1648
1649 Returns the OID.
1650
Paul Kehrer9089c912015-04-20 22:15:20 -05001651.. class:: UnsupportedGeneralNameType
1652
1653 This is raised when a certificate contains an unsupported general name
1654 type in an extension.
1655
Paul Kehrerbed07352015-04-21 08:31:10 -05001656 .. attribute:: type
1657
Paul Kehrer0a621bf2015-04-22 09:22:56 -05001658 :type: int
1659
1660 The integer value of the unsupported type. The complete list of
1661 types can be found in `RFC 5280 section 4.2.1.6`_.
Paul Kehrerbed07352015-04-21 08:31:10 -05001662
Paul Kehrer016e08a2014-11-26 09:41:18 -10001663
Paul Kehrerc7c9a432015-04-19 09:20:13 -05001664.. _`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 -05001665.. _`RFC 5280 section 4.2.1.6`: https://tools.ietf.org/html/rfc5280#section-4.2.1.6