Created
October 6, 2017 10:47
-
-
Save adiroiban/75442306151821713d4125c1a6c00785 to your computer and use it in GitHub Desktop.
Simple test for pyOpenSSL with SNI
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
# 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