Search in sources :

Example 11 with EncryptedEmailPacket

use of i2p.bote.packet.dht.EncryptedEmailPacket in project i2p.i2p-bote by i2p.

the class EmailPacketFolderTest method testProcessDeleteRequest.

/**
 * Tests creation of delete records when processing {@link EmailPacketDeleteRequest}s,
 * and matching them against email packets.
 */
@Test
public void testProcessDeleteRequest() throws GeneralSecurityException, InvalidCipherTextException, MalformedPacketException, PasswordException {
    // create two packets whose base64 DHT keys start with the same two characters
    byte[] emailPkt1Data = Base64.decode("RQTAJHelC-wnxq-OUAnfgqgN84zTCimrfUKw7AgDPHblcwAAAADUk24QY3EPEzk0UmB5PYQxwnEVIWGZkWJ-5ERh30l95QMA0gIs-itszDaiCa4ucekxDL6pZCVMTnI~S0nBx2FQ5Fl4-T50bNojkgJiQZNFB-vwQ4ChB~hxYIomMtbN6tiNDVwYRKjeZHbL3MAffKcwxwF3iPMl8aLLBaU6LxQ~3r7tgTiccHE39Ozm88~Hrf7H-5hWXzTXwm7j1pNJA7hc-wCL3BwngRl8KUsqsII2-PTMI34-a3RfpzMf2cKlY0NVayoW1UxC4dLvtSz-HoLYPMGIMf5zQghPS2PuZaRAKa5oa3PdYJrhvNXCJWpYCL~FynwShQ==");
    byte[] emailPkt2Data = Base64.decode("RQTAJPXENHAvW18uRITLC8n~D0Npd0RwI1e~9IR8QN~BSwAAAAAD9RT-PXacKIest9~E2SzsR5dAlaoh-ZZVcFNcsQbGQwECkgCFnuT5N210f4SbS4pjPeh~hk9hvpEGCEXzOmPfSEeSWhrE5oiQuJI6fet1zrwZfbA6Iqvl-PoLgv5nKU~I7Nlu1f9UXuve2cvQOmTGDlHdzpwd3nTyJCR2bqG4SFPlnaDpa7yDOmH~e8LKBw1YTYSHSyVun7XuijyCcWGKRbSm3tFU382JSSqUQ2APwbHPtPG6akYO5iSq7XMvlBSyLsDHM5wDbaptxEUmnW20x3fVsK-0BNsIXFK-JJVQ12NApVanGaOsyDRh8l-geRWBcYpX7J~RI1A3ZKRBRJj2wgBc6TdAG0-jiI4OfpKZMr2NZ-ugg2-phU9OgY5ZbtBZjlbtADDYlxT~GHvXkCQLwRg4fsxTk9HoshfoWea-4RE1YmwRT96uKRy0SjcUduOPCsI6nEwm1p-5lzGFzcVTTXZyARRzRrhvtAJw616o3RoAj7vGHY~1POJ26m3UBUIXjh2fA7b5HTFARw9VfZYuz9zzT7UjtuPVIgBu-HyX5zBgSrCDhykGqggaVbURCaS2B6BZt8ikU0ponchHkVZzqX2UeT4T1Pd3fyc1fXp1xVInrYWUZvjSoBcJaiqlhvTMMsjzLbiG~a~HoJz67Dvl6GGtcBad1hjhSzwKN9vLpM-sFMqDCBDHDssVZEXk5EXQYltUZVvfaFJYimDfdiM~F23x0Wz2tM5LQXJ86-nn7d5DA-CspMg1xqkAr1iMkgYacOL~2u2PL1ImI1SMZGmY839ekgQlr1gWWU1evQQTUdHH6Bszs0vSW6wymbSTziJopMqv86f2y6SHDEq8qZzYdKhAFQbjFtvNwn7gEJqlhzzI1bO8zjG3xZTiaCpSrmE98L8PZhEIfXvN3PUADSuzsbHmuHQ=");
    EncryptedEmailPacket emailPacket1 = new EncryptedEmailPacket(emailPkt1Data);
    EncryptedEmailPacket emailPacket2 = new EncryptedEmailPacket(emailPkt2Data);
    // matches emailPkt1Data
    UniqueId delAuthKey1 = new UniqueId("nJlsaGZb1k6OFze1fUsHEF0osP5Wv9Rgta8EwHl8Te8=");
    // matches emailPkt2Data
    UniqueId delAuthKey2 = new UniqueId("ImXwDy7HZq7pyjGwxpYmlwaKAWoQlUl2fdrBK~mTt0g=");
    String prefix1 = emailPacket1.getDhtKey().toBase64().substring(0, 2);
    String prefix2 = emailPacket2.getDhtKey().toBase64().substring(0, 2);
    assertEquals("Error setting up test packets: prefixes of DHT keys differ", prefix1, prefix2);
    assertFalse("Error setting up test packets: DHT keys should be different", emailPacket1.getDhtKey().equals(emailPacket2.getDhtKey()));
    // add two packets and delete them via delete requests
    packetFolder.store(emailPacket1);
    assertEquals("Folder should have exactly one element!", 1, packetFolder.getElements().size());
    packetFolder.store(emailPacket2);
    assertEquals("Folder should have two elements!", 2, packetFolder.getElements().size());
    EmailPacketDeleteRequest delRequest1 = new EmailPacketDeleteRequest(emailPacket1.getDhtKey(), delAuthKey1);
    packetFolder.process(delRequest1);
    assertEquals("Folder should have exactly one element!", 1, packetFolder.getElements().size());
    EmailPacketDeleteRequest delRequest2 = new EmailPacketDeleteRequest(emailPacket2.getDhtKey(), delAuthKey2);
    packetFolder.process(delRequest2);
    assertEquals("Folder should be empty!", 0, packetFolder.getElements().size());
    // verify that there is one deletion file containing two entries
    File[] files = packetFolder.getStorageDirectory().listFiles();
    assertEquals(1, files.length);
    assertTrue(files[0].getName().startsWith("DEL_"));
    DataPacket dataPacket = DataPacket.createPacket(files[0]);
    assertTrue(dataPacket instanceof DeletionInfoPacket);
    DeletionInfoPacket delInfoPacket = (DeletionInfoPacket) dataPacket;
    Iterator<DeletionRecord> delPacketIterator = delInfoPacket.iterator();
    assertTrue("DeletionInfoPacket has no elements!", delPacketIterator.hasNext());
    delPacketIterator.next();
    assertTrue("DeletionInfoPacket has less than one element!", delPacketIterator.hasNext());
    delPacketIterator.next();
    assertFalse("DeletionInfoPacket has more than two elements!", delPacketIterator.hasNext());
    // verify that the two deletion records match the DHT keys and auth keys of the deleted packets
    DeleteRequest newDelRequest1 = packetFolder.storeAndCreateDeleteRequest(emailPacket1);
    assertTrue(newDelRequest1 instanceof EmailPacketDeleteRequest);
    EmailPacketDeleteRequest newEmailPacketDelRequest1 = (EmailPacketDeleteRequest) newDelRequest1;
    assertEquals(newEmailPacketDelRequest1.getDhtKey(), emailPacket1.getDhtKey());
    assertEquals(newEmailPacketDelRequest1.getAuthorization(), delAuthKey1);
    DeleteRequest newDelRequest2 = packetFolder.storeAndCreateDeleteRequest(emailPacket2);
    assertTrue(newDelRequest2 instanceof EmailPacketDeleteRequest);
    EmailPacketDeleteRequest newEmailPacketDelRequest2 = (EmailPacketDeleteRequest) newDelRequest2;
    assertEquals(newEmailPacketDelRequest2.getDhtKey(), emailPacket2.getDhtKey());
    assertEquals(newEmailPacketDelRequest2.getAuthorization(), delAuthKey2);
}
Also used : EmailPacketDeleteRequest(i2p.bote.packet.dht.EmailPacketDeleteRequest) UniqueId(i2p.bote.UniqueId) DeletionInfoPacket(i2p.bote.packet.dht.DeletionInfoPacket) DeletionRecord(i2p.bote.packet.dht.DeletionRecord) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) DataPacket(i2p.bote.packet.DataPacket) File(java.io.File) DeleteRequest(i2p.bote.packet.dht.DeleteRequest) EmailPacketDeleteRequest(i2p.bote.packet.dht.EmailPacketDeleteRequest) Test(org.junit.Test)

