Commit 71d9b4ad authored by melandory's avatar melandory Committed by Commit bot

Supplimentary identifier for passwords specific.

Adds new message field to the Password Scpecific proto and implements clearing of the data in case custom passphrase is turned on.
The population of the metadata is not implemented in this CL.

BUG=638963

Review-Url: https://codereview.chromium.org/2278333002
Cr-Commit-Position: refs/heads/master@{#415699}
parent b2f3c132
...@@ -221,6 +221,10 @@ int GetTotalNodeCount(UserShare* share, int64_t root) { ...@@ -221,6 +221,10 @@ int GetTotalNodeCount(UserShare* share, int64_t root) {
return node.GetTotalNodeCount(); return node.GetTotalNodeCount();
} }
const char kUrl[] = "example.com";
const char kPasswordValue[] = "secret";
const char kClientTag[] = "tag";
} // namespace } // namespace
class SyncApiTest : public testing::Test { class SyncApiTest : public testing::Test {
...@@ -517,10 +521,10 @@ TEST_F(SyncApiTest, WriteAndReadPassword) { ...@@ -517,10 +521,10 @@ TEST_F(SyncApiTest, WriteAndReadPassword) {
WriteNode password_node(&trans); WriteNode password_node(&trans);
WriteNode::InitUniqueByCreationResult result = WriteNode::InitUniqueByCreationResult result =
password_node.InitUniqueByCreation(PASSWORDS, root_node, "foo"); password_node.InitUniqueByCreation(PASSWORDS, root_node, kClientTag);
EXPECT_EQ(WriteNode::INIT_SUCCESS, result); EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
sync_pb::PasswordSpecificsData data; sync_pb::PasswordSpecificsData data;
data.set_password_value("secret"); data.set_password_value(kPasswordValue);
password_node.SetPasswordSpecifics(data); password_node.SetPasswordSpecifics(data);
} }
{ {
...@@ -528,10 +532,14 @@ TEST_F(SyncApiTest, WriteAndReadPassword) { ...@@ -528,10 +532,14 @@ TEST_F(SyncApiTest, WriteAndReadPassword) {
ReadNode password_node(&trans); ReadNode password_node(&trans);
EXPECT_EQ(BaseNode::INIT_OK, EXPECT_EQ(BaseNode::INIT_OK,
password_node.InitByClientTagLookup(PASSWORDS, "foo")); password_node.InitByClientTagLookup(PASSWORDS, kClientTag));
const sync_pb::PasswordSpecificsData& data = const sync_pb::PasswordSpecificsData& data =
password_node.GetPasswordSpecifics(); password_node.GetPasswordSpecifics();
EXPECT_EQ("secret", data.password_value()); EXPECT_EQ(kPasswordValue, data.password_value());
// Check that nothing has appeared in the unencrypted field.
EXPECT_FALSE(password_node.GetEntitySpecifics()
.password()
.has_unencrypted_metadata());
} }
} }
...@@ -2043,24 +2051,27 @@ TEST_F(SyncManagerTest, UpdatePasswordSetPasswordSpecifics) { ...@@ -2043,24 +2051,27 @@ TEST_F(SyncManagerTest, UpdatePasswordSetPasswordSpecifics) {
} }
// Passwords have their own handling for encryption. Verify setting a new // Passwords have their own handling for encryption. Verify setting a new
// passphrase updates the data. // passphrase updates the data and clears the unencrypted metadta for passwords.
TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) {
std::string client_tag = "title";
EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
sync_pb::EntitySpecifics entity_specifics; sync_pb::EntitySpecifics entity_specifics;
{ {
ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
Cryptographer* cryptographer = trans.GetCryptographer(); Cryptographer* cryptographer = trans.GetCryptographer();
sync_pb::PasswordSpecificsData data; sync_pb::PasswordSpecificsData data;
data.set_password_value("secret"); data.set_password_value(kPasswordValue);
entity_specifics.mutable_password()
->mutable_unencrypted_metadata()
->set_url(kUrl);
cryptographer->Encrypt( cryptographer->Encrypt(
data, entity_specifics.mutable_password()->mutable_encrypted()); data, entity_specifics.mutable_password()->mutable_encrypted());
} }
MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, EXPECT_TRUE(entity_specifics.password().has_unencrypted_metadata());
syncable::GenerateSyncableHash(PASSWORDS, client_tag), MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, kClientTag,
syncable::GenerateSyncableHash(PASSWORDS, kClientTag),
entity_specifics); entity_specifics);
// New node shouldn't start off unsynced. // New node shouldn't start off unsynced.
EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, kClientTag));
// Set a new passphrase. Should set is_unsynced. // Set a new passphrase. Should set is_unsynced.
testing::Mock::VerifyAndClearExpectations(&encryption_observer_); testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
...@@ -2068,7 +2079,21 @@ TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { ...@@ -2068,7 +2079,21 @@ TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) {
OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
ExpectPassphraseAcceptance(); ExpectPassphraseAcceptance();
SetCustomPassphraseAndCheck("new_passphrase"); SetCustomPassphraseAndCheck("new_passphrase");
EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag)); {
ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
Cryptographer* cryptographer = trans.GetCryptographer();
EXPECT_TRUE(cryptographer->is_ready());
ReadNode password_node(&trans);
EXPECT_EQ(BaseNode::INIT_OK,
password_node.InitByClientTagLookup(PASSWORDS, kClientTag));
const sync_pb::PasswordSpecificsData& data =
password_node.GetPasswordSpecifics();
EXPECT_EQ(kPasswordValue, data.password_value());
EXPECT_FALSE(password_node.GetEntitySpecifics()
.password()
.has_unencrypted_metadata());
}
EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, kClientTag));
} }
// Passwords have their own handling for encryption. Verify it does not result // Passwords have their own handling for encryption. Verify it does not result
......
...@@ -110,6 +110,11 @@ message PasswordSpecificsData { ...@@ -110,6 +110,11 @@ message PasswordSpecificsData {
optional string federation_url = 17; optional string federation_url = 17;
} }
// Contains the password specifics metadata which simplifies its lookup.
message PasswordSpecificsMetadata {
optional string url = 1;
};
// Properties of password sync objects. // Properties of password sync objects.
message PasswordSpecifics { message PasswordSpecifics {
// The actual password data. Contains an encrypted PasswordSpecificsData // The actual password data. Contains an encrypted PasswordSpecificsData
...@@ -118,4 +123,8 @@ message PasswordSpecifics { ...@@ -118,4 +123,8 @@ message PasswordSpecifics {
// An unsynced field for use internally on the client. This field should // An unsynced field for use internally on the client. This field should
// never be set in any network-based communications. // never be set in any network-based communications.
optional PasswordSpecificsData client_only_encrypted_data = 2; optional PasswordSpecificsData client_only_encrypted_data = 2;
// Password related metadata, which is sent to the server side. The field
// should never be set for full encryption users. If encryption is enabled,
// this field must be cleared.
optional PasswordSpecificsMetadata unencrypted_metadata = 3;
} }
...@@ -136,6 +136,13 @@ std::unique_ptr<base::DictionaryValue> EncryptedDataToValue( ...@@ -136,6 +136,13 @@ std::unique_ptr<base::DictionaryValue> EncryptedDataToValue(
return value; return value;
} }
std::unique_ptr<base::DictionaryValue> PasswordSpecificsMetadataToValue(
const sync_pb::PasswordSpecificsMetadata& proto) {
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
SET_STR(url);
return value;
}
std::unique_ptr<base::DictionaryValue> AppSettingsToValue( std::unique_ptr<base::DictionaryValue> AppSettingsToValue(
const sync_pb::AppNotificationSettings& proto) { const sync_pb::AppNotificationSettings& proto) {
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
...@@ -607,6 +614,7 @@ std::unique_ptr<base::DictionaryValue> PasswordSpecificsToValue( ...@@ -607,6 +614,7 @@ std::unique_ptr<base::DictionaryValue> PasswordSpecificsToValue(
const sync_pb::PasswordSpecifics& proto) { const sync_pb::PasswordSpecifics& proto) {
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
SET(encrypted, EncryptedDataToValue); SET(encrypted, EncryptedDataToValue);
SET(unencrypted_metadata, PasswordSpecificsMetadataToValue);
return value; return value;
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "components/sync/base/cryptographer.h" #include "components/sync/base/cryptographer.h"
#include "components/sync/base/passphrase_type.h"
#include "components/sync/syncable/directory.h" #include "components/sync/syncable/directory.h"
#include "components/sync/syncable/entry.h" #include "components/sync/syncable/entry.h"
#include "components/sync/syncable/mutable_entry.h" #include "components/sync/syncable/mutable_entry.h"
...@@ -225,6 +226,14 @@ bool UpdateEntryWithEncryption(BaseTransaction* const trans, ...@@ -225,6 +226,14 @@ bool UpdateEntryWithEncryption(BaseTransaction* const trans,
bookmark_specifics->set_title(kEncryptedString); bookmark_specifics->set_title(kEncryptedString);
} }
} }
if (type == PASSWORDS &&
IsExplicitPassphrase(nigori_handler->GetPassphraseType(trans))) {
sync_pb::PasswordSpecifics* password_specifics =
generated_specifics.mutable_password();
password_specifics->clear_unencrypted_metadata();
}
entry->PutSpecifics(generated_specifics); entry->PutSpecifics(generated_specifics);
DVLOG(1) << "Overwriting specifics of type " << ModelTypeToString(type) DVLOG(1) << "Overwriting specifics of type " << ModelTypeToString(type)
<< " and marking for syncing."; << " and marking for syncing.";
......
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