2005-03-18 jrandom

* Eepproxy Fix for corrupted HTTP headers (thanks nickster!)
    * Fixed case sensitivity issues on the HTTP headers (thanks duck!)
This commit is contained in:
jrandom
2005-03-18 08:48:00 +00:00
committed by zzz
parent a997a46040
commit 89509490c5
4 changed files with 54 additions and 28 deletions

View File

@ -123,13 +123,17 @@ class HTTPResponseOutputStream extends FilterOutputStream {
} else { } else {
for (int j = lastEnd+1; j < i; j++) { for (int j = lastEnd+1; j < i; j++) {
if (_headerBuffer.getData()[j] == ':') { if (_headerBuffer.getData()[j] == ':') {
String key = new String(_headerBuffer.getData(), lastEnd+1, j-(lastEnd+1)); int keyLen = j-(lastEnd+1);
String val = new String(_headerBuffer.getData(), j+2, i-(j+2)); int valLen = i-(j+2);
if ( (keyLen <= 0) || (valLen <= 0) )
throw new IOException("Invalid header @ " + j);
String key = new String(_headerBuffer.getData(), lastEnd+1, keyLen);
String val = new String(_headerBuffer.getData(), j+2, valLen);
if ("Connection".equals(key)) { if ("Connection".equalsIgnoreCase(key)) {
out.write("Connection: close\n".getBytes()); out.write("Connection: close\n".getBytes());
connectionSent = true; connectionSent = true;
} else if ("Proxy-Connection".equals(key)) { } else if ("Proxy-Connection".equalsIgnoreCase(key)) {
out.write("Proxy-Connection: close\n".getBytes()); out.write("Proxy-Connection: close\n".getBytes());
proxyConnectionSent = true; proxyConnectionSent = true;
} else { } else {
@ -185,6 +189,17 @@ class HTTPResponseOutputStream extends FilterOutputStream {
String invalid2 = "HTTP/1.1 200 OK"; String invalid2 = "HTTP/1.1 200 OK";
String invalid3 = "HTTP 200 OK\r\n"; String invalid3 = "HTTP 200 OK\r\n";
String invalid4 = "HTTP 200 OK\r"; String invalid4 = "HTTP 200 OK\r";
String invalid5 = "HTTP/1.1 200 OK\r\n" +
"I am broken, and I smell\r\n" +
"\r\n";
String invalid6 = "HTTP/1.1 200 OK\r\n" +
":I am broken, and I smell\r\n" +
"\r\n";
String invalid7 = "HTTP/1.1 200 OK\n" +
"I am broken, and I smell:\n" +
":asdf\n" +
":\n" +
"\n";
String large = "HTTP/1.1 200 OK\n" + String large = "HTTP/1.1 200 OK\n" +
"Last-modified: Tue, 25 Nov 2003 12:05:38 GMT\n" + "Last-modified: Tue, 25 Nov 2003 12:05:38 GMT\n" +
"Expires: Tue, 25 Nov 2003 12:05:38 GMT\n" + "Expires: Tue, 25 Nov 2003 12:05:38 GMT\n" +
@ -192,20 +207,23 @@ class HTTPResponseOutputStream extends FilterOutputStream {
"\n" + "\n" +
"hi ho, this is the body"; "hi ho, this is the body";
/* */ /* */
test("Simple", simple); test("Simple", simple, true);
test("Filtered", filtered); test("Filtered", filtered, true);
test("Filtered windows", winfilter); test("Filtered windows", winfilter, true);
test("Minimal", minimal); test("Minimal", minimal, true);
test("Windows", winmin); test("Windows", winmin, true);
test("Large", large); test("Large", large, true);
test("Invalid (short headers)", invalid1); test("Invalid (short headers)", invalid1, true);
test("Invalid (no headers)", invalid2); test("Invalid (no headers)", invalid2, true);
test("Invalid (windows with short headers)", invalid3); test("Invalid (windows with short headers)", invalid3, true);
test("Invalid (windows no headers)", invalid4); test("Invalid (windows no headers)", invalid4, true);
test("Invalid (bad headers)", invalid5, true);
test("Invalid (bad headers2)", invalid6, false);
test("Invalid (bad headers3)", invalid7, false);
/* */ /* */
} }
private static void test(String name, String orig) { private static void test(String name, String orig, boolean shouldPass) {
System.out.println("====Testing: " + name + "\n" + orig + "\n------------"); System.out.println("====Testing: " + name + "\n" + orig + "\n------------");
try { try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096); ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
@ -215,7 +233,10 @@ class HTTPResponseOutputStream extends FilterOutputStream {
String received = new String(baos.toByteArray()); String received = new String(baos.toByteArray());
System.out.println(received); System.out.println(received);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); if (shouldPass)
e.printStackTrace();
else
System.out.println("Properly fails with " + e.getMessage());
} }
} }
} }

View File

@ -194,9 +194,10 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug(getPrefix(requestId) + "Line=[" + line + "]"); _log.debug(getPrefix(requestId) + "Line=[" + line + "]");
if (line.startsWith("Connection: ") || String lowercaseLine = line.toLowerCase();
line.startsWith("Keep-Alive: ") || if (lowercaseLine.startsWith("connection: ") ||
line.startsWith("Proxy-Connection: ")) lowercaseLine.startsWith("keep-alive: ") ||
lowercaseLine.startsWith("proxy-connection: "))
continue; continue;
if (method == null) { // first line (GET /base64/realaddr) if (method == null) { // first line (GET /base64/realaddr)
@ -335,29 +336,29 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable
} }
} else { } else {
if (line.startsWith("Host: ") && !usingWWWProxy) { if (lowercaseLine.startsWith("host: ") && !usingWWWProxy) {
line = "Host: " + host; line = "Host: " + host;
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info(getPrefix(requestId) + "Setting host = " + host); _log.info(getPrefix(requestId) + "Setting host = " + host);
} else if (line.startsWith("User-Agent: ")) { } else if (lowercaseLine.startsWith("user-agent: ")) {
// always stripped, added back at the end // always stripped, added back at the end
line = null; line = null;
continue; continue;
} else if (line.startsWith("Accept")) { } else if (lowercaseLine.startsWith("accept")) {
// strip the accept-blah headers, as they vary dramatically from // strip the accept-blah headers, as they vary dramatically from
// browser to browser // browser to browser
line = null; line = null;
continue; continue;
} else if (line.startsWith("Referer: ")) { } else if (lowercaseLine.startsWith("referer: ")) {
// Shouldn't we be more specific, like accepting in-site referers ? // Shouldn't we be more specific, like accepting in-site referers ?
//line = "Referer: i2p"; //line = "Referer: i2p";
line = null; line = null;
continue; // completely strip the line continue; // completely strip the line
} else if (line.startsWith("Via: ")) { } else if (lowercaseLine.startsWith("via: ")) {
//line = "Via: i2p"; //line = "Via: i2p";
line = null; line = null;
continue; // completely strip the line continue; // completely strip the line
} else if (line.startsWith("From: ")) { } else if (lowercaseLine.startsWith("from: ")) {
//line = "From: i2p"; //line = "From: i2p";
line = null; line = null;
continue; // completely strip the line continue; // completely strip the line

View File

@ -1,4 +1,8 @@
$Id: history.txt,v 1.170 2005/03/17 00:29:55 jrandom Exp $ $Id: history.txt,v 1.171 2005/03/17 17:14:31 jrandom Exp $
2005-03-18 jrandom
* Eepproxy Fix for corrupted HTTP headers (thanks nickster!)
* Fixed case sensitivity issues on the HTTP headers (thanks duck!)
2005-03-17 jrandom 2005-03-17 jrandom
* Update the old speed calculator and associated profile data points to * Update the old speed calculator and associated profile data points to

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
* *
*/ */
public class RouterVersion { public class RouterVersion {
public final static String ID = "$Revision: 1.164 $ $Date: 2005/03/17 00:29:55 $"; public final static String ID = "$Revision: 1.165 $ $Date: 2005/03/17 17:12:53 $";
public final static String VERSION = "0.5.0.2"; public final static String VERSION = "0.5.0.2";
public final static long BUILD = 5; public final static long BUILD = 6;
public static void main(String args[]) { public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION); System.out.println("I2P Router version: " + VERSION);
System.out.println("Router ID: " + RouterVersion.ID); System.out.println("Router ID: " + RouterVersion.ID);