curl: detect ECH support dynamically, not at build time

Closes #15402
This commit is contained in:
Daniel Stenberg 2024-10-24 15:49:51 +02:00
parent 8cb2d5f48a
commit 469f53686a
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
6 changed files with 15 additions and 26 deletions

View File

@ -173,21 +173,14 @@ static void free_config_fields(struct OperationConfig *config)
Curl_safefree(config->preproxy);
Curl_safefree(config->proxy_service_name);
Curl_safefree(config->service_name);
Curl_safefree(config->ftp_account);
Curl_safefree(config->ftp_alternative_to_user);
Curl_safefree(config->aws_sigv4);
Curl_safefree(config->proto_str);
Curl_safefree(config->proto_redir_str);
#ifdef USE_ECH
Curl_safefree(config->ech);
config->ech = NULL;
Curl_safefree(config->ech_config);
config->ech_config = NULL;
Curl_safefree(config->ech_public);
config->ech_public = NULL;
#endif
}
void config_free(struct OperationConfig *config)

View File

@ -306,12 +306,9 @@ struct OperationConfig {
bool rm_partial; /* on error, remove partially written output
files */
bool skip_existing;
#ifdef USE_ECH
char *ech; /* Config set by --ech keywords */
char *ech_config; /* Config set by "--ech esl:" option */
char *ech_public; /* Config set by "--ech pn:" option */
#endif
};
struct GlobalConfig {

View File

@ -1917,13 +1917,10 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
err = PARAM_ENGINES_REQUESTED;
}
break;
#ifndef USE_ECH
case C_ECH: /* --ech, not implemented by default */
err = PARAM_LIBCURL_DOESNT_SUPPORT;
break;
#else
case C_ECH: /* --ech */
if(strlen(nextarg) > 4 && strncasecompare("pn:", nextarg, 3)) {
if(!feature_ech)
err = PARAM_LIBCURL_DOESNT_SUPPORT;
else if(strlen(nextarg) > 4 && strncasecompare("pn:", nextarg, 3)) {
/* a public_name */
err = getstr(&config->ech_public, nextarg, DENY_BLANK);
}
@ -1967,7 +1964,6 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
err = getstr(&config->ech, nextarg, DENY_BLANK);
}
break;
#endif
case C_CAPATH: /* --capath */
err = getstr(&config->capath, nextarg, DENY_BLANK);
break;

View File

@ -83,6 +83,7 @@ bool feature_spnego = FALSE;
bool feature_ssl = FALSE;
bool feature_tls_srp = FALSE;
bool feature_zstd = FALSE;
bool feature_ech = FALSE;
static struct feature_name_presentp {
const char *feature_name;
@ -95,6 +96,7 @@ static struct feature_name_presentp {
{"brotli", &feature_brotli, CURL_VERSION_BROTLI},
{"CharConv", NULL, CURL_VERSION_CONV},
{"Debug", NULL, CURL_VERSION_DEBUG},
{"ECH", &feature_ech, 0},
{"gsasl", NULL, CURL_VERSION_GSASL},
{"GSS-API", NULL, CURL_VERSION_GSSAPI},
{"HSTS", &feature_hsts, CURL_VERSION_HSTS},

View File

@ -61,6 +61,7 @@ extern bool feature_spnego;
extern bool feature_ssl;
extern bool feature_tls_srp;
extern bool feature_zstd;
extern bool feature_ech;
CURLcode get_libcurl_info(void);
const char *proto_token(const char *proto);

View File

@ -1734,15 +1734,15 @@ static CURLcode config2setopts(struct GlobalConfig *global,
if(config->hsts)
my_setopt_str(curl, CURLOPT_HSTS, config->hsts);
#ifdef USE_ECH
/* only if enabled in configure */
if(config->ech) /* only if set (optional) */
my_setopt_str(curl, CURLOPT_ECH, config->ech);
if(config->ech_public) /* only if set (optional) */
my_setopt_str(curl, CURLOPT_ECH, config->ech_public);
if(config->ech_config) /* only if set (optional) */
my_setopt_str(curl, CURLOPT_ECH, config->ech_config);
#endif
if(feature_ech) {
/* only if enabled in libcurl */
if(config->ech) /* only if set (optional) */
my_setopt_str(curl, CURLOPT_ECH, config->ech);
if(config->ech_public) /* only if set (optional) */
my_setopt_str(curl, CURLOPT_ECH, config->ech_public);
if(config->ech_config) /* only if set (optional) */
my_setopt_str(curl, CURLOPT_ECH, config->ech_config);
}
/* new in 8.9.0 */
if(config->ip_tos > 0 || config->vlan_priority > 0) {