CURLINFO_TLS_SSL_PTR.3 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. .\" generated by cd2nroff 0.1 from CURLINFO_TLS_SSL_PTR.md
  2. .TH CURLINFO_TLS_SSL_PTR 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLINFO_TLS_SESSION, CURLINFO_TLS_SSL_PTR \- get TLS session info
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_TLS_SSL_PTR,
  9. struct curl_tlssessioninfo **session);
  10. /* if you need compatibility with libcurl < 7.48.0 use
  11. CURLINFO_TLS_SESSION instead: */
  12. CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_TLS_SESSION,
  13. struct curl_tlssessioninfo **session);
  14. .fi
  15. .SH DESCRIPTION
  16. Pass a pointer to a \fIstruct curl_tlssessioninfo \fP*. The pointer is initialized
  17. to refer to a \fIstruct curl_tlssessioninfo \fP* that contains an enum indicating
  18. the SSL library used for the handshake and a pointer to the respective
  19. internal TLS session structure of this underlying SSL library.
  20. This option may be useful for example to extract certificate information in a
  21. format convenient for further processing, such as manual validation. Refer to
  22. the \fBLIMITATIONS\fP section.
  23. .nf
  24. struct curl_tlssessioninfo {
  25. curl_sslbackend backend;
  26. void *internals;
  27. };
  28. .fi
  29. The \fIbackend\fP struct member is one of the defines in the CURLSSLBACKEND_*
  30. series: CURLSSLBACKEND_NONE (when built without TLS support),
  31. CURLSSLBACKEND_WOLFSSL, CURLSSLBACKEND_SECURETRANSPORT, CURLSSLBACKEND_GNUTLS,
  32. CURLSSLBACKEND_MBEDTLS, CURLSSLBACKEND_NSS, CURLSSLBACKEND_OPENSSL or
  33. CURLSSLBACKEND_SCHANNEL. (Note that the OpenSSL
  34. forks are all reported as just OpenSSL here.)
  35. The \fIinternals\fP struct member points to a TLS library specific pointer for
  36. the active ("in use") SSL connection, with the following underlying types:
  37. .IP GnuTLS
  38. \fBgnutls_session_t\fP
  39. .IP OpenSSL
  40. \fICURLINFO_TLS_SESSION(3)\fP: \fBSSL_CTX \fP*
  41. \fICURLINFO_TLS_SSL_PTR(3)\fP: \fBSSL \fP*
  42. Since 7.48.0 the \fIinternals\fP member can point to these other SSL backends
  43. as well:
  44. .IP mbedTLS
  45. \fBmbedTLS_ssl_context \fP*
  46. .IP "Secure Channel"
  47. \fBCtxtHandle \fP*
  48. .IP "Secure Transport"
  49. \fBSSLContext \fP*
  50. .IP wolfSSL
  51. \fBSSL \fP*
  52. .PP
  53. If the \fIinternals\fP pointer is NULL then either the SSL backend is not
  54. supported, an SSL session has not yet been established or the connection is no
  55. longer associated with the easy handle (e.g. \fIcurl_easy_perform(3)\fP has
  56. returned).
  57. .SH LIMITATIONS
  58. This option has some limitations that could make it unsafe when it comes to
  59. the manual verification of certificates.
  60. This option only retrieves the first in\-use SSL session pointer for your easy
  61. handle, however your easy handle may have more than one in\-use SSL session if
  62. using FTP over SSL. That is because the FTP protocol has a control channel and
  63. a data channel and one or both may be over SSL. Currently there is no way to
  64. retrieve a second in\-use SSL session associated with an easy handle.
  65. This option has not been thoroughly tested with clear text protocols that can
  66. be upgraded/downgraded to/from SSL: FTP, SMTP, POP3, IMAP when used with
  67. \fICURLOPT_USE_SSL(3)\fP. Though you can to retrieve the SSL pointer, it is possible
  68. that before you can do that, data (including auth) may have already been sent
  69. over a connection after it was upgraded.
  70. Renegotiation. If unsafe renegotiation or renegotiation in a way that the
  71. certificate is allowed to change is allowed by your SSL library this may occur
  72. and the certificate may change, and data may continue to be sent or received
  73. after renegotiation but before you are able to get the (possibly) changed SSL
  74. pointer, with the (possibly) changed certificate information.
  75. Instead of using this option to poll for certificate changes use
  76. \fICURLOPT_SSL_CTX_FUNCTION(3)\fP to set a verification callback, if supported.
  77. That is safer and does not suffer from any of the problems above.
  78. How are you using this option? Are you affected by any of these limitations?
  79. Please let us know by making a comment at
  80. https://github.com/curl/curl/issues/685
  81. .SH PROTOCOLS
  82. This functionality affects all TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
  83. This option works only with the following TLS backends:
  84. BearSSL, GnuTLS, OpenSSL, Schannel, Secure Transport, mbedTLS and wolfSSL
  85. .SH EXAMPLE
  86. .nf
  87. #include <curl/curl.h>
  88. #include <openssl/ssl.h>
  89. CURL *curl;
  90. static size_t wf(void *ptr, size_t size, size_t nmemb, void *stream)
  91. {
  92. const struct curl_tlssessioninfo *info = NULL;
  93. CURLcode res = curl_easy_getinfo(curl, CURLINFO_TLS_SSL_PTR, &info);
  94. if(info && !res) {
  95. if(CURLSSLBACKEND_OPENSSL == info->backend) {
  96. printf("OpenSSL ver. %s\\n", SSL_get_version((SSL*)info->internals));
  97. }
  98. }
  99. return size * nmemb;
  100. }
  101. int main(int argc, char **argv)
  102. {
  103. CURLcode res;
  104. curl = curl_easy_init();
  105. if(curl) {
  106. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  107. curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wf);
  108. res = curl_easy_perform(curl);
  109. curl_easy_cleanup(curl);
  110. }
  111. return res;
  112. }
  113. .fi
  114. .SH HISTORY
  115. This option supersedes \fICURLINFO_TLS_SESSION(3)\fP which was added in 7.34.0.
  116. This option is exactly the same as that option except in the case of OpenSSL.
  117. .SH AVAILABILITY
  118. Added in curl 7.48.0
  119. .SH RETURN VALUE
  120. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  121. .SH SEE ALSO
  122. .BR CURLINFO_TLS_SESSION (3),
  123. .BR curl_easy_getinfo (3),
  124. .BR curl_easy_setopt (3)