CURLINFO_TLS_SSL_PTR.3 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.haxx.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" **************************************************************************
  22. .\"
  23. .TH CURLINFO_TLS_SSL_PTR 3 "June 28, 2018" "libcurl 7.61.1" "curl_easy_getinfo options"
  24. .SH NAME
  25. CURLINFO_TLS_SESSION, CURLINFO_TLS_SSL_PTR \- get TLS session info
  26. .SH SYNOPSIS
  27. .nf
  28. #include <curl/curl.h>
  29. CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_TLS_SSL_PTR,
  30. struct curl_tlssessioninfo **session);
  31. /* if you need compatibility with libcurl < 7.48.0 use
  32. CURLINFO_TLS_SESSION instead: */
  33. CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_TLS_SESSION,
  34. struct curl_tlssessioninfo **session);
  35. .SH DESCRIPTION
  36. Pass a pointer to a 'struct curl_tlssessioninfo *'. The pointer will be
  37. initialized to refer to a 'struct curl_tlssessioninfo *' that will contain an
  38. enum indicating the SSL library used for the handshake and a pointer to the
  39. respective internal TLS session structure of this underlying SSL library.
  40. This option may be useful for example to extract certificate information in a
  41. format convenient for further processing, such as manual validation. Refer to
  42. the \fBLIMITATIONS\fP section.
  43. .nf
  44. struct curl_tlssessioninfo {
  45. curl_sslbackend backend;
  46. void *internals;
  47. };
  48. .fi
  49. The \fIbackend\fP struct member is one of the defines in the CURLSSLBACKEND_*
  50. series: CURLSSLBACKEND_NONE (when built without TLS support),
  51. CURLSSLBACKEND_AXTLS, CURLSSLBACKEND_CYASSL, CURLSSLBACKEND_DARWINSSL,
  52. CURLSSLBACKEND_GNUTLS, CURLSSLBACKEND_GSKIT, CURLSSLBACKEND_MBEDTLS,
  53. CURLSSLBACKEND_NSS, CURLSSLBACKEND_OPENSSL, CURLSSLBACKEND_POLARSSL or
  54. CURLSSLBACKEND_SCHANNEL. (Note that the OpenSSL forks are all reported as just
  55. OpenSSL here.)
  56. The \fIinternals\fP struct member will point to a TLS library specific pointer
  57. for the active ("in use") SSL connection, with the following underlying types:
  58. .RS
  59. .IP GnuTLS
  60. gnutls_session_t
  61. .IP gskit
  62. gsk_handle
  63. .IP NSS
  64. PRFileDesc *
  65. .IP OpenSSL
  66. CURLINFO_TLS_SESSION: SSL_CTX *
  67. CURLINFO_TLS_SSL_PTR: SSL *
  68. .RE
  69. Since 7.48.0 the \fIinternals\fP member can point to these other SSL backends
  70. as well:
  71. .RS
  72. .IP axTLS
  73. SSL *
  74. .IP mbedTLS
  75. mbedtls_ssl_context *
  76. .IP PolarSSL
  77. ssl_context *
  78. .IP "Secure Channel (WinSSL)"
  79. CtxtHandle *
  80. .IP "Secure Transport (DarwinSSL)"
  81. SSLContext *
  82. .IP "WolfSSL (formerly CyaSSL)"
  83. SSL *
  84. .RE
  85. If the \fIinternals\fP pointer is NULL then either the SSL backend is not
  86. supported, an SSL session has not yet been established or the connection is no
  87. longer associated with the easy handle (eg curl_easy_perform has returned).
  88. .SH LIMITATIONS
  89. \fBThis option has some limitations that could make it unsafe when it comes to
  90. the manual verification of certificates.\fP
  91. This option only retrieves the first in-use SSL session pointer for your easy
  92. handle, however your easy handle may have more than one in-use SSL session if
  93. using FTP over SSL. That is because the FTP protocol has a control channel and
  94. a data channel and one or both may be over SSL. \fBCurrently there is no way to
  95. retrieve a second in-use SSL session associated with an easy handle.\fP
  96. This option has not been thoroughly tested with plaintext protocols that can be
  97. upgraded/downgraded to/from SSL: FTP, SMTP, POP3, IMAP when used with
  98. \fICURLOPT_USE_SSL(3)\fP. Though you will be able to retrieve the SSL pointer,
  99. it's possible that before you can do that \fBdata (including auth) may have
  100. already been sent over a connection after it was upgraded.\fP
  101. Renegotiation. If unsafe renegotiation or renegotiation in a way that the
  102. certificate is allowed to change is allowed by your SSL library this may occur
  103. and the certificate may change, and \fBdata may continue to be sent or received
  104. after renegotiation but before you are able to get the (possibly) changed SSL
  105. pointer,\fP with the (possibly) changed certificate information.
  106. If you are using OpenSSL or wolfSSL then \fICURLOPT_SSL_CTX_FUNCTION(3)\fP can
  107. be used to set a certificate verification callback in the CTX. That is safer
  108. than using this option to poll for certificate changes and doesn't suffer from
  109. any of the problems above. There is currently no way in libcurl to set a
  110. verification callback for the other SSL backends.
  111. How are you using this option? Are you affected by any of these limitations?
  112. Please let us know by making a comment at
  113. https://github.com/curl/curl/issues/685
  114. .SH PROTOCOLS
  115. All TLS-based
  116. .SH EXAMPLE
  117. .nf
  118. #include <curl/curl.h>
  119. #include <openssl/ssl.h>
  120. CURL *curl;
  121. static size_t wf(void *ptr, size_t size, size_t nmemb, void *stream)
  122. {
  123. const struct curl_tlssessioninfo *info = NULL;
  124. CURLcode res = curl_easy_getinfo(curl, CURLINFO_TLS_SSL_PTR, &info);
  125. if(info && !res) {
  126. if(CURLSSLBACKEND_OPENSSL == info->backend) {
  127. printf("OpenSSL ver. %s\\n", SSL_get_version((SSL*)info->internals));
  128. }
  129. }
  130. return size * nmemb;
  131. }
  132. int main(int argc, char** argv)
  133. {
  134. CURLcode res;
  135. curl = curl_easy_init();
  136. if(curl) {
  137. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  138. curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wf);
  139. res = curl_easy_perform(curl);
  140. curl_easy_cleanup(curl);
  141. }
  142. return res;
  143. }
  144. .fi
  145. .SH AVAILABILITY
  146. Added in 7.48.0.
  147. This option supersedes \fICURLINFO_TLS_SESSION(3)\fP which was added in 7.34.0.
  148. This option is exactly the same as that option except in the case of OpenSSL.
  149. .SH RETURN VALUE
  150. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  151. .SH "SEE ALSO"
  152. .BR curl_easy_getinfo "(3), " curl_easy_setopt "(3), "
  153. .BR CURLINFO_TLS_SESSION "(3), "