Package org.hive2hive.core.security

Examples of org.hive2hive.core.security.HybridEncryptedContent


      logger.warn("Did not get an user profile task. User ID = '{}'.", userId);
      context.provideUserProfileTask(null);
    } else {
      logger.debug("Got encrypted user profile task. User ID = '{}'", userId);

      HybridEncryptedContent encrypted = (HybridEncryptedContent) content;
      PrivateKey key = null;
      try {
        key = networkManager.getSession().getKeyPair().getPrivate();
      } catch (NoSessionException e) {
        throw new ProcessExecutionException(e);
View Full Code Here


      logger.error("Could not roll back because no session.");
      return;
    }

    UserProfileTask upTask = context.consumeUserProfileTask();
    HybridEncryptedContent encrypted;
    try {
      encrypted = H2HEncryptionUtil.encryptHybrid(upTask, session.getKeyPair().getPublic());
    } catch (DataLengthException | InvalidKeyException | IllegalStateException
        | InvalidCipherTextException | IllegalBlockSizeException | BadPaddingException | IOException e) {
      logger.error("Could not encrypt the user profile task while rollback.");
      return;
    }

    String userId = networkManager.getUserId();
    DataManager dataManager;
    try {
      dataManager = networkManager.getDataManager();
    } catch (NoPeerConnectionException e) {
      logger.warn(
          "Rollback of remove user profile task failed. No connection. User ID = '{}', Content key = '{}'.",
          userId, upTask.getContentKey());
      return;
    }

    encrypted.setTimeToLive(upTask.getTimeToLive());
    boolean success = dataManager.putUserProfileTask(userId, upTask.getContentKey(), encrypted,
        upTask.getProtectionKey());
    if (success) {
      logger.debug(
          "Rollback of removing user profile task succeeded. User ID = '{}', Content key = '{}'.",
View Full Code Here

    try {
      logger.debug("Encrypting user profile task in a hybrid manner.");
      this.contentKey = userProfileTask.getContentKey();
      this.protectionKey = userProfileTask.getProtectionKey();
      DataManager dataManager = networkManager.getDataManager();
      HybridEncryptedContent encrypted = H2HEncryptionUtil.encryptHybrid(userProfileTask, publicKey);
      encrypted.setTimeToLive(userProfileTask.getTimeToLive());
      boolean success = dataManager.putUserProfileTask(userId, contentKey, encrypted, protectionKey);
      putPerformed = true;

      if (!success) {
        throw new PutFailedException();
View Full Code Here

    // prepare message
    prepareMessage(message);
    message.increaseRoutedSendingCounter();

    // encrypt the message with the given public key
    HybridEncryptedContent encryptedMessage = signAndEncryptMessage(message, targetPublicKey);
    if (encryptedMessage == null)
      return false;

    // send message to the peer which is responsible for the given key
    FutureSend futureSend = networkManager.getConnection().getPeer()
View Full Code Here

    // prepare message
    prepareMessage(message);
    message.increaseDirectSendingCounter();

    // encrypt the message with the given public key
    HybridEncryptedContent encryptedMessage = signAndEncryptMessage(message, targetPublicKey);
    if (encryptedMessage == null)
      return false;

    // send message directly to the peer with the given peer address
    FutureDirect futureDirect = networkManager.getConnection().getPeer()
View Full Code Here

    }

    try {
      // asymmetrically encrypt message
      byte[] messageBytes = EncryptionUtil.serializeObject(message);
      HybridEncryptedContent encryptedMessage = EncryptionUtil.encryptHybrid(messageBytes,
          targetPublicKey, H2HConstants.KEYLENGTH_HYBRID_AES);

      // create signature
      try {
        byte[] signature = EncryptionUtil.sign(messageBytes, session.getKeyPair().getPrivate());
        encryptedMessage.setSignature(session.getUserId(), signature);
      } catch (InvalidKeyException | SignatureException e1) {
        logger.error("An exception occured while signing the message. The message will not be sent.",
            e1);
        return null;
      }
View Full Code Here

      logger.warn("Currently no user is logged in! Keys for decryption needed. Node ID = '{}'.",
          networkManager.getNodeId());
      return AcceptanceReply.FAILURE;
    }

    HybridEncryptedContent encryptedMessage = (HybridEncryptedContent) request;

    // get signature
    String senderId = encryptedMessage.getUserId();
    byte[] signature = encryptedMessage.getSignature();
    if (senderId == null || signature == null) {
      logger.warn("No signature for message.");
      return AcceptanceReply.FAILURE_SIGNATURE;
    }
View Full Code Here

    KeyPair protectionKeysNew = EncryptionUtil.generateRSAKeyPair();

    // generate a fake chunk
    Chunk chunk = new Chunk(proxy.getNodeId(), NetworkTestUtil.randomString().getBytes(), 0);
    // encrypt the chunk
    HybridEncryptedContent encryptedChunk = H2HEncryptionUtil.encryptHybrid(chunk,
        encryptionKeys.getPublic());

    // initialize put
    Parameters parameters = new Parameters().setLocationKey(chunk.getId())
        .setContentKey(H2HConstants.FILE_CHUNK).setProtectionKeys(protectionKeysOld)
View Full Code Here

    fileVersions.add(new FileVersion(0, 123, System.currentTimeMillis(), metaChunks1));
    fileVersions.add(new FileVersion(1, 123, System.currentTimeMillis(), metaChunks2));
    MetaFileSmall metaFileSmall = new MetaFileSmall(metaFileEncryptionKeys.getPublic(), fileVersions,
        chunkEncryptionKeys);
    // encrypt the meta file
    HybridEncryptedContent encryptedMetaFile = H2HEncryptionUtil.encryptHybrid(metaFileSmall,
        metaFileEncryptionKeys.getPublic());
    encryptedMetaFile.generateVersionKey();

    // initialize put
    Parameters parameters = new Parameters()
        .setLocationKey(H2HEncryptionUtil.key2String(metaFileSmall.getId()))
        .setContentKey(H2HConstants.META_FILE).setVersionKey(encryptedMetaFile.getVersionKey())
        .setProtectionKeys(protectionKeysOld).setData(encryptedMetaFile);
    // indicate to generate hash
    parameters.setHashFlag(true);
    // put encrypted meta file into network
    getter.getDataManager().putUnblocked(parameters).awaitUninterruptibly();

    // verify put
    Assert.assertNotNull(getter.getDataManager().getUnblocked(parameters).awaitUninterruptibly()
        .getData());

    // initialize a fake process context
    BasePKUpdateContext context = new TestMetaFilePKUpdateContext(protectionKeysOld, protectionKeysNew,
        metaFileSmall, parameters.getHash(), encryptedMetaFile.getVersionKey());
    // create a change protection keys process step
    ChangeProtectionKeysStep step = new ChangeProtectionKeysStep(context, getter.getDataManager());
    // run process, should not fail
    UseCaseTestUtil.executeProcessTillSucceded(step);
View Full Code Here

    }

    if (chunk != null) {
      try {
        // encrypt the chunk prior to put such that nobody can read it
        HybridEncryptedContent encryptedContent = H2HEncryptionUtil.encryptHybrid(chunk, context
            .consumeChunkKeys().getPublic());

        logger.debug("Uploading chunk {} of file {}.", chunk.getOrder(), file.getName());
        Parameters parameters = new Parameters().setLocationKey(chunk.getId())
            .setContentKey(H2HConstants.FILE_CHUNK).setData(encryptedContent)
View Full Code Here

TOP

Related Classes of org.hive2hive.core.security.HybridEncryptedContent

Copyright © 2018 www.massapicom. 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.