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

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

Issue 10455012: [Sync] Add support for performing a GetKey on startup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fred's comments 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
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/util/cryptographer.h" 5 #include "sync/util/cryptographer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "sync/util/encryptor.h" 11 #include "sync/util/encryptor.h"
12 12
13 namespace syncer { 13 namespace syncer {
14 14
15 const char kNigoriTag[] = "google_chrome_nigori"; 15 const char kNigoriTag[] = "google_chrome_nigori";
16 16
17 // We name a particular Nigori instance (ie. a triplet consisting of a hostname, 17 // We name a particular Nigori instance (ie. a triplet consisting of a hostname,
18 // a username, and a password) by calling Permute on this string. Since the 18 // a username, and a password) by calling Permute on this string. Since the
19 // output of Permute is always the same for a given triplet, clients will always 19 // output of Permute is always the same for a given triplet, clients will always
20 // assign the same name to a particular triplet. 20 // assign the same name to a particular triplet.
21 const char kNigoriKeyName[] = "nigori-key"; 21 const char kNigoriKeyName[] = "nigori-key";
22 22
23 Cryptographer::Observer::~Observer() {} 23 Cryptographer::Observer::~Observer() {}
24 24
25 Cryptographer::Cryptographer(Encryptor* encryptor) 25 Cryptographer::Cryptographer(Encryptor* encryptor)
26 : encryptor_(encryptor), 26 : encryptor_(encryptor),
27 default_nigori_(NULL), 27 default_nigori_(NULL),
28 keystore_nigori_(NULL),
28 encrypted_types_(SensitiveTypes()), 29 encrypted_types_(SensitiveTypes()),
29 encrypt_everything_(false) { 30 encrypt_everything_(false) {
30 DCHECK(encryptor); 31 DCHECK(encryptor);
31 } 32 }
32 33
33 Cryptographer::~Cryptographer() {} 34 Cryptographer::~Cryptographer() {}
34 35
35 void Cryptographer::AddObserver(Observer* observer) { 36 void Cryptographer::AddObserver(Observer* observer) {
36 observers_.AddObserver(observer); 37 observers_.AddObserver(observer);
37 } 38 }
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 } 302 }
302 return Cryptographer::SUCCESS; 303 return Cryptographer::SUCCESS;
303 } else { 304 } else {
304 SetPendingKeys(nigori.encrypted()); 305 SetPendingKeys(nigori.encrypted());
305 return Cryptographer::NEEDS_PASSPHRASE; 306 return Cryptographer::NEEDS_PASSPHRASE;
306 } 307 }
307 } 308 }
308 return Cryptographer::SUCCESS; 309 return Cryptographer::SUCCESS;
309 } 310 }
310 311
312 bool Cryptographer::SetKeystoreKey(const std::string& keystore_key) {
313 if (keystore_key.empty())
314 return false;
315 KeyParams params = {"localhost", "dummy", keystore_key};
316
317 // AddKey updates the default nigori, so we save the current default and
318 // make sure the keystore_nigori_ gets updated instead.
319 NigoriMap::value_type* old_default = default_nigori_;
320 if (AddKey(params)) {
321 keystore_nigori_ = default_nigori_;
322 default_nigori_ = old_default;
323 return true;
324 }
325 return false;
326 }
327
328 bool Cryptographer::HasKeystoreKey() {
329 return keystore_nigori_ != NULL;
330 }
331
311 // Static 332 // Static
312 ModelTypeSet Cryptographer::SensitiveTypes() { 333 ModelTypeSet Cryptographer::SensitiveTypes() {
313 // Both of these have their own encryption schemes, but we include them 334 // Both of these have their own encryption schemes, but we include them
314 // anyways. 335 // anyways.
315 ModelTypeSet types; 336 ModelTypeSet types;
316 types.Put(PASSWORDS); 337 types.Put(PASSWORDS);
317 types.Put(NIGORI); 338 types.Put(NIGORI);
318 return types; 339 return types;
319 } 340 }
320 341
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 key.mac_key())) { 463 key.mac_key())) {
443 NOTREACHED(); 464 NOTREACHED();
444 continue; 465 continue;
445 } 466 }
446 nigoris_[key.name()] = make_linked_ptr(new_nigori.release()); 467 nigoris_[key.name()] = make_linked_ptr(new_nigori.release());
447 } 468 }
448 } 469 }
449 } 470 }
450 471
451 } // namespace syncer 472 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698