I have a HTTP client in Python which needs to use TLS. I need not only
to make encrypted connections but also to retrieve info from the
remote machine, such as the certificate issuer. I need to make
connection to many HTTP servers, often badly behaved, so I absolutely
need to have a timeout. With non-TLS connections,
mysocket.settimeout(5)
does what I want.
Among the many TLS Python modules:
python-gnutls does not allow to use settimeout() on sockets because it uses non-blocking sockets:
gnutls.errors.OperationWouldBlock: Function was interrupted.
python-openssl has a similar issue:
OpenSSL.SSL.WantReadError
The SSL module of the standard library does not work with Python 2.5.
Other libraries like TLSlite apparently does not give access to the metadata of the certificate.
The program is threaded so I cannot use signals. I need detailed control on the HTTP dialog so I cannot use a standard library like urllib2.
Background: this is the survey project DNSwitness. Relevant SO threads: Timeout on a Python function call and How to limit execution time of a function call in Python.