summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authorarindam@chromium.org <arindam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-14 16:49:54 +0000
committerarindam@chromium.org <arindam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-14 16:49:54 +0000
commit41fe98bb5c0955a12d48527308e359ae577f09bc (patch)
tree59e259d9b7abe8d59a288dbd6eddc8aae034c75a /net/http
parent4f26826dc91e9aa41f3adbda05f94c44581eddd8 (diff)
downloadchromium_src-41fe98bb5c0955a12d48527308e359ae577f09bc.zip
chromium_src-41fe98bb5c0955a12d48527308e359ae577f09bc.tar.gz
chromium_src-41fe98bb5c0955a12d48527308e359ae577f09bc.tar.bz2
SOCKS v5 implementation
The implementation is incomplete as it does not support any authentication methods and does not have a UDP layer. BUG=469 TEST=unittests (included) Review URL: http://codereview.chromium.org/150187 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20626 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_network_transaction.cc14
-rw-r--r--net/http/http_network_transaction_unittest.cc132
2 files changed, 137 insertions, 9 deletions
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index ca3547c..f705541 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -26,6 +26,7 @@
#include "net/http/http_response_headers.h"
#include "net/http/http_util.h"
#include "net/socket/client_socket_factory.h"
+#include "net/socket/socks5_client_socket.h"
#include "net/socket/socks_client_socket.h"
#include "net/socket/ssl_client_socket.h"
@@ -336,7 +337,7 @@ int HttpNetworkTransaction::Read(IOBuffer* buf, int buf_len,
CompletionCallback* callback) {
DCHECK(response_.headers);
DCHECK(buf);
- DCHECK(buf_len > 0);
+ DCHECK_LT(0, buf_len);
if (!connection_.is_initialized())
return 0; // connection_ has been reset. Treat like EOF.
@@ -349,7 +350,7 @@ int HttpNetworkTransaction::Read(IOBuffer* buf, int buf_len,
// network attacker can already control HTTP sessions.
// We reach this case when the user cancels a 407 proxy auth prompt.
// See http://crbug.com/8473
- DCHECK(response_.headers->response_code() == 407);
+ DCHECK_EQ(407, response_.headers->response_code());
LogBlockedTunnelResponse(response_.headers->response_code());
return ERR_TUNNEL_CONNECTION_FAILED;
}
@@ -545,10 +546,10 @@ int HttpNetworkTransaction::DoResolveProxy() {
int HttpNetworkTransaction::DoResolveProxyComplete(int result) {
next_state_ = STATE_INIT_CONNECTION;
- // Remove unsupported proxies (like SOCKS5) from the list.
+ // Remove unsupported proxies from the list.
proxy_info_.RemoveProxiesWithoutScheme(
ProxyServer::SCHEME_DIRECT | ProxyServer::SCHEME_HTTP |
- ProxyServer::SCHEME_SOCKS4);
+ ProxyServer::SCHEME_SOCKS4 | ProxyServer::SCHEME_SOCKS5);
pac_request_ = NULL;
@@ -662,7 +663,10 @@ int HttpNetworkTransaction::DoSOCKSConnect() {
request_->url.EffectiveIntPort());
req_info.set_referrer(request_->referrer);
- s = new SOCKSClientSocket(s, req_info, session_->host_resolver());
+ if (proxy_info_.proxy_server().scheme() == ProxyServer::SCHEME_SOCKS5)
+ s = new SOCKS5ClientSocket(s, req_info, session_->host_resolver());
+ else
+ s = new SOCKSClientSocket(s, req_info, session_->host_resolver());
connection_.set_socket(s);
return connection_.socket()->Connect(&io_callback_);
}
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index bcb22a9..74764a5 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -3065,14 +3065,14 @@ TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) {
char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
MockWrite data_writes[] = {
- MockWrite(true, write_buffer, 9),
+ MockWrite(true, write_buffer, arraysize(write_buffer)),
MockWrite("GET / HTTP/1.1\r\n"
"Host: www.google.com\r\n"
"Connection: keep-alive\r\n\r\n")
};
MockRead data_reads[] = {
- MockWrite(true, read_buffer, 8),
+ MockWrite(true, read_buffer, arraysize(read_buffer)),
MockRead("HTTP/1.0 200 OK\r\n"),
MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
MockRead("Payload"),
@@ -3118,14 +3118,138 @@ TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) {
unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 };
MockWrite data_writes[] = {
- MockWrite(true, reinterpret_cast<char*>(write_buffer), 9),
+ MockWrite(true, reinterpret_cast<char*>(write_buffer),
+ arraysize(write_buffer)),
MockWrite("GET / HTTP/1.1\r\n"
"Host: www.google.com\r\n"
"Connection: keep-alive\r\n\r\n")
};
MockRead data_reads[] = {
- MockWrite(true, reinterpret_cast<char*>(read_buffer), 8),
+ MockWrite(true, reinterpret_cast<char*>(read_buffer),
+ arraysize(read_buffer)),
+ MockRead("HTTP/1.0 200 OK\r\n"),
+ MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
+ MockRead("Payload"),
+ MockRead(false, OK)
+ };
+
+ StaticMockSocket data(data_reads, data_writes);
+ session_deps.socket_factory.AddMockSocket(&data);
+
+ MockSSLSocket ssl(true, OK);
+ session_deps.socket_factory.AddMockSSLSocket(&ssl);
+
+ TestCompletionCallback callback;
+
+ int rv = trans->Start(&request, &callback);
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+
+ rv = callback.WaitForResult();
+ EXPECT_EQ(OK, rv);
+
+ const HttpResponseInfo* response = trans->GetResponseInfo();
+ EXPECT_FALSE(response == NULL);
+
+ std::string response_text;
+ rv = ReadTransaction(trans.get(), &response_text);
+ EXPECT_EQ(OK, rv);
+ EXPECT_EQ("Payload", response_text);
+}
+
+TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) {
+ SessionDependencies session_deps;
+ session_deps.proxy_service.reset(CreateFixedProxyService(
+ "socks5://myproxy:1080"));
+
+ scoped_ptr<HttpTransaction> trans(
+ new HttpNetworkTransaction(
+ CreateSession(&session_deps),
+ &session_deps.socket_factory));
+
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("http://www.google.com/");
+ request.load_flags = 0;
+
+ const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 };
+ const char kSOCKS5GreetResponse[] = { 0x05, 0x00 };
+ const char kSOCKS5OkRequest[] =
+ { 0x05, 0x01, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 };
+ const char kSOCKS5OkResponse[] =
+ { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 };
+
+ MockWrite data_writes[] = {
+ MockWrite(true, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)),
+ MockWrite(true, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)),
+ MockWrite("GET / HTTP/1.1\r\n"
+ "Host: www.google.com\r\n"
+ "Connection: keep-alive\r\n\r\n")
+ };
+
+ MockRead data_reads[] = {
+ MockWrite(true, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)),
+ MockWrite(true, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)),
+ MockRead("HTTP/1.0 200 OK\r\n"),
+ MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
+ MockRead("Payload"),
+ MockRead(false, OK)
+ };
+
+ StaticMockSocket data(data_reads, data_writes);
+ session_deps.socket_factory.AddMockSocket(&data);
+
+ TestCompletionCallback callback;
+
+ int rv = trans->Start(&request, &callback);
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+
+ rv = callback.WaitForResult();
+ EXPECT_EQ(OK, rv);
+
+ const HttpResponseInfo* response = trans->GetResponseInfo();
+ EXPECT_FALSE(response == NULL);
+
+ std::string response_text;
+ rv = ReadTransaction(trans.get(), &response_text);
+ EXPECT_EQ(OK, rv);
+ EXPECT_EQ("Payload", response_text);
+}
+
+TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) {
+ SessionDependencies session_deps;
+ session_deps.proxy_service.reset(CreateFixedProxyService(
+ "socks5://myproxy:1080"));
+
+ scoped_ptr<HttpTransaction> trans(
+ new HttpNetworkTransaction(
+ CreateSession(&session_deps),
+ &session_deps.socket_factory));
+
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("https://www.google.com/");
+ request.load_flags = 0;
+
+ const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 };
+ const char kSOCKS5GreetResponse[] = { 0x05, 0x00 };
+ const unsigned char kSOCKS5OkRequest[] =
+ { 0x05, 0x01, 0x00, 0x01, 127, 0, 0, 1, 0x01, 0xBB };
+ const char kSOCKS5OkResponse[] =
+ { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 };
+
+ MockWrite data_writes[] = {
+ MockWrite(true, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)),
+ MockWrite(true, reinterpret_cast<const char*>(kSOCKS5OkRequest),
+ arraysize(kSOCKS5OkRequest)),
+ MockWrite("GET / HTTP/1.1\r\n"
+ "Host: www.google.com\r\n"
+ "Connection: keep-alive\r\n\r\n")
+ };
+
+ MockRead data_reads[] = {
+ MockWrite(true, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)),
+ MockWrite(true, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)),
MockRead("HTTP/1.0 200 OK\r\n"),
MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"),
MockRead("Payload"),