Example 12 with EncryptedEmailPacket

use of i2p.bote.packet.dht.EncryptedEmailPacket in project i2p.i2p-bote by i2p.

the class EmailPacketFolderTest method testCheckExpiration.

@Test
public void testCheckExpiration() throws GeneralSecurityException, InterruptedException, PasswordException {
    final long cutoffTime = System.currentTimeMillis() - ExpirationListener.EXPIRATION_TIME_MILLISECONDS;
    // store a packet that expired 10 seconds ago
    long expirationTime1 = cutoffTime - 10 * 1000;
    EncryptedEmailPacket emailPacket1 = new SettableStoreTimeEncryptedEmailPacket(unencryptedPacket, recipient, expirationTime1);
    packetFolder.store(emailPacket1);
    // round to seconds
    assertEquals(expirationTime1 / 1000L, packetFolder.getElements().get(0).getStoreTime() / 1000L);
    // store a packet that expires in 10 seconds
    long expirationTime2 = cutoffTime + 10 * 1000;
    EncryptedEmailPacket emailPacket2 = new SettableStoreTimeEncryptedEmailPacket(unencryptedPacket2, recipient, expirationTime2);
    packetFolder.store(emailPacket2);
    assertEquals(2, packetFolder.getElements().size());
    // delete expired packets and check that one of the two packets got deleted
    packetFolder.deleteExpired();
    assertEquals(1, packetFolder.getElements().size());
    // 11 seconds later, the remaining packet should have expired
    TimeUnit.SECONDS.sleep(11);
    packetFolder.deleteExpired();
    assertEquals(0, packetFolder.getElements().size());
}
Also used : EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) Test(org.junit.Test)

