Commit 4b559b4d authored by rvargas@google.com's avatar rvargas@google.com

Move crypto files out of base, to a top level directory.

src/crypto is now an independent project that contains our
cryptographic primitives (except md5 and sha1).

This removes the base dependency from nss, openssl and sqlite.

BUG=76996
TEST=none
Review URL: http://codereview.chromium.org/6805019

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81611 0039d316-1c4b-4281-b951-d872f2087c98
parent 056dd45d
......@@ -112,13 +112,6 @@
'callback_unittest.cc',
'command_line_unittest.cc',
'cpu_unittest.cc',
'crypto/encryptor_unittest.cc',
'crypto/rsa_private_key_unittest.cc',
'crypto/rsa_private_key_nss_unittest.cc',
'crypto/secure_hash_unittest.cc',
'crypto/signature_creator_unittest.cc',
'crypto/signature_verifier_unittest.cc',
'crypto/symmetric_key_unittest.cc',
'debug/leak_tracker_unittest.cc',
'debug/stack_trace_unittest.cc',
'debug/trace_event_win_unittest.cc',
......@@ -129,7 +122,6 @@
'file_util_unittest.cc',
'file_version_info_unittest.cc',
'gmock_unittest.cc',
'hmac_unittest.cc',
'id_map_unittest.cc',
'i18n/break_iterator_unittest.cc',
'i18n/char_iterator_unittest.cc',
......@@ -167,7 +159,6 @@
'process_util_unittest_mac.mm',
'rand_util_unittest.cc',
'sha1_unittest.cc',
'sha2_unittest.cc',
'shared_memory_unittest.cc',
'stack_container_unittest.cc',
'string16_unittest.cc',
......@@ -256,7 +247,6 @@
}, { # OS != "linux" and OS != "freebsd" and OS != "openbsd" and OS != "solaris"
'sources!': [
'message_pump_glib_unittest.cc',
'crypto/rsa_private_key_nss_unittest.cc',
]
}],
# This is needed to trigger the dll copy step on windows.
......@@ -281,11 +271,6 @@
'win_util_unittest.cc',
],
}],
[ 'use_openssl==1', {
'sources!': [
'crypto/rsa_private_key_nss_unittest.cc',
],
}],
],
},
{
......
......@@ -456,22 +456,6 @@
},
},
],
[ 'use_openssl==1', {
'dependencies': [
'../third_party/openssl/openssl.gyp:openssl',
],
}, { # use_openssl==0
'sources': [
'base/crypto/scoped_nss_types.h',
],
'dependencies': [
'../build/linux/system.gyp:nss',
],
'export_dependent_settings': [
'../build/linux/system.gyp:nss',
],
}
],
],
'dependencies': [
'symbolize',
......@@ -525,27 +509,13 @@
'$(SDKROOT)/System/Library/Frameworks/Security.framework',
],
},
}, { # OS != "mac"
'sources!': [
'crypto/cssm_init.cc',
'crypto/cssm_init.h',
'crypto/mac_security_services_lock.cc',
'crypto/mac_security_services_lock.h',
],
}],
[ 'OS == "mac" or OS == "win"', {
'dependencies': [
'../third_party/nss/nss.gyp:nss',
],
},],
[ 'OS != "win"', {
'dependencies': ['../third_party/libevent/libevent.gyp:libevent'],
'sources!': [
'third_party/purify/pure_api.c',
'base_drag_source.cc',
'base_drop_target.cc',
'crypto/capi_util.h',
'crypto/capi_util.cc',
'event_recorder.cc',
'file_version_info.cc',
'registry.cc',
......@@ -553,82 +523,11 @@
'win_util.cc',
],
},],
[ 'use_openssl==1', {
# TODO(joth): Use a glob to match exclude patterns once the
# OpenSSL file set is complete.
'sources!': [
'crypto/encryptor_nss.cc',
'crypto/rsa_private_key_nss.cc',
'crypto/secure_hash_default.cc',
'crypto/signature_creator_nss.cc',
'crypto/signature_verifier_nss.cc',
'crypto/symmetric_key_nss.cc',
'hmac_nss.cc',
'nss_util.cc',
'nss_util.h',
'third_party/nss/blapi.h',
'third_party/nss/blapit.h',
'third_party/nss/sha256.h',
'third_party/nss/sha512.cc',
],
}, {
'sources!': [
'crypto/encryptor_openssl.cc',
'crypto/rsa_private_key_openssl.cc',
'crypto/secure_hash_openssl.cc',
'crypto/signature_creator_openssl.cc',
'crypto/signature_verifier_openssl.cc',
'crypto/symmetric_key_openssl.cc',
'hmac_openssl.cc',
'openssl_util.cc',
'openssl_util.h',
],
},],
],
'sources': [
'crypto/capi_util.cc',
'crypto/capi_util.h',
'crypto/crypto_module_blocking_password_delegate.h',
'crypto/cssm_init.cc',
'crypto/cssm_init.h',
'crypto/encryptor.h',
'crypto/encryptor_mac.cc',
'crypto/encryptor_nss.cc',
'crypto/encryptor_openssl.cc',
'crypto/encryptor_win.cc',
'crypto/mac_security_services_lock.cc',
'crypto/mac_security_services_lock.h',
'crypto/rsa_private_key.h',
'crypto/rsa_private_key.cc',
'crypto/rsa_private_key_mac.cc',
'crypto/rsa_private_key_nss.cc',
'crypto/rsa_private_key_openssl.cc',
'crypto/rsa_private_key_win.cc',
'crypto/secure_hash.h',
'crypto/secure_hash_default.cc',
'crypto/secure_hash_openssl.cc',
'crypto/signature_creator.h',
'crypto/signature_creator_mac.cc',
'crypto/signature_creator_nss.cc',
'crypto/signature_creator_openssl.cc',
'crypto/signature_creator_win.cc',
'crypto/signature_verifier.h',
'crypto/signature_verifier_mac.cc',
'crypto/signature_verifier_nss.cc',
'crypto/signature_verifier_openssl.cc',
'crypto/signature_verifier_win.cc',
'crypto/symmetric_key.h',
'crypto/symmetric_key_mac.cc',
'crypto/symmetric_key_nss.cc',
'crypto/symmetric_key_openssl.cc',
'crypto/symmetric_key_win.cc',
'third_party/nspr/prcpucfg.h',
'third_party/nspr/prcpucfg_win.h',
'third_party/nspr/prtypes.h',
'third_party/nss/blapi.h',
'third_party/nss/blapit.h',
'third_party/nss/sha256.h',
'third_party/nss/sha512.cc',
'third_party/purify/pure.h',
'third_party/purify/pure_api.c',
'third_party/xdg_user_dirs/xdg_user_dir_lookup.cc',
......@@ -641,11 +540,6 @@
'event_recorder_stubs.cc',
'file_descriptor_shuffle.cc',
'file_descriptor_shuffle.h',
'hmac.h',
'hmac_mac.cc',
'hmac_nss.cc',
'hmac_openssl.cc',
'hmac_win.cc',
'linux_util.cc',
'linux_util.h',
'md5.cc',
......@@ -661,12 +555,6 @@
'message_pump_mac.mm',
'metrics/field_trial.cc',
'metrics/field_trial.h',
'nss_util.cc',
'nss_util.h',
'openssl_util.cc',
'openssl_util.h',
'sha2.cc',
'sha2.h',
'string16.cc',
'string16.h',
'sync_socket.h',
......
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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.
......@@ -7,7 +7,9 @@
#include <windows.h>
#include <wincrypt.h>
#include "base/crypto/scoped_capi_types.h"
// This file is not being compiled at the moment (see bug 47218). If we keep
// sha1 inside base, we cannot depend on src/crypto.
// #include "crypto/scoped_capi_types.h"
#include "base/logging.h"
namespace base {
......
......@@ -15,7 +15,6 @@
#include "base/logging.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/memory/scoped_ptr.h"
#include "base/nss_util.h"
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/test/multiprocess_test.h"
......@@ -214,14 +213,6 @@ void TestSuite::Initialize() {
icu_util::Initialize();
#if defined(USE_NSS)
// Trying to repeatedly initialize and cleanup NSS and NSPR may result in
// a deadlock. Such repeated initialization will happen when using test
// isolation. Prevent problems by initializing NSS here, so that the cleanup
// will be done only on process exit.
base::EnsureNSSInit();
#endif // defined(USE_NSS)
CatchMaybeTests();
TestTimeouts::Initialize();
......
include_rules = [
"+app",
"+content",
"+crypto",
"+gpu",
"+net",
"+printing",
......
......@@ -13,13 +13,13 @@
#include "base/message_loop.h"
#include "base/metrics/stats_counters.h"
#include "base/metrics/stats_table.h"
#include "base/nss_util.h"
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "build/build_config.h"
#include "crypto/nss_util.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/diagnostics/diagnostics_main.h"
#include "chrome/browser/platform_util.h"
......@@ -589,7 +589,7 @@ int ChromeMain(int argc, char** argv) {
SetupCRT(command_line);
#if defined(USE_NSS)
base::EarlySetupForNSSInit();
crypto::EarlySetupForNSSInit();
#endif
// Initialize the Chrome path provider.
......
......@@ -27,7 +27,7 @@
#include "ui/gfx/gtk_util.h"
#if defined(USE_NSS)
#include "base/nss_util.h"
#include "crypto/nss_util.h"
#endif
#if defined(USE_LINUX_BREAKPAD)
......@@ -69,7 +69,7 @@ void BrowserMainPartsGtk::PreEarlyInitialization() {
#if defined(USE_NSS)
// We want to be sure to init NSPR on the main thread.
base::EnsureNSPRInit();
crypto::EnsureNSPRInit();
#endif
}
......
......@@ -11,8 +11,8 @@
#include "base/file_path.h"
#include "base/mac/mac_util.h"
#include "base/memory/scoped_nsobject.h"
#include "base/nss_util.h"
#include "base/path_service.h"
#include "crypto/nss_util.h"
#include "chrome/app/breakpad_mac.h"
#import "chrome/browser/app_controller_mac.h"
#include "chrome/browser/browser_main_win.h"
......@@ -137,7 +137,7 @@ class BrowserMainPartsMac : public BrowserMainPartsPosix {
net::ClientSocketFactory::UseSystemSSL();
} else {
// We want to be sure to init NSPR on the main thread.
base::EnsureNSPRInit();
crypto::EnsureNSPRInit();
}
}
};
......
......@@ -15,11 +15,11 @@
#include "base/i18n/rtl.h"
#include "base/memory/scoped_native_library.h"
#include "base/memory/scoped_ptr.h"
#include "base/nss_util.h"
#include "base/path_service.h"
#include "base/utf_string_conversions.h"
#include "base/win/windows_version.h"
#include "base/win/wrapped_window_proc.h"
#include "crypto/nss_util.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/browser/first_run/upgrade_util.h"
#include "chrome/browser/metrics/metrics_service.h"
......@@ -295,7 +295,7 @@ class BrowserMainPartsWin : public BrowserMainParts {
net::ClientSocketFactory::UseSystemSSL();
} else {
// We want to be sure to init NSPR on the main thread.
base::EnsureNSPRInit();
crypto::EnsureNSPRInit();
}
}
};
......
......@@ -11,11 +11,10 @@
#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/sha2.h"
#include "base/string_util.h"
#include "base/synchronization/lock.h"
#include "base/third_party/nss/blapi.h"
#include "base/third_party/nss/sha256.h"
#include "crypto/third_party/nss/blapi.h"
#include "crypto/third_party/nss/sha256.h"
#include "chrome/browser/chromeos/boot_times_loader.h"
#include "chrome/browser/chromeos/cros/cryptohome_library.h"
#include "chrome/browser/chromeos/login/auth_response_handler.h"
......
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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.
......@@ -9,16 +9,14 @@
#include <vector>
#include "base/basictypes.h"
#include "base/crypto/rsa_private_key.h"
#include "base/file_path.h"
#include "crypto/rsa_private_key.h"
#include "chrome/browser/chromeos/cros/login_library.h"
#include "chrome/browser/chromeos/login/owner_key_utils.h"
#include "content/browser/browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::base::RSAPrivateKey;
namespace chromeos {
class MockKeyUtils : public OwnerKeyUtils {
......@@ -31,10 +29,11 @@ class MockKeyUtils : public OwnerKeyUtils {
const std::vector<uint8> public_key));
MOCK_METHOD3(Sign, bool(const std::string& data,
std::vector<uint8>* OUT_signature,
base::RSAPrivateKey* key));
MOCK_METHOD1(FindPrivateKey, RSAPrivateKey*(const std::vector<uint8>& key));
crypto::RSAPrivateKey* key));
MOCK_METHOD1(FindPrivateKey,
crypto::RSAPrivateKey*(const std::vector<uint8>& key));
MOCK_METHOD0(GetOwnerKeyFilePath, FilePath());
MOCK_METHOD2(ExportPublicKeyToFile, bool(base::RSAPrivateKey* pair,
MOCK_METHOD2(ExportPublicKeyToFile, bool(crypto::RSAPrivateKey* pair,
const FilePath& key_file));
protected:
virtual ~MockKeyUtils() {}
......
......@@ -6,19 +6,18 @@
#include <limits>
#include "base/crypto/rsa_private_key.h"
#include "base/crypto/signature_creator.h"
#include "base/crypto/signature_verifier.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_util.h"
#include "crypto/rsa_private_key.h"
#include "crypto/signature_creator.h"
#include "crypto/signature_verifier.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/login_library.h"
#include "chrome/common/extensions/extension_constants.h"
using base::RSAPrivateKey;
using extension_misc::kSignatureAlgorithm;
namespace chromeos {
......@@ -49,16 +48,17 @@ class OwnerKeyUtilsImpl : public OwnerKeyUtils {
bool Sign(const std::string& data,
std::vector<uint8>* OUT_signature,
base::RSAPrivateKey* key);
crypto::RSAPrivateKey* key);
RSAPrivateKey* FindPrivateKey(const std::vector<uint8>& key);
crypto::RSAPrivateKey* FindPrivateKey(const std::vector<uint8>& key);
FilePath GetOwnerKeyFilePath();
protected:
virtual ~OwnerKeyUtilsImpl();
bool ExportPublicKeyToFile(RSAPrivateKey* pair, const FilePath& key_file);
bool ExportPublicKeyToFile(crypto::RSAPrivateKey* pair,
const FilePath& key_file);
private:
// The file outside the owner's encrypted home directory where her
......@@ -83,7 +83,7 @@ OwnerKeyUtilsImpl::OwnerKeyUtilsImpl() {}
OwnerKeyUtilsImpl::~OwnerKeyUtilsImpl() {}
bool OwnerKeyUtilsImpl::ExportPublicKeyToFile(RSAPrivateKey* pair,
bool OwnerKeyUtilsImpl::ExportPublicKeyToFile(crypto::RSAPrivateKey* pair,
const FilePath& key_file) {
DCHECK(pair);
bool ok = false;
......@@ -134,7 +134,7 @@ bool OwnerKeyUtilsImpl::ImportPublicKey(const FilePath& key_file,
bool OwnerKeyUtilsImpl::Verify(const std::string& data,
const std::vector<uint8> signature,
const std::vector<uint8> public_key) {
base::SignatureVerifier verifier;
crypto::SignatureVerifier verifier;
if (!verifier.VerifyInit(kSignatureAlgorithm, sizeof(kSignatureAlgorithm),
&signature[0], signature.size(),
&public_key[0], public_key.size())) {
......@@ -148,9 +148,9 @@ bool OwnerKeyUtilsImpl::Verify(const std::string& data,
bool OwnerKeyUtilsImpl::Sign(const std::string& data,
std::vector<uint8>* OUT_signature,
base::RSAPrivateKey* key) {
scoped_ptr<base::SignatureCreator> signer(
base::SignatureCreator::Create(key));
crypto::RSAPrivateKey* key) {
scoped_ptr<crypto::SignatureCreator> signer(
crypto::SignatureCreator::Create(key));
if (!signer->Update(reinterpret_cast<const uint8*>(data.c_str()),
data.length())) {
return false;
......@@ -158,9 +158,9 @@ bool OwnerKeyUtilsImpl::Sign(const std::string& data,
return signer->Final(OUT_signature);
}
RSAPrivateKey* OwnerKeyUtilsImpl::FindPrivateKey(
crypto::RSAPrivateKey* OwnerKeyUtilsImpl::FindPrivateKey(
const std::vector<uint8>& key) {
return RSAPrivateKey::FindFromPublicKeyInfo(key);
return crypto::RSAPrivateKey::FindFromPublicKeyInfo(key);
}
FilePath OwnerKeyUtilsImpl::GetOwnerKeyFilePath() {
......
......@@ -15,7 +15,7 @@
class FilePath;
namespace base {
namespace crypto {
class RSAPrivateKey;
}
......@@ -60,12 +60,12 @@ class OwnerKeyUtils : public base::RefCounted<OwnerKeyUtils> {
// and populate |OUT_signature|.
virtual bool Sign(const std::string& data,
std::vector<uint8>* OUT_signature,
base::RSAPrivateKey* key) = 0;
crypto::RSAPrivateKey* key) = 0;
// Looks for the private key associated with |key| in the default slot,
// and returns it if it can be found. Returns NULL otherwise.
// Caller takes ownership.
virtual base::RSAPrivateKey* FindPrivateKey(
virtual crypto::RSAPrivateKey* FindPrivateKey(
const std::vector<uint8>& key) = 0;
virtual FilePath GetOwnerKeyFilePath() = 0;
......@@ -76,7 +76,7 @@ class OwnerKeyUtils : public base::RefCounted<OwnerKeyUtils> {
// DER encodes public half of |pair| and writes it out to |key_file|.
// The blob on disk is a DER-encoded X509 SubjectPublicKeyInfo object.
// Returns false on error.
virtual bool ExportPublicKeyToFile(base::RSAPrivateKey* pair,
virtual bool ExportPublicKeyToFile(crypto::RSAPrivateKey* pair,
const FilePath& key_file) = 0;
private:
......
......@@ -7,13 +7,13 @@
#include <string>
#include <vector>
#include "base/crypto/rsa_private_key.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_temp_dir.h"
#include "base/nss_util.h"
#include "base/nss_util_internal.h"
#include "crypto/nss_util.h"
#include "crypto/nss_util_internal.h"
#include "crypto/rsa_private_key.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -25,7 +25,7 @@ class OwnerKeyUtilsTest : public ::testing::Test {
virtual ~OwnerKeyUtilsTest() {}
virtual void SetUp() {
base::OpenPersistentNSSDB();
crypto::OpenPersistentNSSDB();
}
// Key generation parameters.
......@@ -39,9 +39,9 @@ class OwnerKeyUtilsTest : public ::testing::Test {
const uint16 OwnerKeyUtilsTest::kKeySizeInBits = 2048;
TEST_F(OwnerKeyUtilsTest, ExportImportPublicKey) {
scoped_ptr<base::RSAPrivateKey> pair(
base::RSAPrivateKey::CreateSensitive(kKeySizeInBits));
ASSERT_NE(pair.get(), reinterpret_cast<base::RSAPrivateKey*>(NULL));
scoped_ptr<crypto::RSAPrivateKey> pair(
crypto::RSAPrivateKey::CreateSensitive(kKeySizeInBits));
ASSERT_NE(pair.get(), reinterpret_cast<crypto::RSAPrivateKey*>(NULL));
// Export public key to file.
ScopedTempDir tmpdir;
......
......@@ -9,8 +9,8 @@
#include <vector>
#include "base/basictypes.h"
#include "base/crypto/rsa_private_key.h"
#include "base/memory/ref_counted.h"
#include "crypto/rsa_private_key.h"
#include "chrome/browser/chromeos/login/owner_key_utils.h"
#include "content/browser/browser_thread.h"
......@@ -89,7 +89,7 @@ class OwnerManager : public base::RefCountedThreadSafe<OwnerManager> {
d->OnKeyOpComplete(return_code, payload);
}
scoped_ptr<base::RSAPrivateKey> private_key_;
scoped_ptr<crypto::RSAPrivateKey> private_key_;
std::vector<uint8> public_key_;
scoped_refptr<OwnerKeyUtils> utils_;
......
......@@ -7,18 +7,18 @@
#include <string>
#include "base/crypto/rsa_private_key.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_temp_dir.h"
#include "base/nss_util.h"
#include "crypto/nss_util.h"
#include "crypto/rsa_private_key.h"
#include "chrome/browser/chromeos/login/mock_owner_key_utils.h"
#include "content/browser/browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::base::RSAPrivateKey;
using ::crypto::RSAPrivateKey;
using ::testing::DoAll;
using ::testing::Eq;
using ::testing::Invoke;
......@@ -40,7 +40,7 @@ class OwnerManagerTest : public ::testing::Test {
virtual ~OwnerManagerTest() {}
virtual void SetUp() {
base::OpenPersistentNSSDB(); // TODO(cmasone): use test DB instead
crypto::OpenPersistentNSSDB(); // TODO(cmasone): use test DB instead
fake_private_key_.reset(RSAPrivateKey::Create(256));
ASSERT_TRUE(fake_private_key_->ExportPublicKey(&fake_public_key_));
......
......@@ -6,20 +6,20 @@
#include <string>
#include "base/crypto/rsa_private_key.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_temp_dir.h"
#include "base/nss_util.h"