From e4edc59689cee2ad15c02d901952a04dd28e49c4 Mon Sep 17 00:00:00 2001 From: hagen Date: Sat, 4 Jun 2016 00:00:00 +0000 Subject: [PATCH 1/5] * HTTPProxy.cpp : force clean recv buffer (#508) --- HTTPProxy.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index 934dbbf5..0d305a47 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -224,8 +224,10 @@ namespace proxy { return; } - if (HandleRequest(len)) + if (HandleRequest(len)) { + m_recv_buf.clear(); return; /* request processed */ + } AsyncSockRead(); } From 66c301c03109088dc7b44f5708fa50b58440cdb6 Mon Sep 17 00:00:00 2001 From: hagen Date: Sat, 4 Jun 2016 00:00:00 +0000 Subject: [PATCH 2/5] * HTTPProxy.cpp : allow "tranparent" proxy (#508) --- HTTPProxy.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index 0d305a47..e8926dc6 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -192,9 +192,28 @@ namespace proxy { std::string dest_host = url.host; uint16_t dest_port = url.port; - /* convert proxy-style http req to ordinary one: */ - /* 1) replace Host header, 2) make relative url */ - req.add_header("Host", url.host, true); + /* set proper 'Host' header in upstream request */ + auto h = req.headers.find("Host"); + if (dest_host != "") { + /* absolute url, replace 'Host' header */ + std::string h = dest_host; + if (dest_port != 0 && dest_port != 80) + h += ":" + std::to_string(dest_port); + req.add_header("Host", h, true); + } else if (h != req.headers.end()) { + /* relative url and 'Host' header provided. transparent proxy mode? */ + i2p::http::URL u; + std::string t = "http://" + h->second; + u.parse(t); + dest_host = u.host; + dest_port = u.port; + } else { + /* relative url and missing 'Host' header */ + std::string message = "Can't detect destination host from request"; + HTTPRequestFailed(message.c_str()); + return true; + } + /* make relative url */ url.schema = ""; url.host = ""; req.uri = url.to_string(); From 03973cc6d4fa6cf17681b5a7f514bc8a8d781368 Mon Sep 17 00:00:00 2001 From: hagen Date: Sat, 4 Jun 2016 00:00:00 +0000 Subject: [PATCH 3/5] * HTTPProxy.cpp : drop X-Forwarded-*, Proxy-*, Via headers from request --- HTTPProxy.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index e8926dc6..a2bc4828 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -137,8 +137,24 @@ namespace proxy { void HTTPReqHandler::SanitizeHTTPRequest(i2p::http::HTTPReq & req) { req.del_header("Referer"); - req.add_header("Connection", "close", true); - req.add_header("User-Agent", "MYOB/6.66 (AN/ON)", true); + req.del_header("Via"); + req.del_header("Forwarded"); + std::vector toErase; + for (auto it : req.headers) { + if (it.first.compare(0, 12, "X-Forwarded-")) { + toErase.push_back(it.first); + } else if (it.first.compare(0, 6, "Proxy-")) { + toErase.push_back(it.first); + } else { + /* allow this header */ + } + } + for (auto header : toErase) { + req.headers.erase(header); + } + /* replace headers */ + req.add_header("Connection", "close", true); /* keep-alive conns not supported yet */ + req.add_header("User-Agent", "MYOB/6.66 (AN/ON)", true); /* privacy */ } /** From a4dc67cba0b85e266b69778fa27a84618bca39bf Mon Sep 17 00:00:00 2001 From: hagen Date: Sat, 4 Jun 2016 00:00:00 +0000 Subject: [PATCH 4/5] * HTTP.{cpp,h} : drop HTTPReq.host --- HTTP.cpp | 9 --------- HTTP.h | 1 - 2 files changed, 10 deletions(-) diff --git a/HTTP.cpp b/HTTP.cpp index ee1010ec..a23f5a72 100644 --- a/HTTP.cpp +++ b/HTTP.cpp @@ -253,21 +253,12 @@ namespace http { if (pos >= eoh) break; } - auto it = headers.find("Host"); - if (it != headers.end ()) { - host = it->second; - } else if (version == "HTTP/1.1") { - return -1; /* 'Host' header required for HTTP/1.1 */ - } else if (url.host != "") { - host = url.host; - } return eoh + strlen(HTTP_EOH); } std::string HTTPReq::to_string() { std::stringstream ss; ss << method << " " << uri << " " << version << CRLF; - ss << "Host: " << host << CRLF; for (auto & h : headers) { ss << h.first << ": " << h.second << CRLF; } diff --git a/HTTP.h b/HTTP.h index 8d10c231..19d0612e 100644 --- a/HTTP.h +++ b/HTTP.h @@ -69,7 +69,6 @@ namespace http { std::string version; std::string method; std::string uri; - std::string host; HTTPReq (): version("HTTP/1.0"), method("GET"), uri("/") {}; From 4d7c089b099fbc7b3a4db58b215fab136fd7de16 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 5 Jun 2016 10:31:55 -0400 Subject: [PATCH 5/5] I2CP config --- docs/configuration.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index 11e8b4a8..9ab85b46 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -58,7 +58,11 @@ All options below still possible in cmdline, but better write it in config file: * --bob.address= - The address to listen on (BOB command channel) * --bob.port= - Port of BOB command channel. Usually 2827. BOB is off if not specified -* --sam.enabled= - If BOB is enabled. false by default +* --bob.enabled= - If BOB is enabled. false by default + +* --i2cp.address= - The address to listen on +* --i2cp.port= - Port of I2CP server. Usually 7654. IPCP is off if not specified +* --i2cp.enabled= - If I2CP is enabled. false by default. Other services don't requeire I2CP * --i2pcontrol.address= - The address to listen on (I2P control service) * --i2pcontrol.port= - Port of I2P control service. Usually 7650. I2PControl is off if not specified