1 .\" **************************************************************************
3 .\" * Project ___| | | | _ \| |
4 .\" * / __| | | | |_) | |
5 .\" * | (__| |_| | _ <| |___
6 .\" * \___|\___/|_| \_\_____|
8 .\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
18 .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 .\" * KIND, either express or implied.
21 .\" **************************************************************************
23 .TH CURLOPT_SSL_CTX_DATA 3 "May 31, 2017" "libcurl 7.59.0" "curl_easy_setopt options"
26 CURLOPT_SSL_CTX_DATA \- custom pointer passed to ssl_ctx callback
28 #include <curl/curl.h>
30 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSL_CTX_DATA, void *pointer);
32 Data \fIpointer\fP to pass to the ssl context callback set by the option
33 \fICURLOPT_SSL_CTX_FUNCTION(3)\fP, this is the pointer you'll get as third
38 All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
41 /* OpenSSL specific */
43 #include <openssl/ssl.h>
44 #include <curl/curl.h>
47 static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm)
52 char *mypem = (char *)parm;
54 bio=BIO_new_mem_buf(mypem, -1);
55 /* use it to read the PEM formatted certificate from memory into an
56 * X509 structure that SSL can use
58 PEM_read_bio_X509(bio, &cert, 0, NULL);
60 printf("PEM_read_bio_X509 failed...\\n");
62 /* get a pointer to the X509 certificate store (which may be empty) */
63 store=SSL_CTX_get_cert_store((SSL_CTX *)sslctx);
65 /* add our certificate to this store */
66 if(X509_STORE_add_cert(store, cert)==0)
67 printf("error adding certificate\\n");
69 /* decrease reference counts */
81 char *mypem = /* example CA cert PEM - shortened */
82 "-----BEGIN CERTIFICATE-----\\n"
83 "MIIHPTCCBSWgAwIBAgIBADANBgkqhkiG9w0BAQQFADB5MRAwDgYDVQQKEwdSb290\\n"
84 "IENBMR4wHAYDVQQLExVodHRwOi8vd3d3LmNhY2VydC5vcmcxIjAgBgNVBAMTGUNB\\n"
85 "IENlcnQgU2lnbmluZyBBdXRob3JpdHkxITAfBgkqhkiG9w0BCQEWEnN1cHBvcnRA\\n"
86 "Y2FjZXJ0Lm9yZzAeFw0wMzAzMzAxMjI5NDlaFw0zMzAzMjkxMjI5NDlaMHkxEDAO\\n"
87 "GCSNe9FINSkYQKyTYOGWhlC0elnYjyELn8+CkcY7v2vcB5G5l1YjqrZslMZIBjzk\\n"
88 "zk6q5PYvCdxTby78dOs6Y5nCpqyJvKeyRKANihDjbPIky/qbn3BHLt4Ui9SyIAmW\\n"
89 "omTxJBzcoTWcFbLUvFUufQb1nA5V9FrWk9p2rSVzTMVD\\n"
90 "-----END CERTIFICATE-----\\n";
92 rv=curl_global_init(CURL_GLOBAL_ALL);
94 rv=curl_easy_setopt(ch, CURLOPT_SSLCERTTYPE, "PEM");
95 rv=curl_easy_setopt(ch, CURLOPT_SSL_VERIFYPEER, 1L);
96 rv=curl_easy_setopt(ch, CURLOPT_URL, "https://www.example.com/");
98 /* Retrieve page using cacerts' certificate -> will succeed
99 * load the certificate by installing a function doing the necessary
100 * "modifications" to the SSL CONTEXT just before link init
102 rv=curl_easy_setopt(ch, CURLOPT_SSL_CTX_FUNCTION, *sslctx_function);
103 rv=curl_easy_setopt(ch, CURLOPT_SSL_CTX_DATA, mypem);
104 rv=curl_easy_perform(ch);
106 printf("*** transfer succeeded ***\\n");
108 printf("*** transfer failed ***\\n");
110 curl_easy_cleanup(ch);
111 curl_global_cleanup();
116 Added in 7.11.0 for OpenSSL. Added in 7.42.0 for wolfSSL/CyaSSL. Other SSL
117 backends not supported.
119 CURLE_OK if supported; or an error such as:
121 CURLE_NOT_BUILT_IN - Not supported by the SSL backend
125 .BR CURLOPT_SSL_CTX_FUNCTION "(3), " CURLOPT_SSLVERSION "(3), "