public void put(Collection<EncryptedEmailPacket> emailPackets) { for (EncryptedEmailPacket emailPacket: emailPackets) { Hash emailPacketKey = emailPacket.getDhtKey(); Hash delVerificationHash = emailPacket.getDeleteVerificationHash(); IndexPacketEntry entry = new IndexPacketEntry(emailPacketKey, delVerificationHash); put(entry); } }
/** * Adds a new entry containing the DHT key and Delete Verification Hash of an Email Packet.<br/> * If an entry with the same DHT key exists already, nothing happens. * @param emailPacket */ public void put(EncryptedEmailPacket emailPacket) { Hash emailPacketKey = emailPacket.getDhtKey(); Hash delVerificationHash = emailPacket.getDeleteVerificationHash(); IndexPacketEntry newEntry = new IndexPacketEntry(emailPacketKey, delVerificationHash); put(newEntry); }
/** * 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()); }
@Test public void testDeleteVerificationHash() { for (int i=0; i<encryptedPackets.length; i++) { EncryptedEmailPacket packet = encryptedPackets[i]; Hash expectedHash = SHA256Generator.getInstance().calculateHash(plaintextPacket.getDeleteAuthorization().toByteArray()); assertEquals("The delete authorization key does not hash to the delete verification hash!", expectedHash, packet.getDeleteVerificationHash()); } }
send(emailPacket, hops, minDelay, maxDelay, relayRedundancy); indexPacket.put(emailPacket); metadata.addPacketInfo(recipientDest, emailPacket.getDhtKey(), emailPacket.getDeleteVerificationHash());