2
0

openssl.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef HEADER_CURL_SSLUSE_H
  2. #define HEADER_CURL_SSLUSE_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. #include "curl_setup.h"
  27. #ifdef USE_OPENSSL
  28. /*
  29. * This header should only be needed to get included by vtls.c, openssl.c
  30. * and ngtcp2.c
  31. */
  32. #include <openssl/ossl_typ.h>
  33. #include <openssl/ssl.h>
  34. #include "urldata.h"
  35. struct ssl_peer;
  36. /* Struct to hold a Curl OpenSSL instance */
  37. struct ossl_ctx {
  38. /* these ones requires specific SSL-types */
  39. SSL_CTX* ssl_ctx;
  40. SSL* ssl;
  41. X509* server_cert;
  42. BIO_METHOD *bio_method;
  43. CURLcode io_result; /* result of last BIO cfilter operation */
  44. #ifndef HAVE_KEYLOG_CALLBACK
  45. /* Set to true once a valid keylog entry has been created to avoid dupes.
  46. This is a bool and not a bitfield because it is passed by address. */
  47. bool keylog_done;
  48. #endif
  49. BIT(x509_store_setup); /* x509 store has been set up */
  50. BIT(reused_session); /* session-ID was reused for this */
  51. };
  52. size_t Curl_ossl_version(char *buffer, size_t size);
  53. typedef CURLcode Curl_ossl_ctx_setup_cb(struct Curl_cfilter *cf,
  54. struct Curl_easy *data,
  55. void *user_data);
  56. typedef int Curl_ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid);
  57. CURLcode Curl_ossl_ctx_init(struct ossl_ctx *octx,
  58. struct Curl_cfilter *cf,
  59. struct Curl_easy *data,
  60. struct ssl_peer *peer,
  61. const unsigned char *alpn, size_t alpn_len,
  62. Curl_ossl_ctx_setup_cb *cb_setup,
  63. void *cb_user_data,
  64. Curl_ossl_new_session_cb *cb_new_session,
  65. void *ssl_user_data);
  66. #if (OPENSSL_VERSION_NUMBER < 0x30000000L)
  67. #define SSL_get1_peer_certificate SSL_get_peer_certificate
  68. #endif
  69. extern const struct Curl_ssl Curl_ssl_openssl;
  70. /**
  71. * Setup the OpenSSL X509_STORE in `ssl_ctx` for the cfilter `cf` and
  72. * easy handle `data`. Will allow reuse of a shared cache if suitable
  73. * and configured.
  74. */
  75. CURLcode Curl_ssl_setup_x509_store(struct Curl_cfilter *cf,
  76. struct Curl_easy *data,
  77. SSL_CTX *ssl_ctx);
  78. CURLcode Curl_ossl_ctx_configure(struct Curl_cfilter *cf,
  79. struct Curl_easy *data,
  80. SSL_CTX *ssl_ctx);
  81. /*
  82. * Add a new session to the cache. Takes ownership of the session.
  83. */
  84. CURLcode Curl_ossl_add_session(struct Curl_cfilter *cf,
  85. struct Curl_easy *data,
  86. const char *ssl_peer_key,
  87. SSL_SESSION *ssl_sessionid,
  88. int ietf_tls_id,
  89. const char *alpn);
  90. /*
  91. * Get the server cert, verify it and show it, etc., only call failf() if
  92. * ssl config verifypeer or -host is set. Otherwise all this is for
  93. * informational purposes only!
  94. */
  95. CURLcode Curl_oss_check_peer_cert(struct Curl_cfilter *cf,
  96. struct Curl_easy *data,
  97. struct ossl_ctx *octx,
  98. struct ssl_peer *peer);
  99. #endif /* USE_OPENSSL */
  100. #endif /* HEADER_CURL_SSLUSE_H */