/** Changes wallet AES encryption key, this is atomic operation. */ public void changeEncryptionKey(KeyCrypter keyCrypter, KeyParameter currentAesKey, KeyParameter newAesKey){ keyChainGroupLock.lock(); try { decrypt(currentAesKey); encrypt(keyCrypter, newAesKey); } finally { keyChainGroupLock.unlock(); } }
/** Changes wallet encryption password, this is atomic operation. */ public void changeEncryptionPassword(CharSequence currentPassword, CharSequence newPassword){ keyChainGroupLock.lock(); try { decrypt(currentPassword); encrypt(newPassword); } finally { keyChainGroupLock.unlock(); } }
/** Changes wallet AES encryption key, this is atomic operation. */ public void changeEncryptionKey(KeyCrypter keyCrypter, KeyParameter currentAesKey, KeyParameter newAesKey){ keyChainGroupLock.lock(); try { decrypt(currentAesKey); encrypt(keyCrypter, newAesKey); } finally { keyChainGroupLock.unlock(); } }
/** Changes wallet encryption password, this is atomic operation. */ public void changeEncryptionPassword(CharSequence currentPassword, CharSequence newPassword){ keyChainGroupLock.lock(); try { decrypt(currentPassword); encrypt(newPassword); } finally { keyChainGroupLock.unlock(); } }
/** Changes wallet encryption password, this is atomic operation. */ public void changeEncryptionPassword(CharSequence currentPassword, CharSequence newPassword){ keyChainGroupLock.lock(); try { decrypt(currentPassword); encrypt(newPassword); } finally { keyChainGroupLock.unlock(); } }
/** Changes wallet AES encryption key, this is atomic operation. */ public void changeEncryptionKey(KeyCrypter keyCrypter, KeyParameter currentAesKey, KeyParameter newAesKey){ keyChainGroupLock.lock(); try { decrypt(currentAesKey); encrypt(keyCrypter, newAesKey); } finally { keyChainGroupLock.unlock(); } }
/** Changes wallet encryption password, this is atomic operation. */ public void changeEncryptionPassword(CharSequence currentPassword, CharSequence newPassword){ keyChainGroupLock.lock(); try { decrypt(currentPassword); encrypt(newPassword); } finally { keyChainGroupLock.unlock(); } }
private static void encrypt() { if (password == null) { System.err.println("You must provide a --password"); return; } if (wallet.isEncrypted()) { System.err.println("This wallet is already encrypted."); return; } wallet.encrypt(password); }
/** Changes wallet AES encryption key, this is atomic operation. */ public void changeEncryptionKey(KeyCrypter keyCrypter, KeyParameter currentAesKey, KeyParameter newAesKey){ keyChainGroupLock.lock(); try { decrypt(currentAesKey); encrypt(keyCrypter, newAesKey); } finally { keyChainGroupLock.unlock(); } }
@Test public void testEncryptedClientWallet() throws Exception { // Encrypt the client wallet String mySecretPw = "MySecret"; wallet.encrypt(mySecretPw); KeyParameter userKeySetup = wallet.getKeyCrypter().deriveKey(mySecretPw); exectuteSimpleChannelTest(userKeySetup); }
@Test(expected = KeyCrypterException.class) public void addUnencryptedKeyToEncryptedWallet() throws Exception { Wallet encryptedWallet = new Wallet(PARAMS); encryptedWallet.encrypt(PASSWORD1); ECKey key1 = new ECKey(); encryptedWallet.importKey(key1); }
@Test public void basicSpendingWithEncryptedWallet() throws Exception { Wallet encryptedWallet = new Wallet(PARAMS); encryptedWallet.encrypt(PASSWORD1); Address myEncryptedAddress = encryptedWallet.freshReceiveKey().toAddress(PARAMS); basicSpendingCommon(encryptedWallet, myEncryptedAddress, OTHER_ADDRESS, encryptedWallet); }
@Test public void changePasswordTest() { Wallet encryptedWallet = new Wallet(PARAMS); encryptedWallet.encrypt(PASSWORD1); CharSequence newPassword = "My name is Tom"; encryptedWallet.changeEncryptionPassword(PASSWORD1, newPassword); assertTrue(encryptedWallet.checkPassword(newPassword)); assertFalse(encryptedWallet.checkPassword(WRONG_PASSWORD)); }
@Test(expected = KeyCrypterException.class) public void addEncryptedKeyToUnencryptedWallet() throws Exception { Wallet encryptedWallet = new Wallet(PARAMS); encryptedWallet.encrypt(PASSWORD1); KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter(); ECKey key1 = new ECKey(); key1 = key1.encrypt(keyCrypter, keyCrypter.deriveKey("PASSWORD!")); wallet.importKey(key1); }
@Test public void importAndEncrypt() throws InsufficientMoneyException { Wallet encryptedWallet = new Wallet(PARAMS); encryptedWallet.encrypt(PASSWORD1); final ECKey key = new ECKey(); encryptedWallet.importKeysAndEncrypt(ImmutableList.of(key), PASSWORD1); assertEquals(1, encryptedWallet.getImportedKeys().size()); assertEquals(key.getPubKeyPoint(), encryptedWallet.getImportedKeys().get(0).getPubKeyPoint()); sendMoneyToWallet(encryptedWallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, Coin.COIN, key.toAddress(PARAMS)); assertEquals(Coin.COIN, encryptedWallet.getBalance()); SendRequest req = SendRequest.emptyWallet(OTHER_ADDRESS); req.aesKey = checkNotNull(encryptedWallet.getKeyCrypter()).deriveKey(PASSWORD1); encryptedWallet.sendCoinsOffline(req); }
@Test(expected = KeyCrypterException.class) public void mismatchedCrypter() throws Exception { Wallet encryptedWallet = new Wallet(PARAMS); encryptedWallet.encrypt(PASSWORD1); KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter(); KeyParameter aesKey = keyCrypter.deriveKey(PASSWORD1); // Try added an ECKey that was encrypted with a differenct ScryptParameters (i.e. a non-homogenous key). // This is not allowed as the ScryptParameters is stored at the Wallet level. Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder() .setSalt(ByteString.copyFrom(KeyCrypterScrypt.randomSalt())); Protos.ScryptParameters scryptParameters = scryptParametersBuilder.build(); KeyCrypter keyCrypterDifferent = new KeyCrypterScrypt(scryptParameters); ECKey ecKeyDifferent = new ECKey(); ecKeyDifferent = ecKeyDifferent.encrypt(keyCrypterDifferent, aesKey); encryptedWallet.importKey(ecKeyDifferent); }
@Test public void changeAesKeyTest() { Wallet encryptedWallet = new Wallet(PARAMS); encryptedWallet.encrypt(PASSWORD1); KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter(); KeyParameter aesKey = keyCrypter.deriveKey(PASSWORD1); CharSequence newPassword = "My name is Tom"; KeyParameter newAesKey = keyCrypter.deriveKey(newPassword); encryptedWallet.changeEncryptionKey(keyCrypter, aesKey, newAesKey); assertTrue(encryptedWallet.checkAESKey(newAesKey)); assertFalse(encryptedWallet.checkAESKey(aesKey)); }
@Test public void isWatching() { assertFalse(wallet.isWatching()); Wallet watchingWallet = Wallet.fromWatchingKey(PARAMS, wallet.getWatchingKey().dropPrivateBytes().dropParent()); assertTrue(watchingWallet.isWatching()); wallet.encrypt(PASSWORD1); assertFalse(wallet.isWatching()); }
@Test public void encryptionDecryptionBadPassword() throws Exception { Wallet encryptedWallet = new Wallet(PARAMS); encryptedWallet.encrypt(PASSWORD1); KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter(); KeyParameter wrongAesKey = keyCrypter.deriveKey(WRONG_PASSWORD); // Check the wallet is currently encrypted assertEquals("Wallet is not an encrypted wallet", EncryptionType.ENCRYPTED_SCRYPT_AES, encryptedWallet.getEncryptionType()); assertFalse(encryptedWallet.checkAESKey(wrongAesKey)); // Check that the wrong password does not decrypt the wallet. try { encryptedWallet.decrypt(wrongAesKey); fail("Incorrectly decoded wallet with wrong password"); } catch (KeyCrypterException ede) { // Expected. } }
@Test public void encryptionDecryptionPasswordBasic() throws Exception { Wallet encryptedWallet = new Wallet(PARAMS); encryptedWallet.encrypt(PASSWORD1); assertTrue(encryptedWallet.isEncrypted()); encryptedWallet.decrypt(PASSWORD1); assertFalse(encryptedWallet.isEncrypted()); // Wallet should now be unencrypted. assertNull("Wallet is not an unencrypted wallet", encryptedWallet.getKeyCrypter()); try { encryptedWallet.checkPassword(PASSWORD1); fail(); } catch (IllegalStateException e) { } }