Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix up Basic auth for non-proxy authentication
With the same caveat as for Digest; we need username and password.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Feb 20, 2015
1 parent 0672368 commit 45ef9e2
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions http.c
Expand Up @@ -1381,8 +1381,17 @@ static int basic_authorization(struct openconnect_info *vpninfo, int proxy,
struct oc_text_buf *hdrbuf)
{
struct oc_text_buf *text;
const char *user, *pass;

if (!vpninfo->proxy_user || !vpninfo->proxy_pass)
if (proxy) {
user = vpninfo->proxy_user;
pass = vpninfo->proxy_pass;
} else {
/* Need to parse this out of the URL */
return -EINVAL;
}

if (!user || !pass)
return -EINVAL;

if (!vpninfo->authmethods_set) {
Expand All @@ -1398,18 +1407,23 @@ static int basic_authorization(struct openconnect_info *vpninfo, int proxy,
}

text = buf_alloc();
buf_append(text, "%s:%s", vpninfo->proxy_user, vpninfo->proxy_pass);
buf_append(text, "%s:%s", user, pass);
if (buf_error(text))
return buf_free(text);

buf_append(hdrbuf, "Proxy-Authorization: Basic ");
buf_append(hdrbuf, "%sAuthorization: Basic ", proxy ? "Proxy-" : "");
buf_append_base64(hdrbuf, text->data, text->pos);
buf_append(hdrbuf, "\r\n");

memset(text->data, 0, text->pos);
buf_free(text);

vpn_progress(vpninfo, PRG_INFO, _("Attempting HTTP Basic authentication to proxy\n"));
if (proxy)
vpn_progress(vpninfo, PRG_INFO, _("Attempting HTTP Basic authentication to proxy\n"));
else
vpn_progress(vpninfo, PRG_INFO, _("Attempting HTTP Basic authentication to server '%s'\n"),
vpninfo->hostname);

auth_state->state = AUTH_IN_PROGRESS;
return 0;
}
Expand Down

0 comments on commit 45ef9e2

Please sign in to comment.