vtls.h 11 KB

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