summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-28 18:34:10 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-28 18:34:10 +0000
commit92cdb1cac7927203a40feec6224b327a21ad8d42 (patch)
treefb2befac0bb0a63db4647824fca747a8e02a151e /components
parentc73236512b5285e65eeda627f94ddce51fcda16f (diff)
downloadchromium_src-92cdb1cac7927203a40feec6224b327a21ad8d42.zip
chromium_src-92cdb1cac7927203a40feec6224b327a21ad8d42.tar.gz
chromium_src-92cdb1cac7927203a40feec6224b327a21ad8d42.tar.bz2
Rename components's Encryptor to OSEncrypt.
To avoid confusion with the Encryptor class that exists under crypto/. BUG=341293 TEST=None R=joi@chromium.org,bcwhite@chromium.org TBR=thestig Review URL: https://codereview.chromium.org/183953005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254177 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r--components/autofill/core/browser/autofill_ie_toolbar_import_win.cc4
-rw-r--r--components/autofill/core/browser/autofill_ie_toolbar_import_win_unittest.cc4
-rw-r--r--components/autofill/core/browser/autofill_test_utils.cc4
-rw-r--r--components/autofill/core/browser/webdata/autofill_table.cc8
-rw-r--r--components/autofill/core/browser/webdata/autofill_table_unittest.cc4
-rw-r--r--components/components_tests.gyp4
-rw-r--r--components/encryptor.gypi18
-rw-r--r--components/encryptor/encryptor.h51
-rw-r--r--components/encryptor/encryptor_switches.h2
-rw-r--r--components/encryptor/keychain_password_mac.h (renamed from components/encryptor/encryptor_password_mac.h)21
-rw-r--r--components/encryptor/keychain_password_mac.mm (renamed from components/encryptor/encryptor_password_mac.mm)4
-rw-r--r--components/encryptor/keychain_password_mac_unittest.mm (renamed from components/encryptor/encryptor_password_mac_unittest.cc)37
-rw-r--r--components/encryptor/os_crypt.h48
-rw-r--r--components/encryptor/os_crypt_mac.mm (renamed from components/encryptor/encryptor_mac.mm)26
-rw-r--r--components/encryptor/os_crypt_posix.cc (renamed from components/encryptor/encryptor_posix.cc)18
-rw-r--r--components/encryptor/os_crypt_unittest.cc (renamed from components/encryptor/encryptor_unittest.cc)75
-rw-r--r--components/encryptor/os_crypt_win.cc (renamed from components/encryptor/encryptor_win.cc)19
-rw-r--r--components/password_manager/core/browser/login_database_win.cc9
-rw-r--r--components/signin/core/webdata/token_service_table.cc6
-rw-r--r--components/sync_driver/system_encryptor.cc6
-rw-r--r--components/sync_driver/system_encryptor_unittest.cc4
21 files changed, 187 insertions, 185 deletions
diff --git a/components/autofill/core/browser/autofill_ie_toolbar_import_win.cc b/components/autofill/core/browser/autofill_ie_toolbar_import_win.cc
index 682f1917..f39fc4d 100644
--- a/components/autofill/core/browser/autofill_ie_toolbar_import_win.cc
+++ b/components/autofill/core/browser/autofill_ie_toolbar_import_win.cc
@@ -24,7 +24,7 @@
#include "components/autofill/core/browser/personal_data_manager_observer.h"
#include "components/autofill/core/browser/phone_number.h"
#include "components/autofill/core/browser/phone_number_i18n.h"
-#include "components/encryptor/encryptor.h"
+#include "components/encryptor/os_crypt.h"
using base::win::RegKey;
@@ -86,7 +86,7 @@ base::string16 ReadAndDecryptValue(const RegKey& key,
result = key.ReadValue(value_name, &(data[0]), &data_size, &data_type);
if (result == ERROR_SUCCESS) {
std::string out_data;
- if (Encryptor::DecryptString(data, &out_data)) {
+ if (OSCrypt::DecryptString(data, &out_data)) {
// The actual data is in UTF16 already.
if (!(out_data.size() & 1) && (out_data.size() > 2) &&
!out_data[out_data.size() - 1] && !out_data[out_data.size() - 2]) {
diff --git a/components/autofill/core/browser/autofill_ie_toolbar_import_win_unittest.cc b/components/autofill/core/browser/autofill_ie_toolbar_import_win_unittest.cc
index 24108ec..4e5c833 100644
--- a/components/autofill/core/browser/autofill_ie_toolbar_import_win_unittest.cc
+++ b/components/autofill/core/browser/autofill_ie_toolbar_import_win_unittest.cc
@@ -10,7 +10,7 @@
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/field_types.h"
-#include "components/encryptor/encryptor.h"
+#include "components/encryptor/os_crypt.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::win::RegKey;
@@ -92,7 +92,7 @@ void EncryptAndWrite(RegKey* key, const ValueDescription* value) {
memcpy(&data[0], value->value, data_size);
std::string encrypted_data;
- Encryptor::EncryptString(data, &encrypted_data);
+ OSCrypt::EncryptString(data, &encrypted_data);
EXPECT_EQ(ERROR_SUCCESS, key->WriteValue(value->value_name,
&encrypted_data[0], encrypted_data.size(), REG_BINARY));
}
diff --git a/components/autofill/core/browser/autofill_test_utils.cc b/components/autofill/core/browser/autofill_test_utils.cc
index a46ed28..c163875 100644
--- a/components/autofill/core/browser/autofill_test_utils.cc
+++ b/components/autofill/core/browser/autofill_test_utils.cc
@@ -16,7 +16,7 @@
#include "components/autofill/core/common/autofill_pref_names.h"
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/form_field_data.h"
-#include "components/encryptor/encryptor.h"
+#include "components/encryptor/os_crypt.h"
#include "components/user_prefs/pref_registry_syncable.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
@@ -207,7 +207,7 @@ void SetCreditCardInfo(CreditCard* credit_card,
void DisableSystemServices(content::BrowserContext* browser_context) {
// Use a mock Keychain rather than the OS one to store credit card data.
#if defined(OS_MACOSX)
- Encryptor::UseMockKeychain(true);
+ OSCrypt::UseMockKeychain(true);
#endif
// Disable auxiliary profiles for unit testing. These reach out to system
diff --git a/components/autofill/core/browser/webdata/autofill_table.cc b/components/autofill/core/browser/webdata/autofill_table.cc
index 039942f..c4656ad 100644
--- a/components/autofill/core/browser/webdata/autofill_table.cc
+++ b/components/autofill/core/browser/webdata/autofill_table.cc
@@ -26,7 +26,7 @@
#include "components/autofill/core/browser/webdata/autofill_change.h"
#include "components/autofill/core/browser/webdata/autofill_entry.h"
#include "components/autofill/core/common/form_field_data.h"
-#include "components/encryptor/encryptor.h"
+#include "components/encryptor/os_crypt.h"
#include "components/webdata/common/web_database.h"
#include "sql/statement.h"
#include "sql/transaction.h"
@@ -109,8 +109,8 @@ void BindCreditCardToStatement(const CreditCard& credit_card,
s->BindString16(index++, GetInfo(credit_card, CREDIT_CARD_EXP_4_DIGIT_YEAR));
std::string encrypted_data;
- Encryptor::EncryptString16(credit_card.GetRawInfo(CREDIT_CARD_NUMBER),
- &encrypted_data);
+ OSCrypt::EncryptString16(credit_card.GetRawInfo(CREDIT_CARD_NUMBER),
+ &encrypted_data);
s->BindBlob(index++, encrypted_data.data(),
static_cast<int>(encrypted_data.length()));
@@ -135,7 +135,7 @@ scoped_ptr<CreditCard> CreditCardFromStatement(const sql::Statement& s) {
std::string encrypted_number;
encrypted_number.resize(encrypted_number_len);
memcpy(&encrypted_number[0], s.ColumnBlob(index++), encrypted_number_len);
- Encryptor::DecryptString16(encrypted_number, &credit_card_number);
+ OSCrypt::DecryptString16(encrypted_number, &credit_card_number);
} else {
index++;
}
diff --git a/components/autofill/core/browser/webdata/autofill_table_unittest.cc b/components/autofill/core/browser/webdata/autofill_table_unittest.cc
index 649eec3..474af46 100644
--- a/components/autofill/core/browser/webdata/autofill_table_unittest.cc
+++ b/components/autofill/core/browser/webdata/autofill_table_unittest.cc
@@ -19,7 +19,7 @@
#include "components/autofill/core/browser/webdata/autofill_entry.h"
#include "components/autofill/core/browser/webdata/autofill_table.h"
#include "components/autofill/core/common/form_field_data.h"
-#include "components/encryptor/encryptor.h"
+#include "components/encryptor/os_crypt.h"
#include "components/webdata/common/web_database.h"
#include "sql/statement.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -118,7 +118,7 @@ class AutofillTableTest : public testing::Test {
protected:
virtual void SetUp() {
#if defined(OS_MACOSX)
- Encryptor::UseMockKeychain(true);
+ OSCrypt::UseMockKeychain(true);
#endif
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
file_ = temp_dir_.path().AppendASCII("TestWebDatabase");
diff --git a/components/components_tests.gyp b/components/components_tests.gyp
index ea83ae6..c47e05e 100644
--- a/components/components_tests.gyp
+++ b/components/components_tests.gyp
@@ -86,9 +86,9 @@
'variations/variations_seed_processor_unittest.cc',
'variations/variations_seed_simulator_unittest.cc',
'visitedlink/test/visitedlink_unittest.cc',
- 'encryptor/encryptor_password_mac_unittest.cc',
- 'encryptor/encryptor_unittest.cc',
+ 'encryptor/keychain_password_mac_unittest.mm',
'encryptor/ie7_password_unittest_win.cc',
+ 'encryptor/os_crypt_unittest.cc',
'web_modal/web_contents_modal_dialog_manager_unittest.cc',
],
'include_dirs': [
diff --git a/components/encryptor.gypi b/components/encryptor.gypi
index 3ddc7a1..f534a85 100644
--- a/components/encryptor.gypi
+++ b/components/encryptor.gypi
@@ -15,29 +15,29 @@
'../crypto/crypto.gyp:crypto',
],
'sources': [
- 'encryptor/encryptor.h',
- 'encryptor/encryptor_mac.mm',
- 'encryptor/encryptor_password_mac.h',
- 'encryptor/encryptor_password_mac.mm',
- 'encryptor/encryptor_posix.cc',
'encryptor/encryptor_switches.cc',
'encryptor/encryptor_switches.h',
- 'encryptor/encryptor_win.cc',
'encryptor/ie7_password_win.cc',
'encryptor/ie7_password_win.h',
+ 'encryptor/keychain_password_mac.h',
+ 'encryptor/keychain_password_mac.mm',
+ 'encryptor/os_crypt.h',
+ 'encryptor/os_crypt_mac.mm',
+ 'encryptor/os_crypt_posix.cc',
+ 'encryptor/os_crypt_win.cc',
],
'conditions': [
['OS=="mac"', {
'sources!': [
- 'encryptor/encryptor_posix.cc',
+ 'encryptor/os_crypt_posix.cc',
],
}],
],
'target_conditions': [
['OS=="ios"', {
'sources/': [
- ['include', '^encryptor/encryptor_mac\\.mm$'],
- ['include', '^encryptor/encryptor_password_mac\\.mm$'],
+ ['include', '^encryptor/keychain_password_mac\\.mm$'],
+ ['include', '^encryptor/os_crypt_mac\\.mm$'],
],
}],
],
diff --git a/components/encryptor/encryptor.h b/components/encryptor/encryptor.h
deleted file mode 100644
index 48bb2e5..0000000
--- a/components/encryptor/encryptor.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// 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_ENCRYPTOR_ENCRYPTOR_H_
-#define COMPONENTS_ENCRYPTOR_ENCRYPTOR_H_
-
-#include <string>
-
-#include "base/strings/string16.h"
-
-// The Encryptor class gives access to simple encryption and decryption of
-// strings. Note that on Mac, access to the system Keychain is required and
-// these calls can block the current thread to collect user input.
-class Encryptor {
- public:
- // Encrypt a string16. The output (second argument) is
- // really an array of bytes, but we're passing it back
- // as a std::string
- static bool EncryptString16(const base::string16& plaintext,
- std::string* ciphertext);
-
- // Decrypt an array of bytes obtained with EncryptString16
- // back into a string16. Note that the input (first argument)
- // is a std::string, so you need to first get your (binary)
- // data into a string.
- static bool DecryptString16(const std::string& ciphertext,
- base::string16* plaintext);
-
- // Encrypt a string.
- static bool EncryptString(const std::string& plaintext,
- std::string* ciphertext);
-
- // Decrypt an array of bytes obtained with EnctryptString
- // back into a string. Note that the input (first argument)
- // is a std::string, so you need to first get your (binary)
- // data into a string.
- static bool DecryptString(const std::string& ciphertext,
- std::string* plaintext);
-
-#if defined(OS_MACOSX)
- // For unit testing purposes we instruct the Encryptor to use a mock Keychain
- // on the Mac. The default is to use the real Keychain.
- static void UseMockKeychain(bool use_mock);
-#endif
-
- private:
- DISALLOW_IMPLICIT_CONSTRUCTORS(Encryptor);
-};
-
-#endif // COMPONENTS_ENCRYPTOR_ENCRYPTOR_H_
diff --git a/components/encryptor/encryptor_switches.h b/components/encryptor/encryptor_switches.h
index 5f25e14..4df069a 100644
--- a/components/encryptor/encryptor_switches.h
+++ b/components/encryptor/encryptor_switches.h
@@ -7,7 +7,7 @@
#ifndef COMPONENTS_ENCRYPTOR__ENCRYPTOR_SWITCHES_H_
#define COMPONENTS_ENCRYPTOR__ENCRYPTOR_SWITCHES_H_
-#include "base/basictypes.h"
+#include "build/build_config.h"
namespace encryptor {
namespace switches {
diff --git a/components/encryptor/encryptor_password_mac.h b/components/encryptor/keychain_password_mac.h
index fc2a915..7cb8faf 100644
--- a/components/encryptor/encryptor_password_mac.h
+++ b/components/encryptor/keychain_password_mac.h
@@ -2,34 +2,35 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef COMPONENTS_ENCRYPTOR_ENCRYPTOR_PASSWORD_MAC_H_
-#define COMPONENTS_ENCRYPTOR_ENCRYPTOR_PASSWORD_MAC_H_
+#ifndef COMPONENTS_ENCRYPTOR_KEYCHAIN_PASSWORD_MAC_H_
+#define COMPONENTS_ENCRYPTOR_KEYCHAIN_PASSWORD_MAC_H_
#include <string>
-#include "base/basictypes.h"
+#include "base/macros.h"
namespace crypto {
class AppleKeychain;
-} // namespace crypto
+}
-class EncryptorPassword {
+class KeychainPassword {
public:
- explicit EncryptorPassword(const crypto::AppleKeychain& keychain)
+ explicit KeychainPassword(const crypto::AppleKeychain& keychain)
: keychain_(keychain) {
}
- // Get the Encryptor password for this system. If no password exists
+ // Get the OSCrypt password for this system. If no password exists
// in the Keychain then one is generated, stored in the Mac keychain, and
// returned.
// If one exists then it is fetched from the Keychain and returned.
// If the user disallows access to the Keychain (or an error occurs) then an
// empty string is returned.
- std::string GetEncryptorPassword() const;
+ std::string GetPassword() const;
private:
- DISALLOW_COPY_AND_ASSIGN(EncryptorPassword);
const crypto::AppleKeychain& keychain_;
+
+ DISALLOW_COPY_AND_ASSIGN(KeychainPassword);
};
-#endif // COMPONENTS_ENCRYPTOR_ENCRYPTOR_PASSWORD_MAC_H_
+#endif // COMPONENTS_ENCRYPTOR_KEYCHAIN_PASSWORD_MAC_H_
diff --git a/components/encryptor/encryptor_password_mac.mm b/components/encryptor/keychain_password_mac.mm
index 0cefdd5..7a078bf 100644
--- a/components/encryptor/encryptor_password_mac.mm
+++ b/components/encryptor/keychain_password_mac.mm
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/encryptor/encryptor_password_mac.h"
+#include "components/encryptor/keychain_password_mac.h"
#import <Security/Security.h>
@@ -47,7 +47,7 @@ std::string AddRandomPasswordToKeychain(const AppleKeychain& keychain,
} // namespace
-std::string EncryptorPassword::GetEncryptorPassword() const {
+std::string KeychainPassword::GetPassword() const {
// These two strings ARE indeed user facing. But they are used to access
// the encryption keyword. So as to not lose encrypted data when system
// locale changes we DO NOT LOCALIZE.
diff --git a/components/encryptor/encryptor_password_mac_unittest.cc b/components/encryptor/keychain_password_mac_unittest.mm
index bc95a44..efa32b4 100644
--- a/components/encryptor/encryptor_password_mac_unittest.cc
+++ b/components/encryptor/keychain_password_mac_unittest.mm
@@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/encryptor/encryptor_password_mac.h"
+#include "components/encryptor/keychain_password_mac.h"
+
#include "crypto/mock_apple_keychain.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -12,62 +13,62 @@ using crypto::MockAppleKeychain;
// Test that if we have an existing password in the Keychain and we are
// authorized by the user to read it then we get it back correctly.
-TEST(EncryptorPasswordTest, FindPasswordSuccess) {
+TEST(KeychainPasswordTest, FindPasswordSuccess) {
MockAppleKeychain keychain;
keychain.set_find_generic_result(noErr);
- EncryptorPassword password(keychain);
- EXPECT_FALSE(password.GetEncryptorPassword().empty());
+ KeychainPassword password(keychain);
+ EXPECT_FALSE(password.GetPassword().empty());
EXPECT_FALSE(keychain.called_add_generic());
EXPECT_EQ(0, keychain.password_data_count());
}
// Test that if we do not have an existing password in the Keychain then it
// gets added successfully and returned.
-TEST(EncryptorPasswordTest, FindPasswordNotFound) {
+TEST(KeychainPasswordTest, FindPasswordNotFound) {
MockAppleKeychain keychain;
keychain.set_find_generic_result(errSecItemNotFound);
- EncryptorPassword password(keychain);
- EXPECT_EQ(24U, password.GetEncryptorPassword().length());
+ KeychainPassword password(keychain);
+ EXPECT_EQ(24U, password.GetPassword().length());
EXPECT_TRUE(keychain.called_add_generic());
EXPECT_EQ(0, keychain.password_data_count());
}
// Test that if get denied access by the user then we return an empty password.
// And we should not try to add one.
-TEST(EncryptorPasswordTest, FindPasswordNotAuthorized) {
+TEST(KeychainPasswordTest, FindPasswordNotAuthorized) {
MockAppleKeychain keychain;
keychain.set_find_generic_result(errSecAuthFailed);
- EncryptorPassword password(keychain);
- EXPECT_TRUE(password.GetEncryptorPassword().empty());
+ KeychainPassword password(keychain);
+ EXPECT_TRUE(password.GetPassword().empty());
EXPECT_FALSE(keychain.called_add_generic());
EXPECT_EQ(0, keychain.password_data_count());
}
// Test that if some random other error happens then we return an empty
// password, and we should not try to add one.
-TEST(EncryptorPasswordTest, FindPasswordOtherError) {
+TEST(KeychainPasswordTest, FindPasswordOtherError) {
MockAppleKeychain keychain;
keychain.set_find_generic_result(errSecNotAvailable);
- EncryptorPassword password(keychain);
- EXPECT_TRUE(password.GetEncryptorPassword().empty());
+ KeychainPassword password(keychain);
+ EXPECT_TRUE(password.GetPassword().empty());
EXPECT_FALSE(keychain.called_add_generic());
EXPECT_EQ(0, keychain.password_data_count());
}
// Test that subsequent additions to the keychain give different passwords.
-TEST(EncryptorPasswordTest, PasswordsDiffer) {
+TEST(KeychainPasswordTest, PasswordsDiffer) {
MockAppleKeychain keychain1;
keychain1.set_find_generic_result(errSecItemNotFound);
- EncryptorPassword encryptor_password1(keychain1);
- std::string password1 = encryptor_password1.GetEncryptorPassword();
+ KeychainPassword encryptor_password1(keychain1);
+ std::string password1 = encryptor_password1.GetPassword();
EXPECT_FALSE(password1.empty());
EXPECT_TRUE(keychain1.called_add_generic());
EXPECT_EQ(0, keychain1.password_data_count());
MockAppleKeychain keychain2;
keychain2.set_find_generic_result(errSecItemNotFound);
- EncryptorPassword encryptor_password2(keychain2);
- std::string password2 = encryptor_password2.GetEncryptorPassword();
+ KeychainPassword encryptor_password2(keychain2);
+ std::string password2 = encryptor_password2.GetPassword();
EXPECT_FALSE(password2.empty());
EXPECT_TRUE(keychain2.called_add_generic());
EXPECT_EQ(0, keychain2.password_data_count());
diff --git a/components/encryptor/os_crypt.h b/components/encryptor/os_crypt.h
new file mode 100644
index 0000000..ae899aa
--- /dev/null
+++ b/components/encryptor/os_crypt.h
@@ -0,0 +1,48 @@
+// 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_ENCRYPTOR_OS_CRYPT_H_
+#define COMPONENTS_ENCRYPTOR_OS_CRYPT_H_
+
+#include <string>
+
+#include "base/strings/string16.h"
+
+// The OSCrypt class gives access to simple encryption and decryption of
+// strings. Note that on Mac, access to the system Keychain is required and
+// these calls can block the current thread to collect user input.
+class OSCrypt {
+ public:
+ // Encrypt a string16. The output (second argument) is really an array of
+ // bytes, but we're passing it back as a std::string.
+ static bool EncryptString16(const base::string16& plaintext,
+ std::string* ciphertext);
+
+ // Decrypt an array of bytes obtained with EncryptString16 back into a
+ // string16. Note that the input (first argument) is a std::string, so you
+ // need to first get your (binary) data into a string.
+ static bool DecryptString16(const std::string& ciphertext,
+ base::string16* plaintext);
+
+ // Encrypt a string.
+ static bool EncryptString(const std::string& plaintext,
+ std::string* ciphertext);
+
+ // Decrypt an array of bytes obtained with EnctryptString back into a string.
+ // Note that the input (first argument) is a std::string, so you need to first
+ // get your (binary) data into a string.
+ static bool DecryptString(const std::string& ciphertext,
+ std::string* plaintext);
+
+#if defined(OS_MACOSX)
+ // For unit testing purposes we instruct the Encryptor to use a mock Keychain
+ // on the Mac. The default is to use the real Keychain.
+ static void UseMockKeychain(bool use_mock);
+#endif
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(OSCrypt);
+};
+
+#endif // COMPONENTS_ENCRYPTOR_OS_CRYPT_H_
diff --git a/components/encryptor/encryptor_mac.mm b/components/encryptor/os_crypt_mac.mm
index 583f18a..13d6c2e 100644
--- a/components/encryptor/encryptor_mac.mm
+++ b/components/encryptor/os_crypt_mac.mm
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/encryptor/encryptor.h"
+#include "components/encryptor/os_crypt.h"
#include <CommonCrypto/CommonCryptor.h> // for kCCBlockSizeAES128
@@ -10,8 +10,8 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/utf_string_conversions.h"
-#include "components/encryptor/encryptor_password_mac.h"
#include "components/encryptor/encryptor_switches.h"
+#include "components/encryptor/keychain_password_mac.h"
#include "crypto/apple_keychain.h"
#include "crypto/encryptor.h"
#include "crypto/symmetric_key.h"
@@ -51,8 +51,8 @@ crypto::SymmetricKey* GetEncryptionKey() {
password = "mock_password";
} else {
AppleKeychain keychain;
- EncryptorPassword encryptor_password(keychain);
- password = encryptor_password.GetEncryptorPassword();
+ KeychainPassword encryptor_password(keychain);
+ password = encryptor_password.GetPassword();
}
if (password.empty())
@@ -74,13 +74,13 @@ crypto::SymmetricKey* GetEncryptionKey() {
} // namespace
-bool Encryptor::EncryptString16(const base::string16& plaintext,
- std::string* ciphertext) {
+bool OSCrypt::EncryptString16(const base::string16& plaintext,
+ std::string* ciphertext) {
return EncryptString(base::UTF16ToUTF8(plaintext), ciphertext);
}
-bool Encryptor::DecryptString16(const std::string& ciphertext,
- base::string16* plaintext) {
+bool OSCrypt::DecryptString16(const std::string& ciphertext,
+ base::string16* plaintext) {
std::string utf8;
if (!DecryptString(ciphertext, &utf8))
return false;
@@ -89,8 +89,8 @@ bool Encryptor::DecryptString16(const std::string& ciphertext,
return true;
}
-bool Encryptor::EncryptString(const std::string& plaintext,
- std::string* ciphertext) {
+bool OSCrypt::EncryptString(const std::string& plaintext,
+ std::string* ciphertext) {
if (plaintext.empty()) {
*ciphertext = std::string();
return true;
@@ -113,8 +113,8 @@ bool Encryptor::EncryptString(const std::string& plaintext,
return true;
}
-bool Encryptor::DecryptString(const std::string& ciphertext,
- std::string* plaintext) {
+bool OSCrypt::DecryptString(const std::string& ciphertext,
+ std::string* plaintext) {
if (ciphertext.empty()) {
*plaintext = std::string();
return true;
@@ -149,7 +149,7 @@ bool Encryptor::DecryptString(const std::string& ciphertext,
return true;
}
-void Encryptor::UseMockKeychain(bool use_mock) {
+void OSCrypt::UseMockKeychain(bool use_mock) {
use_mock_keychain = use_mock;
}
diff --git a/components/encryptor/encryptor_posix.cc b/components/encryptor/os_crypt_posix.cc
index 1bcfe3d..3dc6758 100644
--- a/components/encryptor/encryptor_posix.cc
+++ b/components/encryptor/os_crypt_posix.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/encryptor/encryptor.h"
+#include "components/encryptor/os_crypt.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
@@ -54,13 +54,13 @@ crypto::SymmetricKey* GetEncryptionKey() {
} // namespace
-bool Encryptor::EncryptString16(const base::string16& plaintext,
- std::string* ciphertext) {
+bool OSCrypt::EncryptString16(const base::string16& plaintext,
+ std::string* ciphertext) {
return EncryptString(base::UTF16ToUTF8(plaintext), ciphertext);
}
-bool Encryptor::DecryptString16(const std::string& ciphertext,
- base::string16* plaintext) {
+bool OSCrypt::DecryptString16(const std::string& ciphertext,
+ base::string16* plaintext) {
std::string utf8;
if (!DecryptString(ciphertext, &utf8))
return false;
@@ -69,8 +69,8 @@ bool Encryptor::DecryptString16(const std::string& ciphertext,
return true;
}
-bool Encryptor::EncryptString(const std::string& plaintext,
- std::string* ciphertext) {
+bool OSCrypt::EncryptString(const std::string& plaintext,
+ std::string* ciphertext) {
// This currently "obfuscates" by encrypting with hard-coded password.
// We need to improve this password situation by moving a secure password
// into a system-level key store.
@@ -98,8 +98,8 @@ bool Encryptor::EncryptString(const std::string& plaintext,
return true;
}
-bool Encryptor::DecryptString(const std::string& ciphertext,
- std::string* plaintext) {
+bool OSCrypt::DecryptString(const std::string& ciphertext,
+ std::string* plaintext) {
// This currently "obfuscates" by encrypting with hard-coded password.
// We need to improve this password situation by moving a secure password
// into a system-level key store.
diff --git a/components/encryptor/encryptor_unittest.cc b/components/encryptor/os_crypt_unittest.cc
index 2e90b1e..fcc4d22 100644
--- a/components/encryptor/encryptor_unittest.cc
+++ b/components/encryptor/os_crypt_unittest.cc
@@ -2,31 +2,32 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/encryptor/encryptor.h"
+#include "components/encryptor/os_crypt.h"
#include <string>
+#include "base/compiler_specific.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
-class EncryptorTest : public testing::Test {
+class OSCryptTest : public testing::Test {
public:
- EncryptorTest() {}
+ OSCryptTest() {}
- virtual void SetUp() {
+ virtual void SetUp() OVERRIDE {
#if defined(OS_MACOSX)
- Encryptor::UseMockKeychain(true);
+ OSCrypt::UseMockKeychain(true);
#endif
}
private:
- DISALLOW_COPY_AND_ASSIGN(EncryptorTest);
+ DISALLOW_COPY_AND_ASSIGN(OSCryptTest);
};
-TEST_F(EncryptorTest, String16EncryptionDecryption) {
+TEST_F(OSCryptTest, String16EncryptionDecryption) {
base::string16 plaintext;
base::string16 result;
std::string utf8_plaintext;
@@ -34,21 +35,21 @@ TEST_F(EncryptorTest, String16EncryptionDecryption) {
std::string ciphertext;
// Test borderline cases (empty strings).
- EXPECT_TRUE(Encryptor::EncryptString16(plaintext, &ciphertext));
- EXPECT_TRUE(Encryptor::DecryptString16(ciphertext, &result));
+ EXPECT_TRUE(OSCrypt::EncryptString16(plaintext, &ciphertext));
+ EXPECT_TRUE(OSCrypt::DecryptString16(ciphertext, &result));
EXPECT_EQ(plaintext, result);
// Test a simple string.
plaintext = base::ASCIIToUTF16("hello");
- EXPECT_TRUE(Encryptor::EncryptString16(plaintext, &ciphertext));
- EXPECT_TRUE(Encryptor::DecryptString16(ciphertext, &result));
+ EXPECT_TRUE(OSCrypt::EncryptString16(plaintext, &ciphertext));
+ EXPECT_TRUE(OSCrypt::DecryptString16(ciphertext, &result));
EXPECT_EQ(plaintext, result);
// Test a 16-byte aligned string. This previously hit a boundary error in
- // base::Encryptor::Crypt() on Mac.
+ // base::OSCrypt::Crypt() on Mac.
plaintext = base::ASCIIToUTF16("1234567890123456");
- EXPECT_TRUE(Encryptor::EncryptString16(plaintext, &ciphertext));
- EXPECT_TRUE(Encryptor::DecryptString16(ciphertext, &result));
+ EXPECT_TRUE(OSCrypt::EncryptString16(plaintext, &ciphertext));
+ EXPECT_TRUE(OSCrypt::DecryptString16(ciphertext, &result));
EXPECT_EQ(plaintext, result);
// Test Unicode.
@@ -61,81 +62,81 @@ TEST_F(EncryptorTest, String16EncryptionDecryption) {
plaintext = wchars;
utf8_plaintext = base::UTF16ToUTF8(plaintext);
EXPECT_EQ(plaintext, base::UTF8ToUTF16(utf8_plaintext));
- EXPECT_TRUE(Encryptor::EncryptString16(plaintext, &ciphertext));
- EXPECT_TRUE(Encryptor::DecryptString16(ciphertext, &result));
+ EXPECT_TRUE(OSCrypt::EncryptString16(plaintext, &ciphertext));
+ EXPECT_TRUE(OSCrypt::DecryptString16(ciphertext, &result));
EXPECT_EQ(plaintext, result);
- EXPECT_TRUE(Encryptor::DecryptString(ciphertext, &utf8_result));
+ EXPECT_TRUE(OSCrypt::DecryptString(ciphertext, &utf8_result));
EXPECT_EQ(utf8_plaintext, base::UTF16ToUTF8(result));
- EXPECT_TRUE(Encryptor::EncryptString(utf8_plaintext, &ciphertext));
- EXPECT_TRUE(Encryptor::DecryptString16(ciphertext, &result));
+ EXPECT_TRUE(OSCrypt::EncryptString(utf8_plaintext, &ciphertext));
+ EXPECT_TRUE(OSCrypt::DecryptString16(ciphertext, &result));
EXPECT_EQ(plaintext, result);
- EXPECT_TRUE(Encryptor::DecryptString(ciphertext, &utf8_result));
+ EXPECT_TRUE(OSCrypt::DecryptString(ciphertext, &utf8_result));
EXPECT_EQ(utf8_plaintext, base::UTF16ToUTF8(result));
}
-TEST_F(EncryptorTest, EncryptionDecryption) {
+TEST_F(OSCryptTest, EncryptionDecryption) {
std::string plaintext;
std::string result;
std::string ciphertext;
// Test borderline cases (empty strings).
- ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext));
- ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result));
+ ASSERT_TRUE(OSCrypt::EncryptString(plaintext, &ciphertext));
+ ASSERT_TRUE(OSCrypt::DecryptString(ciphertext, &result));
EXPECT_EQ(plaintext, result);
// Test a simple string.
plaintext = "hello";
- ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext));
- ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result));
+ ASSERT_TRUE(OSCrypt::EncryptString(plaintext, &ciphertext));
+ ASSERT_TRUE(OSCrypt::DecryptString(ciphertext, &result));
EXPECT_EQ(plaintext, result);
// Make sure it null terminates.
plaintext.assign("hello", 3);
- ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext));
- ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result));
+ ASSERT_TRUE(OSCrypt::EncryptString(plaintext, &ciphertext));
+ ASSERT_TRUE(OSCrypt::DecryptString(ciphertext, &result));
EXPECT_EQ(plaintext, "hel");
}
-TEST_F(EncryptorTest, CypherTextDiffers) {
+TEST_F(OSCryptTest, CypherTextDiffers) {
std::string plaintext;
std::string result;
std::string ciphertext;
// Test borderline cases (empty strings).
- ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext));
- ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result));
+ ASSERT_TRUE(OSCrypt::EncryptString(plaintext, &ciphertext));
+ ASSERT_TRUE(OSCrypt::DecryptString(ciphertext, &result));
// |cyphertext| is empty on the Mac, different on Windows.
EXPECT_TRUE(ciphertext.empty() || plaintext != ciphertext);
EXPECT_EQ(plaintext, result);
// Test a simple string.
plaintext = "hello";
- ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext));
- ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result));
+ ASSERT_TRUE(OSCrypt::EncryptString(plaintext, &ciphertext));
+ ASSERT_TRUE(OSCrypt::DecryptString(ciphertext, &result));
EXPECT_NE(plaintext, ciphertext);
EXPECT_EQ(plaintext, result);
// Make sure it null terminates.
plaintext.assign("hello", 3);
- ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext));
- ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result));
+ ASSERT_TRUE(OSCrypt::EncryptString(plaintext, &ciphertext));
+ ASSERT_TRUE(OSCrypt::DecryptString(ciphertext, &result));
EXPECT_NE(plaintext, ciphertext);
EXPECT_EQ(result, "hel");
}
-TEST_F(EncryptorTest, DecryptError) {
+TEST_F(OSCryptTest, DecryptError) {
std::string plaintext;
std::string result;
std::string ciphertext;
// Test a simple string, messing with ciphertext prior to decrypting.
plaintext = "hello";
- ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext));
+ ASSERT_TRUE(OSCrypt::EncryptString(plaintext, &ciphertext));
EXPECT_NE(plaintext, ciphertext);
ASSERT_LT(4UL, ciphertext.size());
ciphertext[3] = ciphertext[3] + 1;
- EXPECT_FALSE(Encryptor::DecryptString(ciphertext, &result));
+ EXPECT_FALSE(OSCrypt::DecryptString(ciphertext, &result));
EXPECT_NE(plaintext, result);
EXPECT_TRUE(result.empty());
}
diff --git a/components/encryptor/encryptor_win.cc b/components/encryptor/os_crypt_win.cc
index 6dd6673..3853509 100644
--- a/components/encryptor/encryptor_win.cc
+++ b/components/encryptor/os_crypt_win.cc
@@ -2,21 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/encryptor/encryptor.h"
+#include "components/encryptor/os_crypt.h"
#include <windows.h>
#include <wincrypt.h>
+
#include "base/strings/utf_string_conversions.h"
#pragma comment(lib, "crypt32.lib")
-bool Encryptor::EncryptString16(const base::string16& plaintext,
- std::string* ciphertext) {
+bool OSCrypt::EncryptString16(const base::string16& plaintext,
+ std::string* ciphertext) {
return EncryptString(base::UTF16ToUTF8(plaintext), ciphertext);
}
-bool Encryptor::DecryptString16(const std::string& ciphertext,
- base::string16* plaintext) {
+bool OSCrypt::DecryptString16(const std::string& ciphertext,
+ base::string16* plaintext) {
std::string utf8;
if (!DecryptString(ciphertext, &utf8))
return false;
@@ -25,8 +26,8 @@ bool Encryptor::DecryptString16(const std::string& ciphertext,
return true;
}
-bool Encryptor::EncryptString(const std::string& plaintext,
- std::string* ciphertext) {
+bool OSCrypt::EncryptString(const std::string& plaintext,
+ std::string* ciphertext) {
DATA_BLOB input;
input.pbData = const_cast<BYTE*>(
reinterpret_cast<const BYTE*>(plaintext.data()));
@@ -46,8 +47,8 @@ bool Encryptor::EncryptString(const std::string& plaintext,
return true;
}
-bool Encryptor::DecryptString(const std::string& ciphertext,
- std::string* plaintext) {
+bool OSCrypt::DecryptString(const std::string& ciphertext,
+ std::string* plaintext) {
DATA_BLOB input;
input.pbData = const_cast<BYTE*>(
reinterpret_cast<const BYTE*>(ciphertext.data()));
diff --git a/components/password_manager/core/browser/login_database_win.cc b/components/password_manager/core/browser/login_database_win.cc
index 44a1d56..3479aef 100644
--- a/components/password_manager/core/browser/login_database_win.cc
+++ b/components/password_manager/core/browser/login_database_win.cc
@@ -2,14 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/strings/string_util.h"
-#include "components/encryptor/encryptor.h"
#include "components/password_manager/core/browser/login_database.h"
+#include "base/strings/string_util.h"
+#include "components/encryptor/os_crypt.h"
+
LoginDatabase::EncryptionResult LoginDatabase::EncryptedString(
const base::string16& plain_text,
std::string* cipher_text) const {
- if (Encryptor::EncryptString16(plain_text, cipher_text))
+ if (OSCrypt::EncryptString16(plain_text, cipher_text))
return ENCRYPTION_RESULT_SUCCESS;
return ENCRYPTION_RESULT_ITEM_FAILURE;
}
@@ -17,7 +18,7 @@ LoginDatabase::EncryptionResult LoginDatabase::EncryptedString(
LoginDatabase::EncryptionResult LoginDatabase::DecryptedString(
const std::string& cipher_text,
base::string16* plain_text) const {
- if (Encryptor::DecryptString16(cipher_text, plain_text))
+ if (OSCrypt::DecryptString16(cipher_text, plain_text))
return ENCRYPTION_RESULT_SUCCESS;
return ENCRYPTION_RESULT_ITEM_FAILURE;
}
diff --git a/components/signin/core/webdata/token_service_table.cc b/components/signin/core/webdata/token_service_table.cc
index bce7fe2..a455bc7 100644
--- a/components/signin/core/webdata/token_service_table.cc
+++ b/components/signin/core/webdata/token_service_table.cc
@@ -8,7 +8,7 @@
#include <string>
#include "base/logging.h"
-#include "components/encryptor/encryptor.h"
+#include "components/encryptor/os_crypt.h"
#include "components/webdata/common/web_database.h"
#include "sql/statement.h"
@@ -72,7 +72,7 @@ bool TokenServiceTable::RemoveTokenForService(const std::string& service) {
bool TokenServiceTable::SetTokenForService(const std::string& service,
const std::string& token) {
std::string encrypted_token;
- bool encrypted = Encryptor::EncryptString(token, &encrypted_token);
+ bool encrypted = OSCrypt::EncryptString(token, &encrypted_token);
if (!encrypted) {
return false;
}
@@ -105,7 +105,7 @@ bool TokenServiceTable::GetAllTokens(
bool entry_ok = !service.empty() &&
s.ColumnBlobAsString(1, &encrypted_token);
if (entry_ok) {
- Encryptor::DecryptString(encrypted_token, &decrypted_token);
+ OSCrypt::DecryptString(encrypted_token, &decrypted_token);
(*tokens)[service] = decrypted_token;
} else {
NOTREACHED();
diff --git a/components/sync_driver/system_encryptor.cc b/components/sync_driver/system_encryptor.cc
index 3198d6f..2a82a6c 100644
--- a/components/sync_driver/system_encryptor.cc
+++ b/components/sync_driver/system_encryptor.cc
@@ -4,7 +4,7 @@
#include "components/sync_driver/system_encryptor.h"
-#include "components/encryptor/encryptor.h"
+#include "components/encryptor/os_crypt.h"
namespace browser_sync {
@@ -12,12 +12,12 @@ SystemEncryptor::~SystemEncryptor() {}
bool SystemEncryptor::EncryptString(const std::string& plaintext,
std::string* ciphertext) {
- return ::Encryptor::EncryptString(plaintext, ciphertext);
+ return ::OSCrypt::EncryptString(plaintext, ciphertext);
}
bool SystemEncryptor::DecryptString(const std::string& ciphertext,
std::string* plaintext) {
- return ::Encryptor::DecryptString(ciphertext, plaintext);
+ return ::OSCrypt::DecryptString(ciphertext, plaintext);
}
} // namespace browser_sync
diff --git a/components/sync_driver/system_encryptor_unittest.cc b/components/sync_driver/system_encryptor_unittest.cc
index b015004..f4c9203 100644
--- a/components/sync_driver/system_encryptor_unittest.cc
+++ b/components/sync_driver/system_encryptor_unittest.cc
@@ -4,7 +4,7 @@
#include "components/sync_driver/system_encryptor.h"
-#include "components/encryptor/encryptor.h"
+#include "components/encryptor/os_crypt.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace browser_sync {
@@ -22,7 +22,7 @@ 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);
+ ::OSCrypt::UseMockKeychain(true);
#endif
std::string ciphertext;
EXPECT_TRUE(encryptor_.EncryptString(kPlaintext, &ciphertext));