Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: sync/util/cryptographer.cc

Issue 442053002: sync: Add non-blocking type encryption (retry) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/util/cryptographer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 = GetDefaultNigoriKey(); 254 std::string unencrypted_token = GetDefaultNigoriKeyData();
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
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::GetDefaultNigoriKey() const { 327 std::string Cryptographer::GetDefaultNigoriKeyName() const {
328 return default_nigori_name_;
329 }
330
331 std::string Cryptographer::GetDefaultNigoriKeyData() const {
328 if (!is_initialized()) 332 if (!is_initialized())
329 return std::string(); 333 return std::string();
330 NigoriMap::const_iterator iter = nigoris_.find(default_nigori_name_); 334 NigoriMap::const_iterator iter = nigoris_.find(default_nigori_name_);
331 if (iter == nigoris_.end()) 335 if (iter == nigoris_.end())
332 return std::string(); 336 return std::string();
333 sync_pb::NigoriKey key; 337 sync_pb::NigoriKey key;
334 if (!iter->second->ExportKeys(key.mutable_user_key(), 338 if (!iter->second->ExportKeys(key.mutable_user_key(),
335 key.mutable_encryption_key(), 339 key.mutable_encryption_key(),
336 key.mutable_mac_key())) 340 key.mutable_mac_key()))
337 return std::string(); 341 return std::string();
(...skipping 14 matching lines...) Expand all
352 NOTREACHED(); 356 NOTREACHED();
353 return false; 357 return false;
354 } 358 }
355 359
356 if (!AddKeyImpl(nigori.Pass(), true)) 360 if (!AddKeyImpl(nigori.Pass(), true))
357 return false; 361 return false;
358 return true; 362 return true;
359 } 363 }
360 364
361 } // namespace syncer 365 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/util/cryptographer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698