Skip to content

Instantly share code, notes, and snippets.

@adiroiban
Created October 6, 2017 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adiroiban/75442306151821713d4125c1a6c00785 to your computer and use it in GitHub Desktop.
Save adiroiban/75442306151821713d4125c1a6c00785 to your computer and use it in GitHub Desktop.
Simple test for pyOpenSSL with SNI
# Copyright (C) Jean-Paul Calderone
# See LICENSE for details.
from sys import argv, stdout
from socket import socket
from OpenSSL.SSL import TLSv1_METHOD, Context, Connection
def test_ssl_client_sni():
"""
Connect to an SNI-enabled server and request a specific hostname.
"""
client = socket()
stdout.flush()
client.connect(('binary.chevah.com', 443))
client_ssl = Connection(Context(TLSv1_METHOD), client)
client_ssl.set_connect_state()
client_ssl.set_tlsext_host_name('binary.chevah.com')
client_ssl.do_handshake()
subject = client_ssl.get_peer_certificate().get_subject().get_components()
client_ssl.close()
assert subject == [('CN', 'binary.chevah.com')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment