Skip to main content

Secure Context

Utilities for creation of SSL/TLS security contexts for servers and clients

The purpose of this module is to expose, simple to use, secure definitions that follow current, community agreed, standards. As of now it offers methods for creation of client and server secure contexts.

It is STRONGLY RECOMMENDED that you READ the CODE BEFORE considering USING this library. I am NOT RESPONSIBLE if your product is hacked or cats become humans overlords due to usage of this code.

Documentation

Currently, only two functions are exported:

def create_server_ssl_context(
    cert_file: Union[Path, str],
    key_file: Union[Path, str],
    *,
    ca_file: Optional[Union[Path, str]] = None,
    ca_path: Optional[Union[Path, str]] = None,
    ca_data: Optional[Union[bytes, str]] = None,
    crl_file: Optional[Union[Path, str]] = None,
    protocols: Optional[List[str]] = None,
    ca_load_default: bool = False,
) -> ssl.SSLContext:
    """Create SSL context for TLS servers

    Args:
        cert_file: Path to SSL certificate file
        key_file: Path to private key file
        ca_file: Path to a file of concatenated CA certificates in PEM format
        ca_path: Path to a directory containing CA certificates in PEM format, following an OpenSSL specific layout
        ca_data: ASCII string of one or more PEM-encoded certificates or a bytes-like object of DER-encoded certificates
        crl_file: Path to a certificate revocation list file
        protocols: ALPN and NPN protocols accepted
        ca_load_default: Whether to load system defaults (default: {False})

    Note:
        If any of `ca_file`, `ca_path`, `ca_data` are defined client authentication will be enabled, which requires all
        clients to provide a accepted certificate to connect to the server.

    Raises:
        SSLError: Occurs if SSLContext creation fails
        FileNotFoundError: Occurs if a file path is invalid

    Returns:
        SSL context

    """
    ...
def create_client_authentication_ssl_context(
    cert_file: Union[Path, str],
    key_file: Union[Path, str],
    *,
    ca_file: Optional[Union[Path, str]] = None,
    ca_path: Optional[Union[Path, str]] = None,
    ca_data: Optional[Union[bytes, str]] = None,
    crl_file: Optional[Union[Path, str]] = None,
    protocols: Optional[List[str]] = None,
    check_hostname: bool = True,
) -> ssl.SSLContext:
    """Create SSL context for clients that require TLS client authentication

    WARNING:
        For clients that DO NOT require client authentication,
        ssl.create_default_context should be used instead

    Args:
        cert_file: Path to SSL certificate file
        key_file: Path to private key file
        ca_file: Path to a file of concatenated CA certificates in PEM format
        ca_path: Path to a directory containing CA certificates in PEM format, following an OpenSSL specific layout
        ca_data: ASCII string of one or more PEM-encoded certificates or a bytes-like object of DER-encoded certificates
        crl_file: Path to a certificate revocation list file
        protocols: ALPN and NPN protocols accepted
        check_hostname: Server hostname match (default: {False})

    Raises:
        SSLError: Occurs if SSLContext creation fails
        FileNotFoundError: Occurs if a file path is invalid

    Returns:
        SSL context

    """
    ...

License

Copyright © 2019-2021 Vítor Vasconcellos

BSD-3-Clause

Release files for secure-context 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for secure-context 2.0.0
File Size Uploaded
secure_context-2.0.0.tar.gz 11.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for secure-context 2.0.0
File
secure_context-2.0.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.6 abi3 Linux glibc 2.17+ x86-64 Details
secure_context-2.0.0-cp36-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl CPython 3.6 abi3 Linux glibc 2.17+ PowerPC 64-le Details
secure_context-2.0.0-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl CPython 3.6 abi3 Linux glibc 2.17+ x86-32 Details
secure_context-2.0.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.6 abi3 Linux glibc 2.17+ ARM64 Details
secure_context-2.0.0-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.whl CPython 3.6 abi3 Linux glibc 2.12+ x86-64 Details
secure_context-2.0.0-cp36-abi3-manylinux_2_12_i686.manylinux2010_i686.whl CPython 3.6 abi3 Linux glibc 2.12+ x86-32 Details

