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

Side by Side Diff: chrome/browser/sync/util/cryptographer.h

Issue 8356026: [Sync] Cache encrypted types info in ProfileSyncService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revert to synchronous notifications Created 9 years, 2 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_SYNC_UTIL_CRYPTOGRAPHER_H_ 5 #ifndef CHROME_BROWSER_SYNC_UTIL_CRYPTOGRAPHER_H_
6 #define CHROME_BROWSER_SYNC_UTIL_CRYPTOGRAPHER_H_ 6 #define CHROME_BROWSER_SYNC_UTIL_CRYPTOGRAPHER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 11
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h"
15 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" 16 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h"
16 #include "chrome/browser/sync/syncable/model_type.h" 17 #include "chrome/browser/sync/syncable/model_type.h"
17 #include "chrome/browser/sync/util/nigori.h" 18 #include "chrome/browser/sync/util/nigori.h"
18 19
19 namespace browser_sync { 20 namespace browser_sync {
20 21
21 extern const char kNigoriTag[]; 22 extern const char kNigoriTag[];
22 23
23 // The parameters used to initialize a Nigori instance. 24 // The parameters used to initialize a Nigori instance.
24 struct KeyParams { 25 struct KeyParams {
(...skipping 11 matching lines...) Expand all
36 // Most likely, an updated Nigori node means that a new passphrase has been set 37 // Most likely, an updated Nigori node means that a new passphrase has been set
37 // and that future node updates won't be decryptable. To remedy this, the user 38 // and that future node updates won't be decryptable. To remedy this, the user
38 // should be prompted for the new passphrase and DecryptPendingKeys be called. 39 // should be prompted for the new passphrase and DecryptPendingKeys be called.
39 // 40 //
40 // Whenever a update to an encrypted node is received from the server, 41 // Whenever a update to an encrypted node is received from the server,
41 // CanDecrypt should be used to verify whether the Cryptographer can decrypt 42 // CanDecrypt should be used to verify whether the Cryptographer can decrypt
42 // that node. If it cannot, then the application of that update should be 43 // that node. If it cannot, then the application of that update should be
43 // delayed until after it can be decrypted. 44 // delayed until after it can be decrypted.
44 class Cryptographer { 45 class Cryptographer {
45 public: 46 public:
46 Cryptographer(); 47 // All Observer methods are done synchronously, so they're called
48 // under a transaction (since all Cryptographer operations are done
49 // under a transaction).
50 class Observer {
51 public:
52 virtual void OnEncryptedTypesChanged(
53 const syncable::ModelTypeSet& encrypted_types,
54 bool encrypt_everything) = 0;
55
56 // Send when all encrypted types have finished encryption.
57 // Guaranteed to be called immeduately after a call of
Nicolas Zea 2011/10/21 14:29:07 immediately
akalin 2011/10/22 03:28:38 Rendered moot
58 // OnEncryptedTypesChanged().
59 virtual void OnEncryptionComplete() = 0;
60
61 protected:
62 virtual ~Observer();
63 };
64
65 explicit Cryptographer();
47 ~Cryptographer(); 66 ~Cryptographer();
48 67
49 // When update on cryptographer is called this enum tells if the 68 // When update on cryptographer is called this enum tells if the
50 // cryptographer was succesfully able to update using the nigori node or if 69 // cryptographer was succesfully able to update using the nigori node or if
51 // it needs a key to decrypt the nigori node. 70 // it needs a key to decrypt the nigori node.
52 enum UpdateResult { 71 enum UpdateResult {
53 SUCCESS, 72 SUCCESS,
54 NEEDS_PASSPHRASE 73 NEEDS_PASSPHRASE
55 }; 74 };
56 75
76 // Manage observers.
77 void AddObserver(Observer* observer);
78 void RemoveObserver(Observer* observer);
79
57 // |restored_bootstrap_token| can be provided via this method to bootstrap 80 // |restored_bootstrap_token| can be provided via this method to bootstrap
58 // Cryptographer instance into the ready state (is_ready will be true). 81 // Cryptographer instance into the ready state (is_ready will be true).
59 // It must be a string that was previously built by the 82 // It must be a string that was previously built by the
60 // GetSerializedBootstrapToken function. It is possible that the token is no 83 // GetSerializedBootstrapToken function. It is possible that the token is no
61 // longer valid (due to server key change), in which case the normal 84 // longer valid (due to server key change), in which case the normal
62 // decryption code paths will fail and the user will need to provide a new 85 // decryption code paths will fail and the user will need to provide a new
63 // passphrase. 86 // passphrase.
64 // It is an error to call this if is_ready() == true, though it is fair to 87 // It is an error to call this if is_ready() == true, though it is fair to
65 // never call Bootstrap at all. 88 // never call Bootstrap at all.
66 void Bootstrap(const std::string& restored_bootstrap_token); 89 void Bootstrap(const std::string& restored_bootstrap_token);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 167
145 // Setter/getter for whether all current and future datatypes should be 168 // Setter/getter for whether all current and future datatypes should be
146 // encrypted. Once set you cannot unset without reading from a new nigori 169 // encrypted. Once set you cannot unset without reading from a new nigori
147 // node. 170 // node.
148 void set_encrypt_everything(); 171 void set_encrypt_everything();
149 bool encrypt_everything() const; 172 bool encrypt_everything() const;
150 173
151 // Set all types in |new_types| as requiring encryption (in addition to the 174 // Set all types in |new_types| as requiring encryption (in addition to the
152 // currently encrypted types). Note: once a type requires encryption it can 175 // currently encrypted types). Note: once a type requires encryption it can
153 // never stop requiring encryption without clearing the server data. 176 // never stop requiring encryption without clearing the server data.
154 void SetEncryptedTypes(syncable::ModelTypeSet new_types); 177 void SetEncryptedTypes(syncable::ModelTypeSet new_types);
Nicolas Zea 2011/10/21 14:29:07 This isn't really used any more (outside of tests)
akalin 2011/10/22 03:28:38 Actually, I ended up needing to clean it up, so I
155 178
156 // Return the set of encrypted types. 179 // Return the set of encrypted types.
157 syncable::ModelTypeSet GetEncryptedTypes() const; 180 syncable::ModelTypeSet GetEncryptedTypes() const;
158 181
182 // Triggers an OnEncryptedTypesChanged and an OnEncryptionComplete
183 // notifiation.
Nicolas Zea 2011/10/21 14:29:07 Is it necessary to always trigger the OnEncryptedT
akalin 2011/10/22 03:28:38 Yeah, fixed. It should only trigger when it actua
184 void MarkEncryptionComplete();
185
159 private: 186 private:
160 FRIEND_TEST_ALL_PREFIXES(CryptographerTest, PackUnpack); 187 FRIEND_TEST_ALL_PREFIXES(CryptographerTest, PackUnpack);
161 typedef std::map<std::string, linked_ptr<const Nigori> > NigoriMap; 188 typedef std::map<std::string, linked_ptr<const Nigori> > NigoriMap;
162 189
190 // Calls OnEncryptedTypesChanged() on all observers.
191 void EmitEncryptedTypesChangeNotification();
Nicolas Zea 2011/10/21 14:29:07 EncryptedTypesChange... -> EncryptedTypesChanged..
akalin 2011/10/22 03:28:38 Done.
192
163 // Helper method to instantiate Nigori instances for each set of key 193 // Helper method to instantiate Nigori instances for each set of key
164 // parameters in |bag| and setting the default encryption key to 194 // parameters in |bag| and setting the default encryption key to
165 // |default_key_name|. 195 // |default_key_name|.
166 void InstallKeys(const std::string& default_key_name, 196 void InstallKeys(const std::string& default_key_name,
167 const sync_pb::NigoriKeyBag& bag); 197 const sync_pb::NigoriKeyBag& bag);
168 198
169 bool AddKeyImpl(Nigori* nigori); 199 bool AddKeyImpl(Nigori* nigori);
170 200
171 // Functions to serialize + encrypt a Nigori object in an opaque format for 201 // Functions to serialize + encrypt a Nigori object in an opaque format for
172 // persistence by sync infrastructure. 202 // persistence by sync infrastructure.
173 bool PackBootstrapToken(const Nigori* nigori, std::string* pack_into) const; 203 bool PackBootstrapToken(const Nigori* nigori, std::string* pack_into) const;
174 Nigori* UnpackBootstrapToken(const std::string& token) const; 204 Nigori* UnpackBootstrapToken(const std::string& token) const;
175 205
206 ObserverList<Observer> observers_;
207
176 NigoriMap nigoris_; // The Nigoris we know about, mapped by key name. 208 NigoriMap nigoris_; // The Nigoris we know about, mapped by key name.
177 NigoriMap::value_type* default_nigori_; // The Nigori used for encryption. 209 NigoriMap::value_type* default_nigori_; // The Nigori used for encryption.
178 210
179 scoped_ptr<sync_pb::EncryptedData> pending_keys_; 211 scoped_ptr<sync_pb::EncryptedData> pending_keys_;
180 212
181 syncable::ModelTypeSet encrypted_types_; 213 syncable::ModelTypeSet encrypted_types_;
182 bool encrypt_everything_; 214 bool encrypt_everything_;
183 215
184 DISALLOW_COPY_AND_ASSIGN(Cryptographer); 216 DISALLOW_COPY_AND_ASSIGN(Cryptographer);
185 }; 217 };
186 218
187 } // namespace browser_sync 219 } // namespace browser_sync
188 220
189 #endif // CHROME_BROWSER_SYNC_UTIL_CRYPTOGRAPHER_H_ 221 #endif // CHROME_BROWSER_SYNC_UTIL_CRYPTOGRAPHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698