CURLOPT_CERTINFO.md (2082B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_CERTINFO 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLINFO_CAINFO (3) 9 - CURLINFO_CAPATH (3) 10 - CURLINFO_CERTINFO (3) 11 - CURLOPT_CAINFO (3) 12 - CURLOPT_SSL_VERIFYPEER (3) 13 Protocol: 14 - TLS 15 TLS-backend: 16 - OpenSSL 17 - GnuTLS 18 - Schannel 19 - rustls 20 Added-in: 7.19.1 21 --- 22 23 # NAME 24 25 CURLOPT_CERTINFO - request SSL certificate information 26 27 # SYNOPSIS 28 29 ~~~c 30 #include <curl/curl.h> 31 32 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CERTINFO, long certinfo); 33 ~~~ 34 35 # DESCRIPTION 36 37 Pass a long set to 1 to enable libcurl's certificate chain info gatherer. With 38 this enabled, libcurl extracts lots of information and data about the 39 certificates in the certificate chain used in the SSL connection. This data 40 may then be retrieved after a transfer using curl_easy_getinfo(3) and 41 its option CURLINFO_CERTINFO(3). 42 43 # DEFAULT 44 45 0 46 47 # %PROTOCOLS% 48 49 # EXAMPLE 50 51 ~~~c 52 int main(void) 53 { 54 CURL *curl = curl_easy_init(); 55 if(curl) { 56 CURLcode res; 57 curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/"); 58 59 /* connect to any HTTPS site, trusted or not */ 60 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); 61 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); 62 63 curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L); 64 65 res = curl_easy_perform(curl); 66 67 if(!res) { 68 struct curl_certinfo *ci; 69 res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ci); 70 71 if(!res) { 72 int i; 73 printf("%d certs!\n", ci->num_of_certs); 74 75 for(i = 0; i < ci->num_of_certs; i++) { 76 struct curl_slist *slist; 77 78 for(slist = ci->certinfo[i]; slist; slist = slist->next) 79 printf("%s\n", slist->data); 80 } 81 } 82 } 83 curl_easy_cleanup(curl); 84 } 85 } 86 ~~~ 87 88 # HISTORY 89 90 Schannel support added in 7.50.0. mbedTLS support added in 8.9.0. 91 92 # %AVAILABILITY% 93 94 # RETURN VALUE 95 96 curl_easy_setopt(3) returns a CURLcode indicating success or error. 97 98 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 99 libcurl-errors(3).