Search in sources :

Example 1 with KeyUpdateHandler

use of i2p.bote.crypto.KeyUpdateHandler in project i2p.i2p-bote by i2p.

the class EmailTest method testHeaderRemoval.

@Test
public void testHeaderRemoval() throws MessagingException, IOException, GeneralSecurityException, PasswordException {
    Email newEmail;
    Collection<UnencryptedEmailPacket> packets;
    ByteArrayOutputStream outputStream;
    KeyUpdateHandler keyUpdateHandler = TestUtil.createDummyKeyUpdateHandler();
    // verify that all BCC addresses are removed when sending to a TO: address
    EmailIdentity identity2 = identities.get(bccEmail);
    packets = bccEmail.createEmailPackets(identity2, keyUpdateHandler, null, I2PBotePacket.MAX_DATAGRAM_SIZE);
    outputStream = new ByteArrayOutputStream();
    for (UnencryptedEmailPacket packet : packets) outputStream.write(packet.getContent());
    newEmail = new Email(outputStream.toByteArray());
    assertNull("BCC headers were not removed!", newEmail.getHeader("BCC"));
    assertEquals(3, newEmail.getAllRecipients().length);
    // verify that the recipient is not removed if it is a BCC: addresses
    // use the plain email dest because that is what the Email class compares against
    packets = bccEmail.createEmailPackets(bccIdentity, keyUpdateHandler, bccEmailDestination, I2PBotePacket.MAX_DATAGRAM_SIZE);
    outputStream = new ByteArrayOutputStream();
    for (UnencryptedEmailPacket packet : packets) outputStream.write(packet.getContent());
    newEmail = new Email(outputStream.toByteArray());
    assertNotNull("BCC header expected!", newEmail.getHeader("BCC"));
    assertEquals("One BCC header expected!", 1, newEmail.getHeader("BCC").length);
    assertEquals(4, newEmail.getAllRecipients().length);
}
Also used : KeyUpdateHandler(i2p.bote.crypto.KeyUpdateHandler) UnencryptedEmailPacket(i2p.bote.packet.dht.UnencryptedEmailPacket) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with KeyUpdateHandler

use of i2p.bote.crypto.KeyUpdateHandler in project i2p.i2p-bote by i2p.

the class EmailTest method testSign.

