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