Home | History | Annotate | Download | only in component_updater
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_
      6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 #include "base/basictypes.h"
     11 #include "base/files/file_path.h"
     12 
     13 class ComponentInstaller;
     14 class ComponentPatcher;
     15 
     16 // In charge of unpacking the component CRX package and verifying that it is
     17 // well formed and the cryptographic signature is correct. If there is no
     18 // error the component specific installer will be invoked to proceed with
     19 // the component installation or update.
     20 //
     21 // This class should be used only by the component updater. It is inspired
     22 // and overlaps with code in the extension's SandboxedUnpacker.
     23 // The main differences are:
     24 // - The public key hash is full SHA256.
     25 // - Does not use a sandboxed unpacker. A valid component is fully trusted.
     26 // - The manifest can have different attributes and resources are not
     27 //   transcoded.
     28 class ComponentUnpacker {
     29  public:
     30   // Possible error conditions.
     31   // Add only to the bottom of this enum; the order must be kept stable.
     32   enum Error {
     33     kNone,
     34     kInvalidParams,
     35     kInvalidFile,
     36     kUnzipPathError,
     37     kUnzipFailed,
     38     kNoManifest,
     39     kBadManifest,
     40     kBadExtension,
     41     kInvalidId,
     42     kInstallerError,
     43     kIoError,
     44     kDeltaVerificationFailure,
     45     kDeltaBadCommands,
     46     kDeltaUnsupportedCommand,
     47     kDeltaOperationFailure,
     48     kDeltaPatchProcessFailure,
     49     kDeltaMissingExistingFile,
     50     kFingerprintWriteFailed,
     51   };
     52   // Unpacks, verifies and calls the installer. |pk_hash| is the expected
     53   // public key SHA256 hash. |path| is the current location of the CRX.
     54   ComponentUnpacker(const std::vector<uint8>& pk_hash,
     55                     const base::FilePath& path,
     56                     const std::string& fingerprint,
     57                     ComponentPatcher* patcher,
     58                     ComponentInstaller* installer);
     59 
     60   // If something went wrong during unpacking or installer invocation, the
     61   // destructor will delete the unpacked CRX files.
     62   ~ComponentUnpacker();
     63 
     64   Error error() const { return error_; }
     65 
     66   int extended_error() const { return extended_error_; }
     67 
     68  private:
     69   base::FilePath unpack_path_;
     70   Error error_;
     71   int extended_error_;  // Provides additional error information.
     72 };
     73 
     74 #endif  // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_
     75