@Test(expected = PutFailedException.class) public void testContentProtectionPutWithoutProtectionKey() throws Exception { NetworkManager node = NetworkTestUtil.getRandomNode(network); String locationKey = randomString(); String contentKey = randomString(); AESEncryptedVersionManager<H2HTestData> versionManager = new AESEncryptedVersionManager<H2HTestData>( node.getDataManager(), encryptionKey, locationKey, contentKey); H2HTestData version0 = new H2HTestData("version0"); versionManager.put(version0, protectionKeys); H2HTestData version1 = new H2HTestData("version1"); version1.setVersionKey(version0.getVersionKey()); versionManager.put(version1, null); }
public void put(T networkContent, KeyPair protectionKeys) throws PutFailedException { try { EncryptedNetworkContent encrypted = encryption.encryptAES(networkContent, encryptionKey); encrypted.setBasedOnKey(networkContent.getBasedOnKey()); encrypted.setVersionKey(networkContent.getVersionKey()); encrypted.generateVersionKey(); IParameters parameters = new Parameters().setLocationKey(this.parameters.getLocationKey()) .setContentKey(this.parameters.getContentKey()).setVersionKey(encrypted.getVersionKey()) .setBasedOnKey(encrypted.getBasedOnKey()).setNetworkContent(encrypted).setProtectionKeys(protectionKeys) .setTTL(networkContent.getTimeToLive()).setPrepareFlag(true); H2HPutStatus status = dataManager.put(parameters); if (status.equals(H2HPutStatus.FAILED)) { throw new PutFailedException("Put failed."); } else if (status.equals(H2HPutStatus.VERSION_FORK)) { logger.warn("Version fork after put detected. Rejecting put"); if (!dataManager.remove(parameters)) { logger.warn("Removing of conflicting version failed."); } throw new VersionForkAfterPutException(); } else { networkContent.setVersionKey(encrypted.getVersionKey()); networkContent.setBasedOnKey(encrypted.getBasedOnKey()); digestCache.put(parameters.getVersionKey(), new HashSet<Number160>(parameters.getData().basedOnSet())); contentCache.put(parameters.getVersionKey(), networkContent); encryptedContentCache.put(parameters.getVersionKey(), encrypted); } } catch (GeneralSecurityException | IOException e) { logger.error("Cannot encrypt the user profile. reason = '{}'", e.getMessage()); throw new PutFailedException(String.format("Cannot encrypt the user profile. reason = '%s'", e.getMessage())); } }
AESEncryptedVersionManager extends BaseVersionManager<T> { public void put(T networkContent, KeyPair protectionKeys) throws PutFailedException { try { EncryptedNetworkContent encrypted = encryption.encryptAES(networkContent, encryptionKey); encrypted.setBasedOnKey(networkContent.getBasedOnKey()); encrypted.setVersionKey(networkContent.getVersionKey()); encrypted.generateVersionKey(); IParameters parameters = new Parameters().setLocationKey(this.parameters.getLocationKey()) .setContentKey(this.parameters.getContentKey()).setVersionKey(encrypted.getVersionKey()) .setBasedOnKey(encrypted.getBasedOnKey()).setNetworkContent(encrypted).setProtectionKeys(protectionKeys) .setTTL(networkContent.getTimeToLive()).setPrepareFlag(true); H2HPutStatus status = dataManager.put(parameters); if (status.equals(H2HPutStatus.FAILED)) { throw new PutFailedException("Put failed."); } else if (status.equals(H2HPutStatus.VERSION_FORK)) { logger.warn("Version fork after put detected. Rejecting put"); if (!dataManager.remove(parameters)) { logger.warn("Removing of conflicting version failed."); } throw new VersionForkAfterPutException(); } else { networkContent.setVersionKey(encrypted.getVersionKey()); networkContent.setBasedOnKey(encrypted.getBasedOnKey()); digestCache.put(parameters.getVersionKey(), new HashSet<Number160>(parameters.getData().basedOnSet())); contentCache.put(parameters.getVersionKey(), networkContent); encryptedContentCache.put(parameters.getVersionKey(), encrypted); } } catch (GeneralSecurityException | IOException e) { logger.error("Cannot encrypt the user profile. reason = '{}'", e.getMessage()); throw new PutFailedException(String.format("Cannot encrypt the user profile. reason = '%s'", e.getMessage())); } } }
AESEncryptedVersionManager extends BaseVersionManager<T> { public void put(T networkContent, KeyPair protectionKeys) throws PutFailedException { try { EncryptedNetworkContent encrypted = encryption.encryptAES(networkContent, encryptionKey); encrypted.setBasedOnKey(networkContent.getBasedOnKey()); encrypted.setVersionKey(networkContent.getVersionKey()); encrypted.generateVersionKey(); IParameters parameters = new Parameters().setLocationKey(this.parameters.getLocationKey()) .setContentKey(this.parameters.getContentKey()).setVersionKey(encrypted.getVersionKey()) .setBasedOnKey(encrypted.getBasedOnKey()).setNetworkContent(encrypted).setProtectionKeys(protectionKeys) .setTTL(networkContent.getTimeToLive()).setPrepareFlag(true); H2HPutStatus status = dataManager.put(parameters); if (status.equals(H2HPutStatus.FAILED)) { throw new PutFailedException("Put failed."); } else if (status.equals(H2HPutStatus.VERSION_FORK)) { logger.warn("Version fork after put detected. Rejecting put"); if (!dataManager.remove(parameters)) { logger.warn("Removing of conflicting version failed."); } throw new VersionForkAfterPutException(); } else { networkContent.setVersionKey(encrypted.getVersionKey()); networkContent.setBasedOnKey(encrypted.getBasedOnKey()); digestCache.put(parameters.getVersionKey(), new HashSet<Number160>(parameters.getData().basedOnSet())); contentCache.put(parameters.getVersionKey(), networkContent); encryptedContentCache.put(parameters.getVersionKey(), encrypted); } } catch (GeneralSecurityException | IOException e) { logger.error("Cannot encrypt the user profile. reason = '{}'", e.getMessage()); throw new PutFailedException(String.format("Cannot encrypt the user profile. reason = '%s'", e.getMessage())); } } AESEncryptedVersionManager(DataManager dataManager, SecretKey encryptionKey, String locationKey,
			String contentKey);  AESEncryptedVersionManager(DataManager dataManager, IH2HEncryption encryption, SecretKey encryptionKey,
			String locationKey, String contentKey); }
