Search in sources :

Example 1 with EmailPacketDeleteRequest

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

the class EmailPacketFolder method process.

/**
 * Deletes email packets.
 * @param delRequest An instance of {@link EmailPacketDeleteRequest}
 */
@Override
public synchronized void process(DeleteRequest delRequest) {
    log.debug("Processing delete request: " + delRequest);
    if (!(delRequest instanceof EmailPacketDeleteRequest))
        log.error("Invalid type of delete request for EmailPacketFolder: " + delRequest.getClass());
    EmailPacketDeleteRequest emailPacketDelRequest = (EmailPacketDeleteRequest) delRequest;
    // see if the packet exists
    Hash dhtKey = emailPacketDelRequest.getDhtKey();
    DhtStorablePacket storedPacket = retrieve(dhtKey);
    if (storedPacket instanceof EncryptedEmailPacket) {
        // verify
        Hash verificationHash = ((EncryptedEmailPacket) storedPacket).getDeleteVerificationHash();
        UniqueId delAuthorization = emailPacketDelRequest.getAuthorization();
        boolean valid = Util.isDeleteAuthorizationValid(verificationHash, delAuthorization);
        if (valid)
            delete(dhtKey, delAuthorization);
        else
            log.debug("Invalid Delete Authorization in EmailPacketDeleteRequest. Should be: <" + verificationHash.toBase64() + ">");
    } else if (storedPacket != null)
        log.debug("EncryptedEmailPacket expected for DHT key <" + dhtKey + ">, found " + storedPacket.getClass().getSimpleName());
}
Also used : EmailPacketDeleteRequest(i2p.bote.packet.dht.EmailPacketDeleteRequest) DhtStorablePacket(i2p.bote.packet.dht.DhtStorablePacket) UniqueId(i2p.bote.UniqueId) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) Hash(net.i2p.data.Hash)

Example 2 with EmailPacketDeleteRequest

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

the class EmailPacketFolder method packetReceived.

/**
 * Handles delete requests
 */
@Override
public void packetReceived(CommunicationPacket packet, Destination sender, long receiveTime) {
    if (packet instanceof EmailPacketDeleteRequest) {
        EmailPacketDeleteRequest delRequest = (EmailPacketDeleteRequest) packet;
        process(delRequest);
    }
}
Also used : EmailPacketDeleteRequest(i2p.bote.packet.dht.EmailPacketDeleteRequest)

Example 3 with EmailPacketDeleteRequest

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

the class EmailPacketFolder method storeAndCreateDeleteRequest.

@Override
public DeleteRequest storeAndCreateDeleteRequest(DhtStorablePacket packetToStore) {
    if (!(packetToStore instanceof EncryptedEmailPacket))
        throw new IllegalArgumentException("Invalid packet type: " + packetToStore.getClass().getSimpleName() + "; this folder only stores packets of type " + EncryptedEmailPacket.class.getSimpleName() + ".");
    DeleteRequest delRequest = null;
    // read the deletion info file for the email packet's DHT key
    Hash dhtKey = packetToStore.getDhtKey();
    String delFileName = getDeletionFileName(dhtKey);
    DeletionInfoPacket delInfo = createDelInfoPacket(delFileName);
    if (delInfo != null) {
        DeletionRecord delRecord = delInfo.getEntry(dhtKey);
        if (delRecord != null)
            delRequest = new EmailPacketDeleteRequest(delRecord.dhtKey, delRecord.delAuthorization);
    } else
        // if the DHT key has not been recorded as deleted, store the email packet
        store(packetToStore);
    return delRequest;
}
Also used : EmailPacketDeleteRequest(i2p.bote.packet.dht.EmailPacketDeleteRequest) DeletionInfoPacket(i2p.bote.packet.dht.DeletionInfoPacket) DeletionRecord(i2p.bote.packet.dht.DeletionRecord) EncryptedEmailPacket(i2p.bote.packet.dht.EncryptedEmailPacket) Hash(net.i2p.data.Hash) DeleteRequest(i2p.bote.packet.dht.DeleteRequest) EmailPacketDeleteRequest(i2p.bote.packet.dht.EmailPacketDeleteRequest)

Example 4 with EmailPacketDeleteRequest

use of i2p.bote.packet.dht.EmailPacketDeleteRequest 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[] email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1Pd3fyc1fXp1xVInrYWUZvjSoBcJaiqlhvTMMsjzLbiG~a~HoJz67Dvl6GGtcBad1hjhSzwKN9vLpM-sFMqDCBDHDssVZEXk5EXQYltUZVvfaFJYimDfdiM~F23x0Wz2tM5LQXJ86-nn7d5DA-CspMg1xqkAr1iMkgYacOL~2u2PL1ImI1SMZGmY839ekgQlr1gWWU1evQQTUdHH6Bszs0vSW6wymbSTziJopMqv86f2y6SHDEq8qZzYdKhAFQbjFtvNwn7gEJqlhzzI1bO8zjG3xZTiaCpSrmE98L8PZhEIfXvN3PUADSuzsbHmuHQ=");
    EncryptedEmailPacket 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 5 with EmailPacketDeleteRequest

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

Aggregations

EmailPacketDeleteRequest (i2p.bote.packet.dht.EmailPacketDeleteRequest)5 UniqueId (i2p.bote.UniqueId)3 EncryptedEmailPacket (i2p.bote.packet.dht.EncryptedEmailPacket)3 DeleteRequest (i2p.bote.packet.dht.DeleteRequest)2 DeletionInfoPacket (i2p.bote.packet.dht.DeletionInfoPacket)2 DeletionRecord (i2p.bote.packet.dht.DeletionRecord)2 Hash (net.i2p.data.Hash)2 Test (org.junit.Test)2 DataPacket (i2p.bote.packet.DataPacket)1 DhtStorablePacket (i2p.bote.packet.dht.DhtStorablePacket)1 File (java.io.File)1