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

Side by Side Diff: sync/test/fake_sync_encryption_handler.cc

Issue 10916036: [Sync] Implement keystore migration support. (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
« no previous file with comments | « sync/test/fake_sync_encryption_handler.h ('k') | sync/util/cryptographer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/test/fake_sync_encryption_handler.h" 5 #include "sync/test/fake_sync_encryption_handler.h"
6 6
7 #include "sync/protocol/nigori_specifics.pb.h" 7 #include "sync/protocol/nigori_specifics.pb.h"
8 #include "sync/syncable/nigori_util.h" 8 #include "sync/syncable/nigori_util.h"
9 9
10 namespace syncer { 10 namespace syncer {
11 11
12 FakeSyncEncryptionHandler::FakeSyncEncryptionHandler() 12 FakeSyncEncryptionHandler::FakeSyncEncryptionHandler()
13 : encrypted_types_(SensitiveTypes()), 13 : encrypted_types_(SensitiveTypes()),
14 encrypt_everything_(false), 14 encrypt_everything_(false),
15 passphrase_state_(IMPLICIT_PASSPHRASE), 15 passphrase_type_(IMPLICIT_PASSPHRASE),
16 cryptographer_(&encryptor_) { 16 cryptographer_(&encryptor_) {
17 } 17 }
18 FakeSyncEncryptionHandler::~FakeSyncEncryptionHandler() {} 18 FakeSyncEncryptionHandler::~FakeSyncEncryptionHandler() {}
19 19
20 void FakeSyncEncryptionHandler::Init() { 20 void FakeSyncEncryptionHandler::Init() {
21 // Do nothing. 21 // Do nothing.
22 } 22 }
23 23
24 void FakeSyncEncryptionHandler::ApplyNigoriUpdate( 24 void FakeSyncEncryptionHandler::ApplyNigoriUpdate(
25 const sync_pb::NigoriSpecifics& nigori, 25 const sync_pb::NigoriSpecifics& nigori,
26 syncable::BaseTransaction* const trans) { 26 syncable::BaseTransaction* const trans) {
27 if (nigori.encrypt_everything()) 27 if (nigori.encrypt_everything())
28 EnableEncryptEverything(); 28 EnableEncryptEverything();
29 if (nigori.using_explicit_passphrase()) 29 if (nigori.keybag_is_frozen())
30 passphrase_state_ = CUSTOM_PASSPHRASE; 30 passphrase_type_ = CUSTOM_PASSPHRASE;
31 31
32 if (cryptographer_.CanDecrypt(nigori.encrypted())) 32 // TODO(zea): consider adding fake support for migration.
33 cryptographer_.InstallKeys(nigori.encrypted()); 33 if (cryptographer_.CanDecrypt(nigori.encryption_keybag()))
34 else if (nigori.has_encrypted()) 34 cryptographer_.InstallKeys(nigori.encryption_keybag());
35 cryptographer_.SetPendingKeys(nigori.encrypted()); 35 else if (nigori.has_encryption_keybag())
36 cryptographer_.SetPendingKeys(nigori.encryption_keybag());
36 37
37 if (cryptographer_.has_pending_keys()) { 38 if (cryptographer_.has_pending_keys()) {
38 DVLOG(1) << "OnPassPhraseRequired Sent"; 39 DVLOG(1) << "OnPassPhraseRequired Sent";
39 sync_pb::EncryptedData pending_keys = cryptographer_.GetPendingKeys(); 40 sync_pb::EncryptedData pending_keys = cryptographer_.GetPendingKeys();
40 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, 41 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
41 OnPassphraseRequired(REASON_DECRYPTION, 42 OnPassphraseRequired(REASON_DECRYPTION,
42 pending_keys)); 43 pending_keys));
43 } else if (!cryptographer_.is_ready()) { 44 } else if (!cryptographer_.is_ready()) {
44 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " 45 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not "
45 << "ready"; 46 << "ready";
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 87 }
87 88
88 void FakeSyncEncryptionHandler::RemoveObserver(Observer* observer) { 89 void FakeSyncEncryptionHandler::RemoveObserver(Observer* observer) {
89 observers_.RemoveObserver(observer); 90 observers_.RemoveObserver(observer);
90 } 91 }
91 92
92 void FakeSyncEncryptionHandler::SetEncryptionPassphrase( 93 void FakeSyncEncryptionHandler::SetEncryptionPassphrase(
93 const std::string& passphrase, 94 const std::string& passphrase,
94 bool is_explicit) { 95 bool is_explicit) {
95 if (is_explicit) 96 if (is_explicit)
96 passphrase_state_ = CUSTOM_PASSPHRASE; 97 passphrase_type_ = CUSTOM_PASSPHRASE;
97 } 98 }
98 99
99 void FakeSyncEncryptionHandler::SetDecryptionPassphrase( 100 void FakeSyncEncryptionHandler::SetDecryptionPassphrase(
100 const std::string& passphrase) { 101 const std::string& passphrase) {
101 // Do nothing. 102 // Do nothing.
102 } 103 }
103 104
104 void FakeSyncEncryptionHandler::EnableEncryptEverything() { 105 void FakeSyncEncryptionHandler::EnableEncryptEverything() {
105 if (encrypt_everything_) 106 if (encrypt_everything_)
106 return; 107 return;
107 encrypt_everything_ = true; 108 encrypt_everything_ = true;
108 encrypted_types_ = ModelTypeSet::All(); 109 encrypted_types_ = ModelTypeSet::All();
109 FOR_EACH_OBSERVER( 110 FOR_EACH_OBSERVER(
110 Observer, observers_, 111 Observer, observers_,
111 OnEncryptedTypesChanged(encrypted_types_, encrypt_everything_)); 112 OnEncryptedTypesChanged(encrypted_types_, encrypt_everything_));
112 } 113 }
113 114
114 bool FakeSyncEncryptionHandler::EncryptEverythingEnabled() const { 115 bool FakeSyncEncryptionHandler::EncryptEverythingEnabled() const {
115 return encrypt_everything_; 116 return encrypt_everything_;
116 } 117 }
117 118
118 PassphraseState FakeSyncEncryptionHandler::GetPassphraseState() const { 119 PassphraseType FakeSyncEncryptionHandler::GetPassphraseType() const {
119 return passphrase_state_; 120 return passphrase_type_;
120 } 121 }
121 122
122 } // namespace syncer 123 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/test/fake_sync_encryption_handler.h ('k') | sync/util/cryptographer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698