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

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

Issue 10844005: [Sync] Refactor GetEncryptedTypes usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + add dcheck Created 8 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 | Annotate | Revision Log
« no previous file with comments | « sync/test/fake_sync_encryption_handler.cc ('k') | sync/util/cryptographer.cc » ('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 #ifndef SYNC_UTIL_CRYPTOGRAPHER_H_ 5 #ifndef SYNC_UTIL_CRYPTOGRAPHER_H_
6 #define SYNC_UTIL_CRYPTOGRAPHER_H_ 6 #define SYNC_UTIL_CRYPTOGRAPHER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "sync/internal_api/public/base/model_type.h"
15 #include "sync/protocol/encryption.pb.h" 14 #include "sync/protocol/encryption.pb.h"
16 #include "sync/util/nigori.h" 15 #include "sync/util/nigori.h"
17 16
18 namespace sync_pb { 17 namespace sync_pb {
19 class NigoriKeyBag; 18 class NigoriKeyBag;
20 class NigoriSpecifics; 19 class NigoriSpecifics;
21 } 20 }
22 21
23 namespace syncer { 22 namespace syncer {
24 23
25 class Encryptor; 24 class Encryptor;
26 25
27 namespace syncable {
28 class BaseTransaction;
29 class NigoriHandler;
30 }
31
32 extern const char kNigoriTag[]; 26 extern const char kNigoriTag[];
33 27
34 // The parameters used to initialize a Nigori instance. 28 // The parameters used to initialize a Nigori instance.
35 struct KeyParams { 29 struct KeyParams {
36 std::string hostname; 30 std::string hostname;
37 std::string username; 31 std::string username;
38 std::string password; 32 std::string password;
39 }; 33 };
40 34
41 // This class manages the Nigori objects used to encrypt and decrypt sensitive 35 // This class manages the Nigori objects used to encrypt and decrypt sensitive
42 // sync data (eg. passwords). Each Nigori object knows how to handle data 36 // sync data (eg. passwords). Each Nigori object knows how to handle data
43 // protected with a particular passphrase. 37 // protected with a particular passphrase.
44 // 38 //
45 // Whenever an update to the Nigori sync node is received from the server, 39 // Whenever an update to the Nigori sync node is received from the server,
46 // SetPendingKeys should be called with the encrypted contents of that node. 40 // SetPendingKeys should be called with the encrypted contents of that node.
47 // Most likely, an updated Nigori node means that a new passphrase has been set 41 // Most likely, an updated Nigori node means that a new passphrase has been set
48 // and that future node updates won't be decryptable. To remedy this, the user 42 // and that future node updates won't be decryptable. To remedy this, the user
49 // should be prompted for the new passphrase and DecryptPendingKeys be called. 43 // should be prompted for the new passphrase and DecryptPendingKeys be called.
50 // 44 //
51 // Whenever a update to an encrypted node is received from the server, 45 // Whenever a update to an encrypted node is received from the server,
52 // CanDecrypt should be used to verify whether the Cryptographer can decrypt 46 // CanDecrypt should be used to verify whether the Cryptographer can decrypt
53 // that node. If it cannot, then the application of that update should be 47 // that node. If it cannot, then the application of that update should be
54 // delayed until after it can be decrypted. 48 // delayed until after it can be decrypted.
55 class Cryptographer { 49 class Cryptographer {
56 public: 50 public:
57 // Does not take ownership of |encryptor|. 51 // Does not take ownership of |encryptor|.
58 explicit Cryptographer(Encryptor* encryptor); 52 explicit Cryptographer(Encryptor* encryptor);
59 ~Cryptographer(); 53 ~Cryptographer();
60 54
61 // Set the sync nigori node handler.
62 // TODO(zea): refactor so that Cryptographer doesn't need any connection
63 // to a NigoriHandler. crbug.com/139848
64 void SetNigoriHandler(syncable::NigoriHandler* delegate);
65
66 // NigoriHandler delegator methods (passes through to delegate).
67 void ApplyNigoriUpdate(const sync_pb::NigoriSpecifics& nigori,
68 syncable::BaseTransaction* const trans);
69 void UpdateNigoriFromEncryptedTypes(
70 sync_pb::NigoriSpecifics* nigori,
71 syncable::BaseTransaction* const trans) const;
72 ModelTypeSet GetEncryptedTypes() const;
73
74 // |restored_bootstrap_token| can be provided via this method to bootstrap 55 // |restored_bootstrap_token| can be provided via this method to bootstrap
75 // Cryptographer instance into the ready state (is_ready will be true). 56 // Cryptographer instance into the ready state (is_ready will be true).
76 // It must be a string that was previously built by the 57 // It must be a string that was previously built by the
77 // GetSerializedBootstrapToken function. It is possible that the token is no 58 // GetSerializedBootstrapToken function. It is possible that the token is no
78 // longer valid (due to server key change), in which case the normal 59 // longer valid (due to server key change), in which case the normal
79 // decryption code paths will fail and the user will need to provide a new 60 // decryption code paths will fail and the user will need to provide a new
80 // passphrase. 61 // passphrase.
81 // It is an error to call this if is_ready() == true, though it is fair to 62 // It is an error to call this if is_ready() == true, though it is fair to
82 // never call Bootstrap at all. 63 // never call Bootstrap at all.
83 void Bootstrap(const std::string& restored_bootstrap_token); 64 void Bootstrap(const std::string& restored_bootstrap_token);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 Nigori* UnpackBootstrapToken(const std::string& token) const; 183 Nigori* UnpackBootstrapToken(const std::string& token) const;
203 184
204 Encryptor* const encryptor_; 185 Encryptor* const encryptor_;
205 186
206 NigoriMap nigoris_; // The Nigoris we know about, mapped by key name. 187 NigoriMap nigoris_; // The Nigoris we know about, mapped by key name.
207 NigoriMap::value_type* default_nigori_; // The Nigori used for encryption. 188 NigoriMap::value_type* default_nigori_; // The Nigori used for encryption.
208 NigoriMap::value_type* keystore_nigori_; // Nigori generated from keystore. 189 NigoriMap::value_type* keystore_nigori_; // Nigori generated from keystore.
209 190
210 scoped_ptr<sync_pb::EncryptedData> pending_keys_; 191 scoped_ptr<sync_pb::EncryptedData> pending_keys_;
211 192
212 // The sync nigori node handler. Necessary until we decouple the encrypted
213 // types from the cryptographer.
214 syncable::NigoriHandler* nigori_node_handler_;
215
216 DISALLOW_COPY_AND_ASSIGN(Cryptographer); 193 DISALLOW_COPY_AND_ASSIGN(Cryptographer);
217 }; 194 };
218 195
219 } // namespace syncer 196 } // namespace syncer
220 197
221 #endif // SYNC_UTIL_CRYPTOGRAPHER_H_ 198 #endif // SYNC_UTIL_CRYPTOGRAPHER_H_
OLDNEW
« no previous file with comments | « sync/test/fake_sync_encryption_handler.cc ('k') | sync/util/cryptographer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698