My Question
I'm trying to use an encrypted client private key when using python requests. As it doesn't support encrypted keys, I have to decrypt it first and then send it to requests
. The problem is that requests
only accepts file paths for specifying client keys/certificates. How can I make it accept a string?
Example of what I want to do:
#X509
CLIENT_CERT_PATH = "path/to/cert" #perhaps I should convert this into a string too?
#PKey
CLIENT_PKEY_STRING = decrypt("path/to/encrypted_key")
response = requests.get(url = url, cert = (CLIENT_CERT_PATH, CLIENT_PKEY_STRING)) #how?
Attempts
Tried Python requests CA certificates as a string but I got the following behaviour: AttributeError: module 'urllib3.contrib' has no attribute 'pyopenssl'
.
Also tried Example of including a certficate in a post request with python and http.client and even adapted it to look like:
class openSSLContext(requests.packages.urllib3.util.ssl_.SSLContext):
def __init__(self, method):
pk = crypto.load_privatekey(crypto.FILETYPE_PEM, open(CL_PKEY_PATH, "rb").read())
cert = crypto.load_certificate(crypto.FILETYPE_PEM, open(CL_CERT_PATH, "rb").read())
requests.packages.urllib3.util.ssl_.SSLContext = openSSLContext
but I don't know where to go from here.
Versions
Python 3.9.2
pyOpenSSL == 20.0.1
requests == 2.25.1
urllib3 == 1.26.4