Exemplo n.º 1
0
  @Override
  public void inviteUser(
      String ownerAlias,
      PrivateKey ownerPrivSigKey,
      PublicKey ownerPubEncKey,
      PrivateKey ownerPrivEncKey,
      String alias,
      PublicKey userPubEncKey,
      PublicKey userPubSigKey)
      throws ShareMetaDataException {

    // Check if called by owner
    if (!Utils.keysMatch(shareMetaData.ownerPubSigKey, ownerPrivSigKey)) {
      throw new ShareMetaDataException("This method can only be called by the share owner!");
    }

    SharePartList spl = shareMetaData.getSharePartList();
    // Check if user alias already exists
    if (spl.getPublicKey(alias) == null) {
      spl.add(userPubSigKey, alias);
    }

    // Create deviceList and sign for user
    HashMap<String, PublicKey> dkList = new HashMap<String, PublicKey>();
    dkList.put(IVolume.MASTER_KEY, userPubEncKey);
    DeviceList devices = shareMetaData.createDeviceList(userPubSigKey, dkList);

    try {
      shareMetaData.addObfuscationKey(ownerPubEncKey, ownerPrivEncKey, userPubEncKey);
    } catch (SymmetricKeyEncryptionException | SymmetricKeyDecryptionException e) {
      throw new ShareMetaDataException("Could not add encrypted obfuscation key for new user", e);
    }

    // add encrypted sharekey for device
    try {
      this.shareMetaData.shareKeys.addDevice(ownerPubEncKey, ownerPrivEncKey, userPubEncKey);
    } catch (Exception e) {
      throw new ShareMetaDataException("Could not add encrypted share keys for new user", e);
    }

    // Sign everything
    try {
      spl.sign(ownerPrivSigKey);
    } catch (SignatureException e) {
      throw new ShareMetaDataException("Could not add new user to ShareParticipantList.", e);
    }

    try {
      devices.sign(ownerPrivSigKey, shareMetaData.shareKeys, shareMetaData.obfuscationKeys);
    } catch (SignatureException e) {
      throw new ShareMetaDataException("Could not sign devicelist", e);
    }

    this.shareMetaData.persist();
    this.shareMetaData.persist(devices);
  }
Exemplo n.º 2
0
  @Override
  public void addDevice(
      String alias,
      PublicKey masterPubSigKey,
      PrivateKey masterPrivSigKey,
      String newDeviceAlias,
      PublicKey newDevicePubKey,
      PublicKey masterPubEncKey,
      PrivateKey masterPrivEncKey)
      throws ShareMetaDataException {

    if (IVolume.MASTER_KEY.equals(newDeviceAlias)) {
      throw new IllegalArgumentException("Illegal alias for device. Choose another alias");
    }

    // verify matching public/private keys
    if (!Utils.keysMatch(masterPubSigKey, masterPrivSigKey)) {
      throw new IllegalArgumentException(
          "User's master private and public signature keys do not match!");
    }
    if (!Utils.keysMatch(masterPubEncKey, masterPrivEncKey)) {
      throw new IllegalArgumentException(
          "User's master private and public encryption keys do not match!");
    }

    // verify integrity of ShareParticipantList
    SharePartList sharePartList = shareMetaData.getSharePartList();
    try {
      SignatureHelper.verify(
          sharePartList, sharePartList.getSignature(), shareMetaData.ownerPubSigKey);
    } catch (InvalidKeyException
        | NoSuchAlgorithmException
        | SignatureException
        | SerializationException e) {
      throw new ShareMetaDataException("Could not verify ShareParticipantsList signature", e);
    }

    // check if masterPubSigKey is in ShareParticipants
    if (!sharePartList.getPublicKey(alias).equals(masterPubSigKey)) {
      throw new ShareMetaDataException(
          "Given user singature publickey is not " + "in sharepartiticapnts list");
    }

    // Get DeviceList for user
    DeviceList deviceList = shareMetaData.getDeviceLists().get(masterPubSigKey);
    if (deviceList == null) {
      throw new ShareMetaDataException(
          "DeviceList for user " + alias + " was empty, which should never be the case.");
    }

    // add device
    deviceList.addDevice(newDeviceAlias, newDevicePubKey);

    // add encrypted Obfuscation key for new device
    try {
      shareMetaData.addObfuscationKey(masterPubEncKey, masterPrivEncKey, newDevicePubKey);
    } catch (SymmetricKeyEncryptionException | SymmetricKeyDecryptionException e) {
      throw new ShareMetaDataException("Could not add encrypted obfuscation key for new device", e);
    }

    // add encrypted sharekey for device
    try {
      this.shareMetaData.shareKeys.addDevice(masterPubEncKey, masterPrivEncKey, newDevicePubKey);
    } catch (Exception e) {
      throw new ShareMetaDataException("Could not add encrypted share keys for new device", e);
    }
    // Sign everything
    try {
      deviceList.sign(masterPrivSigKey, shareMetaData.shareKeys, shareMetaData.obfuscationKeys);
    } catch (SignatureException e) {
      throw new ShareMetaDataException("Could not sign devicelist", e);
    }

    this.shareMetaData.persist(deviceList);
  }