-
Notifications
You must be signed in to change notification settings - Fork 780
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
SSL client validation (certificate-based authentication) #295
Closed
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
090eaa0
Added SSL-certificate-based client authentication.
hoehermann 554a822
Added manual for certificate-based client authentication.
hoehermann a426020
Added hints to which Python versions allow client certificate authent…
hoehermann 8cb3acd
Kept ssl.create_default_context, but added fallback to ssl.wrap_socke…
hoehermann dfd50db
Improved `test_do_handshake_ssl_error_eof_raises_close_error` so it w…
hoehermann 8bad0ca
Improve test so it does not test methods that do not exist in old Pyt…
hoehermann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 |
---|---|---|
|
@@ -541,16 +541,31 @@ def do_handshake(self, sock, address): | |
% self.cert) | ||
retsock = None | ||
try: | ||
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) | ||
context.load_cert_chain(certfile=self.cert, keyfile=self.key) | ||
if self.verify_client: | ||
context.verify_mode = ssl.CERT_REQUIRED | ||
context.set_default_verify_paths() | ||
if self.cafile: | ||
context.load_verify_locations(cafile=self.cafile) | ||
retsock = context.wrap_socket( | ||
sock, | ||
server_side=True) | ||
try: | ||
# try creating new-style SSL wrapping for extended features | ||
context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) | ||
context.load_cert_chain(certfile=self.cert, keyfile=self.key) | ||
if self.verify_client: | ||
context.verify_mode = ssl.CERT_REQUIRED | ||
context.set_default_verify_paths() | ||
if self.cafile: | ||
context.load_verify_locations(cafile=self.cafile) | ||
retsock = context.wrap_socket( | ||
sock, | ||
server_side=True) | ||
except AttributeError as ae: | ||
if str(ae) != "'module' object has no attribute 'create_default_context'": | ||
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. When fixed this should also be merged in to the original commit. |
||
# this exception is not caused by create_default_context not existing in old version. re-raise exception to be handled somewhere elese. | ||
raise | ||
elif self.verify_client: | ||
raise self.EClose("Client certificate verification requested, but not Python is too old.") | ||
else: | ||
# new-style SSL wrapping is not needed, falling back to old style | ||
retsock = ssl.wrap_socket( | ||
sock, | ||
server_side=True, | ||
certfile=self.cert, | ||
keyfile=self.key) | ||
except ssl.SSLError: | ||
_, x, _ = sys.exc_info() | ||
if x.args[0] == ssl.SSL_ERROR_EOF: | ||
|
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.
This can be done a lot cleaner. E.g.