From 3fa964af1c44352d08fca3a4bb0cad6006b3640c Mon Sep 17 00:00:00 2001 From: "zea@chromium.org" Date: Thu, 24 Feb 2011 18:54:39 +0000 Subject: [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 --- chrome/browser/sync/util/cryptographer.cc | 13 +++++++++---- chrome/browser/sync/util/cryptographer.h | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'chrome/browser/sync/util') 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; -- cgit v1.1