Fix sporadic failures in StoreAndRetrieveMnemonicSeedInEncryptedStore

This commit is contained in:
sasha 2022-04-01 14:35:47 -07:00
parent d711a7c529
commit 3cf2ba8853
1 changed files with 7 additions and 8 deletions

View File

@ -359,15 +359,14 @@ TEST(KeystoreTests, StoreAndRetrieveMnemonicSeedInEncryptedStore) {
seedOut = keyStore.GetMnemonicSeed(); seedOut = keyStore.GetMnemonicSeed();
EXPECT_FALSE(seedOut.has_value()); EXPECT_FALSE(seedOut.has_value());
// Unlocking with a random key should fail // Unlocking with a random key causes sporadic failures, since we currently
CKeyingMaterial vRandomKey(32, 0); // don't use an authenticated encryption scheme for CCryptoKeyStore.
GetRandBytes(vRandomKey.data(), 32);
EXPECT_FALSE(keyStore.Unlock(vRandomKey));
// Unlocking with a slightly-modified vMasterKey should fail // Currently, DecryptMnemonicSeed tests if a key is invalid by looking at
CKeyingMaterial vModifiedKey(vMasterKey); // the return value of CBCDecrypt. If keyStore.Unlock is called with an
vModifiedKey[0] += 1; // invalid key, there's roughly a 257/65536 chance that the padding check
EXPECT_FALSE(keyStore.Unlock(vModifiedKey)); // in CBCDecrypt will pass, in which case DecryptMnemonicSeed then calls
// the deserialization code in mnemonic.h with random data.
// Unlocking with vMasterKey should succeed // Unlocking with vMasterKey should succeed
ASSERT_TRUE(keyStore.Unlock(vMasterKey)); ASSERT_TRUE(keyStore.Unlock(vMasterKey));