On this page
ssl.SSLContext
Prev: ssl.SSLCertVerificationError | Up: ssl | Next: ssl.SSLEOFError
Rel: ssl.AlertDescription, ssl.cert_time_to_seconds, ssl.CertificateError, ssl.create_connection
Ref: docs.python.org — ssl.SSLContext
Tags: #public #python3 #stdlib #ssl
Import
import ssl
from ssl import SSLContext
Signature & Overview
ssl.SSLContext(protocol=None, *args, **kwargs)
An SSLContext holds various SSL-related configuration options and data, such as certificates and possibly a private key.
Methods & Attributes
SSLContext.cert_store_stats(self, /)— Returns quantities of loaded X.509 certificates.SSLContext.get_ca_certs(self, /, binary_form=False)— Returns a list of dicts with information of loaded CA certs.SSLContext.get_ciphers(self, /)—SSLContext.get_ciphersmethod/property.SSLContext.hostname_checks_common_name(...)—SSLContext.hostname_checks_common_namemethod/property.SSLContext.load_cert_chain(self, /, certfile, keyfile=None, password=None)—SSLContext.load_cert_chainmethod/property.SSLContext.load_default_certs(self, purpose=<Purpose.SERVER_AUTH: _ASN1Object(nid=129, shortname='serverAuth', longname='TLS Web Server Authentication', oid='1.3.6.1.5.5.7.3.1')>)—SSLContext.load_default_certsmethod/property.SSLContext.load_dh_params(self, path, /)—SSLContext.load_dh_paramsmethod/property.SSLContext.load_verify_locations(self, /, cafile=None, capath=None, cadata=None)—SSLContext.load_verify_locationsmethod/property.SSLContext.maximum_version(...)—SSLContext.maximum_versionmethod/property.SSLContext.minimum_version(...)—SSLContext.minimum_versionmethod/property.SSLContext.options(...)—SSLContext.optionsmethod/property.SSLContext.protocol(...)—SSLContext.protocolmethod/property.SSLContext.session_stats(self, /)—SSLContext.session_statsmethod/property.SSLContext.set_alpn_protocols(self, alpn_protocols)—SSLContext.set_alpn_protocolsmethod/property.SSLContext.set_ciphers(self, cipherlist, /)—SSLContext.set_ciphersmethod/property.SSLContext.set_default_verify_paths(self, /)—SSLContext.set_default_verify_pathsmethod/property.SSLContext.set_ecdh_curve(self, name, /)—SSLContext.set_ecdh_curvemethod/property.SSLContext.set_npn_protocols(self, npn_protocols)—SSLContext.set_npn_protocolsmethod/property.SSLContext.set_psk_client_callback(self, /, callback)—SSLContext.set_psk_client_callbackmethod/property.SSLContext.set_psk_server_callback(self, /, callback, identity_hint=None)—SSLContext.set_psk_server_callbackmethod/property.SSLContext.set_servername_callback(self, server_name_callback)—SSLContext.set_servername_callbackmethod/property.SSLContext.sslobject_class(*args, **kwargs)— This class implements an interface on top of a low-level SSL object as implemented by OpenSSL. This object captures the state of an SSL connection but does not provide any network IO itself. IO needs to be performedSSLContext.sslsocket_class(*args, **kwargs)— This class implements a subtype of socket.socket that wraps the underlying OS socket in an SSL context when necessary, and provides read and write methods over that channel.SSLContext.verify_flags(...)—SSLContext.verify_flagsmethod/property.SSLContext.verify_mode(...)—SSLContext.verify_modemethod/property.SSLContext.wrap_bio(self, incoming, outgoing, server_side=False, server_hostname=None, session=None)—SSLContext.wrap_biomethod/property.SSLContext.wrap_socket(self, sock, server_side=False, do_handshake_on_connect=True, suppress_ragged_eofs=True, server_hostname=None, session=None)—SSLContext.wrap_socketmethod/property.
Usage
import ssl
ctx = ssl.create_default_context()
ctx.minimum_version = ssl.TLSVersion.TLSv1_2
assert isinstance(ctx, ssl.SSLContext) and ctx.verify_mode == ssl.CERT_REQUIRED
Gotchas
- Create with
ssl.create_default_context(), not rawSSLContext(): RawSSLContext(PROTOCOL_TLS_CLIENT)has no CA certificates loaded until you callload_default_certs(). - Reuse one
SSLContextacross connections: Loading CA bundles on every request is slow.
REPL Inspect
from ssl import SSLContext
help(SSLContext)
Linked from
Related notes
- tuts/python3/stdlib_module/ssl/SSLCertVerificationError Linked here; links to this page; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/SSLEOFError Linked here; links to this page; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/ssl/AlertDescription Linked here; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/cert_time_to_seconds Linked here; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/CertificateError Linked here; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/create_connection Linked here; shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/create_default_context shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/DefaultVerifyPaths shared tags: #ssl, #stdlib
- tuts/python3/stdlib_module/ssl/DER_cert_to_PEM_cert shared tags: #ssl, #stdlib