Search in sources :

Example 1 with UnencryptedEmailPacket

use of i2p.bote.packet.dht.UnencryptedEmailPacket 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 UnencryptedEmailPacket

use of i2p.bote.packet.dht.UnencryptedEmailPacket 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 UnencryptedEmailPacket

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

the class OutboxProcessor method sendToOne.

/**
 * Sends an {@link Email} to one recipient.
 * @param senderIdentity The sender's Email Identity, or <code>null</code> for anonymous emails
 * @param recipient
 * @param email
 * @throws MessagingException
 * @throws DhtException
 * @throws GeneralSecurityException
 * @throws PasswordException
 * @throws InterruptedException
 */
private void sendToOne(EmailIdentity senderIdentity, String recipient, Email email) throws MessagingException, DhtException, GeneralSecurityException, PasswordException, InterruptedException {
    // only used for logging
    String logSuffix = null;
    try {
        logSuffix = "Recipient = '" + recipient + "' Message ID = '" + email.getMessageID() + "'";
        log.info("Sending email: " + logSuffix);
        EmailDestination recipientDest = new EmailDestination(recipient);
        EmailIdentity.IdentityConfig identityConfig;
        if (email.isAnonymous())
            identityConfig = configuration;
        else
            identityConfig = senderIdentity.getWrappedConfig(configuration);
        int hops = identityConfig.getNumStoreHops();
        long minDelay = identityConfig.getRelayMinDelay() * 60 * 1000;
        long maxDelay = identityConfig.getRelayMaxDelay() * 60 * 1000;
        int relayRedundancy = identityConfig.getRelayRedundancy();
        int maxPacketSize = getMaxEmailPacketSize(hops);
        Collection<UnencryptedEmailPacket> emailPackets = email.createEmailPackets(senderIdentity, identities, recipient, maxPacketSize);
        IndexPacket indexPacket = new IndexPacket(recipientDest);
        EmailMetadata metadata = email.getMetadata();
        for (UnencryptedEmailPacket unencryptedPacket : emailPackets) {
            EncryptedEmailPacket emailPacket = new EncryptedEmailPacket(unencryptedPacket, recipientDest);
            send(emailPacket, hops, minDelay, maxDelay, relayRedundancy);
            indexPacket.put(emailPacket);
            metadata.addPacketInfo(recipientDest, emailPacket.getDhtKey(), emailPacket.getDeleteVerificationHash());
        }
        send(indexPacket, hops, minDelay, maxDelay, relayRedundancy);
        outbox.saveMetadata(email);
    } catch (GeneralSecurityException e) {
        log.error("Invalid recipient address. " + logSuffix, e);
        outbox.setStatus(email, new EmailStatus(Status.INVALID_RECIPIENT, recipient));
        throw e;
    } catch (MessagingException e) {
        log.error("Can't create email packets. " + logSuffix, e);
        outbox.setStatus(email, new EmailStatus(Status.ERROR_CREATING_PACKETS, e.getLocalizedMessage()));
        throw e;
    } catch (DhtException e) {
        log.error("Can't store email packet on the DHT. " + logSuffix, e);
        outbox.setStatus(email, new EmailStatus(Status.ERROR_SENDING, e.getLocalizedMessage()));
        throw e;
    } catch (IOException e) {
        log.error("Can't save metadata. " + logSuffix, e);
        outbox.setStatus(email, new EmailStatus(Status.ERROR_SAVING_METADATA, e.getLocalizedMessage()));
    }
}
Also used : MessagingException(javax.mail.MessagingException) EmailIdentity(i2p.bote.email.EmailIdentity) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) GeneralSecurityException(java.security.GeneralSecurityException) EmailStatus(i2p.bote.folder.Outbox.EmailStatus) EmailMetadata(i2p.bote.email.EmailMetadata) IOException(java.io.IOException) IndexPacket(i2p.bote.packet.dht.IndexPacket) EmailDestination(i2p.bote.email.EmailDestination) UnencryptedEmailPacket(i2p.bote.packet.dht.UnencryptedEmailPacket) DhtException(i2p.bote.network.DhtException)

Example 4 with UnencryptedEmailPacket

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

the class EmailPacketFolderTest method setUp.

