Search in sources :

Example 16 with UniqueId

use of i2p.bote.UniqueId in project i2p.i2p-bote by i2p.

the class MessageIdCache method write.

private void write(File cacheFile) {
    log.debug("Writing message ID cache file: <" + cacheFile.getAbsolutePath() + ">");
    String newLine = System.getProperty("line.separator");
    Writer writer = null;
    try {
        writer = new BufferedWriter(new OutputStreamWriter(new SecureFileOutputStream(cacheFile.getAbsolutePath())));
        for (UniqueId id : idList) writer.write(id.toBase64() + newLine);
    } catch (IOException e) {
        log.error("Can't write message ID cache file.", e);
    } finally {
        if (writer != null)
            try {
                writer.close();
            } catch (IOException e) {
                log.error("Error closing Writer.", e);
            }
    }
}
Also used : UniqueId(i2p.bote.UniqueId) OutputStreamWriter(java.io.OutputStreamWriter) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter)

Example 17 with UniqueId

use of i2p.bote.UniqueId in project i2p.i2p-bote by i2p.

the class EmailPacketFolderTest method testProcessDeleteRequest.

/**
 * Tests creation of delete records when processing {@link EmailPacketDeleteRequest}s,
 * and matching them against email packets.
 */
@Test
public void testProcessDeleteRequest() throws GeneralSecurityException, InvalidCipherTextException, MalformedPacketException, PasswordException {
    // create two packets whose base64 DHT keys start with the same two characters
    byte[] emailPkt1Data = Base64.decode("RQTAJHelC-wnxq-OUAnfgqgN84zTCimrfUKw7AgDPHblcwAAAADUk24QY3EPEzk0UmB5PYQxwnEVIWGZkWJ-5ERh30l95QMA0gIs-itszDaiCa4ucekxDL6pZCVMTnI~S0nBx2FQ5Fl4-T50bNojkgJiQZNFB-vwQ4ChB~hxYIomMtbN6tiNDVwYRKjeZHbL3MAffKcwxwF3iPMl8aLLBaU6LxQ~3r7tgTiccHE39Ozm88~Hrf7H-5hWXzTXwm7j1pNJA7hc-wCL3BwngRl8KUsqsII2-PTMI34-a3RfpzMf2cKlY0NVayoW1UxC4dLv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ket emailPacket1 = new EncryptedEmailPacket(emailPkt1Data);
    EncryptedEmailPacket emailPacket2 = new EncryptedEmailPacket(emailPkt2Data);
    // matches emailPkt1Data
    UniqueId delAuthKey1 = new UniqueId("nJlsaGZb1k6OFze1fUsHEF0osP5Wv9Rgta8EwHl8Te8=");
    // matches emailPkt2Data
    UniqueId delAuthKey2 = new UniqueId("ImXwDy7HZq7pyjGwxpYmlwaKAWoQlUl2fdrBK~mTt0g=");
    String prefix1 = emailPacket1.getDhtKey().toBase64().substring(0, 2);
    String prefix2 = emailPacket2.getDhtKey().toBase64().substring(0, 2);
    assertEquals("Error setting up test packets: prefixes of DHT keys differ", prefix1, prefix2);
    assertFalse("Error setting up test packets: DHT keys should be different", emailPacket1.getDhtKey().equals(emailPacket2.getDhtKey()));
    // add two packets and delete them via delete requests
    packetFolder.store(emailPacket1);
    assertEquals("Folder should have exactly one element!", 1, packetFolder.getElements().size());
    packetFolder.store(emailPacket2);
    assertEquals("Folder should have two elements!", 2, packetFolder.getElements().size());
    EmailPacketDeleteRequest delRequest1 = new EmailPacketDeleteRequest(emailPacket1.getDhtKey(), delAuthKey1);
    packetFolder.process(delRequest1);
    assertEquals("Folder should have exactly one element!", 1, packetFolder.getElements().size());
    EmailPacketDeleteRequest delRequest2 = new EmailPacketDeleteRequest(emailPacket2.getDhtKey(), delAuthKey2);
    packetFolder.process(delRequest2);
    assertEquals("Folder should be empty!", 0, packetFolder.getElements().size());
    // verify that there is one deletion file containing two entries
    File[] files = packetFolder.getStorageDirectory().listFiles();
    assertEquals(1, files.length);
    assertTrue(files[0].getName().startsWith("DEL_"));
    DataPacket dataPacket = DataPacket.createPacket(files[0]);
    assertTrue(dataPacket instanceof DeletionInfoPacket);
    DeletionInfoPacket delInfoPacket = (DeletionInfoPacket) dataPacket;
    Iterator<DeletionRecord> delPacketIterator = delInfoPacket.iterator();
    assertTrue("DeletionInfoPacket has no elements!", delPacketIterator.hasNext());
    delPacketIterator.next();
    assertTrue("DeletionInfoPacket has less than one element!", delPacketIterator.hasNext());
    delPacketIterator.next();
    assertFalse("DeletionInfoPacket has more than two elements!", delPacketIterator.hasNext());
    // verify that the two deletion records match the DHT keys and auth keys of the deleted packets
    DeleteRequest newDelRequest1 = packetFolder.storeAndCreateDeleteRequest(emailPacket1);
    assertTrue(newDelRequest1 instanceof EmailPacketDeleteRequest);
    EmailPacketDeleteRequest newEmailPacketDelRequest1 = (EmailPacketDeleteRequest) newDelRequest1;
    assertEquals(newEmailPacketDelRequest1.getDhtKey(), emailPacket1.getDhtKey());
    assertEquals(newEmailPacketDelRequest1.getAuthorization(), delAuthKey1);
    DeleteRequest newDelRequest2 = packetFolder.storeAndCreateDeleteRequest(emailPacket2);
    assertTrue(newDelRequest2 instanceof EmailPacketDeleteRequest);
    EmailPacketDeleteRequest newEmailPacketDelRequest2 = (EmailPacketDeleteRequest) newDelRequest2;
    assertEquals(newEmailPacketDelRequest2.getDhtKey(), emailPacket2.getDhtKey());
    assertEquals(newEmailPacketDelRequest2.getAuthorization(), delAuthKey2);
}
Also used : EmailPacketDeleteRequest(i2p.bote.packet.dht.EmailPacketDeleteRequest) UniqueId(i2p.bote.UniqueId) DeletionInfoPacket(i2p.bote.packet.dht.DeletionInfoPacket) DeletionRecord(i2p.bote.packet.dht.DeletionRecord) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) DataPacket(i2p.bote.packet.DataPacket) File(java.io.File) DeleteRequest(i2p.bote.packet.dht.DeleteRequest) EmailPacketDeleteRequest(i2p.bote.packet.dht.EmailPacketDeleteRequest) Test(org.junit.Test)

