Skip to content

Instantly share code, notes, and snippets.

@dweekly
Created April 29, 2018 04:44
Show Gist options
  • Select an option

  • Save dweekly/8635f80405f4a73e7a4e03052f9db4b0 to your computer and use it in GitHub Desktop.

Select an option

Save dweekly/8635f80405f4a73e7a4e03052f9db4b0 to your computer and use it in GitHub Desktop.
Strange NPN issue with Python SSL: any protocol is valid...?
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