vtls.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. #ifndef HEADER_CURL_VTLS_H
  2. #define HEADER_CURL_VTLS_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. struct connectdata;
  28. struct ssl_config_data;
  29. struct ssl_primary_config;
  30. struct Curl_ssl_session;
  31. #define SSLSUPP_CA_PATH (1<<0) /* supports CAPATH */
  32. #define SSLSUPP_CERTINFO (1<<1) /* supports CURLOPT_CERTINFO */
  33. #define SSLSUPP_PINNEDPUBKEY (1<<2) /* supports CURLOPT_PINNEDPUBLICKEY */
  34. #define SSLSUPP_SSL_CTX (1<<3) /* supports CURLOPT_SSL_CTX */
  35. #define SSLSUPP_HTTPS_PROXY (1<<4) /* supports access via HTTPS proxies */
  36. #define SSLSUPP_TLS13_CIPHERSUITES (1<<5) /* supports TLS 1.3 ciphersuites */
  37. #define SSLSUPP_CAINFO_BLOB (1<<6)
  38. #define SSLSUPP_ECH (1<<7)
  39. #define SSLSUPP_CA_CACHE (1<<8)
  40. #define SSLSUPP_CIPHER_LIST (1<<9) /* supports TLS 1.0-1.2 ciphersuites */
  41. #ifdef USE_ECH
  42. # include "curl_base64.h"
  43. # define ECH_ENABLED(__data__) \
  44. (__data__->set.tls_ech && \
  45. !(__data__->set.tls_ech & CURLECH_DISABLE)\
  46. )
  47. #endif /* USE_ECH */
  48. #define ALPN_ACCEPTED "ALPN: server accepted "
  49. #define VTLS_INFOF_NO_ALPN \
  50. "ALPN: server did not agree on a protocol. Uses default."
  51. #define VTLS_INFOF_ALPN_OFFER_1STR \
  52. "ALPN: curl offers %s"
  53. #define VTLS_INFOF_ALPN_ACCEPTED \
  54. ALPN_ACCEPTED "%.*s"
  55. #define VTLS_INFOF_NO_ALPN_DEFERRED \
  56. "ALPN: deferred handshake for early data without specific protocol."
  57. #define VTLS_INFOF_ALPN_DEFERRED \
  58. "ALPN: deferred handshake for early data using '%.*s'."
  59. /* Curl_multi SSL backend-specific data; declared differently by each SSL
  60. backend */
  61. struct Curl_cfilter;
  62. CURLsslset Curl_init_sslset_nolock(curl_sslbackend id, const char *name,
  63. const curl_ssl_backend ***avail);
  64. #ifndef MAX_PINNED_PUBKEY_SIZE
  65. #define MAX_PINNED_PUBKEY_SIZE 1048576 /* 1MB */
  66. #endif
  67. #ifndef CURL_SHA256_DIGEST_LENGTH
  68. #define CURL_SHA256_DIGEST_LENGTH 32 /* fixed size */
  69. #endif
  70. curl_sslbackend Curl_ssl_backend(void);
  71. /**
  72. * Init ssl config for a new easy handle.
  73. */
  74. void Curl_ssl_easy_config_init(struct Curl_easy *data);
  75. /**
  76. * Init the `data->set.ssl` and `data->set.proxy_ssl` for
  77. * connection matching use.
  78. */
  79. CURLcode Curl_ssl_easy_config_complete(struct Curl_easy *data);
  80. /**
  81. * Init SSL configs (main + proxy) for a new connection from the easy handle.
  82. */
  83. CURLcode Curl_ssl_conn_config_init(struct Curl_easy *data,
  84. struct connectdata *conn);
  85. /**
  86. * Free allocated resources in SSL configs (main + proxy) for
  87. * the given connection.
  88. */
  89. void Curl_ssl_conn_config_cleanup(struct connectdata *conn);
  90. /**
  91. * Return TRUE iff SSL configuration from `data` is functionally the
  92. * same as the one on `candidate`.
  93. * @param proxy match the proxy SSL config or the main one
  94. */
  95. bool Curl_ssl_conn_config_match(struct Curl_easy *data,
  96. struct connectdata *candidate,
  97. bool proxy);
  98. /* Update certain connection SSL config flags after they have
  99. * been changed on the easy handle. Will work for `verifypeer`,
  100. * `verifyhost` and `verifystatus`. */
  101. void Curl_ssl_conn_config_update(struct Curl_easy *data, bool for_proxy);
  102. /**
  103. * Init SSL peer information for filter. Can be called repeatedly.
  104. */
  105. CURLcode Curl_ssl_peer_init(struct ssl_peer *peer,
  106. struct Curl_cfilter *cf, int transport);
  107. /**
  108. * Free all allocated data and reset peer information.
  109. */
  110. void Curl_ssl_peer_cleanup(struct ssl_peer *peer);
  111. #ifdef USE_SSL
  112. int Curl_ssl_init(void);
  113. void Curl_ssl_cleanup(void);
  114. /* tell the SSL stuff to close down all open information regarding
  115. connections (and thus session ID caching etc) */
  116. void Curl_ssl_close_all(struct Curl_easy *data);
  117. CURLcode Curl_ssl_set_engine(struct Curl_easy *data, const char *engine);
  118. /* Sets engine as default for all SSL operations */
  119. CURLcode Curl_ssl_set_engine_default(struct Curl_easy *data);
  120. struct curl_slist *Curl_ssl_engines_list(struct Curl_easy *data);
  121. /* init the SSL session ID cache */
  122. CURLcode Curl_ssl_initsessions(struct Curl_easy *, size_t);
  123. void Curl_ssl_version(char *buffer, size_t size);
  124. /* Certificate information list handling. */
  125. #define CURL_X509_STR_MAX 100000
  126. void Curl_ssl_free_certinfo(struct Curl_easy *data);
  127. CURLcode Curl_ssl_init_certinfo(struct Curl_easy *data, int num);
  128. CURLcode Curl_ssl_push_certinfo_len(struct Curl_easy *data, int certnum,
  129. const char *label, const char *value,
  130. size_t valuelen);
  131. CURLcode Curl_ssl_push_certinfo(struct Curl_easy *data, int certnum,
  132. const char *label, const char *value);
  133. /* Functions to be used by SSL library adaptation functions */
  134. /* Lock session cache mutex.
  135. * Call this before calling other Curl_ssl_*session* functions
  136. * Caller should unlock this mutex as soon as possible, as it may block
  137. * other SSL connection from making progress.
  138. * The purpose of explicitly locking SSL session cache data is to allow
  139. * individual SSL engines to manage session lifetime in their specific way.
  140. */
  141. void Curl_ssl_sessionid_lock(struct Curl_easy *data);
  142. /* Unlock session cache mutex */
  143. void Curl_ssl_sessionid_unlock(struct Curl_easy *data);
  144. /* Kill a single session ID entry in the cache
  145. * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
  146. * This will call engine-specific curlssl_session_free function, which must
  147. * take sessionid object ownership from sessionid cache
  148. * (e.g. decrement refcount).
  149. */
  150. void Curl_ssl_kill_session(struct Curl_ssl_session *session);
  151. /* delete a session from the cache
  152. * Sessionid mutex must be locked (see Curl_ssl_sessionid_lock).
  153. * This will call engine-specific curlssl_session_free function, which must
  154. * take sessionid object ownership from sessionid cache
  155. * (e.g. decrement refcount).
  156. */
  157. void Curl_ssl_delsessionid(struct Curl_easy *data, void *ssl_sessionid);
  158. /* get N random bytes into the buffer */
  159. CURLcode Curl_ssl_random(struct Curl_easy *data, unsigned char *buffer,
  160. size_t length);
  161. /* Check pinned public key. */
  162. CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data,
  163. const char *pinnedpubkey,
  164. const unsigned char *pubkey, size_t pubkeylen);
  165. bool Curl_ssl_cert_status_request(void);
  166. bool Curl_ssl_false_start(struct Curl_easy *data);
  167. /* The maximum size of the SSL channel binding is 85 bytes, as defined in
  168. * RFC 5929, Section 4.1. The 'tls-server-end-point:' prefix is 21 bytes long,
  169. * and SHA-512 is the longest supported hash algorithm, with a digest length of
  170. * 64 bytes.
  171. * The maximum size of the channel binding is therefore 21 + 64 = 85 bytes.
  172. */
  173. #define SSL_CB_MAX_SIZE 85
  174. /* Return the tls-server-end-point channel binding, including the
  175. * 'tls-server-end-point:' prefix.
  176. * If successful, the data is written to the dynbuf, and CURLE_OK is returned.
  177. * The dynbuf MUST HAVE a minimum toobig size of SSL_CB_MAX_SIZE.
  178. * If the dynbuf is too small, CURLE_OUT_OF_MEMORY is returned.
  179. * If channel binding is not supported, binding stays empty and CURLE_OK is
  180. * returned.
  181. */
  182. CURLcode Curl_ssl_get_channel_binding(struct Curl_easy *data, int sockindex,
  183. struct dynbuf *binding);
  184. #define SSL_SHUTDOWN_TIMEOUT 10000 /* ms */
  185. CURLcode Curl_ssl_cfilter_add(struct Curl_easy *data,
  186. struct connectdata *conn,
  187. int sockindex);
  188. CURLcode Curl_cf_ssl_insert_after(struct Curl_cfilter *cf_at,
  189. struct Curl_easy *data);
  190. CURLcode Curl_ssl_cfilter_remove(struct Curl_easy *data,
  191. int sockindex, bool send_shutdown);
  192. #ifndef CURL_DISABLE_PROXY
  193. CURLcode Curl_cf_ssl_proxy_insert_after(struct Curl_cfilter *cf_at,
  194. struct Curl_easy *data);
  195. #endif /* !CURL_DISABLE_PROXY */
  196. /**
  197. * True iff the underlying SSL implementation supports the option.
  198. * Option is one of the defined SSLSUPP_* values.
  199. * `data` maybe NULL for the features of the default implementation.
  200. */
  201. bool Curl_ssl_supports(struct Curl_easy *data, unsigned int ssl_option);
  202. /**
  203. * Get the internal ssl instance (like OpenSSL's SSL*) from the filter
  204. * chain at `sockindex` of type specified by `info`.
  205. * For `n` == 0, the first active (top down) instance is returned.
  206. * 1 gives the second active, etc.
  207. * NULL is returned when no active SSL filter is present.
  208. */
  209. void *Curl_ssl_get_internals(struct Curl_easy *data, int sockindex,
  210. CURLINFO info, int n);
  211. /**
  212. * Get the ssl_config_data in `data` that is relevant for cfilter `cf`.
  213. */
  214. struct ssl_config_data *Curl_ssl_cf_get_config(struct Curl_cfilter *cf,
  215. struct Curl_easy *data);
  216. /**
  217. * Get the primary config relevant for the filter from its connection.
  218. */
  219. struct ssl_primary_config *
  220. Curl_ssl_cf_get_primary_config(struct Curl_cfilter *cf);
  221. extern struct Curl_cftype Curl_cft_ssl;
  222. #ifndef CURL_DISABLE_PROXY
  223. extern struct Curl_cftype Curl_cft_ssl_proxy;
  224. #endif
  225. #else /* if not USE_SSL */
  226. /* When SSL support is not present, just define away these function calls */
  227. #define Curl_ssl_init() 1
  228. #define Curl_ssl_cleanup() Curl_nop_stmt
  229. #define Curl_ssl_close_all(x) Curl_nop_stmt
  230. #define Curl_ssl_set_engine(x,y) CURLE_NOT_BUILT_IN
  231. #define Curl_ssl_set_engine_default(x) CURLE_NOT_BUILT_IN
  232. #define Curl_ssl_engines_list(x) NULL
  233. #define Curl_ssl_initsessions(x,y) CURLE_OK
  234. #define Curl_ssl_free_certinfo(x) Curl_nop_stmt
  235. #define Curl_ssl_kill_session(x) Curl_nop_stmt
  236. #define Curl_ssl_random(x,y,z) ((void)x, CURLE_NOT_BUILT_IN)
  237. #define Curl_ssl_cert_status_request() FALSE
  238. #define Curl_ssl_false_start(a) FALSE
  239. #define Curl_ssl_get_internals(a,b,c,d) NULL
  240. #define Curl_ssl_supports(a,b) FALSE
  241. #define Curl_ssl_cfilter_add(a,b,c) CURLE_NOT_BUILT_IN
  242. #define Curl_ssl_cfilter_remove(a,b,c) CURLE_OK
  243. #define Curl_ssl_cf_get_config(a,b) NULL
  244. #define Curl_ssl_cf_get_primary_config(a) NULL
  245. #endif
  246. #endif /* HEADER_CURL_VTLS_H */