Said  Saifi
Said Saifi

Reputation: 2398

How can I set the certificates in CURL

In order to get a successful response I am using curl --cacert <path of ca.pem> ... but how can i set the path of ca.pem in a configuration file in mac in order to not specify the path of the certificate every time, and i can directly use curl ...

Upvotes: 15

Views: 57354

Answers (2)

dropbear
dropbear

Reputation: 1727

If your curl version was not built with TLS backend Schannel, you can set the environment variable CURL_CA_BUNDLE to the path of your certificate file.

You can verify this by running curl -V. If the version string does not contain Schannel this answer applies to you.

Please note that if you have the certificate in your home folder, you should write the full path and not use ~.

This works for me: export CURL_CA_BUNDLE="/Users/myuser/cert.crt"

Source: cURL documentation

Upvotes: 1

drew010
drew010

Reputation: 69937

On your system you can set environment variables to point to these files.

Try:

export SSL_CERT_FILE=/path/to/ca.pem

There is also SSL_CERT_DIR environment variable to specify the directory containing certificates.

You can add this to your .bashrc or .bash_profile file to make this permanent.

This can be changed at compile time with curl by passing --with-ca-path=DIRECTORY when building curl but I'd recommend leaving it as is.

Better yet, find out what CA path/file your OS and/or OpenSSL are using and add the relevant certificate there. I have no idea where they live on Mac but you should have a directory of trusted CA certs which curl is using for verification (probably somewhere in /etc).

Upvotes: 28

Related Questions