vtls.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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, <[email protected]>, 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_cfilter;
  31. struct Curl_easy;
  32. struct dynbuf;
  33. #define SSLSUPP_CA_PATH (1 << 0) /* supports CAPATH */
  34. #define SSLSUPP_CERTINFO (1 << 1) /* supports CURLOPT_CERTINFO */
  35. #define SSLSUPP_PINNEDPUBKEY (1 << 2) /* supports CURLOPT_PINNEDPUBLICKEY */
  36. #define SSLSUPP_SSL_CTX (1 << 3) /* supports CURLOPT_SSL_CTX */
  37. #define SSLSUPP_HTTPS_PROXY (1 << 4) /* supports access via HTTPS proxies */
  38. #define SSLSUPP_TLS13_CIPHERSUITES (1 << 5) /* supports TLS 1.3 ciphersuites */
  39. #define SSLSUPP_CAINFO_BLOB (1 << 6)
  40. #define SSLSUPP_ECH (1 << 7)
  41. #define SSLSUPP_CA_CACHE (1 << 8)
  42. #define SSLSUPP_CIPHER_LIST (1 << 9) /* supports TLS 1.0-1.2 ciphersuites */
  43. #define SSLSUPP_SIGNATURE_ALGORITHMS (1 << 10) /* supports TLS sigalgs */
  44. #ifdef USE_ECH
  45. # include "../curlx/base64.h"
  46. # define ECH_ENABLED(__data__) \
  47. (__data__->set.tls_ech && !(__data__->set.tls_ech & CURLECH_DISABLE))
  48. #endif /* USE_ECH */
  49. #define ALPN_ACCEPTED "ALPN: server accepted "
  50. #define VTLS_INFOF_NO_ALPN \
  51. "ALPN: server did not agree on a protocol. Uses default."
  52. #define VTLS_INFOF_ALPN_OFFER_1STR \
  53. "ALPN: curl offers %s"
  54. #define VTLS_INFOF_ALPN_ACCEPTED \
  55. ALPN_ACCEPTED "%.*s"
  56. #define VTLS_INFOF_NO_ALPN_DEFERRED \
  57. "ALPN: deferred handshake for early data without specific protocol."
  58. #define VTLS_INFOF_ALPN_DEFERRED \
  59. "ALPN: deferred handshake for early data using '%.*s'."
  60. /* IETF defined version numbers used in TLS protocol negotiation */
  61. #define CURL_IETF_PROTO_UNKNOWN 0x0
  62. #define CURL_IETF_PROTO_SSL3 0x0300
  63. #define CURL_IETF_PROTO_TLS1 0x0301
  64. #define CURL_IETF_PROTO_TLS1_1 0x0302
  65. #define CURL_IETF_PROTO_TLS1_2 0x0303
  66. #define CURL_IETF_PROTO_TLS1_3 0x0304
  67. #define CURL_IETF_PROTO_DTLS1 0xFEFF
  68. #define CURL_IETF_PROTO_DTLS1_2 0xFEFD
  69. typedef enum {
  70. CURL_SSL_PEER_DNS,
  71. CURL_SSL_PEER_IPV4,
  72. CURL_SSL_PEER_IPV6
  73. } ssl_peer_type;
  74. struct ssl_peer {
  75. char *hostname; /* hostname for verification */
  76. char *dispname; /* display version of hostname */
  77. char *sni; /* SNI version of hostname or NULL if not usable */
  78. char *scache_key; /* for lookups in session cache */
  79. ssl_peer_type type; /* type of the peer information */
  80. int port; /* port we are talking to */
  81. int transport; /* one of TRNSPRT_* defines */
  82. };
  83. CURLsslset Curl_init_sslset_nolock(curl_sslbackend id, const char *name,
  84. const curl_ssl_backend ***avail);
  85. #ifndef MAX_PINNED_PUBKEY_SIZE
  86. #define MAX_PINNED_PUBKEY_SIZE 1048576 /* 1 MiB */
  87. #endif
  88. curl_sslbackend Curl_ssl_backend(void);
  89. /**
  90. * Init ssl config for a new easy handle.
  91. */
  92. void Curl_ssl_easy_config_init(struct Curl_easy *data);
  93. /**
  94. * Init the `data->set.ssl` and `data->set.proxy_ssl` for
  95. * connection matching use.
  96. */
  97. CURLcode Curl_ssl_easy_config_complete(struct Curl_easy *data);
  98. /**
  99. * Init SSL configs (main + proxy) for a new connection from the easy handle.
  100. */
  101. CURLcode Curl_ssl_conn_config_init(struct Curl_easy *data,
  102. struct connectdata *conn);
  103. /**
  104. * Free allocated resources in SSL configs (main + proxy) for
  105. * the given connection.
  106. */
  107. void Curl_ssl_conn_config_cleanup(struct connectdata *conn);
  108. /**
  109. * Return TRUE iff SSL configuration from `data` is functionally the
  110. * same as the one on `candidate`.
  111. * @param proxy match the proxy SSL config or the main one
  112. */
  113. bool Curl_ssl_conn_config_match(struct Curl_easy *data,
  114. struct connectdata *candidate,
  115. bool proxy);
  116. /* Update certain connection SSL config flags after they have
  117. * been changed on the easy handle. Will work for `verifypeer`,
  118. * `verifyhost` and `verifystatus`. */
  119. void Curl_ssl_conn_config_update(struct Curl_easy *data, bool for_proxy);
  120. /**
  121. * Init SSL peer information for filter. Can be called repeatedly.
  122. */
  123. CURLcode Curl_ssl_peer_init(struct ssl_peer *peer,
  124. struct Curl_cfilter *cf,
  125. const char *tls_id,
  126. int transport);
  127. /**
  128. * Free all allocated data and reset peer information.
  129. */
  130. void Curl_ssl_peer_cleanup(struct ssl_peer *peer);
  131. #ifdef USE_SSL
  132. int Curl_ssl_init(void);
  133. void Curl_ssl_cleanup(void);
  134. /* tell the SSL stuff to close down all open information regarding
  135. connections (and thus session ID caching etc) */
  136. void Curl_ssl_close_all(struct Curl_easy *data);
  137. CURLcode Curl_ssl_set_engine(struct Curl_easy *data, const char *engine);
  138. /* Sets engine as default for all SSL operations */
  139. CURLcode Curl_ssl_set_engine_default(struct Curl_easy *data);
  140. struct curl_slist *Curl_ssl_engines_list(struct Curl_easy *data);
  141. void Curl_ssl_version(char *buffer, size_t size);
  142. /* Certificate information list handling. */
  143. #define CURL_X509_STR_MAX 100000
  144. #define MAX_ALLOWED_CERT_AMOUNT 100
  145. void Curl_ssl_free_certinfo(struct Curl_easy *data);
  146. CURLcode Curl_ssl_init_certinfo(struct Curl_easy *data, int num);
  147. CURLcode Curl_ssl_push_certinfo_len(struct Curl_easy *data, int certnum,
  148. const char *label, const char *value,
  149. size_t valuelen);
  150. CURLcode Curl_ssl_push_certinfo(struct Curl_easy *data, int certnum,
  151. const char *label, const char *value);
  152. /* Functions to be used by SSL library adaptation functions */
  153. /* get N random bytes into the buffer */
  154. CURLcode Curl_ssl_random(struct Curl_easy *data, unsigned char *buffer,
  155. size_t length);
  156. /* Check pinned public key. */
  157. CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data,
  158. const char *pinnedpubkey,
  159. const unsigned char *pubkey, size_t pubkeylen);
  160. bool Curl_ssl_cert_status_request(void);
  161. /* The maximum size of the SSL channel binding is 85 bytes, as defined in
  162. * RFC 5929, Section 4.1. The 'tls-server-end-point:' prefix is 21 bytes long,
  163. * and SHA-512 is the longest supported hash algorithm, with a digest length of
  164. * 64 bytes.
  165. * The maximum size of the channel binding is therefore 21 + 64 = 85 bytes.
  166. */
  167. #define SSL_CB_MAX_SIZE 85
  168. /* Return the tls-server-end-point channel binding, including the
  169. * 'tls-server-end-point:' prefix.
  170. * If successful, the data is written to the dynbuf, and CURLE_OK is returned.
  171. * The dynbuf MUST HAVE a minimum toobig size of SSL_CB_MAX_SIZE.
  172. * If the dynbuf is too small, CURLE_OUT_OF_MEMORY is returned.
  173. * If channel binding is not supported, binding stays empty and CURLE_OK is
  174. * returned.
  175. */
  176. CURLcode Curl_ssl_get_channel_binding(struct Curl_easy *data, int sockindex,
  177. struct dynbuf *binding);
  178. #define SSL_SHUTDOWN_TIMEOUT 10000 /* ms */
  179. CURLcode Curl_ssl_cfilter_add(struct Curl_easy *data,
  180. struct connectdata *conn,
  181. int sockindex);
  182. CURLcode Curl_cf_ssl_insert_after(struct Curl_cfilter *cf_at,
  183. struct Curl_easy *data);
  184. CURLcode Curl_ssl_cfilter_remove(struct Curl_easy *data,
  185. int sockindex, bool send_shutdown);
  186. #ifndef CURL_DISABLE_PROXY
  187. CURLcode Curl_cf_ssl_proxy_insert_after(struct Curl_cfilter *cf_at,
  188. struct Curl_easy *data);
  189. #endif /* !CURL_DISABLE_PROXY */
  190. /**
  191. * True iff the underlying SSL implementation supports the option.
  192. * Option is one of the defined SSLSUPP_* values.
  193. * `data` maybe NULL for the features of the default implementation.
  194. */
  195. bool Curl_ssl_supports(struct Curl_easy *data, unsigned int ssl_option);
  196. /**
  197. * Get the ssl_config_data in `data` that is relevant for cfilter `cf`.
  198. */
  199. struct ssl_config_data *Curl_ssl_cf_get_config(struct Curl_cfilter *cf,
  200. struct Curl_easy *data);
  201. /**
  202. * Get the primary config relevant for the filter from its connection.
  203. */
  204. struct ssl_primary_config *
  205. Curl_ssl_cf_get_primary_config(struct Curl_cfilter *cf);
  206. extern struct Curl_cftype Curl_cft_ssl;
  207. #ifndef CURL_DISABLE_PROXY
  208. extern struct Curl_cftype Curl_cft_ssl_proxy;
  209. #endif
  210. #else /* if not USE_SSL */
  211. /* When SSL support is not present, just define away these function calls */
  212. #define Curl_ssl_init() 1
  213. #define Curl_ssl_cleanup() Curl_nop_stmt
  214. #define Curl_ssl_close_all(x) Curl_nop_stmt
  215. #define Curl_ssl_set_engine(x, y) CURLE_NOT_BUILT_IN
  216. #define Curl_ssl_set_engine_default(x) CURLE_NOT_BUILT_IN
  217. #define Curl_ssl_engines_list(x) NULL
  218. #define Curl_ssl_free_certinfo(x) Curl_nop_stmt
  219. #define Curl_ssl_random(x, y, z) ((void)x, CURLE_NOT_BUILT_IN)
  220. #define Curl_ssl_cert_status_request() FALSE
  221. #define Curl_ssl_supports(a, b) FALSE
  222. #define Curl_ssl_cfilter_add(a, b, c) CURLE_NOT_BUILT_IN
  223. #define Curl_ssl_cfilter_remove(a, b, c) CURLE_OK
  224. #define Curl_ssl_cf_get_config(a, b) NULL
  225. #define Curl_ssl_cf_get_primary_config(a) NULL
  226. #endif
  227. #endif /* HEADER_CURL_VTLS_H */