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

Side by Side Diff: components/sync/base/cryptographer.h

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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 COMPONENTS_SYNC_BASE_CRYPTOGRAPHER_H_
6 #define SYNC_UTIL_CRYPTOGRAPHER_H_ 6 #define COMPONENTS_SYNC_BASE_CRYPTOGRAPHER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.h"
14 #include "sync/base/sync_export.h" 14 #include "components/sync/base/nigori.h"
15 #include "sync/protocol/encryption.pb.h" 15 #include "components/sync/base/sync_export.h"
16 #include "sync/util/nigori.h" 16 #include "components/sync/protocol/encryption.pb.h"
17 17
18 namespace sync_pb { 18 namespace sync_pb {
19 class NigoriKeyBag; 19 class NigoriKeyBag;
20 class NigoriSpecifics; 20 class NigoriSpecifics;
21 } 21 }
22 22
23 namespace syncer { 23 namespace syncer {
24 24
25 class Encryptor; 25 class Encryptor;
26 26
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 // Sets the default key to the nigori with name |key_name|. |key_name| must 153 // Sets the default key to the nigori with name |key_name|. |key_name| must
154 // correspond to a nigori that has already been installed into the keybag. 154 // correspond to a nigori that has already been installed into the keybag.
155 void SetDefaultKey(const std::string& key_name); 155 void SetDefaultKey(const std::string& key_name);
156 156
157 bool is_initialized() const { 157 bool is_initialized() const {
158 return !nigoris_.empty() && !default_nigori_name_.empty(); 158 return !nigoris_.empty() && !default_nigori_name_.empty();
159 } 159 }
160 160
161 // Returns whether this Cryptographer is ready to encrypt and decrypt data. 161 // Returns whether this Cryptographer is ready to encrypt and decrypt data.
162 bool is_ready() const { 162 bool is_ready() const { return is_initialized() && !has_pending_keys(); }
163 return is_initialized() && !has_pending_keys();
164 }
165 163
166 // Returns whether there is a pending set of keys that needs to be decrypted. 164 // Returns whether there is a pending set of keys that needs to be decrypted.
167 bool has_pending_keys() const { return NULL != pending_keys_.get(); } 165 bool has_pending_keys() const { return NULL != pending_keys_.get(); }
168 166
169 // Obtain a token that can be provided on construction to a future 167 // Obtain a token that can be provided on construction to a future
170 // Cryptographer instance to bootstrap itself. Returns false if such a token 168 // Cryptographer instance to bootstrap itself. Returns false if such a token
171 // can't be created (i.e. if this Cryptograhper doesn't have valid keys). 169 // can't be created (i.e. if this Cryptograhper doesn't have valid keys).
172 bool GetBootstrapToken(std::string* token) const; 170 bool GetBootstrapToken(std::string* token) const;
173 171
174 Encryptor* encryptor() const { return encryptor_; } 172 Encryptor* encryptor() const { return encryptor_; }
175 173
176 // Returns true if |keybag| is decryptable and either is a subset of nigoris_ 174 // Returns true if |keybag| is decryptable and either is a subset of nigoris_
177 // and/or has a different default key. 175 // and/or has a different default key.
178 bool KeybagIsStale(const sync_pb::EncryptedData& keybag) const; 176 bool KeybagIsStale(const sync_pb::EncryptedData& keybag) const;
179 177
180 // Returns the name of the Nigori key currently used for encryption. 178 // Returns the name of the Nigori key currently used for encryption.
181 std::string GetDefaultNigoriKeyName() const; 179 std::string GetDefaultNigoriKeyName() const;
182 180
183 // Returns a serialized sync_pb::NigoriKey version of current default 181 // Returns a serialized sync_pb::NigoriKey version of current default
184 // encryption key. 182 // encryption key.
185 std::string GetDefaultNigoriKeyData() const; 183 std::string GetDefaultNigoriKeyData() const;
186 184
187 // Generates a new Nigori from |serialized_nigori_key|, and if successful 185 // Generates a new Nigori from |serialized_nigori_key|, and if successful
188 // installs the new nigori as the default key. 186 // installs the new nigori as the default key.
189 bool ImportNigoriKey(const std::string& serialized_nigori_key); 187 bool ImportNigoriKey(const std::string& serialized_nigori_key);
190 188
191 private: 189 private:
192 typedef std::map<std::string, linked_ptr<const Nigori> > NigoriMap; 190 typedef std::map<std::string, linked_ptr<const Nigori>> NigoriMap;
193 191
194 // Helper method to instantiate Nigori instances for each set of key 192 // Helper method to instantiate Nigori instances for each set of key
195 // parameters in |bag|. 193 // parameters in |bag|.
196 // Does not update the default nigori. 194 // Does not update the default nigori.
197 void InstallKeyBag(const sync_pb::NigoriKeyBag& bag); 195 void InstallKeyBag(const sync_pb::NigoriKeyBag& bag);
198 196
199 // Helper method to add a nigori to the keybag, optionally making it the 197 // Helper method to add a nigori to the keybag, optionally making it the
200 // default as well. 198 // default as well.
201 bool AddKeyImpl(std::unique_ptr<Nigori> nigori, bool set_as_default); 199 bool AddKeyImpl(std::unique_ptr<Nigori> nigori, bool set_as_default);
202 200
203 // Helper to unencrypt a bootstrap token into a serialized sync_pb::NigoriKey. 201 // Helper to unencrypt a bootstrap token into a serialized sync_pb::NigoriKey.
204 std::string UnpackBootstrapToken(const std::string& token) const; 202 std::string UnpackBootstrapToken(const std::string& token) const;
205 203
206 Encryptor* const encryptor_; 204 Encryptor* const encryptor_;
207 205
208 // The Nigoris we know about, mapped by key name. 206 // The Nigoris we know about, mapped by key name.
209 NigoriMap nigoris_; 207 NigoriMap nigoris_;
210 208
211 // The key name associated with the default nigori. If non-empty, must 209 // The key name associated with the default nigori. If non-empty, must
212 // correspond to a nigori within |nigoris_|. 210 // correspond to a nigori within |nigoris_|.
213 std::string default_nigori_name_; 211 std::string default_nigori_name_;
214 212
215 std::unique_ptr<sync_pb::EncryptedData> pending_keys_; 213 std::unique_ptr<sync_pb::EncryptedData> pending_keys_;
216 214
217 DISALLOW_ASSIGN(Cryptographer); 215 DISALLOW_ASSIGN(Cryptographer);
218 }; 216 };
219 217
220 } // namespace syncer 218 } // namespace syncer
221 219
222 #endif // SYNC_UTIL_CRYPTOGRAPHER_H_ 220 #endif // COMPONENTS_SYNC_BASE_CRYPTOGRAPHER_H_
OLDNEW
« no previous file with comments | « components/sync/base/cancelation_signal_unittest.cc ('k') | components/sync/base/cryptographer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698