-
Notifications
You must be signed in to change notification settings - Fork 193
Support external SSLContext #129
Support external SSLContext #129
Conversation
""" | ||
def __init__(self, host, port=None, window_manager=None, enable_push=False, | ||
def __init__(self, host, port=None, window_manager=None, enable_push=False, SSLContext=None, |
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.
Can we keep the name of this parameter in keeping with the style of the rest? ssl_context
is preferred. =)
I think this is a good start, but there's some work left to do. =) The Additionally, I think we should have a factory function that creates SSLContexts and make it more obvious. This may just mean promoting |
Thanks for the quick feedback, will work on the missing parts :) On another matter, I'm using |
You should always use |
@@ -31,7 +31,7 @@ def wrap_socket(sock, server_hostname): | |||
global _context | |||
|
|||
if _context is None: # pragma: no cover | |||
_context = _init_context() | |||
_context = ssl_context or _init_context() |
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 actually think this logic is wrong. The provided ssl_context
should be used only for the specific call to wrap_socket, but this affects all subsequent calls. I think probably we should use a different, local variable in this method, and then prefer ssl_context
to _context
.
Loading the certificate adds no value to the test and file cannot be found under the pypy test environment
Use local ssl_context variable instead of global context variable. Respect 80 columns limit and add ´param´ in front of new argument in comments
I'm thinking of adding new tests to validate a provided |
@jdecuyper It does, but it's fraught with difficulty because those tests end up enormously platform dependent. I think it's probably enough to run one test that does something that can easily be detected at the socket level: maybe force a TLS version lower than 1.2? |
So far this looks good @jdecuyper! 👍 |
Update the abstraction and SSLContext tests to take the new ssl_context parameter into account.
@sigmavirus24 thanks :) With the last commit, a custom Now I want to make Sorry for so many newbies questions and thanks a lot for you help so far! |
I think location of a certificate file should be the only optional parameter we expose, to satisfy #8. Anything else can be mutated on the
Sounds good to me! Don't forget to add a docstring that explains it, and then make sure that you document the method in the API documentation.
Absolutely no need to apologise! It's far better to ask the question than to muddle on confused, and we're really happy to help. You're doing great work! ✨ |
Allow user to provide their own certification file. Add description of the init_context method to the API documentation.
@Lukasa
Let me know if there is anything else that needs to be changed (code or documentation). |
\o/ This looks fantastic @jdecuyper, thanks so much! 🍰 |
PR for issue #8
@Lukasa: this is preliminary work, would love to get some feedback on code and unit tests to know if I'm on the right track.
SSLContext
can be assigned tohyper.tls._context
or passed as an argument to theHTTP20Connection
constructor. Both cases are covered in the unit test.SSLContext
argument will later be moved to theHTTPConnection
abstraction layer?