Commit 9cd0a79d authored by Maksim Moskvitin's avatar Maksim Moskvitin Committed by Commit Bot

Restore cryptographer checks in custom passphrase tests

crrev.com/c/1787610 removed cryptographer checks in custom passphrase
unittests, because used KeyDerivationMethod became an implementation
detail.

This CL restore those checks by bridge providing custom passphrase key
derivation params through getter.

Bug: 922900
Change-Id: I31abbf54e162c779cea50020231aed85e2e1a9d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869221
Auto-Submit: Maksim Moskvitin <mmoskvitin@google.com>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Commit-Queue: Maksim Moskvitin <mmoskvitin@google.com>
Cr-Commit-Position: refs/heads/master@{#707800}
parent 0e6a524c
......@@ -999,6 +999,14 @@ bool NigoriSyncBridgeImpl::HasPendingKeysForTesting() const {
return state_.pending_keys.has_value();
}
KeyDerivationParams
NigoriSyncBridgeImpl::GetCustomPassphraseKeyDerivationParamsForTesting() const {
if (!state_.custom_passphrase_key_derivation_params) {
return KeyDerivationParams::CreateForPbkdf2();
}
return *state_.custom_passphrase_key_derivation_params;
}
std::string NigoriSyncBridgeImpl::PackExplicitPassphraseKeyForTesting(
const Encryptor& encryptor,
const CryptographerImpl& cryptographer) {
......
......@@ -32,6 +32,7 @@ class NigoriLocalData;
namespace syncer {
class Encryptor;
class KeyDerivationParams;
class NigoriStorage;
class PendingLocalNigoriCommit;
......@@ -89,6 +90,7 @@ class NigoriSyncBridgeImpl : public KeystoreKeysHandler,
sync_pb::NigoriSpecifics::PassphraseType GetPassphraseTypeForTesting() const;
ModelTypeSet GetEncryptedTypesForTesting() const;
bool HasPendingKeysForTesting() const;
KeyDerivationParams GetCustomPassphraseKeyDerivationParamsForTesting() const;
static std::string PackExplicitPassphraseKeyForTesting(
const Encryptor& encryptor,
......
......@@ -968,8 +968,12 @@ TEST_F(NigoriSyncBridgeImplTest,
EXPECT_THAT(bridge()->ApplySyncChanges(base::nullopt), Eq(base::nullopt));
EXPECT_THAT(bridge()->GetData(), HasCustomPassphraseNigori());
// TODO(crbug.com/922900): find a good way to get key derivation method and
// salt to check expectations about cryptographer state.
const KeyParams passphrase_key_params = {
bridge()->GetCustomPassphraseKeyDerivationParamsForTesting(),
kCustomPassphrase};
const Cryptographer& cryptographer = bridge()->GetCryptographerForTesting();
EXPECT_THAT(cryptographer, CanDecryptWith(passphrase_key_params));
EXPECT_THAT(cryptographer, HasDefaultKeyDerivedFrom(passphrase_key_params));
}
// Tests that pending local change with setting custom passphrase is applied,
......@@ -1027,11 +1031,14 @@ TEST_F(NigoriSyncBridgeImplTest,
EXPECT_THAT(bridge()->ApplySyncChanges(base::nullopt), Eq(base::nullopt));
EXPECT_THAT(bridge()->GetData(), HasCustomPassphraseNigori());
const KeyParams passphrase_key_params = {
bridge()->GetCustomPassphraseKeyDerivationParamsForTesting(),
kCustomPassphrase};
const Cryptographer& cryptographer = bridge()->GetCryptographerForTesting();
EXPECT_THAT(cryptographer, CanDecryptWith(kKeystoreKeyParams1));
EXPECT_THAT(cryptographer, CanDecryptWith(kKeystoreKeyParams2));
// TODO(crbug.com/922900): find a good way to get key derivation method and
// salt to check expectations about cryptographer state.
EXPECT_THAT(cryptographer, CanDecryptWith(passphrase_key_params));
EXPECT_THAT(cryptographer, HasDefaultKeyDerivedFrom(passphrase_key_params));
}
// Tests that SetEncryptionPassphrase() call doesn't lead to custom passphrase
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment