Examples of EncryptedNetworkContent


Examples of org.hive2hive.core.security.EncryptedNetworkContent

    if (loadedContent == null) {
      throw new ProcessExecutionException("User profile not found.");
    } else {
      // decrypt user profile
      EncryptedNetworkContent encryptedContent = (EncryptedNetworkContent) loadedContent;

      SecretKey decryptionKey = PasswordUtil.generateAESKeyFromPassword(credentials.getPassword(),
          credentials.getPin(), H2HConstants.KEYLENGTH_USER_PROFILE);

      NetworkContent decryptedContent = null;
View Full Code Here

Examples of org.hive2hive.core.security.EncryptedNetworkContent

        entry.setGetError(new GetFailedException("User profile not found. Got null."));
      } else {
        try {
          logger.trace("Decrypting user profile with 256-bit AES key from password. user id = '{}'",
              credentials.getUserId());
          EncryptedNetworkContent encrypted = (EncryptedNetworkContent) content;
          NetworkContent decrypted = H2HEncryptionUtil.decryptAES(encrypted, userProfileEncryptionKey);
          UserProfile userProfile = (UserProfile) decrypted;
          userProfile.setVersionKey(content.getVersionKey());
          userProfile.setBasedOnKey(content.getBasedOnKey());
View Full Code Here

Examples of org.hive2hive.core.security.EncryptedNetworkContent

   */
  public void put(PutQueueEntry entry) {
    logger.debug("Put user profile. user id = '{}'", credentials.getUserId());
    try {
      logger.trace("Encrypting user profile with 256bit AES key from password. user id ='{}'", credentials.getUserId());
      EncryptedNetworkContent encryptedUserProfile = H2HEncryptionUtil.encryptAES(entry.getUserProfile(),
          userProfileEncryptionKey);

      encryptedUserProfile.setBasedOnKey(entry.getUserProfile().getVersionKey());
      encryptedUserProfile.generateVersionKey();

      IParameters parameters = new Parameters().setLocationKey(credentials.getProfileLocationKey())
          .setContentKey(H2HConstants.USER_PROFILE).setVersionKey(encryptedUserProfile.getVersionKey())
          .setData(encryptedUserProfile).setProtectionKeys(entry.getUserProfile().getProtectionKeys())
          .setTTL(entry.getUserProfile().getTimeToLive());

      boolean success = dataManager.put(parameters);
      if (!success) {
        entry.setPutError(new PutFailedException("Put failed."));
      } else {
        // cache user profile
        cachedUserProfile = entry.getUserProfile();
        cachedUserProfile.setBasedOnKey(encryptedUserProfile.getBasedOnKey());
        cachedUserProfile.setVersionKey(encryptedUserProfile.getVersionKey());
      }
    } catch (DataLengthException | IllegalStateException | InvalidCipherTextException | IOException e) {
      logger.error("Cannot encrypt the user profile. reason = '{}'", e.getMessage());
      entry.setPutError(new PutFailedException(String.format("Cannot encrypt the user profile. reason = '%s'",
          e.getMessage())));
View Full Code Here

Examples of org.hive2hive.core.security.EncryptedNetworkContent

    FutureGet global = client.getDataManager().getUnblocked(
        new Parameters().setLocationKey(credentials.getProfileLocationKey()).setContentKey(
            H2HConstants.USER_PROFILE));
    global.awaitUninterruptibly();
    global.getFutureRequests().awaitUninterruptibly();
    EncryptedNetworkContent found = (EncryptedNetworkContent) global.getData().object();
    Assert.assertNotNull(found);

    // decrypt it using the same password as set above
    SecretKey decryptionKeys = PasswordUtil.generateAESKeyFromPassword(credentials.getPassword(),
        credentials.getPin(), H2HConstants.KEYLENGTH_USER_PROFILE);
View Full Code Here

Examples of org.hive2hive.core.security.EncryptedNetworkContent

    UserProfile testProfile = new UserProfile(credentials.getUserId());

    // add them already to the DHT
    SecretKey encryptionKeys = PasswordUtil.generateAESKeyFromPassword(credentials.getPassword(), credentials.getPin(),
        H2HConstants.KEYLENGTH_USER_PROFILE);
    EncryptedNetworkContent encrypted = H2HEncryptionUtil.encryptAES(testProfile, encryptionKeys);
    FuturePut putGlobal = putter.getDataManager().putUnblocked(
        new Parameters().setLocationKey(credentials.getProfileLocationKey())
            .setContentKey(H2HConstants.USER_PROFILE).setData(encrypted));
    putGlobal.awaitUninterruptibly();
View Full Code Here

Examples of org.hive2hive.core.security.EncryptedNetworkContent

    // encrypt user profile
    SecretKey encryptionKey = PasswordUtil.generateAESKeyFromPassword(credentials.getPassword(),
        credentials.getPin(), H2HConstants.KEYLENGTH_USER_PROFILE);

    EncryptedNetworkContent encryptedProfile = null;
    try {
      encryptedProfile = H2HEncryptionUtil.encryptAES(userProfile, encryptionKey);
    } catch (DataLengthException | IllegalStateException | InvalidCipherTextException | IOException e) {
      throw new ProcessExecutionException("User profile could not be encrypted.");
    }

    try {
      encryptedProfile.generateVersionKey();
    } catch (IOException e) {
      throw new ProcessExecutionException("User profile version key could not be generated.", e);
    }

    // assign ttl value
    encryptedProfile.setTimeToLive(userProfile.getTimeToLive());
   
    // put encrypted user profile
    try {
      put(credentials.getProfileLocationKey(), H2HConstants.USER_PROFILE, encryptedProfile,
          userProfile.getProtectionKeys());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.