mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
common: Make proper use of http proxy parameter.
* common/http.c (is_hostname_port): New. (send_request): Fix proxy name parsing. -- Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
a0dead5edc
commit
54e55149f2
@ -1394,6 +1394,33 @@ parse_tuple (char *string)
|
||||
}
|
||||
|
||||
|
||||
/* Return true if STRING is likely "hostname:port" or only "hostname". */
|
||||
static int
|
||||
is_hostname_port (const char *string)
|
||||
{
|
||||
int colons = 0;
|
||||
|
||||
if (!string || !*string)
|
||||
return 0;
|
||||
for (; *string; string++)
|
||||
{
|
||||
if (*string == ':')
|
||||
{
|
||||
if (colons)
|
||||
return 0;
|
||||
if (!string[1])
|
||||
return 0;
|
||||
colons++;
|
||||
}
|
||||
else if (!colons && strchr (" \t\f\n\v_@[]/", *string))
|
||||
return 0; /* Invalid characters in hostname. */
|
||||
else if (colons && !digitp (string))
|
||||
return 0; /* Not a digit in the port. */
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Send a HTTP request to the server
|
||||
* Returns 0 if the request was successful
|
||||
@ -1474,8 +1501,26 @@ send_request (http_t hd, const char *httphost, const char *auth,
|
||||
if (proxy)
|
||||
http_proxy = proxy;
|
||||
|
||||
err = parse_uri (&uri, http_proxy, 0,
|
||||
!!(hd->flags & HTTP_FLAG_FORCE_TLS));
|
||||
err = parse_uri (&uri, http_proxy, 1, 0);
|
||||
if (gpg_err_code (err) == GPG_ERR_INV_URI
|
||||
&& is_hostname_port (http_proxy))
|
||||
{
|
||||
/* Retry assuming a "hostname:port" string. */
|
||||
char *tmpname = strconcat ("http://", http_proxy, NULL);
|
||||
if (tmpname && !parse_uri (&uri, tmpname, 0, 0))
|
||||
err = 0;
|
||||
xfree (tmpname);
|
||||
}
|
||||
|
||||
if (err)
|
||||
;
|
||||
else if (!strcmp (uri->scheme, "http") || !strcmp (uri->scheme, "socks4"))
|
||||
;
|
||||
else if (!strcmp (uri->scheme, "socks5h"))
|
||||
err = gpg_err_make (default_errsource, GPG_ERR_NOT_IMPLEMENTED);
|
||||
else
|
||||
err = gpg_err_make (default_errsource, GPG_ERR_INV_URI);
|
||||
|
||||
if (err)
|
||||
{
|
||||
log_error ("invalid HTTP proxy (%s): %s\n",
|
||||
|
Loading…
x
Reference in New Issue
Block a user