Reusing an HTTPS Session in Python

I would like to be able to use concurrent requests on an HTTPS server. I am currently using PyCURL, but it cannot reuse the same SSL session identifier between different descriptors, and each descriptor can only monitor download / upload each time.

Given that reconciliation takes time (especially because a client certificate is used), reusing the identifier (like browsers to download multiple resources in parallel with the network) will likely improve performance.

So now, is there anyone about a workaround for PyCURL or an alternative HTTP module that supports this? httplib does not work either.

+4
source share
1 answer

Reusing session identifiers is currently not readily available, as indicated here , I have not heard of any simple solution for this, but it should just need to maintain its context after the initial handshake and reuse of it.

PyOpenSSL reveals these mechanisms, but at a lower level than most people would like. I put my money in the following sequence of events:

  • Think about how to get started with session loading, just do a proof of concept. A useful tool for this is the openssl binary (the one commonly used to create SSL keys). This has a built-in client that you can use as follows:

openssl s_client -connect HOST: 443

  • You can print all kinds of good diagnostic materials (for example, your SSL session identifier) ​​so that you can verify it outside of your immediate problem.

  • After that, httplib SSL support is pretty simple, HTTPSConnection is a very thin wrapper around HTTPConnection (there are only two methods that extend the class.>

httplib.py - class HTTPSConnection

def connect(self): "Connect to a host on a given (SSL) port." sock = socket.create_connection((self.host, self.port), self.timeout, self.source_address) if self._tunnel_host: self.sock = sock self._tunnel() self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file) 
+1
source

All Articles