Search in sources :

Example 1 with EmailDestination

use of i2p.bote.email.EmailDestination in project i2p.i2p-bote by i2p.

the class GeneralHelper method saveContact.

/**
 * Updates a contact in the address book if the Destination <code>destinationString</code> exists,
 * or adds a new contact to the address book.
 * @param destinationString A base64-encoded Email Destination key
 * @param name
 * @param pictureBase64
 * @param text
 * @return null if sucessful, or an error message if an error occured
 * @throws PasswordException
 * @throws GeneralSecurityException
 */
public static String saveContact(String destinationString, String name, String pictureBase64, String text) throws PasswordException, GeneralSecurityException {
    destinationString = Util.fixAddress(destinationString);
    AddressBook addressBook = getInstance().getAddressBook();
    Contact contact = addressBook.get(destinationString);
    if (contact != null) {
        contact.setName(name);
        contact.setPictureBase64(pictureBase64);
        contact.setText(text);
    } else {
        EmailDestination destination;
        try {
            destination = new EmailDestination(destinationString);
        } catch (GeneralSecurityException e) {
            Log log = new Log(GeneralHelper.class);
            log.error("Can't save contact to address book.", e);
            return e.getLocalizedMessage();
        }
        contact = new Contact(name, destination, pictureBase64, text);
        addressBook.add(contact);
    }
    try {
        addressBook.save();
        return null;
    } catch (IOException e) {
        return e.getLocalizedMessage();
    }
}
Also used : AddressBook(i2p.bote.addressbook.AddressBook) Log(net.i2p.util.Log) EmailDestination(i2p.bote.email.EmailDestination) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) Contact(i2p.bote.packet.dht.Contact)

Example 2 with EmailDestination

use of i2p.bote.email.EmailDestination 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 3 with EmailDestination

use of i2p.bote.email.EmailDestination 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 4 with EmailDestination

use of i2p.bote.email.EmailDestination in project i2p.i2p-bote by i2p.

the class IndexPacketFolderTest method setUp.

