-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce backwards compatible SSL. - [script.py] Add optional argument for ssl-private_key, ssl-public_key and ssl-ca - [web.py] Add optional ssl_context - [conftest.py] Pytest utilities to test ssl - [script_test.py/web_test.py] Add ssl testing
- Loading branch information
Showing
7 changed files
with
270 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import ssl | ||
|
||
import pytest | ||
import trustme | ||
|
||
|
||
@pytest.fixture | ||
def ca(): | ||
yield trustme.CA() | ||
|
||
|
||
@pytest.fixture | ||
def tls_ca_path(ca): | ||
with ca.cert_pem.tempfile() as ca_cert_pem: | ||
yield ca_cert_pem | ||
|
||
|
||
@pytest.fixture | ||
def tls_certificate(ca): | ||
yield ca.issue_cert("localhost", "127.0.0.1", "::1") | ||
|
||
|
||
@pytest.fixture | ||
def tls_public_key_path(tls_certificate): | ||
"""Provide a certificate chain PEM file path via fixture.""" | ||
with tls_certificate.private_key_and_cert_chain_pem.tempfile() as cert_pem: | ||
yield cert_pem | ||
|
||
|
||
@pytest.fixture | ||
def tls_private_key_path(tls_certificate): | ||
"""Provide a certificate private key PEM file path via fixture.""" | ||
with tls_certificate.private_key_pem.tempfile() as cert_key_pem: | ||
yield cert_key_pem | ||
|
||
|
||
@pytest.fixture | ||
def ssl_context(tls_certificate): | ||
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) | ||
tls_certificate.configure_cert(ssl_ctx) | ||
yield ssl_ctx | ||
|
||
|
||
@pytest.fixture | ||
def ssl_context_server(tls_public_key_path, ca): | ||
ssl_ctx = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH) | ||
ca.configure_trust(ssl_ctx) | ||
yield ssl_ctx |
Oops, something went wrong.