public void testSequenceNumberEncryption() { BlockCipher ivCipher = new Rijndael(); ivCipher.initialize(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); byte[] ivNonce = new byte[16]; BlockCipher incommingCipher = new Rijndael(); incommingCipher.initialize(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); SessionKey sessionKey = new SessionKey(null, null, null, incommingCipher, null, ivCipher, ivNonce, null, null, -1); byte[] encrypted = NewPacketFormat.encryptSequenceNumber(0, sessionKey); /* This result has not been checked, but it was the output when * this test was added and we are (in this test) only * interested in making sure the output doesn't change. */ byte[] correct = new byte[] {(byte) 0xF7, (byte) 0x95, (byte) 0xBD, (byte) 0x4A}; assertTrue(Arrays.equals(correct, encrypted)); }
assertTrue(Arrays.equals(message, copyOfMessage)); assertTrue(Arrays.equals(message, receiverNode.decryptedMessages.get(0)));
public void testLoadStatsLowLevel() throws BlockedTooLongException, InterruptedException { final byte[] loadMessage = new byte[] { (byte)0xFF, (byte)0xEE, (byte)0xDD, (byte)0xCC, (byte)0xBB, (byte)0xAA}; final SessionKey senderKey = new SessionKey(null, null, null, null, null, null, null, null, new NewPacketFormatKeyContext(0, 0), 1); NullBasePeerNode senderNode = new NullBasePeerNode() { @Override public MessageItem makeLoadStats(boolean realtime, boolean highPriority, boolean noRemember) { return new MessageItem(loadMessage, null, false, null, (short) 0, false, false); } @Override public SessionKey getCurrentKeyTracker() { return senderKey; } }; NewPacketFormat sender = new NewPacketFormat(senderNode, 0, 0); PeerMessageQueue senderQueue = new PeerMessageQueue(); senderQueue.queueAndEstimateSize(new MessageItem(new byte[128], null, false, null, (short) 0, false, true), 1024); Thread.sleep(PacketSender.MAX_COALESCING_DELAY*2); NPFPacket packet1 = sender.createPacket(512, senderQueue, senderKey, false); assertTrue(packet1 != null); assertEquals(1, packet1.getFragments().size()); assertEquals(1, packet1.getLossyMessages().size()); NPFPacketTest.checkEquals(loadMessage, packet1.getLossyMessages().get(0)); // Don't decode the packet because it's not a real message. }