@Before
public void setUp() throws Exception {
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    testDir = new File(tempDir, "EmailPacketFolderTest-" + System.currentTimeMillis());
    folderDir = new File(testDir, "dht_email_pkt");
    packetFolder = new EmailPacketFolder(folderDir);
    // make two UnencryptedEmailPackets with different contents
    byte[] content1 = "test TEST test ABCDEFGH asdfsadfsadf 3487562384".getBytes();
    byte[] content2 = "fdlkhgjfljh test 123456".getBytes();
    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;
    unencryptedPacket = new UnencryptedEmailPacket(new ByteArrayInputStream(content1), messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
    unencryptedPacket.setNumFragments(1);
    unencryptedPacket2 = new UnencryptedEmailPacket(new ByteArrayInputStream(content2), messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
    unencryptedPacket.setNumFragments(1);
    String base64Dest = "m-5~1dZ0MrGdyAWu-C2ecNAB5LCCsHQpeSfjn-r~mqMfNvroR98~BRmReUDmb0la-r-pBHLMtflrJE7aTrGwDTBm5~AJFEm-9SJPZnyGs-ed5pOj4Db65yJml1y1n77qr1~mM4GITl6KuIoxg8YwvPrCIlXe2hiiDCoC-uY9-np9UY";
    recipient = new EmailDestination(base64Dest);
    emailPacket = new EncryptedEmailPacket(unencryptedPacket, recipient);
    sender = new Destination("X3oKYQJ~1EAz7B1ZYGSrOTIMCW5Rnn2Svoc38dx5D9~zvz8vqiWcH-pCqQDwLgPWl9RTBzHtTmZcGRPXIv54i0XWeUfX6rTPDQGuZsnBMM0xrkH2FNLNFaJa0NgW3uKXWpNj9AI1AXUXzK-2MYTYoaZHx5SBoCaKfAGMcFJvTON1~kopxBxdBF9Q7T4~PJ3I2LeU-ycmUlehe9N9bIu7adUGyPGVl8Ka-UxwQromoJ~vSWHHl8HkwcDkW--v9Aj~wvFqxqriFkB1EeBiThi3V4XtVY~GUP4IkRj9YZGTsSBf3eS4xwXgnYWlB7IvxAGBfHY9MCg3lbAa1Dg~1IH6rhtXxsXUtGcXsz9yMZTxXHd~rGo~JrXeM1y~Vcenpr6tJcum6pxevkKzzT0qDegGPH3Zhqz7sSeeIaJEcPBUAkX89csqyFWFIjTMm6yZp2rW-QYUnVNLNTjf7vndYUAEICogAkq~btqpIzrGEpm3Pr9F23br3SpbOmdxQxg51AMmAAAA");
}
Also used : UniqueId(i2p.bote.UniqueId) EmailDestination(i2p.bote.email.EmailDestination) Destination(net.i2p.data.Destination) ByteArrayInputStream(java.io.ByteArrayInputStream) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) EmailDestination(i2p.bote.email.EmailDestination) UnencryptedEmailPacket(i2p.bote.packet.dht.UnencryptedEmailPacket) File(java.io.File) Before(org.junit.Before)

Example 5 with UnencryptedEmailPacket

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

the class FolderTest method createEmailPacket.

EncryptedEmailPacket createEmailPacket(EmailDestination dest, String message) throws Exception {
    byte[] content = message.getBytes();
    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;
    UnencryptedEmailPacket plaintextPacket = new UnencryptedEmailPacket(new ByteArrayInputStream(content), messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
    plaintextPacket.setNumFragments(1);
    return new EncryptedEmailPacket(plaintextPacket, dest);
}
Also used : UniqueId(i2p.bote.UniqueId) ByteArrayInputStream(java.io.ByteArrayInputStream) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) UnencryptedEmailPacket(i2p.bote.packet.dht.UnencryptedEmailPacket)

Aggregations

UnencryptedEmailPacket (i2p.bote.packet.dht.UnencryptedEmailPacket)12 EncryptedEmailPacket (i2p.bote.packet.dht.EncryptedEmailPacket)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 UniqueId (i2p.bote.UniqueId)5 KeyUpdateHandler (i2p.bote.crypto.KeyUpdateHandler)5 EmailDestination (i2p.bote.email.EmailDestination)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Test (org.junit.Test)4 File (java.io.File)3 Before (org.junit.Before)3 EmailIdentity (i2p.bote.email.EmailIdentity)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 GeneralSecurityException (java.security.GeneralSecurityException)2 MessagingException (javax.mail.MessagingException)2 Destination (net.i2p.data.Destination)2 Email (i2p.bote.email.Email)1 EmailMetadata (i2p.bote.email.EmailMetadata)1 EmailStatus (i2p.bote.folder.Outbox.EmailStatus)1 DhtException (i2p.bote.network.DhtException)1