Skip to content
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

Implement asgiref tls extension #1119

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test for escaping
Matt Gilene committed May 27, 2024
commit eb60eb87812b8f19e45946738ebc06d90272665d
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -57,8 +57,8 @@ def tls_certificate(tls_certificate_authority: trustme.CA) -> trustme.LeafCert:


@pytest.fixture
def tls_client_certificate(tls_certificate_authority: trustme.CA) -> trustme.LeafCert:
return tls_certificate_authority.issue_cert("client@example.com", common_name="uvicorn client")
def tls_client_certificate(request, tls_certificate_authority: trustme.CA) -> trustme.LeafCert:
return tls_certificate_authority.issue_cert("client@example.com", common_name=getattr(request, "param", "uvicorn client"))


@pytest.fixture
15 changes: 15 additions & 0 deletions tests/test_ssl.py
Original file line number Diff line number Diff line change
@@ -37,13 +37,28 @@ async def test_run(


@pytest.mark.anyio
@pytest.mark.parametrize(
"tls_client_certificate, expected_common_name",
[
("test common name", "test common name"),
(' \\,+"<>;=\000\n\r ', 'CN=\\ \\\\\\,\\+\\"\\<\\>\\;\\=\\\x00\\0a\\0d\\ '),
],
indirect=["tls_client_certificate"],
)
async def test_run_httptools_client_cert(
tls_ca_ssl_context,
tls_certificate_server_cert_path,
tls_certificate_private_key_path,
tls_ca_certificate_pem_path,
tls_client_certificate_pem_path,
expected_common_name,
):
async def app(scope, receive, send):
assert scope["type"] == "http"
assert expected_common_name in scope["extensions"]["tls"]["client_cert_name"]
await send({"type": "http.response.start", "status": 204, "headers": []})
await send({"type": "http.response.body", "body": b"", "more_body": False})

config = Config(
app=app,
loop="asyncio",
2 changes: 1 addition & 1 deletion uvicorn/protocols/utils.py
Original file line number Diff line number Diff line change
@@ -143,6 +143,6 @@ def get_tls_info(transport: asyncio.Transport) -> dict[object, object]:
ssl_info["tls_version"] = (
TLS_VERSION_MAP[ssl_object.version()] if ssl_object.version() in TLS_VERSION_MAP else None
)
ssl_info["cipher_suite"] = TLS_CIPHER_SUITES[ssl_object.cipher()[0]]
ssl_info["cipher_suite"] = getattr(TLS_CIPHER_SUITES, ssl_object.cipher()[0], None)

return ssl_info