}
static int
-tlswrap(int fd)
+tlswrap(int fd, char *servername)
{
TLSconn conn;
memset(&conn, 0, sizeof(conn));
if(debug)
conn.trace = tlstrace;
+ if(servername != nil)
+ conn.serverName = smprint("%N", servername);
if((fd = tlsClient(fd, &conn)) < 0){
if(debug) fprint(2, "tlsClient: %r\n");
return -1;
}
free(conn.cert);
free(conn.sessionID);
+ free(conn.serverName);
return fd;
}
if((fd = dial(addr, 0, 0, &ctl)) >= 0){
if(proxy){
if(strcmp(proxy->scheme, "https") == 0)
- fd = tlswrap(fd);
+ fd = tlswrap(fd, proxy->host);
} else {
if(strcmp(u->scheme, "https") == 0)
- fd = tlswrap(fd);
+ fd = tlswrap(fd, u->host);
}
}
if(fd < 0){
/* free the tail */
hcloseall(x);
} while(i);
- exits(0);
+ exits(nil);
}
return;
}
pass = u->pass;
realm = nonce = opaque = nil;
if(!cistrncmp(s, "Basic ", 6)){
- char cred[128], plain[128];
UserPasswd *up;
s += 6;
user = up->user;
pass = up->passwd;
}
- n = snprint(plain, sizeof(plain), "%s:%s", user ? user : "", pass ? pass : "");
+ fmtstrinit(&fmt);
+ fmtprint(&fmt, "%s:%s", user ? user : "", pass ? pass : "");
if(up){
memset(up->user, 0, strlen(up->user));
memset(up->passwd, 0, strlen(up->passwd));
free(up);
}
- n = enc64(cred, sizeof(cred), (uchar*)plain, n);
- memset(plain, 0, sizeof(plain));
- if(n == -1)
+ if((s = fmtstrflush(&fmt)) == nil)
return -1;
+ n = strlen(s);
fmtstrinit(&fmt);
- fmtprint(&fmt, "Basic %s", cred);
- memset(cred, 0, sizeof(cred));
+ fmtprint(&fmt, "Basic %.*[", n, s);
+ memset(s, 0, n);
+ free(s);
u = saneurl(url(".", u)); /* all uris below the requested one */
}else
if(!cistrncmp(s, "Digest ", 7)){
fmtprint(&fmt, "Digest ");
fmtprint(&fmt, "username=\"%s\", ", ouser);
fmtprint(&fmt, "realm=\"%s\", ", realm);
- fmtprint(&fmt, "host=\"%H\", ", u->host);
+ fmtprint(&fmt, "host=\"%N\", ", u->host);
fmtprint(&fmt, "uri=\"%U\", ", ru);
fmtprint(&fmt, "nonce=\"%s\", ", nonce);
fmtprint(&fmt, "response=\"%s\"", resp);
static void
catch(void *, char *msg)
{
- if(strstr("alarm", msg) || strstr("die", msg))
+ if(strstr("alarm", msg) != nil)
noted(NCONT);
else
noted(NDFLT);
/* http requires ascii encoding of host */
free(host);
- host = smprint("%H", u->host);
+ host = smprint("%N", u->host);
if(proxy && strcmp(u->scheme, "https") != 0){
ru = *u;
}else
h->keep = 0;
if(pid == 0)
- exits(0);
+ exits(nil);
}
/* no timeout when posting */
alarm(0);
goto Error;
if(x = lookkey(shdr, "Proxy-Authorization"))
flushauth(proxy, x);
- if(hauthenticate(u, &ru, method, "Proxy-Authenticate", rhdr) < 0)
+ if(hauthenticate(proxy, proxy, method, "Proxy-Authenticate", rhdr) < 0)
goto Error;
}
case 0: /* No status */
* then the proxy server has established the connection.
*/
if(h->tunnel && !retry && (i/100) == 2){
- if((h->fd = tlswrap(h->fd)) < 0)
+ if((h->fd = tlswrap(h->fd, host)) < 0)
break;
/* proceed to the original request */
shdr = k->next;
free(k);
}
- exits(0);
+ exits(nil);
}