I am using request library for automating APIs/microservices. I tried passing URL, certificates(path of the certificate file and key file) in get request.
After running the program, It asks for PEM pass phrase. Please refer below lines of command prompt.
>>> r = requests.get("https://foo.example.com/api/user/bill", cert=("client.crt", "client.key"))
Enter PEM pass phrase:
>>>
How to pass the passphrase programmatically in the program in order to avoid manual intervention of entering PEM passphrase in the program?
The requests library doesn't support password-protected PEM files yet.
One option is to convert it to a pkcs12 file and use the requests-pkcs12 libary from https://pypi.org/project/requests-pkcs12/
Another option is to convert it to a pkcs12 file and then to a PEM file without password.
You can convert it as follows:
# Password protected PEM to pkcs12
openssl pkcs12 -export -out cert.p12 -in cert.pem -inkey key.pem -passin pass:supersecret -passout pass:supersecret
# pkcs12 to PEM without password
openssl pkcs12 -in cert.p12 -out cert_without_pwd.pem -nodes -password supersecret
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With