int basic_auth (SOCKET s ) { char *cred, *user = relay_user, *pass= relay_pass; int len, ret; char * userpass= NULL; if (user == NULL) { g_error("Cannot decide username for proxy authentication.(%s,%d)",__FILE__, __LINE__); return -1; } if (pass == NULL) { g_error("Can not decide password for proxy authentication.(%s,%d)", __FILE__, __LINE__); } // if ((pass = determine_relay_password ()) == NULL && // (pass = readpass("Enter proxy authentication password for %s@%s: ", //relay_user, relay_host)) == NULL) // g_error("Cannot decide password for proxy authentication."); len = strlen(user)+strlen(pass)+1; userpass = xmalloc(len+1); snprintf(userpass, len+1, "%s:%s", user, pass); //memset (pass, 0, strlen(pass)); cred = make_base64_string(userpass); memset (userpass, 0, len); ret = sendf(s, "Proxy-Authorization: Basic %s\r\n", cred); memset(cred, 0, strlen(cred)); free(cred); return ret; }
static const char * username_password_as_base64 (const struct http_proxy_info *p, struct gc_arena *gc) { struct buffer out = alloc_buf_gc (strlen (p->up.username) + strlen (p->up.password) + 2, gc); ASSERT (strlen (p->up.username) > 0); buf_printf (&out, "%s:%s", p->up.username, p->up.password); return (const char *)make_base64_string ((const uint8_t*)BSTR (&out), gc); }