-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
add a ssl_context option to fingerprint - to allow the developer to override the automatically created ssl_context #2735
Closed
stephan48
wants to merge
13
commits into
aio-libs:master
from
stephan48:fingerprint-with-ssl-context
Closed
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ea147b1
add a ssl_context option to fingerprint - to allow the developer to o…
stephan48 6c9a9f5
greatly simplify the expression - i don't know what my IDE did there …
stephan48 b4bcd89
Merge branch 'master' into fingerprint-with-ssl-context
asvetlov a2fabeb
Merge branch 'master' into fingerprint-with-ssl-context
webknjaz f615480
simplify check logic in _get_ssl_context
stephan48 59fe5c1
Merge https://github.com/aio-libs/aiohttp into fingerprint-with-ssl-c…
stephan48 82309e2
adjust line length in _get_ssl_context"
stephan48 305f562
correct syntax error occuring due to line breaking /o"
stephan48 206eaef
correct code according to guidelines
stephan48 427d7f4
Merge https://github.com/aio-libs/aiohttp into fingerprint-with-ssl-c…
stephan48 abfd287
correct code according to styling guides
stephan48 9ce8d5d
Merge branch 'master' into fingerprint-with-ssl-context
webknjaz b832f46
Merge branch 'master' into fingerprint-with-ssl-context
asvetlov File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -764,13 +764,23 @@ def _make_ssl_context(verified): | |
sslcontext.set_default_verify_paths() | ||
return sslcontext | ||
|
||
def _check_ssl(self, ssl_ctx): | ||
if isinstance(ssl_ctx, ssl.SSLContext): | ||
return ssl_ctx | ||
if (isinstance(ssl_ctx, Fingerprint) and | ||
isinstance(ssl_ctx.ssl_context, ssl.SSLContext)): | ||
return ssl_ctx.ssl_context | ||
|
||
# not verified or fingerprinted | ||
return self._make_ssl_context(False) | ||
|
||
def _get_ssl_context(self, req): | ||
"""Logic to get the correct SSL context | ||
|
||
0. if req.ssl is false, return None | ||
0. if req.is_ssl() is false, return None | ||
|
||
1. if ssl_context is specified in req, use it | ||
2. if _ssl_context is specified in self, use it | ||
2. if _ssl_context is specified in self, use and check it | ||
3. otherwise: | ||
1. if verify_ssl is not specified in req, use self.ssl_context | ||
(will generate a default context according to self.verify_ssl) | ||
|
@@ -781,18 +791,13 @@ def _get_ssl_context(self, req): | |
if req.is_ssl(): | ||
if ssl is None: # pragma: no cover | ||
raise RuntimeError('SSL is not supported.') | ||
sslcontext = req.ssl | ||
if isinstance(sslcontext, ssl.SSLContext): | ||
return sslcontext | ||
if sslcontext is not None: | ||
# not verified or fingerprinted | ||
return self._make_ssl_context(False) | ||
sslcontext = self._ssl | ||
if isinstance(sslcontext, ssl.SSLContext): | ||
return sslcontext | ||
if sslcontext is not None: | ||
# not verified or fingerprinted | ||
return self._make_ssl_context(False) | ||
|
||
if req.ssl is not None: | ||
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. smth like this would look nicer that duplicate if-clauses: _ssl = req.ssl or self._ssl
if _ssl is not None:
return self._check_ssl(_ssl) |
||
return self._check_ssl(req.ssl) | ||
|
||
if self._ssl is not None: | ||
return self._check_ssl(self._ssl) | ||
|
||
return self._make_ssl_context(True) | ||
else: | ||
return None | ||
|
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.
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.
Please add a test for covering the line execution.