-
-
Notifications
You must be signed in to change notification settings - Fork 803
Implement asgiref tls extension #1119
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
Open
mdgilene
wants to merge
17
commits into
encode:master
Choose a base branch
from
mdgilene:feature-asgiref-tls-extension
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
aa26b2c
Implement asgiref tls extension
mdgilene 3ae8704
Only add tls extension if connection is over tls
mdgilene 278fd24
Merge branch 'master' into feature-asgiref-tls-extension
mdgilene 053dc4f
Fix formatting issues
mdgilene 4114948
Merge remote-tracking branch 'upstream/master' into feature-asgiref-t…
mdgilene a84dc93
Address linting issues and fix tests
mdgilene d1feb3c
Merge remote-tracking branch 'upstream/master' into feature-asgiref-t…
5c7b539
Fix issues found by check script
02c53b4
add generated TLS constants
jschlyter b4da8a2
Add generate script and update generation to run formatting automatic…
19a5c1e
Added DN escaping and use new generated cipher_suite lookup table
eb60eb8
Add test for escaping
9f05147
Run formatting on tests
1ac95c0
Merge branch 'master' into feature-asgiref-tls-extension
mdgilene 050d862
fix incorrect dictionary access
7b24335
Merge branch 'feature-asgiref-tls-extension' of https://github.com/md…
f50dddb
Merge branch 'master' into feature-asgiref-tls-extension
mdgilene 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh -e | ||
|
||
if [ -d 'venv' ] ; then | ||
PREFIX="venv/bin/" | ||
else | ||
PREFIX="" | ||
fi | ||
|
||
set -x | ||
|
||
${PREFIX}python -m tools.generate_tls_const |
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,49 @@ | ||
import pprint | ||
import xml.etree.ElementTree as ET | ||
import subprocess | ||
|
||
import httpx | ||
|
||
GENERATED_FILENAME = "uvicorn/protocols/http/tls_const.py" | ||
|
||
TLS_PARAMETERS_URL = "https://www.iana.org/assignments/tls-parameters/tls-parameters.xml" | ||
NAMESPACES = {"iana": "http://www.iana.org/assignments"} | ||
TLS_CIPHER_SUITES_XPATH = './/iana:registry[@id="tls-parameters-4"]/iana:record' | ||
|
||
content = httpx.get(TLS_PARAMETERS_URL).content | ||
root = ET.fromstring(content) | ||
|
||
tls_cipher_suites = {} | ||
|
||
for record in root.findall(TLS_CIPHER_SUITES_XPATH, NAMESPACES): | ||
cipher = record.find("iana:description", NAMESPACES).text | ||
if cipher == "Unassigned": | ||
continue | ||
if cipher == "Reserved": | ||
continue | ||
|
||
value = record.find("iana:value", NAMESPACES).text | ||
if "-" in value: | ||
continue | ||
|
||
vs = [int(v, 16) for v in value.split(",")] | ||
code = (vs[0] << 8) + vs[1] | ||
tls_cipher_suites[cipher] = code | ||
|
||
|
||
GENERATED_SOURCE = f""" | ||
# generated by tools/generate_tls_const.py | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Final | ||
|
||
TLS_CIPHER_SUITES: Final[dict[str, int]] = {pprint.pformat(tls_cipher_suites)} | ||
""" | ||
|
||
|
||
with open(GENERATED_FILENAME, "wt") as fp: | ||
fp.write(GENERATED_SOURCE) | ||
|
||
subprocess.run(["ruff", "format", GENERATED_FILENAME]) | ||
subprocess.run(["ruff", "check", "--fix", GENERATED_FILENAME]) |
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
Oops, something went wrong.
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.