CURLOPT_SSL_CTX_DATA.3 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. .\" generated by cd2nroff 0.1 from CURLOPT_SSL_CTX_DATA.md
  2. .TH CURLOPT_SSL_CTX_DATA 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_SSL_CTX_DATA \- pointer passed to SSL context callback
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSL_CTX_DATA, void *pointer);
  9. .fi
  10. .SH DESCRIPTION
  11. Data \fIpointer\fP to pass to the ssl context callback set by the option
  12. \fICURLOPT_SSL_CTX_FUNCTION(3)\fP, this is the pointer you get as third
  13. parameter.
  14. .SH DEFAULT
  15. NULL
  16. .SH PROTOCOLS
  17. This functionality affects all TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
  18. This option works only with the following TLS backends:
  19. BearSSL, OpenSSL, mbedTLS and wolfSSL
  20. .SH EXAMPLE
  21. .nf
  22. /* OpenSSL specific */
  23. #include <openssl/ssl.h>
  24. #include <curl/curl.h>
  25. #include <stdio.h>
  26. static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm)
  27. {
  28. X509_STORE *store;
  29. X509 *cert = NULL;
  30. BIO *bio;
  31. char *mypem = parm;
  32. /* get a BIO */
  33. bio = BIO_new_mem_buf(mypem, -1);
  34. /* use it to read the PEM formatted certificate from memory into an
  35. * X509 structure that SSL can use
  36. */
  37. PEM_read_bio_X509(bio, &cert, 0, NULL);
  38. if(!cert)
  39. printf("PEM_read_bio_X509 failed...\\n");
  40. /* get a pointer to the X509 certificate store (which may be empty) */
  41. store = SSL_CTX_get_cert_store((SSL_CTX *)sslctx);
  42. /* add our certificate to this store */
  43. if(X509_STORE_add_cert(store, cert) == 0)
  44. printf("error adding certificate\\n");
  45. /* decrease reference counts */
  46. X509_free(cert);
  47. BIO_free(bio);
  48. /* all set to go */
  49. return CURLE_OK;
  50. }
  51. int main(void)
  52. {
  53. CURL *ch;
  54. CURLcode rv;
  55. char *mypem = /* example CA cert PEM - shortened */
  56. "-----BEGIN CERTIFICATE-----\\n"
  57. "MIIHPTCCBSWgAwIBAgIBADANBgkqhkiG9w0BAQQFADB5MRAwDgYDVQQKEwdSb290\\n"
  58. "IENBMR4wHAYDVQQLExVodHRwOi8vd3d3LmNhY2VydC5vcmcxIjAgBgNVBAMTGUNB\\n"
  59. "IENlcnQgU2lnbmluZyBBdXRob3JpdHkxITAfBgkqhkiG9w0BCQEWEnN1cHBvcnRA\\n"
  60. "Y2FjZXJ0Lm9yZzAeFw0wMzAzMzAxMjI5NDlaFw0zMzAzMjkxMjI5NDlaMHkxEDAO\\n"
  61. "GCSNe9FINSkYQKyTYOGWhlC0elnYjyELn8+CkcY7v2vcB5G5l1YjqrZslMZIBjzk\\n"
  62. "zk6q5PYvCdxTby78dOs6Y5nCpqyJvKeyRKANihDjbPIky/qbn3BHLt4Ui9SyIAmW\\n"
  63. "omTxJBzcoTWcFbLUvFUufQb1nA5V9FrWk9p2rSVzTMVD\\n"
  64. "-----END CERTIFICATE-----\\n";
  65. curl_global_init(CURL_GLOBAL_ALL);
  66. ch = curl_easy_init();
  67. curl_easy_setopt(ch, CURLOPT_SSLCERTTYPE, "PEM");
  68. curl_easy_setopt(ch, CURLOPT_SSL_VERIFYPEER, 1L);
  69. curl_easy_setopt(ch, CURLOPT_URL, "https://www.example.com/");
  70. curl_easy_setopt(ch, CURLOPT_SSL_CTX_FUNCTION, *sslctx_function);
  71. curl_easy_setopt(ch, CURLOPT_SSL_CTX_DATA, mypem);
  72. rv = curl_easy_perform(ch);
  73. if(!rv)
  74. printf("*** transfer succeeded ***\\n");
  75. else
  76. printf("*** transfer failed ***\\n");
  77. curl_easy_cleanup(ch);
  78. curl_global_cleanup();
  79. return rv;
  80. }
  81. .fi
  82. .SH HISTORY
  83. Added in 7.11.0 for OpenSSL, in 7.42.0 for wolfSSL, in 7.54.0 for mbedTLS,
  84. in 7.83.0 in BearSSL.
  85. .SH AVAILABILITY
  86. Added in curl 7.10.6
  87. .SH RETURN VALUE
  88. CURLE_OK if supported; or an error such as:
  89. CURLE_NOT_BUILT_IN \- Not supported by the SSL backend
  90. CURLE_UNKNOWN_OPTION
  91. .SH SEE ALSO
  92. .BR CURLOPT_SSLVERSION (3),
  93. .BR CURLOPT_SSL_CTX_FUNCTION (3)