diff options
author | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-31 19:44:25 +0000 |
---|---|---|
committer | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-31 19:44:25 +0000 |
commit | 310512cc361ab20d11a236095664fafae2250fac (patch) | |
tree | ce779afc56fb845f043ea7f54e905c7ff4d8d697 /sync/util | |
parent | 126f1d652abfd11204fb7b4aed48dcb9999903d9 (diff) | |
download | chromium_src-310512cc361ab20d11a236095664fafae2250fac.zip chromium_src-310512cc361ab20d11a236095664fafae2250fac.tar.gz chromium_src-310512cc361ab20d11a236095664fafae2250fac.tar.bz2 |
[Sync] Add support for performing a GetKey on startup.
The functionality is behind the --sync-keystore-encryption flag, and the key
is not currently consumed by anything, but this lays the groundwork for testing
the server and client interaction.
We request a key anytime we perform a GetUpdates while the cryptographer
does not have a keystore key. But, it is considered an error to request a key
and not receive one, putting us into a state of backoff.
BUG=129665
TEST=sync_unit_tests, running against python server
Review URL: https://chromiumcodereview.appspot.com/10455012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149248 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/util')
-rw-r--r-- | sync/util/cryptographer.cc | 21 | ||||
-rw-r--r-- | sync/util/cryptographer.h | 10 | ||||
-rw-r--r-- | sync/util/get_session_name.cc | 2 |
3 files changed, 32 insertions, 1 deletions
diff --git a/sync/util/cryptographer.cc b/sync/util/cryptographer.cc index 2c0d794..d63166b 100644 --- a/sync/util/cryptographer.cc +++ b/sync/util/cryptographer.cc @@ -25,6 +25,7 @@ Cryptographer::Observer::~Observer() {} Cryptographer::Cryptographer(Encryptor* encryptor) : encryptor_(encryptor), default_nigori_(NULL), + keystore_nigori_(NULL), encrypted_types_(SensitiveTypes()), encrypt_everything_(false) { DCHECK(encryptor); @@ -308,6 +309,26 @@ Cryptographer::UpdateResult Cryptographer::Update( return Cryptographer::SUCCESS; } +bool Cryptographer::SetKeystoreKey(const std::string& keystore_key) { + if (keystore_key.empty()) + return false; + KeyParams params = {"localhost", "dummy", keystore_key}; + + // AddKey updates the default nigori, so we save the current default and + // make sure the keystore_nigori_ gets updated instead. + NigoriMap::value_type* old_default = default_nigori_; + if (AddKey(params)) { + keystore_nigori_ = default_nigori_; + default_nigori_ = old_default; + return true; + } + return false; +} + +bool Cryptographer::HasKeystoreKey() { + return keystore_nigori_ != NULL; +} + // Static ModelTypeSet Cryptographer::SensitiveTypes() { // Both of these have their own encryption schemes, but we include them diff --git a/sync/util/cryptographer.h b/sync/util/cryptographer.h index f02875a..d664020 100644 --- a/sync/util/cryptographer.h +++ b/sync/util/cryptographer.h @@ -179,6 +179,15 @@ class Cryptographer { // stored in the |pending_keys_|. UpdateResult Update(const sync_pb::NigoriSpecifics& nigori); + // Set the keystore-derived nigori from the provided key. + // Returns true if we succesfully create the keystore derived nigori from the + // provided key, false otherwise. + bool SetKeystoreKey(const std::string& keystore_key); + + // Returns true if we currently have a keystore-derived nigori, false + // otherwise. + bool HasKeystoreKey(); + // The set of types that are always encrypted. static ModelTypeSet SensitiveTypes(); @@ -237,6 +246,7 @@ class Cryptographer { NigoriMap nigoris_; // The Nigoris we know about, mapped by key name. NigoriMap::value_type* default_nigori_; // The Nigori used for encryption. + NigoriMap::value_type* keystore_nigori_; // Nigori generated from keystore. scoped_ptr<sync_pb::EncryptedData> pending_keys_; diff --git a/sync/util/get_session_name.cc b/sync/util/get_session_name.cc index 99a4ce0..8c86c5c 100644 --- a/sync/util/get_session_name.cc +++ b/sync/util/get_session_name.cc @@ -43,7 +43,7 @@ std::string GetSessionNameSynchronously() { #elif defined(OS_LINUX) session_name = base::GetLinuxDistro(); #elif defined(OS_MACOSX) - session_name = internal::GetHardwareModelName(); +// session_name = internal::GetHardwareModelName(); #elif defined(OS_WIN) session_name = internal::GetComputerName(); #elif defined(OS_ANDROID) |