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