Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a rest call request from python using client certificate (in windows)

I'm trying to make a RESTfull call in Python (2.7) to a tomcat server and it must be done using SSL with client certificate.

The following line is how the call to tomcat is done:

result = requests.get(url, headers=headers, verify=settings.SLA_CA_SERVER_CERTIFICATE, cert=(settings.SLA_CLIENT_CERTIFICATE_PUBLIC, settings.SLA_CLIENT_CERTIFICATE_PRIVATE), **kwargs)


I got the following error:
[Errno 336265225] _ssl.c:355: error:140B0009:SSL routines:SSL_CTX_use_PrivateKey_file:PEM lib ()

I've tried using in the cert variable .pem files and .key and .crt files and had no luck. The private key hasn't a password. Any clue why I'm having this error?

Thank you very much

like image 652
Elena Avatar asked May 27 '26 16:05

Elena


1 Answers

I was creating the public certificate and private key from .p12 file using openssl in windows. I created them using and openssl from linux (ubuntu) and it worked.

Just informative, the commands used to create the keys where

openssl pkcs12 -in path.p12 -out newfile.crt.pem -clcerts -nokeys    
openssl pkcs12 -in path.p12 -out newfile.key.pem -nocerts -nodes
like image 188
Elena Avatar answered May 30 '26 04:05

Elena