diff options
author | tommycli@chromium.org <tommycli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-15 19:07:35 +0000 |
---|---|---|
committer | tommycli@chromium.org <tommycli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-15 19:09:03 +0000 |
commit | 8c83fe076ebe86c04e6d703be2bfb2f2e8729158 (patch) | |
tree | 268331ca7a39e75a7e9aeabd3d7cf2ca923156b3 | |
parent | 41e4e2adfd63eadf7c2067654863ff558a9cd70f (diff) | |
download | chromium_src-8c83fe076ebe86c04e6d703be2bfb2f2e8729158.zip chromium_src-8c83fe076ebe86c04e6d703be2bfb2f2e8729158.tar.gz chromium_src-8c83fe076ebe86c04e6d703be2bfb2f2e8729158.tar.bz2 |
Componentize component_updater: Split crx_file code off into its own component.
CRX file code currently lives under extensions/. However,
component_updater also uses them to package components. The
CRX code should therefore live as its own component.
BUG=371463
TBR=blundell@chromium.org
Review URL: https://codereview.chromium.org/474633005
Cr-Commit-Position: refs/heads/master@{#289966}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289966 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/component_updater/DEPS | 1 | ||||
-rw-r--r-- | chrome/browser/component_updater/component_patcher_operation.cc | 1 | ||||
-rw-r--r-- | chrome/browser/component_updater/component_unpacker.cc | 18 | ||||
-rw-r--r-- | chrome/browser/component_updater/component_updater_utils.cc | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/DEPS | 1 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_creator.cc | 10 | ||||
-rw-r--r-- | chrome/browser/extensions/install_signer.cc | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/sandboxed_unpacker.cc | 8 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 3 | ||||
-rw-r--r-- | components/components.gyp | 1 | ||||
-rw-r--r-- | components/crx_file.gypi | 26 | ||||
-rw-r--r-- | components/crx_file/constants.h | 21 | ||||
-rw-r--r-- | components/crx_file/crx_file.cc (renamed from extensions/common/crx_file.cc) | 8 | ||||
-rw-r--r-- | components/crx_file/crx_file.h (renamed from extensions/common/crx_file.h) | 12 | ||||
-rw-r--r-- | extensions/DEPS | 1 | ||||
-rw-r--r-- | extensions/common/BUILD.gn | 2 | ||||
-rw-r--r-- | extensions/common/constants.h | 7 | ||||
-rw-r--r-- | extensions/extensions.gyp | 3 |
18 files changed, 90 insertions, 45 deletions
diff --git a/chrome/browser/component_updater/DEPS b/chrome/browser/component_updater/DEPS index cb4f58d..7b7f9e9 100644 --- a/chrome/browser/component_updater/DEPS +++ b/chrome/browser/component_updater/DEPS @@ -1,5 +1,6 @@ include_rules = [ "+components/component_updater", + "+components/crx_file", "+media/cdm/ppapi/supported_cdm_versions.h", "+ppapi/thunk", "+third_party/widevine" diff --git a/chrome/browser/component_updater/component_patcher_operation.cc b/chrome/browser/component_updater/component_patcher_operation.cc index 5fd0986..e522dd2 100644 --- a/chrome/browser/component_updater/component_patcher_operation.cc +++ b/chrome/browser/component_updater/component_patcher_operation.cc @@ -18,7 +18,6 @@ #include "crypto/secure_hash.h" #include "crypto/sha2.h" #include "crypto/signature_verifier.h" -#include "extensions/common/crx_file.h" using crypto::SecureHash; diff --git a/chrome/browser/component_updater/component_unpacker.cc b/chrome/browser/component_updater/component_unpacker.cc index 67c6616..74e8a8e 100644 --- a/chrome/browser/component_updater/component_unpacker.cc +++ b/chrome/browser/component_updater/component_unpacker.cc @@ -20,10 +20,10 @@ #include "chrome/browser/component_updater/component_patcher.h" #include "chrome/browser/component_updater/component_patcher_operation.h" #include "chrome/browser/component_updater/component_updater_service.h" +#include "components/crx_file/constants.h" +#include "components/crx_file/crx_file.h" #include "crypto/secure_hash.h" #include "crypto/signature_verifier.h" -#include "extensions/common/constants.h" -#include "extensions/common/crx_file.h" #include "third_party/zlib/google/zip.h" using crypto::SecureHash; @@ -37,17 +37,17 @@ namespace { class CRXValidator { public: explicit CRXValidator(FILE* crx_file) : valid_(false), is_delta_(false) { - extensions::CrxFile::Header header; + crx_file::CrxFile::Header header; size_t len = fread(&header, 1, sizeof(header), crx_file); if (len < sizeof(header)) return; - extensions::CrxFile::Error error; - scoped_ptr<extensions::CrxFile> crx( - extensions::CrxFile::Parse(header, &error)); + crx_file::CrxFile::Error error; + scoped_ptr<crx_file::CrxFile> crx( + crx_file::CrxFile::Parse(header, &error)); if (!crx.get()) return; - is_delta_ = extensions::CrxFile::HeaderIsDelta(header); + is_delta_ = crx_file::CrxFile::HeaderIsDelta(header); std::vector<uint8> key(header.key_size); len = fread(&key[0], sizeof(uint8), header.key_size, crx_file); @@ -60,8 +60,8 @@ class CRXValidator { return; crypto::SignatureVerifier verifier; - if (!verifier.VerifyInit(extension_misc::kSignatureAlgorithm, - sizeof(extension_misc::kSignatureAlgorithm), + if (!verifier.VerifyInit(crx_file::kSignatureAlgorithm, + sizeof(crx_file::kSignatureAlgorithm), &signature[0], signature.size(), &key[0], diff --git a/chrome/browser/component_updater/component_updater_utils.cc b/chrome/browser/component_updater/component_updater_utils.cc index 051a8e9..a3b2038 100644 --- a/chrome/browser/component_updater/component_updater_utils.cc +++ b/chrome/browser/component_updater/component_updater_utils.cc @@ -18,7 +18,6 @@ #include "chrome/browser/component_updater/component_updater_configurator.h" #include "chrome/browser/component_updater/crx_update_item.h" #include "components/omaha_query_params/omaha_query_params.h" -#include "extensions/common/extension.h" #include "net/base/load_flags.h" #include "net/url_request/url_fetcher.h" #include "net/url_request/url_request_context_getter.h" @@ -181,7 +180,10 @@ std::string HexStringToID(const std::string& hexstr) { id.append(1, 'a'); } } - DCHECK(extensions::Extension::IdIsValid(id)); + + // TODO(tommycli): Add back the DCHECK validating the generated id. This + // requires moving the extension id_util functions into components/crx_file. + return id; } diff --git a/chrome/browser/extensions/DEPS b/chrome/browser/extensions/DEPS index 8e06baf..a91962e 100644 --- a/chrome/browser/extensions/DEPS +++ b/chrome/browser/extensions/DEPS @@ -7,6 +7,7 @@ include_rules = [ "+apps/app_window.h", "+apps/app_window_registry.h", "-chrome/browser/apps", + "+components/crx_file", "+components/user_manager", # For access to testing command line switches. diff --git a/chrome/browser/extensions/extension_creator.cc b/chrome/browser/extensions/extension_creator.cc index ca91851..f6cc4bd 100644 --- a/chrome/browser/extensions/extension_creator.cc +++ b/chrome/browser/extensions/extension_creator.cc @@ -14,9 +14,9 @@ #include "base/files/scoped_temp_dir.h" #include "base/strings/string_util.h" #include "chrome/browser/extensions/extension_creator_filter.h" +#include "components/crx_file/crx_file.h" #include "crypto/rsa_private_key.h" #include "crypto/signature_creator.h" -#include "extensions/common/crx_file.h" #include "extensions/common/extension.h" #include "extensions/common/file_util.h" #include "extensions/common/id_util.h" @@ -249,13 +249,13 @@ bool ExtensionCreator::WriteCRX(const base::FilePath& zip_path, std::vector<uint8> public_key; CHECK(private_key->ExportPublicKey(&public_key)); - CrxFile::Error error; - scoped_ptr<CrxFile> crx( - CrxFile::Create(public_key.size(), signature.size(), &error)); + crx_file::CrxFile::Error error; + scoped_ptr<crx_file::CrxFile> crx( + crx_file::CrxFile::Create(public_key.size(), signature.size(), &error)); if (!crx) { LOG(ERROR) << "cannot create CrxFileHeader: " << error; } - const CrxFile::Header header = crx->header(); + const crx_file::CrxFile::Header header = crx->header(); if (fwrite(&header, sizeof(header), 1, crx_handle.get()) != 1) { PLOG(ERROR) << "fwrite failed to write header"; diff --git a/chrome/browser/extensions/install_signer.cc b/chrome/browser/extensions/install_signer.cc index b2b9c0a..643e0ff 100644 --- a/chrome/browser/extensions/install_signer.cc +++ b/chrome/browser/extensions/install_signer.cc @@ -21,11 +21,11 @@ #include "base/time/time.h" #include "base/values.h" #include "chrome/common/chrome_switches.h" +#include "components/crx_file/constants.h" #include "crypto/random.h" #include "crypto/secure_hash.h" #include "crypto/sha2.h" #include "crypto/signature_verifier.h" -#include "extensions/common/constants.h" #include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher_delegate.h" #include "net/url_request/url_request_context_getter.h" @@ -253,8 +253,8 @@ bool InstallSigner::VerifySignature(const InstallSignature& signature) { return false; crypto::SignatureVerifier verifier; - if (!verifier.VerifyInit(extension_misc::kSignatureAlgorithm, - sizeof(extension_misc::kSignatureAlgorithm), + if (!verifier.VerifyInit(crx_file::kSignatureAlgorithm, + sizeof(crx_file::kSignatureAlgorithm), reinterpret_cast<const uint8*>( signature.signature.data()), signature.signature.size(), diff --git a/chrome/browser/extensions/sandboxed_unpacker.cc b/chrome/browser/extensions/sandboxed_unpacker.cc index f54c41d..bfdc115 100644 --- a/chrome/browser/extensions/sandboxed_unpacker.cc +++ b/chrome/browser/extensions/sandboxed_unpacker.cc @@ -26,12 +26,13 @@ #include "chrome/common/chrome_utility_messages.h" #include "chrome/common/extensions/chrome_utility_extensions_messages.h" #include "chrome/common/extensions/extension_file_util.h" +#include "components/crx_file/constants.h" +#include "components/crx_file/crx_file.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/utility_process_host.h" #include "content/public/common/common_param_traits.h" #include "crypto/signature_verifier.h" #include "extensions/common/constants.h" -#include "extensions/common/crx_file.h" #include "extensions/common/extension.h" #include "extensions/common/extension_l10n_util.h" #include "extensions/common/file_util.h" @@ -46,6 +47,7 @@ using base::ASCIIToUTF16; using content::BrowserThread; using content::UtilityProcessHost; +using crx_file::CrxFile; // The following macro makes histograms that record the length of paths // in this file much easier to read. @@ -543,8 +545,8 @@ bool SandboxedUnpacker::ValidateSignature() { } crypto::SignatureVerifier verifier; - if (!verifier.VerifyInit(extension_misc::kSignatureAlgorithm, - sizeof(extension_misc::kSignatureAlgorithm), + if (!verifier.VerifyInit(crx_file::kSignatureAlgorithm, + sizeof(crx_file::kSignatureAlgorithm), &signature.front(), signature.size(), &key.front(), diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index c788c99..746e54f 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2864,7 +2864,9 @@ '../components/components.gyp:captive_portal', '../components/components.gyp:cloud_devices_common', '../components/components.gyp:component_metrics_proto', + '../components/components.gyp:component_updater', '../components/components.gyp:content_settings_core_common', + '../components/components.gyp:crx_file', '../components/components.gyp:data_reduction_proxy_browser', '../components/components.gyp:domain_reliability', '../components/components.gyp:favicon_base', @@ -2959,7 +2961,6 @@ '../third_party/re2/re2.gyp:re2', '../cc/cc.gyp:cc', '../components/components.gyp:autofill_content_browser', - '../components/components.gyp:component_updater', '../components/components.gyp:dom_distiller_content', '../components/components.gyp:keyed_service_content', '../components/components.gyp:navigation_interception', diff --git a/components/components.gyp b/components/components.gyp index 2d75d9b..6d864c3 100644 --- a/components/components.gyp +++ b/components/components.gyp @@ -19,6 +19,7 @@ 'component_updater.gypi', 'content_settings.gypi', 'cronet.gypi', + 'crx_file.gypi', 'data_reduction_proxy.gypi', 'dom_distiller.gypi', 'domain_reliability.gypi', diff --git a/components/crx_file.gypi b/components/crx_file.gypi new file mode 100644 index 0000000..07a0487 --- /dev/null +++ b/components/crx_file.gypi @@ -0,0 +1,26 @@ +# 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. + +{ + 'targets': [ + { + 'target_name': 'crx_file', + 'type': 'static_library', + 'dependencies': [ + '../base/base.gyp:base', + ], + 'include_dirs': [ + '..', + ], + 'defines': [ + 'CRX_FILE_IMPLEMENTATION', + ], + 'sources': [ + 'crx_file/constants.h', + 'crx_file/crx_file.cc', + 'crx_file/crx_file.h', + ], + }, + ], +} diff --git a/components/crx_file/constants.h b/components/crx_file/constants.h new file mode 100644 index 0000000..cae0bc3 --- /dev/null +++ b/components/crx_file/constants.h @@ -0,0 +1,21 @@ +// 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_CRX_FILE_CONSTANTS_H_ +#define COMPONENTS_CRX_FILE_CONSTANTS_H_ + +#include "base/basictypes.h" + +namespace crx_file { + +// Note: this structure is an ASN.1 which encodes the algorithm used +// with its parameters. This is defined in PKCS #1 v2.1 (RFC 3447). +// It is encoding: { OID sha1WithRSAEncryption PARAMETERS NULL } +const uint8 kSignatureAlgorithm[15] = {0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, + 0x01, 0x01, 0x05, 0x05, 0x00}; + +} // namespace crx_file + +#endif // COMPONENTS_CRX_FILE_CONSTANTS_H_ diff --git a/extensions/common/crx_file.cc b/components/crx_file/crx_file.cc index 73e7f7b..391d549 100644 --- a/extensions/common/crx_file.cc +++ b/components/crx_file/crx_file.cc @@ -1,10 +1,10 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// 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. -#include "extensions/common/crx_file.h" +#include "components/crx_file/crx_file.h" -namespace extensions { +namespace crx_file { namespace { @@ -78,4 +78,4 @@ bool CrxFile::HeaderIsValid(const CrxFile::Header& header, return valid; } -} // namespace extensions +} // namespace crx_file diff --git a/extensions/common/crx_file.h b/components/crx_file/crx_file.h index d7c33ab..55e4c39 100644 --- a/extensions/common/crx_file.h +++ b/components/crx_file/crx_file.h @@ -1,15 +1,15 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// 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 EXTENSIONS_COMMON_CRX_FILE_H_ -#define EXTENSIONS_COMMON_CRX_FILE_H_ +#ifndef COMPONENTS_CRX_FILE_CRX_FILE_H_ +#define COMPONENTS_CRX_FILE_CRX_FILE_H_ #include <sys/types.h> #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" -namespace extensions { +namespace crx_file { // CRX files have a header that includes a magic key, version number, and // some signature sizing information. Use CrxFile object to validate whether @@ -74,6 +74,6 @@ class CrxFile { static bool HeaderIsValid(const Header& header, Error* error); }; -} // namespace extensions +} // namespace crx_file -#endif // EXTENSIONS_COMMON_CRX_FILE_H_ +#endif // COMPONENTS_CRX_FILE_CRX_FILE_H_ diff --git a/extensions/DEPS b/extensions/DEPS index fede72f..7e2496a 100644 --- a/extensions/DEPS +++ b/extensions/DEPS @@ -1,5 +1,6 @@ include_rules = [ # Do not add Chrome dependencies. Much work went into removing them. + "+components/crx_file", "+components/url_matcher", "-content", "+content/public/common", diff --git a/extensions/common/BUILD.gn b/extensions/common/BUILD.gn index be874e4..204d9db 100644 --- a/extensions/common/BUILD.gn +++ b/extensions/common/BUILD.gn @@ -18,8 +18,6 @@ source_set("common") { "common_manifest_handlers.h", "constants.cc", "constants.h", - "crx_file.cc", - "crx_file.h", "csp_validator.cc", "csp_validator.h", "dom_action_types.h", diff --git a/extensions/common/constants.h b/extensions/common/constants.h index 66fe2ba..3dde500 100644 --- a/extensions/common/constants.h +++ b/extensions/common/constants.h @@ -110,13 +110,6 @@ const int kUnknownWindowId = -1; // Matches chrome.windows.WINDOW_ID_CURRENT. const int kCurrentWindowId = -2; -// Note: this structure is an ASN.1 which encodes the algorithm used -// with its parameters. This is defined in PKCS #1 v2.1 (RFC 3447). -// It is encoding: { OID sha1WithRSAEncryption PARAMETERS NULL } -const uint8 kSignatureAlgorithm[15] = {0x30, 0x0d, 0x06, 0x09, 0x2a, - 0x86, 0x48, 0x86, 0xf7, 0x0d, - 0x01, 0x01, 0x05, 0x05, 0x00}; - // NOTE: If you change this list, you should also change kExtensionIconSizes // in cc file. enum ExtensionIcons { diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp index 29e865f..e86b5b5 100644 --- a/extensions/extensions.gyp +++ b/extensions/extensions.gyp @@ -16,6 +16,7 @@ # api resources compiled into the chrome resource bundle. # http://crbug.com/162530 '../chrome/chrome_resources.gyp:chrome_resources', + '../components/components.gyp:crx_file', '../components/components.gyp:url_matcher', '../content/content.gyp:content_common', '../crypto/crypto.gyp:crypto', @@ -48,8 +49,6 @@ 'common/common_manifest_handlers.h', 'common/constants.cc', 'common/constants.h', - 'common/crx_file.cc', - 'common/crx_file.h', 'common/csp_validator.cc', 'common/csp_validator.h', 'common/dom_action_types.h', |