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

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

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
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 "components/sync/test/fake_sync_encryption_handler.h"
6 6
7 #include "sync/protocol/nigori_specifics.pb.h" 7 #include "components/sync/protocol/nigori_specifics.pb.h"
8 #include "sync/syncable/nigori_util.h" 8 #include "components/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_type_(IMPLICIT_PASSPHRASE), 15 passphrase_type_(IMPLICIT_PASSPHRASE),
16 cryptographer_(&encryptor_) { 16 cryptographer_(&encryptor_) {}
17 }
18 FakeSyncEncryptionHandler::~FakeSyncEncryptionHandler() {} 17 FakeSyncEncryptionHandler::~FakeSyncEncryptionHandler() {}
19 18
20 void FakeSyncEncryptionHandler::Init() { 19 void FakeSyncEncryptionHandler::Init() {
21 // Set up a basic cryptographer. 20 // Set up a basic cryptographer.
22 KeyParams keystore_params = {"localhost", "dummy", "keystore_key"}; 21 KeyParams keystore_params = {"localhost", "dummy", "keystore_key"};
23 cryptographer_.AddKey(keystore_params); 22 cryptographer_.AddKey(keystore_params);
24 } 23 }
25 24
26 void FakeSyncEncryptionHandler::ApplyNigoriUpdate( 25 void FakeSyncEncryptionHandler::ApplyNigoriUpdate(
27 const sync_pb::NigoriSpecifics& nigori, 26 const sync_pb::NigoriSpecifics& nigori,
28 syncable::BaseTransaction* const trans) { 27 syncable::BaseTransaction* const trans) {
29 if (nigori.encrypt_everything()) 28 if (nigori.encrypt_everything())
30 EnableEncryptEverything(); 29 EnableEncryptEverything();
31 if (nigori.keybag_is_frozen()) 30 if (nigori.keybag_is_frozen())
32 passphrase_type_ = CUSTOM_PASSPHRASE; 31 passphrase_type_ = CUSTOM_PASSPHRASE;
33 32
34 // TODO(zea): consider adding fake support for migration. 33 // TODO(zea): consider adding fake support for migration.
35 if (cryptographer_.CanDecrypt(nigori.encryption_keybag())) 34 if (cryptographer_.CanDecrypt(nigori.encryption_keybag()))
36 cryptographer_.InstallKeys(nigori.encryption_keybag()); 35 cryptographer_.InstallKeys(nigori.encryption_keybag());
37 else if (nigori.has_encryption_keybag()) 36 else if (nigori.has_encryption_keybag())
38 cryptographer_.SetPendingKeys(nigori.encryption_keybag()); 37 cryptographer_.SetPendingKeys(nigori.encryption_keybag());
39 38
40 if (cryptographer_.has_pending_keys()) { 39 if (cryptographer_.has_pending_keys()) {
41 DVLOG(1) << "OnPassPhraseRequired Sent"; 40 DVLOG(1) << "OnPassPhraseRequired Sent";
42 sync_pb::EncryptedData pending_keys = cryptographer_.GetPendingKeys(); 41 sync_pb::EncryptedData pending_keys = cryptographer_.GetPendingKeys();
43 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, 42 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
44 OnPassphraseRequired(REASON_DECRYPTION, 43 OnPassphraseRequired(REASON_DECRYPTION, pending_keys));
45 pending_keys));
46 } else if (!cryptographer_.is_ready()) { 44 } else if (!cryptographer_.is_ready()) {
47 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " 45 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not "
48 << "ready"; 46 << "ready";
49 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, 47 FOR_EACH_OBSERVER(
50 OnPassphraseRequired(REASON_ENCRYPTION, 48 SyncEncryptionHandler::Observer, observers_,
51 sync_pb::EncryptedData())); 49 OnPassphraseRequired(REASON_ENCRYPTION, sync_pb::EncryptedData()));
52 } 50 }
53 } 51 }
54 52
55 void FakeSyncEncryptionHandler::UpdateNigoriFromEncryptedTypes( 53 void FakeSyncEncryptionHandler::UpdateNigoriFromEncryptedTypes(
56 sync_pb::NigoriSpecifics* nigori, 54 sync_pb::NigoriSpecifics* nigori,
57 syncable::BaseTransaction* const trans) const { 55 syncable::BaseTransaction* const trans) const {
58 syncable::UpdateNigoriFromEncryptedTypes(encrypted_types_, 56 syncable::UpdateNigoriFromEncryptedTypes(encrypted_types_,
59 encrypt_everything_, 57 encrypt_everything_, nigori);
60 nigori);
61 } 58 }
62 59
63 bool FakeSyncEncryptionHandler::NeedKeystoreKey( 60 bool FakeSyncEncryptionHandler::NeedKeystoreKey(
64 syncable::BaseTransaction* const trans) const { 61 syncable::BaseTransaction* const trans) const {
65 return keystore_key_.empty(); 62 return keystore_key_.empty();
66 } 63 }
67 64
68 bool FakeSyncEncryptionHandler::SetKeystoreKeys( 65 bool FakeSyncEncryptionHandler::SetKeystoreKeys(
69 const google::protobuf::RepeatedPtrField<google::protobuf::string>& keys, 66 const google::protobuf::RepeatedPtrField<google::protobuf::string>& keys,
70 syncable::BaseTransaction* const trans) { 67 syncable::BaseTransaction* const trans) {
71 if (keys.size() == 0) 68 if (keys.size() == 0)
72 return false; 69 return false;
73 std::string new_key = keys.Get(keys.size()-1); 70 std::string new_key = keys.Get(keys.size() - 1);
74 if (new_key.empty()) 71 if (new_key.empty())
75 return false; 72 return false;
76 keystore_key_ = new_key; 73 keystore_key_ = new_key;
77 74
78
79 DVLOG(1) << "Keystore bootstrap token updated."; 75 DVLOG(1) << "Keystore bootstrap token updated.";
80 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, 76 FOR_EACH_OBSERVER(
81 OnBootstrapTokenUpdated(keystore_key_, 77 SyncEncryptionHandler::Observer, observers_,
82 KEYSTORE_BOOTSTRAP_TOKEN)); 78 OnBootstrapTokenUpdated(keystore_key_, KEYSTORE_BOOTSTRAP_TOKEN));
83 return true; 79 return true;
84 } 80 }
85 81
86 ModelTypeSet FakeSyncEncryptionHandler::GetEncryptedTypes( 82 ModelTypeSet FakeSyncEncryptionHandler::GetEncryptedTypes(
87 syncable::BaseTransaction* const trans) const { 83 syncable::BaseTransaction* const trans) const {
88 return encrypted_types_; 84 return encrypted_types_;
89 } 85 }
90 86
91 void FakeSyncEncryptionHandler::AddObserver(Observer* observer) { 87 void FakeSyncEncryptionHandler::AddObserver(Observer* observer) {
92 observers_.AddObserver(observer); 88 observers_.AddObserver(observer);
(...skipping 27 matching lines...) Expand all
120 116
121 bool FakeSyncEncryptionHandler::IsEncryptEverythingEnabled() const { 117 bool FakeSyncEncryptionHandler::IsEncryptEverythingEnabled() const {
122 return encrypt_everything_; 118 return encrypt_everything_;
123 } 119 }
124 120
125 PassphraseType FakeSyncEncryptionHandler::GetPassphraseType() const { 121 PassphraseType FakeSyncEncryptionHandler::GetPassphraseType() const {
126 return passphrase_type_; 122 return passphrase_type_;
127 } 123 }
128 124
129 } // namespace syncer 125 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/test/fake_sync_encryption_handler.h ('k') | components/sync/test/local_sync_test_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698