When would one use the --cacert
option vs. the --capath
option within curl
(CLI that is).
--cacert
appears to reference a monolithic file that contains multiple PEMs. Assume it scans through to find the matching hostname?
--capath
appears to reference a directory in which multiple files live. Does curl pick up the appropriate certificate as a filename therein?
On Windows you can run the following as a batch file and pass in the capath folder name:
c_rehash.cmd:
Example:
From the docs:
So, if you specify --cacert, the CA certs are stored in the specified file. These CA certificates are used to verify the certs of remote servers that cURL connects to.
The --capath option is used to specify a directory containing the CA certs rather than a single file. The c_rehash utility should be used to prepare the directory i.e., create the necessary links. The main benefit of using --capath would appear to be that it's more efficient than the --cacert single file approach if you have many CA certs.
Here's a script that probably does what c_rehash does:
With both options you should be careful to only include CA certs from CAs you trust. If for example, you know the remote servers should always be issued with certs from YourCompanyCA, then this is the only CA cert you should include.