Commit 8c83fe07 authored by tommycli@chromium.org's avatar tommycli@chromium.org

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
parent 41e4e2ad
include_rules = [
"+components/component_updater",
"+components/crx_file",
"+media/cdm/ppapi/supported_cdm_versions.h",
"+ppapi/thunk",
"+third_party/widevine"
......
......@@ -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;
......
......@@ -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],
......
......@@ -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;
}
......
......@@ -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.
......
......@@ -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";
......
......@@ -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(),
......
......@@ -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(),
......
......@@ -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',
......
......@@ -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',
......
# 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',
],
},
],
}
// 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_
// 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
// 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_
include_rules = [
# Do not add Chrome dependencies. Much work went into removing them.
"+components/crx_file",
"+components/url_matcher",
"-content",
"+content/public/common",
......
......@@ -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",
......
......@@ -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 {
......
......@@ -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',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment