CURLOPT_SSL_CTX_DATA.3 4.2 KB

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