Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Requests: .pem -> .crt + key

I've been given a .pem file for authentication on an XML POST API. I would prefer using Python Requests and have found in the documentation that I need to convert the .pem file to a server certification and key. I have been unable to find exactly what Requests needs (what kind of certification).

I've had to do some openssl conversions on files before, but I'm no expert. Can anyone explain what kind of certificate and key is needed by Requests and how I can convert a .pem into those files?

For more context into the Requests documentation please see http://docs.python-requests.org/en/latest/user/advanced/#ssl-cert-verification

You'll notice a reference to /path/server.crt and /path/key.

like image 268
Rico Avatar asked May 16 '14 23:05

Rico


People also ask

What is PEM CRT key?

key files are generally the private key, used by the server to encrypt and package data for verification by clients. . pem files are generally the public key, used by the client to verify and decrypt data sent by servers. PEM files could also be encoded private keys, so check the content if you're not sure.


1 Answers

There's a behaviour of requests (see documentation here) that you can take advantage of here without having to generate a crt or key files.

Let's say you have the pem file here: /path/to/certificate.pem, you can then do:

r = requests.get('https://example.com', verify='/path/to/cetificate.pem')

And it should work perfectly.

like image 58
Ian Stapleton Cordasco Avatar answered Oct 12 '22 10:10

Ian Stapleton Cordasco