summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-27 17:54:48 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-27 17:54:48 +0000
commitb584a879c1f8c607d952890a84b1625fa8d0a74f (patch)
tree57ac2dba65c764a22f31f15cc5e86c666a83a207 /components
parentafcc6820dc65730d049495cae6c418711aa5fa30 (diff)
downloadchromium_src-b584a879c1f8c607d952890a84b1625fa8d0a74f.zip
chromium_src-b584a879c1f8c607d952890a84b1625fa8d0a74f.tar.gz
chromium_src-b584a879c1f8c607d952890a84b1625fa8d0a74f.tar.bz2
components/autofill: Break the dependency on sync utility file.
Do this moving data_encryption_win* into core/browser, since it's only used from there. BUG=140037 TEST=unit_tests,checkdeps.py R=joi@chromium.org,isherman@chromium.org,akalin@chromium.org NOTRY=true Review URL: https://chromiumcodereview.appspot.com/17745004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208948 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r--components/autofill.gypi2
-rw-r--r--components/autofill/core/browser/DEPS3
-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/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
8 files changed, 114 insertions, 7 deletions
diff --git a/components/autofill.gypi b/components/autofill.gypi
index ebd4cf0..a8a140b 100644
--- a/components/autofill.gypi
+++ b/components/autofill.gypi
@@ -163,6 +163,8 @@
'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/DEPS b/components/autofill/core/browser/DEPS
index f10e304..af47ba2 100644
--- a/components/autofill/core/browser/DEPS
+++ b/components/autofill/core/browser/DEPS
@@ -33,9 +33,6 @@ include_rules = [
"!content/public/common/url_constants.h",
"!third_party/WebKit/public/web/WebAutofillClient.h",
"!third_party/WebKit/public/web/WebInputElement.h",
-
- # TODO(akalin): Remove this dependency.
- "!sync/util/data_encryption_win.h",
]
specific_include_rules = {
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 d34e362..c4c3cf0 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 "sync/util/data_encryption_win.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 (syncer::DecryptData(data, &out_data)) {
+ if (DecryptData(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 13e1b03..48d57aa 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 "sync/util/data_encryption_win.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::win::RegKey;
@@ -91,7 +91,7 @@ void EncryptAndWrite(RegKey* key, const ValueDescription* value) {
data.resize(data_size);
memcpy(&data[0], value->value, data_size);
- std::vector<uint8> encrypted_data = syncer::EncryptData(data);
+ std::vector<uint8> encrypted_data = EncryptData(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
new file mode 100644
index 0000000..0b4df97
--- /dev/null
+++ b/components/autofill/core/browser/data_encryption_win.cc
@@ -0,0 +1,57 @@
+// 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
new file mode 100644
index 0000000..1ad1140
--- /dev/null
+++ b/components/autofill/core/browser/data_encryption_win.h
@@ -0,0 +1,20 @@
+// 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
new file mode 100644
index 0000000..6e0fca9
--- /dev/null
+++ b/components/autofill/core/browser/data_encryption_win_unittest.cc
@@ -0,0 +1,27 @@
+// 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 2de146b..4325216 100644
--- a/components/components_tests.gypi
+++ b/components/components_tests.gypi
@@ -11,6 +11,7 @@
'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',
@@ -32,6 +33,9 @@
# Dependencies of auto_login_parser
'auto_login_parser',
+ # Dependencies of autofill
+ 'autofill_core_browser',
+
# Dependencies of browser_context_keyed_service
'browser_context_keyed_service',