Example 13 with EncryptedEmailPacket

use of i2p.bote.packet.dht.EncryptedEmailPacket in project i2p.i2p-bote by i2p.

the class RelayPacketFolderTest method setUp.

@Before
public void setUp() throws Exception {
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    testDir = new File(tempDir, "RelayPacketFolderTest-" + System.currentTimeMillis());
    folderDir = new File(testDir, "relay_pkt");
    folder = new RelayPacketFolder(folderDir);
    // make an EncryptedEmailPacket
    String base64Destination = "X3oKYQJ~1EAz7B1ZYGSrOTIMCW5Rnn2Svoc38dx5D9~zvz8vqiWcH-pCqQDwLgPWl9RTBzHtTmZcGRPXIv54i0XWeUfX6rTPDQGuZsnBMM0xrkH2FNLNFaJa0NgW3uKXWpNj9AI1AXUXzK-2MYTYoaZHx5SBoCaKfAGMcFJvTON1~kopxBxdBF9Q7T4~PJ3I2LeU-ycmUlehe9N9bIu7adUGyPGVl8Ka-UxwQromoJ~vSWHHl8HkwcDkW--v9Aj~wvFqxqriFkB1EeBiThi3V4XtVY~GUP4IkRj9YZGTsSBf3eS4xwXgnYWlB7IvxAGBfHY9MCg3lbAa1Dg~1IH6rhtXxsXUtGcXsz9yMZTxXHd~rGo~JrXeM1y~Vcenpr6tJcum6pxevkKzzT0qDegGPH3Zhqz7sSeeIaJEcPBUAkX89csqyFWFIjTMm6yZp2rW-QYUnVNLNTjf7vndYUAEICogAkq~btqpIzrGEpm3Pr9F23br3SpbOmdxQxg51AMmAAAA";
    Destination nextDestination = new Destination(base64Destination.substring(0, 516));
    long delayMilliseconds = TimeUnit.MILLISECONDS.convert(111, TimeUnit.MINUTES);
    String content = "Warum, warum, warum\n" + "Ist die Banane krumm?\n" + "Weil niemand in den Urwald zog\n" + "Und die Banane grade bog.\n";
    byte[] messageIdBytes = new byte[] { -69, -24, -109, 1, 69, -122, -69, 113, -68, -90, 55, -28, 105, 97, 125, 70, 51, 58, 14, 2, -13, -53, 90, -29, 36, 67, 36, -94, -108, -125, 11, 123 };
    UniqueId messageId = new UniqueId(messageIdBytes, 0);
    int fragmentIndex = 0;
    InputStream contentStream = new ByteArrayInputStream(content.getBytes());
    UnencryptedEmailPacket unencryptedPacket = new UnencryptedEmailPacket(contentStream, messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
    unencryptedPacket.setNumFragments(1);
    String base64EmailDest = "rIbyUukqtsacD-MDJJ8KbIP9d3WQQo~t~zysc3bNcF1mSwz9PcGJnvWCNhnG2nzbdUAIDouESZjLRnBr7-mxNS";
    EmailDestination recipient = new EmailDestination(base64EmailDest);
    emailPacket = new EncryptedEmailPacket(unencryptedPacket, recipient);
    // make a RelayRequest
    StoreRequest storeRequest = new StoreRequest(emailPacket);
    relayRequest = new RelayRequest(storeRequest, nextDestination, delayMilliseconds, 1000);
}
Also used : Destination(net.i2p.data.Destination) EmailDestination(i2p.bote.email.EmailDestination) UniqueId(i2p.bote.UniqueId) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) StoreRequest(i2p.bote.packet.dht.StoreRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) EmailDestination(i2p.bote.email.EmailDestination) UnencryptedEmailPacket(i2p.bote.packet.dht.UnencryptedEmailPacket) File(java.io.File) RelayRequest(i2p.bote.packet.relay.RelayRequest) Before(org.junit.Before)

Example 14 with EncryptedEmailPacket

use of i2p.bote.packet.dht.EncryptedEmailPacket in project i2p.i2p-bote by i2p.

the class OutboxProcessorTest method testSendEmail.

