| 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 CURLOPT_SSL_CTX_DATA 3 "19 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options" |
| 24 |
.SH NAME |
| 25 |
CURLOPT_SSL_CTX_DATA \- custom pointer passed to ssl_ctx callback |
| 26 |
.SH SYNOPSIS |
| 27 |
#include <curl/curl.h> |
| 28 |
|
| 29 |
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSL_CTX_DATA, void *pointer); |
| 30 |
.SH DESCRIPTION |
| 31 |
Data \fIpointer\fP to pass to the ssl context callback set by the option |
| 32 |
\fICURLOPT_SSL_CTX_FUNCTION(3)\fP, this is the pointer you'll get as third |
| 33 |
parameter. |
| 34 |
.SH DEFAULT |
| 35 |
NULL |
| 36 |
.SH PROTOCOLS |
| 37 |
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc. |
| 38 |
.SH EXAMPLE |
| 39 |
.nf |
| 40 |
/* OpenSSL specific */ |
| 41 |
|
| 42 |
#include <openssl/ssl.h> |
| 43 |
#include <curl/curl.h> |
| 44 |
#include <stdio.h> |
| 45 |
|
| 46 |
static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm) |
| 47 |
{ |
| 48 |
X509_STORE *store; |
| 49 |
X509 *cert=NULL; |
| 50 |
BIO *bio; |
| 51 |
char *mypem = (char *)parm; |
| 52 |
/* get a BIO */ |
| 53 |
bio=BIO_new_mem_buf(mypem, -1); |
| 54 |
/* use it to read the PEM formatted certificate from memory into an |
| 55 |
* X509 structure that SSL can use |
| 56 |
*/ |
| 57 |
PEM_read_bio_X509(bio, &cert, 0, NULL); |
| 58 |
if(cert == NULL) |
| 59 |
printf("PEM_read_bio_X509 failed...\\n"); |
| 60 |
|
| 61 |
/* get a pointer to the X509 certificate store (which may be empty) */ |
| 62 |
store=SSL_CTX_get_cert_store((SSL_CTX *)sslctx); |
| 63 |
|
| 64 |
/* add our certificate to this store */ |
| 65 |
if(X509_STORE_add_cert(store, cert)==0) |
| 66 |
printf("error adding certificate\\n"); |
| 67 |
|
| 68 |
/* decrease reference counts */ |
| 69 |
X509_free(cert); |
| 70 |
BIO_free(bio); |
| 71 |
|
| 72 |
/* all set to go */ |
| 73 |
return CURLE_OK; |
| 74 |
} |
| 75 |
|
| 76 |
int main(void) |
| 77 |
{ |
| 78 |
CURL * ch; |
| 79 |
CURLcode rv; |
| 80 |
char *mypem = /* example CA cert PEM - shortened */ |
| 81 |
"-----BEGIN CERTIFICATE-----\\n" |
| 82 |
"MIIHPTCCBSWgAwIBAgIBADANBgkqhkiG9w0BAQQFADB5MRAwDgYDVQQKEwdSb290\\n" |
| 83 |
"IENBMR4wHAYDVQQLExVodHRwOi8vd3d3LmNhY2VydC5vcmcxIjAgBgNVBAMTGUNB\\n" |
| 84 |
"IENlcnQgU2lnbmluZyBBdXRob3JpdHkxITAfBgkqhkiG9w0BCQEWEnN1cHBvcnRA\\n" |
| 85 |
"Y2FjZXJ0Lm9yZzAeFw0wMzAzMzAxMjI5NDlaFw0zMzAzMjkxMjI5NDlaMHkxEDAO\\n" |
| 86 |
"GCSNe9FINSkYQKyTYOGWhlC0elnYjyELn8+CkcY7v2vcB5G5l1YjqrZslMZIBjzk\\n" |
| 87 |
"zk6q5PYvCdxTby78dOs6Y5nCpqyJvKeyRKANihDjbPIky/qbn3BHLt4Ui9SyIAmW\\n" |
| 88 |
"omTxJBzcoTWcFbLUvFUufQb1nA5V9FrWk9p2rSVzTMVD\\n" |
| 89 |
"-----END CERTIFICATE-----\\n"; |
| 90 |
|
| 91 |
rv=curl_global_init(CURL_GLOBAL_ALL); |
| 92 |
ch=curl_easy_init(); |
| 93 |
rv=curl_easy_setopt(ch, CURLOPT_SSLCERTTYPE, "PEM"); |
| 94 |
rv=curl_easy_setopt(ch, CURLOPT_SSL_VERIFYPEER, 1L); |
| 95 |
rv=curl_easy_setopt(ch, CURLOPT_URL, "https://www.example.com/"); |
| 96 |
|
| 97 |
/* Retrieve page using cacerts' certificate -> will succeed |
| 98 |
* load the certificate by installing a function doing the necessary |
| 99 |
* "modifications" to the SSL CONTEXT just before link init |
| 100 |
*/ |
| 101 |
rv=curl_easy_setopt(ch, CURLOPT_SSL_CTX_FUNCTION, *sslctx_function); |
| 102 |
rv=curl_easy_setopt(ch, CURLOPT_SSL_CTX_DATA, mypem); |
| 103 |
rv=curl_easy_perform(ch); |
| 104 |
if(rv==CURLE_OK) |
| 105 |
printf("*** transfer succeeded ***\\n"); |
| 106 |
else |
| 107 |
printf("*** transfer failed ***\\n"); |
| 108 |
|
| 109 |
curl_easy_cleanup(ch); |
| 110 |
curl_global_cleanup(); |
| 111 |
return rv; |
| 112 |
} |
| 113 |
.fi |
| 114 |
.SH AVAILABILITY |
| 115 |
Added in 7.11.0 for OpenSSL, in 7.42.0 for wolfSSL and in 7.54.0 for |
| 116 |
mbedTLS. Other SSL backends are not supported. |
| 117 |
.SH RETURN VALUE |
| 118 |
CURLE_OK if supported; or an error such as: |
| 119 |
|
| 120 |
CURLE_NOT_BUILT_IN - Not supported by the SSL backend |
| 121 |
|
| 122 |
CURLE_UNKNOWN_OPTION |
| 123 |
.SH "SEE ALSO" |
| 124 |
.BR CURLOPT_SSL_CTX_FUNCTION "(3), " CURLOPT_SSLVERSION "(3), " |