I have tried searching and asking for a solution to this over arching problem. I would like to supply a list of host names and get the certificate information from those sites. The problem is I am in a proxy environment and cannot seem to find a work around.
This connection works just fine for sites inside my proxy, or for any site when I am on my home laptop
import ssl, socket
host = 'google.com'
hostname = host
ctx = ssl.create_default_context()
s = ctx.wrap_socket(socket.socket(), server_hostname=hostname)
s.connect((hostname, 443))
cert = s.getpeercert()
(I even tried setting timeout to None and still received an error.)
But anything that is outside of my proxy will return a timeout error. I tried to work in socks with this :
import ssl, socks, pprint
host = 'google.com'
hostname = host
s = socks.socksocket()
s.set_proxy(socks.SOCKS5, 'http://proxy.com', port, False, 'username',
'password')
ctx = ssl.create_default_context()
ssl_sock = ctx.wrap_socket(s, server_hostname=hostname)
ssl_sock.connect((hostname, 443))
cert = ssl_sock.getpeercert()
but this did not work either.
Is there a module that exists that will do all the socket, connections, handshake for me and also allow a proxy to be used?