Repository navigation
fix: strict X.509 certificate chains for Hermes Python 3.13 #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
| #!/bin/sh | ||
| set -eu | ||
|
|
||
| # A separate interpreter preserves the Hermes admission package's tool pin. | ||
| # The venv holds test dependencies only; all synthetic TLS keys stay in the | ||
| # Rust fixture's disposable tempfile and are never emitted by this script. | ||
| strict_venv=$(mktemp -d "${TMPDIR:-/tmp}/charon-strict-python.XXXXXX") | ||
| trap 'rm -rf "$strict_venv"' EXIT HUP INT TERM | ||
| mise exec python@3.13.5 -- python -m venv "$strict_venv" | ||
| "$strict_venv/bin/python" -m pip --disable-pip-version-check install --quiet httpx==0.28.1 | ||
| CHARON_STRICT_TLS_PYTHON="$strict_venv/bin/python" cargo test --lib \ | ||
| gateway::tests::python_313_strict_clients_accept_generated_chain -- --ignored --nocapture |
This file contains hidden or 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,64 @@ | ||
| """Hermes-matched clients against the real generated-CA CONNECT fixture.""" | ||
|
|
||
| import socket | ||
| import ssl | ||
| import sys | ||
| import urllib.request | ||
|
|
||
| import httpx | ||
|
|
||
|
|
||
| assert sys.version_info[:3] == (3, 13, 5), "requires Hermes Python 3.13.5" | ||
| assert httpx.__version__ == "0.28.1", "requires Hermes HTTPX 0.28.1" | ||
| proxy, ca_file = sys.argv[1:] | ||
| context = ssl.create_default_context(cafile=ca_file) | ||
| # Python's default is TLS 1.2; state that floor explicitly for the raw probe | ||
| # and static analysis. Verification flags and hostname checking stay intact. | ||
| context.minimum_version = ssl.TLSVersion.TLSv1_2 | ||
| assert context.verify_flags & ssl.VERIFY_X509_STRICT | ||
| assert context.verify_mode == ssl.CERT_REQUIRED and context.check_hostname | ||
| url = "https://allowed.test/plain" | ||
|
|
||
| opener = urllib.request.build_opener( | ||
| urllib.request.ProxyHandler({"https": proxy}), | ||
| urllib.request.HTTPSHandler(context=context), | ||
| ) | ||
| with opener.open(url, timeout=10) as response: | ||
| assert response.status == 200 | ||
| assert b"data: /plain" in response.read() | ||
|
|
||
| # Match the cutover reproduction: HTTPX constructs its own default strict | ||
| # context from the CA filename. Do not change verify flags or hostname checks. | ||
| response = httpx.get(url, proxy=proxy, verify=ca_file, timeout=10, trust_env=False) | ||
| assert response.status_code == 200 and "data: /plain" in response.text | ||
| with httpx.Client(proxy=proxy, verify=context, timeout=10, trust_env=False) as client: | ||
| assert client.get(url).status_code == 200 | ||
| assert client.get("https://allowed.test/not-granted").status_code == 403 | ||
| assert client.get(url).status_code == 200 | ||
|
|
||
| try: | ||
| httpx.get(url, proxy=proxy, timeout=10, trust_env=False) | ||
| except httpx.ConnectError as error: | ||
| assert "CERTIFICATE_VERIFY_FAILED" in str(error) | ||
| else: | ||
| raise AssertionError("untrusted interception CA was accepted") | ||
|
|
||
| host, port = proxy.removeprefix("http://").rsplit(":", 1) | ||
| with socket.create_connection((host, int(port)), timeout=10) as tunnel: | ||
| tunnel.sendall(b"CONNECT allowed.test:443 HTTP/1.1\r\nHost: allowed.test:443\r\n\r\n") | ||
| headers = b"" | ||
| while not headers.endswith(b"\r\n\r\n"): | ||
| chunk = tunnel.recv(1) | ||
| assert chunk and len(headers) < 4096 | ||
| headers += chunk | ||
| assert headers.startswith(b"HTTP/1.1 200") | ||
| try: | ||
| context.wrap_socket(tunnel, server_hostname="wrong.test") | ||
| except ssl.SSLCertVerificationError: | ||
| pass | ||
| else: | ||
| raise AssertionError("hostname checking was bypassed") | ||
|
|
||
| assert context.verify_flags & ssl.VERIFY_X509_STRICT | ||
| assert context.verify_mode == ssl.CERT_REQUIRED and context.check_hostname | ||
| print("PASS: Python 3.13.5 urllib and HTTPX 0.28.1 strict CONNECT trust, reuse and denials") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.