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

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

Issue 6465005: [Sync] Initial support for encrypting any datatype (no UI hookup yet). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + small fix Created 9 years, 10 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 | « chrome/browser/sync/util/cryptographer.h ('k') | chrome/chrome.gyp » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/base64.h" 5 #include "base/base64.h"
6 #include "chrome/browser/sync/util/cryptographer.h" 6 #include "chrome/browser/sync/util/cryptographer.h"
7 #include "chrome/browser/password_manager/encryptor.h" 7 #include "chrome/browser/password_manager/encryptor.h"
8 8
9 namespace browser_sync { 9 namespace browser_sync {
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 encrypted->mutable_blob())) { 52 encrypted->mutable_blob())) {
53 NOTREACHED(); // Encrypt should not fail. 53 NOTREACHED(); // Encrypt should not fail.
54 return false; 54 return false;
55 } 55 }
56 return true; 56 return true;
57 } 57 }
58 58
59 bool Cryptographer::Decrypt(const sync_pb::EncryptedData& encrypted, 59 bool Cryptographer::Decrypt(const sync_pb::EncryptedData& encrypted,
60 ::google::protobuf::MessageLite* message) const { 60 ::google::protobuf::MessageLite* message) const {
61 DCHECK(message); 61 DCHECK(message);
62 std::string plaintext = DecryptToString(encrypted);
63 return message->ParseFromString(plaintext);
64 }
62 65
66 std::string Cryptographer::DecryptToString(
67 const sync_pb::EncryptedData& encrypted) const {
63 NigoriMap::const_iterator it = nigoris_.find(encrypted.key_name()); 68 NigoriMap::const_iterator it = nigoris_.find(encrypted.key_name());
64 if (nigoris_.end() == it) { 69 if (nigoris_.end() == it) {
65 NOTREACHED() << "Cannot decrypt message"; 70 NOTREACHED() << "Cannot decrypt message";
66 return false; // Caller should have called CanDecrypt(encrypt). 71 return std::string(""); // Caller should have called CanDecrypt(encrypt).
67 } 72 }
68 73
69 std::string plaintext; 74 std::string plaintext;
70 if (!it->second->Decrypt(encrypted.blob(), &plaintext)) { 75 if (!it->second->Decrypt(encrypted.blob(), &plaintext)) {
71 return false; 76 return std::string("");
72 } 77 }
73 78
74 return message->ParseFromString(plaintext); 79 return plaintext;
75 } 80 }
76 81
77 bool Cryptographer::GetKeys(sync_pb::EncryptedData* encrypted) const { 82 bool Cryptographer::GetKeys(sync_pb::EncryptedData* encrypted) const {
78 DCHECK(encrypted); 83 DCHECK(encrypted);
79 DCHECK(!nigoris_.empty()); 84 DCHECK(!nigoris_.empty());
80 85
81 // Create a bag of all the Nigori parameters we know about. 86 // Create a bag of all the Nigori parameters we know about.
82 sync_pb::NigoriKeyBag bag; 87 sync_pb::NigoriKeyBag bag;
83 for (NigoriMap::const_iterator it = nigoris_.begin(); it != nigoris_.end(); 88 for (NigoriMap::const_iterator it = nigoris_.begin(); it != nigoris_.end();
84 ++it) { 89 ++it) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 return false; 202 return false;
198 } 203 }
199 return true; 204 return true;
200 } 205 }
201 206
202 Nigori* Cryptographer::UnpackBootstrapToken(const std::string& token) const { 207 Nigori* Cryptographer::UnpackBootstrapToken(const std::string& token) const {
203 if (token.empty()) 208 if (token.empty())
204 return NULL; 209 return NULL;
205 210
206 std::string encrypted_data; 211 std::string encrypted_data;
207 if (!base::Base64Decode(token, &encrypted_data)){ 212 if (!base::Base64Decode(token, &encrypted_data)) {
208 DLOG(WARNING) << "Could not decode token."; 213 DLOG(WARNING) << "Could not decode token.";
209 return NULL; 214 return NULL;
210 } 215 }
211 216
212 std::string unencrypted_token; 217 std::string unencrypted_token;
213 if (!Encryptor::DecryptString(encrypted_data, &unencrypted_token)) { 218 if (!Encryptor::DecryptString(encrypted_data, &unencrypted_token)) {
214 DLOG(WARNING) << "Decryption of bootstrap token failed."; 219 DLOG(WARNING) << "Decryption of bootstrap token failed.";
215 return NULL; 220 return NULL;
216 } 221 }
217 222
(...skipping 28 matching lines...) Expand all
246 continue; 251 continue;
247 } 252 }
248 nigoris_[key.name()] = make_linked_ptr(new_nigori.release()); 253 nigoris_[key.name()] = make_linked_ptr(new_nigori.release());
249 } 254 }
250 } 255 }
251 DCHECK(nigoris_.end() != nigoris_.find(default_key_name)); 256 DCHECK(nigoris_.end() != nigoris_.find(default_key_name));
252 default_nigori_ = &*nigoris_.find(default_key_name); 257 default_nigori_ = &*nigoris_.find(default_key_name);
253 } 258 }
254 259
255 } // namespace browser_sync 260 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/util/cryptographer.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698