Search in sources :

Example 6 with EmailIdentity

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

the class EditIdentityFragment method initializeIdentity.

private void initializeIdentity() {
    if (mKey == null) {
        // Show the encryption choice field
        CryptoAdapter adapter = new CryptoAdapter(getActivity());
        mCryptoField.setAdapter(adapter);
        mCryptoField.setSelection(mDefaultPos);
        mCryptoField.setVisibility(View.VISIBLE);
        // If no identities, set this as default by default
        try {
            mDefaultField.setChecked(I2PBote.getInstance().getIdentities().size() == 0);
        } catch (PasswordException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (GeneralSecurityException e) {
            e.printStackTrace();
        }
    } else {
        // Load the identity to edit
        try {
            EmailIdentity identity = BoteHelper.getIdentity(mKey);
            String pic = identity.getPictureBase64();
            if (pic != null && !pic.isEmpty()) {
                setPictureB64(pic);
            }
            mNameField.setText(identity.getPublicName());
            mDescField.setText(identity.getDescription());
            mDefaultField.setChecked(identity.isDefaultIdentity());
        } catch (PasswordException e) {
            // TODO Handle
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Handle
            e.printStackTrace();
        } catch (GeneralSecurityException e) {
            // TODO Handle
            e.printStackTrace();
        }
    }
}
Also used : PasswordException(i2p.bote.fileencryption.PasswordException) EmailIdentity(i2p.bote.email.EmailIdentity) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException)

Example 7 with EmailIdentity

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

the class IdentityAdapter method onBindViewHolder.

// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    switch(holder.getItemViewType()) {
        case R.layout.listitem_empty:
            ((TextView) holder.itemView).setText(mCtx.getResources().getString(R.string.no_identities));
            break;
        case R.layout.listitem_identity:
            final IdentityViewHolder cvh = (IdentityViewHolder) holder;
            EmailIdentity identity = mIdentities.get(position);
            ViewGroup.LayoutParams lp = cvh.mPicture.getLayoutParams();
            cvh.mPicture.setImageBitmap(BoteHelper.getIdentityPicture(identity, lp.width, lp.height));
            cvh.mName.setText(identity.getPublicName());
            cvh.itemView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    mListener.onIdentitySelected(mIdentities.get(cvh.getAdapterPosition()));
                }
            });
            break;
        default:
            break;
    }
}
Also used : EmailIdentity(i2p.bote.email.EmailIdentity) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 8 with EmailIdentity

use of i2p.bote.email.EmailIdentity 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 9 with EmailIdentity

use of i2p.bote.email.EmailIdentity 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)

Example 10 with EmailIdentity

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

the class I2PBote method sendEmail.

public void sendEmail(Email email) throws MessagingException, PasswordException, IOException, GeneralSecurityException {
    email.checkAddresses();
    // sign email unless sender is anonymous
    if (!email.isAnonymous()) {
        String sender = email.getOneFromAddress();
        EmailIdentity senderIdentity = identities.extractIdentity(sender);
        if (senderIdentity == null)
            throw new NoIdentityForSenderException(sender);
        email.sign(senderIdentity, identities);
    }
    // set the signature flag so the signature isn't reverified every time the email is loaded
    email.setSignatureFlag();
    outbox.add(email);
    if (outboxProcessor != null)
        outboxProcessor.checkForEmail();
}
Also used : NoIdentityForSenderException(i2p.bote.email.NoIdentityForSenderException) EmailIdentity(i2p.bote.email.EmailIdentity)

Aggregations

EmailIdentity (i2p.bote.email.EmailIdentity)19 EmailDestination (i2p.bote.email.EmailDestination)4 GeneralSecurityException (java.security.GeneralSecurityException)4 MessagingException (javax.mail.MessagingException)4 InternetAddress (javax.mail.internet.InternetAddress)4 Before (org.junit.Before)4 Email (i2p.bote.email.Email)3 Identities (i2p.bote.email.Identities)3 IOException (java.io.IOException)3 Address (javax.mail.Address)3 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 UniqueId (i2p.bote.UniqueId)2 KeyUpdateHandler (i2p.bote.crypto.KeyUpdateHandler)2 PasswordException (i2p.bote.fileencryption.PasswordException)2 EmailStatus (i2p.bote.folder.Outbox.EmailStatus)2 EncryptedEmailPacket (i2p.bote.packet.dht.EncryptedEmailPacket)2 IndexPacket (i2p.bote.packet.dht.IndexPacket)2 UnencryptedEmailPacket (i2p.bote.packet.dht.UnencryptedEmailPacket)2