xref: /curl/docs/libcurl/opts/CURLOPT_CERTINFO.md (revision 5a488251)
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
20Added-in: 7.19.1
21---
22
23# NAME
24
25CURLOPT_CERTINFO - request SSL certificate information
26
27# SYNOPSIS
28
29~~~c
30#include <curl/curl.h>
31
32CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CERTINFO, long certinfo);
33~~~
34
35# DESCRIPTION
36
37Pass a long set to 1 to enable libcurl's certificate chain info gatherer. With
38this enabled, libcurl extracts lots of information and data about the
39certificates in the certificate chain used in the SSL connection. This data
40may then be retrieved after a transfer using curl_easy_getinfo(3) and
41its option CURLINFO_CERTINFO(3).
42
43# DEFAULT
44
450
46
47# %PROTOCOLS%
48
49# EXAMPLE
50
51~~~c
52int 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
90Schannel support added in 7.50.0. Secure Transport support added in 7.79.0.
91mbedTLS support added in 8.9.0.
92
93# %AVAILABILITY%
94
95# RETURN VALUE
96
97Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
98