summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-03 03:46:24 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-03 03:46:24 +0000
commit2a7f963d5b7be2efdf98e6a52cee42f4857d5cc0 (patch)
tree5ae671a0d7272a982a2551d4cc6acb139014b49a
parentc060ceb77b5147e90ae1743c38e5f3498ab4145f (diff)
downloadchromium_src-2a7f963d5b7be2efdf98e6a52cee42f4857d5cc0.zip
chromium_src-2a7f963d5b7be2efdf98e6a52cee42f4857d5cc0.tar.gz
chromium_src-2a7f963d5b7be2efdf98e6a52cee42f4857d5cc0.tar.bz2
components/autofill: Use webdata Encryptor API.
BUG=None TEST=components_unittests TBR=isherman@chromium.org Review URL: https://codereview.chromium.org/18121008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209871 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--components/autofill.gypi2
-rw-r--r--components/autofill/core/browser/autofill_ie_toolbar_import_win.cc6
-rw-r--r--components/autofill/core/browser/autofill_ie_toolbar_import_win_unittest.cc5
-rw-r--r--components/autofill/core/browser/data_encryption_win.cc57
-rw-r--r--components/autofill/core/browser/data_encryption_win.h20
-rw-r--r--components/autofill/core/browser/data_encryption_win_unittest.cc27
-rw-r--r--components/components_tests.gypi4
7 files changed, 6 insertions, 115 deletions
diff --git a/components/autofill.gypi b/components/autofill.gypi
index 4c31aea..2ba7e16 100644
--- a/components/autofill.gypi
+++ b/components/autofill.gypi
@@ -163,8 +163,6 @@
'autofill/core/browser/credit_card.h',
'autofill/core/browser/credit_card_field.cc',
'autofill/core/browser/credit_card_field.h',
- 'autofill/core/browser/data_encryption_win.cc',
- 'autofill/core/browser/data_encryption_win.h',
'autofill/core/browser/email_field.cc',
'autofill/core/browser/email_field.h',
'autofill/core/browser/field_types.h',
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 c4c3cf0..4ac4edc 100644
--- a/components/autofill/core/browser/autofill_ie_toolbar_import_win.cc
+++ b/components/autofill/core/browser/autofill_ie_toolbar_import_win.cc
@@ -18,13 +18,13 @@
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/crypto/rc4_decryptor.h"
-#include "components/autofill/core/browser/data_encryption_win.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/form_group.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#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/webdata/encryptor/encryptor.h"
using base::win::RegKey;
@@ -81,12 +81,12 @@ base::string16 ReadAndDecryptValue(const RegKey& key,
LONG result = key.ReadValue(value_name, NULL, &data_size, &data_type);
if ((result != ERROR_SUCCESS) || !data_size || data_type != REG_BINARY)
return base::string16();
- std::vector<uint8> data;
+ std::string data;
data.resize(data_size);
result = key.ReadValue(value_name, &(data[0]), &data_size, &data_type);
if (result == ERROR_SUCCESS) {
std::string out_data;
- if (DecryptData(data, &out_data)) {
+ if (Encryptor::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 48d57aa..dd343d1 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
@@ -9,8 +9,8 @@
#include "base/win/registry.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/credit_card.h"
-#include "components/autofill/core/browser/data_encryption_win.h"
#include "components/autofill/core/browser/field_types.h"
+#include "components/webdata/encryptor/encryptor.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::win::RegKey;
@@ -91,7 +91,8 @@ void EncryptAndWrite(RegKey* key, const ValueDescription* value) {
data.resize(data_size);
memcpy(&data[0], value->value, data_size);
- std::vector<uint8> encrypted_data = EncryptData(data);
+ std::string encrypted_data;
+ Encryptor::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/data_encryption_win.cc b/components/autofill/core/browser/data_encryption_win.cc
deleted file mode 100644
index 0b4df97..0000000
--- a/components/autofill/core/browser/data_encryption_win.cc
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2013 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/autofill/core/browser/data_encryption_win.h"
-
-#include <windows.h>
-#include <wincrypt.h>
-
-#include <cstddef>
-
-#include "base/logging.h"
-
-#pragma comment(lib, "crypt32.lib")
-
-// TODO(akalin): Merge this with similar code in
-// components/webdata/encryptor/encryptor_win.cc. Preferably, all
-// this stuff would live in crypto/.
-
-namespace autofill {
-
-std::vector<uint8> EncryptData(const std::string& data) {
- DATA_BLOB unencrypted_data = { 0 };
- unencrypted_data.pbData = (BYTE*)(data.data());
- unencrypted_data.cbData = data.size();
- DATA_BLOB encrypted_data = { 0 };
-
- if (!CryptProtectData(&unencrypted_data, L"", NULL, NULL, NULL, 0,
- &encrypted_data))
- LOG(ERROR) << "Encryption fails: " << data;
-
- std::vector<uint8> result(encrypted_data.pbData,
- encrypted_data.pbData + encrypted_data.cbData);
- LocalFree(encrypted_data.pbData);
- return result;
-}
-
-bool DecryptData(const std::vector<uint8>& in_data, std::string* out_data) {
- DATA_BLOB encrypted_data, decrypted_data;
- encrypted_data.pbData =
- (in_data.empty() ? NULL : const_cast<BYTE*>(&in_data[0]));
- encrypted_data.cbData = in_data.size();
- LPWSTR descrip = L"";
-
- if (!CryptUnprotectData(&encrypted_data, &descrip, NULL, NULL, NULL, 0,
- &decrypted_data)) {
- LOG(ERROR) << "Decryption fails: ";
- return false;
- } else {
- out_data->assign(reinterpret_cast<const char*>(decrypted_data.pbData),
- decrypted_data.cbData);
- LocalFree(decrypted_data.pbData);
- return true;
- }
-}
-
-} // namespace autofill
diff --git a/components/autofill/core/browser/data_encryption_win.h b/components/autofill/core/browser/data_encryption_win.h
deleted file mode 100644
index 1ad1140..0000000
--- a/components/autofill/core/browser/data_encryption_win.h
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2013 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_AUTOFILL_CORE_BROWSER_DATA_ENCRYPTION_WIN_H_
-#define COMPONENTS_AUTOFILL_CORE_BROWSER_DATA_ENCRYPTION_WIN_H_
-
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-
-namespace autofill {
-
-std::vector<uint8> EncryptData(const std::string& data);
-bool DecryptData(const std::vector<uint8>& in_data, std::string* out_data);
-
-} // namespace autofill
-
-#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_DATA_ENCRYPTION_WIN_H_
diff --git a/components/autofill/core/browser/data_encryption_win_unittest.cc b/components/autofill/core/browser/data_encryption_win_unittest.cc
deleted file mode 100644
index 6e0fca9..0000000
--- a/components/autofill/core/browser/data_encryption_win_unittest.cc
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2013 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/autofill/core/browser/data_encryption_win.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace autofill {
-namespace {
-
-TEST(DataEncryptionWinTest, TestEncryptDecryptOfSampleString) {
- std::vector<uint8> example(EncryptData("example"));
- ASSERT_FALSE(example.empty());
- std::string result;
- ASSERT_TRUE(DecryptData(example, &result));
- ASSERT_TRUE(result == "example");
-}
-
-TEST(DataEncryptionWinTest, TestDecryptFailure) {
- std::vector<uint8> example(0, 0);
- std::string result;
- ASSERT_FALSE(DecryptData(example, &result));
-}
-
-} // namespace
-} // namespace autofill
diff --git a/components/components_tests.gypi b/components/components_tests.gypi
index 4325216..2de146b 100644
--- a/components/components_tests.gypi
+++ b/components/components_tests.gypi
@@ -11,7 +11,6 @@
'type': '<(gtest_target_type)',
'sources': [
'auto_login_parser/auto_login_parser_unittest.cc',
- 'autofill/core/browser/data_encryption_win_unittest.cc',
'browser_context_keyed_service/browser_context_dependency_manager_unittest.cc',
'browser_context_keyed_service/dependency_graph_unittest.cc',
'navigation_interception/intercept_navigation_resource_throttle_unittest.cc',
@@ -33,9 +32,6 @@
# Dependencies of auto_login_parser
'auto_login_parser',
- # Dependencies of autofill
- 'autofill_core_browser',
-
# Dependencies of browser_context_keyed_service
'browser_context_keyed_service',