@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); }