Example 18 with UniqueId

use of i2p.bote.UniqueId in project i2p.i2p-bote by i2p.

the class EmailPacketFolderTest method testPacketReceived.

/**
 * Tests processing of one valid and one invalid {@link EmailPacketDeleteRequest}.
 */
@Test
public void testPacketReceived() throws PasswordException {
    packetFolder.store(emailPacket);
    assertEquals(1, packetFolder.getElements().size());
    EmailPacketDeleteRequest delRequest;
    // send an invalid delete request
    byte[] delAuthBytes = unencryptedPacket.getDeleteAuthorization().toByteArray().clone();
    delAuthBytes[5] ^= 1;
    UniqueId invalidAuthorization = new UniqueId(delAuthBytes, 0);
    delRequest = new EmailPacketDeleteRequest(emailPacket.getDhtKey(), invalidAuthorization);
    packetFolder.packetReceived(delRequest, sender, System.currentTimeMillis());
    assertEquals(1, packetFolder.getElements().size());
    // send a valid delete request
    delRequest = new EmailPacketDeleteRequest(emailPacket.getDhtKey(), unencryptedPacket.getDeleteAuthorization());
    packetFolder.packetReceived(delRequest, sender, System.currentTimeMillis());
    assertEquals(0, packetFolder.getElements().size());
}
Also used : EmailPacketDeleteRequest(i2p.bote.packet.dht.EmailPacketDeleteRequest) UniqueId(i2p.bote.UniqueId) Test(org.junit.Test)

Example 19 with UniqueId

use of i2p.bote.UniqueId in project i2p.i2p-bote by i2p.

the class RelayPacketFolderTest method setUp.

