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 "components/sync/base/cryptographer.h" | 5 #include "components/sync/base/cryptographer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/base64.h" | 12 #include "base/base64.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" |
14 #include "components/sync/base/encryptor.h" | 15 #include "components/sync/base/encryptor.h" |
15 #include "components/sync/protocol/nigori_specifics.pb.h" | 16 #include "components/sync/protocol/nigori_specifics.pb.h" |
16 | 17 |
17 namespace syncer { | 18 namespace syncer { |
18 | 19 |
19 const char kNigoriTag[] = "google_chrome_nigori"; | 20 const char kNigoriTag[] = "google_chrome_nigori"; |
20 | 21 |
21 // We name a particular Nigori instance (ie. a triplet consisting of a hostname, | 22 // We name a particular Nigori instance (ie. a triplet consisting of a hostname, |
22 // a username, and a password) by calling Permute on this string. Since the | 23 // a username, and a password) by calling Permute on this string. Since the |
23 // output of Permute is always the same for a given triplet, clients will always | 24 // output of Permute is always the same for a given triplet, clients will always |
(...skipping 10 matching lines...) Expand all Loading... |
34 for (NigoriMap::const_iterator it = other.nigoris_.begin(); | 35 for (NigoriMap::const_iterator it = other.nigoris_.begin(); |
35 it != other.nigoris_.end(); ++it) { | 36 it != other.nigoris_.end(); ++it) { |
36 std::string user_key, encryption_key, mac_key; | 37 std::string user_key, encryption_key, mac_key; |
37 it->second->ExportKeys(&user_key, &encryption_key, &mac_key); | 38 it->second->ExportKeys(&user_key, &encryption_key, &mac_key); |
38 linked_ptr<Nigori> nigori_copy(new Nigori()); | 39 linked_ptr<Nigori> nigori_copy(new Nigori()); |
39 nigori_copy->InitByImport(user_key, encryption_key, mac_key); | 40 nigori_copy->InitByImport(user_key, encryption_key, mac_key); |
40 nigoris_.insert(std::make_pair(it->first, nigori_copy)); | 41 nigoris_.insert(std::make_pair(it->first, nigori_copy)); |
41 } | 42 } |
42 | 43 |
43 if (other.pending_keys_) { | 44 if (other.pending_keys_) { |
44 pending_keys_.reset(new sync_pb::EncryptedData(*(other.pending_keys_))); | 45 pending_keys_ = |
| 46 base::MakeUnique<sync_pb::EncryptedData>(*(other.pending_keys_)); |
45 } | 47 } |
46 } | 48 } |
47 | 49 |
48 Cryptographer::~Cryptographer() {} | 50 Cryptographer::~Cryptographer() {} |
49 | 51 |
50 void Cryptographer::Bootstrap(const std::string& restored_bootstrap_token) { | 52 void Cryptographer::Bootstrap(const std::string& restored_bootstrap_token) { |
51 if (is_initialized()) { | 53 if (is_initialized()) { |
52 NOTREACHED(); | 54 NOTREACHED(); |
53 return; | 55 return; |
54 } | 56 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 225 } |
224 | 226 |
225 void Cryptographer::SetDefaultKey(const std::string& key_name) { | 227 void Cryptographer::SetDefaultKey(const std::string& key_name) { |
226 DCHECK(nigoris_.end() != nigoris_.find(key_name)); | 228 DCHECK(nigoris_.end() != nigoris_.find(key_name)); |
227 default_nigori_name_ = key_name; | 229 default_nigori_name_ = key_name; |
228 } | 230 } |
229 | 231 |
230 void Cryptographer::SetPendingKeys(const sync_pb::EncryptedData& encrypted) { | 232 void Cryptographer::SetPendingKeys(const sync_pb::EncryptedData& encrypted) { |
231 DCHECK(!CanDecrypt(encrypted)); | 233 DCHECK(!CanDecrypt(encrypted)); |
232 DCHECK(!encrypted.blob().empty()); | 234 DCHECK(!encrypted.blob().empty()); |
233 pending_keys_.reset(new sync_pb::EncryptedData(encrypted)); | 235 pending_keys_ = base::MakeUnique<sync_pb::EncryptedData>(encrypted); |
234 } | 236 } |
235 | 237 |
236 const sync_pb::EncryptedData& Cryptographer::GetPendingKeys() const { | 238 const sync_pb::EncryptedData& Cryptographer::GetPendingKeys() const { |
237 DCHECK(has_pending_keys()); | 239 DCHECK(has_pending_keys()); |
238 return *(pending_keys_.get()); | 240 return *(pending_keys_.get()); |
239 } | 241 } |
240 | 242 |
241 bool Cryptographer::DecryptPendingKeys(const KeyParams& params) { | 243 bool Cryptographer::DecryptPendingKeys(const KeyParams& params) { |
242 Nigori nigori; | 244 Nigori nigori; |
243 if (!nigori.InitByDerivation(params.hostname, params.username, | 245 if (!nigori.InitByDerivation(params.hostname, params.username, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 NOTREACHED(); | 369 NOTREACHED(); |
368 return false; | 370 return false; |
369 } | 371 } |
370 | 372 |
371 if (!AddKeyImpl(std::move(nigori), true)) | 373 if (!AddKeyImpl(std::move(nigori), true)) |
372 return false; | 374 return false; |
373 return true; | 375 return true; |
374 } | 376 } |
375 | 377 |
376 } // namespace syncer | 378 } // namespace syncer |
OLD | NEW |