doh: add options to disable ssl verification

- New libcurl options CURLOPT_DOH_SSL_VERIFYHOST,
  CURLOPT_DOH_SSL_VERIFYPEER and CURLOPT_DOH_SSL_VERIFYSTATUS do the
  same as their respective counterparts.

- New curl tool options --doh-insecure and --doh-cert-status do the same
  as their respective counterparts.

Prior to this change DOH SSL certificate verification settings for
verifyhost and verifypeer were supposed to be inherited respectively
from CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER, but due to a bug
were not. As a result DOH verification remained at the default, ie
enabled, and it was not possible to disable. This commit changes
behavior so that the DOH verification settings are independent and not
inherited.

Ref: https://github.com/curl/curl/pull/4579#issuecomment-554723676

Fixes https://github.com/curl/curl/issues/4578
Closes https://github.com/curl/curl/pull/6597
This commit is contained in:
Jay Satiro 2021-02-11 17:09:59 -05:00
parent b68026f7f4
commit 53022e1893
22 changed files with 404 additions and 44 deletions

View file

@ -174,10 +174,13 @@ struct OperationConfig {
bool globoff;
bool use_httpget;
bool insecure_ok; /* set TRUE to allow insecure SSL connects */
bool doh_insecure_ok; /* set TRUE to allow insecure SSL connects
for DOH */
bool proxy_insecure_ok; /* set TRUE to allow insecure SSL connects
for proxy */
bool terminal_binary_ok;
bool verifystatus;
bool doh_verifystatus;
bool create_dirs;
bool ftp_create_dirs;
bool ftp_skip_ip;

View file

@ -251,6 +251,7 @@ static const struct LongShort aliases[]= {
{"Ep", "pinnedpubkey", ARG_STRING},
{"EP", "proxy-pinnedpubkey", ARG_STRING},
{"Eq", "cert-status", ARG_BOOL},
{"EQ", "doh-cert-status", ARG_BOOL},
{"Er", "false-start", ARG_BOOL},
{"Es", "ssl-no-revoke", ARG_BOOL},
{"ES", "ssl-revoke-best-effort", ARG_BOOL},
@ -294,6 +295,7 @@ static const struct LongShort aliases[]= {
{"j", "junk-session-cookies", ARG_BOOL},
{"J", "remote-header-name", ARG_BOOL},
{"k", "insecure", ARG_BOOL},
{"kd", "doh-insecure", ARG_BOOL},
{"K", "config", ARG_FILENAME},
{"l", "list-only", ARG_BOOL},
{"L", "location", ARG_BOOL},
@ -1626,6 +1628,10 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
config->verifystatus = TRUE;
break;
case 'Q': /* --doh-cert-status */
config->doh_verifystatus = TRUE;
break;
case 'r': /* --false-start */
config->falsestart = TRUE;
break;
@ -1887,7 +1893,10 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
config->content_disposition = toggle;
break;
case 'k': /* allow insecure SSL connects */
config->insecure_ok = toggle;
if(subletter == 'd') /* --doh-insecure */
config->doh_insecure_ok = toggle;
else
config->insecure_ok = toggle;
break;
case 'K': /* parse config file */
if(parseconfig(nextarg, global))

View file

@ -149,7 +149,7 @@ static const struct helptxt helptext[] = {
"Client certificate file and password",
CURLHELP_TLS},
{" --cert-status",
"Verify the status of the server certificate",
"Verify the status of the server cert via OCSP-staple",
CURLHELP_TLS},
{" --cert-type <type>",
"Certificate type (DER/PEM/ENG)",
@ -241,6 +241,12 @@ static const struct helptxt helptext[] = {
{" --dns-servers <addresses>",
"DNS server addrs to use",
CURLHELP_DNS},
{" --doh-cert-status",
"Verify the status of the DOH server cert via OCSP-staple",
CURLHELP_DNS | CURLHELP_TLS},
{" --doh-insecure",
"Allow insecure DOH server connections",
CURLHELP_DNS | CURLHELP_TLS},
{" --doh-url <URL>",
"Resolve host names over DOH",
CURLHELP_DNS},

View file

@ -1685,6 +1685,12 @@ static CURLcode single_transfer(struct GlobalConfig *global,
/* libcurl default is strict verifyhost -> 2L */
/* my_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L); */
}
if(config->doh_insecure_ok) {
my_setopt(curl, CURLOPT_DOH_SSL_VERIFYPEER, 0L);
my_setopt(curl, CURLOPT_DOH_SSL_VERIFYHOST, 0L);
}
if(config->proxy_insecure_ok) {
my_setopt(curl, CURLOPT_PROXY_SSL_VERIFYPEER, 0L);
my_setopt(curl, CURLOPT_PROXY_SSL_VERIFYHOST, 0L);
@ -1696,6 +1702,9 @@ static CURLcode single_transfer(struct GlobalConfig *global,
if(config->verifystatus)
my_setopt(curl, CURLOPT_SSL_VERIFYSTATUS, 1L);
if(config->doh_verifystatus)
my_setopt(curl, CURLOPT_DOH_SSL_VERIFYSTATUS, 1L);
if(config->falsestart)
my_setopt(curl, CURLOPT_SSL_FALSESTART, 1L);
@ -2399,7 +2408,7 @@ static CURLcode transfer_per_config(struct GlobalConfig *global,
capath_from_env = false;
if(!config->cacert &&
!config->capath &&
!config->insecure_ok) {
(!config->insecure_ok || (config->doh_url && !config->doh_insecure_ok))) {
CURL *curltls = curl_easy_init();
struct curl_tlssessioninfo *tls_backend_info = NULL;