@Before
public void setUp() throws Exception {
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    testDir = new File(tempDir, "RelayPacketFolderTest-" + System.currentTimeMillis());
    folderDir = new File(testDir, "relay_pkt");
    folder = new RelayPacketFolder(folderDir);
    // make an EncryptedEmailPacket
    String base64Destination = "X3oKYQJ~1EAz7B1ZYGSrOTIMCW5Rnn2Svoc38dx5D9~zvz8vqiWcH-pCqQDwLgPWl9RTBzHtTmZcGRPXIv54i0XWeUfX6rTPDQGuZsnBMM0xrkH2FNLNFaJa0NgW3uKXWpNj9AI1AXUXzK-2MYTYoaZHx5SBoCaKfAGMcFJvTON1~kopxBxdBF9Q7T4~PJ3I2LeU-ycmUlehe9N9bIu7adUGyPGVl8Ka-UxwQromoJ~vSWHHl8HkwcDkW--v9Aj~wvFqxqriFkB1EeBiThi3V4XtVY~GUP4IkRj9YZGTsSBf3eS4xwXgnYWlB7IvxAGBfHY9MCg3lbAa1Dg~1IH6rhtXxsXUtGcXsz9yMZTxXHd~rGo~JrXeM1y~Vcenpr6tJcum6pxevkKzzT0qDegGPH3Zhqz7sSeeIaJEcPBUAkX89csqyFWFIjTMm6yZp2rW-QYUnVNLNTjf7vndYUAEICogAkq~btqpIzrGEpm3Pr9F23br3SpbOmdxQxg51AMmAAAA";
    Destination nextDestination = new Destination(base64Destination.substring(0, 516));
    long delayMilliseconds = TimeUnit.MILLISECONDS.convert(111, TimeUnit.MINUTES);
    String content = "Warum, warum, warum\n" + "Ist die Banane krumm?\n" + "Weil niemand in den Urwald zog\n" + "Und die Banane grade bog.\n";
    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;
    InputStream contentStream = new ByteArrayInputStream(content.getBytes());
    UnencryptedEmailPacket unencryptedPacket = new UnencryptedEmailPacket(contentStream, messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
    unencryptedPacket.setNumFragments(1);
    String base64EmailDest = "rIbyUukqtsacD-MDJJ8KbIP9d3WQQo~t~zysc3bNcF1mSwz9PcGJnvWCNhnG2nzbdUAIDouESZjLRnBr7-mxNS";
    EmailDestination recipient = new EmailDestination(base64EmailDest);
    emailPacket = new EncryptedEmailPacket(unencryptedPacket, recipient);
    // make a RelayRequest
    StoreRequest storeRequest = new StoreRequest(emailPacket);
    relayRequest = new RelayRequest(storeRequest, nextDestination, delayMilliseconds, 1000);
}
Also used : Destination(net.i2p.data.Destination) EmailDestination(i2p.bote.email.EmailDestination) UniqueId(i2p.bote.UniqueId) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) StoreRequest(i2p.bote.packet.dht.StoreRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) EmailDestination(i2p.bote.email.EmailDestination) UnencryptedEmailPacket(i2p.bote.packet.dht.UnencryptedEmailPacket) File(java.io.File) RelayRequest(i2p.bote.packet.relay.RelayRequest) Before(org.junit.Before)

Example 20 with UniqueId

use of i2p.bote.UniqueId in project i2p.i2p-bote by i2p.

the class StoreRequestTest method setUp.

@Before
public void setUp() throws Exception {
    byte[] emailContent = new byte[] { 2, 109, -80, -37, -106, 83, -33, -39, -94, -76, -112, -98, 99, 25, -61, 44, -92, -85, 1, 10, -128, -2, -27, -86, -126, -33, -11, 42, 56, 3, -97, -101, 111, 7, -96, 25, 121, 74, 89, -40, -33, 82, -50, -18, 49, 106, 13, -121, 53, -83, -2, 35, -7, 71, -71, 26, 90, 1 };
    UniqueId messageId = new UniqueId(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 }, 0);
    String base64Identity = "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";
    EmailIdentity identity = new EmailIdentity(base64Identity);
    EmailDestination destination = new EmailDestination(identity.getKey());
    int fragmentIndex = 0;
    UnencryptedEmailPacket emailPacket = new UnencryptedEmailPacket(new ByteArrayInputStream(emailContent), messageId, fragmentIndex, I2PBotePacket.MAX_DATAGRAM_SIZE);
    emailPacket.setNumFragments(1);
    dhtPacket = new EncryptedEmailPacket(emailPacket, destination);
    storeRequest = new StoreRequest(dhtPacket);
}
Also used : UniqueId(i2p.bote.UniqueId) ByteArrayInputStream(java.io.ByteArrayInputStream) EmailIdentity(i2p.bote.email.EmailIdentity) EmailDestination(i2p.bote.email.EmailDestination) Before(org.junit.Before)

Aggregations

UniqueId (i2p.bote.UniqueId)25 ByteArrayInputStream (java.io.ByteArrayInputStream)9 Before (org.junit.Before)9 EncryptedEmailPacket (i2p.bote.packet.dht.EncryptedEmailPacket)7 EmailDestination (i2p.bote.email.EmailDestination)6 Hash (net.i2p.data.Hash)6 UnencryptedEmailPacket (i2p.bote.packet.dht.UnencryptedEmailPacket)5 File (java.io.File)5 DataPacket (i2p.bote.packet.DataPacket)3 DeletionInfoPacket (i2p.bote.packet.dht.DeletionInfoPacket)3 DhtStorablePacket (i2p.bote.packet.dht.DhtStorablePacket)3 EmailPacketDeleteRequest (i2p.bote.packet.dht.EmailPacketDeleteRequest)3 IOException (java.io.IOException)3 Destination (net.i2p.data.Destination)3 EmailIdentity (i2p.bote.email.EmailIdentity)2 DeletionAwareDhtFolder (i2p.bote.folder.DeletionAwareDhtFolder)2 DhtStorageHandler (i2p.bote.network.DhtStorageHandler)2 ResponsePacket (i2p.bote.packet.ResponsePacket)2 DeleteRequest (i2p.bote.packet.dht.DeleteRequest)2 DeletionQuery (i2p.bote.packet.dht.DeletionQuery)2