@Test
public void testSendEmail() throws Exception {
    EmailIdentity identity = TestUtil.createTestIdentities().get(0).identity;
    String address = "tester <" + identity.getKey() + ">";
    when(identities.extractIdentity(address)).thenReturn(identity);
    testEmail = new Email(true);
    testEmail.setFrom(new InternetAddress(address));
    testEmail.addRecipient(RecipientType.TO, new InternetAddress("Erika Mustermann <m-5~1dZ0MrGdyAWu-C2ecNAB5LCCsHQpeSfjn-r~mqMfNvroR98~BRmReUDmb0la-r-pBHLMtflrJE7aTrGwDTBm5~AJFEm-9SJPZnyGs-ed5pOj4Db65yJml1y1n77qr1~mM4GITl6KuIoxg8YwvPrCIlXe2hiiDCoC-uY9-np9UY>"));
    testEmail.setSubject("Test", "UTF-8");
    testEmail.setText("foobar");
    op.sendEmail(testEmail);
    ArgumentCaptor<DhtStorablePacket> arg = ArgumentCaptor.forClass(DhtStorablePacket.class);
    verify(dht, times(2)).store(arg.capture());
    List<DhtStorablePacket> values = arg.getAllValues();
    assertTrue(values.get(0) instanceof EncryptedEmailPacket);
    assertTrue(values.get(1) instanceof IndexPacket);
    assertTrue(((IndexPacket) values.get(1)).contains(((EncryptedEmailPacket) values.get(0)).getDhtKey()));
}
Also used : DhtStorablePacket(i2p.bote.packet.dht.DhtStorablePacket) InternetAddress(javax.mail.internet.InternetAddress) Email(i2p.bote.email.Email) EmailIdentity(i2p.bote.email.EmailIdentity) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) IndexPacket(i2p.bote.packet.dht.IndexPacket) Test(org.junit.Test)

Example 15 with EncryptedEmailPacket

use of i2p.bote.packet.dht.EncryptedEmailPacket in project i2p.i2p-bote by i2p.

the class OutboxProcessorTest method testSendAnonymousEmail.

@Test
public void testSendAnonymousEmail() throws Exception {
    testEmail = new Email(true);
    testEmail.setFrom(new InternetAddress("anonymous"));
    testEmail.addRecipient(RecipientType.TO, new InternetAddress("Erika Mustermann <m-5~1dZ0MrGdyAWu-C2ecNAB5LCCsHQpeSfjn-r~mqMfNvroR98~BRmReUDmb0la-r-pBHLMtflrJE7aTrGwDTBm5~AJFEm-9SJPZnyGs-ed5pOj4Db65yJml1y1n77qr1~mM4GITl6KuIoxg8YwvPrCIlXe2hiiDCoC-uY9-np9UY>"));
    testEmail.setSubject("Test", "UTF-8");
    testEmail.setText("foobar");
    op.sendEmail(testEmail);
    ArgumentCaptor<DhtStorablePacket> arg = ArgumentCaptor.forClass(DhtStorablePacket.class);
    verify(dht, times(2)).store(arg.capture());
    List<DhtStorablePacket> values = arg.getAllValues();
    assertTrue(values.get(0) instanceof EncryptedEmailPacket);
    assertTrue(values.get(1) instanceof IndexPacket);
    assertTrue(((IndexPacket) values.get(1)).contains(((EncryptedEmailPacket) values.get(0)).getDhtKey()));
}
Also used : DhtStorablePacket(i2p.bote.packet.dht.DhtStorablePacket) InternetAddress(javax.mail.internet.InternetAddress) Email(i2p.bote.email.Email) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) IndexPacket(i2p.bote.packet.dht.IndexPacket) Test(org.junit.Test)

Aggregations

EncryptedEmailPacket (i2p.bote.packet.dht.EncryptedEmailPacket)16 UniqueId (i2p.bote.UniqueId)7 UnencryptedEmailPacket (i2p.bote.packet.dht.UnencryptedEmailPacket)6 Test (org.junit.Test)6 EmailDestination (i2p.bote.email.EmailDestination)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)5 DhtStorablePacket (i2p.bote.packet.dht.DhtStorablePacket)4 IndexPacket (i2p.bote.packet.dht.IndexPacket)4 DeleteRequest (i2p.bote.packet.dht.DeleteRequest)3 DeletionInfoPacket (i2p.bote.packet.dht.DeletionInfoPacket)3 DeletionRecord (i2p.bote.packet.dht.DeletionRecord)3 EmailPacketDeleteRequest (i2p.bote.packet.dht.EmailPacketDeleteRequest)3 Hash (net.i2p.data.Hash)3 Before (org.junit.Before)3 Email (i2p.bote.email.Email)2 EmailIdentity (i2p.bote.email.EmailIdentity)2 DataPacket (i2p.bote.packet.DataPacket)2 InternetAddress (javax.mail.internet.InternetAddress)2 Destination (net.i2p.data.Destination)2