Total release size: 6.5 MB

Release files / secure_context-2.0.0.tar.gz

Download URL secure_context-2.0.0.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6bb3ac31f616e657f042365ec0afa7faf4ad8f9d72fa5a28e8a0e531d8a4c773
BLAKE2b-256 checksum
How to use checksums
146e8d6b67e095f778ec60d46de8c40fcbc5604e9a33e9d25272d9b296e76a93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.9.7 Linux/5.15.2-zen1-1-zen

Release files / secure_context-2.0.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL secure_context-2.0.0-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.0 MB
Tags CPython 3.6 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
2f48e606dd070f075aeeb6a9c2c332c240c6cf142d185f08770d4c47466cbb7e
BLAKE2b-256 checksum
How to use checksums
7616d1750322e00d6074a6355b036f876f4f5a83f81144025852e4efa5a449e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.9.7 Linux/5.15.2-zen1-1-zen

Release files / secure_context-2.0.0-cp36-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL secure_context-2.0.0-cp36-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 1.2 MB
Tags CPython 3.6 Linux glibc 2.17+ PowerPC 64-le abi3
SHA-256 checksum
How to use checksums
62306361f12ba7bef72847f62052433682ad632cb32b2f8477149baf636f7705
BLAKE2b-256 checksum
How to use checksums
8ec547813379e1f83f3b0d0a4617c3e2b6bba9344a117d7c745db40ea40256b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.9.7 Linux/5.15.2-zen1-1-zen

Release files / secure_context-2.0.0-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL secure_context-2.0.0-cp36-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Size 1.1 MB
Tags CPython 3.6 Linux glibc 2.17+ x86-32 abi3
SHA-256 checksum
How to use checksums
8bdd98f14a3203ace5bb970432c4f0d1ab0348bde754412248edfb77ce52917e
BLAKE2b-256 checksum
How to use checksums
9c4ad0d0448ae31eba3eb4c9ba7dac9f78459fbb4eaec0bcee7940c37c429371
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.9.7 Linux/5.15.2-zen1-1-zen

Release files / secure_context-2.0.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL secure_context-2.0.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.0 MB
Tags CPython 3.6 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
8ce45519154355565efdda3c85449a6536e1331bd59bdc555f34adeb36324859
BLAKE2b-256 checksum
How to use checksums
2e32b662e237489d7ade0c884d9ed4549659d263b0c3375b9e6e3c63340af2ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.9.7 Linux/5.15.2-zen1-1-zen

Release files / secure_context-2.0.0-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.whl

Download URL secure_context-2.0.0-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Size 1.0 MB
Tags CPython 3.6 Linux glibc 2.12+ x86-64 abi3
SHA-256 checksum
How to use checksums
0ca8a9f80003fda806a2e1d7bbba5c06baf1648bbb6d17a458dda60373d61722
BLAKE2b-256 checksum
How to use checksums
fdefc2cf505bb366613619d294058e928028b17fe372b879bf4d3b8f5e1591eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.9.7 Linux/5.15.2-zen1-1-zen

Release files / secure_context-2.0.0-cp36-abi3-manylinux_2_12_i686.manylinux2010_i686.whl

Download URL secure_context-2.0.0-cp36-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
Size 1.1 MB
Tags CPython 3.6 Linux glibc 2.12+ x86-32 abi3
SHA-256 checksum
How to use checksums
9ddadc0a896e12ade9935160df3421e1c07f3cb7116b4674cfc1eed403d68321
BLAKE2b-256 checksum
How to use checksums
7757215071ee5b91c3b1da70a3d06ecfbe1361a26c58b3c5781c14d7625d0277
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.9.7 Linux/5.15.2-zen1-1-zen

Release history Release notifications | RSS feed

This release

2.0.0 This release

7 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page