0

I need to call some APIs which are authenticated via mTLS; requests supports this natively, by providing certificate and private key as paths to the corresponding files.

Now, in my setting, I will be retrieving certificate and private key at runtime and I would like to avoid storing them in temporary files on disk just to pass them over to requests, as it would worsen the security of the system.

I managed to perform such calls successfully by implementing what was suggested in this SO answer, but it turns out that importing from urllib3.contrib.pyopenssl is now deprecated by urllib3 and will be removed soon. In fact, this was pointed out in the comments and the suggested solution was to use OpenSSL.SSL.Context instead. However, when I try this I get a AttributeError: 'Context' object has no attribute 'wrap_socket'. I also tried to extend Context by copying over the definition of PyOpenSSLContext.wrap_socket, but this in turn requires to import from urllib3.contrib.pyopenssl.

I am aware of other solutions, but I've not been able to make them work, and I'd prefer to avoid mockeypatching production code if at all possible.

Any help or suggestion is very well appreciated.

St3p
  • 16
  • 3

0 Answers0