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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 } | 244 } |
245 InstallKeyBag(bag); | 245 InstallKeyBag(bag); |
246 const std::string& new_default_key_name = pending_keys_->key_name(); | 246 const std::string& new_default_key_name = pending_keys_->key_name(); |
247 SetDefaultKey(new_default_key_name); | 247 SetDefaultKey(new_default_key_name); |
248 pending_keys_.reset(); | 248 pending_keys_.reset(); |
249 return true; | 249 return true; |
250 } | 250 } |
251 | 251 |
252 bool Cryptographer::GetBootstrapToken(std::string* token) const { | 252 bool Cryptographer::GetBootstrapToken(std::string* token) const { |
253 DCHECK(token); | 253 DCHECK(token); |
254 std::string unencrypted_token = GetDefaultNigoriKeyData(); | 254 std::string unencrypted_token = GetDefaultNigoriKey(); |
255 if (unencrypted_token.empty()) | 255 if (unencrypted_token.empty()) |
256 return false; | 256 return false; |
257 | 257 |
258 std::string encrypted_token; | 258 std::string encrypted_token; |
259 if (!encryptor_->EncryptString(unencrypted_token, &encrypted_token)) { | 259 if (!encryptor_->EncryptString(unencrypted_token, &encrypted_token)) { |
260 NOTREACHED(); | 260 NOTREACHED(); |
261 return false; | 261 return false; |
262 } | 262 } |
263 | 263 |
264 base::Base64Encode(encrypted_token, token); | 264 base::Base64Encode(encrypted_token, token); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 if (!Decrypt(encrypted_bag, &bag)) { | 317 if (!Decrypt(encrypted_bag, &bag)) { |
318 LOG(ERROR) << "Failed to decrypt keybag for stale check. " | 318 LOG(ERROR) << "Failed to decrypt keybag for stale check. " |
319 << "Assuming keybag is corrupted."; | 319 << "Assuming keybag is corrupted."; |
320 return true; | 320 return true; |
321 } | 321 } |
322 if (static_cast<size_t>(bag.key_size()) < nigoris_.size()) | 322 if (static_cast<size_t>(bag.key_size()) < nigoris_.size()) |
323 return true; | 323 return true; |
324 return false; | 324 return false; |
325 } | 325 } |
326 | 326 |
327 std::string Cryptographer::GetDefaultNigoriKeyName() const { | 327 std::string Cryptographer::GetDefaultNigoriKey() const { |
328 return default_nigori_name_; | |
329 } | |
330 | |
331 std::string Cryptographer::GetDefaultNigoriKeyData() const { | |
332 if (!is_initialized()) | 328 if (!is_initialized()) |
333 return std::string(); | 329 return std::string(); |
334 NigoriMap::const_iterator iter = nigoris_.find(default_nigori_name_); | 330 NigoriMap::const_iterator iter = nigoris_.find(default_nigori_name_); |
335 if (iter == nigoris_.end()) | 331 if (iter == nigoris_.end()) |
336 return std::string(); | 332 return std::string(); |
337 sync_pb::NigoriKey key; | 333 sync_pb::NigoriKey key; |
338 if (!iter->second->ExportKeys(key.mutable_user_key(), | 334 if (!iter->second->ExportKeys(key.mutable_user_key(), |
339 key.mutable_encryption_key(), | 335 key.mutable_encryption_key(), |
340 key.mutable_mac_key())) | 336 key.mutable_mac_key())) |
341 return std::string(); | 337 return std::string(); |
(...skipping 14 matching lines...) Expand all Loading... |
356 NOTREACHED(); | 352 NOTREACHED(); |
357 return false; | 353 return false; |
358 } | 354 } |
359 | 355 |
360 if (!AddKeyImpl(nigori.Pass(), true)) | 356 if (!AddKeyImpl(nigori.Pass(), true)) |
361 return false; | 357 return false; |
362 return true; | 358 return true; |
363 } | 359 } |
364 | 360 |
365 } // namespace syncer | 361 } // namespace syncer |
OLD | NEW |