| 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/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "sync/protocol/nigori_specifics.pb.h" | 12 #include "sync/protocol/nigori_specifics.pb.h" |
| 13 #include "sync/util/encryptor.h" | 13 #include "sync/util/encryptor.h" |
| 14 | 14 |
| 15 namespace syncer { | 15 namespace syncer { |
| 16 | 16 |
| 17 const char kNigoriTag[] = "google_chrome_nigori"; | 17 const char kNigoriTag[] = "google_chrome_nigori"; |
| 18 | 18 |
| 19 // We name a particular Nigori instance (ie. a triplet consisting of a hostname, | 19 // We name a particular Nigori instance (ie. a triplet consisting of a hostname, |
| 20 // a username, and a password) by calling Permute on this string. Since the | 20 // a username, and a password) by calling Permute on this string. Since the |
| 21 // output of Permute is always the same for a given triplet, clients will always | 21 // output of Permute is always the same for a given triplet, clients will always |
| 22 // assign the same name to a particular triplet. | 22 // assign the same name to a particular triplet. |
| 23 const char kNigoriKeyName[] = "nigori-key"; | 23 const char kNigoriKeyName[] = "nigori-key"; |
| 24 | 24 |
| 25 Cryptographer::Cryptographer(Encryptor* encryptor) | 25 Cryptographer::Cryptographer(Encryptor* encryptor) |
| 26 : encryptor_(encryptor) { | 26 : encryptor_(encryptor) { |
| 27 DCHECK(encryptor); | 27 DCHECK(encryptor); |
| 28 } | 28 } |
| 29 | 29 |
| 30 Cryptographer::Cryptographer(const Cryptographer& other) |
| 31 : encryptor_(other.encryptor_), |
| 32 default_nigori_name_(other.default_nigori_name_) { |
| 33 for (NigoriMap::const_iterator it = other.nigoris_.begin(); |
| 34 it != other.nigoris_.end(); |
| 35 ++it) { |
| 36 std::string user_key, encryption_key, mac_key; |
| 37 it->second->ExportKeys(&user_key, &encryption_key, &mac_key); |
| 38 linked_ptr<Nigori> nigori_copy(new Nigori()); |
| 39 nigori_copy->InitByImport(user_key, encryption_key, mac_key); |
| 40 nigoris_.insert(std::make_pair(it->first, nigori_copy)); |
| 41 } |
| 42 |
| 43 if (other.pending_keys_) { |
| 44 pending_keys_.reset(new sync_pb::EncryptedData(*(other.pending_keys_))); |
| 45 } |
| 46 } |
| 47 |
| 30 Cryptographer::~Cryptographer() {} | 48 Cryptographer::~Cryptographer() {} |
| 31 | 49 |
| 32 | 50 |
| 33 void Cryptographer::Bootstrap(const std::string& restored_bootstrap_token) { | 51 void Cryptographer::Bootstrap(const std::string& restored_bootstrap_token) { |
| 34 if (is_initialized()) { | 52 if (is_initialized()) { |
| 35 NOTREACHED(); | 53 NOTREACHED(); |
| 36 return; | 54 return; |
| 37 } | 55 } |
| 38 | 56 |
| 39 std::string serialized_nigori_key = | 57 std::string serialized_nigori_key = |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 NOTREACHED(); | 374 NOTREACHED(); |
| 357 return false; | 375 return false; |
| 358 } | 376 } |
| 359 | 377 |
| 360 if (!AddKeyImpl(nigori.Pass(), true)) | 378 if (!AddKeyImpl(nigori.Pass(), true)) |
| 361 return false; | 379 return false; |
| 362 return true; | 380 return true; |
| 363 } | 381 } |
| 364 | 382 |
| 365 } // namespace syncer | 383 } // namespace syncer |
| OLD | NEW |