@Test
public void testSign() throws MessagingException, SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException, GeneralSecurityException, PasswordException {
    // -1 for the anonymous email that was not added to the map
    assertEquals(emails.size() - 1, identities.size());
    for (Email email : emails) {
        EmailIdentity identity = identities.get(email);
        if (identity == null)
            continue;
        // sign and verify signature
        email.sign(identity, TestUtil.createDummyKeyUpdateHandler());
        assertTrue(email.isSignatureValid());
        // write the email to a byte array, make a new email from the byte array, and verify the signature
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        KeyUpdateHandler keyUpdateHandler = TestUtil.createDummyKeyUpdateHandler();
        for (UnencryptedEmailPacket packet : email.createEmailPackets(identity, keyUpdateHandler, null, I2PBotePacket.MAX_DATAGRAM_SIZE)) outputStream.write(packet.getContent());
        email = new Email(outputStream.toByteArray());
        assertTrue(email.isSignatureValid());
    }
}
Also used : KeyUpdateHandler(i2p.bote.crypto.KeyUpdateHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UnencryptedEmailPacket(i2p.bote.packet.dht.UnencryptedEmailPacket) Test(org.junit.Test)

Example 3 with KeyUpdateHandler

use of i2p.bote.crypto.KeyUpdateHandler in project i2p.i2p-bote by i2p.

the class IncompleteEmailFolderTest method testAddEmail.

private void testAddEmail(String mailContent, int expectedNumPackets) throws Exception {
    Email email = new Email(true);
    String recipient = "test@bote.i2p";
    email.addRecipient(RecipientType.TO, new InternetAddress(recipient));
    email.setText(mailContent);
    EmailIdentity identity = new EmailIdentity("DVkhqF6R9SHB5svViGtqRYZO7oI-0-omnIFtae29fNnNtTTH2j37Fr5fWp4t6rseTjiJ8gwg08DnbA4qP72aSQcDQPSErOELOMSU5BUTtsT8hnv1-DKdhIn~1qoIjxzIFHbxT3xnR3nFI7lKd6couscilzPBCjoFDUKb5ds2u23RO29K7~EKxU1O7Ltu6sT5etXkJkhAziOcuyfZyxJXqH1caYX5e2aWIhY3D2ESfy4nMK66r5KcDVQOPTzCkJq6d1FFOmnDGrlJjN~HgHmfUCtLbO~TLugWx9FCiDGfPkBb-3ODYTDaUR1zobOj1tiffV3Nm73PsYddRt84emLKzIRsC77JJpflw~h8UIRYJ29vJDf4VQ54BhZcelmN192sIrWr2nKN8n6PpSP4LI4RAuG2UvLytnDYzFM7O9WcnFP2-Qs3t1lD9aF72JVTYTpH5PZupnB1cglSsdRg8RmtRa41Fseyx8D3EdH~DCdpMGmfupaWp9~dKpFMleqk9scRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABTjDxn3wEOjCjJ4APg~2IGpqWwy2Hw728aZ3eCC5l0MP913BLdIfSUiXPbs6sN9A2");
    KeyUpdateHandler keyUpdateHandler = TestUtil.createDummyKeyUpdateHandler();
    Collection<UnencryptedEmailPacket> packets = email.createEmailPackets(identity, keyUpdateHandler, recipient, I2PBotePacket.MAX_DATAGRAM_SIZE);
    assertTrue("Expected " + expectedNumPackets + " email packets, got " + packets.size(), packets.size() == expectedNumPackets);
    assertTrue("The inbox should be empty at this point!", inbox.getElements().size() == 0);
    for (UnencryptedEmailPacket emailPacket : packets) incompleteFolder.addEmailPacket(emailPacket);
    assertTrue("The incomplete emails folder is not empty!", incompleteFolder.getElements().size() == 0);
    assertTrue("Expected: one email in the inbox, actual number = " + inbox.getElements().size(), inbox.getElements().size() == 1);
    // Verify that the original email and the email in the folder are the same except for the signature header
    Email storedEmail = inbox.getElements().iterator().next();
    storedEmail.removeHeader("X-I2PBote-Sig-Valid");
    TestUtil.assertEquals("Stored email differs from original email!", email, storedEmail);
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Email(i2p.bote.email.Email) KeyUpdateHandler(i2p.bote.crypto.KeyUpdateHandler) EmailIdentity(i2p.bote.email.EmailIdentity) UnencryptedEmailPacket(i2p.bote.packet.dht.UnencryptedEmailPacket)

Example 4 with KeyUpdateHandler

use of i2p.bote.crypto.KeyUpdateHandler in project i2p.i2p-bote by i2p.

the class EmailTest method testCompression.

@Test
public void testCompression() throws MessagingException, GeneralSecurityException, PasswordException {
    // create a 500,000-char string that should compress to one packet
    StringBuilder stringBuilder = new StringBuilder();
    for (int i = 0; i < 50000; i++) stringBuilder.append("0123456789");
    Email newEmail = new Email(true);
    newEmail.setText(stringBuilder.toString());
    KeyUpdateHandler keyUpdateHandler = TestUtil.createDummyKeyUpdateHandler();
    Collection<UnencryptedEmailPacket> packets = newEmail.createEmailPackets(bccIdentity, keyUpdateHandler, null, I2PBotePacket.MAX_DATAGRAM_SIZE);
    assertEquals("The email was not compressed into one email packet.", 1, packets.size());
}
Also used : KeyUpdateHandler(i2p.bote.crypto.KeyUpdateHandler) UnencryptedEmailPacket(i2p.bote.packet.dht.UnencryptedEmailPacket) Test(org.junit.Test)

Example 5 with KeyUpdateHandler

use of i2p.bote.crypto.KeyUpdateHandler in project i2p.i2p-bote by i2p.

the class EmailTest method testCreateEmailPackets.

@Test
public void testCreateEmailPackets() throws MessagingException, IOException, GeneralSecurityException, SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, PasswordException {
    // convert an email to a byte array, convert back, and compare with the original email
    for (Email email : emails) {
        EmailIdentity identity = identities.get(email);
        KeyUpdateHandler keyUpdateHandler = TestUtil.createDummyKeyUpdateHandler();
        Collection<UnencryptedEmailPacket> packets = email.createEmailPackets(identity, keyUpdateHandler, null, I2PBotePacket.MAX_DATAGRAM_SIZE);
        // the emails are somewhat compressible, but definitely not by 50%
        assertTrue("Expected more email packets. #packets = " + packets.size(), packets.size() > email.getText().length() / I2PBotePacket.MAX_DATAGRAM_SIZE / 2);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        for (UnencryptedEmailPacket packet : packets) outputStream.write(packet.getContent());
        Email newEmail = new Email(outputStream.toByteArray());
        assertEquals(email.getContent(), newEmail.getContent());
        // check packet sizes against size limit
        for (UnencryptedEmailPacket packet : packets) assertTrue("Email packet exceeds max size!", packet.toByteArray().length <= I2PBotePacket.MAX_DATAGRAM_SIZE);
    }
}
Also used : KeyUpdateHandler(i2p.bote.crypto.KeyUpdateHandler) UnencryptedEmailPacket(i2p.bote.packet.dht.UnencryptedEmailPacket) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

KeyUpdateHandler (i2p.bote.crypto.KeyUpdateHandler)7 UnencryptedEmailPacket (i2p.bote.packet.dht.UnencryptedEmailPacket)5 Test (org.junit.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 EmailIdentity (i2p.bote.email.EmailIdentity)2 Email (i2p.bote.email.Email)1 InputStream (java.io.InputStream)1 InternetAddress (javax.mail.internet.InternetAddress)1 Expectations (org.jmock.Expectations)1 Mockery (org.jmock.Mockery)1 Before (org.junit.Before)1