Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: sync/internal_api/sync_encryption_handler_impl_unittest.cc

Issue 10917246: [Sync] Add keystore encryption info to about:sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 14 matching lines...) Expand all
25 #include "sync/test/fake_encryptor.h" 25 #include "sync/test/fake_encryptor.h"
26 #include "sync/util/cryptographer.h" 26 #include "sync/util/cryptographer.h"
27 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 29
30 namespace syncer { 30 namespace syncer {
31 31
32 namespace { 32 namespace {
33 33
34 using ::testing::_; 34 using ::testing::_;
35 using ::testing::AnyNumber;
35 using ::testing::Mock; 36 using ::testing::Mock;
36 using ::testing::SaveArg; 37 using ::testing::SaveArg;
37 using ::testing::StrictMock; 38 using ::testing::StrictMock;
38 39
39 // The raw keystore key the server sends. 40 // The raw keystore key the server sends.
40 static const char kRawKeystoreKey[] = "keystore_key"; 41 static const char kRawKeystoreKey[] = "keystore_key";
41 // Base64 encoded version of |kRawKeystoreKey|. 42 // Base64 encoded version of |kRawKeystoreKey|.
42 static const char kKeystoreKey[] = "a2V5c3RvcmVfa2V5"; 43 static const char kKeystoreKey[] = "a2V5c3RvcmVfa2V5";
43 44
44 class SyncEncryptionHandlerObserverMock 45 class SyncEncryptionHandlerObserverMock
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 sync_pb::NigoriSpecifics current_nigori_specifics; 378 sync_pb::NigoriSpecifics current_nigori_specifics;
378 GetCryptographer()->AddKey(old_key); 379 GetCryptographer()->AddKey(old_key);
379 GetCryptographer()->AddKey(current_key); 380 GetCryptographer()->AddKey(current_key);
380 GetCryptographer()->Encrypt( 381 GetCryptographer()->Encrypt(
381 our_encrypted_specifics, 382 our_encrypted_specifics,
382 our_encrypted_specifics.mutable_encrypted()); 383 our_encrypted_specifics.mutable_encrypted());
383 GetCryptographer()->GetKeys( 384 GetCryptographer()->GetKeys(
384 current_nigori_specifics.mutable_encryption_keybag()); 385 current_nigori_specifics.mutable_encryption_keybag());
385 current_nigori_specifics.set_encrypt_everything(true); 386 current_nigori_specifics.set_encrypt_everything(true);
386 387
387 EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)); 388 EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
388 EXPECT_CALL(*observer(), OnEncryptedTypesChanged( 389 EXPECT_CALL(*observer(), OnEncryptedTypesChanged(
389 HasModelTypes(UserTypes()), true)); 390 HasModelTypes(UserTypes()), true));
390 { 391 {
391 // Update the encryption handler. 392 // Update the encryption handler.
392 WriteTransaction trans(FROM_HERE, user_share()); 393 WriteTransaction trans(FROM_HERE, user_share());
393 encryption_handler()->ApplyNigoriUpdate( 394 encryption_handler()->ApplyNigoriUpdate(
394 current_nigori_specifics, 395 current_nigori_specifics,
395 trans.GetWrappedTrans()); 396 trans.GetWrappedTrans());
396 } 397 }
397 Mock::VerifyAndClearExpectations(observer()); 398 Mock::VerifyAndClearExpectations(observer());
398 399
399 // Now set up the old nigori specifics and apply it on top. 400 // Now set up the old nigori specifics and apply it on top.
400 // Has an old set of keys, and no encrypted types. 401 // Has an old set of keys, and no encrypted types.
401 sync_pb::NigoriSpecifics old_nigori; 402 sync_pb::NigoriSpecifics old_nigori;
402 other_cryptographer.GetKeys(old_nigori.mutable_encryption_keybag()); 403 other_cryptographer.GetKeys(old_nigori.mutable_encryption_keybag());
403 404
404 EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)); 405 EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
405 { 406 {
406 // Update the encryption handler. 407 // Update the encryption handler.
407 WriteTransaction trans(FROM_HERE, user_share()); 408 WriteTransaction trans(FROM_HERE, user_share());
408 encryption_handler()->ApplyNigoriUpdate( 409 encryption_handler()->ApplyNigoriUpdate(
409 old_nigori, 410 old_nigori,
410 trans.GetWrappedTrans()); 411 trans.GetWrappedTrans());
411 } 412 }
412 EXPECT_TRUE(GetCryptographer()->is_ready()); 413 EXPECT_TRUE(GetCryptographer()->is_ready());
413 EXPECT_FALSE(GetCryptographer()->has_pending_keys()); 414 EXPECT_FALSE(GetCryptographer()->has_pending_keys());
414 415
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK); 506 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK);
506 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); 507 Cryptographer other_cryptographer(GetCryptographer()->encryptor());
507 KeyParams other_key = {"localhost", "dummy", kOtherKey}; 508 KeyParams other_key = {"localhost", "dummy", kOtherKey};
508 other_cryptographer.AddKey(other_key); 509 other_cryptographer.AddKey(other_key);
509 510
510 sync_pb::NigoriSpecifics nigori; 511 sync_pb::NigoriSpecifics nigori;
511 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); 512 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
512 nigori.set_keybag_is_frozen(false); 513 nigori.set_keybag_is_frozen(false);
513 nigori.set_encrypt_everything(false); 514 nigori.set_encrypt_everything(false);
514 EXPECT_CALL(*observer(), 515 EXPECT_CALL(*observer(),
515 OnCryptographerStateChanged(_)); 516 OnCryptographerStateChanged(_)).Times(AnyNumber());
516 EXPECT_CALL(*observer(), 517 EXPECT_CALL(*observer(),
517 OnPassphraseRequired(_, _)); 518 OnPassphraseRequired(_, _));
518 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans()); 519 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
519 nigori_node.SetNigoriSpecifics(nigori); 520 nigori_node.SetNigoriSpecifics(nigori);
520 } 521 }
521 // Run any tasks posted via AppplyNigoriUpdate. 522 // Run any tasks posted via AppplyNigoriUpdate.
522 PumpLoop(); 523 PumpLoop();
523 EXPECT_FALSE(encryption_handler()->MigratedToKeystore()); 524 EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
524 Mock::VerifyAndClearExpectations(observer()); 525 Mock::VerifyAndClearExpectations(observer());
525 526
526 EXPECT_CALL(*observer(), 527 EXPECT_CALL(*observer(),
527 OnCryptographerStateChanged(_)); 528 OnCryptographerStateChanged(_)).Times(AnyNumber());
528 EXPECT_CALL(*observer(), 529 EXPECT_CALL(*observer(),
529 OnPassphraseAccepted()); 530 OnPassphraseAccepted());
530 EXPECT_CALL(*observer(), 531 EXPECT_CALL(*observer(),
531 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 532 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
532 EXPECT_CALL(*observer(), 533 EXPECT_CALL(*observer(),
533 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 534 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
534 EXPECT_CALL(*observer(), 535 EXPECT_CALL(*observer(),
535 OnEncryptionComplete()); 536 OnEncryptionComplete());
536 EXPECT_FALSE(encryption_handler()->MigratedToKeystore()); 537 EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
537 encryption_handler()->SetDecryptionPassphrase(kOtherKey); 538 encryption_handler()->SetDecryptionPassphrase(kOtherKey);
(...skipping 23 matching lines...) Expand all
561 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK); 562 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK);
562 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); 563 Cryptographer other_cryptographer(GetCryptographer()->encryptor());
563 KeyParams other_key = {"localhost", "dummy", kOtherKey}; 564 KeyParams other_key = {"localhost", "dummy", kOtherKey};
564 other_cryptographer.AddKey(other_key); 565 other_cryptographer.AddKey(other_key);
565 566
566 sync_pb::NigoriSpecifics nigori; 567 sync_pb::NigoriSpecifics nigori;
567 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); 568 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
568 nigori.set_keybag_is_frozen(true); 569 nigori.set_keybag_is_frozen(true);
569 nigori.set_encrypt_everything(false); 570 nigori.set_encrypt_everything(false);
570 EXPECT_CALL(*observer(), 571 EXPECT_CALL(*observer(),
571 OnCryptographerStateChanged(_)); 572 OnCryptographerStateChanged(_)).Times(AnyNumber());
572 EXPECT_CALL(*observer(), 573 EXPECT_CALL(*observer(),
573 OnPassphraseRequired(_, _)); 574 OnPassphraseRequired(_, _));
574 EXPECT_CALL(*observer(), 575 EXPECT_CALL(*observer(),
575 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 576 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
576 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans()); 577 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
577 nigori_node.SetNigoriSpecifics(nigori); 578 nigori_node.SetNigoriSpecifics(nigori);
578 } 579 }
579 // Run any tasks posted via AppplyNigoriUpdate. 580 // Run any tasks posted via AppplyNigoriUpdate.
580 PumpLoop(); 581 PumpLoop();
581 EXPECT_FALSE(encryption_handler()->MigratedToKeystore()); 582 EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
582 Mock::VerifyAndClearExpectations(observer()); 583 Mock::VerifyAndClearExpectations(observer());
583 584
584 EXPECT_CALL(*observer(), 585 EXPECT_CALL(*observer(),
585 OnCryptographerStateChanged(_)); 586 OnCryptographerStateChanged(_)).Times(AnyNumber());
586 EXPECT_CALL(*observer(), 587 EXPECT_CALL(*observer(),
587 OnPassphraseAccepted()); 588 OnPassphraseAccepted());
588 EXPECT_CALL(*observer(), 589 EXPECT_CALL(*observer(),
589 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 590 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
590 EXPECT_CALL(*observer(), 591 EXPECT_CALL(*observer(),
591 OnEncryptedTypesChanged(_, true)); 592 OnEncryptedTypesChanged(_, true));
592 EXPECT_CALL(*observer(), 593 EXPECT_CALL(*observer(),
593 OnEncryptionComplete()).Times(2); 594 OnEncryptionComplete()).Times(2);
594 EXPECT_FALSE(encryption_handler()->MigratedToKeystore()); 595 EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
595 encryption_handler()->SetDecryptionPassphrase(kOtherKey); 596 encryption_handler()->SetDecryptionPassphrase(kOtherKey);
596 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 597 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
597 EXPECT_EQ(CUSTOM_PASSPHRASE, encryption_handler()->GetPassphraseType()); 598 EXPECT_EQ(CUSTOM_PASSPHRASE, encryption_handler()->GetPassphraseType());
598 VerifyMigratedNigori(CUSTOM_PASSPHRASE, kOtherKey); 599 VerifyMigratedNigori(CUSTOM_PASSPHRASE, kOtherKey);
599 } 600 }
600 601
601 // Test that we trigger a migration when we set the keystore key, had an 602 // Test that we trigger a migration when we set the keystore key, had an
602 // implicit passphrase, and did not have encrypt everything. We should switch 603 // implicit passphrase, and did not have encrypt everything. We should switch
603 // to KEYSTORE_PASSPHRASE. 604 // to KEYSTORE_PASSPHRASE.
604 TEST_F(SyncEncryptionHandlerImplTest, MigrateOnKeystoreKeyAvailableImplicit) { 605 TEST_F(SyncEncryptionHandlerImplTest, MigrateOnKeystoreKeyAvailableImplicit) {
605 const char kCurKey[] = "cur"; 606 const char kCurKey[] = "cur";
606 KeyParams current_key = {"localhost", "dummy", kCurKey}; 607 KeyParams current_key = {"localhost", "dummy", kCurKey};
607 GetCryptographer()->AddKey(current_key); 608 GetCryptographer()->AddKey(current_key);
608 EXPECT_CALL(*observer(), 609 EXPECT_CALL(*observer(),
609 OnCryptographerStateChanged(_)); 610 OnCryptographerStateChanged(_)).Times(AnyNumber());
610 EXPECT_CALL(*observer(), 611 EXPECT_CALL(*observer(),
611 OnEncryptedTypesChanged(_, false)); 612 OnEncryptedTypesChanged(_, false));
612 EXPECT_CALL(*observer(), 613 EXPECT_CALL(*observer(),
613 OnEncryptionComplete()); 614 OnEncryptionComplete());
614 encryption_handler()->Init(); 615 encryption_handler()->Init();
615 Mock::VerifyAndClearExpectations(observer()); 616 Mock::VerifyAndClearExpectations(observer());
616 617
617 { 618 {
618 ReadTransaction trans(FROM_HERE, user_share()); 619 ReadTransaction trans(FROM_HERE, user_share());
619 // Once we provide a keystore key, we should perform the migration. 620 // Once we provide a keystore key, we should perform the migration.
620 EXPECT_CALL(*observer(), 621 EXPECT_CALL(*observer(),
622 OnCryptographerStateChanged(_)).Times(AnyNumber());
623 EXPECT_CALL(*observer(),
621 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 624 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
622 encryption_handler()->SetKeystoreKey(kRawKeystoreKey, 625 encryption_handler()->SetKeystoreKey(kRawKeystoreKey,
623 trans.GetWrappedTrans()); 626 trans.GetWrappedTrans());
624 } 627 }
625 EXPECT_CALL(*observer(), 628 EXPECT_CALL(*observer(),
626 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 629 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
627 // The actual migration gets posted, so run all pending tasks. 630 // The actual migration gets posted, so run all pending tasks.
628 PumpLoop(); 631 PumpLoop();
629 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 632 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
630 EXPECT_EQ(KEYSTORE_PASSPHRASE, 633 EXPECT_EQ(KEYSTORE_PASSPHRASE,
631 encryption_handler()->GetPassphraseType()); 634 encryption_handler()->GetPassphraseType());
632 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 635 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
633 VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey); 636 VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey);
634 } 637 }
635 638
636 // Test that we trigger a migration when we set the keystore key, had an 639 // Test that we trigger a migration when we set the keystore key, had an
637 // implicit passphrase, and encrypt everything enabled. We should switch to 640 // implicit passphrase, and encrypt everything enabled. We should switch to
638 // FROZEN_IMPLICIT_PASSPHRASE. 641 // FROZEN_IMPLICIT_PASSPHRASE.
639 TEST_F(SyncEncryptionHandlerImplTest, 642 TEST_F(SyncEncryptionHandlerImplTest,
640 MigrateOnKeystoreKeyAvailableFrozenImplicit) { 643 MigrateOnKeystoreKeyAvailableFrozenImplicit) {
641 const char kCurKey[] = "cur"; 644 const char kCurKey[] = "cur";
642 KeyParams current_key = {"localhost", "dummy", kCurKey}; 645 KeyParams current_key = {"localhost", "dummy", kCurKey};
643 GetCryptographer()->AddKey(current_key); 646 GetCryptographer()->AddKey(current_key);
644 EXPECT_CALL(*observer(), 647 EXPECT_CALL(*observer(),
645 OnCryptographerStateChanged(_)); 648 OnCryptographerStateChanged(_)).Times(AnyNumber());
646 EXPECT_CALL(*observer(), 649 EXPECT_CALL(*observer(),
647 OnEncryptedTypesChanged(_, false)); 650 OnEncryptedTypesChanged(_, false));
648 EXPECT_CALL(*observer(), 651 EXPECT_CALL(*observer(),
649 OnEncryptionComplete()); 652 OnEncryptionComplete());
650 encryption_handler()->Init(); 653 encryption_handler()->Init();
651 Mock::VerifyAndClearExpectations(observer()); 654 Mock::VerifyAndClearExpectations(observer());
652 655
653 EXPECT_CALL(*observer(), 656 EXPECT_CALL(*observer(),
654 OnEncryptedTypesChanged(_, true)); 657 OnEncryptedTypesChanged(_, true));
655 EXPECT_CALL(*observer(), 658 EXPECT_CALL(*observer(),
656 OnEncryptionComplete()); 659 OnEncryptionComplete());
657 encryption_handler()->EnableEncryptEverything(); 660 encryption_handler()->EnableEncryptEverything();
658 661
659 { 662 {
660 ReadTransaction trans(FROM_HERE, user_share()); 663 ReadTransaction trans(FROM_HERE, user_share());
661 // Once we provide a keystore key, we should perform the migration. 664 // Once we provide a keystore key, we should perform the migration.
662 EXPECT_CALL(*observer(), 665 EXPECT_CALL(*observer(),
666 OnCryptographerStateChanged(_)).Times(AnyNumber());
667 EXPECT_CALL(*observer(),
663 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 668 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
664 encryption_handler()->SetKeystoreKey(kRawKeystoreKey, 669 encryption_handler()->SetKeystoreKey(kRawKeystoreKey,
665 trans.GetWrappedTrans()); 670 trans.GetWrappedTrans());
666 } 671 }
667 EXPECT_CALL(*observer(), 672 EXPECT_CALL(*observer(),
668 OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE)); 673 OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE));
669 // The actual migration gets posted, so run all pending tasks. 674 // The actual migration gets posted, so run all pending tasks.
670 PumpLoop(); 675 PumpLoop();
671 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 676 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
672 EXPECT_EQ(FROZEN_IMPLICIT_PASSPHRASE, 677 EXPECT_EQ(FROZEN_IMPLICIT_PASSPHRASE,
673 encryption_handler()->GetPassphraseType()); 678 encryption_handler()->GetPassphraseType());
674 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled()); 679 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled());
675 VerifyMigratedNigori(FROZEN_IMPLICIT_PASSPHRASE, kCurKey); 680 VerifyMigratedNigori(FROZEN_IMPLICIT_PASSPHRASE, kCurKey);
676 } 681 }
677 682
678 // Test that we trigger a migration when we set the keystore key, had a 683 // Test that we trigger a migration when we set the keystore key, had a
679 // custom passphrase, and encrypt everything enabled. The passphrase state 684 // custom passphrase, and encrypt everything enabled. The passphrase state
680 // should remain as CUSTOM_PASSPHRASE, and encrypt everything stay the same. 685 // should remain as CUSTOM_PASSPHRASE, and encrypt everything stay the same.
681 TEST_F(SyncEncryptionHandlerImplTest, 686 TEST_F(SyncEncryptionHandlerImplTest,
682 MigrateOnKeystoreKeyAvailableCustomWithEncryption) { 687 MigrateOnKeystoreKeyAvailableCustomWithEncryption) {
683 const char kCurKey[] = "cur"; 688 const char kCurKey[] = "cur";
684 EXPECT_CALL(*observer(), 689 EXPECT_CALL(*observer(),
685 OnCryptographerStateChanged(_)).Times(2); 690 OnCryptographerStateChanged(_)).Times(AnyNumber());
686 EXPECT_CALL(*observer(), 691 EXPECT_CALL(*observer(),
687 OnPassphraseRequired(_, _)); 692 OnPassphraseRequired(_, _));
688 EXPECT_CALL(*observer(), 693 EXPECT_CALL(*observer(),
689 OnPassphraseAccepted()); 694 OnPassphraseAccepted());
690 EXPECT_CALL(*observer(), 695 EXPECT_CALL(*observer(),
691 OnEncryptedTypesChanged(_, false)); 696 OnEncryptedTypesChanged(_, false));
692 EXPECT_CALL(*observer(), 697 EXPECT_CALL(*observer(),
693 OnEncryptionComplete()); 698 OnEncryptionComplete());
694 EXPECT_CALL(*observer(), 699 EXPECT_CALL(*observer(),
695 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 700 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
696 EXPECT_CALL(*observer(), 701 EXPECT_CALL(*observer(),
697 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 702 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
698 encryption_handler()->Init(); 703 encryption_handler()->Init();
699 encryption_handler()->SetEncryptionPassphrase(kCurKey, true); 704 encryption_handler()->SetEncryptionPassphrase(kCurKey, true);
700 Mock::VerifyAndClearExpectations(observer()); 705 Mock::VerifyAndClearExpectations(observer());
701 706
702 EXPECT_CALL(*observer(), 707 EXPECT_CALL(*observer(),
703 OnEncryptedTypesChanged(_, true)); 708 OnEncryptedTypesChanged(_, true));
704 EXPECT_CALL(*observer(), 709 EXPECT_CALL(*observer(),
705 OnEncryptionComplete()); 710 OnEncryptionComplete());
706 encryption_handler()->EnableEncryptEverything(); 711 encryption_handler()->EnableEncryptEverything();
707 Mock::VerifyAndClearExpectations(observer()); 712 Mock::VerifyAndClearExpectations(observer());
708 713
709 { 714 {
710 ReadTransaction trans(FROM_HERE, user_share()); 715 ReadTransaction trans(FROM_HERE, user_share());
711 // Once we provide a keystore key, we should perform the migration. 716 // Once we provide a keystore key, we should perform the migration.
712 EXPECT_CALL(*observer(), 717 EXPECT_CALL(*observer(),
718 OnCryptographerStateChanged(_)).Times(AnyNumber());
719 EXPECT_CALL(*observer(),
713 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 720 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
714 encryption_handler()->SetKeystoreKey(kRawKeystoreKey, 721 encryption_handler()->SetKeystoreKey(kRawKeystoreKey,
715 trans.GetWrappedTrans()); 722 trans.GetWrappedTrans());
716 } 723 }
717 // The actual migration gets posted, so run all pending tasks. 724 // The actual migration gets posted, so run all pending tasks.
718 PumpLoop(); 725 PumpLoop();
719 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 726 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
720 EXPECT_EQ(CUSTOM_PASSPHRASE, 727 EXPECT_EQ(CUSTOM_PASSPHRASE,
721 encryption_handler()->GetPassphraseType()); 728 encryption_handler()->GetPassphraseType());
722 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled()); 729 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled());
723 VerifyMigratedNigori(CUSTOM_PASSPHRASE, kCurKey); 730 VerifyMigratedNigori(CUSTOM_PASSPHRASE, kCurKey);
724 } 731 }
725 732
726 // Test that we trigger a migration when we set the keystore key, had a 733 // Test that we trigger a migration when we set the keystore key, had a
727 // custom passphrase, and did not have encrypt everything. The passphrase state 734 // custom passphrase, and did not have encrypt everything. The passphrase state
728 // should remain as CUSTOM_PASSPHRASE, and encrypt everything should be enabled. 735 // should remain as CUSTOM_PASSPHRASE, and encrypt everything should be enabled.
729 TEST_F(SyncEncryptionHandlerImplTest, 736 TEST_F(SyncEncryptionHandlerImplTest,
730 MigrateOnKeystoreKeyAvailableCustomNoEncryption) { 737 MigrateOnKeystoreKeyAvailableCustomNoEncryption) {
731 const char kCurKey[] = "cur"; 738 const char kCurKey[] = "cur";
732 EXPECT_CALL(*observer(), 739 EXPECT_CALL(*observer(),
733 OnCryptographerStateChanged(_)).Times(2); 740 OnCryptographerStateChanged(_)).Times(AnyNumber());
734 EXPECT_CALL(*observer(), 741 EXPECT_CALL(*observer(),
735 OnPassphraseRequired(_, _)); 742 OnPassphraseRequired(_, _));
736 EXPECT_CALL(*observer(), 743 EXPECT_CALL(*observer(),
737 OnPassphraseAccepted()); 744 OnPassphraseAccepted());
738 EXPECT_CALL(*observer(), 745 EXPECT_CALL(*observer(),
739 OnEncryptedTypesChanged(_, false)); 746 OnEncryptedTypesChanged(_, false));
740 EXPECT_CALL(*observer(), 747 EXPECT_CALL(*observer(),
741 OnEncryptionComplete()); 748 OnEncryptionComplete());
742 EXPECT_CALL(*observer(), 749 EXPECT_CALL(*observer(),
743 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 750 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
744 EXPECT_CALL(*observer(), 751 EXPECT_CALL(*observer(),
745 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 752 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
746 encryption_handler()->Init(); 753 encryption_handler()->Init();
747 encryption_handler()->SetEncryptionPassphrase(kCurKey, true); 754 encryption_handler()->SetEncryptionPassphrase(kCurKey, true);
748 Mock::VerifyAndClearExpectations(observer()); 755 Mock::VerifyAndClearExpectations(observer());
749 756
750 { 757 {
751 ReadTransaction trans(FROM_HERE, user_share()); 758 ReadTransaction trans(FROM_HERE, user_share());
752 // Once we provide a keystore key, we should perform the migration. 759 // Once we provide a keystore key, we should perform the migration.
753 EXPECT_CALL(*observer(), 760 EXPECT_CALL(*observer(),
761 OnCryptographerStateChanged(_)).Times(AnyNumber());
762 EXPECT_CALL(*observer(),
754 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 763 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
755 encryption_handler()->SetKeystoreKey(kRawKeystoreKey, 764 encryption_handler()->SetKeystoreKey(kRawKeystoreKey,
756 trans.GetWrappedTrans()); 765 trans.GetWrappedTrans());
757 } 766 }
758 EXPECT_CALL(*observer(), 767 EXPECT_CALL(*observer(),
759 OnEncryptedTypesChanged(_, true)); 768 OnEncryptedTypesChanged(_, true));
760 EXPECT_CALL(*observer(), 769 EXPECT_CALL(*observer(),
761 OnEncryptionComplete()); 770 OnEncryptionComplete());
762 // The actual migration gets posted, so run all pending tasks. 771 // The actual migration gets posted, so run all pending tasks.
763 PumpLoop(); 772 PumpLoop();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 nigori.set_keystore_migration_time(1); 810 nigori.set_keystore_migration_time(1);
802 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE); 811 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE);
803 812
804 EXPECT_CALL(*observer(), 813 EXPECT_CALL(*observer(),
805 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 814 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
806 EXPECT_CALL(*observer(), 815 EXPECT_CALL(*observer(),
807 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 816 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
808 EXPECT_CALL(*observer(), 817 EXPECT_CALL(*observer(),
809 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 818 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
810 EXPECT_CALL(*observer(), 819 EXPECT_CALL(*observer(),
811 OnCryptographerStateChanged(_)).Times(2); 820 OnCryptographerStateChanged(_)).Times(AnyNumber());
812 encryption_handler()->SetKeystoreKey(kRawKeystoreKey, 821 encryption_handler()->SetKeystoreKey(kRawKeystoreKey,
813 trans.GetWrappedTrans()); 822 trans.GetWrappedTrans());
814 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans()); 823 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
815 nigori_node.SetNigoriSpecifics(nigori); 824 nigori_node.SetNigoriSpecifics(nigori);
816 } 825 }
817 // Run any tasks posted via AppplyNigoriUpdate. 826 // Run any tasks posted via AppplyNigoriUpdate.
818 PumpLoop(); 827 PumpLoop();
819 Mock::VerifyAndClearExpectations(observer()); 828 Mock::VerifyAndClearExpectations(observer());
820 829
821 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 830 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 trans.GetWrappedTrans()); 866 trans.GetWrappedTrans());
858 } 867 }
859 EXPECT_FALSE(encryption_handler()->MigratedToKeystore()); 868 EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
860 869
861 { 870 {
862 EXPECT_CALL(*observer(), 871 EXPECT_CALL(*observer(),
863 OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE)); 872 OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE));
864 EXPECT_CALL(*observer(), 873 EXPECT_CALL(*observer(),
865 OnPassphraseRequired(_, _)); 874 OnPassphraseRequired(_, _));
866 EXPECT_CALL(*observer(), 875 EXPECT_CALL(*observer(),
867 OnCryptographerStateChanged(_)); 876 OnCryptographerStateChanged(_)).Times(AnyNumber());
868 EXPECT_CALL(*observer(), 877 EXPECT_CALL(*observer(),
869 OnEncryptedTypesChanged(_, true)); 878 OnEncryptedTypesChanged(_, true));
870 WriteTransaction trans(FROM_HERE, user_share()); 879 WriteTransaction trans(FROM_HERE, user_share());
871 WriteNode nigori_node(&trans); 880 WriteNode nigori_node(&trans);
872 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK); 881 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK);
873 sync_pb::NigoriSpecifics nigori; 882 sync_pb::NigoriSpecifics nigori;
874 nigori.set_keybag_is_frozen(true); 883 nigori.set_keybag_is_frozen(true);
875 nigori.set_passphrase_type( 884 nigori.set_passphrase_type(
876 sync_pb::NigoriSpecifics::FROZEN_IMPLICIT_PASSPHRASE); 885 sync_pb::NigoriSpecifics::FROZEN_IMPLICIT_PASSPHRASE);
877 nigori.set_keystore_migration_time(1); 886 nigori.set_keystore_migration_time(1);
878 nigori.set_encrypt_everything(true); 887 nigori.set_encrypt_everything(true);
879 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); 888 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
880 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans()); 889 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
881 nigori_node.SetNigoriSpecifics(nigori); 890 nigori_node.SetNigoriSpecifics(nigori);
882 } 891 }
883 // Run any tasks posted via AppplyNigoriUpdate. 892 // Run any tasks posted via AppplyNigoriUpdate.
884 PumpLoop(); 893 PumpLoop();
885 Mock::VerifyAndClearExpectations(observer()); 894 Mock::VerifyAndClearExpectations(observer());
886 895
887 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 896 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
888 EXPECT_EQ(FROZEN_IMPLICIT_PASSPHRASE, 897 EXPECT_EQ(FROZEN_IMPLICIT_PASSPHRASE,
889 encryption_handler()->GetPassphraseType()); 898 encryption_handler()->GetPassphraseType());
890 EXPECT_TRUE(GetCryptographer()->has_pending_keys()); 899 EXPECT_TRUE(GetCryptographer()->has_pending_keys());
891 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled()); 900 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled());
892 901
893 EXPECT_CALL(*observer(), 902 EXPECT_CALL(*observer(),
894 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 903 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
895 EXPECT_CALL(*observer(), 904 EXPECT_CALL(*observer(),
896 OnCryptographerStateChanged(_)); 905 OnCryptographerStateChanged(_)).Times(AnyNumber());
897 EXPECT_CALL(*observer(), 906 EXPECT_CALL(*observer(),
898 OnEncryptionComplete()); 907 OnEncryptionComplete());
899 EXPECT_CALL(*observer(), 908 EXPECT_CALL(*observer(),
900 OnPassphraseAccepted()); 909 OnPassphraseAccepted());
901 encryption_handler()->SetDecryptionPassphrase(kCurKey); 910 encryption_handler()->SetDecryptionPassphrase(kCurKey);
902 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 911 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
903 EXPECT_TRUE(GetCryptographer()->is_ready()); 912 EXPECT_TRUE(GetCryptographer()->is_ready());
904 VerifyMigratedNigoriWithTimestamp(1, FROZEN_IMPLICIT_PASSPHRASE, kCurKey); 913 VerifyMigratedNigoriWithTimestamp(1, FROZEN_IMPLICIT_PASSPHRASE, kCurKey);
905 914
906 // Check that the cryptographer still encrypts with the current key. 915 // Check that the cryptographer still encrypts with the current key.
(...skipping 29 matching lines...) Expand all
936 trans.GetWrappedTrans()); 945 trans.GetWrappedTrans());
937 } 946 }
938 EXPECT_FALSE(encryption_handler()->MigratedToKeystore()); 947 EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
939 948
940 { 949 {
941 EXPECT_CALL(*observer(), 950 EXPECT_CALL(*observer(),
942 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 951 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
943 EXPECT_CALL(*observer(), 952 EXPECT_CALL(*observer(),
944 OnPassphraseRequired(_, _)); 953 OnPassphraseRequired(_, _));
945 EXPECT_CALL(*observer(), 954 EXPECT_CALL(*observer(),
946 OnCryptographerStateChanged(_)); 955 OnCryptographerStateChanged(_)).Times(AnyNumber());
947 EXPECT_CALL(*observer(), 956 EXPECT_CALL(*observer(),
948 OnEncryptedTypesChanged(_, true)); 957 OnEncryptedTypesChanged(_, true));
949 WriteTransaction trans(FROM_HERE, user_share()); 958 WriteTransaction trans(FROM_HERE, user_share());
950 WriteNode nigori_node(&trans); 959 WriteNode nigori_node(&trans);
951 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK); 960 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK);
952 sync_pb::NigoriSpecifics nigori; 961 sync_pb::NigoriSpecifics nigori;
953 nigori.set_keybag_is_frozen(true); 962 nigori.set_keybag_is_frozen(true);
954 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE); 963 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE);
955 nigori.set_keystore_migration_time(1); 964 nigori.set_keystore_migration_time(1);
956 nigori.set_encrypt_everything(true); 965 nigori.set_encrypt_everything(true);
957 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); 966 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
958 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans()); 967 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
959 nigori_node.SetNigoriSpecifics(nigori); 968 nigori_node.SetNigoriSpecifics(nigori);
960 } 969 }
961 // Run any tasks posted via AppplyNigoriUpdate. 970 // Run any tasks posted via AppplyNigoriUpdate.
962 PumpLoop(); 971 PumpLoop();
963 Mock::VerifyAndClearExpectations(observer()); 972 Mock::VerifyAndClearExpectations(observer());
964 973
965 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 974 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
966 EXPECT_EQ(CUSTOM_PASSPHRASE, encryption_handler()->GetPassphraseType()); 975 EXPECT_EQ(CUSTOM_PASSPHRASE, encryption_handler()->GetPassphraseType());
967 EXPECT_TRUE(GetCryptographer()->has_pending_keys()); 976 EXPECT_TRUE(GetCryptographer()->has_pending_keys());
968 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled()); 977 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled());
969 978
970 EXPECT_CALL(*observer(), 979 EXPECT_CALL(*observer(),
971 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 980 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
972 EXPECT_CALL(*observer(), 981 EXPECT_CALL(*observer(),
973 OnCryptographerStateChanged(_)); 982 OnCryptographerStateChanged(_)).Times(AnyNumber());
974 EXPECT_CALL(*observer(), 983 EXPECT_CALL(*observer(),
975 OnEncryptionComplete()); 984 OnEncryptionComplete());
976 EXPECT_CALL(*observer(), 985 EXPECT_CALL(*observer(),
977 OnPassphraseAccepted()); 986 OnPassphraseAccepted());
978 encryption_handler()->SetDecryptionPassphrase(kCurKey); 987 encryption_handler()->SetDecryptionPassphrase(kCurKey);
979 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 988 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
980 EXPECT_TRUE(GetCryptographer()->is_ready()); 989 EXPECT_TRUE(GetCryptographer()->is_ready());
981 VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kCurKey); 990 VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kCurKey);
982 991
983 // Check that the cryptographer still encrypts with the current key. 992 // Check that the cryptographer still encrypts with the current key.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 nigori.set_keybag_is_frozen(true); 1025 nigori.set_keybag_is_frozen(true);
1017 nigori.set_keystore_migration_time(1); 1026 nigori.set_keystore_migration_time(1);
1018 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE); 1027 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE);
1019 nigori.set_encrypt_everything(true); 1028 nigori.set_encrypt_everything(true);
1020 nigori_node.SetNigoriSpecifics(nigori); 1029 nigori_node.SetNigoriSpecifics(nigori);
1021 } 1030 }
1022 1031
1023 EXPECT_CALL(*observer(), 1032 EXPECT_CALL(*observer(),
1024 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 1033 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
1025 EXPECT_CALL(*observer(), 1034 EXPECT_CALL(*observer(),
1026 OnCryptographerStateChanged(_)); 1035 OnCryptographerStateChanged(_)).Times(AnyNumber());
1027 EXPECT_CALL(*observer(), 1036 EXPECT_CALL(*observer(),
1028 OnEncryptedTypesChanged(_, true)).Times(2); 1037 OnEncryptedTypesChanged(_, true)).Times(2);
1029 EXPECT_CALL(*observer(), 1038 EXPECT_CALL(*observer(),
1030 OnEncryptionComplete()); 1039 OnEncryptionComplete());
1031 encryption_handler()->Init(); 1040 encryption_handler()->Init();
1032 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1041 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1033 EXPECT_TRUE(GetCryptographer()->is_ready()); 1042 EXPECT_TRUE(GetCryptographer()->is_ready());
1034 EXPECT_EQ(encryption_handler()->GetPassphraseType(), CUSTOM_PASSPHRASE); 1043 EXPECT_EQ(encryption_handler()->GetPassphraseType(), CUSTOM_PASSPHRASE);
1035 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled()); 1044 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled());
1036 VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kCurKey); 1045 VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kCurKey);
1037 1046
1038 { 1047 {
1039 EXPECT_CALL(*observer(), 1048 EXPECT_CALL(*observer(),
1040 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 1049 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
1041 ReadTransaction trans(FROM_HERE, user_share()); 1050 ReadTransaction trans(FROM_HERE, user_share());
1042 encryption_handler()->SetKeystoreKey(kRawKeystoreKey, 1051 encryption_handler()->SetKeystoreKey(kRawKeystoreKey,
1043 trans.GetWrappedTrans()); 1052 trans.GetWrappedTrans());
1044 } 1053 }
1045 Mock::VerifyAndClearExpectations(observer()); 1054 Mock::VerifyAndClearExpectations(observer());
1046 1055
1047 // Now build an old unmigrated nigori node with old encrypted types. We should 1056 // Now build an old unmigrated nigori node with old encrypted types. We should
1048 // properly overwrite it with the migrated + encrypt everything state. 1057 // properly overwrite it with the migrated + encrypt everything state.
1049 EXPECT_CALL(*observer(), 1058 EXPECT_CALL(*observer(),
1050 OnCryptographerStateChanged(_)); 1059 OnCryptographerStateChanged(_)).Times(AnyNumber());
1051 { 1060 {
1052 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); 1061 Cryptographer other_cryptographer(GetCryptographer()->encryptor());
1053 other_cryptographer.AddKey(old_key); 1062 other_cryptographer.AddKey(old_key);
1054 WriteTransaction trans(FROM_HERE, user_share()); 1063 WriteTransaction trans(FROM_HERE, user_share());
1055 WriteNode nigori_node(&trans); 1064 WriteNode nigori_node(&trans);
1056 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK); 1065 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK);
1057 sync_pb::NigoriSpecifics nigori; 1066 sync_pb::NigoriSpecifics nigori;
1058 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); 1067 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
1059 nigori.set_keybag_is_frozen(false); 1068 nigori.set_keybag_is_frozen(false);
1060 nigori.set_encrypt_everything(false); 1069 nigori.set_encrypt_everything(false);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 nigori.set_keybag_is_frozen(true); 1103 nigori.set_keybag_is_frozen(true);
1095 nigori.set_keystore_migration_time(1); 1104 nigori.set_keystore_migration_time(1);
1096 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE); 1105 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE);
1097 nigori.set_encrypt_everything(true); 1106 nigori.set_encrypt_everything(true);
1098 nigori_node.SetNigoriSpecifics(nigori); 1107 nigori_node.SetNigoriSpecifics(nigori);
1099 } 1108 }
1100 1109
1101 EXPECT_CALL(*observer(), 1110 EXPECT_CALL(*observer(),
1102 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 1111 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
1103 EXPECT_CALL(*observer(), 1112 EXPECT_CALL(*observer(),
1104 OnCryptographerStateChanged(_)); 1113 OnCryptographerStateChanged(_)).Times(AnyNumber());
1105 EXPECT_CALL(*observer(), 1114 EXPECT_CALL(*observer(),
1106 OnEncryptedTypesChanged(_, true)).Times(2); 1115 OnEncryptedTypesChanged(_, true)).Times(2);
1107 EXPECT_CALL(*observer(), 1116 EXPECT_CALL(*observer(),
1108 OnEncryptionComplete()); 1117 OnEncryptionComplete());
1109 encryption_handler()->Init(); 1118 encryption_handler()->Init();
1110 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1119 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1111 EXPECT_TRUE(GetCryptographer()->is_ready()); 1120 EXPECT_TRUE(GetCryptographer()->is_ready());
1112 EXPECT_EQ(encryption_handler()->GetPassphraseType(), CUSTOM_PASSPHRASE); 1121 EXPECT_EQ(encryption_handler()->GetPassphraseType(), CUSTOM_PASSPHRASE);
1113 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled()); 1122 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled());
1114 VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kCurKey); 1123 VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kCurKey);
1115 1124
1116 { 1125 {
1117 EXPECT_CALL(*observer(), 1126 EXPECT_CALL(*observer(),
1118 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 1127 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
1119 ReadTransaction trans(FROM_HERE, user_share()); 1128 ReadTransaction trans(FROM_HERE, user_share());
1120 encryption_handler()->SetKeystoreKey(kRawKeystoreKey, 1129 encryption_handler()->SetKeystoreKey(kRawKeystoreKey,
1121 trans.GetWrappedTrans()); 1130 trans.GetWrappedTrans());
1122 } 1131 }
1123 Mock::VerifyAndClearExpectations(observer()); 1132 Mock::VerifyAndClearExpectations(observer());
1124 1133
1125 // Now build an old keystore nigori node with old encrypted types. We should 1134 // Now build an old keystore nigori node with old encrypted types. We should
1126 // properly overwrite it with the migrated + encrypt everything state. 1135 // properly overwrite it with the migrated + encrypt everything state.
1127 EXPECT_CALL(*observer(), 1136 EXPECT_CALL(*observer(),
1128 OnCryptographerStateChanged(_)); 1137 OnCryptographerStateChanged(_)).Times(AnyNumber());
1129 { 1138 {
1130 WriteTransaction trans(FROM_HERE, user_share()); 1139 WriteTransaction trans(FROM_HERE, user_share());
1131 WriteNode nigori_node(&trans); 1140 WriteNode nigori_node(&trans);
1132 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK); 1141 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK);
1133 sync_pb::NigoriSpecifics nigori; 1142 sync_pb::NigoriSpecifics nigori;
1134 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); 1143 Cryptographer other_cryptographer(GetCryptographer()->encryptor());
1135 other_cryptographer.AddKey(old_key); 1144 other_cryptographer.AddKey(old_key);
1136 encryption_handler()->GetKeystoreDecryptor( 1145 encryption_handler()->GetKeystoreDecryptor(
1137 other_cryptographer, 1146 other_cryptographer,
1138 kKeystoreKey, 1147 kKeystoreKey,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 nigori.mutable_keystore_decryptor_token()->CopyFrom( 1192 nigori.mutable_keystore_decryptor_token()->CopyFrom(
1184 keystore_decryptor_token); 1193 keystore_decryptor_token);
1185 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); 1194 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
1186 nigori.set_keybag_is_frozen(true); 1195 nigori.set_keybag_is_frozen(true);
1187 nigori.set_keystore_migration_time(1); 1196 nigori.set_keystore_migration_time(1);
1188 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE); 1197 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE);
1189 1198
1190 EXPECT_CALL(*observer(), 1199 EXPECT_CALL(*observer(),
1191 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 1200 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
1192 EXPECT_CALL(*observer(), 1201 EXPECT_CALL(*observer(),
1193 OnCryptographerStateChanged(_)); 1202 OnCryptographerStateChanged(_)).Times(AnyNumber());
1194 EXPECT_CALL(*observer(), 1203 EXPECT_CALL(*observer(),
1195 OnPassphraseRequired(_, _)); 1204 OnPassphraseRequired(_, _));
1196 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans()); 1205 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
1197 nigori_node.SetNigoriSpecifics(nigori); 1206 nigori_node.SetNigoriSpecifics(nigori);
1198 } 1207 }
1199 // Run any tasks posted via AppplyNigoriUpdate. 1208 // Run any tasks posted via AppplyNigoriUpdate.
1200 PumpLoop(); 1209 PumpLoop();
1201 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1210 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1202 EXPECT_TRUE(GetCryptographer()->has_pending_keys()); 1211 EXPECT_TRUE(GetCryptographer()->has_pending_keys());
1203 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); 1212 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
1204 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1213 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1205 Mock::VerifyAndClearExpectations(observer()); 1214 Mock::VerifyAndClearExpectations(observer());
1206 1215
1207 EXPECT_CALL(*observer(), 1216 EXPECT_CALL(*observer(),
1208 OnCryptographerStateChanged(_)); 1217 OnCryptographerStateChanged(_)).Times(AnyNumber());
1209 EXPECT_CALL(*observer(), 1218 EXPECT_CALL(*observer(),
1210 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1219 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1211 { 1220 {
1212 EXPECT_CALL(*observer(), 1221 EXPECT_CALL(*observer(),
1213 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 1222 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
1214 ReadTransaction trans(FROM_HERE, user_share()); 1223 ReadTransaction trans(FROM_HERE, user_share());
1215 encryption_handler()->SetKeystoreKey(kRawKeystoreKey, 1224 encryption_handler()->SetKeystoreKey(kRawKeystoreKey,
1216 trans.GetWrappedTrans()); 1225 trans.GetWrappedTrans());
1217 } 1226 }
1218 PumpLoop(); 1227 PumpLoop();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 nigori_node.SetNigoriSpecifics(nigori); 1277 nigori_node.SetNigoriSpecifics(nigori);
1269 EXPECT_CALL(*observer(), 1278 EXPECT_CALL(*observer(),
1270 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 1279 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
1271 encryption_handler()->SetKeystoreKey(kRawKeystoreKey, 1280 encryption_handler()->SetKeystoreKey(kRawKeystoreKey,
1272 trans.GetWrappedTrans()); 1281 trans.GetWrappedTrans());
1273 } 1282 }
1274 1283
1275 EXPECT_CALL(*observer(), 1284 EXPECT_CALL(*observer(),
1276 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 1285 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
1277 EXPECT_CALL(*observer(), 1286 EXPECT_CALL(*observer(),
1278 OnCryptographerStateChanged(_)).Times(2); 1287 OnCryptographerStateChanged(_)).Times(AnyNumber());
1279 EXPECT_CALL(*observer(), 1288 EXPECT_CALL(*observer(),
1280 OnEncryptedTypesChanged(_, false)); 1289 OnEncryptedTypesChanged(_, false));
1281 EXPECT_CALL(*observer(), 1290 EXPECT_CALL(*observer(),
1282 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1291 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1283 EXPECT_CALL(*observer(), 1292 EXPECT_CALL(*observer(),
1284 OnEncryptionComplete()); 1293 OnEncryptionComplete());
1285 encryption_handler()->Init(); 1294 encryption_handler()->Init();
1286 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1295 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1287 EXPECT_TRUE(GetCryptographer()->is_ready()); 1296 EXPECT_TRUE(GetCryptographer()->is_ready());
1288 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); 1297 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
1289 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1298 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1290 Mock::VerifyAndClearExpectations(observer()); 1299 Mock::VerifyAndClearExpectations(observer());
1291 1300
1292 const char kNewKey[] = "new_key"; 1301 const char kNewKey[] = "new_key";
1293 EXPECT_CALL(*observer(), 1302 EXPECT_CALL(*observer(),
1294 OnCryptographerStateChanged(_)); 1303 OnCryptographerStateChanged(_)).Times(AnyNumber());
1295 EXPECT_CALL(*observer(), 1304 EXPECT_CALL(*observer(),
1296 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 1305 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
1297 EXPECT_CALL(*observer(), 1306 EXPECT_CALL(*observer(),
1298 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1307 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1299 EXPECT_CALL(*observer(), 1308 EXPECT_CALL(*observer(),
1300 OnPassphraseAccepted()); 1309 OnPassphraseAccepted());
1301 EXPECT_CALL(*observer(), 1310 EXPECT_CALL(*observer(),
1302 OnEncryptedTypesChanged(_, true)); 1311 OnEncryptedTypesChanged(_, true));
1303 EXPECT_CALL(*observer(), 1312 EXPECT_CALL(*observer(),
1304 OnEncryptionComplete()).Times(2); 1313 OnEncryptionComplete()).Times(2);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 nigori.set_keystore_migration_time(1); 1374 nigori.set_keystore_migration_time(1);
1366 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE); 1375 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE);
1367 nigori_node.SetNigoriSpecifics(nigori); 1376 nigori_node.SetNigoriSpecifics(nigori);
1368 } 1377 }
1369 1378
1370 EXPECT_CALL(*observer(), 1379 EXPECT_CALL(*observer(),
1371 OnPassphraseRequired(_, _)); 1380 OnPassphraseRequired(_, _));
1372 EXPECT_CALL(*observer(), 1381 EXPECT_CALL(*observer(),
1373 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 1382 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
1374 EXPECT_CALL(*observer(), 1383 EXPECT_CALL(*observer(),
1375 OnCryptographerStateChanged(_)); 1384 OnCryptographerStateChanged(_)).Times(AnyNumber());
1376 EXPECT_CALL(*observer(), 1385 EXPECT_CALL(*observer(),
1377 OnEncryptedTypesChanged(_, false)); 1386 OnEncryptedTypesChanged(_, false));
1378 encryption_handler()->Init(); 1387 encryption_handler()->Init();
1379 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1388 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1380 EXPECT_TRUE(GetCryptographer()->has_pending_keys()); 1389 EXPECT_TRUE(GetCryptographer()->has_pending_keys());
1381 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); 1390 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
1382 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1391 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1383 Mock::VerifyAndClearExpectations(observer()); 1392 Mock::VerifyAndClearExpectations(observer());
1384 1393
1385 EXPECT_CALL(*observer(), 1394 EXPECT_CALL(*observer(),
1386 OnPassphraseAccepted()); 1395 OnPassphraseAccepted());
1387 EXPECT_CALL(*observer(), 1396 EXPECT_CALL(*observer(),
1388 OnCryptographerStateChanged(_)); 1397 OnCryptographerStateChanged(_)).Times(AnyNumber());
1389 EXPECT_CALL(*observer(), 1398 EXPECT_CALL(*observer(),
1390 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1399 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1391 EXPECT_CALL(*observer(), 1400 EXPECT_CALL(*observer(),
1392 OnEncryptionComplete()); 1401 OnEncryptionComplete());
1393 encryption_handler()->SetDecryptionPassphrase(kOldKey); 1402 encryption_handler()->SetDecryptionPassphrase(kOldKey);
1394 EXPECT_TRUE(GetCryptographer()->is_ready()); 1403 EXPECT_TRUE(GetCryptographer()->is_ready());
1395 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1404 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1396 Mock::VerifyAndClearExpectations(observer()); 1405 Mock::VerifyAndClearExpectations(observer());
1397 1406
1398 const char kNewKey[] = "new_key"; 1407 const char kNewKey[] = "new_key";
1399 EXPECT_CALL(*observer(), 1408 EXPECT_CALL(*observer(),
1400 OnCryptographerStateChanged(_)); 1409 OnCryptographerStateChanged(_)).Times(AnyNumber());
1401 EXPECT_CALL(*observer(), 1410 EXPECT_CALL(*observer(),
1402 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 1411 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
1403 EXPECT_CALL(*observer(), 1412 EXPECT_CALL(*observer(),
1404 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1413 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1405 EXPECT_CALL(*observer(), 1414 EXPECT_CALL(*observer(),
1406 OnPassphraseAccepted()); 1415 OnPassphraseAccepted());
1407 EXPECT_CALL(*observer(), 1416 EXPECT_CALL(*observer(),
1408 OnEncryptedTypesChanged(_, true)); 1417 OnEncryptedTypesChanged(_, true));
1409 EXPECT_CALL(*observer(), 1418 EXPECT_CALL(*observer(),
1410 OnEncryptionComplete()).Times(2); 1419 OnEncryptionComplete()).Times(2);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 nigori.set_keystore_migration_time(1); 1480 nigori.set_keystore_migration_time(1);
1472 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE); 1481 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE);
1473 nigori_node.SetNigoriSpecifics(nigori); 1482 nigori_node.SetNigoriSpecifics(nigori);
1474 } 1483 }
1475 1484
1476 EXPECT_CALL(*observer(), 1485 EXPECT_CALL(*observer(),
1477 OnPassphraseRequired(_, _)); 1486 OnPassphraseRequired(_, _));
1478 EXPECT_CALL(*observer(), 1487 EXPECT_CALL(*observer(),
1479 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 1488 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
1480 EXPECT_CALL(*observer(), 1489 EXPECT_CALL(*observer(),
1481 OnCryptographerStateChanged(_)); 1490 OnCryptographerStateChanged(_)).Times(AnyNumber());
1482 EXPECT_CALL(*observer(), 1491 EXPECT_CALL(*observer(),
1483 OnEncryptedTypesChanged(_, false)); 1492 OnEncryptedTypesChanged(_, false));
1484 encryption_handler()->Init(); 1493 encryption_handler()->Init();
1485 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1494 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1486 EXPECT_TRUE(GetCryptographer()->has_pending_keys()); 1495 EXPECT_TRUE(GetCryptographer()->has_pending_keys());
1487 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); 1496 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
1488 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1497 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1489 Mock::VerifyAndClearExpectations(observer()); 1498 Mock::VerifyAndClearExpectations(observer());
1490 1499
1491 EXPECT_CALL(*observer(), 1500 EXPECT_CALL(*observer(),
1492 OnPassphraseAccepted()); 1501 OnPassphraseAccepted());
1493 EXPECT_CALL(*observer(), 1502 EXPECT_CALL(*observer(),
1494 OnCryptographerStateChanged(_)); 1503 OnCryptographerStateChanged(_)).Times(AnyNumber());
1495 EXPECT_CALL(*observer(), 1504 EXPECT_CALL(*observer(),
1496 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1505 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1497 EXPECT_CALL(*observer(), 1506 EXPECT_CALL(*observer(),
1498 OnEncryptionComplete()); 1507 OnEncryptionComplete());
1499 encryption_handler()->SetDecryptionPassphrase(kOldKey); 1508 encryption_handler()->SetDecryptionPassphrase(kOldKey);
1500 EXPECT_TRUE(GetCryptographer()->is_ready()); 1509 EXPECT_TRUE(GetCryptographer()->is_ready());
1501 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1510 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1502 Mock::VerifyAndClearExpectations(observer()); 1511 Mock::VerifyAndClearExpectations(observer());
1503 1512
1504 // Should get dropped on the floor silently. 1513 // Should get dropped on the floor silently.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 nigori.set_keybag_is_frozen(true); 1574 nigori.set_keybag_is_frozen(true);
1566 nigori.set_keystore_migration_time(1); 1575 nigori.set_keystore_migration_time(1);
1567 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE); 1576 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE);
1568 nigori_node.SetNigoriSpecifics(nigori); 1577 nigori_node.SetNigoriSpecifics(nigori);
1569 } 1578 }
1570 EXPECT_CALL(*observer(), 1579 EXPECT_CALL(*observer(),
1571 OnPassphraseRequired(_, _)); 1580 OnPassphraseRequired(_, _));
1572 EXPECT_CALL(*observer(), 1581 EXPECT_CALL(*observer(),
1573 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 1582 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
1574 EXPECT_CALL(*observer(), 1583 EXPECT_CALL(*observer(),
1575 OnCryptographerStateChanged(_)); 1584 OnCryptographerStateChanged(_)).Times(AnyNumber());
1576 EXPECT_CALL(*observer(), 1585 EXPECT_CALL(*observer(),
1577 OnEncryptedTypesChanged(_, false)); 1586 OnEncryptedTypesChanged(_, false));
1578 encryption_handler()->Init(); 1587 encryption_handler()->Init();
1579 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1588 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1580 EXPECT_TRUE(GetCryptographer()->has_pending_keys()); 1589 EXPECT_TRUE(GetCryptographer()->has_pending_keys());
1581 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); 1590 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
1582 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1591 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1583 Mock::VerifyAndClearExpectations(observer()); 1592 Mock::VerifyAndClearExpectations(observer());
1584 1593
1585 EXPECT_CALL(*observer(), 1594 EXPECT_CALL(*observer(),
1586 OnPassphraseAccepted()); 1595 OnPassphraseAccepted());
1587 EXPECT_CALL(*observer(), 1596 EXPECT_CALL(*observer(),
1588 OnCryptographerStateChanged(_)); 1597 OnCryptographerStateChanged(_)).Times(AnyNumber());
1589 EXPECT_CALL(*observer(), 1598 EXPECT_CALL(*observer(),
1590 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1599 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1591 EXPECT_CALL(*observer(), 1600 EXPECT_CALL(*observer(),
1592 OnEncryptionComplete()); 1601 OnEncryptionComplete());
1593 encryption_handler()->SetDecryptionPassphrase(kCurKey); 1602 encryption_handler()->SetDecryptionPassphrase(kCurKey);
1594 Mock::VerifyAndClearExpectations(observer()); 1603 Mock::VerifyAndClearExpectations(observer());
1595 1604
1596 EXPECT_CALL(*observer(), 1605 EXPECT_CALL(*observer(),
1597 OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE)); 1606 OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE));
1598 EXPECT_CALL(*observer(), 1607 EXPECT_CALL(*observer(),
1599 OnEncryptionComplete()); 1608 OnEncryptionComplete());
1600 EXPECT_CALL(*observer(), 1609 EXPECT_CALL(*observer(),
1601 OnEncryptedTypesChanged(_, true)); 1610 OnEncryptedTypesChanged(_, true));
1611 EXPECT_CALL(*observer(),
1612 OnCryptographerStateChanged(_)).Times(AnyNumber());
1602 encryption_handler()->EnableEncryptEverything(); 1613 encryption_handler()->EnableEncryptEverything();
1603 Mock::VerifyAndClearExpectations(observer()); 1614 Mock::VerifyAndClearExpectations(observer());
1604 1615
1605 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1616 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1606 EXPECT_TRUE(GetCryptographer()->is_ready()); 1617 EXPECT_TRUE(GetCryptographer()->is_ready());
1607 EXPECT_EQ(FROZEN_IMPLICIT_PASSPHRASE, 1618 EXPECT_EQ(FROZEN_IMPLICIT_PASSPHRASE,
1608 encryption_handler()->GetPassphraseType()); 1619 encryption_handler()->GetPassphraseType());
1609 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled()); 1620 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled());
1610 VerifyMigratedNigoriWithTimestamp(1, FROZEN_IMPLICIT_PASSPHRASE, kCurKey); 1621 VerifyMigratedNigoriWithTimestamp(1, FROZEN_IMPLICIT_PASSPHRASE, kCurKey);
1611 1622
(...skipping 23 matching lines...) Expand all
1635 KeyParams cur_key = {"localhost", "dummy", kCurKey}; 1646 KeyParams cur_key = {"localhost", "dummy", kCurKey};
1636 KeyParams keystore_key = {"localhost", "dummy", kKeystoreKey}; 1647 KeyParams keystore_key = {"localhost", "dummy", kKeystoreKey};
1637 GetCryptographer()->AddKey(old_key); 1648 GetCryptographer()->AddKey(old_key);
1638 GetCryptographer()->AddKey(cur_key); 1649 GetCryptographer()->AddKey(cur_key);
1639 1650
1640 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); 1651 Cryptographer other_cryptographer(GetCryptographer()->encryptor());
1641 other_cryptographer.AddKey(old_key); 1652 other_cryptographer.AddKey(old_key);
1642 EXPECT_TRUE(other_cryptographer.is_ready()); 1653 EXPECT_TRUE(other_cryptographer.is_ready());
1643 1654
1644 EXPECT_CALL(*observer(), 1655 EXPECT_CALL(*observer(),
1645 OnCryptographerStateChanged(_)); 1656 OnCryptographerStateChanged(_)).Times(AnyNumber());
1646 EXPECT_CALL(*observer(), 1657 EXPECT_CALL(*observer(),
1647 OnEncryptedTypesChanged(_, false)); 1658 OnEncryptedTypesChanged(_, false));
1648 EXPECT_CALL(*observer(), 1659 EXPECT_CALL(*observer(),
1649 OnEncryptionComplete()); 1660 OnEncryptionComplete());
1650 encryption_handler()->Init(); 1661 encryption_handler()->Init();
1651 EXPECT_TRUE(GetCryptographer()->is_ready()); 1662 EXPECT_TRUE(GetCryptographer()->is_ready());
1652 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1663 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1653 1664
1654 { 1665 {
1655 EXPECT_CALL(*observer(), 1666 EXPECT_CALL(*observer(),
1656 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 1667 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
1657 ReadTransaction trans(FROM_HERE, user_share()); 1668 ReadTransaction trans(FROM_HERE, user_share());
1658 encryption_handler()->SetKeystoreKey(kRawKeystoreKey, 1669 encryption_handler()->SetKeystoreKey(kRawKeystoreKey,
1659 trans.GetWrappedTrans()); 1670 trans.GetWrappedTrans());
1660 } 1671 }
1661 EXPECT_CALL(*observer(), 1672 EXPECT_CALL(*observer(),
1662 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 1673 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
1663 PumpLoop(); 1674 PumpLoop();
1664 Mock::VerifyAndClearExpectations(observer()); 1675 Mock::VerifyAndClearExpectations(observer());
1665 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1676 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1666 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); 1677 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
1667 VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey); 1678 VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey);
1668 1679
1669 // Now build an old keystore passphrase nigori node. 1680 // Now build an old keystore passphrase nigori node.
1670 EXPECT_CALL(*observer(), 1681 EXPECT_CALL(*observer(),
1671 OnCryptographerStateChanged(_)); 1682 OnCryptographerStateChanged(_)).Times(AnyNumber());
1672 { 1683 {
1673 WriteTransaction trans(FROM_HERE, user_share()); 1684 WriteTransaction trans(FROM_HERE, user_share());
1674 WriteNode nigori_node(&trans); 1685 WriteNode nigori_node(&trans);
1675 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK); 1686 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK);
1676 sync_pb::NigoriSpecifics nigori; 1687 sync_pb::NigoriSpecifics nigori;
1677 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); 1688 Cryptographer other_cryptographer(GetCryptographer()->encryptor());
1678 other_cryptographer.AddKey(old_key); 1689 other_cryptographer.AddKey(old_key);
1679 encryption_handler()->GetKeystoreDecryptor( 1690 encryption_handler()->GetKeystoreDecryptor(
1680 other_cryptographer, 1691 other_cryptographer,
1681 kKeystoreKey, 1692 kKeystoreKey,
(...skipping 10 matching lines...) Expand all
1692 1703
1693 // Verify we're still migrated and have proper encryption state. 1704 // Verify we're still migrated and have proper encryption state.
1694 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1705 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1695 EXPECT_TRUE(GetCryptographer()->is_ready()); 1706 EXPECT_TRUE(GetCryptographer()->is_ready());
1696 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); 1707 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
1697 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1708 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1698 VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey); 1709 VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey);
1699 } 1710 }
1700 1711
1701 } // namespace syncer 1712 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/sync_encryption_handler_impl.cc ('k') | sync/internal_api/sync_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698