diff options
Diffstat (limited to 'components/sync_driver')
-rw-r--r-- | components/sync_driver/DEPS | 1 | ||||
-rw-r--r-- | components/sync_driver/system_encryptor.cc | 23 | ||||
-rw-r--r-- | components/sync_driver/system_encryptor.h | 27 | ||||
-rw-r--r-- | components/sync_driver/system_encryptor_unittest.cc | 37 |
4 files changed, 88 insertions, 0 deletions
diff --git a/components/sync_driver/DEPS b/components/sync_driver/DEPS index 067cea9..d3a3e4d 100644 --- a/components/sync_driver/DEPS +++ b/components/sync_driver/DEPS @@ -1,5 +1,6 @@ include_rules = [ # SyncDriver is used by iOS, which does not use content. "-content", + "+components/webdata/encryptor", "+sync", ] diff --git a/components/sync_driver/system_encryptor.cc b/components/sync_driver/system_encryptor.cc new file mode 100644 index 0000000..74d63fc --- /dev/null +++ b/components/sync_driver/system_encryptor.cc @@ -0,0 +1,23 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/sync_driver/system_encryptor.h" + +#include "components/webdata/encryptor/encryptor.h" + +namespace browser_sync { + +SystemEncryptor::~SystemEncryptor() {} + +bool SystemEncryptor::EncryptString(const std::string& plaintext, + std::string* ciphertext) { + return ::Encryptor::EncryptString(plaintext, ciphertext); +} + +bool SystemEncryptor::DecryptString(const std::string& ciphertext, + std::string* plaintext) { + return ::Encryptor::DecryptString(ciphertext, plaintext); +} + +} // namespace browser_sync diff --git a/components/sync_driver/system_encryptor.h b/components/sync_driver/system_encryptor.h new file mode 100644 index 0000000..5552b76 --- /dev/null +++ b/components/sync_driver/system_encryptor.h @@ -0,0 +1,27 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_SYNC_DRIVER_SYSTEM_ENCRYPTOR_H_ +#define COMPONENTS_SYNC_DRIVER_SYSTEM_ENCRYPTOR_H_ + +#include "base/compiler_specific.h" +#include "sync/util/encryptor.h" + +namespace browser_sync { + +// Encryptor that uses the Chrome password manager's encryptor. +class SystemEncryptor : public syncer::Encryptor { + public: + virtual ~SystemEncryptor(); + + virtual bool EncryptString(const std::string& plaintext, + std::string* ciphertext) OVERRIDE; + + virtual bool DecryptString(const std::string& ciphertext, + std::string* plaintext) OVERRIDE; +}; + +} // namespace browser_sync + +#endif // COMPONENTS_SYNC_DRIVER_SYSTEM_ENCRYPTOR_H_ diff --git a/components/sync_driver/system_encryptor_unittest.cc b/components/sync_driver/system_encryptor_unittest.cc new file mode 100644 index 0000000..a172afa --- /dev/null +++ b/components/sync_driver/system_encryptor_unittest.cc @@ -0,0 +1,37 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/sync_driver/system_encryptor.h" + +#include "components/webdata/encryptor/encryptor.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace browser_sync { + +namespace { + +const char kPlaintext[] = "The Magic Words are Squeamish Ossifrage"; + +class SystemEncryptorTest : public testing::Test { + protected: + SystemEncryptor encryptor_; +}; + +TEST_F(SystemEncryptorTest, EncryptDecrypt) { +#if defined(OS_MACOSX) + // SystemEncryptor ends up needing access to the keychain on OS X, + // so use the mock keychain to prevent prompts. + ::Encryptor::UseMockKeychain(true); +#endif + std::string ciphertext; + EXPECT_TRUE(encryptor_.EncryptString(kPlaintext, &ciphertext)); + EXPECT_NE(kPlaintext, ciphertext); + std::string plaintext; + EXPECT_TRUE(encryptor_.DecryptString(ciphertext, &plaintext)); + EXPECT_EQ(kPlaintext, plaintext); +} + +} // namespace + +} // namespace browser_sync |