Commit ba06b861 authored by David Davidović's avatar David Davidović Committed by Commit Bot

[sync::nigori] Small cleanups to encryption code

Switched KeyDerivationParams to class (from struct) and defined
operator!= on it.

Removed a DCHECK which could theoretically trigger when the server sends
invalid data.

Merged some very similar tests for SyncEncryptionHandlerImpl.

Fixed some formatting.

Change-Id: Ia4d6a0baec984872c8c53cdc27bdd870aa3c9f57
Reviewed-on: https://chromium-review.googlesource.com/1236340
Commit-Queue: David Davidović <davidovic@google.com>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarvitaliii <vitaliii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594339}
parent f116efb3
...@@ -100,8 +100,12 @@ bool KeyDerivationParams::operator==(const KeyDerivationParams& other) const { ...@@ -100,8 +100,12 @@ bool KeyDerivationParams::operator==(const KeyDerivationParams& other) const {
scrypt_salt_ == other.scrypt_salt_; scrypt_salt_ == other.scrypt_salt_;
} }
bool KeyDerivationParams::operator!=(const KeyDerivationParams& other) const {
return !(*this == other);
}
const std::string& KeyDerivationParams::scrypt_salt() const { const std::string& KeyDerivationParams::scrypt_salt() const {
DCHECK(method_ == KeyDerivationMethod::SCRYPT_8192_8_11); DCHECK_EQ(method_, KeyDerivationMethod::SCRYPT_8192_8_11);
return scrypt_salt_; return scrypt_salt_;
} }
......
...@@ -20,7 +20,7 @@ namespace syncer { ...@@ -20,7 +20,7 @@ namespace syncer {
class Nigori; class Nigori;
struct KeyDerivationParams { class KeyDerivationParams {
public: public:
static KeyDerivationParams CreateForPbkdf2(); static KeyDerivationParams CreateForPbkdf2();
static KeyDerivationParams CreateForScrypt(const std::string& salt); static KeyDerivationParams CreateForScrypt(const std::string& salt);
...@@ -33,6 +33,7 @@ struct KeyDerivationParams { ...@@ -33,6 +33,7 @@ struct KeyDerivationParams {
KeyDerivationParams(KeyDerivationParams&& other); KeyDerivationParams(KeyDerivationParams&& other);
KeyDerivationParams& operator=(const KeyDerivationParams& other); KeyDerivationParams& operator=(const KeyDerivationParams& other);
bool operator==(const KeyDerivationParams& other) const; bool operator==(const KeyDerivationParams& other) const;
bool operator!=(const KeyDerivationParams& other) const;
private: private:
KeyDerivationParams(KeyDerivationMethod method, KeyDerivationParams(KeyDerivationMethod method,
......
...@@ -224,7 +224,6 @@ KeyDerivationMethod GetKeyDerivationMethodFromNigori( ...@@ -224,7 +224,6 @@ KeyDerivationMethod GetKeyDerivationMethodFromNigori(
std::string GetScryptSaltFromNigori(const sync_pb::NigoriSpecifics& nigori) { std::string GetScryptSaltFromNigori(const sync_pb::NigoriSpecifics& nigori) {
DCHECK_EQ(nigori.custom_passphrase_key_derivation_method(), DCHECK_EQ(nigori.custom_passphrase_key_derivation_method(),
sync_pb::NigoriSpecifics::SCRYPT_8192_8_11); sync_pb::NigoriSpecifics::SCRYPT_8192_8_11);
DCHECK(nigori.has_custom_passphrase_key_derivation_salt());
std::string decoded_salt; std::string decoded_salt;
bool result = base::Base64Decode( bool result = base::Base64Decode(
nigori.custom_passphrase_key_derivation_salt(), &decoded_salt); nigori.custom_passphrase_key_derivation_salt(), &decoded_salt);
...@@ -239,7 +238,6 @@ KeyDerivationParams GetKeyDerivationParamsFromNigori( ...@@ -239,7 +238,6 @@ KeyDerivationParams GetKeyDerivationParamsFromNigori(
case KeyDerivationMethod::PBKDF2_HMAC_SHA1_1003: case KeyDerivationMethod::PBKDF2_HMAC_SHA1_1003:
return KeyDerivationParams::CreateForPbkdf2(); return KeyDerivationParams::CreateForPbkdf2();
case KeyDerivationMethod::SCRYPT_8192_8_11: case KeyDerivationMethod::SCRYPT_8192_8_11:
DCHECK(nigori.has_custom_passphrase_key_derivation_salt());
return KeyDerivationParams::CreateForScrypt( return KeyDerivationParams::CreateForScrypt(
GetScryptSaltFromNigori(nigori)); GetScryptSaltFromNigori(nigori));
case KeyDerivationMethod::UNSUPPORTED: case KeyDerivationMethod::UNSUPPORTED:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment