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 /extensions | |
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
Diffstat (limited to 'extensions')
-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/common/crx_file.cc | 81 | ||||
-rw-r--r-- | extensions/common/crx_file.h | 79 | ||||
-rw-r--r-- | extensions/extensions.gyp | 3 |
6 files changed, 2 insertions, 171 deletions
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/common/crx_file.cc b/extensions/common/crx_file.cc deleted file mode 100644 index 73e7f7b..0000000 --- a/extensions/common/crx_file.cc +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) 2012 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" - -namespace extensions { - -namespace { - -// The current version of the crx format. -static const uint32 kCurrentVersion = 2; - -// The current version of the crx diff format. -static const uint32 kCurrentDiffVersion = 0; - -// The maximum size the crx parser will tolerate for a public key. -static const uint32 kMaxPublicKeySize = 1 << 16; - -// The maximum size the crx parser will tolerate for a signature. -static const uint32 kMaxSignatureSize = 1 << 16; - -} // namespace - -// The magic string embedded in the header. -const char kCrxFileHeaderMagic[] = "Cr24"; -const char kCrxDiffFileHeaderMagic[] = "CrOD"; - -scoped_ptr<CrxFile> CrxFile::Parse(const CrxFile::Header& header, - CrxFile::Error* error) { - if (HeaderIsValid(header, error)) - return scoped_ptr<CrxFile>(new CrxFile(header)); - return scoped_ptr<CrxFile>(); -} - -scoped_ptr<CrxFile> CrxFile::Create(const uint32 key_size, - const uint32 signature_size, - CrxFile::Error* error) { - CrxFile::Header header; - memcpy(&header.magic, kCrxFileHeaderMagic, kCrxFileHeaderMagicSize); - header.version = kCurrentVersion; - header.key_size = key_size; - header.signature_size = signature_size; - if (HeaderIsValid(header, error)) - return scoped_ptr<CrxFile>(new CrxFile(header)); - return scoped_ptr<CrxFile>(); -} - -CrxFile::CrxFile(const Header& header) : header_(header) { -} - -bool CrxFile::HeaderIsDelta(const CrxFile::Header& header) { - return !strncmp(kCrxDiffFileHeaderMagic, header.magic, sizeof(header.magic)); -} - -bool CrxFile::HeaderIsValid(const CrxFile::Header& header, - CrxFile::Error* error) { - bool valid = false; - bool diffCrx = false; - if (!strncmp(kCrxDiffFileHeaderMagic, header.magic, sizeof(header.magic))) - diffCrx = true; - if (strncmp(kCrxFileHeaderMagic, header.magic, sizeof(header.magic)) && - !diffCrx) - *error = kWrongMagic; - else if (header.version != kCurrentVersion - && !(diffCrx && header.version == kCurrentDiffVersion)) - *error = kInvalidVersion; - else if (header.key_size > kMaxPublicKeySize) - *error = kInvalidKeyTooLarge; - else if (header.key_size == 0) - *error = kInvalidKeyTooSmall; - else if (header.signature_size > kMaxSignatureSize) - *error = kInvalidSignatureTooLarge; - else if (header.signature_size == 0) - *error = kInvalidSignatureTooSmall; - else - valid = true; - return valid; -} - -} // namespace extensions diff --git a/extensions/common/crx_file.h b/extensions/common/crx_file.h deleted file mode 100644 index d7c33ab..0000000 --- a/extensions/common/crx_file.h +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) 2012 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_ - -#include <sys/types.h> -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" - -namespace extensions { - -// CRX files have a header that includes a magic key, version number, and -// some signature sizing information. Use CrxFile object to validate whether -// the header is valid or not. -class CrxFile { - public: - // The size of the magic character sequence at the beginning of each crx - // file, in bytes. This should be a multiple of 4. - static const size_t kCrxFileHeaderMagicSize = 4; - - // This header is the first data at the beginning of an extension. Its - // contents are purposely 32-bit aligned so that it can just be slurped into - // a struct without manual parsing. - struct Header { - char magic[kCrxFileHeaderMagicSize]; - uint32 version; - uint32 key_size; // The size of the public key, in bytes. - uint32 signature_size; // The size of the signature, in bytes. - // An ASN.1-encoded PublicKeyInfo structure follows. - // The signature follows. - }; - - enum Error { - kWrongMagic, - kInvalidVersion, - kInvalidKeyTooLarge, - kInvalidKeyTooSmall, - kInvalidSignatureTooLarge, - kInvalidSignatureTooSmall, - }; - - // Construct a new CRX file header object with bytes of a header - // read from a CRX file. If a null scoped_ptr is returned, |error| - // contains an error code with additional information. - static scoped_ptr<CrxFile> Parse(const Header& header, Error* error); - - // Construct a new header for the given key and signature sizes. - // Returns a null scoped_ptr if erroneous values of |key_size| and/or - // |signature_size| are provided. |error| contains an error code with - // additional information. - // Use this constructor and then .header() to obtain the Header - // for writing out to a CRX file. - static scoped_ptr<CrxFile> Create(const uint32 key_size, - const uint32 signature_size, - Error* error); - - // Returns the header structure for writing out to a CRX file. - const Header& header() const { return header_; } - - // Checks a valid |header| to determine whether or not the CRX represents a - // differential CRX. - static bool HeaderIsDelta(const Header& header); - - private: - Header header_; - - // Constructor is private. Clients should use static factory methods above. - explicit CrxFile(const Header& header); - - // Checks the |header| for validity and returns true if the values are valid. - // If false is returned, more detailed error code is returned in |error|. - static bool HeaderIsValid(const Header& header, Error* error); -}; - -} // namespace extensions - -#endif // EXTENSIONS_COMMON_CRX_FILE_H_ 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', |