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