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