diff options
author | malets <malets@yandex-team.ru> | 2015-02-19 00:23:29 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-19 08:24:07 +0000 |
commit | a17a62ab89a227166c665a4da0391c02111152ae (patch) | |
tree | bd3f7ebfab4acaaf4b52b78894c4ce19559c65df /sync/util | |
parent | 4725bfa6da3bc5a03c22c6e381583f403f8d3f90 (diff) | |
download | chromium_src-a17a62ab89a227166c665a4da0391c02111152ae.zip chromium_src-a17a62ab89a227166c665a4da0391c02111152ae.tar.gz chromium_src-a17a62ab89a227166c665a4da0391c02111152ae.tar.bz2 |
Add one test for Cryptographer::InstallKeys
Add a test which covers the case of exporting all the keys
and installing them back to fully bootstrap another cryptographer.
Review URL: https://codereview.chromium.org/896313002
Cr-Commit-Position: refs/heads/master@{#317008}
Diffstat (limited to 'sync/util')
-rw-r--r-- | sync/util/cryptographer_unittest.cc | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/sync/util/cryptographer_unittest.cc b/sync/util/cryptographer_unittest.cc index b1f7e6e..49d149c 100644 --- a/sync/util/cryptographer_unittest.cc +++ b/sync/util/cryptographer_unittest.cc @@ -258,4 +258,50 @@ TEST_F(CryptographerTest, CopyConstructor) { EXPECT_EQ(encrypted_c.key_name(), encrypted_k2.key_name()); } +// Test verifies that GetBootstrapToken/Bootstrap only transfers default +// key. Additional call to GetKeys/InstallKeys is needed to transfer keybag +// to decrypt messages encrypted with old keys. +TEST_F(CryptographerTest, GetKeysThenInstall) { + sync_pb::PasswordSpecificsData original; + original.set_origin("http://example.com"); + original.set_username_value("luser"); + original.set_password_value("p4ssw0rd"); + + // First, encrypt the same value using two different keys. + KeyParams params1 = {"localhost", "dummy", "dummy"}; + EXPECT_TRUE(cryptographer_.AddKey(params1)); + EXPECT_TRUE(cryptographer_.is_ready()); + + sync_pb::EncryptedData encrypted_k1; + EXPECT_TRUE(cryptographer_.Encrypt(original, &encrypted_k1)); + + KeyParams params2 = {"localhost", "dummy2", "dummy2"}; + EXPECT_TRUE(cryptographer_.AddKey(params2)); + EXPECT_TRUE(cryptographer_.is_ready()); + + sync_pb::EncryptedData encrypted_k2; + EXPECT_TRUE(cryptographer_.Encrypt(original, &encrypted_k2)); + + // Then construct second cryptographer and bootstrap it from the first one. + Cryptographer another_cryptographer(cryptographer_.encryptor()); + std::string bootstrap_token; + EXPECT_TRUE(cryptographer_.GetBootstrapToken(&bootstrap_token)); + another_cryptographer.Bootstrap(bootstrap_token); + + // Before key installation, the second cryptographer should only be able + // to decrypt using the last key. + EXPECT_FALSE(another_cryptographer.CanDecrypt(encrypted_k1)); + EXPECT_TRUE(another_cryptographer.CanDecrypt(encrypted_k2)); + + sync_pb::EncryptedData keys; + EXPECT_TRUE(cryptographer_.GetKeys(&keys)); + ASSERT_TRUE(another_cryptographer.CanDecrypt(keys)); + another_cryptographer.InstallKeys(keys); + + // Verify that bootstrapped cryptographer decrypts succesfully using + // all the keys after key installation. + EXPECT_TRUE(another_cryptographer.CanDecrypt(encrypted_k1)); + EXPECT_TRUE(another_cryptographer.CanDecrypt(encrypted_k2)); +} + } // namespace syncer |