Created
April 29, 2018 04:44
-
-
Save dweekly/8635f80405f4a73e7a4e03052f9db4b0 to your computer and use it in GitHub Desktop.
Strange NPN issue with Python SSL: any protocol is valid...?
This file contains hidden or 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
| import ssl | |
| import socket | |
| import certifi | |
| ca_store = certifi.where() | |
| ctx = ssl.create_default_context() | |
| ctx.load_verify_locations(ca_store) | |
| server = "www.twitter.com" | |
| # set a bogus protocol for NPN | |
| ctx.set_npn_protocols(['herpderp/7']) | |
| conn = ctx.wrap_socket(socket.socket(socket.AF_INET),server_hostname=server) | |
| conn.connect((server, 443)) | |
| # no matching NPN protocol should be returned | |
| supported_proto = conn.selected_npn_protocol() | |
| if(supported_proto): | |
| print(server+" NPN sez: "+supported_proto) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment