public void TestGarlicCreateMessage() { var dsm1 = new DeliveryStatusMessage(0x425c) { MessageId = 2354 }; var dsm2 = new DeliveryStatusMessage(0x425c) { MessageId = 2354 }; dsm2.Timestamp = dsm1.Timestamp; dsm2.Expiration = dsm1.Expiration; var dsm1h = dsm1.CreateHeader16; var dsm2h = dsm2.CreateHeader16; var dsm1hap = dsm1h.HeaderAndPayload; var dsm2hap = dsm2h.HeaderAndPayload; var st11 = FreenetBase64.Encode(dsm1hap); var st12 = FreenetBase64.Encode(dsm2hap); Assert.IsTrue(dsm1hap == dsm2hap); var gcd1 = new GarlicCloveDeliveryDestination( dsm1, Destination.IdentHash); var gcd2 = new GarlicCloveDeliveryDestination( dsm2, Destination.IdentHash); var gcd1ar = gcd1.ToByteArray(); var gcd2ar = gcd2.ToByteArray(); var st1 = FreenetBase64.Encode(new BufLen(gcd1ar)); var st2 = FreenetBase64.Encode(new BufLen(gcd2ar)); Assert.IsTrue(BufUtils.Equal(gcd1ar, gcd2ar)); var msg1 = new GarlicClove(gcd1); var msg2 = new GarlicClove(gcd2); var g1 = new Garlic(msg1, msg2); var g2 = new Garlic(new BufRefLen(g1.ToByteArray()).Clone()); Assert.IsTrue(BufUtils.Equal(g1.ToByteArray(), g2.ToByteArray())); }
public void TestGarlicCreate() { var ls = new I2PDate(DateTime.Now + TimeSpan.FromMinutes(5)); var origmessage = new DeliveryStatusMessage(I2NPMessage.GenerateMessageId()); var bigmessage = new DataMessage(new BufLen(BufUtils.RandomBytes(14 * 1024))); var garlic = new Garlic( new GarlicClove( new GarlicCloveDeliveryLocal(origmessage), ls), new GarlicClove( new GarlicCloveDeliveryLocal(bigmessage), ls) ); var egmsg = Garlic.EGEncryptGarlic( garlic, Public, new I2PSessionKey(), null); var origegdata = I2NPMessage.Clone(egmsg); var origegdata2 = I2NPMessage.Clone(egmsg); // Decrypt var(aesblock, sessionkey1) = Garlic.EGDecryptGarlic(origegdata, Private); var newgarlic = new Garlic((BufRefLen)aesblock.Payload); var g1 = new BufLen(garlic.ToByteArray()); var g2 = new BufLen(newgarlic.ToByteArray()); Assert.IsTrue(g1 == g2); // Retrieve var(aesblock2, sessionkey2) = Garlic.RetrieveAESBlock(origegdata2, Private, null); newgarlic = new Garlic((BufRefLen)aesblock2.Payload); g1 = new BufLen(garlic.ToByteArray()); g2 = new BufLen(newgarlic.ToByteArray()); Assert.IsTrue(g1 == g2); Assert.IsTrue(sessionkey1 == sessionkey2); }
public void TestEncodeDecodeAES() { var m1 = new DeliveryStatusMessage(0x4321); var m2 = new DeliveryStatusMessage(0xa3c2); var garlic = new Garlic( new GarlicClove( new GarlicCloveDeliveryDestination( m1, Destination.IdentHash)), new GarlicClove( new GarlicCloveDeliveryDestination( m2, Destination.IdentHash)) ); // No tags var sessionkey = new I2PSessionKey(); var sessiontag = new I2PSessionTag(); var cg = Garlic.AESEncryptGarlic(garlic, sessionkey, sessiontag, null); var egdata = I2NPMessage.Clone(cg); var(aesblock, sk) = Garlic.RetrieveAESBlock(egdata, Private, (t) => sessionkey); var g2 = new Garlic((BufRefLen)aesblock.Payload); Assert.IsTrue(BufUtils.Equal(garlic.ToByteArray(), g2.ToByteArray())); // With tags var tags = new List <I2PSessionTag>(); for (int i = 0; i < 30; ++i) { tags.Add(new I2PSessionTag()); } cg = Garlic.AESEncryptGarlic(garlic, sessionkey, sessiontag, null); egdata = I2NPMessage.Clone(cg); (aesblock, sk) = Garlic.RetrieveAESBlock(egdata, Private, (t) => sessionkey); g2 = new Garlic((BufRefLen)aesblock.Payload); Assert.IsTrue(BufUtils.Equal(garlic.ToByteArray(), g2.ToByteArray())); }