--- ReplayClient/ReplayConnection.java.~1.7.~ Mon Jun 17 16:53:19 2002 +++ ReplayClient/ReplayConnection.java Tue Jun 18 21:42:02 2002 @@ -34,6 +34,7 @@ import java.net.*; import java.io.*; import java.util.*; +import java.security.*; import swapdv.Logger.*; import swapdv.ReplayGuide.*; import swapdv.ReplayServer.*; @@ -88,10 +89,95 @@ Logger.log(c.chan, LoggerI.LEVEL_DEBUG, "Sent HTTP headers"); try { os.flush(); } catch (Exception ex) {} } + + protected String encryptString(String s) { + int length = s.length()+32; + byte[] cbuf = new byte[length]; + int key = 0; // "should" be random + int obfusc = 0; // "should" be random + int t = (int)(new Date().getTime()/1000); + + cbuf[0] = 0; // obfusc[3] + cbuf[1] = (byte)0xaf; // (key ^ 0xcb0baf47)[2] + cbuf[2] = (byte)0xcb; // (key ^ 0xcb0baf47)[0] + cbuf[3] = 0; // obfusc[2] + cbuf[4] = (byte)0x0b; // (key ^ 0xcb0baf47)[1] + cbuf[5] = 0; + cbuf[6] = 0; + cbuf[7] = (byte)0x47; // (key ^ 0xcb0baf47)[3] + + cbuf[24] = (byte)0x42; + cbuf[25] = (byte)0xff; + cbuf[26] = (byte)0xdf; + cbuf[27] = (byte)0xa9; + + cbuf[28] = (byte)((t >> 24) & 0xff); + cbuf[29] = (byte)((t >> 16) & 0xff); + cbuf[30] = (byte)((t >> 8) & 0xff); + cbuf[31] = (byte)(t & 0xff); + + for (int i = 0; i < s.length(); i++) { + cbuf[i+32] = (byte)s.charAt(i); + } + + for (int i = 24; i < length; i++) { + key = key * 0xb8f7 + 0x15bb9; + cbuf[i] ^= key; + } + + MessageDigest md5; + + try { + md5 = MessageDigest.getInstance("Md5"); + } + catch (Exception ex) { + Logger.log(c.chan, LoggerI.LEVEL_DEBUG, "Exception while getting md5: " + ex.getMessage()); + return null; + } + + md5.update(cbuf, 24, length-24); + byte[] extradata = { (byte)0xda,(byte)0x76,(byte)0x5c,(byte)0xd4, (byte)0x34,(byte)0xc3,(byte)0xd7,(byte)0x2c, + (byte)0xac,(byte)0x40,(byte)0xb8,(byte)0xd8, (byte)0x59,(byte)0xbc,(byte)0x59,(byte)0x34, + (byte)0xaa,(byte)0xbf,(byte)0x89,(byte)0xbd, (byte)0x85,(byte)0xe8,(byte)0x40,(byte)0x27, + (byte)0x78,(byte)0x2b,(byte)0x18,(byte)0x6e, (byte)0xa6,(byte)0x6e,(byte)0x5a,(byte)0xc6, + (byte)0xda,(byte)0xe3,(byte)0x86,(byte)0x84, (byte)0x40,(byte)0x14,(byte)0x2a,(byte)0x23, + (byte)0x4f,(byte)0x5d,(byte)0x38,(byte)0x5e, (byte)0x7f,(byte)0xd9,(byte)0x73,(byte)0x7d, + (byte)0xe4,(byte)0x80,(byte)0x3d,(byte)0x21, (byte)0x28,(byte)0x41,(byte)0xf1,(byte)0xb2, + (byte)0x96,(byte)0x43,(byte)0x2b,(byte)0xcc, (byte)0x0c,(byte)0x9d,(byte)0x26,(byte)0xb9, + }; + md5.update(extradata); + byte[] digest = md5.digest(); + for (int i = 0; i < 16; i++) { + cbuf[i+8] = digest[i]; + } + + String r = ""; + for (int i = 0; i < length; i++) { + char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' + }; + + r += digits[(cbuf[i]>>4) & 0xf]; + r += digits[cbuf[i] & 0xf]; + } + + Logger.log(c.chan, LoggerI.LEVEL_DEBUG, "Encrypted to " + r); + + return r; + } protected void writeRequest(String req) { + int queryStart = req.indexOf((int)'?'); + if (queryStart >= 0 && req.indexOf("/Video") >= 0) { + req = req.substring(0, queryStart) + "?__Q_=" + + encryptString(req.substring(queryStart+1)); + Logger.log(c.chan, LoggerI.LEVEL_DEBUG, "Encrypted"); + } else { + Logger.log(c.chan, LoggerI.LEVEL_DEBUG, "No query to encrypt"); + } + httpLine("GET http://"+c.ipAddr+":"+c.port+"/"+req+" HTTP/1.1"); - Logger.log(c.chan, LoggerI.LEVEL_DEBUG, "Sent HTTP request"); + Logger.log(c.chan, LoggerI.LEVEL_DEBUG, "Sent HTTP request: " + req); } protected void processHeader() { @@ -232,4 +318,4 @@ try {is.close();} catch (Exception ex) {} s = null; } -} \ No newline at end of file +} --- ReplayServer/HttpRequest.java.~1.6.~ Wed Jun 12 15:16:13 2002 +++ ReplayServer/HttpRequest.java Tue Jun 18 21:44:49 2002 @@ -132,6 +132,27 @@ throw e; } } + + private String decryptString(String s) { + char[] asascii = s.toCharArray(); + int length = s.length()/2; + byte[] bytes = new byte[length]; + for (int i = 0; i < length; i++) { + bytes[i] = (byte)Integer.parseInt(s.substring(i*2, i*2+2),16); + } + int key = ((bytes[2] << 24) | (bytes[4] << 16) | + (bytes[1] << 8) | bytes[7]) ^ 0xcb0baf47; + + String r = new String(); + for (int i = 24; i < length; i++) { + key = key * 0xb8f7 + 0x15bb9; + bytes[i] ^= key; + if (i >= 32) + r += (char) bytes[i]; + } + Logger.log(0, LoggerI.LEVEL_DEBUG, "Decrypted to :"+r+":"); + return r; + } private Properties decodeString(String s) { String pair, name,value; @@ -151,6 +172,10 @@ //Logger.log(0, LoggerI.LEVEL_DEBUG, "decodeString: adding pair " + name +" = "+ value); name = decode(name); value = decode(value); + if (name.compareTo("__Q_") == 0) { + return decodeString(decryptString(value)); + } + p.put(name,value); } return p;