OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sync/internal_api/sync_encryption_handler_impl.h" | 5 #include "sync/internal_api/sync_encryption_handler_impl.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <string> | 9 #include <string> |
8 | 10 |
9 #include "base/base64.h" | 11 #include "base/base64.h" |
10 #include "base/json/json_string_value_serializer.h" | 12 #include "base/json/json_string_value_serializer.h" |
11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
12 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
13 #include "base/tracked_objects.h" | 15 #include "base/tracked_objects.h" |
14 #include "sync/internal_api/public/base/model_type_test_util.h" | 16 #include "sync/internal_api/public/base/model_type_test_util.h" |
15 #include "sync/internal_api/public/read_node.h" | 17 #include "sync/internal_api/public/read_node.h" |
16 #include "sync/internal_api/public/read_transaction.h" | 18 #include "sync/internal_api/public/read_transaction.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 SyncEncryptionHandlerObserverMock* observer() { return &observer_; } | 141 SyncEncryptionHandlerObserverMock* observer() { return &observer_; } |
140 Cryptographer* GetCryptographer() { | 142 Cryptographer* GetCryptographer() { |
141 return encryption_handler_->GetCryptographerUnsafe(); | 143 return encryption_handler_->GetCryptographerUnsafe(); |
142 } | 144 } |
143 | 145 |
144 void VerifyMigratedNigori(PassphraseType passphrase_type, | 146 void VerifyMigratedNigori(PassphraseType passphrase_type, |
145 const std::string& passphrase) { | 147 const std::string& passphrase) { |
146 VerifyMigratedNigoriWithTimestamp(0, passphrase_type, passphrase); | 148 VerifyMigratedNigoriWithTimestamp(0, passphrase_type, passphrase); |
147 } | 149 } |
148 | 150 |
149 void VerifyMigratedNigoriWithTimestamp( | 151 void VerifyMigratedNigoriWithTimestamp(int64_t migration_time, |
150 int64 migration_time, | 152 PassphraseType passphrase_type, |
151 PassphraseType passphrase_type, | 153 const std::string& passphrase) { |
152 const std::string& passphrase) { | |
153 ReadTransaction trans(FROM_HERE, user_share()); | 154 ReadTransaction trans(FROM_HERE, user_share()); |
154 ReadNode nigori_node(&trans); | 155 ReadNode nigori_node(&trans); |
155 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); | 156 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); |
156 const sync_pb::NigoriSpecifics& nigori = nigori_node.GetNigoriSpecifics(); | 157 const sync_pb::NigoriSpecifics& nigori = nigori_node.GetNigoriSpecifics(); |
157 if (migration_time > 0) | 158 if (migration_time > 0) |
158 EXPECT_EQ(migration_time, nigori.keystore_migration_time()); | 159 EXPECT_EQ(migration_time, nigori.keystore_migration_time()); |
159 else | 160 else |
160 EXPECT_TRUE(nigori.has_keystore_migration_time()); | 161 EXPECT_TRUE(nigori.has_keystore_migration_time()); |
161 EXPECT_TRUE(nigori.keybag_is_frozen()); | 162 EXPECT_TRUE(nigori.keybag_is_frozen()); |
162 if (passphrase_type == CUSTOM_PASSPHRASE || | 163 if (passphrase_type == CUSTOM_PASSPHRASE || |
(...skipping 26 matching lines...) Expand all Loading... |
189 | 190 |
190 Cryptographer temp_cryptographer(&encryptor_); | 191 Cryptographer temp_cryptographer(&encryptor_); |
191 KeyParams params = {"localhost", "dummy", passphrase}; | 192 KeyParams params = {"localhost", "dummy", passphrase}; |
192 temp_cryptographer.AddKey(params); | 193 temp_cryptographer.AddKey(params); |
193 EXPECT_TRUE(temp_cryptographer.CanDecryptUsingDefaultKey( | 194 EXPECT_TRUE(temp_cryptographer.CanDecryptUsingDefaultKey( |
194 nigori.encryption_keybag())); | 195 nigori.encryption_keybag())); |
195 } | 196 } |
196 | 197 |
197 sync_pb::NigoriSpecifics BuildMigratedNigori( | 198 sync_pb::NigoriSpecifics BuildMigratedNigori( |
198 PassphraseType passphrase_type, | 199 PassphraseType passphrase_type, |
199 int64 migration_time, | 200 int64_t migration_time, |
200 const std::string& default_passphrase, | 201 const std::string& default_passphrase, |
201 const std::string& keystore_key) { | 202 const std::string& keystore_key) { |
202 DCHECK_NE(passphrase_type, IMPLICIT_PASSPHRASE); | 203 DCHECK_NE(passphrase_type, IMPLICIT_PASSPHRASE); |
203 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); | 204 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); |
204 | 205 |
205 std::string default_key = default_passphrase; | 206 std::string default_key = default_passphrase; |
206 if (default_key.empty()) { | 207 if (default_key.empty()) { |
207 default_key = keystore_key; | 208 default_key = keystore_key; |
208 } else { | 209 } else { |
209 KeyParams keystore_params = {"localhost", "dummy", keystore_key}; | 210 KeyParams keystore_params = {"localhost", "dummy", keystore_key}; |
(...skipping 22 matching lines...) Expand all Loading... |
232 nigori.set_passphrase_type( | 233 nigori.set_passphrase_type( |
233 passphrase_type == CUSTOM_PASSPHRASE ? | 234 passphrase_type == CUSTOM_PASSPHRASE ? |
234 sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE : | 235 sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE : |
235 sync_pb::NigoriSpecifics::FROZEN_IMPLICIT_PASSPHRASE); | 236 sync_pb::NigoriSpecifics::FROZEN_IMPLICIT_PASSPHRASE); |
236 } | 237 } |
237 return nigori; | 238 return nigori; |
238 } | 239 } |
239 | 240 |
240 // Build a migrated nigori node with the specified default passphrase | 241 // Build a migrated nigori node with the specified default passphrase |
241 // and keystore key and initialize the encryption handler with it. | 242 // and keystore key and initialize the encryption handler with it. |
242 void InitKeystoreMigratedNigori(int64 migration_time, | 243 void InitKeystoreMigratedNigori(int64_t migration_time, |
243 const std::string& default_passphrase, | 244 const std::string& default_passphrase, |
244 const std::string& keystore_key) { | 245 const std::string& keystore_key) { |
245 { | 246 { |
246 WriteTransaction trans(FROM_HERE, user_share()); | 247 WriteTransaction trans(FROM_HERE, user_share()); |
247 WriteNode nigori_node(&trans); | 248 WriteNode nigori_node(&trans); |
248 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); | 249 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); |
249 sync_pb::NigoriSpecifics nigori = BuildMigratedNigori( | 250 sync_pb::NigoriSpecifics nigori = BuildMigratedNigori( |
250 KEYSTORE_PASSPHRASE, | 251 KEYSTORE_PASSPHRASE, |
251 migration_time, | 252 migration_time, |
252 default_passphrase, | 253 default_passphrase, |
(...skipping 13 matching lines...) Expand all Loading... |
266 OnEncryptionComplete()).Times(AtLeast(1)); | 267 OnEncryptionComplete()).Times(AtLeast(1)); |
267 encryption_handler()->Init(); | 268 encryption_handler()->Init(); |
268 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); | 269 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); |
269 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); | 270 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); |
270 EXPECT_FALSE(encryption_handler()->IsEncryptEverythingEnabled()); | 271 EXPECT_FALSE(encryption_handler()->IsEncryptEverythingEnabled()); |
271 Mock::VerifyAndClearExpectations(observer()); | 272 Mock::VerifyAndClearExpectations(observer()); |
272 } | 273 } |
273 | 274 |
274 // Build a migrated nigori node with the specified default passphrase | 275 // Build a migrated nigori node with the specified default passphrase |
275 // as a custom passphrase. | 276 // as a custom passphrase. |
276 void InitCustomPassMigratedNigori(int64 migration_time, | 277 void InitCustomPassMigratedNigori(int64_t migration_time, |
277 const std::string& default_passphrase) { | 278 const std::string& default_passphrase) { |
278 { | 279 { |
279 WriteTransaction trans(FROM_HERE, user_share()); | 280 WriteTransaction trans(FROM_HERE, user_share()); |
280 WriteNode nigori_node(&trans); | 281 WriteNode nigori_node(&trans); |
281 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); | 282 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); |
282 sync_pb::NigoriSpecifics nigori = BuildMigratedNigori( | 283 sync_pb::NigoriSpecifics nigori = BuildMigratedNigori( |
283 CUSTOM_PASSPHRASE, | 284 CUSTOM_PASSPHRASE, |
284 migration_time, | 285 migration_time, |
285 default_passphrase, | 286 default_passphrase, |
286 kKeystoreKey); | 287 kKeystoreKey); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 Mock::VerifyAndClearExpectations(observer()); | 338 Mock::VerifyAndClearExpectations(observer()); |
338 } | 339 } |
339 | 340 |
340 // Verify we can restore the SyncEncryptionHandler state using a saved | 341 // Verify we can restore the SyncEncryptionHandler state using a saved |
341 // |bootstrap_token| and |nigori_state|. | 342 // |bootstrap_token| and |nigori_state|. |
342 // | 343 // |
343 // |migration_time| is the time migration occurred. | 344 // |migration_time| is the time migration occurred. |
344 // | 345 // |
345 // |passphrase| is the custom passphrase. | 346 // |passphrase| is the custom passphrase. |
346 void VerifyRestoreAfterCustomPassphrase( | 347 void VerifyRestoreAfterCustomPassphrase( |
347 int64 migration_time, | 348 int64_t migration_time, |
348 const std::string& passphrase, | 349 const std::string& passphrase, |
349 const std::string& bootstrap_token, | 350 const std::string& bootstrap_token, |
350 const SyncEncryptionHandler::NigoriState& nigori_state, | 351 const SyncEncryptionHandler::NigoriState& nigori_state, |
351 PassphraseType passphrase_type) { | 352 PassphraseType passphrase_type) { |
352 TearDown(); | 353 TearDown(); |
353 test_user_share_.SetUp(); | 354 test_user_share_.SetUp(); |
354 SetUpEncryptionWithKeyForBootstrapping(bootstrap_token); | 355 SetUpEncryptionWithKeyForBootstrapping(bootstrap_token); |
355 EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber()); | 356 EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber()); |
356 EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true)) | 357 EXPECT_CALL(*observer(), OnEncryptedTypesChanged(_, true)) |
357 .Times(AnyNumber()); | 358 .Times(AnyNumber()); |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 TEST_F(SyncEncryptionHandlerImplTest, ReceiveUnmigratedNigoriAfterMigration) { | 1332 TEST_F(SyncEncryptionHandlerImplTest, ReceiveUnmigratedNigoriAfterMigration) { |
1332 const char kOldKey[] = "old"; | 1333 const char kOldKey[] = "old"; |
1333 const char kCurKey[] = "cur"; | 1334 const char kCurKey[] = "cur"; |
1334 sync_pb::EncryptedData encrypted; | 1335 sync_pb::EncryptedData encrypted; |
1335 KeyParams old_key = {"localhost", "dummy", kOldKey}; | 1336 KeyParams old_key = {"localhost", "dummy", kOldKey}; |
1336 KeyParams cur_key = {"localhost", "dummy", kCurKey}; | 1337 KeyParams cur_key = {"localhost", "dummy", kCurKey}; |
1337 GetCryptographer()->AddKey(old_key); | 1338 GetCryptographer()->AddKey(old_key); |
1338 GetCryptographer()->AddKey(cur_key); | 1339 GetCryptographer()->AddKey(cur_key); |
1339 | 1340 |
1340 // Build a migrated nigori with full encryption. | 1341 // Build a migrated nigori with full encryption. |
1341 const int64 migration_time = 1; | 1342 const int64_t migration_time = 1; |
1342 { | 1343 { |
1343 WriteTransaction trans(FROM_HERE, user_share()); | 1344 WriteTransaction trans(FROM_HERE, user_share()); |
1344 WriteNode nigori_node(&trans); | 1345 WriteNode nigori_node(&trans); |
1345 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); | 1346 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); |
1346 sync_pb::NigoriSpecifics nigori; | 1347 sync_pb::NigoriSpecifics nigori; |
1347 GetCryptographer()->GetKeys(nigori.mutable_encryption_keybag()); | 1348 GetCryptographer()->GetKeys(nigori.mutable_encryption_keybag()); |
1348 nigori.set_keybag_is_frozen(true); | 1349 nigori.set_keybag_is_frozen(true); |
1349 nigori.set_keystore_migration_time(1); | 1350 nigori.set_keystore_migration_time(1); |
1350 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE); | 1351 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE); |
1351 nigori.set_encrypt_everything(true); | 1352 nigori.set_encrypt_everything(true); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 Mock::VerifyAndClearExpectations(observer()); | 1470 Mock::VerifyAndClearExpectations(observer()); |
1470 | 1471 |
1471 // Now build an old keystore nigori node with old encrypted types. We should | 1472 // Now build an old keystore nigori node with old encrypted types. We should |
1472 // properly overwrite it with the migrated + encrypt everything state. | 1473 // properly overwrite it with the migrated + encrypt everything state. |
1473 EXPECT_CALL(*observer(), | 1474 EXPECT_CALL(*observer(), |
1474 OnCryptographerStateChanged(_)).Times(AnyNumber()); | 1475 OnCryptographerStateChanged(_)).Times(AnyNumber()); |
1475 SyncEncryptionHandler::NigoriState captured_nigori_state; | 1476 SyncEncryptionHandler::NigoriState captured_nigori_state; |
1476 EXPECT_CALL(*observer(), OnLocalSetPassphraseEncryption(_)) | 1477 EXPECT_CALL(*observer(), OnLocalSetPassphraseEncryption(_)) |
1477 .WillOnce(testing::SaveArg<0>(&captured_nigori_state)); | 1478 .WillOnce(testing::SaveArg<0>(&captured_nigori_state)); |
1478 EXPECT_CALL(*observer(), OnEncryptionComplete()); | 1479 EXPECT_CALL(*observer(), OnEncryptionComplete()); |
1479 const int64 migration_time = 1; | 1480 const int64_t migration_time = 1; |
1480 { | 1481 { |
1481 WriteTransaction trans(FROM_HERE, user_share()); | 1482 WriteTransaction trans(FROM_HERE, user_share()); |
1482 WriteNode nigori_node(&trans); | 1483 WriteNode nigori_node(&trans); |
1483 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); | 1484 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); |
1484 sync_pb::NigoriSpecifics nigori; | 1485 sync_pb::NigoriSpecifics nigori; |
1485 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); | 1486 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); |
1486 other_cryptographer.AddKey(old_key); | 1487 other_cryptographer.AddKey(old_key); |
1487 encryption_handler()->GetKeystoreDecryptor( | 1488 encryption_handler()->GetKeystoreDecryptor( |
1488 other_cryptographer, | 1489 other_cryptographer, |
1489 kKeystoreKey, | 1490 kKeystoreKey, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1609 other_cryptographer.AddKey(cur_key); | 1610 other_cryptographer.AddKey(cur_key); |
1610 EXPECT_TRUE(other_cryptographer.is_ready()); | 1611 EXPECT_TRUE(other_cryptographer.is_ready()); |
1611 EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor( | 1612 EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor( |
1612 other_cryptographer, | 1613 other_cryptographer, |
1613 kKeystoreKey, | 1614 kKeystoreKey, |
1614 &keystore_decryptor_token)); | 1615 &keystore_decryptor_token)); |
1615 | 1616 |
1616 // Build a nigori node with the generated keystore decryptor token and | 1617 // Build a nigori node with the generated keystore decryptor token and |
1617 // initialize the encryption handler with it. The cryptographer should be | 1618 // initialize the encryption handler with it. The cryptographer should be |
1618 // initialized properly to decrypt both kOldKey and kKeystoreKey. | 1619 // initialized properly to decrypt both kOldKey and kKeystoreKey. |
1619 const int64 migration_time = 1; | 1620 const int64_t migration_time = 1; |
1620 { | 1621 { |
1621 WriteTransaction trans(FROM_HERE, user_share()); | 1622 WriteTransaction trans(FROM_HERE, user_share()); |
1622 WriteNode nigori_node(&trans); | 1623 WriteNode nigori_node(&trans); |
1623 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); | 1624 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); |
1624 sync_pb::NigoriSpecifics nigori; | 1625 sync_pb::NigoriSpecifics nigori; |
1625 nigori.mutable_keystore_decryptor_token()->CopyFrom( | 1626 nigori.mutable_keystore_decryptor_token()->CopyFrom( |
1626 keystore_decryptor_token); | 1627 keystore_decryptor_token); |
1627 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); | 1628 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); |
1628 nigori.set_keybag_is_frozen(true); | 1629 nigori.set_keybag_is_frozen(true); |
1629 nigori.set_keystore_migration_time(migration_time); | 1630 nigori.set_keystore_migration_time(migration_time); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1726 other_cryptographer.AddNonDefaultKey(keystore_key); | 1727 other_cryptographer.AddNonDefaultKey(keystore_key); |
1727 EXPECT_TRUE(other_cryptographer.is_ready()); | 1728 EXPECT_TRUE(other_cryptographer.is_ready()); |
1728 EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor( | 1729 EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor( |
1729 other_cryptographer, | 1730 other_cryptographer, |
1730 kKeystoreKey, | 1731 kKeystoreKey, |
1731 &keystore_decryptor_token)); | 1732 &keystore_decryptor_token)); |
1732 | 1733 |
1733 // Build a nigori node with the generated keystore decryptor token and | 1734 // Build a nigori node with the generated keystore decryptor token and |
1734 // initialize the encryption handler with it. The cryptographer will have | 1735 // initialize the encryption handler with it. The cryptographer will have |
1735 // pending keys until we provide the decryption passphrase. | 1736 // pending keys until we provide the decryption passphrase. |
1736 const int64 migration_time = 1; | 1737 const int64_t migration_time = 1; |
1737 { | 1738 { |
1738 WriteTransaction trans(FROM_HERE, user_share()); | 1739 WriteTransaction trans(FROM_HERE, user_share()); |
1739 WriteNode nigori_node(&trans); | 1740 WriteNode nigori_node(&trans); |
1740 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); | 1741 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); |
1741 sync_pb::NigoriSpecifics nigori; | 1742 sync_pb::NigoriSpecifics nigori; |
1742 nigori.mutable_keystore_decryptor_token()->CopyFrom( | 1743 nigori.mutable_keystore_decryptor_token()->CopyFrom( |
1743 keystore_decryptor_token); | 1744 keystore_decryptor_token); |
1744 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); | 1745 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); |
1745 nigori.set_keybag_is_frozen(true); | 1746 nigori.set_keybag_is_frozen(true); |
1746 nigori.set_keystore_migration_time(migration_time); | 1747 nigori.set_keystore_migration_time(migration_time); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1940 other_cryptographer.AddNonDefaultKey(keystore_key); | 1941 other_cryptographer.AddNonDefaultKey(keystore_key); |
1941 EXPECT_TRUE(other_cryptographer.is_ready()); | 1942 EXPECT_TRUE(other_cryptographer.is_ready()); |
1942 EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor( | 1943 EXPECT_TRUE(encryption_handler()->GetKeystoreDecryptor( |
1943 other_cryptographer, | 1944 other_cryptographer, |
1944 kKeystoreKey, | 1945 kKeystoreKey, |
1945 &keystore_decryptor_token)); | 1946 &keystore_decryptor_token)); |
1946 | 1947 |
1947 // Build a nigori node with the generated keystore decryptor token and | 1948 // Build a nigori node with the generated keystore decryptor token and |
1948 // initialize the encryption handler with it. The cryptographer will have | 1949 // initialize the encryption handler with it. The cryptographer will have |
1949 // pending keys until we provide the decryption passphrase. | 1950 // pending keys until we provide the decryption passphrase. |
1950 const int64 migration_time = 1; | 1951 const int64_t migration_time = 1; |
1951 { | 1952 { |
1952 WriteTransaction trans(FROM_HERE, user_share()); | 1953 WriteTransaction trans(FROM_HERE, user_share()); |
1953 WriteNode nigori_node(&trans); | 1954 WriteNode nigori_node(&trans); |
1954 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); | 1955 ASSERT_EQ(nigori_node.InitTypeRoot(NIGORI), BaseNode::INIT_OK); |
1955 sync_pb::NigoriSpecifics nigori; | 1956 sync_pb::NigoriSpecifics nigori; |
1956 nigori.mutable_keystore_decryptor_token()->CopyFrom( | 1957 nigori.mutable_keystore_decryptor_token()->CopyFrom( |
1957 keystore_decryptor_token); | 1958 keystore_decryptor_token); |
1958 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); | 1959 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); |
1959 nigori.set_keybag_is_frozen(true); | 1960 nigori.set_keybag_is_frozen(true); |
1960 nigori.set_keystore_migration_time(migration_time); | 1961 nigori.set_keystore_migration_time(migration_time); |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2407 | 2408 |
2408 // Verify that a key rotation done after we've migrated a custom passphrase | 2409 // Verify that a key rotation done after we've migrated a custom passphrase |
2409 // nigori node preserves the custom passphrase. | 2410 // nigori node preserves the custom passphrase. |
2410 TEST_F(SyncEncryptionHandlerImplTest, RotateKeysMigratedCustomPassphrase) { | 2411 TEST_F(SyncEncryptionHandlerImplTest, RotateKeysMigratedCustomPassphrase) { |
2411 const char kCustomPass[] = "custom_passphrase"; | 2412 const char kCustomPass[] = "custom_passphrase"; |
2412 const char kRawOldKeystoreKey[] = "old_keystore_key"; | 2413 const char kRawOldKeystoreKey[] = "old_keystore_key"; |
2413 | 2414 |
2414 KeyParams custom_key = {"localhost", "dummy", kCustomPass}; | 2415 KeyParams custom_key = {"localhost", "dummy", kCustomPass}; |
2415 GetCryptographer()->AddKey(custom_key); | 2416 GetCryptographer()->AddKey(custom_key); |
2416 | 2417 |
2417 const int64 migration_time = 1; | 2418 const int64_t migration_time = 1; |
2418 InitCustomPassMigratedNigori(migration_time, kCustomPass); | 2419 InitCustomPassMigratedNigori(migration_time, kCustomPass); |
2419 VerifyMigratedNigoriWithTimestamp(migration_time, CUSTOM_PASSPHRASE, | 2420 VerifyMigratedNigoriWithTimestamp(migration_time, CUSTOM_PASSPHRASE, |
2420 kCustomPass); | 2421 kCustomPass); |
2421 | 2422 |
2422 SyncEncryptionHandler::NigoriState captured_nigori_state; | 2423 SyncEncryptionHandler::NigoriState captured_nigori_state; |
2423 { | 2424 { |
2424 // Pass multiple keystore keys, signaling a rotation has happened. | 2425 // Pass multiple keystore keys, signaling a rotation has happened. |
2425 google::protobuf::RepeatedPtrField<google::protobuf::string> keys; | 2426 google::protobuf::RepeatedPtrField<google::protobuf::string> keys; |
2426 keys.Add()->assign(kRawOldKeystoreKey); | 2427 keys.Add()->assign(kRawOldKeystoreKey); |
2427 keys.Add()->assign(kRawKeystoreKey); | 2428 keys.Add()->assign(kRawKeystoreKey); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2494 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); | 2495 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); |
2495 { | 2496 { |
2496 ReadTransaction trans(FROM_HERE, user_share()); | 2497 ReadTransaction trans(FROM_HERE, user_share()); |
2497 encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto( | 2498 encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto( |
2498 kRawKeystoreKey), | 2499 kRawKeystoreKey), |
2499 trans.GetWrappedTrans()); | 2500 trans.GetWrappedTrans()); |
2500 } | 2501 } |
2501 } | 2502 } |
2502 | 2503 |
2503 } // namespace syncer | 2504 } // namespace syncer |
OLD | NEW |