Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ...

like image 607
Said Saifi Avatar asked Jul 25 '16 14:07

Said Saifi


People also ask

How do you specify a certificate in curl command?

If you are using the curl command line tool, you can specify your own CA cert file by setting the environment variable CURL_CA_BUNDLE to the path of your choice. If you are using the curl command line tool on Windows, curl will search for a CA cert file named "curl-ca-bundle.

How do I change the certificate path in curl?

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.

How do I enable SSL on curl?

You need to pass the -k or --insecure option to the curl command. This option explicitly allows curl to perform “insecure” SSL connections and transfers. All SSL connections are attempted to be made secure by using the CA certificate bundle installed by default.


1 Answers

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).

like image 74
drew010 Avatar answered Oct 11 '22 04:10

drew010