0

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?

  • It looks like you are trying to use a SOCKS prxy but give the URL of a HTTP proxy. This will not work. It is unclear what requirements are really there to connect to the proxy but I assume it will be a HTTP proxy (since more common in companies) and marked the question of duplicate of one which explains how to handle this case. – Steffen Ullrich Aug 13 '19 at 05:20
  • I did end up realizing that and changing it to HTTP but still had the same result: Timeout Error – Virtual Penman Aug 13 '19 at 14:41

0 Answers0