I'm trying to use Python to test a web server. I have nearly no experience with Python, but encouraged to use it because its easy to learn and simple to do things with (someone else's opinion, not mine at the moment). The script I am using is:
s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s2 = ssl.wrap_socket(s1,
ca_certs="./pki/signing-dss-cert.pem",
cert_reqs=ssl.CERT_REQUIRED,
ssl_version=ssl.PROTOCOL_TLSv1,
server_hostname="localhost")
s2.connect( ("localhost", 8443) )
s2.send("GET / ")
time.sleep(1)
s2.send("HTTP/1.1")
The error is:
Traceback (most recent call last):
File "./fetch.sh", line 10, in <module>
server_hostname="localhost")
TypeError: wrap_socket() got an unexpected keyword argument 'server_hostname'
I've also tried using servername
, name
, hostname
and sni
with no joy.
The Python docs don't mention SNI (TLS/SSL wrapper for socket objects and SSL wiki page). But I know the patch for SNI and server_hostname
was incorporated 4 years ago in 2010 (Add a *server_hostname* argument to SSLContext.wrap_socket
, changeset 65593:846c0e1342d0).
The equivalent OpenSSL call I need access to is SSL_set_tlsext_host_name
.
How do I specify the SNI hostname? (Eventually, I'll need to set it to an arbitrary name because I am testing a proxy).