summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync/util
diff options
context:
space:
mode:
authorzea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-24 18:54:39 +0000
committerzea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-24 18:54:39 +0000
commit3fa964af1c44352d08fca3a4bb0cad6006b3640c (patch)
tree4e92d801c0566acfa9531ad31a2813e4f2cf71b8 /chrome/browser/sync/util
parentef3facf5d7cae5977657f6ff7dfe3f14746eb08b (diff)
downloadchromium_src-3fa964af1c44352d08fca3a4bb0cad6006b3640c.zip
chromium_src-3fa964af1c44352d08fca3a4bb0cad6006b3640c.tar.gz
chromium_src-3fa964af1c44352d08fca3a4bb0cad6006b3640c.tar.bz2
[Sync] Unrevert r75287 (initial support for sync encryption of all datatypes). Fix passphrase race.
BUG=73218,59242 TEST=unit,sync_unit,sync_integration Review URL: http://codereview.chromium.org/6561001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75920 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/util')
-rw-r--r--chrome/browser/sync/util/cryptographer.cc13
-rw-r--r--chrome/browser/sync/util/cryptographer.h4
2 files changed, 13 insertions, 4 deletions
diff --git a/chrome/browser/sync/util/cryptographer.cc b/chrome/browser/sync/util/cryptographer.cc
index 747b094..da94681 100644
--- a/chrome/browser/sync/util/cryptographer.cc
+++ b/chrome/browser/sync/util/cryptographer.cc
@@ -59,19 +59,24 @@ bool Cryptographer::Encrypt(const ::google::protobuf::MessageLite& message,
bool Cryptographer::Decrypt(const sync_pb::EncryptedData& encrypted,
::google::protobuf::MessageLite* message) const {
DCHECK(message);
+ std::string plaintext = DecryptToString(encrypted);
+ return message->ParseFromString(plaintext);
+}
+std::string Cryptographer::DecryptToString(
+ const sync_pb::EncryptedData& encrypted) const {
NigoriMap::const_iterator it = nigoris_.find(encrypted.key_name());
if (nigoris_.end() == it) {
NOTREACHED() << "Cannot decrypt message";
- return false; // Caller should have called CanDecrypt(encrypt).
+ return std::string(""); // Caller should have called CanDecrypt(encrypt).
}
std::string plaintext;
if (!it->second->Decrypt(encrypted.blob(), &plaintext)) {
- return false;
+ return std::string("");
}
- return message->ParseFromString(plaintext);
+ return plaintext;
}
bool Cryptographer::GetKeys(sync_pb::EncryptedData* encrypted) const {
@@ -204,7 +209,7 @@ Nigori* Cryptographer::UnpackBootstrapToken(const std::string& token) const {
return NULL;
std::string encrypted_data;
- if (!base::Base64Decode(token, &encrypted_data)){
+ if (!base::Base64Decode(token, &encrypted_data)) {
DLOG(WARNING) << "Could not decode token.";
return NULL;
}
diff --git a/chrome/browser/sync/util/cryptographer.h b/chrome/browser/sync/util/cryptographer.h
index ada084cc..adb809b 100644
--- a/chrome/browser/sync/util/cryptographer.h
+++ b/chrome/browser/sync/util/cryptographer.h
@@ -71,6 +71,10 @@ class Cryptographer {
bool Decrypt(const sync_pb::EncryptedData& encrypted,
::google::protobuf::MessageLite* message) const;
+ // Decrypts |encrypted| and returns plaintext decrypted data. If decryption
+ // fails, returns empty string.
+ std::string DecryptToString(const sync_pb::EncryptedData& encrypted) const;
+
// Encrypts the set of currently known keys into |encrypted|. Returns true if
// successful.
bool GetKeys(sync_pb::EncryptedData* encrypted) const;