AESEncryptedVersionManager extends BaseVersionManager<T> { public void put(T networkContent, KeyPair protectionKeys) throws PutFailedException { try { EncryptedNetworkContent encrypted = encryption.encryptAES(networkContent, encryptionKey); encrypted.setBasedOnKey(networkContent.getBasedOnKey()); encrypted.setVersionKey(networkContent.getVersionKey()); encrypted.generateVersionKey(); IParameters parameters = new Parameters().setLocationKey(this.parameters.getLocationKey()) .setContentKey(this.parameters.getContentKey()).setVersionKey(encrypted.getVersionKey()) .setBasedOnKey(encrypted.getBasedOnKey()).setNetworkContent(encrypted).setProtectionKeys(protectionKeys) .setTTL(networkContent.getTimeToLive()).setPrepareFlag(true); H2HPutStatus status = dataManager.put(parameters); if (status.equals(H2HPutStatus.FAILED)) { throw new PutFailedException("Put failed."); } else if (status.equals(H2HPutStatus.VERSION_FORK)) { logger.warn("Version fork after put detected. Rejecting put"); if (!dataManager.remove(parameters)) { logger.warn("Removing of conflicting version failed."); } throw new VersionForkAfterPutException(); } else { networkContent.setVersionKey(encrypted.getVersionKey()); networkContent.setBasedOnKey(encrypted.getBasedOnKey()); digestCache.put(parameters.getVersionKey(), new HashSet<Number160>(parameters.getData().basedOnSet())); contentCache.put(parameters.getVersionKey(), networkContent); encryptedContentCache.put(parameters.getVersionKey(), encrypted); } } catch (GeneralSecurityException | IOException e) { logger.error("Cannot encrypt the user profile. reason = '{}'", e.getMessage()); throw new PutFailedException(String.format("Cannot encrypt the user profile. reason = '%s'", e.getMessage())); } } AESEncryptedVersionManager(DataManager dataManager, SecretKey encryptionKey, String locationKey,
			String contentKey);  AESEncryptedVersionManager(DataManager dataManager, IH2HEncryption encryption, SecretKey encryptionKey,
			String locationKey, String contentKey); @SuppressWarnings("unchecked") T get(); void put(T networkContent, KeyPair protectionKeys); }
AESEncryptedVersionManager extends BaseVersionManager<T> { public void put(T networkContent, KeyPair protectionKeys) throws PutFailedException { try { EncryptedNetworkContent encrypted = encryption.encryptAES(networkContent, encryptionKey); encrypted.setBasedOnKey(networkContent.getBasedOnKey()); encrypted.setVersionKey(networkContent.getVersionKey()); encrypted.generateVersionKey(); IParameters parameters = new Parameters().setLocationKey(this.parameters.getLocationKey()) .setContentKey(this.parameters.getContentKey()).setVersionKey(encrypted.getVersionKey()) .setBasedOnKey(encrypted.getBasedOnKey()).setNetworkContent(encrypted).setProtectionKeys(protectionKeys) .setTTL(networkContent.getTimeToLive()).setPrepareFlag(true); H2HPutStatus status = dataManager.put(parameters); if (status.equals(H2HPutStatus.FAILED)) { throw new PutFailedException("Put failed."); } else if (status.equals(H2HPutStatus.VERSION_FORK)) { logger.warn("Version fork after put detected. Rejecting put"); if (!dataManager.remove(parameters)) { logger.warn("Removing of conflicting version failed."); } throw new VersionForkAfterPutException(); } else { networkContent.setVersionKey(encrypted.getVersionKey()); networkContent.setBasedOnKey(encrypted.getBasedOnKey()); digestCache.put(parameters.getVersionKey(), new HashSet<Number160>(parameters.getData().basedOnSet())); contentCache.put(parameters.getVersionKey(), networkContent); encryptedContentCache.put(parameters.getVersionKey(), encrypted); } } catch (GeneralSecurityException | IOException e) { logger.error("Cannot encrypt the user profile. reason = '{}'", e.getMessage()); throw new PutFailedException(String.format("Cannot encrypt the user profile. reason = '%s'", e.getMessage())); } } AESEncryptedVersionManager(DataManager dataManager, SecretKey encryptionKey, String locationKey,
			String contentKey);  AESEncryptedVersionManager(DataManager dataManager, IH2HEncryption encryption, SecretKey encryptionKey,
			String locationKey, String contentKey); @SuppressWarnings("unchecked") T get(); void put(T networkContent, KeyPair protectionKeys);  }