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" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (!nigori->InitByDerivation(params.hostname, | 180 if (!nigori->InitByDerivation(params.hostname, |
181 params.username, | 181 params.username, |
182 params.password)) { | 182 params.password)) { |
183 NOTREACHED(); // Invalid username or password. | 183 NOTREACHED(); // Invalid username or password. |
184 return false; | 184 return false; |
185 } | 185 } |
186 return AddKeyImpl(nigori.Pass(), false); | 186 return AddKeyImpl(nigori.Pass(), false); |
187 } | 187 } |
188 | 188 |
189 bool Cryptographer::AddKeyFromBootstrapToken( | 189 bool Cryptographer::AddKeyFromBootstrapToken( |
190 const std::string restored_bootstrap_token) { | 190 const std::string& restored_bootstrap_token) { |
191 // Create the new Nigori and make it the default encryptor. | 191 // Create the new Nigori and make it the default encryptor. |
192 std::string serialized_nigori_key = UnpackBootstrapToken( | 192 std::string serialized_nigori_key = UnpackBootstrapToken( |
193 restored_bootstrap_token); | 193 restored_bootstrap_token); |
194 return ImportNigoriKey(serialized_nigori_key); | 194 return ImportNigoriKey(serialized_nigori_key); |
195 } | 195 } |
196 | 196 |
197 bool Cryptographer::AddKeyImpl(scoped_ptr<Nigori> initialized_nigori, | 197 bool Cryptographer::AddKeyImpl(scoped_ptr<Nigori> initialized_nigori, |
198 bool set_as_default) { | 198 bool set_as_default) { |
199 std::string name; | 199 std::string name; |
200 if (!initialized_nigori->Permute(Nigori::Password, kNigoriKeyName, &name)) { | 200 if (!initialized_nigori->Permute(Nigori::Password, kNigoriKeyName, &name)) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 if (iter == nigoris_.end()) | 354 if (iter == nigoris_.end()) |
355 return std::string(); | 355 return std::string(); |
356 sync_pb::NigoriKey key; | 356 sync_pb::NigoriKey key; |
357 if (!iter->second->ExportKeys(key.mutable_user_key(), | 357 if (!iter->second->ExportKeys(key.mutable_user_key(), |
358 key.mutable_encryption_key(), | 358 key.mutable_encryption_key(), |
359 key.mutable_mac_key())) | 359 key.mutable_mac_key())) |
360 return std::string(); | 360 return std::string(); |
361 return key.SerializeAsString(); | 361 return key.SerializeAsString(); |
362 } | 362 } |
363 | 363 |
364 bool Cryptographer::ImportNigoriKey(const std::string serialized_nigori_key) { | 364 bool Cryptographer::ImportNigoriKey(const std::string& serialized_nigori_key) { |
365 if (serialized_nigori_key.empty()) | 365 if (serialized_nigori_key.empty()) |
366 return false; | 366 return false; |
367 | 367 |
368 sync_pb::NigoriKey key; | 368 sync_pb::NigoriKey key; |
369 if (!key.ParseFromString(serialized_nigori_key)) | 369 if (!key.ParseFromString(serialized_nigori_key)) |
370 return false; | 370 return false; |
371 | 371 |
372 scoped_ptr<Nigori> nigori(new Nigori); | 372 scoped_ptr<Nigori> nigori(new Nigori); |
373 if (!nigori->InitByImport(key.user_key(), key.encryption_key(), | 373 if (!nigori->InitByImport(key.user_key(), key.encryption_key(), |
374 key.mac_key())) { | 374 key.mac_key())) { |
375 NOTREACHED(); | 375 NOTREACHED(); |
376 return false; | 376 return false; |
377 } | 377 } |
378 | 378 |
379 if (!AddKeyImpl(nigori.Pass(), true)) | 379 if (!AddKeyImpl(nigori.Pass(), true)) |
380 return false; | 380 return false; |
381 return true; | 381 return true; |
382 } | 382 } |
383 | 383 |
384 } // namespace syncer | 384 } // namespace syncer |
OLD | NEW |