Author: toad
Date: 2007-06-05 00:15:54 +0000 (Tue, 05 Jun 2007)
New Revision: 13470
Modified:
trunk/freenet/src/freenet/node/FNPPacketMangler.java
Log:
Pad message packets (not just auth packets). Round up to next multiple of 64
and then add a random number of bytes 0...63.
Yes this sucks, but not as badly as not padding them at all.
Modified: trunk/freenet/src/freenet/node/FNPPacketMangler.java
===================================================================
--- trunk/freenet/src/freenet/node/FNPPacketMangler.java 2007-06-04
23:19:28 UTC (rev 13469)
+++ trunk/freenet/src/freenet/node/FNPPacketMangler.java 2007-06-05
00:15:54 UTC (rev 13470)
@@ -1245,6 +1245,20 @@
1 + // no forgotten packets
length; // the payload !
+ // Padding
+ // This will do an adequate job of disguising the contents, and a poor
(but not totally
+ // worthless) job of disguising the traffic. FIXME!!!!!
+ // Ideally we'd mimic the size profile - and the session bytes! - of a
common protocol.
+
+ int paddedLen = ((packetLength + 63) / 64) * 64;
+ paddedLen += node.random.nextInt(64);
+ if(packetLength <= 1280 && paddedLen > 1280) paddedLen = 1280;
+
+ byte[] padding = new byte[paddedLen - packetLength];
+ node.random.nextBytes(padding);
+
+ packetLength = paddedLen;
+
if(logMINOR) Logger.minor(this, "Packet length: "+packetLength+"
("+length+")");
byte[] plaintext = new byte[packetLength];
@@ -1354,6 +1368,9 @@
System.arraycopy(buf, offset, plaintext, ptr, length);
ptr += length;
+ System.arraycopy(padding, 0, plaintext, ptr, padding.length);
+ ptr += padding.length;
+
if(ptr != plaintext.length) {
Logger.error(this, "Inconsistent length: "+plaintext.length+"
buffer but "+(ptr)+" actual");
byte[] newBuf = new byte[ptr];