-
Notifications
You must be signed in to change notification settings - Fork 10
Add AuthorityKeyIdentifier extension for compatibility with Python 3.13 #23
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,13 +12,12 @@ | |
|
|
||
| import os | ||
| import pytest | ||
| import requests | ||
| import socket | ||
| import ssl | ||
| from urllib.request import urlopen, URLError | ||
| from contextlib import closing, contextmanager | ||
| from datetime import datetime, timedelta, timezone | ||
| from flask import Flask | ||
| from requests.exceptions import SSLError | ||
| from tempfile import TemporaryDirectory | ||
| from threading import Thread | ||
| from werkzeug.serving import make_server | ||
|
|
@@ -54,14 +53,16 @@ def make_flask_app(): | |
| @app.route("/") | ||
| def working(): | ||
| return "working" | ||
|
|
||
| return app | ||
|
|
||
|
|
||
| @contextmanager | ||
| def tls_server(certfile: str, keyfile: str, host: str = "localhost", port: int = 0): | ||
| if port == 0: | ||
| port = find_free_port() | ||
|
|
||
| ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) | ||
| ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) | ||
| ssl_context.load_cert_chain(certfile, keyfile) | ||
| server = make_server( | ||
| host, port, make_flask_app(), ssl_context=ssl_context, threaded=True | ||
|
|
@@ -373,10 +374,16 @@ def test_certs(): | |
| ) as server: | ||
| # Execute/Verify | ||
| url = f"https://{server.host}:{server.port}" | ||
|
|
||
| # Fails without specifying a CA for verification | ||
| with pytest.raises(SSLError): | ||
| requests.get(url) | ||
| with pytest.raises(URLError, match="SSL"): | ||
| with urlopen(url): | ||
| pass | ||
|
|
||
| ssl_context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH, cafile=ca_record["files"]["cert"]) | ||
| ssl_context.verify_mode = ssl.CERT_REQUIRED | ||
| ssl_context.load_default_certs() | ||
| ssl_context.load_cert_chain(ca_record["files"]["cert"], ca_record["files"]["key"]) | ||
|
|
||
| # Succeeds when supplying the CA cert | ||
| requests.get(url, verify=ca_record["files"]["cert"]) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw, the reason I switched from requests to urlopen here is that requests does not use the default ssl config and this test still passed, even on 3.13. Only http libraries that use more default ssl setup (urllib, httpx, tornado, etc.) see this.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, I figured that might have been why you did that. So it seems the default ssl setup is more strict than what
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, requests predates a lot of the standard library SSL stuff and is pretty hardcore about not changing default behavior no matter what, so changes in the standard library often don't affect requests. |
||
| with urlopen(url, context=ssl_context): | ||
| pass | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what was requires to pass default ssl checks in Python 3.13