CURLINFO_CERTINFO.3 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. .\" generated by cd2nroff 0.1 from CURLINFO_CERTINFO.md
  2. .TH CURLINFO_CERTINFO 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLINFO_CERTINFO \- get the TLS certificate chain
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_CERTINFO,
  9. struct curl_certinfo **chainp);
  10. .fi
  11. .SH DESCRIPTION
  12. Pass a pointer to a \fIstruct curl_certinfo \fP* and it is set to point to a
  13. struct that holds info about the server\(aqs certificate chain, assuming you had
  14. \fICURLOPT_CERTINFO(3)\fP enabled when the request was made.
  15. .nf
  16. struct curl_certinfo {
  17. int num_of_certs;
  18. struct curl_slist **certinfo;
  19. };
  20. .fi
  21. The \fIcertinfo\fP struct member is an array of linked lists of certificate
  22. information. The \fInum_of_certs\fP struct member is the number of certificates
  23. which is the number of elements in the array. Each certificate\(aqs list has
  24. items with textual information in the format "name:content" such as
  25. \&"Subject:Foo", "Issuer:Bar", etc. The items in each list varies depending on
  26. the SSL backend and the certificate.
  27. .SH PROTOCOLS
  28. This functionality affects all TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
  29. This option works only with the following TLS backends:
  30. GnuTLS, OpenSSL, Schannel and Secure Transport
  31. .SH EXAMPLE
  32. .nf
  33. int main(void)
  34. {
  35. CURL *curl = curl_easy_init();
  36. if(curl) {
  37. CURLcode res;
  38. curl_easy_setopt(curl, CURLOPT_URL, "https://www.example.com/");
  39. /* connect to any HTTPS site, trusted or not */
  40. curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
  41. curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
  42. curl_easy_setopt(curl, CURLOPT_CERTINFO, 1L);
  43. res = curl_easy_perform(curl);
  44. if(!res) {
  45. int i;
  46. struct curl_certinfo *ci;
  47. res = curl_easy_getinfo(curl, CURLINFO_CERTINFO, &ci);
  48. if(!res) {
  49. printf("%d certs!\\n", ci->num_of_certs);
  50. for(i = 0; i < ci->num_of_certs; i++) {
  51. struct curl_slist *slist;
  52. for(slist = ci->certinfo[i]; slist; slist = slist->next)
  53. printf("%s\\n", slist->data);
  54. }
  55. }
  56. }
  57. curl_easy_cleanup(curl);
  58. }
  59. }
  60. .fi
  61. See also the \fIcertinfo.c\fP example.
  62. .SH HISTORY
  63. GnuTLS support added in 7.42.0. Schannel support added in 7.50.0. Secure
  64. Transport support added in 7.79.0. mbedTLS support added in 8.9.0.
  65. .SH AVAILABILITY
  66. Added in curl 7.19.1
  67. .SH RETURN VALUE
  68. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  69. .SH SEE ALSO
  70. .BR CURLINFO_CAPATH (3),
  71. .BR curl_easy_getinfo (3),
  72. .BR curl_easy_setopt (3)