@Before
public void setUp() throws Exception {
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    testDir = new File(tempDir, "IndexPacketFolderTest-" + System.currentTimeMillis());
    folderDir = new File(testDir, "dht_index_pkt");
    folder = new SettableStoreTimeIndexPacketFolder(folderDir);
    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;
    unencryptedPacket1 = new UnencryptedEmailPacket(new ByteArrayInputStream(content1), messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
    unencryptedPacket1.setNumFragments(1);
    unencryptedPacket2 = new UnencryptedEmailPacket(new ByteArrayInputStream(content2), messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
    unencryptedPacket2.setNumFragments(1);
    destination1 = new EmailDestination("2XP9Ep3WWLk3-FTlMgUjgw4h8GYVBCvR6YrPyKdhP4xyQMSh8Da0VjZCmQGbD3PCeaGXAShBKbKjhJjQ7laekI");
    destination2 = new EmailDestination("m-5~1dZ0MrGdyAWu-C2ecNAB5LCCsHQpeSfjn-r~mqMfNvroR98~BRmReUDmb0la-r-pBHLMtflrJE7aTrGwDTBm5~AJFEm-9SJPZnyGs-ed5pOj4Db65yJml1y1n77qr1~mM4GITl6KuIoxg8YwvPrCIlXe2hiiDCoC-uY9-np9UY");
    destination3 = new EmailDestination("0XuJjhgp58aOhvHHgpaxoQYsCUfDS6BECMEoVxFGEFPdk3y8lbzIsq9eUyeizFleMacYwoscCir8nQLlW34lxfRmirkNpD9vU1XnmjnZ5hGdnor1qIDqz3KJ040dVQ617MwyG97xxYLT0FsH907vBXgdc4RCHwKd1~9siagA5CSMaA~wM8ymKXLypiZGYexENLmim7nMzJTQYoOM~fVS99UaGJleDBN3pgZ2EvRYDQV2VqKH7Gee07R3y7b~c0tAKVHS0IbPQfTVJigrIHjTl~ZczxpaeTM04T8IgxKnO~lSmR1w7Ik8TpEkETwT9PDwUqQsjmlSY8E~WwwGMRJVyIRZUkHeRZ0aFq7us8W9EKzYtjjiU1z0QFpZrTfJE8oqCbnH5Lqv5Q86UdTPpriJC1N99E77TpCTnNzcBnpp6ko2JCy2IJUveaigKxS6EmS9KarkkkBRsckOKZZ6UNTOqPZsBCsx0Q9WvDF-Uc3dtouXWyenxRptaQsdkZyYlEQv");
    emailPacket1 = new EncryptedEmailPacket(unencryptedPacket1, destination1);
    emailPacket2 = new EncryptedEmailPacket(unencryptedPacket2, destination2);
}
Also used : UniqueId(i2p.bote.UniqueId) 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 EmailDestination

use of i2p.bote.email.EmailDestination in project i2p.i2p-bote by i2p.

the class EncryptedEmailPacketTest method setUp.

@Before
public void setUp() throws Exception {
    // make an UnencryptedEmailPacket
    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;
    plaintextPacket = new UnencryptedEmailPacket(new ByteArrayInputStream(content), messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
    plaintextPacket.setNumFragments(1);
    encryptedPackets = new EncryptedEmailPacket[2];
    identities = new EmailIdentity[2];
    // make a ElGamal/DSA identity
    String elGamalBase64 = "piYT1uJ3O8~bBPZmTvehMbp3-Zksg5enhvIlp2X8txqL25l0WdQMWwyt30UAOVQqxGdnMPTqqjh~-zoa~rCQORo~J1gRxLwCX9LlHQqaIimJilrbN-rhKy4Xlft054wbgQjLSC-WICE4W64KDfitwRzdr7lV6lz~0KFiZ8erZ-~WPMG1CgWEku9lILQUdUHyFBguPcK9oPDq7oGBuFGy8w0CvAq7ex3nmbL7zQVA~VqILtOGeGK2fidCuuofj4AQsTcXmH9O0nxZGCIJBhf~4EWmazvxu8XVB8pabNQvRDbmFu6q85JTwmxC45lCjqNw30hp8q2zoqP-zchjWOrxFUhSumpBdD0xXJR~qmhejh4WnuRnnam9j3fcxH5i~T7xWgmvIbpZEI4kyc9VEbXbLI7k-bU2A6sdP-AGt5~TjGLcxpdsPnOLRXO-Dsi7E9-3Kc84s4TmdpEJdtHn1dxYyeeT-ysVOqXjv5w5Cuk0XJpUIJG8n7aXHpNb-QLxPD3yAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADWF3qnAX-p41Po~VNmOUzS-Yt~noD8-e~L3P5rZXBWf-XtB4hkloo6m1jwqphEdf1";
    identities[0] = new EmailIdentity(elGamalBase64);
    EmailDestination elGamalDestination = new EmailDestination(identities[0].getKey());
    // make an ElGamal encrypted packet
    assertTrue(identities[0].getCryptoImpl() instanceof ElGamal2048_DSA1024);
    encryptedPackets[0] = new EncryptedEmailPacket(plaintextPacket, elGamalDestination);
    // make a ECDH/ECDSA identity
    String ecdhBase64 = "m-5~1dZ0MrGdyAWu-C2ecNAB5LCCsHQpeSfjn-r~mqMfNvroR98~BRmReUDmb0la-r-pBHLMtflrJE7aTrGwDTBm5~AJFEm-9SJPZnyGs-ed5pOj4Db65yJml1y1n77qr1~mM4GITl6KuIoxg8YwvPrCIlXe2hiiDCoC-uY9-np9UYYujtjOOwCqXPH9PIbcZeFRkegbOxw5G6I7M4-TZBFbxYDtaew6HX9hnQEGWHkaapq2kTTB3Hmv0Uyo64jvcfMmSRcPng3J1Ho5mHgnzsH0qxQemnBcw7Lfc9fU8xRz858uyiQ8J8XH3T8S7k2~8L7awSgaT7uHQgpV~Rs0p1ofJ70g";
    identities[1] = new EmailIdentity(ecdhBase64);
    EmailDestination ecdhDestination = new EmailDestination(identities[1].getKey());
    // make an ECDH encrypted packet
    assertTrue(identities[1].getCryptoImpl() instanceof ECDH521_ECDSA521);
    encryptedPackets[1] = new EncryptedEmailPacket(plaintextPacket, ecdhDestination);
}
Also used : UniqueId(i2p.bote.UniqueId) ByteArrayInputStream(java.io.ByteArrayInputStream) EmailIdentity(i2p.bote.email.EmailIdentity) EmailDestination(i2p.bote.email.EmailDestination) ElGamal2048_DSA1024(i2p.bote.crypto.ElGamal2048_DSA1024) ECDH521_ECDSA521(i2p.bote.crypto.ECDH521_ECDSA521) Before(org.junit.Before)

Aggregations

EmailDestination (i2p.bote.email.EmailDestination)14 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Before (org.junit.Before)7 UniqueId (i2p.bote.UniqueId)6 EncryptedEmailPacket (i2p.bote.packet.dht.EncryptedEmailPacket)5 UnencryptedEmailPacket (i2p.bote.packet.dht.UnencryptedEmailPacket)5 File (java.io.File)5 GeneralSecurityException (java.security.GeneralSecurityException)5 EmailIdentity (i2p.bote.email.EmailIdentity)4 Contact (i2p.bote.packet.dht.Contact)4 Destination (net.i2p.data.Destination)3 AddressBook (i2p.bote.addressbook.AddressBook)2 IndexPacket (i2p.bote.packet.dht.IndexPacket)2 StoreRequest (i2p.bote.packet.dht.StoreRequest)2 IOException (java.io.IOException)2 MessagingException (javax.mail.MessagingException)2 Person (i2p.bote.android.util.Person)1 ECDH521_ECDSA521 (i2p.bote.crypto.ECDH521_ECDSA521)1 ElGamal2048_DSA1024 (i2p.bote.crypto.ElGamal2048_DSA1024)1 EmailMetadata (i2p.bote.email.EmailMetadata)1