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);
}
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());
}
}
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()));
}
}
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");
}
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);
}
Aggregations