blob: d09651fbd7bfe0ee767e77de1bae00794d711062 [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
53X.509 is an ITU-T standard for a `public key infrastructure`_. X.509v3 is
54defined in :rfc:`5280` (which obsoletes :rfc:`2459` and :rfc:`3280`). X.509
55certificates are commonly used in protocols like `TLS`_.
Paul Kehrerb2de9482014-12-11 14:54:48 -060056
57Loading Certificates
58~~~~~~~~~~~~~~~~~~~~
Paul Kehrer016e08a2014-11-26 09:41:18 -100059
60.. function:: load_pem_x509_certificate(data, backend)
61
62 .. versionadded:: 0.7
63
Paul Kehrere76cd272014-12-14 19:00:51 -060064 Deserialize a certificate from PEM encoded data. PEM certificates are
65 base64 decoded and have delimiters that look like
66 ``-----BEGIN CERTIFICATE-----``.
Paul Kehrer016e08a2014-11-26 09:41:18 -100067
68 :param bytes data: The PEM encoded certificate data.
69
70 :param backend: A backend supporting the
71 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
72 interface.
73
Paul Kehrere76cd272014-12-14 19:00:51 -060074 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -100075
76.. function:: load_der_x509_certificate(data, backend)
77
78 .. versionadded:: 0.7
79
Paul Kehrere76cd272014-12-14 19:00:51 -060080 Deserialize a certificate from DER encoded data. DER is a binary format
Paul Kehrer92aac382014-12-15 16:25:28 -060081 and is commonly found in files with the ``.cer`` extension (although file
82 extensions are not a guarantee of encoding type).
Paul Kehrer016e08a2014-11-26 09:41:18 -100083
84 :param bytes data: The DER encoded certificate data.
85
86 :param backend: A backend supporting the
87 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
88 interface.
89
Paul Kehrere76cd272014-12-14 19:00:51 -060090 :returns: An instance of :class:`~cryptography.x509.Certificate`.
Paul Kehrer016e08a2014-11-26 09:41:18 -100091
Paul Kehrer016e08a2014-11-26 09:41:18 -100092.. doctest::
93
Paul Kehrercc8a26e2014-12-16 12:40:16 -060094 >>> from cryptography import x509
Paul Kehrer016e08a2014-11-26 09:41:18 -100095 >>> from cryptography.hazmat.backends import default_backend
Paul Kehrercc8a26e2014-12-16 12:40:16 -060096 >>> cert = x509.load_pem_x509_certificate(pem_data, default_backend())
Paul Kehrer016e08a2014-11-26 09:41:18 -100097 >>> cert.serial
98 2
99
Paul Kehrera1a1f232015-03-15 15:34:35 -0500100Loading Certificate Signing Requests
101~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600102
Paul Kehrer31e39882015-03-11 11:37:04 -0500103.. function:: load_pem_x509_csr(data, backend)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600104
105 .. versionadded:: 0.9
106
Paul Kehrera1a1f232015-03-15 15:34:35 -0500107 Deserialize a certificate signing request (CSR) from PEM encoded data. PEM
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500108 requests are base64 decoded and have delimiters that look like
Paul Kehrerd3dafbd2015-03-15 16:24:18 -0500109 ``-----BEGIN CERTIFICATE REQUEST-----``. This format is also known as
110 PKCS#10.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600111
112 :param bytes data: The PEM encoded request data.
113
114 :param backend: A backend supporting the
115 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
116 interface.
117
Paul Kehrera1a1f232015-03-15 15:34:35 -0500118 :returns: An instance of
119 :class:`~cryptography.x509.CertificateSigningRequest`.
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600120
Paul Kehrer1effb6e2015-03-30 15:05:59 -0500121.. function:: load_der_x509_csr(data, backend)
122
123 .. versionadded:: 0.9
124
125 Deserialize a certificate signing request (CSR) from DER encoded data. DER
126 is a binary format and is not commonly used with CSRs.
127
128 :param bytes data: The DER encoded request data.
129
130 :param backend: A backend supporting the
131 :class:`~cryptography.hazmat.backends.interfaces.X509Backend`
132 interface.
133
134 :returns: An instance of
135 :class:`~cryptography.x509.CertificateSigningRequest`.
136
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600137.. doctest::
138
139 >>> from cryptography import x509
140 >>> from cryptography.hazmat.backends import default_backend
141 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500142 >>> csr = x509.load_pem_x509_csr(pem_req_data, default_backend())
143 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600144 True
145
Paul Kehrere76cd272014-12-14 19:00:51 -0600146X.509 Certificate Object
147~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerb2de9482014-12-11 14:54:48 -0600148
Paul Kehrere76cd272014-12-14 19:00:51 -0600149.. class:: Certificate
Paul Kehrerb2de9482014-12-11 14:54:48 -0600150
151 .. versionadded:: 0.7
152
153 .. attribute:: version
154
Paul Kehrere76cd272014-12-14 19:00:51 -0600155 :type: :class:`~cryptography.x509.Version`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600156
Paul Kehrere76cd272014-12-14 19:00:51 -0600157 The certificate version as an enumeration. Version 3 certificates are
158 the latest version and also the only type you should see in practice.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600159
Alex Gaynor89c4dc82014-12-16 16:49:33 -0800160 :raises cryptography.x509.InvalidVersion: If the version in the
Alex Gaynor6d7ab4c2014-12-16 16:50:33 -0800161 certificate is not a known
162 :class:`X.509 version <cryptography.x509.Version>`.
Paul Kehrer92aac382014-12-15 16:25:28 -0600163
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600164 .. doctest::
165
166 >>> cert.version
167 <Version.v3: 2>
168
Paul Kehrerb2de9482014-12-11 14:54:48 -0600169 .. method:: fingerprint(algorithm)
170
171 :param algorithm: The
Paul Kehrer601278a2015-02-12 12:51:00 -0600172 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600173 that will be used to generate the fingerprint.
174
175 :return bytes: The fingerprint using the supplied hash algorithm as
176 bytes.
177
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600178 .. doctest::
179
180 >>> from cryptography.hazmat.primitives import hashes
181 >>> cert.fingerprint(hashes.SHA256())
Paul Kehrer78a81502014-12-16 14:47:52 -0600182 '\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 -0600183
Paul Kehrerb2de9482014-12-11 14:54:48 -0600184 .. attribute:: serial
185
186 :type: int
187
188 The serial as a Python integer.
189
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600190 .. doctest::
191
192 >>> cert.serial
193 2
194
Paul Kehrerb2de9482014-12-11 14:54:48 -0600195 .. method:: public_key()
196
197 :type:
Alex Stapletonf79c2312014-12-30 12:50:14 +0000198 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
Paul Kehrer45efdbc2015-02-12 10:58:22 -0600199 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
200 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
Paul Kehrerb2de9482014-12-11 14:54:48 -0600201
202 The public key associated with the certificate.
203
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600204 .. doctest::
205
Alex Stapletonf79c2312014-12-30 12:50:14 +0000206 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600207 >>> public_key = cert.public_key()
Alex Stapletonf79c2312014-12-30 12:50:14 +0000208 >>> isinstance(public_key, rsa.RSAPublicKey)
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600209 True
210
Paul Kehrerb2de9482014-12-11 14:54:48 -0600211 .. attribute:: not_valid_before
212
213 :type: :class:`datetime.datetime`
214
Paul Kehrer78a81502014-12-16 14:47:52 -0600215 A naïve datetime representing the beginning of the validity period for
216 the certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600217
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600218 .. doctest::
219
220 >>> cert.not_valid_before
221 datetime.datetime(2010, 1, 1, 8, 30)
222
Paul Kehrerb2de9482014-12-11 14:54:48 -0600223 .. attribute:: not_valid_after
224
225 :type: :class:`datetime.datetime`
226
Paul Kehrer78a81502014-12-16 14:47:52 -0600227 A naïve datetime representing the end of the validity period for the
228 certificate in UTC. This value is inclusive.
Paul Kehrerb2de9482014-12-11 14:54:48 -0600229
Paul Kehrercc8a26e2014-12-16 12:40:16 -0600230 .. doctest::
231
232 >>> cert.not_valid_after
233 datetime.datetime(2030, 12, 31, 8, 30)
234
Paul Kehrer719d5362015-01-01 20:03:52 -0600235 .. attribute:: issuer
236
237 .. versionadded:: 0.8
238
239 :type: :class:`Name`
240
241 The :class:`Name` of the issuer.
242
243 .. attribute:: subject
244
245 .. versionadded:: 0.8
246
247 :type: :class:`Name`
248
249 The :class:`Name` of the subject.
250
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600251 .. attribute:: signature_hash_algorithm
Paul Kehrer56da2a52015-02-11 23:35:07 -0600252
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600253 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
Paul Kehrer56da2a52015-02-11 23:35:07 -0600254
Paul Kehrere612ec72015-02-16 14:33:35 -0600255 Returns the
Paul Kehrer71d40c62015-02-19 08:21:04 -0600256 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600257 was used in signing this certificate.
Paul Kehrer56da2a52015-02-11 23:35:07 -0600258
259 .. doctest::
260
Paul Kehrer8802a5b2015-02-13 12:06:57 -0600261 >>> from cryptography.hazmat.primitives import hashes
262 >>> isinstance(cert.signature_hash_algorithm, hashes.SHA256)
263 True
Paul Kehrer719d5362015-01-01 20:03:52 -0600264
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500265 .. attribute:: extensions
266
267 :type: :class:`Extensions`
268
269 The extensions encoded in the certificate.
270
271 :raises cryptography.x509.DuplicateExtension: If more than one
272 extension of the same type is found within the certificate.
273
Paul Kehrerfa56a232015-03-17 13:14:03 -0500274 .. doctest::
275
276 >>> for ext in cert.extensions:
277 ... print(ext)
Paul Kehrercbfb1012015-04-10 20:57:20 -0400278 <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 Kehrerfa56a232015-03-17 13:14:03 -0500279 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
280
Paul Kehrer5aadb9c2015-03-11 20:48:42 -0500281X.509 CSR (Certificate Signing Request) Object
282~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600283
Paul Kehrera1a1f232015-03-15 15:34:35 -0500284.. class:: CertificateSigningRequest
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600285
286 .. versionadded:: 0.9
287
288 .. method:: public_key()
289
290 :type:
291 :class:`~cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey` or
292 :class:`~cryptography.hazmat.primitives.asymmetric.dsa.DSAPublicKey` or
293 :class:`~cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey`
294
295 The public key associated with the request.
296
297 .. doctest::
298
299 >>> from cryptography.hazmat.primitives.asymmetric import rsa
Paul Kehrera1a1f232015-03-15 15:34:35 -0500300 >>> public_key = csr.public_key()
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600301 >>> isinstance(public_key, rsa.RSAPublicKey)
302 True
303
304 .. attribute:: subject
305
306 :type: :class:`Name`
307
308 The :class:`Name` of the subject.
309
310 .. attribute:: signature_hash_algorithm
311
312 :type: :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm`
313
314 Returns the
315 :class:`~cryptography.hazmat.primitives.hashes.HashAlgorithm` which
316 was used in signing this request.
317
318 .. doctest::
319
320 >>> from cryptography.hazmat.primitives import hashes
Paul Kehrera1a1f232015-03-15 15:34:35 -0500321 >>> isinstance(csr.signature_hash_algorithm, hashes.SHA1)
Paul Kehrerdc480ad2015-02-23 12:14:54 -0600322 True
323
Paul Kehrer719d5362015-01-01 20:03:52 -0600324.. class:: Name
325
326 .. versionadded:: 0.8
327
Paul Kehrer53d8d492015-02-13 18:47:30 -0600328 An X509 Name is an ordered list of attributes. The object is iterable to
Paul Kehrerd21596e2015-02-14 09:17:26 -0600329 get every attribute or you can use :meth:`Name.get_attributes_for_oid` to
Paul Kehrer719d5362015-01-01 20:03:52 -0600330 obtain the specific type you want. Names are sometimes represented as a
Paul Kehrer53d8d492015-02-13 18:47:30 -0600331 slash or comma delimited string (e.g. ``/CN=mydomain.com/O=My Org/C=US`` or
332 ``CN=mydomain.com, O=My Org, C=US``).
Paul Kehrer719d5362015-01-01 20:03:52 -0600333
Paul Kehrer53d8d492015-02-13 18:47:30 -0600334 .. doctest::
Paul Kehrer719d5362015-01-01 20:03:52 -0600335
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600336 >>> len(cert.subject)
Paul Kehrer53d8d492015-02-13 18:47:30 -0600337 3
Paul Kehrer8b21a4a2015-02-14 07:56:36 -0600338 >>> for attribute in cert.subject:
339 ... print(attribute)
340 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
341 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'Test Certificates 2011')>
342 <NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>
Paul Kehrer719d5362015-01-01 20:03:52 -0600343
Paul Kehrere901d642015-02-11 18:50:58 -0600344 .. method:: get_attributes_for_oid(oid)
Paul Kehrer719d5362015-01-01 20:03:52 -0600345
Paul Kehrere901d642015-02-11 18:50:58 -0600346 :param oid: An :class:`ObjectIdentifier` instance.
Paul Kehrer719d5362015-01-01 20:03:52 -0600347
Paul Kehrere901d642015-02-11 18:50:58 -0600348 :returns: A list of :class:`NameAttribute` instances that match the
349 OID provided. If nothing matches an empty list will be returned.
Paul Kehrer719d5362015-01-01 20:03:52 -0600350
351 .. doctest::
352
Paul Kehrere901d642015-02-11 18:50:58 -0600353 >>> cert.subject.get_attributes_for_oid(x509.OID_COMMON_NAME)
354 [<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'Good CA')>]
Paul Kehrerb2de9482014-12-11 14:54:48 -0600355
Paul Kehrere76cd272014-12-14 19:00:51 -0600356.. class:: Version
Paul Kehrer016e08a2014-11-26 09:41:18 -1000357
358 .. versionadded:: 0.7
359
360 An enumeration for X.509 versions.
361
362 .. attribute:: v1
363
364 For version 1 X.509 certificates.
365
366 .. attribute:: v3
367
368 For version 3 X.509 certificates.
369
Paul Kehrer806bfb22015-02-02 17:05:24 -0600370.. class:: NameAttribute
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600371
372 .. versionadded:: 0.8
373
Paul Kehrer834d22f2015-02-06 11:01:07 -0600374 An X.509 name consists of a list of NameAttribute instances.
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600375
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600376 .. attribute:: oid
377
378 :type: :class:`ObjectIdentifier`
379
380 The attribute OID.
381
382 .. attribute:: value
383
Paul Kehrerd5852cb2015-01-30 08:25:23 -0600384 :type: :term:`text`
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600385
386 The value of the attribute.
387
388.. class:: ObjectIdentifier
389
390 .. versionadded:: 0.8
391
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600392 Object identifiers (frequently seen abbreviated as OID) identify the type
Paul Kehrer806bfb22015-02-02 17:05:24 -0600393 of a value (see: :class:`NameAttribute`).
Paul Kehrer5b0a8d62015-01-30 20:05:55 -0600394
Paul Kehrerd44f9a62015-02-04 14:47:34 -0600395 .. attribute:: dotted_string
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600396
397 :type: :class:`str`
398
Paul Kehrerfedf4f42015-02-06 11:22:07 -0600399 The dotted string value of the OID (e.g. ``"2.5.4.3"``)
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600400
Paul Kehrer8cf26422015-03-21 09:50:24 -0500401X.509 Extensions
402~~~~~~~~~~~~~~~~
403
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500404.. class:: Extensions
405
406 .. versionadded:: 0.9
407
408 An X.509 Extensions instance is an ordered list of extensions. The object
409 is iterable to get every extension.
410
Paul Kehrerfa56a232015-03-17 13:14:03 -0500411 .. method:: get_extension_for_oid(oid)
412
413 :param oid: An :class:`ObjectIdentifier` instance.
414
415 :returns: An instance of the extension class.
416
417 :raises cryptography.x509.ExtensionNotFound: If the certificate does
418 not have the extension requested.
419
420 :raises cryptography.x509.UnsupportedExtension: If the certificate
421 contains an extension that is not supported.
422
423 .. doctest::
424
425 >>> cert.extensions.get_extension_for_oid(x509.OID_BASIC_CONSTRAINTS)
426 <Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConstraints)>, critical=True, value=<BasicConstraints(ca=True, path_length=None)>)>
427
Paul Kehrer8cf26422015-03-21 09:50:24 -0500428.. class:: Extension
429
430 .. versionadded:: 0.9
431
Paul Kehrer85894662015-03-22 13:19:31 -0500432 .. attribute:: oid
433
434 :type: :class:`ObjectIdentifier`
435
Paul Kehrer5553d572015-03-23 21:08:01 -0500436 The :ref:`extension OID <extension_oids>`.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500437
438 .. attribute:: critical
439
440 :type: bool
441
Paul Kehrer58b75692015-03-22 23:24:58 -0500442 Determines whether a given extension is critical or not. :rfc:`5280`
443 requires that "A certificate-using system MUST reject the certificate
444 if it encounters a critical extension it does not recognize or a
445 critical extension that contains information that it cannot process".
Paul Kehrer8cf26422015-03-21 09:50:24 -0500446
Paul Kehrer85894662015-03-22 13:19:31 -0500447 .. attribute:: value
448
449 Returns an instance of the extension type corresponding to the OID.
450
Paul Kehrercecbbba2015-03-30 14:58:38 -0500451.. class:: KeyUsage
452
453 .. versionadded:: 0.9
454
455 The key usage extension defines the purpose of the key contained in the
456 certificate. The usage restriction might be employed when a key that could
457 be used for more than one operation is to be restricted. It corresponds to
458 :data:`OID_KEY_USAGE`.
459
460 .. attribute:: digital_signature
461
462 :type: bool
463
Paul Kehrer738407b2015-04-01 22:39:02 -0500464 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500465 digital signatures, other than signatures on certificates
466 (``key_cert_sign``) and CRLs (``crl_sign``).
467
468 .. attribute:: content_commitment
469
470 :type: bool
471
Paul Kehrer738407b2015-04-01 22:39:02 -0500472 This purpose is set to true when the subject public key is used for verifying
Paul Kehrercecbbba2015-03-30 14:58:38 -0500473 digital signatures, other than signatures on certificates
474 (``key_cert_sign``) and CRLs (``crl_sign``). It is used to provide a
475 non-repudiation service that protects against the signing entity
476 falsely denying some action. In the case of later conflict, a
477 reliable third party may determine the authenticity of the signed
478 data. This was called ``non_repudiation`` in older revisions of the
479 X.509 specification.
480
481 .. attribute:: key_encipherment
482
483 :type: bool
484
Paul Kehrer738407b2015-04-01 22:39:02 -0500485 This purpose is set to true when the subject public key is used for
486 enciphering private or secret keys.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500487
488 .. attribute:: data_encipherment
489
490 :type: bool
491
Paul Kehrer738407b2015-04-01 22:39:02 -0500492 This purpose is set to true when the subject public key is used for
493 directly enciphering raw user data without the use of an intermediate
494 symmetric cipher.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500495
496 .. attribute:: key_agreement
497
498 :type: bool
499
Paul Kehrer738407b2015-04-01 22:39:02 -0500500 This purpose is set to true when the subject public key is used for key
501 agreement. For example, when a Diffie-Hellman key is to be used for
502 key management, then this purpose is set to true.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500503
504 .. attribute:: key_cert_sign
505
506 :type: bool
507
Paul Kehrer738407b2015-04-01 22:39:02 -0500508 This purpose is set to true when the subject public key is used for
509 verifying signatures on public key certificates. If this purpose is set
510 to true then ``ca`` must be true in the :class:`BasicConstraints`
511 extension.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500512
513 .. attribute:: crl_sign
514
515 :type: bool
516
Paul Kehrer738407b2015-04-01 22:39:02 -0500517 This purpose is set to true when the subject public key is used for
518 verifying signatures on certificate revocation lists.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500519
520 .. attribute:: encipher_only
521
522 :type: bool
523
Paul Kehrer738407b2015-04-01 22:39:02 -0500524 When this purposes is set to true and the ``key_agreement`` purpose is
525 also set, the subject public key may be used only for enciphering data
526 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500527
528 :raises ValueError: This is raised if accessed when ``key_agreement``
529 is false.
530
531 .. attribute:: decipher_only
532
533 :type: bool
534
Paul Kehrer738407b2015-04-01 22:39:02 -0500535 When this purposes is set to true and the ``key_agreement`` purpose is
536 also set, the subject public key may be used only for deciphering data
537 while performing key agreement.
Paul Kehrercecbbba2015-03-30 14:58:38 -0500538
539 :raises ValueError: This is raised if accessed when ``key_agreement``
540 is false.
541
542
Paul Kehrer8cf26422015-03-21 09:50:24 -0500543.. class:: BasicConstraints
544
545 .. versionadded:: 0.9
546
Paul Kehrer85894662015-03-22 13:19:31 -0500547 Basic constraints is an X.509 extension type that defines whether a given
Paul Kehrer8cf26422015-03-21 09:50:24 -0500548 certificate is allowed to sign additional certificates and what path
Paul Kehrer85894662015-03-22 13:19:31 -0500549 length restrictions may exist. It corresponds to
550 :data:`OID_BASIC_CONSTRAINTS`.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500551
552 .. attribute:: ca
553
554 :type: bool
555
556 Whether the certificate can sign certificates.
557
558 .. attribute:: path_length
559
Paul Kehrerfd1444c2015-03-21 19:47:05 -0500560 :type: int or None
Paul Kehrer8cf26422015-03-21 09:50:24 -0500561
562 The maximum path length for certificates subordinate to this
563 certificate. This attribute only has meaning if ``ca`` is true.
564 If ``ca`` is true then a path length of None means there's no
565 restriction on the number of subordinate CAs in the certificate chain.
566 If it is zero or greater then that number defines the maximum length.
567 For example, a ``path_length`` of 1 means the certificate can sign a
568 subordinate CA, but the subordinate CA is not allowed to create
Paul Kehrerfd1444c2015-03-21 19:47:05 -0500569 subordinates with ``ca`` set to true.
Paul Kehrer8cf26422015-03-21 09:50:24 -0500570
Paul Kehrerffa2a152015-03-31 08:18:25 -0500571.. class:: ExtendedKeyUsage
572
573 .. versionadded:: 0.9
574
575 This extension indicates one or more purposes for which the certified
576 public key may be used, in addition to or in place of the basic
577 purposes indicated in the key usage extension. The object is
578 iterable to obtain the list of :ref:`extended key usage OIDs <eku_oids>`.
579
Paul Kehrer1eb82a62015-03-31 20:00:33 -0500580.. class:: SubjectKeyIdentifier
581
582 .. versionadded:: 0.9
583
584 The subject key identifier extension provides a means of identifying
585 certificates that contain a particular public key.
586
587 .. attribute:: digest
588
589 :type: bytes
590
591 The binary value of the identifier.
592
Paul Kehrer8cf26422015-03-21 09:50:24 -0500593
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600594Object Identifiers
595~~~~~~~~~~~~~~~~~~
596
Paul Kehrer4bb46492015-02-07 16:59:14 -0600597X.509 elements are frequently identified by :class:`ObjectIdentifier`
598instances. The following common OIDs are available as constants.
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600599
Paul Kehrer56da2a52015-02-11 23:35:07 -0600600Name OIDs
601~~~~~~~~~
602
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600603.. data:: OID_COMMON_NAME
604
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -0600605 Corresponds to the dotted string ``"2.5.4.3"``. Historically the domain
606 name would be encoded here for server certificates. :rfc:`2818` deprecates
607 this practice and names of that type should now be located in a
Paul Kehrer4bb46492015-02-07 16:59:14 -0600608 SubjectAlternativeName extension. This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600609
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600610.. data:: OID_COUNTRY_NAME
611
Paul Kehrer4bb46492015-02-07 16:59:14 -0600612 Corresponds to the dotted string ``"2.5.4.6"``. This OID is typically seen
613 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600614
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600615.. data:: OID_LOCALITY_NAME
616
Paul Kehrer4bb46492015-02-07 16:59:14 -0600617 Corresponds to the dotted string ``"2.5.4.7"``. This OID is typically seen
618 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600619
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600620.. data:: OID_STATE_OR_PROVINCE_NAME
621
Paul Kehrer4bb46492015-02-07 16:59:14 -0600622 Corresponds to the dotted string ``"2.5.4.8"``. This OID is typically seen
623 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600624
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600625.. data:: OID_ORGANIZATION_NAME
626
Paul Kehrer4bb46492015-02-07 16:59:14 -0600627 Corresponds to the dotted string ``"2.5.4.10"``. This OID is typically seen
628 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600629
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600630.. data:: OID_ORGANIZATIONAL_UNIT_NAME
631
Paul Kehrer4bb46492015-02-07 16:59:14 -0600632 Corresponds to the dotted string ``"2.5.4.11"``. This OID is typically seen
633 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600634
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600635.. data:: OID_SERIAL_NUMBER
636
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -0600637 Corresponds to the dotted string ``"2.5.4.5"``. This is distinct from the
638 serial number of the certificate itself (which can be obtained with
Paul Kehrer4bb46492015-02-07 16:59:14 -0600639 :func:`Certificate.serial`). This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600640
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600641.. data:: OID_SURNAME
642
Paul Kehrer4bb46492015-02-07 16:59:14 -0600643 Corresponds to the dotted string ``"2.5.4.4"``. This OID is typically seen
644 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600645
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600646.. data:: OID_GIVEN_NAME
647
Paul Kehrer4bb46492015-02-07 16:59:14 -0600648 Corresponds to the dotted string ``"2.5.4.42"``. This OID is typically seen
649 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600650
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600651.. data:: OID_TITLE
652
Paul Kehrer4bb46492015-02-07 16:59:14 -0600653 Corresponds to the dotted string ``"2.5.4.12"``. This OID is typically seen
654 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600655
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600656.. data:: OID_GENERATION_QUALIFIER
657
Paul Kehrer4bb46492015-02-07 16:59:14 -0600658 Corresponds to the dotted string ``"2.5.4.44"``. This OID is typically seen
659 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600660
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600661.. data:: OID_DN_QUALIFIER
662
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -0600663 Corresponds to the dotted string ``"2.5.4.46"``. This specifies
664 disambiguating information to add to the relative distinguished name of an
Paul Kehrer4bb46492015-02-07 16:59:14 -0600665 entry. See :rfc:`2256`. This OID is typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600666
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600667.. data:: OID_PSEUDONYM
668
Paul Kehrer4bb46492015-02-07 16:59:14 -0600669 Corresponds to the dotted string ``"2.5.4.65"``. This OID is typically seen
670 in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600671
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600672.. data:: OID_DOMAIN_COMPONENT
673
Paul Kehrerfb5ac9e2015-02-07 16:29:37 -0600674 Corresponds to the dotted string ``"0.9.2342.19200300.100.1.25"``. A string
Paul Kehrer4bb46492015-02-07 16:59:14 -0600675 holding one component of a domain name. See :rfc:`4519`. This OID is
676 typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600677
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600678.. data:: OID_EMAIL_ADDRESS
679
Paul Kehrer4bb46492015-02-07 16:59:14 -0600680 Corresponds to the dotted string ``"1.2.840.113549.1.9.1"``. This OID is
681 typically seen in X.509 names.
Paul Kehrer858b9b72015-02-05 09:50:31 -0600682
Paul Kehrer56da2a52015-02-11 23:35:07 -0600683Signature Algorithm OIDs
684~~~~~~~~~~~~~~~~~~~~~~~~
685
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600686.. data:: OID_RSA_WITH_MD5
Paul Kehrer56da2a52015-02-11 23:35:07 -0600687
688 Corresponds to the dotted string ``"1.2.840.113549.1.1.4"``. This is
689 an MD5 digest signed by an RSA key.
690
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600691.. data:: OID_RSA_WITH_SHA1
Paul Kehrer56da2a52015-02-11 23:35:07 -0600692
693 Corresponds to the dotted string ``"1.2.840.113549.1.1.5"``. This is
694 a SHA1 digest signed by an RSA key.
695
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600696.. data:: OID_RSA_WITH_SHA224
Paul Kehrer56da2a52015-02-11 23:35:07 -0600697
698 Corresponds to the dotted string ``"1.2.840.113549.1.1.14"``. This is
699 a SHA224 digest signed by an RSA key.
700
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600701.. data:: OID_RSA_WITH_SHA256
Paul Kehrer56da2a52015-02-11 23:35:07 -0600702
703 Corresponds to the dotted string ``"1.2.840.113549.1.1.11"``. This is
704 a SHA256 digest signed by an RSA key.
705
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600706.. data:: OID_RSA_WITH_SHA384
Paul Kehrer56da2a52015-02-11 23:35:07 -0600707
708 Corresponds to the dotted string ``"1.2.840.113549.1.1.12"``. This is
709 a SHA384 digest signed by an RSA key.
710
Paul Kehrer1a7ba872015-02-19 18:09:05 -0600711.. data:: OID_RSA_WITH_SHA512
Paul Kehrer56da2a52015-02-11 23:35:07 -0600712
713 Corresponds to the dotted string ``"1.2.840.113549.1.1.13"``. This is
714 a SHA512 digest signed by an RSA key.
715
716.. data:: OID_ECDSA_WITH_SHA224
717
718 Corresponds to the dotted string ``"1.2.840.10045.4.3.1"``. This is
719 a SHA224 digest signed by an ECDSA key.
720
721.. data:: OID_ECDSA_WITH_SHA256
722
723 Corresponds to the dotted string ``"1.2.840.10045.4.3.2"``. This is
724 a SHA256 digest signed by an ECDSA key.
725
726.. data:: OID_ECDSA_WITH_SHA384
727
728 Corresponds to the dotted string ``"1.2.840.10045.4.3.3"``. This is
729 a SHA384 digest signed by an ECDSA key.
730
731.. data:: OID_ECDSA_WITH_SHA512
732
733 Corresponds to the dotted string ``"1.2.840.10045.4.3.4"``. This is
734 a SHA512 digest signed by an ECDSA key.
735
736.. data:: OID_DSA_WITH_SHA1
737
738 Corresponds to the dotted string ``"1.2.840.10040.4.3"``. This is
739 a SHA1 digest signed by a DSA key.
740
741.. data:: OID_DSA_WITH_SHA224
742
743 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.1"``. This is
744 a SHA224 digest signed by a DSA key.
745
746.. data:: OID_DSA_WITH_SHA256
747
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500748 Corresponds to the dotted string ``"2.16.840.1.101.3.4.3.2"``. This is
Paul Kehrer56da2a52015-02-11 23:35:07 -0600749 a SHA256 digest signed by a DSA key.
750
Paul Kehrerffa2a152015-03-31 08:18:25 -0500751.. _eku_oids:
752
Paul Kehrere1513fa2015-03-30 23:08:17 -0500753Extended Key Usage OIDs
754~~~~~~~~~~~~~~~~~~~~~~~
755
756.. data:: OID_SERVER_AUTH
757
758 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.1"``. This is used to
759 denote that a certificate may be used for TLS web server authentication.
760
761.. data:: OID_CLIENT_AUTH
762
763 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.2"``. This is used to
764 denote that a certificate may be used for TLS web client authentication.
765
766.. data:: OID_CODE_SIGNING
767
768 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.3"``. This is used to
769 denote that a certificate may be used for code signing.
770
771.. data:: OID_EMAIL_PROTECTION
772
773 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.4"``. This is used to
774 denote that a certificate may be used for email protection.
775
776.. data:: OID_TIME_STAMPING
777
778 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.8"``. This is used to
779 denote that a certificate may be used for time stamping.
780
781.. data:: OID_OCSP_SIGNING
782
783 Corresponds to the dotted string ``"1.3.6.1.5.5.7.3.9"``. This is used to
784 denote that a certificate may be used for signing OCSP responses.
785
Paul Kehrer5553d572015-03-23 21:08:01 -0500786.. _extension_oids:
787
Paul Kehrer2bb94642015-03-21 09:54:17 -0500788Extension OIDs
789~~~~~~~~~~~~~~
790
791.. data:: OID_BASIC_CONSTRAINTS
792
793 Corresponds to the dotted string ``"2.5.29.19"``. The identifier for the
Paul Kehrer611d3d32015-03-22 13:31:18 -0500794 :class:`BasicConstraints` extension type.
Paul Kehrer2bb94642015-03-21 09:54:17 -0500795
Paul Kehrercecbbba2015-03-30 14:58:38 -0500796.. data:: OID_KEY_USAGE
797
798 Corresponds to the dotted string ``"2.5.29.15"``. The identifier for the
799 :class:`KeyUsage` extension type.
800
Paul Kehrer56da2a52015-02-11 23:35:07 -0600801
Paul Kehrer912d3fb2015-01-29 11:19:22 -0600802Exceptions
803~~~~~~~~~~
804
Paul Kehrere76cd272014-12-14 19:00:51 -0600805.. class:: InvalidVersion
Paul Kehrera68fd332014-11-27 07:08:40 -1000806
807 This is raised when an X.509 certificate has an invalid version number.
Paul Kehrer016e08a2014-11-26 09:41:18 -1000808
Paul Kehrerd5cccf72014-12-15 17:20:33 -0600809 .. attribute:: parsed_version
810
Paul Kehrerbbffc402014-12-17 13:33:55 -0600811 :type: int
812
813 Returns the raw version that was parsed from the certificate.
Paul Kehrerd5cccf72014-12-15 17:20:33 -0600814
Paul Kehrerfbb7ac82015-03-16 19:26:29 -0500815.. class:: DuplicateExtension
816
817 This is raised when more than one X.509 extension of the same type is
818 found within a certificate.
819
820 .. attribute:: oid
821
822 :type: :class:`ObjectIdentifier`
823
824 Returns the OID.
825
826.. class:: UnsupportedExtension
827
828 This is raised when a certificate contains an unsupported extension type.
829
830 .. attribute:: oid
831
832 :type: :class:`ObjectIdentifier`
833
834 Returns the OID.
835
Paul Kehrerfa56a232015-03-17 13:14:03 -0500836.. class:: ExtensionNotFound
837
838 This is raised when calling :meth:`Extensions.get_extension_for_oid` with
839 an extension OID that is not present in the certificate.
840
841 .. attribute:: oid
842
843 :type: :class:`ObjectIdentifier`
844
845 Returns the OID.
846
Paul Kehrer016e08a2014-11-26 09:41:18 -1000847
848.. _`public key infrastructure`: https://en.wikipedia.org/wiki/Public_key_infrastructure
Paul Kehrera68fd332014-11-27 07:08:40 -1000849.. _`TLS`: https://en.wikipedia.org/wiki/Transport_Layer_Security