CURLINFO_CERTINFO(3)
π CURLINFO_CERTINFO π
Okay bestie, so this is a page from the Library Functions Manual β it's CURLINFO_CERTINFO(3) and it's literally all about peeking at the TLS certificate chain. Grab a snack, we're getting into it. π
β¨ NAME β¨
CURLINFO_CERTINFO β the TLS certificate chain, bestie. That's the whole vibe.
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_CERTINFO,
struct curl_certinfo **chainp);
π¦ DESCRIPTION π¦
So here's the tea: you pass in a pointer to a struct curl_certinfo * and curl sets it to point at a struct holding all the info about the server's certificate chain β but only if you had CURLOPT_CERTINFO(3) enabled when the request was made. No cap, that part is non-negotiable. π
struct curl_certinfo {
int num_of_certs;
struct curl_slist **certinfo;
};
The certinfo struct member is an array of linked lists of certificate information. The num_of_certs struct member is the number of certificates β which is also the number of elements in the array. Iconic, honestly. π
Each certificate's list has items with textual information in the format "name:content" β think "Subject:Foo", "Issuer:Bar", etc. The items in each list vary depending on the SSL backend and the certificate, so don't come for me if yours looks different. π«Ά
π§ PROTOCOLS π§
This functionality affects all TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc. All of them. The whole squad. π₯
This option works only with the following TLS backends: GnuTLS, OpenSSL, Rustls and Schannel.
β EXAMPLE β
Here's the demo, and yes you can copy it straight up, it's giving main character energy:
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
/* connect to any HTTPS site, trusted or not */
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
result = curl_easy_perform(curl);
if(!result) {
int i;
struct curl_certinfo *ci;
result = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ci);
if(!result) {
printf("%d certs!\n", ci->num_of_certs);
for(i = 0; i < ci->num_of_certs; i++) {
struct curl_slist *slist;
for(slist = ci->certinfo[i]; slist; slist = slist->next)
printf("%s\n", slist->data);
}
}
}
curl_easy_cleanup(curl);
}
}
Also go look at the certinfo.c example, it's in the repo and it slays. π
Heads up: that example turns offCURLOPT_SSL_VERIFYPEERandCURLOPT_SSL_VERIFYHOSTon purpose β because it connects to any HTTPS site, trusted or not. It's a demo move, not a "do this in prod" move. π
π HISTORY π
- GnuTLS support added in
7.42.0. - Schannel support added in
7.50.0. - mbedTLS support added in
8.9.0.
π AVAILABILITY π
Added in curl 7.19.1. She's been around a minute. β¨
π RETURN VALUE π
curl_easy_getinfo(3) returns a CURLcode indicating success or error.
CURLE_OK (0) means everything was OK, non-zero means an error occurred β see libcurl-errors(3). Periodt. π
π₯ SEE ALSO π₯
That's the whole page, bestie β go forth and read those certs. π
Big love from the libcurl gang, page dated 2026-10-12, documented under the libcurl banner. Mwah. π
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms