From 109ca1cf9b29865a0f99dc99f379784dc980ac46 Mon Sep 17 00:00:00 2001 From: "thestig@chromium.org" Date: Thu, 9 Apr 2009 17:47:35 +0000 Subject: Add dummy encryptor implementations for mac and linux. Review URL: http://codereview.chromium.org/43095 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13435 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/browser.vcproj | 2 +- chrome/browser/password_manager/encryptor.cc | 65 ---------------------- chrome/browser/password_manager/encryptor_linux.cc | 44 +++++++++++++++ chrome/browser/password_manager/encryptor_mac.mm | 42 ++++++++++++++ chrome/browser/password_manager/encryptor_win.cc | 65 ++++++++++++++++++++++ chrome/browser/webdata/web_database.cc | 17 ++---- chrome/chrome.gyp | 10 ++-- chrome/common/temp_scaffolding_stubs.h | 15 ----- 8 files changed, 161 insertions(+), 99 deletions(-) delete mode 100644 chrome/browser/password_manager/encryptor.cc create mode 100644 chrome/browser/password_manager/encryptor_linux.cc create mode 100644 chrome/browser/password_manager/encryptor_mac.mm create mode 100644 chrome/browser/password_manager/encryptor_win.cc (limited to 'chrome') diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index 08401f2..5e7cfbe 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -1422,7 +1422,7 @@ Name="Password Manager" > -#include -#include "base/string_util.h" - -#pragma comment(lib, "crypt32.lib") - -bool Encryptor::EncryptString16(const string16& plaintext, - std::string* ciphertext) { - return EncryptString(UTF16ToUTF8(plaintext), ciphertext); -} - -bool Encryptor::DecryptString16(const std::string& ciphertext, - string16* plaintext) { - std::string utf8; - if (!DecryptString(ciphertext, &utf8)) - return false; - - *plaintext = UTF8ToUTF16(utf8); - return true; -} - -bool Encryptor::EncryptString(const std::string& plaintext, - std::string* ciphertext) { - DATA_BLOB input; - input.pbData = const_cast( - reinterpret_cast(plaintext.data())); - input.cbData = static_cast(plaintext.length()); - - DATA_BLOB output; - BOOL result = CryptProtectData(&input, L"", NULL, NULL, NULL, - 0, &output); - if (!result) - return false; - - // this does a copy - ciphertext->assign(reinterpret_cast(output.pbData), - output.cbData); - - LocalFree(output.pbData); - return true; -} - -bool Encryptor::DecryptString(const std::string& ciphertext, - std::string* plaintext) { - DATA_BLOB input; - input.pbData = const_cast( - reinterpret_cast(ciphertext.data())); - input.cbData = static_cast(ciphertext.length()); - - DATA_BLOB output; - BOOL result = CryptUnprotectData(&input, NULL, NULL, NULL, NULL, - 0, &output); - if (!result) - return false; - - plaintext->assign(reinterpret_cast(output.pbData), output.cbData); - LocalFree(output.pbData); - return true; -} diff --git a/chrome/browser/password_manager/encryptor_linux.cc b/chrome/browser/password_manager/encryptor_linux.cc new file mode 100644 index 0000000..9c40c37 --- /dev/null +++ b/chrome/browser/password_manager/encryptor_linux.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2006-2008 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 "chrome/browser/password_manager/encryptor.h" + +#include "base/logging.h" +#include "base/string_util.h" + +bool Encryptor::EncryptString16(const string16& plaintext, + std::string* ciphertext) { + return EncryptString(UTF16ToUTF8(plaintext), ciphertext); +} + +bool Encryptor::DecryptString16(const std::string& ciphertext, + string16* plaintext) { + std::string utf8; + if (!DecryptString(ciphertext, &utf8)) + return false; + + *plaintext = UTF8ToUTF16(utf8); + return true; +} + +bool Encryptor::EncryptString(const std::string& plaintext, + std::string* ciphertext) { + // This doesn't actually encrypt, we need to work on the Encryptor API. + // http://code.google.com/p/chromium/issues/detail?id=8205 + NOTIMPLEMENTED(); + + // this does a copy + ciphertext->assign(plaintext.data(), plaintext.length()); + return true; +} + +bool Encryptor::DecryptString(const std::string& ciphertext, + std::string* plaintext) { + // This doesn't actually decrypt, we need to work on the Encryptor API. + // http://code.google.com/p/chromium/issues/detail?id=8205 + NOTIMPLEMENTED(); + + plaintext->assign(ciphertext.data(), ciphertext.length()); + return true; +} diff --git a/chrome/browser/password_manager/encryptor_mac.mm b/chrome/browser/password_manager/encryptor_mac.mm new file mode 100644 index 0000000..435f08d --- /dev/null +++ b/chrome/browser/password_manager/encryptor_mac.mm @@ -0,0 +1,42 @@ +// Copyright (c) 2006-2008 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 "chrome/browser/password_manager/encryptor.h" + +#include "base/logging.h" +#include "base/string_util.h" + +bool Encryptor::EncryptString16(const string16& plaintext, + std::string* ciphertext) { + return EncryptString(UTF16ToUTF8(plaintext), ciphertext); +} + +bool Encryptor::DecryptString16(const std::string& ciphertext, + string16* plaintext) { + std::string utf8; + if (!DecryptString(ciphertext, &utf8)) + return false; + + *plaintext = UTF8ToUTF16(utf8); + return true; +} + +bool Encryptor::EncryptString(const std::string& plaintext, + std::string* ciphertext) { + // This doesn't actually encrypt, we need to work on the Encryptor API. + NOTIMPLEMENTED(); + + // this does a copy + ciphertext->assign(plaintext.data(), plaintext.length()); + return true; +} + +bool Encryptor::DecryptString(const std::string& ciphertext, + std::string* plaintext) { + // This doesn't actually decrypt, we need to work on the Encryptor API. + NOTIMPLEMENTED(); + + plaintext->assign(ciphertext.data(), ciphertext.length()); + return true; +} diff --git a/chrome/browser/password_manager/encryptor_win.cc b/chrome/browser/password_manager/encryptor_win.cc new file mode 100644 index 0000000..76a9d3d --- /dev/null +++ b/chrome/browser/password_manager/encryptor_win.cc @@ -0,0 +1,65 @@ +// Copyright (c) 2006-2008 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 "chrome/browser/password_manager/encryptor.h" + +#include +#include +#include "base/string_util.h" + +#pragma comment(lib, "crypt32.lib") + +bool Encryptor::EncryptString16(const string16& plaintext, + std::string* ciphertext) { + return EncryptString(UTF16ToUTF8(plaintext), ciphertext); +} + +bool Encryptor::DecryptString16(const std::string& ciphertext, + string16* plaintext) { + std::string utf8; + if (!DecryptString(ciphertext, &utf8)) + return false; + + *plaintext = UTF8ToUTF16(utf8); + return true; +} + +bool Encryptor::EncryptString(const std::string& plaintext, + std::string* ciphertext) { + DATA_BLOB input; + input.pbData = const_cast( + reinterpret_cast(plaintext.data())); + input.cbData = static_cast(plaintext.length()); + + DATA_BLOB output; + BOOL result = CryptProtectData(&input, L"", NULL, NULL, NULL, + 0, &output); + if (!result) + return false; + + // this does a copy + ciphertext->assign(reinterpret_cast(output.pbData), + output.cbData); + + LocalFree(output.pbData); + return true; +} + +bool Encryptor::DecryptString(const std::string& ciphertext, + std::string* plaintext) { + DATA_BLOB input; + input.pbData = const_cast( + reinterpret_cast(ciphertext.data())); + input.cbData = static_cast(ciphertext.length()); + + DATA_BLOB output; + BOOL result = CryptUnprotectData(&input, NULL, NULL, NULL, NULL, + 0, &output); + if (!result) + return false; + + plaintext->assign(reinterpret_cast(output.pbData), output.cbData); + LocalFree(output.pbData); + return true; +} diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc index fe9fb5f..9497885 100644 --- a/chrome/browser/webdata/web_database.cc +++ b/chrome/browser/webdata/web_database.cc @@ -12,26 +12,17 @@ #include "base/gfx/png_encoder.h" #include "base/string_util.h" #include "base/time.h" -#include "base/values.h" #include "chrome/browser/history/history_database.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/common/l10n_util.h" -#include "chrome/common/scoped_vector.h" #include "webkit/glue/password_form.h" -#if defined(OS_POSIX) -// TODO(port): get rid of this include. It's used just to provide declarations -// and stub definitions for classes we encouter during the porting effort. -#include "chrome/common/temp_scaffolding_stubs.h" -#endif - -// TODO(port): Get rid of this section and finish porting. -#if defined(OS_WIN) // Encryptor is the *wrong* way of doing things; we need to turn it into a -// bottleneck to use the platform methods (e.g. Keychain on the Mac). That's -// going to take a massive change in its API... +// bottleneck to use the platform methods (e.g. Keychain on the Mac, Gnome +// Keyring / KWallet on Linux). That's going to take a massive change in its +// API... see: +// http://code.google.com/p/chromium/issues/detail?id=8205 (Linux) #include "chrome/browser/password_manager/encryptor.h" -#endif //////////////////////////////////////////////////////////////////////////////// // diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 61096fe..6d1c473 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -845,7 +845,9 @@ 'browser/options_window.h', 'browser/page_state.cc', 'browser/page_state.h', - 'browser/password_manager/encryptor.cc', + 'browser/password_manager/encryptor_linux.cc', + 'browser/password_manager/encryptor_mac.mm', + 'browser/password_manager/encryptor_win.cc', 'browser/password_manager/encryptor.h', 'browser/password_manager/ie7_password.cc', 'browser/password_manager/ie7_password.h', @@ -1329,9 +1331,8 @@ # Exclude all of hang_monitor. ['exclude', '^browser/hang_monitor/'], - # Exclude most of password_manager. - ['exclude', '^browser/password_manager/'], - ['include', '^browser/password_manager/password(_form)?_manager\\.cc$'], + # Exclude parts of password_manager. + ['exclude', '^browser/password_manager/ie7_password\\.cc$'], # Exclude most of printing. ['exclude', '^browser/printing/'], @@ -2285,7 +2286,6 @@ 'browser/importer/firefox_importer_unittest.cc', 'browser/importer/importer_unittest.cc', 'browser/login_prompt_unittest.cc', - 'browser/password_manager/encryptor_unittest.cc', 'browser/password_manager/password_form_manager_unittest.cc', 'browser/printing/page_number_unittest.cc', 'browser/printing/page_overlays_unittest.cc', diff --git a/chrome/common/temp_scaffolding_stubs.h b/chrome/common/temp_scaffolding_stubs.h index 12c05a6..d5359a9 100644 --- a/chrome/common/temp_scaffolding_stubs.h +++ b/chrome/common/temp_scaffolding_stubs.h @@ -404,21 +404,6 @@ class WindowSizer { //--------------------------------------------------------------------------- // These stubs are for Profile -class Encryptor { - public: - static bool EncryptString16(const string16& plaintext, - std::string* ciphertext) { - NOTIMPLEMENTED(); - return false; - } - - static bool DecryptString16(const std::string& ciphertext, - string16* plaintext) { - NOTIMPLEMENTED(); - return false; - } -}; - class WebAppLauncher { public: static void Launch(Profile* profile, const GURL& url) { -- cgit v1.1