cheroot.ssl package#

Submodules#

Module contents#

Implementation of the SSL adapter base interface.

class cheroot.ssl.Adapter(certificate, private_key, certificate_chain=None, ciphers=None, *, private_key_password=None)#

Bases: SSLEnvironMixin, ABC

Base class for SSL driver library adapters.

Required methods:

  • wrap(sock) -> (wrapped socket, ssl environ dict)

  • _get_library_version_environ() -> dict

  • _get_optional_environ(conn) -> dict

_abc_impl = <_abc._abc_data object>#
abstract _get_library_version_environ()#

Get SSL library version information.

Must be implemented by subclasses to provide adapter-specific version strings.

Returns:

dict: SSL_VERSION_INTERFACE and SSL_VERSION_LIBRARY

abstract _get_optional_environ(conn)#

Get optional environment variables.

Must be implemented by subclasses for adapter-specific handling of optional fields like SNI, compression, etc.

Returns:

dict: Optional SSL environment variables

abstract bind(sock)#

Wrap and return the given socket.

get_environ(conn)#

Return WSGI environ entries to be merged into each request.

Unified implementation used by all subclasses. This orchestrates the collection of SSL environment variables from various sources: - Core TLS info (protocol, cipher) - Library versions - Optional fields (SNI, etc.) - Session info - Client certificate - Server certificate

Note: This returns only SSL-specific variables. General server variables (SERVER_NAME, SERVER_PORT, etc.) are added by the Gateway when building the complete WSGI environ for each request.

abstract wrap(sock)#

Wrap and return the given socket, plus WSGI environ entries.

class cheroot.ssl.SSLEnvironMixin#

Bases: object

Mixin class providing methods for generating WSGI environment variables.

This mixin handles GENERIC SSL environment variable generation that works across all SSL implementations. Adapter-specific logic (like certificate parsing) is delegated to subclass implementations.

_get_client_cert_environ(conn, ssl_environ)#

Add client certificate details to the environment.

SHOULD be overridden by subclasses for adapter-specific handling. Default implementation does nothing.

_get_core_tls_environ(conn)#

Add core TLS version and cipher info to the environment.

This is generic and works for all SSL adapters since TLSSocket provides a uniform get_cipher_info() interface.

_get_server_cert_environ()#

Get server certificate info from the connection.

MUST be overridden by subclasses to provide adapter-specific parsing. Returns dict of SSL_SERVER_* environ variables.

Default implementation returns empty dict.

cheroot.ssl._parse_dn_components(components, key_prefix, dn_type)#

Parse Distinguished Name components into environ dict.

Args:

components: Iterable of (key, value) tuples key_prefix: ‘SSL_CLIENT’ or ‘SSL_SERVER’ dn_type: ‘S’ for subject or ‘I’ for issuer

Returns:

dict: DN and CN environment variables

cheroot.ssl.parse_pyopenssl_cert_to_environ(cert, key_prefix)#

Parse a pyOpenSSL X509 certificate into WSGI environ dict.

cheroot.ssl.parse_x509_cert_to_environ(cert, key_prefix)#

Parse a cryptography x509 certificate into environ dict.