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