| 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/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 Loading... |
| 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 syncer::ModelTypeSet Cryptographer::SensitiveTypes() { | 333 syncer::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 syncer::ModelTypeSet types; | 336 syncer::ModelTypeSet types; |
| 316 types.Put(syncer::PASSWORDS); | 337 types.Put(syncer::PASSWORDS); |
| 317 types.Put(syncer::NIGORI); | 338 types.Put(syncer::NIGORI); |
| 318 return types; | 339 return types; |
| 319 } | 340 } |
| 320 | 341 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 key.mac_key())) { | 465 key.mac_key())) { |
| 445 NOTREACHED(); | 466 NOTREACHED(); |
| 446 continue; | 467 continue; |
| 447 } | 468 } |
| 448 nigoris_[key.name()] = make_linked_ptr(new_nigori.release()); | 469 nigoris_[key.name()] = make_linked_ptr(new_nigori.release()); |
| 449 } | 470 } |
| 450 } | 471 } |
| 451 } | 472 } |
| 452 | 473 |
| 453 } // namespace syncer | 474 } // namespace syncer |
| OLD | NEW |