-
-
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 1 commit
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 |
---|---|---|
|
@@ -754,10 +754,17 @@ def _make_ssl_context(verified): | |
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 | ||
|
||
for both we first check the following: | ||
1. if it an instance of ssl.SSLContext, use it | ||
2. if it an instance of aiohttp.Fingerprint, has a specified ssl_context which is also a ssl.SSLContext | ||
instance, use it | ||
3. fallback to a newly generated SSL Context without verification | ||
|
||
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) | ||
|
@@ -771,12 +778,18 @@ def _get_ssl_context(self, req): | |
sslcontext = req.ssl | ||
if isinstance(sslcontext, ssl.SSLContext): | ||
return sslcontext | ||
if not (not isinstance(sslcontext, Fingerprint) or not (sslcontext.ssl_context is not None) or not isinstance( | ||
sslcontext.ssl_context, ssl.SSLContext)): | ||
return sslcontext.ssl_context | ||
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 not (not isinstance(sslcontext, Fingerprint) or not (sslcontext.ssl_context is not None) or not isinstance( | ||
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. This is a duplicate check. Consider code reuse, so that it won't result in diverse copy-paste in future. |
||
sslcontext.ssl_context, ssl.SSLContext)): | ||
return sslcontext.ssl_context | ||
if sslcontext is not None: | ||
# not verified or fingerprinted | ||
return self._make_ssl_context(False) | ||
|
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.
There's too many negations, which is hard to understand instantly and easy to misunderstand. I think, this can (and should) be simplified.
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.
It seems to me that you want this check: