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

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 + address comments 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/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 13 matching lines...) Expand all
24 #include "sync/test/fake_encryptor.h" 24 #include "sync/test/fake_encryptor.h"
25 #include "sync/util/cryptographer.h" 25 #include "sync/util/cryptographer.h"
26 #include "testing/gmock/include/gmock/gmock.h" 26 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 28
29 namespace syncer { 29 namespace syncer {
30 30
31 namespace { 31 namespace {
32 32
33 using ::testing::_; 33 using ::testing::_;
34 using ::testing::AnyNumber;
34 using ::testing::Mock; 35 using ::testing::Mock;
35 using ::testing::StrictMock; 36 using ::testing::StrictMock;
36 37
37 static const char kKeystoreKey[] = "keystore_key"; 38 static const char kKeystoreKey[] = "keystore_key";
38 39
39 class SyncEncryptionHandlerObserverMock 40 class SyncEncryptionHandlerObserverMock
40 : public SyncEncryptionHandler::Observer { 41 : public SyncEncryptionHandler::Observer {
41 public: 42 public:
42 MOCK_METHOD2(OnPassphraseRequired, 43 MOCK_METHOD2(OnPassphraseRequired,
43 void(PassphraseRequiredReason, 44 void(PassphraseRequiredReason,
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 sync_pb::NigoriSpecifics current_nigori_specifics; 373 sync_pb::NigoriSpecifics current_nigori_specifics;
373 GetCryptographer()->AddKey(old_key); 374 GetCryptographer()->AddKey(old_key);
374 GetCryptographer()->AddKey(current_key); 375 GetCryptographer()->AddKey(current_key);
375 GetCryptographer()->Encrypt( 376 GetCryptographer()->Encrypt(
376 our_encrypted_specifics, 377 our_encrypted_specifics,
377 our_encrypted_specifics.mutable_encrypted()); 378 our_encrypted_specifics.mutable_encrypted());
378 GetCryptographer()->GetKeys( 379 GetCryptographer()->GetKeys(
379 current_nigori_specifics.mutable_encryption_keybag()); 380 current_nigori_specifics.mutable_encryption_keybag());
380 current_nigori_specifics.set_encrypt_everything(true); 381 current_nigori_specifics.set_encrypt_everything(true);
381 382
382 EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)); 383 EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
383 EXPECT_CALL(*observer(), OnEncryptedTypesChanged( 384 EXPECT_CALL(*observer(), OnEncryptedTypesChanged(
384 HasModelTypes(UserTypes()), true)); 385 HasModelTypes(UserTypes()), true));
385 { 386 {
386 // Update the encryption handler. 387 // Update the encryption handler.
387 WriteTransaction trans(FROM_HERE, user_share()); 388 WriteTransaction trans(FROM_HERE, user_share());
388 encryption_handler()->ApplyNigoriUpdate( 389 encryption_handler()->ApplyNigoriUpdate(
389 current_nigori_specifics, 390 current_nigori_specifics,
390 trans.GetWrappedTrans()); 391 trans.GetWrappedTrans());
391 } 392 }
392 Mock::VerifyAndClearExpectations(observer()); 393 Mock::VerifyAndClearExpectations(observer());
393 394
394 // Now set up the old nigori specifics and apply it on top. 395 // Now set up the old nigori specifics and apply it on top.
395 // Has an old set of keys, and no encrypted types. 396 // Has an old set of keys, and no encrypted types.
396 sync_pb::NigoriSpecifics old_nigori; 397 sync_pb::NigoriSpecifics old_nigori;
397 other_cryptographer.GetKeys(old_nigori.mutable_encryption_keybag()); 398 other_cryptographer.GetKeys(old_nigori.mutable_encryption_keybag());
398 399
399 EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)); 400 EXPECT_CALL(*observer(), OnCryptographerStateChanged(_)).Times(AnyNumber());
400 { 401 {
401 // Update the encryption handler. 402 // Update the encryption handler.
402 WriteTransaction trans(FROM_HERE, user_share()); 403 WriteTransaction trans(FROM_HERE, user_share());
403 encryption_handler()->ApplyNigoriUpdate( 404 encryption_handler()->ApplyNigoriUpdate(
404 old_nigori, 405 old_nigori,
405 trans.GetWrappedTrans()); 406 trans.GetWrappedTrans());
406 } 407 }
407 EXPECT_TRUE(GetCryptographer()->is_ready()); 408 EXPECT_TRUE(GetCryptographer()->is_ready());
408 EXPECT_FALSE(GetCryptographer()->has_pending_keys()); 409 EXPECT_FALSE(GetCryptographer()->has_pending_keys());
409 410
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK); 496 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK);
496 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); 497 Cryptographer other_cryptographer(GetCryptographer()->encryptor());
497 KeyParams other_key = {"localhost", "dummy", kOtherKey}; 498 KeyParams other_key = {"localhost", "dummy", kOtherKey};
498 other_cryptographer.AddKey(other_key); 499 other_cryptographer.AddKey(other_key);
499 500
500 sync_pb::NigoriSpecifics nigori; 501 sync_pb::NigoriSpecifics nigori;
501 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); 502 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
502 nigori.set_keybag_is_frozen(false); 503 nigori.set_keybag_is_frozen(false);
503 nigori.set_encrypt_everything(false); 504 nigori.set_encrypt_everything(false);
504 EXPECT_CALL(*observer(), 505 EXPECT_CALL(*observer(),
505 OnCryptographerStateChanged(_)); 506 OnCryptographerStateChanged(_)).Times(AnyNumber());
506 EXPECT_CALL(*observer(), 507 EXPECT_CALL(*observer(),
507 OnPassphraseRequired(_, _)); 508 OnPassphraseRequired(_, _));
508 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans()); 509 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
509 nigori_node.SetNigoriSpecifics(nigori); 510 nigori_node.SetNigoriSpecifics(nigori);
510 } 511 }
511 // Run any tasks posted via AppplyNigoriUpdate. 512 // Run any tasks posted via AppplyNigoriUpdate.
512 PumpLoop(); 513 PumpLoop();
513 EXPECT_FALSE(encryption_handler()->MigratedToKeystore()); 514 EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
514 Mock::VerifyAndClearExpectations(observer()); 515 Mock::VerifyAndClearExpectations(observer());
515 516
516 EXPECT_CALL(*observer(), 517 EXPECT_CALL(*observer(),
517 OnCryptographerStateChanged(_)); 518 OnCryptographerStateChanged(_)).Times(AnyNumber());
518 EXPECT_CALL(*observer(), 519 EXPECT_CALL(*observer(),
519 OnPassphraseAccepted()); 520 OnPassphraseAccepted());
520 EXPECT_CALL(*observer(), 521 EXPECT_CALL(*observer(),
521 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 522 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
522 EXPECT_CALL(*observer(), 523 EXPECT_CALL(*observer(),
523 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 524 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
524 EXPECT_CALL(*observer(), 525 EXPECT_CALL(*observer(),
525 OnEncryptionComplete()); 526 OnEncryptionComplete());
526 EXPECT_FALSE(encryption_handler()->MigratedToKeystore()); 527 EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
527 encryption_handler()->SetDecryptionPassphrase(kOtherKey); 528 encryption_handler()->SetDecryptionPassphrase(kOtherKey);
(...skipping 22 matching lines...) Expand all
550 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK); 551 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK);
551 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); 552 Cryptographer other_cryptographer(GetCryptographer()->encryptor());
552 KeyParams other_key = {"localhost", "dummy", kOtherKey}; 553 KeyParams other_key = {"localhost", "dummy", kOtherKey};
553 other_cryptographer.AddKey(other_key); 554 other_cryptographer.AddKey(other_key);
554 555
555 sync_pb::NigoriSpecifics nigori; 556 sync_pb::NigoriSpecifics nigori;
556 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); 557 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
557 nigori.set_keybag_is_frozen(true); 558 nigori.set_keybag_is_frozen(true);
558 nigori.set_encrypt_everything(false); 559 nigori.set_encrypt_everything(false);
559 EXPECT_CALL(*observer(), 560 EXPECT_CALL(*observer(),
560 OnCryptographerStateChanged(_)); 561 OnCryptographerStateChanged(_)).Times(AnyNumber());
561 EXPECT_CALL(*observer(), 562 EXPECT_CALL(*observer(),
562 OnPassphraseRequired(_, _)); 563 OnPassphraseRequired(_, _));
563 EXPECT_CALL(*observer(), 564 EXPECT_CALL(*observer(),
564 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 565 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
565 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans()); 566 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
566 nigori_node.SetNigoriSpecifics(nigori); 567 nigori_node.SetNigoriSpecifics(nigori);
567 } 568 }
568 // Run any tasks posted via AppplyNigoriUpdate. 569 // Run any tasks posted via AppplyNigoriUpdate.
569 PumpLoop(); 570 PumpLoop();
570 EXPECT_FALSE(encryption_handler()->MigratedToKeystore()); 571 EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
571 Mock::VerifyAndClearExpectations(observer()); 572 Mock::VerifyAndClearExpectations(observer());
572 573
573 EXPECT_CALL(*observer(), 574 EXPECT_CALL(*observer(),
574 OnCryptographerStateChanged(_)); 575 OnCryptographerStateChanged(_)).Times(AnyNumber());
575 EXPECT_CALL(*observer(), 576 EXPECT_CALL(*observer(),
576 OnPassphraseAccepted()); 577 OnPassphraseAccepted());
577 EXPECT_CALL(*observer(), 578 EXPECT_CALL(*observer(),
578 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 579 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
579 EXPECT_CALL(*observer(), 580 EXPECT_CALL(*observer(),
580 OnEncryptedTypesChanged(_, true)); 581 OnEncryptedTypesChanged(_, true));
581 EXPECT_CALL(*observer(), 582 EXPECT_CALL(*observer(),
582 OnEncryptionComplete()).Times(2); 583 OnEncryptionComplete()).Times(2);
583 EXPECT_FALSE(encryption_handler()->MigratedToKeystore()); 584 EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
584 encryption_handler()->SetDecryptionPassphrase(kOtherKey); 585 encryption_handler()->SetDecryptionPassphrase(kOtherKey);
585 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 586 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
586 EXPECT_EQ(CUSTOM_PASSPHRASE, encryption_handler()->GetPassphraseType()); 587 EXPECT_EQ(CUSTOM_PASSPHRASE, encryption_handler()->GetPassphraseType());
587 VerifyMigratedNigori(CUSTOM_PASSPHRASE, kOtherKey); 588 VerifyMigratedNigori(CUSTOM_PASSPHRASE, kOtherKey);
588 } 589 }
589 590
590 // Test that we trigger a migration when we set the keystore key, had an 591 // Test that we trigger a migration when we set the keystore key, had an
591 // implicit passphrase, and did not have encrypt everything. We should switch 592 // implicit passphrase, and did not have encrypt everything. We should switch
592 // to KEYSTORE_PASSPHRASE. 593 // to KEYSTORE_PASSPHRASE.
593 TEST_F(SyncEncryptionHandlerImplTest, MigrateOnKeystoreKeyAvailableImplicit) { 594 TEST_F(SyncEncryptionHandlerImplTest, MigrateOnKeystoreKeyAvailableImplicit) {
594 const char kCurKey[] = "cur"; 595 const char kCurKey[] = "cur";
595 KeyParams current_key = {"localhost", "dummy", kCurKey}; 596 KeyParams current_key = {"localhost", "dummy", kCurKey};
596 GetCryptographer()->AddKey(current_key); 597 GetCryptographer()->AddKey(current_key);
597 EXPECT_CALL(*observer(), 598 EXPECT_CALL(*observer(),
598 OnCryptographerStateChanged(_)); 599 OnCryptographerStateChanged(_)).Times(AnyNumber());
599 EXPECT_CALL(*observer(), 600 EXPECT_CALL(*observer(),
600 OnEncryptedTypesChanged(_, false)); 601 OnEncryptedTypesChanged(_, false));
601 EXPECT_CALL(*observer(), 602 EXPECT_CALL(*observer(),
602 OnEncryptionComplete()); 603 OnEncryptionComplete());
603 encryption_handler()->Init(); 604 encryption_handler()->Init();
604 Mock::VerifyAndClearExpectations(observer()); 605 Mock::VerifyAndClearExpectations(observer());
605 606
606 { 607 {
607 ReadTransaction trans(FROM_HERE, user_share()); 608 ReadTransaction trans(FROM_HERE, user_share());
608 // Once we provide a keystore key, we should perform the migration. 609 // Once we provide a keystore key, we should perform the migration.
609 EXPECT_CALL(*observer(), 610 EXPECT_CALL(*observer(),
611 OnCryptographerStateChanged(_)).Times(AnyNumber());
612 EXPECT_CALL(*observer(),
610 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 613 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
611 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans()); 614 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans());
612 } 615 }
613 EXPECT_CALL(*observer(), 616 EXPECT_CALL(*observer(),
614 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 617 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
615 // The actual migration gets posted, so run all pending tasks. 618 // The actual migration gets posted, so run all pending tasks.
616 PumpLoop(); 619 PumpLoop();
617 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 620 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
618 EXPECT_EQ(KEYSTORE_PASSPHRASE, 621 EXPECT_EQ(KEYSTORE_PASSPHRASE,
619 encryption_handler()->GetPassphraseType()); 622 encryption_handler()->GetPassphraseType());
620 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 623 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
621 VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey); 624 VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey);
622 } 625 }
623 626
624 // Test that we trigger a migration when we set the keystore key, had an 627 // Test that we trigger a migration when we set the keystore key, had an
625 // implicit passphrase, and encrypt everything enabled. We should switch to 628 // implicit passphrase, and encrypt everything enabled. We should switch to
626 // FROZEN_IMPLICIT_PASSPHRASE. 629 // FROZEN_IMPLICIT_PASSPHRASE.
627 TEST_F(SyncEncryptionHandlerImplTest, 630 TEST_F(SyncEncryptionHandlerImplTest,
628 MigrateOnKeystoreKeyAvailableFrozenImplicit) { 631 MigrateOnKeystoreKeyAvailableFrozenImplicit) {
629 const char kCurKey[] = "cur"; 632 const char kCurKey[] = "cur";
630 KeyParams current_key = {"localhost", "dummy", kCurKey}; 633 KeyParams current_key = {"localhost", "dummy", kCurKey};
631 GetCryptographer()->AddKey(current_key); 634 GetCryptographer()->AddKey(current_key);
632 EXPECT_CALL(*observer(), 635 EXPECT_CALL(*observer(),
633 OnCryptographerStateChanged(_)); 636 OnCryptographerStateChanged(_)).Times(AnyNumber());
634 EXPECT_CALL(*observer(), 637 EXPECT_CALL(*observer(),
635 OnEncryptedTypesChanged(_, false)); 638 OnEncryptedTypesChanged(_, false));
636 EXPECT_CALL(*observer(), 639 EXPECT_CALL(*observer(),
637 OnEncryptionComplete()); 640 OnEncryptionComplete());
638 encryption_handler()->Init(); 641 encryption_handler()->Init();
639 Mock::VerifyAndClearExpectations(observer()); 642 Mock::VerifyAndClearExpectations(observer());
640 643
641 EXPECT_CALL(*observer(), 644 EXPECT_CALL(*observer(),
642 OnEncryptedTypesChanged(_, true)); 645 OnEncryptedTypesChanged(_, true));
643 EXPECT_CALL(*observer(), 646 EXPECT_CALL(*observer(),
644 OnEncryptionComplete()); 647 OnEncryptionComplete());
645 encryption_handler()->EnableEncryptEverything(); 648 encryption_handler()->EnableEncryptEverything();
646 649
647 { 650 {
648 ReadTransaction trans(FROM_HERE, user_share()); 651 ReadTransaction trans(FROM_HERE, user_share());
649 // Once we provide a keystore key, we should perform the migration. 652 // Once we provide a keystore key, we should perform the migration.
650 EXPECT_CALL(*observer(), 653 EXPECT_CALL(*observer(),
654 OnCryptographerStateChanged(_)).Times(AnyNumber());
655 EXPECT_CALL(*observer(),
651 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 656 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
652 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans()); 657 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans());
653 } 658 }
654 EXPECT_CALL(*observer(), 659 EXPECT_CALL(*observer(),
655 OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE)); 660 OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE));
656 // The actual migration gets posted, so run all pending tasks. 661 // The actual migration gets posted, so run all pending tasks.
657 PumpLoop(); 662 PumpLoop();
658 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 663 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
659 EXPECT_EQ(FROZEN_IMPLICIT_PASSPHRASE, 664 EXPECT_EQ(FROZEN_IMPLICIT_PASSPHRASE,
660 encryption_handler()->GetPassphraseType()); 665 encryption_handler()->GetPassphraseType());
661 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled()); 666 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled());
662 VerifyMigratedNigori(FROZEN_IMPLICIT_PASSPHRASE, kCurKey); 667 VerifyMigratedNigori(FROZEN_IMPLICIT_PASSPHRASE, kCurKey);
663 } 668 }
664 669
665 // Test that we trigger a migration when we set the keystore key, had a 670 // Test that we trigger a migration when we set the keystore key, had a
666 // custom passphrase, and encrypt everything enabled. The passphrase state 671 // custom passphrase, and encrypt everything enabled. The passphrase state
667 // should remain as CUSTOM_PASSPHRASE, and encrypt everything stay the same. 672 // should remain as CUSTOM_PASSPHRASE, and encrypt everything stay the same.
668 TEST_F(SyncEncryptionHandlerImplTest, 673 TEST_F(SyncEncryptionHandlerImplTest,
669 MigrateOnKeystoreKeyAvailableCustomWithEncryption) { 674 MigrateOnKeystoreKeyAvailableCustomWithEncryption) {
670 const char kCurKey[] = "cur"; 675 const char kCurKey[] = "cur";
671 EXPECT_CALL(*observer(), 676 EXPECT_CALL(*observer(),
672 OnCryptographerStateChanged(_)).Times(2); 677 OnCryptographerStateChanged(_)).Times(AnyNumber());
673 EXPECT_CALL(*observer(), 678 EXPECT_CALL(*observer(),
674 OnPassphraseRequired(_, _)); 679 OnPassphraseRequired(_, _));
675 EXPECT_CALL(*observer(), 680 EXPECT_CALL(*observer(),
676 OnPassphraseAccepted()); 681 OnPassphraseAccepted());
677 EXPECT_CALL(*observer(), 682 EXPECT_CALL(*observer(),
678 OnEncryptedTypesChanged(_, false)); 683 OnEncryptedTypesChanged(_, false));
679 EXPECT_CALL(*observer(), 684 EXPECT_CALL(*observer(),
680 OnEncryptionComplete()); 685 OnEncryptionComplete());
681 EXPECT_CALL(*observer(), 686 EXPECT_CALL(*observer(),
682 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 687 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
683 EXPECT_CALL(*observer(), 688 EXPECT_CALL(*observer(),
684 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 689 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
685 encryption_handler()->Init(); 690 encryption_handler()->Init();
686 encryption_handler()->SetEncryptionPassphrase(kCurKey, true); 691 encryption_handler()->SetEncryptionPassphrase(kCurKey, true);
687 Mock::VerifyAndClearExpectations(observer()); 692 Mock::VerifyAndClearExpectations(observer());
688 693
689 EXPECT_CALL(*observer(), 694 EXPECT_CALL(*observer(),
690 OnEncryptedTypesChanged(_, true)); 695 OnEncryptedTypesChanged(_, true));
691 EXPECT_CALL(*observer(), 696 EXPECT_CALL(*observer(),
692 OnEncryptionComplete()); 697 OnEncryptionComplete());
693 encryption_handler()->EnableEncryptEverything(); 698 encryption_handler()->EnableEncryptEverything();
694 Mock::VerifyAndClearExpectations(observer()); 699 Mock::VerifyAndClearExpectations(observer());
695 700
696 { 701 {
697 ReadTransaction trans(FROM_HERE, user_share()); 702 ReadTransaction trans(FROM_HERE, user_share());
698 // Once we provide a keystore key, we should perform the migration. 703 // Once we provide a keystore key, we should perform the migration.
699 EXPECT_CALL(*observer(), 704 EXPECT_CALL(*observer(),
705 OnCryptographerStateChanged(_)).Times(AnyNumber());
706 EXPECT_CALL(*observer(),
700 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 707 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
701 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans()); 708 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans());
702 } 709 }
703 // The actual migration gets posted, so run all pending tasks. 710 // The actual migration gets posted, so run all pending tasks.
704 PumpLoop(); 711 PumpLoop();
705 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 712 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
706 EXPECT_EQ(CUSTOM_PASSPHRASE, 713 EXPECT_EQ(CUSTOM_PASSPHRASE,
707 encryption_handler()->GetPassphraseType()); 714 encryption_handler()->GetPassphraseType());
708 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled()); 715 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled());
709 VerifyMigratedNigori(CUSTOM_PASSPHRASE, kCurKey); 716 VerifyMigratedNigori(CUSTOM_PASSPHRASE, kCurKey);
710 } 717 }
711 718
712 // Test that we trigger a migration when we set the keystore key, had a 719 // Test that we trigger a migration when we set the keystore key, had a
713 // custom passphrase, and did not have encrypt everything. The passphrase state 720 // custom passphrase, and did not have encrypt everything. The passphrase state
714 // should remain as CUSTOM_PASSPHRASE, and encrypt everything should be enabled. 721 // should remain as CUSTOM_PASSPHRASE, and encrypt everything should be enabled.
715 TEST_F(SyncEncryptionHandlerImplTest, 722 TEST_F(SyncEncryptionHandlerImplTest,
716 MigrateOnKeystoreKeyAvailableCustomNoEncryption) { 723 MigrateOnKeystoreKeyAvailableCustomNoEncryption) {
717 const char kCurKey[] = "cur"; 724 const char kCurKey[] = "cur";
718 EXPECT_CALL(*observer(), 725 EXPECT_CALL(*observer(),
akalin 2012/09/18 00:19:21 Looks like it's time for another mock -> fake conv
719 OnCryptographerStateChanged(_)).Times(2); 726 OnCryptographerStateChanged(_)).Times(AnyNumber());
720 EXPECT_CALL(*observer(), 727 EXPECT_CALL(*observer(),
721 OnPassphraseRequired(_, _)); 728 OnPassphraseRequired(_, _));
722 EXPECT_CALL(*observer(), 729 EXPECT_CALL(*observer(),
723 OnPassphraseAccepted()); 730 OnPassphraseAccepted());
724 EXPECT_CALL(*observer(), 731 EXPECT_CALL(*observer(),
725 OnEncryptedTypesChanged(_, false)); 732 OnEncryptedTypesChanged(_, false));
726 EXPECT_CALL(*observer(), 733 EXPECT_CALL(*observer(),
727 OnEncryptionComplete()); 734 OnEncryptionComplete());
728 EXPECT_CALL(*observer(), 735 EXPECT_CALL(*observer(),
729 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 736 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
730 EXPECT_CALL(*observer(), 737 EXPECT_CALL(*observer(),
731 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 738 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
732 encryption_handler()->Init(); 739 encryption_handler()->Init();
733 encryption_handler()->SetEncryptionPassphrase(kCurKey, true); 740 encryption_handler()->SetEncryptionPassphrase(kCurKey, true);
734 Mock::VerifyAndClearExpectations(observer()); 741 Mock::VerifyAndClearExpectations(observer());
735 742
736 { 743 {
737 ReadTransaction trans(FROM_HERE, user_share()); 744 ReadTransaction trans(FROM_HERE, user_share());
738 // Once we provide a keystore key, we should perform the migration. 745 // Once we provide a keystore key, we should perform the migration.
739 EXPECT_CALL(*observer(), 746 EXPECT_CALL(*observer(),
747 OnCryptographerStateChanged(_)).Times(AnyNumber());
748 EXPECT_CALL(*observer(),
740 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 749 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
741 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans()); 750 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans());
742 } 751 }
743 EXPECT_CALL(*observer(), 752 EXPECT_CALL(*observer(),
744 OnEncryptedTypesChanged(_, true)); 753 OnEncryptedTypesChanged(_, true));
745 EXPECT_CALL(*observer(), 754 EXPECT_CALL(*observer(),
746 OnEncryptionComplete()); 755 OnEncryptionComplete());
747 // The actual migration gets posted, so run all pending tasks. 756 // The actual migration gets posted, so run all pending tasks.
748 PumpLoop(); 757 PumpLoop();
749 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 758 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 nigori.set_keystore_migration_time(1); 795 nigori.set_keystore_migration_time(1);
787 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE); 796 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE);
788 797
789 EXPECT_CALL(*observer(), 798 EXPECT_CALL(*observer(),
790 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 799 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
791 EXPECT_CALL(*observer(), 800 EXPECT_CALL(*observer(),
792 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 801 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
793 EXPECT_CALL(*observer(), 802 EXPECT_CALL(*observer(),
794 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 803 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
795 EXPECT_CALL(*observer(), 804 EXPECT_CALL(*observer(),
796 OnCryptographerStateChanged(_)).Times(2); 805 OnCryptographerStateChanged(_)).Times(AnyNumber());
797 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans()); 806 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans());
798 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans()); 807 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
799 nigori_node.SetNigoriSpecifics(nigori); 808 nigori_node.SetNigoriSpecifics(nigori);
800 } 809 }
801 // Run any tasks posted via AppplyNigoriUpdate. 810 // Run any tasks posted via AppplyNigoriUpdate.
802 PumpLoop(); 811 PumpLoop();
803 Mock::VerifyAndClearExpectations(observer()); 812 Mock::VerifyAndClearExpectations(observer());
804 813
805 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 814 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
806 EXPECT_TRUE(GetCryptographer()->is_ready()); 815 EXPECT_TRUE(GetCryptographer()->is_ready());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans()); 849 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans());
841 } 850 }
842 EXPECT_FALSE(encryption_handler()->MigratedToKeystore()); 851 EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
843 852
844 { 853 {
845 EXPECT_CALL(*observer(), 854 EXPECT_CALL(*observer(),
846 OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE)); 855 OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE));
847 EXPECT_CALL(*observer(), 856 EXPECT_CALL(*observer(),
848 OnPassphraseRequired(_, _)); 857 OnPassphraseRequired(_, _));
849 EXPECT_CALL(*observer(), 858 EXPECT_CALL(*observer(),
850 OnCryptographerStateChanged(_)); 859 OnCryptographerStateChanged(_)).Times(AnyNumber());
851 EXPECT_CALL(*observer(), 860 EXPECT_CALL(*observer(),
852 OnEncryptedTypesChanged(_, true)); 861 OnEncryptedTypesChanged(_, true));
853 WriteTransaction trans(FROM_HERE, user_share()); 862 WriteTransaction trans(FROM_HERE, user_share());
854 WriteNode nigori_node(&trans); 863 WriteNode nigori_node(&trans);
855 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK); 864 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK);
856 sync_pb::NigoriSpecifics nigori; 865 sync_pb::NigoriSpecifics nigori;
857 nigori.set_keybag_is_frozen(true); 866 nigori.set_keybag_is_frozen(true);
858 nigori.set_passphrase_type( 867 nigori.set_passphrase_type(
859 sync_pb::NigoriSpecifics::FROZEN_IMPLICIT_PASSPHRASE); 868 sync_pb::NigoriSpecifics::FROZEN_IMPLICIT_PASSPHRASE);
860 nigori.set_keystore_migration_time(1); 869 nigori.set_keystore_migration_time(1);
861 nigori.set_encrypt_everything(true); 870 nigori.set_encrypt_everything(true);
862 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); 871 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
863 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans()); 872 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
864 nigori_node.SetNigoriSpecifics(nigori); 873 nigori_node.SetNigoriSpecifics(nigori);
865 } 874 }
866 // Run any tasks posted via AppplyNigoriUpdate. 875 // Run any tasks posted via AppplyNigoriUpdate.
867 PumpLoop(); 876 PumpLoop();
868 Mock::VerifyAndClearExpectations(observer()); 877 Mock::VerifyAndClearExpectations(observer());
869 878
870 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 879 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
871 EXPECT_EQ(FROZEN_IMPLICIT_PASSPHRASE, 880 EXPECT_EQ(FROZEN_IMPLICIT_PASSPHRASE,
872 encryption_handler()->GetPassphraseType()); 881 encryption_handler()->GetPassphraseType());
873 EXPECT_TRUE(GetCryptographer()->has_pending_keys()); 882 EXPECT_TRUE(GetCryptographer()->has_pending_keys());
874 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled()); 883 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled());
875 884
876 EXPECT_CALL(*observer(), 885 EXPECT_CALL(*observer(),
877 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 886 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
878 EXPECT_CALL(*observer(), 887 EXPECT_CALL(*observer(),
879 OnCryptographerStateChanged(_)); 888 OnCryptographerStateChanged(_)).Times(AnyNumber());
880 EXPECT_CALL(*observer(), 889 EXPECT_CALL(*observer(),
881 OnEncryptionComplete()); 890 OnEncryptionComplete());
882 EXPECT_CALL(*observer(), 891 EXPECT_CALL(*observer(),
883 OnPassphraseAccepted()); 892 OnPassphraseAccepted());
884 encryption_handler()->SetDecryptionPassphrase(kCurKey); 893 encryption_handler()->SetDecryptionPassphrase(kCurKey);
885 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 894 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
886 EXPECT_TRUE(GetCryptographer()->is_ready()); 895 EXPECT_TRUE(GetCryptographer()->is_ready());
887 VerifyMigratedNigoriWithTimestamp(1, FROZEN_IMPLICIT_PASSPHRASE, kCurKey); 896 VerifyMigratedNigoriWithTimestamp(1, FROZEN_IMPLICIT_PASSPHRASE, kCurKey);
888 897
889 // Check that the cryptographer still encrypts with the current key. 898 // Check that the cryptographer still encrypts with the current key.
(...skipping 30 matching lines...) Expand all
920 trans.GetWrappedTrans()); 929 trans.GetWrappedTrans());
921 } 930 }
922 EXPECT_FALSE(encryption_handler()->MigratedToKeystore()); 931 EXPECT_FALSE(encryption_handler()->MigratedToKeystore());
923 932
924 { 933 {
925 EXPECT_CALL(*observer(), 934 EXPECT_CALL(*observer(),
926 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 935 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
927 EXPECT_CALL(*observer(), 936 EXPECT_CALL(*observer(),
928 OnPassphraseRequired(_, _)); 937 OnPassphraseRequired(_, _));
929 EXPECT_CALL(*observer(), 938 EXPECT_CALL(*observer(),
930 OnCryptographerStateChanged(_)); 939 OnCryptographerStateChanged(_)).Times(AnyNumber());
931 EXPECT_CALL(*observer(), 940 EXPECT_CALL(*observer(),
932 OnEncryptedTypesChanged(_, true)); 941 OnEncryptedTypesChanged(_, true));
933 WriteTransaction trans(FROM_HERE, user_share()); 942 WriteTransaction trans(FROM_HERE, user_share());
934 WriteNode nigori_node(&trans); 943 WriteNode nigori_node(&trans);
935 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK); 944 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK);
936 sync_pb::NigoriSpecifics nigori; 945 sync_pb::NigoriSpecifics nigori;
937 nigori.set_keybag_is_frozen(true); 946 nigori.set_keybag_is_frozen(true);
938 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE); 947 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE);
939 nigori.set_keystore_migration_time(1); 948 nigori.set_keystore_migration_time(1);
940 nigori.set_encrypt_everything(true); 949 nigori.set_encrypt_everything(true);
941 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); 950 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
942 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans()); 951 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
943 nigori_node.SetNigoriSpecifics(nigori); 952 nigori_node.SetNigoriSpecifics(nigori);
944 } 953 }
945 // Run any tasks posted via AppplyNigoriUpdate. 954 // Run any tasks posted via AppplyNigoriUpdate.
946 PumpLoop(); 955 PumpLoop();
947 Mock::VerifyAndClearExpectations(observer()); 956 Mock::VerifyAndClearExpectations(observer());
948 957
949 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 958 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
950 EXPECT_EQ(CUSTOM_PASSPHRASE, encryption_handler()->GetPassphraseType()); 959 EXPECT_EQ(CUSTOM_PASSPHRASE, encryption_handler()->GetPassphraseType());
951 EXPECT_TRUE(GetCryptographer()->has_pending_keys()); 960 EXPECT_TRUE(GetCryptographer()->has_pending_keys());
952 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled()); 961 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled());
953 962
954 EXPECT_CALL(*observer(), 963 EXPECT_CALL(*observer(),
955 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 964 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
956 EXPECT_CALL(*observer(), 965 EXPECT_CALL(*observer(),
957 OnCryptographerStateChanged(_)); 966 OnCryptographerStateChanged(_)).Times(AnyNumber());
958 EXPECT_CALL(*observer(), 967 EXPECT_CALL(*observer(),
959 OnEncryptionComplete()); 968 OnEncryptionComplete());
960 EXPECT_CALL(*observer(), 969 EXPECT_CALL(*observer(),
961 OnPassphraseAccepted()); 970 OnPassphraseAccepted());
962 encryption_handler()->SetDecryptionPassphrase(kCurKey); 971 encryption_handler()->SetDecryptionPassphrase(kCurKey);
963 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 972 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
964 EXPECT_TRUE(GetCryptographer()->is_ready()); 973 EXPECT_TRUE(GetCryptographer()->is_ready());
965 VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kCurKey); 974 VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kCurKey);
966 975
967 // Check that the cryptographer still encrypts with the current key. 976 // Check that the cryptographer still encrypts with the current key.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 nigori.set_keybag_is_frozen(true); 1009 nigori.set_keybag_is_frozen(true);
1001 nigori.set_keystore_migration_time(1); 1010 nigori.set_keystore_migration_time(1);
1002 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE); 1011 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE);
1003 nigori.set_encrypt_everything(true); 1012 nigori.set_encrypt_everything(true);
1004 nigori_node.SetNigoriSpecifics(nigori); 1013 nigori_node.SetNigoriSpecifics(nigori);
1005 } 1014 }
1006 1015
1007 EXPECT_CALL(*observer(), 1016 EXPECT_CALL(*observer(),
1008 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 1017 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
1009 EXPECT_CALL(*observer(), 1018 EXPECT_CALL(*observer(),
1010 OnCryptographerStateChanged(_)); 1019 OnCryptographerStateChanged(_)).Times(AnyNumber());
1011 EXPECT_CALL(*observer(), 1020 EXPECT_CALL(*observer(),
1012 OnEncryptedTypesChanged(_, true)).Times(2); 1021 OnEncryptedTypesChanged(_, true)).Times(2);
1013 EXPECT_CALL(*observer(), 1022 EXPECT_CALL(*observer(),
1014 OnEncryptionComplete()); 1023 OnEncryptionComplete());
1015 encryption_handler()->Init(); 1024 encryption_handler()->Init();
1016 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1025 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1017 EXPECT_TRUE(GetCryptographer()->is_ready()); 1026 EXPECT_TRUE(GetCryptographer()->is_ready());
1018 EXPECT_EQ(encryption_handler()->GetPassphraseType(), CUSTOM_PASSPHRASE); 1027 EXPECT_EQ(encryption_handler()->GetPassphraseType(), CUSTOM_PASSPHRASE);
1019 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled()); 1028 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled());
1020 VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kCurKey); 1029 VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kCurKey);
1021 1030
1022 { 1031 {
1023 EXPECT_CALL(*observer(), 1032 EXPECT_CALL(*observer(),
1024 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 1033 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
1025 ReadTransaction trans(FROM_HERE, user_share()); 1034 ReadTransaction trans(FROM_HERE, user_share());
1026 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans()); 1035 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans());
1027 } 1036 }
1028 Mock::VerifyAndClearExpectations(observer()); 1037 Mock::VerifyAndClearExpectations(observer());
1029 1038
1030 // Now build an old unmigrated nigori node with old encrypted types. We should 1039 // Now build an old unmigrated nigori node with old encrypted types. We should
1031 // properly overwrite it with the migrated + encrypt everything state. 1040 // properly overwrite it with the migrated + encrypt everything state.
1032 EXPECT_CALL(*observer(), 1041 EXPECT_CALL(*observer(),
1033 OnCryptographerStateChanged(_)); 1042 OnCryptographerStateChanged(_)).Times(AnyNumber());
1034 { 1043 {
1035 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); 1044 Cryptographer other_cryptographer(GetCryptographer()->encryptor());
1036 other_cryptographer.AddKey(old_key); 1045 other_cryptographer.AddKey(old_key);
1037 WriteTransaction trans(FROM_HERE, user_share()); 1046 WriteTransaction trans(FROM_HERE, user_share());
1038 WriteNode nigori_node(&trans); 1047 WriteNode nigori_node(&trans);
1039 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK); 1048 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK);
1040 sync_pb::NigoriSpecifics nigori; 1049 sync_pb::NigoriSpecifics nigori;
1041 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); 1050 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
1042 nigori.set_keybag_is_frozen(false); 1051 nigori.set_keybag_is_frozen(false);
1043 nigori.set_encrypt_everything(false); 1052 nigori.set_encrypt_everything(false);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 nigori.set_keybag_is_frozen(true); 1086 nigori.set_keybag_is_frozen(true);
1078 nigori.set_keystore_migration_time(1); 1087 nigori.set_keystore_migration_time(1);
1079 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE); 1088 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::CUSTOM_PASSPHRASE);
1080 nigori.set_encrypt_everything(true); 1089 nigori.set_encrypt_everything(true);
1081 nigori_node.SetNigoriSpecifics(nigori); 1090 nigori_node.SetNigoriSpecifics(nigori);
1082 } 1091 }
1083 1092
1084 EXPECT_CALL(*observer(), 1093 EXPECT_CALL(*observer(),
1085 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 1094 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
1086 EXPECT_CALL(*observer(), 1095 EXPECT_CALL(*observer(),
1087 OnCryptographerStateChanged(_)); 1096 OnCryptographerStateChanged(_)).Times(AnyNumber());
1088 EXPECT_CALL(*observer(), 1097 EXPECT_CALL(*observer(),
1089 OnEncryptedTypesChanged(_, true)).Times(2); 1098 OnEncryptedTypesChanged(_, true)).Times(2);
1090 EXPECT_CALL(*observer(), 1099 EXPECT_CALL(*observer(),
1091 OnEncryptionComplete()); 1100 OnEncryptionComplete());
1092 encryption_handler()->Init(); 1101 encryption_handler()->Init();
1093 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1102 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1094 EXPECT_TRUE(GetCryptographer()->is_ready()); 1103 EXPECT_TRUE(GetCryptographer()->is_ready());
1095 EXPECT_EQ(encryption_handler()->GetPassphraseType(), CUSTOM_PASSPHRASE); 1104 EXPECT_EQ(encryption_handler()->GetPassphraseType(), CUSTOM_PASSPHRASE);
1096 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled()); 1105 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled());
1097 VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kCurKey); 1106 VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kCurKey);
1098 1107
1099 { 1108 {
1100 EXPECT_CALL(*observer(), 1109 EXPECT_CALL(*observer(),
1101 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 1110 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
1102 ReadTransaction trans(FROM_HERE, user_share()); 1111 ReadTransaction trans(FROM_HERE, user_share());
1103 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans()); 1112 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans());
1104 } 1113 }
1105 Mock::VerifyAndClearExpectations(observer()); 1114 Mock::VerifyAndClearExpectations(observer());
1106 1115
1107 // Now build an old keystore nigori node with old encrypted types. We should 1116 // Now build an old keystore nigori node with old encrypted types. We should
1108 // properly overwrite it with the migrated + encrypt everything state. 1117 // properly overwrite it with the migrated + encrypt everything state.
1109 EXPECT_CALL(*observer(), 1118 EXPECT_CALL(*observer(),
1110 OnCryptographerStateChanged(_)); 1119 OnCryptographerStateChanged(_)).Times(AnyNumber());
1111 { 1120 {
1112 WriteTransaction trans(FROM_HERE, user_share()); 1121 WriteTransaction trans(FROM_HERE, user_share());
1113 WriteNode nigori_node(&trans); 1122 WriteNode nigori_node(&trans);
1114 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK); 1123 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK);
1115 sync_pb::NigoriSpecifics nigori; 1124 sync_pb::NigoriSpecifics nigori;
1116 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); 1125 Cryptographer other_cryptographer(GetCryptographer()->encryptor());
1117 other_cryptographer.AddKey(old_key); 1126 other_cryptographer.AddKey(old_key);
1118 encryption_handler()->GetKeystoreDecryptor( 1127 encryption_handler()->GetKeystoreDecryptor(
1119 other_cryptographer, 1128 other_cryptographer,
1120 kKeystoreKey, 1129 kKeystoreKey,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 nigori.mutable_keystore_decryptor_token()->CopyFrom( 1174 nigori.mutable_keystore_decryptor_token()->CopyFrom(
1166 keystore_decryptor_token); 1175 keystore_decryptor_token);
1167 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); 1176 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
1168 nigori.set_keybag_is_frozen(true); 1177 nigori.set_keybag_is_frozen(true);
1169 nigori.set_keystore_migration_time(1); 1178 nigori.set_keystore_migration_time(1);
1170 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE); 1179 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE);
1171 1180
1172 EXPECT_CALL(*observer(), 1181 EXPECT_CALL(*observer(),
1173 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 1182 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
1174 EXPECT_CALL(*observer(), 1183 EXPECT_CALL(*observer(),
1175 OnCryptographerStateChanged(_)); 1184 OnCryptographerStateChanged(_)).Times(AnyNumber());
1176 EXPECT_CALL(*observer(), 1185 EXPECT_CALL(*observer(),
1177 OnPassphraseRequired(_, _)); 1186 OnPassphraseRequired(_, _));
1178 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans()); 1187 encryption_handler()->ApplyNigoriUpdate(nigori, trans.GetWrappedTrans());
1179 nigori_node.SetNigoriSpecifics(nigori); 1188 nigori_node.SetNigoriSpecifics(nigori);
1180 } 1189 }
1181 // Run any tasks posted via AppplyNigoriUpdate. 1190 // Run any tasks posted via AppplyNigoriUpdate.
1182 PumpLoop(); 1191 PumpLoop();
1183 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1192 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1184 EXPECT_TRUE(GetCryptographer()->has_pending_keys()); 1193 EXPECT_TRUE(GetCryptographer()->has_pending_keys());
1185 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); 1194 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
1186 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1195 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1187 Mock::VerifyAndClearExpectations(observer()); 1196 Mock::VerifyAndClearExpectations(observer());
1188 1197
1189 EXPECT_CALL(*observer(), 1198 EXPECT_CALL(*observer(),
1190 OnCryptographerStateChanged(_)); 1199 OnCryptographerStateChanged(_)).Times(AnyNumber());
1191 EXPECT_CALL(*observer(), 1200 EXPECT_CALL(*observer(),
1192 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1201 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1193 { 1202 {
1194 EXPECT_CALL(*observer(), 1203 EXPECT_CALL(*observer(),
1195 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 1204 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
1196 ReadTransaction trans(FROM_HERE, user_share()); 1205 ReadTransaction trans(FROM_HERE, user_share());
1197 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans()); 1206 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans());
1198 } 1207 }
1199 PumpLoop(); 1208 PumpLoop();
1200 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1209 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE); 1257 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE);
1249 nigori_node.SetNigoriSpecifics(nigori); 1258 nigori_node.SetNigoriSpecifics(nigori);
1250 EXPECT_CALL(*observer(), 1259 EXPECT_CALL(*observer(),
1251 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 1260 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
1252 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans()); 1261 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans());
1253 } 1262 }
1254 1263
1255 EXPECT_CALL(*observer(), 1264 EXPECT_CALL(*observer(),
1256 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 1265 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
1257 EXPECT_CALL(*observer(), 1266 EXPECT_CALL(*observer(),
1258 OnCryptographerStateChanged(_)).Times(2); 1267 OnCryptographerStateChanged(_)).Times(AnyNumber());
1259 EXPECT_CALL(*observer(), 1268 EXPECT_CALL(*observer(),
1260 OnEncryptedTypesChanged(_, false)); 1269 OnEncryptedTypesChanged(_, false));
1261 EXPECT_CALL(*observer(), 1270 EXPECT_CALL(*observer(),
1262 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1271 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1263 EXPECT_CALL(*observer(), 1272 EXPECT_CALL(*observer(),
1264 OnEncryptionComplete()); 1273 OnEncryptionComplete());
1265 encryption_handler()->Init(); 1274 encryption_handler()->Init();
1266 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1275 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1267 EXPECT_TRUE(GetCryptographer()->is_ready()); 1276 EXPECT_TRUE(GetCryptographer()->is_ready());
1268 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); 1277 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
1269 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1278 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1270 Mock::VerifyAndClearExpectations(observer()); 1279 Mock::VerifyAndClearExpectations(observer());
1271 1280
1272 const char kNewKey[] = "new_key"; 1281 const char kNewKey[] = "new_key";
1273 EXPECT_CALL(*observer(), 1282 EXPECT_CALL(*observer(),
1274 OnCryptographerStateChanged(_)); 1283 OnCryptographerStateChanged(_)).Times(AnyNumber());
1275 EXPECT_CALL(*observer(), 1284 EXPECT_CALL(*observer(),
1276 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 1285 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
1277 EXPECT_CALL(*observer(), 1286 EXPECT_CALL(*observer(),
1278 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1287 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1279 EXPECT_CALL(*observer(), 1288 EXPECT_CALL(*observer(),
1280 OnPassphraseAccepted()); 1289 OnPassphraseAccepted());
1281 EXPECT_CALL(*observer(), 1290 EXPECT_CALL(*observer(),
1282 OnEncryptedTypesChanged(_, true)); 1291 OnEncryptedTypesChanged(_, true));
1283 EXPECT_CALL(*observer(), 1292 EXPECT_CALL(*observer(),
1284 OnEncryptionComplete()).Times(2); 1293 OnEncryptionComplete()).Times(2);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 nigori.set_keystore_migration_time(1); 1354 nigori.set_keystore_migration_time(1);
1346 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE); 1355 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE);
1347 nigori_node.SetNigoriSpecifics(nigori); 1356 nigori_node.SetNigoriSpecifics(nigori);
1348 } 1357 }
1349 1358
1350 EXPECT_CALL(*observer(), 1359 EXPECT_CALL(*observer(),
1351 OnPassphraseRequired(_, _)); 1360 OnPassphraseRequired(_, _));
1352 EXPECT_CALL(*observer(), 1361 EXPECT_CALL(*observer(),
1353 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 1362 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
1354 EXPECT_CALL(*observer(), 1363 EXPECT_CALL(*observer(),
1355 OnCryptographerStateChanged(_)); 1364 OnCryptographerStateChanged(_)).Times(AnyNumber());
1356 EXPECT_CALL(*observer(), 1365 EXPECT_CALL(*observer(),
1357 OnEncryptedTypesChanged(_, false)); 1366 OnEncryptedTypesChanged(_, false));
1358 encryption_handler()->Init(); 1367 encryption_handler()->Init();
1359 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1368 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1360 EXPECT_TRUE(GetCryptographer()->has_pending_keys()); 1369 EXPECT_TRUE(GetCryptographer()->has_pending_keys());
1361 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); 1370 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
1362 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1371 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1363 Mock::VerifyAndClearExpectations(observer()); 1372 Mock::VerifyAndClearExpectations(observer());
1364 1373
1365 EXPECT_CALL(*observer(), 1374 EXPECT_CALL(*observer(),
1366 OnPassphraseAccepted()); 1375 OnPassphraseAccepted());
1367 EXPECT_CALL(*observer(), 1376 EXPECT_CALL(*observer(),
1368 OnCryptographerStateChanged(_)); 1377 OnCryptographerStateChanged(_)).Times(AnyNumber());
1369 EXPECT_CALL(*observer(), 1378 EXPECT_CALL(*observer(),
1370 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1379 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1371 EXPECT_CALL(*observer(), 1380 EXPECT_CALL(*observer(),
1372 OnEncryptionComplete()); 1381 OnEncryptionComplete());
1373 encryption_handler()->SetDecryptionPassphrase(kOldKey); 1382 encryption_handler()->SetDecryptionPassphrase(kOldKey);
1374 EXPECT_TRUE(GetCryptographer()->is_ready()); 1383 EXPECT_TRUE(GetCryptographer()->is_ready());
1375 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1384 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1376 Mock::VerifyAndClearExpectations(observer()); 1385 Mock::VerifyAndClearExpectations(observer());
1377 1386
1378 const char kNewKey[] = "new_key"; 1387 const char kNewKey[] = "new_key";
1379 EXPECT_CALL(*observer(), 1388 EXPECT_CALL(*observer(),
1380 OnCryptographerStateChanged(_)); 1389 OnCryptographerStateChanged(_)).Times(AnyNumber());
1381 EXPECT_CALL(*observer(), 1390 EXPECT_CALL(*observer(),
1382 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); 1391 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
1383 EXPECT_CALL(*observer(), 1392 EXPECT_CALL(*observer(),
1384 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1393 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1385 EXPECT_CALL(*observer(), 1394 EXPECT_CALL(*observer(),
1386 OnPassphraseAccepted()); 1395 OnPassphraseAccepted());
1387 EXPECT_CALL(*observer(), 1396 EXPECT_CALL(*observer(),
1388 OnEncryptedTypesChanged(_, true)); 1397 OnEncryptedTypesChanged(_, true));
1389 EXPECT_CALL(*observer(), 1398 EXPECT_CALL(*observer(),
1390 OnEncryptionComplete()).Times(2); 1399 OnEncryptionComplete()).Times(2);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 nigori.set_keystore_migration_time(1); 1460 nigori.set_keystore_migration_time(1);
1452 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE); 1461 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE);
1453 nigori_node.SetNigoriSpecifics(nigori); 1462 nigori_node.SetNigoriSpecifics(nigori);
1454 } 1463 }
1455 1464
1456 EXPECT_CALL(*observer(), 1465 EXPECT_CALL(*observer(),
1457 OnPassphraseRequired(_, _)); 1466 OnPassphraseRequired(_, _));
1458 EXPECT_CALL(*observer(), 1467 EXPECT_CALL(*observer(),
1459 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 1468 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
1460 EXPECT_CALL(*observer(), 1469 EXPECT_CALL(*observer(),
1461 OnCryptographerStateChanged(_)); 1470 OnCryptographerStateChanged(_)).Times(AnyNumber());
1462 EXPECT_CALL(*observer(), 1471 EXPECT_CALL(*observer(),
1463 OnEncryptedTypesChanged(_, false)); 1472 OnEncryptedTypesChanged(_, false));
1464 encryption_handler()->Init(); 1473 encryption_handler()->Init();
1465 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1474 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1466 EXPECT_TRUE(GetCryptographer()->has_pending_keys()); 1475 EXPECT_TRUE(GetCryptographer()->has_pending_keys());
1467 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); 1476 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
1468 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1477 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1469 Mock::VerifyAndClearExpectations(observer()); 1478 Mock::VerifyAndClearExpectations(observer());
1470 1479
1471 EXPECT_CALL(*observer(), 1480 EXPECT_CALL(*observer(),
1472 OnPassphraseAccepted()); 1481 OnPassphraseAccepted());
1473 EXPECT_CALL(*observer(), 1482 EXPECT_CALL(*observer(),
1474 OnCryptographerStateChanged(_)); 1483 OnCryptographerStateChanged(_)).Times(AnyNumber());
1475 EXPECT_CALL(*observer(), 1484 EXPECT_CALL(*observer(),
1476 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1485 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1477 EXPECT_CALL(*observer(), 1486 EXPECT_CALL(*observer(),
1478 OnEncryptionComplete()); 1487 OnEncryptionComplete());
1479 encryption_handler()->SetDecryptionPassphrase(kOldKey); 1488 encryption_handler()->SetDecryptionPassphrase(kOldKey);
1480 EXPECT_TRUE(GetCryptographer()->is_ready()); 1489 EXPECT_TRUE(GetCryptographer()->is_ready());
1481 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1490 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1482 Mock::VerifyAndClearExpectations(observer()); 1491 Mock::VerifyAndClearExpectations(observer());
1483 1492
1484 // Should get dropped on the floor silently. 1493 // Should get dropped on the floor silently.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 nigori.set_keybag_is_frozen(true); 1554 nigori.set_keybag_is_frozen(true);
1546 nigori.set_keystore_migration_time(1); 1555 nigori.set_keystore_migration_time(1);
1547 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE); 1556 nigori.set_passphrase_type(sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE);
1548 nigori_node.SetNigoriSpecifics(nigori); 1557 nigori_node.SetNigoriSpecifics(nigori);
1549 } 1558 }
1550 EXPECT_CALL(*observer(), 1559 EXPECT_CALL(*observer(),
1551 OnPassphraseRequired(_, _)); 1560 OnPassphraseRequired(_, _));
1552 EXPECT_CALL(*observer(), 1561 EXPECT_CALL(*observer(),
1553 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 1562 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
1554 EXPECT_CALL(*observer(), 1563 EXPECT_CALL(*observer(),
1555 OnCryptographerStateChanged(_)); 1564 OnCryptographerStateChanged(_)).Times(AnyNumber());
1556 EXPECT_CALL(*observer(), 1565 EXPECT_CALL(*observer(),
1557 OnEncryptedTypesChanged(_, false)); 1566 OnEncryptedTypesChanged(_, false));
1558 encryption_handler()->Init(); 1567 encryption_handler()->Init();
1559 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1568 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1560 EXPECT_TRUE(GetCryptographer()->has_pending_keys()); 1569 EXPECT_TRUE(GetCryptographer()->has_pending_keys());
1561 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); 1570 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
1562 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1571 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1563 Mock::VerifyAndClearExpectations(observer()); 1572 Mock::VerifyAndClearExpectations(observer());
1564 1573
1565 EXPECT_CALL(*observer(), 1574 EXPECT_CALL(*observer(),
1566 OnPassphraseAccepted()); 1575 OnPassphraseAccepted());
1567 EXPECT_CALL(*observer(), 1576 EXPECT_CALL(*observer(),
1568 OnCryptographerStateChanged(_)); 1577 OnCryptographerStateChanged(_)).Times(AnyNumber());
1569 EXPECT_CALL(*observer(), 1578 EXPECT_CALL(*observer(),
1570 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1579 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1571 EXPECT_CALL(*observer(), 1580 EXPECT_CALL(*observer(),
1572 OnEncryptionComplete()); 1581 OnEncryptionComplete());
1573 encryption_handler()->SetDecryptionPassphrase(kCurKey); 1582 encryption_handler()->SetDecryptionPassphrase(kCurKey);
1574 Mock::VerifyAndClearExpectations(observer()); 1583 Mock::VerifyAndClearExpectations(observer());
1575 1584
1576 EXPECT_CALL(*observer(), 1585 EXPECT_CALL(*observer(),
1577 OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE)); 1586 OnPassphraseTypeChanged(FROZEN_IMPLICIT_PASSPHRASE));
1578 EXPECT_CALL(*observer(), 1587 EXPECT_CALL(*observer(),
1579 OnEncryptionComplete()); 1588 OnEncryptionComplete());
1580 EXPECT_CALL(*observer(), 1589 EXPECT_CALL(*observer(),
1581 OnEncryptedTypesChanged(_, true)); 1590 OnEncryptedTypesChanged(_, true));
1591 EXPECT_CALL(*observer(),
1592 OnCryptographerStateChanged(_)).Times(AnyNumber());
1582 encryption_handler()->EnableEncryptEverything(); 1593 encryption_handler()->EnableEncryptEverything();
1583 Mock::VerifyAndClearExpectations(observer()); 1594 Mock::VerifyAndClearExpectations(observer());
1584 1595
1585 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1596 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1586 EXPECT_TRUE(GetCryptographer()->is_ready()); 1597 EXPECT_TRUE(GetCryptographer()->is_ready());
1587 EXPECT_EQ(FROZEN_IMPLICIT_PASSPHRASE, 1598 EXPECT_EQ(FROZEN_IMPLICIT_PASSPHRASE,
1588 encryption_handler()->GetPassphraseType()); 1599 encryption_handler()->GetPassphraseType());
1589 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled()); 1600 EXPECT_TRUE(encryption_handler()->EncryptEverythingEnabled());
1590 VerifyMigratedNigoriWithTimestamp(1, FROZEN_IMPLICIT_PASSPHRASE, kCurKey); 1601 VerifyMigratedNigoriWithTimestamp(1, FROZEN_IMPLICIT_PASSPHRASE, kCurKey);
1591 1602
(...skipping 23 matching lines...) Expand all
1615 KeyParams cur_key = {"localhost", "dummy", kCurKey}; 1626 KeyParams cur_key = {"localhost", "dummy", kCurKey};
1616 KeyParams keystore_key = {"localhost", "dummy", kKeystoreKey}; 1627 KeyParams keystore_key = {"localhost", "dummy", kKeystoreKey};
1617 GetCryptographer()->AddKey(old_key); 1628 GetCryptographer()->AddKey(old_key);
1618 GetCryptographer()->AddKey(cur_key); 1629 GetCryptographer()->AddKey(cur_key);
1619 1630
1620 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); 1631 Cryptographer other_cryptographer(GetCryptographer()->encryptor());
1621 other_cryptographer.AddKey(old_key); 1632 other_cryptographer.AddKey(old_key);
1622 EXPECT_TRUE(other_cryptographer.is_ready()); 1633 EXPECT_TRUE(other_cryptographer.is_ready());
1623 1634
1624 EXPECT_CALL(*observer(), 1635 EXPECT_CALL(*observer(),
1625 OnCryptographerStateChanged(_)); 1636 OnCryptographerStateChanged(_)).Times(AnyNumber());
1626 EXPECT_CALL(*observer(), 1637 EXPECT_CALL(*observer(),
1627 OnEncryptedTypesChanged(_, false)); 1638 OnEncryptedTypesChanged(_, false));
1628 EXPECT_CALL(*observer(), 1639 EXPECT_CALL(*observer(),
1629 OnEncryptionComplete()); 1640 OnEncryptionComplete());
1630 encryption_handler()->Init(); 1641 encryption_handler()->Init();
1631 EXPECT_TRUE(GetCryptographer()->is_ready()); 1642 EXPECT_TRUE(GetCryptographer()->is_ready());
1632 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1643 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1633 1644
1634 { 1645 {
1635 EXPECT_CALL(*observer(), 1646 EXPECT_CALL(*observer(),
1636 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN)); 1647 OnBootstrapTokenUpdated(_, KEYSTORE_BOOTSTRAP_TOKEN));
1637 ReadTransaction trans(FROM_HERE, user_share()); 1648 ReadTransaction trans(FROM_HERE, user_share());
1638 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans()); 1649 encryption_handler()->SetKeystoreKey(kKeystoreKey, trans.GetWrappedTrans());
1639 } 1650 }
1640 EXPECT_CALL(*observer(), 1651 EXPECT_CALL(*observer(),
1641 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE)); 1652 OnPassphraseTypeChanged(KEYSTORE_PASSPHRASE));
1642 PumpLoop(); 1653 PumpLoop();
1643 Mock::VerifyAndClearExpectations(observer()); 1654 Mock::VerifyAndClearExpectations(observer());
1644 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1655 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1645 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); 1656 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
1646 VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey); 1657 VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey);
1647 1658
1648 // Now build an old keystore passphrase nigori node. 1659 // Now build an old keystore passphrase nigori node.
1649 EXPECT_CALL(*observer(), 1660 EXPECT_CALL(*observer(),
1650 OnCryptographerStateChanged(_)); 1661 OnCryptographerStateChanged(_)).Times(AnyNumber());
1651 { 1662 {
1652 WriteTransaction trans(FROM_HERE, user_share()); 1663 WriteTransaction trans(FROM_HERE, user_share());
1653 WriteNode nigori_node(&trans); 1664 WriteNode nigori_node(&trans);
1654 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK); 1665 ASSERT_EQ(nigori_node.InitByTagLookup(kNigoriTag), BaseNode::INIT_OK);
1655 sync_pb::NigoriSpecifics nigori; 1666 sync_pb::NigoriSpecifics nigori;
1656 Cryptographer other_cryptographer(GetCryptographer()->encryptor()); 1667 Cryptographer other_cryptographer(GetCryptographer()->encryptor());
1657 other_cryptographer.AddKey(old_key); 1668 other_cryptographer.AddKey(old_key);
1658 encryption_handler()->GetKeystoreDecryptor( 1669 encryption_handler()->GetKeystoreDecryptor(
1659 other_cryptographer, 1670 other_cryptographer,
1660 kKeystoreKey, 1671 kKeystoreKey,
(...skipping 10 matching lines...) Expand all
1671 1682
1672 // Verify we're still migrated and have proper encryption state. 1683 // Verify we're still migrated and have proper encryption state.
1673 EXPECT_TRUE(encryption_handler()->MigratedToKeystore()); 1684 EXPECT_TRUE(encryption_handler()->MigratedToKeystore());
1674 EXPECT_TRUE(GetCryptographer()->is_ready()); 1685 EXPECT_TRUE(GetCryptographer()->is_ready());
1675 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE); 1686 EXPECT_EQ(encryption_handler()->GetPassphraseType(), KEYSTORE_PASSPHRASE);
1676 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled()); 1687 EXPECT_FALSE(encryption_handler()->EncryptEverythingEnabled());
1677 VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey); 1688 VerifyMigratedNigori(KEYSTORE_PASSPHRASE, kCurKey);
1678 } 1689 }
1679 1690
1680 } // namespace syncer 1691 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698