| 1 |
.\" ************************************************************************** |
| 2 |
.\" * _ _ ____ _ |
| 3 |
.\" * Project ___| | | | _ \| | |
| 4 |
.\" * / __| | | | |_) | | |
| 5 |
.\" * | (__| |_| | _ <| |___ |
| 6 |
.\" * \___|\___/|_| \_\_____| |
| 7 |
.\" * |
| 8 |
.\" * Copyright (C) 1998 - 2019, Daniel Stenberg, <[email protected]>, 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 "23 Feb 2016" "libcurl 7.48.0" "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 |
|
| 30 |
CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_TLS_SSL_PTR, |
| 31 |
struct curl_tlssessioninfo **session); |
| 32 |
|
| 33 |
/* if you need compatibility with libcurl < 7.48.0 use |
| 34 |
CURLINFO_TLS_SESSION instead: */ |
| 35 |
|
| 36 |
CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_TLS_SESSION, |
| 37 |
struct curl_tlssessioninfo **session); |
| 38 |
.SH DESCRIPTION |
| 39 |
Pass a pointer to a 'struct curl_tlssessioninfo *'. The pointer will be |
| 40 |
initialized to refer to a 'struct curl_tlssessioninfo *' that will contain an |
| 41 |
enum indicating the SSL library used for the handshake and a pointer to the |
| 42 |
respective internal TLS session structure of this underlying SSL library. |
| 43 |
|
| 44 |
This option may be useful for example to extract certificate information in a |
| 45 |
format convenient for further processing, such as manual validation. Refer to |
| 46 |
the \fBLIMITATIONS\fP section. |
| 47 |
|
| 48 |
.nf |
| 49 |
struct curl_tlssessioninfo { |
| 50 |
curl_sslbackend backend; |
| 51 |
void *internals; |
| 52 |
}; |
| 53 |
.fi |
| 54 |
|
| 55 |
The \fIbackend\fP struct member is one of the defines in the CURLSSLBACKEND_* |
| 56 |
series: CURLSSLBACKEND_NONE (when built without TLS support), |
| 57 |
CURLSSLBACKEND_WOLFSSL, CURLSSLBACKEND_DARWINSSL, |
| 58 |
CURLSSLBACKEND_GNUTLS, CURLSSLBACKEND_GSKIT, CURLSSLBACKEND_MBEDTLS, |
| 59 |
CURLSSLBACKEND_NSS, CURLSSLBACKEND_OPENSSL, CURLSSLBACKEND_POLARSSL, |
| 60 |
CURLSSLBACKEND_SCHANNEL or CURLSSLBACKEND_MESALINK. (Note that the OpenSSL |
| 61 |
forks are all reported as just OpenSSL here.) |
| 62 |
|
| 63 |
The \fIinternals\fP struct member will point to a TLS library specific pointer |
| 64 |
for the active ("in use") SSL connection, with the following underlying types: |
| 65 |
.RS |
| 66 |
.IP GnuTLS |
| 67 |
gnutls_session_t |
| 68 |
.IP gskit |
| 69 |
gsk_handle |
| 70 |
.IP NSS |
| 71 |
PRFileDesc * |
| 72 |
.IP OpenSSL |
| 73 |
CURLINFO_TLS_SESSION: SSL_CTX * |
| 74 |
|
| 75 |
CURLINFO_TLS_SSL_PTR: SSL * |
| 76 |
.RE |
| 77 |
Since 7.48.0 the \fIinternals\fP member can point to these other SSL backends |
| 78 |
as well: |
| 79 |
.RS |
| 80 |
.IP mbedTLS |
| 81 |
mbedtls_ssl_context * |
| 82 |
.IP PolarSSL |
| 83 |
ssl_context * |
| 84 |
.IP "Secure Channel" |
| 85 |
CtxtHandle * |
| 86 |
.IP "Secure Transport" |
| 87 |
SSLContext * |
| 88 |
.IP "wolfSSL" |
| 89 |
SSL * |
| 90 |
.IP "MesaLink" |
| 91 |
SSL * |
| 92 |
.RE |
| 93 |
|
| 94 |
If the \fIinternals\fP pointer is NULL then either the SSL backend is not |
| 95 |
supported, an SSL session has not yet been established or the connection is no |
| 96 |
longer associated with the easy handle (eg curl_easy_perform has returned). |
| 97 |
.SH LIMITATIONS |
| 98 |
This option has some limitations that could make it unsafe when it comes to |
| 99 |
the manual verification of certificates. |
| 100 |
|
| 101 |
This option only retrieves the first in-use SSL session pointer for your easy |
| 102 |
handle, however your easy handle may have more than one in-use SSL session if |
| 103 |
using FTP over SSL. That is because the FTP protocol has a control channel and |
| 104 |
a data channel and one or both may be over SSL. Currently there is no way to |
| 105 |
retrieve a second in-use SSL session associated with an easy handle. |
| 106 |
|
| 107 |
This option has not been thoroughly tested with plaintext protocols that can |
| 108 |
be upgraded/downgraded to/from SSL: FTP, SMTP, POP3, IMAP when used with |
| 109 |
\fICURLOPT_USE_SSL(3)\fP. Though you will be able to retrieve the SSL pointer, |
| 110 |
it's possible that before you can do that data (including auth) may have |
| 111 |
already been sent over a connection after it was upgraded. |
| 112 |
|
| 113 |
Renegotiation. If unsafe renegotiation or renegotiation in a way that the |
| 114 |
certificate is allowed to change is allowed by your SSL library this may occur |
| 115 |
and the certificate may change, and data may continue to be sent or received |
| 116 |
after renegotiation but before you are able to get the (possibly) changed SSL |
| 117 |
pointer, with the (possibly) changed certificate information. |
| 118 |
|
| 119 |
If you are using OpenSSL or wolfSSL then \fICURLOPT_SSL_CTX_FUNCTION(3)\fP can |
| 120 |
be used to set a certificate verification callback in the CTX. That is safer |
| 121 |
than using this option to poll for certificate changes and doesn't suffer from |
| 122 |
any of the problems above. There is currently no way in libcurl to set a |
| 123 |
verification callback for the other SSL backends. |
| 124 |
|
| 125 |
How are you using this option? Are you affected by any of these limitations? |
| 126 |
Please let us know by making a comment at |
| 127 |
https://github.com/curl/curl/issues/685 |
| 128 |
.SH PROTOCOLS |
| 129 |
All TLS-based |
| 130 |
.SH EXAMPLE |
| 131 |
.nf |
| 132 |
#include <curl/curl.h> |
| 133 |
#include <openssl/ssl.h> |
| 134 |
|
| 135 |
CURL *curl; |
| 136 |
static size_t wf(void *ptr, size_t size, size_t nmemb, void *stream) |
| 137 |
{ |
| 138 |
const struct curl_tlssessioninfo *info = NULL; |
| 139 |
CURLcode res = curl_easy_getinfo(curl, CURLINFO_TLS_SSL_PTR, &info); |
| 140 |
if(info && !res) { |
| 141 |
if(CURLSSLBACKEND_OPENSSL == info->backend) { |
| 142 |
printf("OpenSSL ver. %s\\n", SSL_get_version((SSL*)info->internals)); |
| 143 |
} |
| 144 |
} |
| 145 |
return size * nmemb; |
| 146 |
} |
| 147 |
|
| 148 |
int main(int argc, char** argv) |
| 149 |
{ |
| 150 |
CURLcode res; |
| 151 |
curl = curl_easy_init(); |
| 152 |
if(curl) { |
| 153 |
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); |
| 154 |
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, wf); |
| 155 |
res = curl_easy_perform(curl); |
| 156 |
curl_easy_cleanup(curl); |
| 157 |
} |
| 158 |
return res; |
| 159 |
} |
| 160 |
.fi |
| 161 |
.SH AVAILABILITY |
| 162 |
Added in 7.48.0. |
| 163 |
|
| 164 |
This option supersedes \fICURLINFO_TLS_SESSION(3)\fP which was added in 7.34.0. |
| 165 |
This option is exactly the same as that option except in the case of OpenSSL. |
| 166 |
.SH RETURN VALUE |
| 167 |
Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. |
| 168 |
.SH "SEE ALSO" |
| 169 |
.BR curl_easy_getinfo "(3), " curl_easy_setopt "(3), " |
| 170 |
.BR CURLINFO_TLS_SESSION "(3), " |