3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-12 18:25:51 +00:00

DeterministicKeyChain: Allow decrypting DeterministicKeyChain with arbitrary path

This commit is contained in:
HashEngineering 2018-03-14 22:01:53 -07:00
parent afe1b69f31
commit 6aba962d62
2 changed files with 6 additions and 5 deletions

View File

@ -425,7 +425,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
* For use in encryption when {@link #toEncrypted(KeyCrypter, KeyParameter)} is called, so that
* subclasses can override that method and create an instance of the right class.
*
* See also {@link #makeKeyChainFromSeed(DeterministicSeed)}
* See also {@link #makeKeyChainFromSeed(DeterministicSeed, ImmutableList<ChildNumber>)}
*/
protected DeterministicKeyChain(KeyCrypter crypter, KeyParameter aesKey, DeterministicKeyChain chain) {
// Can't encrypt a watching chain.
@ -1048,7 +1048,7 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
checkState(seed.isEncrypted());
String passphrase = DEFAULT_PASSPHRASE_FOR_MNEMONIC; // FIXME allow non-empty passphrase
DeterministicSeed decSeed = seed.decrypt(getKeyCrypter(), passphrase, aesKey);
DeterministicKeyChain chain = makeKeyChainFromSeed(decSeed);
DeterministicKeyChain chain = makeKeyChainFromSeed(decSeed, getAccountPath());
// Now double check that the keys match to catch the case where the key is wrong but padding didn't catch it.
if (!chain.getWatchingKey().getPubKeyPoint().equals(getWatchingKey().getPubKeyPoint()))
throw new KeyCrypterException("Provided AES key is wrong");
@ -1075,8 +1075,8 @@ public class DeterministicKeyChain implements EncryptableKeyChain {
* Subclasses should override this to create an instance of the subclass instead of a plain DKC.
* This is used in encryption/decryption.
*/
protected DeterministicKeyChain makeKeyChainFromSeed(DeterministicSeed seed) {
return new DeterministicKeyChain(seed);
protected DeterministicKeyChain makeKeyChainFromSeed(DeterministicSeed seed, ImmutableList<ChildNumber> accountPath) {
return new DeterministicKeyChain(seed, accountPath);
}
@Override

View File

@ -166,13 +166,14 @@ public class WalletTest extends TestWithWallet {
}
@Test
public void encryptWalletWithArbitraryPath() throws Exception {
public void encryptDecryptWalletWithArbitraryPath() throws Exception {
final byte[] ENTROPY = Sha256Hash.hash("don't use a string seed like this in real life".getBytes());
KeyChainGroup keyChainGroup = new KeyChainGroup(UNITTEST,
new DeterministicSeed(ENTROPY, "", 1389353062L),
DeterministicKeyChain.BIP44_ACCOUNT_ZERO_PATH);
Wallet encryptedWallet = new Wallet(UNITTEST, keyChainGroup);
encryptedWallet.encrypt(PASSWORD1);
encryptedWallet.decrypt(PASSWORD1);
}
@Test