From adf56a16e1003b667e8288987a009180f9936513 Mon Sep 17 00:00:00 2001 From: jrandom <jrandom> Date: Wed, 17 Aug 2005 20:16:27 +0000 Subject: [PATCH] 2005-08-17 jrandom * Revise the SSU peer testing protocol so that Bob verifies Charlie's viability before agreeing to Alice's request. This doesn't work with older SSU peer test builds, but is backwards compatible (older nodes won't ask newer nodes to participate in tests, and newer nodes won't ask older nodes to either). --- .../router/transport/udp/PacketBuilder.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java b/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java index 98145dff88..f0bf1ac0ed 100644 --- a/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java +++ b/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java @@ -583,7 +583,51 @@ public class PacketBuilder { setTo(packet, charlieIP, charliePort); return packet; } - + + /** + * Build a packet as if we are Charlie sending Bob a packet verifying that we will help test Alice. + * + * @return ready to send packet, or null if there was a problem + */ + public UDPPacket buildPeerTestToBob(InetAddress bobIP, int bobPort, InetAddress aliceIP, int alicePort, SessionKey aliceIntroKey, long nonce, SessionKey bobCipherKey, SessionKey bobMACKey) { + UDPPacket packet = UDPPacket.acquire(_context); + byte data[] = packet.getPacket().getData(); + Arrays.fill(data, 0, data.length, (byte)0x0); + int off = UDPPacket.MAC_SIZE + UDPPacket.IV_SIZE; + + // header + data[off] = PEER_TEST_FLAG_BYTE; + off++; + long now = _context.clock().now() / 1000; + DataHelper.toLong(data, off, 4, now); + if (_log.shouldLog(Log.DEBUG)) + _log.debug("Sending peer test " + nonce + " to Bob with time = " + new Date(now*1000)); + off += 4; + + // now for the body + DataHelper.toLong(data, off, 4, nonce); + off += 4; + byte ip[] = aliceIP.getAddress(); + DataHelper.toLong(data, off, 1, ip.length); + off++; + System.arraycopy(ip, 0, data, off, ip.length); + off += ip.length; + DataHelper.toLong(data, off, 2, alicePort); + off += 2; + System.arraycopy(aliceIntroKey.getData(), 0, data, off, SessionKey.KEYSIZE_BYTES); + off += SessionKey.KEYSIZE_BYTES; + + // we can pad here if we want, maybe randomized? + + // pad up so we're on the encryption boundary + if ( (off % 16) != 0) + off += 16 - (off % 16); + packet.getPacket().setLength(off); + authenticate(packet, bobCipherKey, bobMACKey); + setTo(packet, bobIP, bobPort); + return packet; + } + private void setTo(UDPPacket packet, InetAddress ip, int port) { packet.getPacket().setAddress(ip); packet.getPacket().setPort(port); -- GitLab