-
Notifications
You must be signed in to change notification settings - Fork 1
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
pyatls: use urllib3 v2 #12
Changes from all commits
39e54b3
8633337
8f68651
0185340
df25dd4
15bad1a
1103263
08a4e7a
9caede8
fff70b4
381dc39
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[project] | ||
name = "pyatls" | ||
version = "0.0.2" | ||
version = "0.0.3" | ||
description = "A Python package that implements Attested TLS (aTLS)." | ||
readme = "README.md" | ||
authors = [{ name = "Opaque Systems", email = "[email protected]" }] | ||
|
@@ -24,7 +24,7 @@ dependencies = [ | |
"cryptography", | ||
"PyJWT", | ||
"pyOpenSSL", | ||
"urllib3 >= 1.26.16, < 2.1.0", | ||
"urllib3 >= 2.0.0, < 2.1.0", | ||
] | ||
|
||
[project.urls] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
cryptography==41.0.3 | ||
PyJWT==2.8.0 | ||
pyOpenSSL==23.2.0 | ||
urllib3==1.26.16 | ||
requests==2.31.0 | ||
urllib3==2.0.4 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import socket | ||
from http.client import HTTPS_PORT, HTTPConnection | ||
from typing import Optional, Tuple | ||
from typing import ClassVar, Optional, Tuple | ||
|
||
from atls import ATLSContext | ||
from urllib3.connection import HTTPConnection, port_by_scheme | ||
from urllib3.util.connection import _TYPE_SOCKET_OPTIONS | ||
from urllib3.util.timeout import _DEFAULT_TIMEOUT, _TYPE_TIMEOUT | ||
|
||
Comment on lines
+5
to
+6
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. Not a huge deal, but importing variables starting with _ feels a bit weird since they are the python equivalent of private variables and methods (and therefore I am not certain if they are protected from changing / breaking between minor version bumps unlike public methods). 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, I don't like it either. The alternative though is duplicating them, which felt nastier when I was considering what to do. Thinking about it more now, maybe I should duplicate them since these end up being part of the aTLS package's public API. |
||
|
||
class HTTPAConnection(HTTPConnection): | ||
|
@@ -22,8 +23,9 @@ class HTTPAConnection(HTTPConnection): | |
port : int, optional | ||
Port to connect to. | ||
|
||
timeout : int | ||
Timeout for the attempt to connect to the host on the specified port. | ||
timeout : _TYPE_TIMEOUT | ||
Maximum amount of time, in seconds, to await an attempt to connect to | ||
the host on the specified port before timing out. | ||
|
||
source_address : tuple of str and int, optional | ||
A pair of (host, port) for the client socket to bind to before | ||
|
@@ -32,27 +34,35 @@ class HTTPAConnection(HTTPConnection): | |
blocksize : int | ||
Size in bytes of blocks when sending and receiving data to and from the | ||
remote host, respectively. | ||
|
||
socket_options: _TYPE_SOCKET_OPTIONS, optional | ||
A sequence of socket options to apply to the socket. | ||
""" | ||
|
||
default_port = HTTPS_PORT | ||
default_port: ClassVar[int] = port_by_scheme["https"] | ||
|
||
def __init__( | ||
self, | ||
host: str, | ||
context: ATLSContext, | ||
port: Optional[int] = None, | ||
timeout: int = socket._GLOBAL_DEFAULT_TIMEOUT, # type: ignore | ||
timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, | ||
source_address: Optional[Tuple[str, int]] = None, | ||
blocksize: int = 8192, | ||
socket_options: Optional[_TYPE_SOCKET_OPTIONS] = None, | ||
) -> None: | ||
super().__init__(host, port, timeout, source_address, blocksize) | ||
|
||
if not isinstance(context, ATLSContext): | ||
raise ValueError("context must be an instance of AtlsContext") | ||
super().__init__( | ||
host, | ||
port, | ||
timeout=timeout, | ||
source_address=source_address, | ||
blocksize=blocksize, | ||
socket_options=socket_options, | ||
) | ||
|
||
self._context = context | ||
|
||
def connect(self) -> None: | ||
super().connect() | ||
|
||
self.sock = self._context.wrap_socket(self.sock) | ||
self.sock = self._context.wrap_socket(self.sock) # type: ignore |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import Any, ClassVar, Dict, List, Optional, Tuple | ||
|
||
from atls import ATLSContext | ||
from atls.httpa_connection import HTTPAConnection | ||
from atls.validators import Validator | ||
from urllib3.util.connection import _TYPE_SOCKET_OPTIONS | ||
from urllib3.util.timeout import _DEFAULT_TIMEOUT, _TYPE_TIMEOUT | ||
|
||
|
||
class _HTTPAConnectionShim(HTTPAConnection): | ||
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. Any particular reason this file and class have an _ in front, because my understanding is that means you don't intend to import it anywhere else, but you do end up importing it in other files (I also have never seen a python file that starts with an _, but that might be a convention I am not aware of). 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. Regarding the file name, I saw it in the As for the class name, the intention is to mark it as internal to the library, but still available to the library itself. Some tools (like VS Code) automatically hide modules ( I suppose that if the file starts with an underscore, then there is no point to also the class starting with one. I can leave the underscore in the file and remove it from the class. Thoughts? |
||
""" | ||
Provides impendance-matching at the interface between urllib3 and the | ||
HTTPAConnection class. | ||
""" | ||
|
||
Validators: ClassVar[List[Validator]] | ||
|
||
is_verified: bool = True | ||
|
||
def __init__( | ||
self, | ||
host: str, | ||
port: Optional[int] = None, | ||
timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT, | ||
source_address: Optional[Tuple[str, int]] = None, | ||
blocksize: int = 8192, | ||
socket_options: Optional[_TYPE_SOCKET_OPTIONS] = None, | ||
**_kwargs: Dict[str, Any], | ||
) -> None: | ||
context = ATLSContext(self.Validators) | ||
|
||
super().__init__( | ||
host, | ||
context, | ||
port, | ||
timeout, | ||
source_address, | ||
blocksize, | ||
socket_options, | ||
) |
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.
do we need it here?
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.
I suppose it depends on what we use this file for. If it's for development dependencies, then yes; if it's for general dependencies, then I'd say no.
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.
Maybe I should rename it to
requirements-dev.txt
.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.
I think it is fine to have it here.