Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force requests use the certificates on my ubuntu system

I'm using a self-signed cert for debug purpose.

$ cp hbrls-server.cert /usr/local/share/ca-certificates/
$ update-ca-certificates

After that, I can see hbrls-server.pem in /etc/ssl/certs/. But requests still raises the SSLError.

If I specify the cert like this: requests.get('https://blabla', verify='/etc/ssl/certs/hbrls-server.pem'), it will be OK.

And python -m requests.certs returns /usr/local/lib/python2.7/dist-packages/certifi/cacert.pem.

How can I make requests to use the certs on the system. I'm working on dockerize sth, and would not like to see that verify=path-to-cert in my code.

EDIT: ubuntu 12.04, python 2.7.3, requests 2.7.0

like image 431
hbrls Avatar asked Jul 16 '15 08:07

hbrls


People also ask

Where do I put certificates in Ubuntu?

The default location to install certificates is /etc/ssl/certs . This enables multiple services to use the same certificate without overly complicated file permissions. For applications that can be configured to use a CA certificate, you should also copy the /etc/ssl/certs/cacert.

How do I know if SSL certificate is installed Ubuntu?

You can perform this with the following command: sudo update-ca-certificates . You will notice that the command reports it has installed certificates if required (up-to-date installations may already have the root certificate).


1 Answers

You can set the environment variable REQUESTS_CA_BUNDLE so you don't have to modify your code:

export REQUESTS_CA_BUNDLE=/usr/local/share/ca-certificates/hbrls-server.cert

Source: https://requests.readthedocs.io/en/master/user/advanced/#ssl-cert-verification

like image 60
Marc Abramowitz Avatar answered Oct 07 '22 15:10

Marc Abramowitz