My code sample:
import OpenSSL
import socket
ctx = OpenSSL.SSL.Context(OpenSSL.SSL.SSLv23_METHOD)
s = socket.socket(AF_INET, SOCK_STREAM)
connection = OpenSSL.SSL.Connection(ctx, s)
connection.connect((str(ip), port))
connection.setblocking(1)
connection.do_handshake()
chain = connection.get_peer_cert_chain()
The case is that if host has SNI extension I get an error:
[('SSL routines', 'SSL3_READ_BYTES', 'sslv3 alert handshake failure')]
I believe that I can overcome this using OpenSSL.SSL.Connection.set_tlsext_host_name(name)
, but for user hostname is unknown and I would like to connect to every available hostname.
So my question is: Is there a way to connect to host by ip and retrieve all available hostnames that provide certificates? Or is there a way to just retrieve all certificates from a SNI host?