GNURLOPT_CAINFO(3)
π GNURLOPT_CAINFO(3) β the gnurl/easy_setopt era, bestie β¨
okay so real talk, this is one of those pages from the gnurl corner of the world β manual name GNURLOPT_CAINFO, function family curl_easy_setopt β and it's your whole guide to telling curl which file full of certificates to trust. let's go π
β¨ NAME β¨
CURLOPT_CAINFO β the path to your Certificate Authority (CA) bundle, aka the lil file of trust π
π¦ SYNOPSIS π¦
#include <gnurl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CAINFO, char *path);
πΈ DESCRIPTION πΈ
so basically you pass in a char * pointing at a null-terminated string β and that string names a file holding one or more certificates you'll use to verify the peer with. that's it, that's the vibe π«Ά
and here's the loophole, no cap: if CURLOPT_SSL_VERIFYPEER(3) is zero and you're deliberately skipping verification of the server's certificate, then CURLOPT_CAINFO(3) doesn't even have to point at an accessible file. like, it can just be vibes π
by default this option is set to the system path where libcurl's cacert bundle is assumed to live β as established at build time, iykyk β
if curl is built against the NSS SSL library, then the NSS PEM PKCS#11 module (libnsspem.so) needs to be available for this option to work properly. starting with curl-7.55.0, if both CURLOPT_CAINFO(3) and CURLOPT_CAPATH(3) are unset, NSS-linked libcurl tries to load libnssckbi.so β and that one's got a way more comprehensive set of trust info than nss-pem supports, because libnssckbi.so also includes info about distrusted certificates. messy but iconic π₯
(iOS and macOS) when curl uses Secure Transport, this option is supported. if the option is not set, then curl will use the certificates in the system and user Keychain to verify the peer π
(Schannel) this option is supported for Schannel in Windows 7 or later, but we recommend not using it until Windows 8, since it works better starting then. if the option is not set, then curl will use the certificates in the Windows' store of root certificates β which is the default for Schannel πͺ
and the best part? the application does not have to keep the string around after setting this option. set it and forget it, main character energy π
π DEFAULT π
Built-in system specific. when curl is built with Secure Transport or Schannel, this option is not set by default. periodt π
π PROTOCOLS π
all the TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc. the whole secure squad π§
π EXAMPLE π
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
curl_easy_setopt(curl, CURLOPT_CAINFO, "/etc/certs/cabundle.pem");
ret = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
β AVAILABILITY β
for the SSL engines that don't support certificate files, the CURLOPT_CAINFO option is just ignored π. Schannel support was added in libcurl 7.60.
π RETURN VALUE π
returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or CURLE_OUT_OF_MEMORY if there was insufficient heap space π
π SEE ALSO π
and that's the page, bestie π«Ά this one's served up from libcurl 7.37.0, dated 17 Jun 2014, living under the GNURLOPT_CAINFO(3) header β go forth and verify those peers β¨ππ
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms