diff --git a/src/wallet/crypter.cpp b/src/wallet/crypter.cpp index d60ce1359d..6a7aae8373 100644 --- a/src/wallet/crypter.cpp +++ b/src/wallet/crypter.cpp @@ -198,7 +198,7 @@ bool CCryptoKeyStore::Unlock(const CKeyingMaterial& vMasterKeyIn) if (vchCryptedBip39Words.size() || vchCryptedBip39Passphrase.size() || vchCryptedBip39VchSeed.size()) { if (!DecryptBip39(vMasterKeyIn)) { LogPrintf("Failed to decrypt bip 39 data"); - assert(false); + return false; } } if (keyPass && keyFail) diff --git a/src/wallet/test/crypto_tests.cpp b/src/wallet/test/crypto_tests.cpp index 60bc70281d..ef9a84c90e 100644 --- a/src/wallet/test/crypto_tests.cpp +++ b/src/wallet/test/crypto_tests.cpp @@ -13,6 +13,12 @@ BOOST_FIXTURE_TEST_SUITE(wallet_crypto, BasicTestingSetup) + class TestCryptoKeyStore : public CCryptoKeyStore + { + public: + using CCryptoKeyStore::Unlock; + }; + class TestCrypter { public: @@ -132,4 +138,13 @@ BOOST_FIXTURE_TEST_SUITE(wallet_crypto, BasicTestingSetup) } } + BOOST_AUTO_TEST_CASE(unlock_rejects_invalid_encrypted_bip39_data) + { + TestCryptoKeyStore keystore; + keystore.AddCryptedWords(uint256(), std::vector(1, 0)); + + CKeyingMaterial masterKey(WALLET_CRYPTO_KEY_SIZE, 0); + BOOST_CHECK(!keystore.Unlock(masterKey)); + } + BOOST_AUTO_TEST_SUITE_END()