diff options
author | Roger Dingledine <arma@torproject.org> | 2005-04-26 18:33:33 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2005-04-26 18:33:33 +0000 |
commit | 5e86e87124e643108c827366daac878e708d935d (patch) | |
tree | 9b7f3e77b257c52c77324c58fcb9624385c74319 /src/or/connection_or.c | |
parent | 95a01599ae2e7c2006f3bdae7da34e4cdb95b4f8 (diff) | |
download | tor-5e86e87124e643108c827366daac878e708d935d.tar.gz tor-5e86e87124e643108c827366daac878e708d935d.zip |
Add basic HttpsProxyAuthenticator support, based on patch
from Adam Langley.
svn:r4115
Diffstat (limited to 'src/or/connection_or.c')
-rw-r--r-- | src/or/connection_or.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/or/connection_or.c b/src/or/connection_or.c index 461ca96922..aa8dc0abe6 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -171,11 +171,35 @@ int connection_or_finished_connecting(connection_t *conn) char buf[1024]; char addrbuf[INET_NTOA_BUF_LEN]; struct in_addr in; + const char *authenticator = get_options()->HttpsProxyAuthenticator; in.s_addr = htonl(conn->addr); tor_inet_ntoa(&in, addrbuf, sizeof(addrbuf)); - tor_snprintf(buf, sizeof(buf), "CONNECT %s:%d HTTP/1.0\r\n\r\n", - addrbuf, conn->port); + + if (authenticator) { + /* an authenticator in Basic authentication + * is just the string "username:password" */ + const int authenticator_length = strlen(authenticator); + /* The base64_encode function needs a minimum buffer length + * of 66 bytes. */ + const int base64_authenticator_length = (authenticator_length/48+1)*66; + char *base64_authenticator = tor_malloc(base64_authenticator_length); + if (base64_encode(base64_authenticator, base64_authenticator_length, + authenticator, authenticator_length) < 0) { + log_fn(LOG_WARN, "Encoding authenticator failed"); + base64_authenticator[0] = 0; + } else { + /* remove extra \n at end of encoding */ + base64_authenticator[strlen(base64_authenticator) - 1] = 0; + } + tor_snprintf(buf, sizeof(buf), "CONNECT %s:%d HTTP/1.1\r\n" + "Proxy-Authorization: Basic %s\r\n\r\n", addrbuf, + conn->port, base64_authenticator); + tor_free(base64_authenticator); + } else { + tor_snprintf(buf, sizeof(buf), "CONNECT %s:%d HTTP/1.0\r\n\r\n", + addrbuf, conn->port); + } connection_write_to_buf(buf, strlen(buf), conn); conn->state = OR_CONN_STATE_PROXY_FLUSHING; return 0; |