2
0

vtls_int.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #ifndef HEADER_CURL_VTLS_INT_H
  2. #define HEADER_CURL_VTLS_INT_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. #include "cfilters.h"
  28. #include "urldata.h"
  29. #ifdef USE_SSL
  30. /* see https://www.iana.org/assignments/tls-extensiontype-values/ */
  31. #define ALPN_HTTP_1_1_LENGTH 8
  32. #define ALPN_HTTP_1_1 "http/1.1"
  33. #define ALPN_H2_LENGTH 2
  34. #define ALPN_H2 "h2"
  35. #define ALPN_H3_LENGTH 2
  36. #define ALPN_H3 "h3"
  37. /* conservative sizes on the ALPN entries and count we are handling,
  38. * we can increase these if we ever feel the need or have to accommodate
  39. * ALPN strings from the "outside". */
  40. #define ALPN_NAME_MAX 10
  41. #define ALPN_ENTRIES_MAX 3
  42. #define ALPN_PROTO_BUF_MAX (ALPN_ENTRIES_MAX * (ALPN_NAME_MAX + 1))
  43. struct alpn_spec {
  44. const char entries[ALPN_ENTRIES_MAX][ALPN_NAME_MAX];
  45. size_t count; /* number of entries */
  46. };
  47. struct alpn_proto_buf {
  48. unsigned char data[ALPN_PROTO_BUF_MAX];
  49. int len;
  50. };
  51. CURLcode Curl_alpn_to_proto_buf(struct alpn_proto_buf *buf,
  52. const struct alpn_spec *spec);
  53. CURLcode Curl_alpn_to_proto_str(struct alpn_proto_buf *buf,
  54. const struct alpn_spec *spec);
  55. CURLcode Curl_alpn_set_negotiated(struct Curl_cfilter *cf,
  56. struct Curl_easy *data,
  57. const unsigned char *proto,
  58. size_t proto_len);
  59. /* Information in each SSL cfilter context: cf->ctx */
  60. struct ssl_connect_data {
  61. ssl_connection_state state;
  62. ssl_connect_state connecting_state;
  63. struct ssl_peer peer;
  64. const struct alpn_spec *alpn; /* ALPN to use or NULL for none */
  65. void *backend; /* vtls backend specific props */
  66. struct cf_call_data call_data; /* data handle used in current call */
  67. struct curltime handshake_done; /* time when handshake finished */
  68. BIT(use_alpn); /* if ALPN shall be used in handshake */
  69. BIT(peer_closed); /* peer has closed connection */
  70. };
  71. #undef CF_CTX_CALL_DATA
  72. #define CF_CTX_CALL_DATA(cf) \
  73. ((struct ssl_connect_data *)(cf)->ctx)->call_data
  74. /* Definitions for SSL Implementations */
  75. struct Curl_ssl {
  76. /*
  77. * This *must* be the first entry to allow returning the list of available
  78. * backends in curl_global_sslset().
  79. */
  80. curl_ssl_backend info;
  81. unsigned int supports; /* bitfield, see above */
  82. size_t sizeof_ssl_backend_data;
  83. int (*init)(void);
  84. void (*cleanup)(void);
  85. size_t (*version)(char *buffer, size_t size);
  86. int (*check_cxn)(struct Curl_cfilter *cf, struct Curl_easy *data);
  87. int (*shut_down)(struct Curl_cfilter *cf,
  88. struct Curl_easy *data);
  89. bool (*data_pending)(struct Curl_cfilter *cf,
  90. const struct Curl_easy *data);
  91. /* return 0 if a find random is filled in */
  92. CURLcode (*random)(struct Curl_easy *data, unsigned char *entropy,
  93. size_t length);
  94. bool (*cert_status_request)(void);
  95. CURLcode (*connect_blocking)(struct Curl_cfilter *cf,
  96. struct Curl_easy *data);
  97. CURLcode (*connect_nonblocking)(struct Curl_cfilter *cf,
  98. struct Curl_easy *data,
  99. bool *done);
  100. /* During handshake, adjust the pollset to include the socket
  101. * for POLLOUT or POLLIN as needed.
  102. * Mandatory. */
  103. void (*adjust_pollset)(struct Curl_cfilter *cf, struct Curl_easy *data,
  104. struct easy_pollset *ps);
  105. void *(*get_internals)(struct ssl_connect_data *connssl, CURLINFO info);
  106. void (*close)(struct Curl_cfilter *cf, struct Curl_easy *data);
  107. void (*close_all)(struct Curl_easy *data);
  108. CURLcode (*set_engine)(struct Curl_easy *data, const char *engine);
  109. CURLcode (*set_engine_default)(struct Curl_easy *data);
  110. struct curl_slist *(*engines_list)(struct Curl_easy *data);
  111. bool (*false_start)(void);
  112. CURLcode (*sha256sum)(const unsigned char *input, size_t inputlen,
  113. unsigned char *sha256sum, size_t sha256sumlen);
  114. bool (*attach_data)(struct Curl_cfilter *cf, struct Curl_easy *data);
  115. void (*detach_data)(struct Curl_cfilter *cf, struct Curl_easy *data);
  116. void (*free_multi_ssl_backend_data)(struct multi_ssl_backend_data *mbackend);
  117. ssize_t (*recv_plain)(struct Curl_cfilter *cf, struct Curl_easy *data,
  118. char *buf, size_t len, CURLcode *code);
  119. ssize_t (*send_plain)(struct Curl_cfilter *cf, struct Curl_easy *data,
  120. const void *mem, size_t len, CURLcode *code);
  121. };
  122. extern const struct Curl_ssl *Curl_ssl;
  123. int Curl_none_init(void);
  124. void Curl_none_cleanup(void);
  125. int Curl_none_shutdown(struct Curl_cfilter *cf, struct Curl_easy *data);
  126. int Curl_none_check_cxn(struct Curl_cfilter *cf, struct Curl_easy *data);
  127. CURLcode Curl_none_random(struct Curl_easy *data, unsigned char *entropy,
  128. size_t length);
  129. void Curl_none_close_all(struct Curl_easy *data);
  130. void Curl_none_session_free(void *ptr);
  131. bool Curl_none_data_pending(struct Curl_cfilter *cf,
  132. const struct Curl_easy *data);
  133. bool Curl_none_cert_status_request(void);
  134. CURLcode Curl_none_set_engine(struct Curl_easy *data, const char *engine);
  135. CURLcode Curl_none_set_engine_default(struct Curl_easy *data);
  136. struct curl_slist *Curl_none_engines_list(struct Curl_easy *data);
  137. bool Curl_none_false_start(void);
  138. void Curl_ssl_adjust_pollset(struct Curl_cfilter *cf, struct Curl_easy *data,
  139. struct easy_pollset *ps);
  140. /**
  141. * Get the SSL filter below the given one or NULL if there is none.
  142. */
  143. bool Curl_ssl_cf_is_proxy(struct Curl_cfilter *cf);
  144. /* extract a session ID
  145. * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
  146. * Caller must make sure that the ownership of returned sessionid object
  147. * is properly taken (e.g. its refcount is incremented
  148. * under sessionid mutex).
  149. */
  150. bool Curl_ssl_getsessionid(struct Curl_cfilter *cf,
  151. struct Curl_easy *data,
  152. const struct ssl_peer *peer,
  153. void **ssl_sessionid,
  154. size_t *idsize); /* set 0 if unknown */
  155. /* add a new session ID
  156. * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
  157. * Caller must ensure that it has properly shared ownership of this sessionid
  158. * object with cache (e.g. incrementing refcount on success)
  159. * Call takes ownership of `ssl_sessionid`, using `sessionid_free_cb`
  160. * to destroy it in case of failure or later removal.
  161. */
  162. CURLcode Curl_ssl_addsessionid(struct Curl_cfilter *cf,
  163. struct Curl_easy *data,
  164. const struct ssl_peer *peer,
  165. void *ssl_sessionid,
  166. size_t idsize,
  167. Curl_ssl_sessionid_dtor *sessionid_free_cb);
  168. #include "openssl.h" /* OpenSSL versions */
  169. #include "gtls.h" /* GnuTLS versions */
  170. #include "wolfssl.h" /* wolfSSL versions */
  171. #include "schannel.h" /* Schannel SSPI version */
  172. #include "sectransp.h" /* SecureTransport (Darwin) version */
  173. #include "mbedtls.h" /* mbedTLS versions */
  174. #include "bearssl.h" /* BearSSL versions */
  175. #include "rustls.h" /* rustls versions */
  176. #endif /* USE_SSL */
  177. #endif /* HEADER_CURL_VTLS_INT_H */