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

Unified Diff: components/sync/base/nigori.cc

Issue 2813453004: [sync] Fix decryption failure caused by missing user_key (Closed)
Patch Set: Restore derivation check, add tests Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/sync/base/nigori.h ('k') | components/sync/base/nigori_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync/base/nigori.cc
diff --git a/components/sync/base/nigori.cc b/components/sync/base/nigori.cc
index 03c61b23472a34410579a40e987186db3bcde1d8..e87e96ccfccf1872eed11b042b1c58bf7f6dad06 100644
--- a/components/sync/base/nigori.cc
+++ b/components/sync/base/nigori.cc
@@ -79,6 +79,12 @@ bool Nigori::InitByDerivation(const std::string& hostname,
if (!user_salt->GetRawKey(&raw_user_salt))
return false;
+ // Kuser = PBKDF2(P, Suser, Nuser, 16)
+ user_key_ = SymmetricKey::DeriveKeyFromPassword(
+ SymmetricKey::AES, password, raw_user_salt, kUserIterations,
+ kDerivedKeySizeInBits);
+ DCHECK(user_key_);
+
// Kenc = PBKDF2(P, Suser, Nenc, 16)
encryption_key_ = SymmetricKey::DeriveKeyFromPassword(
SymmetricKey::AES, password, raw_user_salt, kEncryptionIterations,
@@ -91,11 +97,14 @@ bool Nigori::InitByDerivation(const std::string& hostname,
kDerivedKeySizeInBits);
DCHECK(mac_key_);
- return encryption_key_ && mac_key_;
+ return user_key_ && encryption_key_ && mac_key_;
}
-bool Nigori::InitByImport(const std::string& encryption_key,
+bool Nigori::InitByImport(const std::string& user_key,
+ const std::string& encryption_key,
const std::string& mac_key) {
+ user_key_ = SymmetricKey::Import(SymmetricKey::AES, user_key);
+
encryption_key_ = SymmetricKey::Import(SymmetricKey::AES, encryption_key);
DCHECK(encryption_key_);
@@ -223,11 +232,14 @@ bool Nigori::Decrypt(const std::string& encrypted, std::string* value) const {
return true;
}
-bool Nigori::ExportKeys(std::string* encryption_key,
+bool Nigori::ExportKeys(std::string* user_key,
+ std::string* encryption_key,
std::string* mac_key) const {
DCHECK(encryption_key);
DCHECK(mac_key);
+ user_key_->GetRawKey(user_key);
+
return encryption_key_->GetRawKey(encryption_key) &&
mac_key_->GetRawKey(mac_key);
}
« no previous file with comments | « components/sync/base/nigori.h ('k') | components/sync/base/nigori_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698