OLD | NEW |
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 #include "sync/util/cryptographer.h" | |
10 | 9 |
11 namespace syncer { | 10 namespace syncer { |
12 | 11 |
13 FakeSyncEncryptionHandler::FakeSyncEncryptionHandler() | 12 FakeSyncEncryptionHandler::FakeSyncEncryptionHandler() |
14 : encrypted_types_(SensitiveTypes()), | 13 : encrypted_types_(SensitiveTypes()), |
15 encrypt_everything_(false), | 14 encrypt_everything_(false), |
16 explicit_passphrase_(false), | 15 explicit_passphrase_(false), |
17 cryptographer_(NULL) { | 16 cryptographer_(&encryptor_) { |
18 } | 17 } |
19 FakeSyncEncryptionHandler::~FakeSyncEncryptionHandler() {} | 18 FakeSyncEncryptionHandler::~FakeSyncEncryptionHandler() {} |
20 | 19 |
21 void FakeSyncEncryptionHandler::Init() { | 20 void FakeSyncEncryptionHandler::Init() { |
22 // Do nothing. | 21 // Do nothing. |
23 } | 22 } |
24 | 23 |
25 void FakeSyncEncryptionHandler::ApplyNigoriUpdate( | 24 void FakeSyncEncryptionHandler::ApplyNigoriUpdate( |
26 const sync_pb::NigoriSpecifics& nigori, | 25 const sync_pb::NigoriSpecifics& nigori, |
27 syncable::BaseTransaction* const trans) { | 26 syncable::BaseTransaction* const trans) { |
28 if (nigori.encrypt_everything()) | 27 if (nigori.encrypt_everything()) |
29 EnableEncryptEverything(); | 28 EnableEncryptEverything(); |
30 if (nigori.using_explicit_passphrase()) | 29 if (nigori.using_explicit_passphrase()) |
31 explicit_passphrase_ = true; | 30 explicit_passphrase_ = true; |
32 | 31 |
33 if (!cryptographer_) | 32 if (cryptographer_.CanDecrypt(nigori.encrypted())) |
34 return; | 33 cryptographer_.InstallKeys(nigori.encrypted()); |
| 34 else if (nigori.has_encrypted()) |
| 35 cryptographer_.SetPendingKeys(nigori.encrypted()); |
35 | 36 |
36 if (cryptographer_->CanDecrypt(nigori.encrypted())) | 37 if (cryptographer_.has_pending_keys()) { |
37 cryptographer_->InstallKeys(nigori.encrypted()); | |
38 else | |
39 cryptographer_->SetPendingKeys(nigori.encrypted()); | |
40 | |
41 if (cryptographer_->has_pending_keys()) { | |
42 DVLOG(1) << "OnPassPhraseRequired Sent"; | 38 DVLOG(1) << "OnPassPhraseRequired Sent"; |
43 sync_pb::EncryptedData pending_keys = cryptographer_->GetPendingKeys(); | 39 sync_pb::EncryptedData pending_keys = cryptographer_.GetPendingKeys(); |
44 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, | 40 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
45 OnPassphraseRequired(REASON_DECRYPTION, | 41 OnPassphraseRequired(REASON_DECRYPTION, |
46 pending_keys)); | 42 pending_keys)); |
47 } else if (!cryptographer_->is_ready()) { | 43 } else if (!cryptographer_.is_ready()) { |
48 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " | 44 DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not " |
49 << "ready"; | 45 << "ready"; |
50 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, | 46 FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_, |
51 OnPassphraseRequired(REASON_ENCRYPTION, | 47 OnPassphraseRequired(REASON_ENCRYPTION, |
52 sync_pb::EncryptedData())); | 48 sync_pb::EncryptedData())); |
53 } | 49 } |
54 } | 50 } |
55 | 51 |
56 void FakeSyncEncryptionHandler::UpdateNigoriFromEncryptedTypes( | 52 void FakeSyncEncryptionHandler::UpdateNigoriFromEncryptedTypes( |
57 sync_pb::NigoriSpecifics* nigori, | 53 sync_pb::NigoriSpecifics* nigori, |
58 syncable::BaseTransaction* const trans) const { | 54 syncable::BaseTransaction* const trans) const { |
59 syncable::UpdateNigoriFromEncryptedTypes(encrypted_types_, | 55 syncable::UpdateNigoriFromEncryptedTypes(encrypted_types_, |
60 encrypt_everything_, | 56 encrypt_everything_, |
61 nigori); | 57 nigori); |
62 } | 58 } |
63 | 59 |
| 60 ModelTypeSet FakeSyncEncryptionHandler::GetEncryptedTypes( |
| 61 syncable::BaseTransaction* const trans) const { |
| 62 return encrypted_types_; |
| 63 } |
| 64 |
64 void FakeSyncEncryptionHandler::AddObserver(Observer* observer) { | 65 void FakeSyncEncryptionHandler::AddObserver(Observer* observer) { |
65 observers_.AddObserver(observer); | 66 observers_.AddObserver(observer); |
66 } | 67 } |
67 | 68 |
68 void FakeSyncEncryptionHandler::RemoveObserver(Observer* observer) { | 69 void FakeSyncEncryptionHandler::RemoveObserver(Observer* observer) { |
69 observers_.RemoveObserver(observer); | 70 observers_.RemoveObserver(observer); |
70 } | 71 } |
71 | 72 |
72 void FakeSyncEncryptionHandler::SetEncryptionPassphrase( | 73 void FakeSyncEncryptionHandler::SetEncryptionPassphrase( |
73 const std::string& passphrase, | 74 const std::string& passphrase, |
(...skipping 14 matching lines...) Expand all Loading... |
88 encrypted_types_ = ModelTypeSet::All(); | 89 encrypted_types_ = ModelTypeSet::All(); |
89 FOR_EACH_OBSERVER( | 90 FOR_EACH_OBSERVER( |
90 Observer, observers_, | 91 Observer, observers_, |
91 OnEncryptedTypesChanged(encrypted_types_, encrypt_everything_)); | 92 OnEncryptedTypesChanged(encrypted_types_, encrypt_everything_)); |
92 } | 93 } |
93 | 94 |
94 bool FakeSyncEncryptionHandler::EncryptEverythingEnabled() const { | 95 bool FakeSyncEncryptionHandler::EncryptEverythingEnabled() const { |
95 return encrypt_everything_; | 96 return encrypt_everything_; |
96 } | 97 } |
97 | 98 |
98 ModelTypeSet FakeSyncEncryptionHandler::GetEncryptedTypes() const { | |
99 return encrypted_types_; | |
100 } | |
101 | |
102 bool FakeSyncEncryptionHandler::IsUsingExplicitPassphrase() const { | 99 bool FakeSyncEncryptionHandler::IsUsingExplicitPassphrase() const { |
103 return explicit_passphrase_; | 100 return explicit_passphrase_; |
104 } | 101 } |
105 | 102 |
106 } // namespace syncer | 103 } // namespace syncer |
OLD | NEW |