[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
asargent | c4fdad2 | 2015-08-28 22:44:39 | [diff] [blame] | 5 | #ifndef EXTENSIONS_BROWSER_SANDBOXED_UNPACKER_H_ |
| 6 | #define EXTENSIONS_BROWSER_SANDBOXED_UNPACKER_H_ |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 7 | |
waffles | 5918d5f | 2017-05-23 01:45:28 | [diff] [blame] | 8 | #include <memory> |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 9 | #include <string> |
| 10 | |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 11 | #include "base/files/file_path.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 12 | #include "base/files/scoped_temp_dir.h" |
avi | c9cec10 | 2015-12-23 00:39:26 | [diff] [blame] | 13 | #include "base/macros.h" |
fdoray | 33d98b6 | 2016-12-23 14:02:52 | [diff] [blame] | 14 | #include "base/memory/ref_counted_delete_on_sequence.h" |
Oleg Davydov | 795d1b60 | 2020-01-02 09:44:27 | [diff] [blame] | 15 | #include "base/memory/scoped_refptr.h" |
asargent | c4fdad2 | 2015-08-28 22:44:39 | [diff] [blame] | 16 | #include "base/memory/weak_ptr.h" |
Karandeep Bhatia | a893065 | 2017-10-11 17:41:12 | [diff] [blame] | 17 | #include "base/optional.h" |
Jay Civelli | bed6dcd | 2018-01-25 00:08:24 | [diff] [blame] | 18 | #include "base/strings/string_piece.h" |
[email protected] | 41a17c5 | 2013-06-28 00:27:53 | [diff] [blame] | 19 | #include "base/time/time.h" |
Oksana Zhuravlova | 2378337 | 2018-04-24 18:47:49 | [diff] [blame] | 20 | #include "base/values.h" |
ginkage | 553af320 | 2015-02-04 12:39:09 | [diff] [blame] | 21 | #include "extensions/browser/crx_file_info.h" |
Jay Civelli | ea8f3df | 2018-01-24 05:17:32 | [diff] [blame] | 22 | #include "extensions/browser/image_sanitizer.h" |
ginkage | 47e603e | 2015-02-27 08:42:41 | [diff] [blame] | 23 | #include "extensions/browser/install/crx_install_error.h" |
Jay Civelli | 6d0e68e | 2018-01-24 16:42:53 | [diff] [blame] | 24 | #include "extensions/browser/json_file_sanitizer.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 25 | #include "extensions/common/manifest.h" |
Miyoung Shin | 364c657 | 2019-09-11 09:02:19 | [diff] [blame] | 26 | #include "mojo/public/cpp/bindings/remote.h" |
Ken Rockot | dc32df89 | 2019-11-01 06:32:10 | [diff] [blame] | 27 | #include "services/data_decoder/public/cpp/data_decoder.h" |
Ken Rockot | 19db638 | 2018-02-10 01:41:02 | [diff] [blame] | 28 | #include "services/data_decoder/public/mojom/json_parser.mojom.h" |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 29 | |
[email protected] | 3d8eb9f | 2013-07-11 23:37:25 | [diff] [blame] | 30 | class SkBitmap; |
| 31 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 32 | namespace base { |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 33 | class SequencedTaskRunner; |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 34 | } |
| 35 | |
Joshua Pawlicki | fd01b7c | 2019-01-17 16:18:34 | [diff] [blame] | 36 | namespace crx_file { |
| 37 | enum class VerifierFormat; |
| 38 | } |
| 39 | |
[email protected] | f5ac274 | 2012-07-02 17:50:58 | [diff] [blame] | 40 | namespace extensions { |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 41 | class Extension; |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 42 | enum class SandboxedUnpackerFailureReason; |
[email protected] | f5ac274 | 2012-07-02 17:50:58 | [diff] [blame] | 43 | |
Karan Bhatia | 23e67edd | 2018-06-26 20:43:01 | [diff] [blame] | 44 | namespace declarative_net_request { |
Karan Bhatia | 8134835 | 2019-03-25 22:50:01 | [diff] [blame] | 45 | struct IndexAndPersistJSONRulesetResult; |
Karan Bhatia | 23e67edd | 2018-06-26 20:43:01 | [diff] [blame] | 46 | } |
| 47 | |
[email protected] | f5ac274 | 2012-07-02 17:50:58 | [diff] [blame] | 48 | class SandboxedUnpackerClient |
fdoray | 33d98b6 | 2016-12-23 14:02:52 | [diff] [blame] | 49 | : public base::RefCountedDeleteOnSequence<SandboxedUnpackerClient> { |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 50 | public: |
tapted | 1e394abd | 2015-04-15 23:22:25 | [diff] [blame] | 51 | // Initialize the ref-counted base to always delete on the UI thread. Note |
| 52 | // the constructor call must also happen on the UI thread. |
| 53 | SandboxedUnpackerClient(); |
| 54 | |
Oleg Davydov | 795d1b60 | 2020-01-02 09:44:27 | [diff] [blame] | 55 | // Determines whether |extension| requires computing and storing |
| 56 | // computed_hashes.json and returns the result through |callback|. |
| 57 | // Currently we do this only for force-installed extensions outside of Chrome |
| 58 | // Web Store, and that is reflected in method's name. |
| 59 | virtual void ShouldComputeHashesForOffWebstoreExtension( |
| 60 | scoped_refptr<const Extension> extension, |
| 61 | base::OnceCallback<void(bool)> callback); |
| 62 | |
[email protected] | 9428edc | 2009-11-18 18:02:47 | [diff] [blame] | 63 | // temp_dir - A temporary directory containing the results of the extension |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 64 | // unpacking. The client is responsible for deleting this directory. |
| 65 | // |
| 66 | // extension_root - The path to the extension root inside of temp_dir. |
| 67 | // |
[email protected] | ad93c6ba | 2011-05-26 04:48:33 | [diff] [blame] | 68 | // original_manifest - The parsed but unmodified version of the manifest, |
| 69 | // with no modifications such as localization, etc. |
| 70 | // |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 71 | // extension - The extension that was unpacked. The client is responsible |
| 72 | // for deleting this memory. |
[email protected] | 3d8eb9f | 2013-07-11 23:37:25 | [diff] [blame] | 73 | // |
| 74 | // install_icon - The icon we will display in the installation UI, if any. |
Karandeep Bhatia | a893065 | 2017-10-11 17:41:12 | [diff] [blame] | 75 | // |
| 76 | // dnr_ruleset_checksum - Checksum for the indexed ruleset corresponding to |
| 77 | // the Declarative Net Request API. Optional since it's only valid for |
| 78 | // extensions which provide a declarative ruleset. |
Karan Bhatia | f4859e369 | 2018-06-21 05:57:42 | [diff] [blame] | 79 | // |
| 80 | // Note: OnUnpackSuccess/Failure may be called either synchronously or |
| 81 | // asynchronously from SandboxedUnpacker::StartWithCrx/Directory. |
lazyboy | 6cff6b18 | 2017-03-30 18:43:49 | [diff] [blame] | 82 | virtual void OnUnpackSuccess( |
| 83 | const base::FilePath& temp_dir, |
| 84 | const base::FilePath& extension_root, |
| 85 | std::unique_ptr<base::DictionaryValue> original_manifest, |
| 86 | const Extension* extension, |
Karandeep Bhatia | a893065 | 2017-10-11 17:41:12 | [diff] [blame] | 87 | const SkBitmap& install_icon, |
| 88 | const base::Optional<int>& dnr_ruleset_checksum) = 0; |
ginkage | 47e603e | 2015-02-27 08:42:41 | [diff] [blame] | 89 | virtual void OnUnpackFailure(const CrxInstallError& error) = 0; |
[email protected] | 8de85a6 | 2009-11-06 08:32:17 | [diff] [blame] | 90 | |
| 91 | protected: |
fdoray | 33d98b6 | 2016-12-23 14:02:52 | [diff] [blame] | 92 | friend class base::RefCountedDeleteOnSequence<SandboxedUnpackerClient>; |
tapted | 1e394abd | 2015-04-15 23:22:25 | [diff] [blame] | 93 | friend class base::DeleteHelper<SandboxedUnpackerClient>; |
[email protected] | 8de85a6 | 2009-11-06 08:32:17 | [diff] [blame] | 94 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 95 | virtual ~SandboxedUnpackerClient() = default; |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 96 | }; |
| 97 | |
asargent | c4fdad2 | 2015-08-28 22:44:39 | [diff] [blame] | 98 | // SandboxedUnpacker does work to optionally unpack and then validate/sanitize |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 99 | // an extension, either starting from a crx file, or else an already unzipped |
Jay Civelli | b6f2cc9c | 2018-03-10 01:13:57 | [diff] [blame] | 100 | // directory (eg., from a differential update). The parsing of complex data |
| 101 | // formats like JPEG or JSON is performed in specific, sandboxed services. |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 102 | // |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 103 | // Unpacking an extension using this class makes changes to its source, such as |
| 104 | // transcoding all images to PNG, parsing all message catalogs, and rewriting |
| 105 | // the manifest JSON. As such, it should not be used when the output is not |
| 106 | // intended to be given back to the author. |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 107 | // |
| 108 | // Lifetime management: |
| 109 | // |
Jay Civelli | b6f2cc9c | 2018-03-10 01:13:57 | [diff] [blame] | 110 | // This class is ref-counted by each call it makes to itself on another thread. |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 111 | // |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 112 | // Additionally, we hold a reference to our own client so that the client lives |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 113 | // long enough to receive the result of unpacking. |
| 114 | // |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 115 | // NOTE: This class should only be used on the FILE thread. |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 116 | // |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 117 | class SandboxedUnpacker : public base::RefCountedThreadSafe<SandboxedUnpacker> { |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 118 | public: |
Joshua Pawlicki | 1ca9a28 | 2019-04-18 13:56:48 | [diff] [blame] | 119 | // Overrides the required verifier format for testing purposes. Only one |
| 120 | // ScopedVerifierFormatOverrideForTest may exist at a time. |
| 121 | class ScopedVerifierFormatOverrideForTest { |
| 122 | public: |
| 123 | explicit ScopedVerifierFormatOverrideForTest( |
| 124 | crx_file::VerifierFormat format); |
| 125 | ~ScopedVerifierFormatOverrideForTest(); |
| 126 | }; |
| 127 | |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 128 | // Creates a SandboxedUnpacker that will do work to unpack an extension, |
asargent | c4fdad2 | 2015-08-28 22:44:39 | [diff] [blame] | 129 | // passing the |location| and |creation_flags| to Extension::Create. The |
| 130 | // |extensions_dir| parameter should specify the directory under which we'll |
| 131 | // create a subdirectory to write the unpacked extension contents. |
Devlin Cronin | b7a9717 | 2017-08-10 01:25:32 | [diff] [blame] | 132 | // Note: Because this requires disk I/O, the task runner passed should use |
| 133 | // TaskShutdownBehavior::SKIP_ON_SHUTDOWN to ensure that either the task is |
| 134 | // fully run (if initiated before shutdown) or not run at all (if shutdown is |
| 135 | // initiated first). See crbug.com/235525. |
| 136 | // TODO(devlin): We should probably just have SandboxedUnpacker use the common |
| 137 | // ExtensionFileTaskRunner, and not pass in a separate one. |
| 138 | // TODO(devlin): SKIP_ON_SHUTDOWN is also not quite sufficient for this. We |
| 139 | // should probably instead be using base::ImportantFileWriter or similar. |
dcheng | 605ef8d | 2014-08-28 18:29:44 | [diff] [blame] | 140 | SandboxedUnpacker( |
dcheng | 605ef8d | 2014-08-28 18:29:44 | [diff] [blame] | 141 | Manifest::Location location, |
| 142 | int creation_flags, |
| 143 | const base::FilePath& extensions_dir, |
| 144 | const scoped_refptr<base::SequencedTaskRunner>& unpacker_io_task_runner, |
| 145 | SandboxedUnpackerClient* client); |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 146 | |
asargent | c4fdad2 | 2015-08-28 22:44:39 | [diff] [blame] | 147 | // Start processing the extension, either from a CRX file or already unzipped |
| 148 | // in a directory. The client is called with the results. The directory form |
| 149 | // requires the id and base64-encoded public key (for insertion into the |
| 150 | // 'key' field of the manifest.json file). |
| 151 | void StartWithCrx(const CRXFileInfo& crx_info); |
| 152 | void StartWithDirectory(const std::string& extension_id, |
| 153 | const std::string& public_key_base64, |
| 154 | const base::FilePath& directory); |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 155 | |
| 156 | private: |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 157 | friend class base::RefCountedThreadSafe<SandboxedUnpacker>; |
[email protected] | 10735aa | 2011-01-31 14:41:18 | [diff] [blame] | 158 | |
[email protected] | f5ac274 | 2012-07-02 17:50:58 | [diff] [blame] | 159 | friend class SandboxedUnpackerTest; |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 160 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 161 | ~SandboxedUnpacker(); |
[email protected] | e60b649 | 2009-11-07 01:06:28 | [diff] [blame] | 162 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 163 | // Create |temp_dir_| used to unzip or unpack the extension in. |
| 164 | bool CreateTempDirectory(); |
[email protected] | 650852e | 2011-01-19 13:26:02 | [diff] [blame] | 165 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 166 | // Helper functions to simplify calling ReportFailure. |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 167 | base::string16 FailureReasonToString16( |
| 168 | const SandboxedUnpackerFailureReason reason); |
| 169 | void FailWithPackageError(const SandboxedUnpackerFailureReason reason); |
ginkage | 553af320 | 2015-02-04 12:39:09 | [diff] [blame] | 170 | |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 171 | // Validates the signature of the extension and extract the key to |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 172 | // |public_key_|. True if the signature validates, false otherwise. |
asargent | c4fdad2 | 2015-08-28 22:44:39 | [diff] [blame] | 173 | bool ValidateSignature(const base::FilePath& crx_path, |
Joshua Pawlicki | fd01b7c | 2019-01-17 16:18:34 | [diff] [blame] | 174 | const std::string& expected_hash, |
| 175 | const crx_file::VerifierFormat required_format); |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 176 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 177 | // Unzips the extension into directory. |
Jay Civelli | b6f2cc9c | 2018-03-10 01:13:57 | [diff] [blame] | 178 | void Unzip(const base::FilePath& crx_path, |
| 179 | const base::FilePath& unzipped_dir); |
| 180 | void UnzipDone(const base::FilePath& zip_file, |
| 181 | const base::FilePath& unzip_dir, |
| 182 | const std::string& error); |
[email protected] | 373c106 | 2011-06-09 21:11:51 | [diff] [blame] | 183 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 184 | // Unpacks the extension in directory and returns the manifest. |
| 185 | void Unpack(const base::FilePath& directory); |
Oksana Zhuravlova | 2378337 | 2018-04-24 18:47:49 | [diff] [blame] | 186 | void ReadManifestDone(base::Optional<base::Value> manifest, |
Jay Civelli | 26a8564 | 2018-01-26 21:29:39 | [diff] [blame] | 187 | const base::Optional<std::string>& error); |
Oleg Davydov | a4ffe6a | 2020-01-07 10:34:48 | [diff] [blame] | 188 | void UnpackExtensionSucceeded(base::Value manifest); |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 189 | |
Karan Bhatia | f4859e369 | 2018-06-21 05:57:42 | [diff] [blame] | 190 | // Helper which calls ReportFailure. |
| 191 | void ReportUnpackExtensionFailed(base::StringPiece error); |
Jay Civelli | bed6dcd | 2018-01-25 00:08:24 | [diff] [blame] | 192 | |
Oleg Davydov | a4ffe6a | 2020-01-07 10:34:48 | [diff] [blame] | 193 | void ImageSanitizationDone(ImageSanitizer::Status status, |
Jay Civelli | ea8f3df | 2018-01-24 05:17:32 | [diff] [blame] | 194 | const base::FilePath& path); |
| 195 | void ImageSanitizerDecodedImage(const base::FilePath& path, SkBitmap image); |
| 196 | |
Oleg Davydov | a4ffe6a | 2020-01-07 10:34:48 | [diff] [blame] | 197 | void ReadMessageCatalogs(); |
Jay Civelli | 6d0e68e | 2018-01-24 16:42:53 | [diff] [blame] | 198 | |
| 199 | void SanitizeMessageCatalogs( |
Jay Civelli | 6d0e68e | 2018-01-24 16:42:53 | [diff] [blame] | 200 | const std::set<base::FilePath>& message_catalog_paths); |
| 201 | |
Oleg Davydov | a4ffe6a | 2020-01-07 10:34:48 | [diff] [blame] | 202 | void MessageCatalogsSanitized(JsonFileSanitizer::Status status, |
Jay Civelli | 6d0e68e | 2018-01-24 16:42:53 | [diff] [blame] | 203 | const std::string& error_msg); |
| 204 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 205 | // Reports unpack success or failure, or unzip failure. |
Oleg Davydov | a4ffe6a | 2020-01-07 10:34:48 | [diff] [blame] | 206 | void ReportSuccess(); |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 207 | |
| 208 | // Puts a sanboxed unpacker failure in histogram |
| 209 | // Extensions.SandboxUnpackFailureReason. |
| 210 | void ReportFailure(const SandboxedUnpackerFailureReason reason, |
| 211 | const base::string16& error); |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 212 | |
[email protected] | 9428edc | 2009-11-18 18:02:47 | [diff] [blame] | 213 | // Overwrites original manifest with safe result from utility process. |
Oleg Davydov | a4ffe6a | 2020-01-07 10:34:48 | [diff] [blame] | 214 | // Returns nullopt on error. |
| 215 | base::Optional<base::Value> RewriteManifestFile(const base::Value& manifest); |
[email protected] | 9428edc | 2009-11-18 18:02:47 | [diff] [blame] | 216 | |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 217 | // Cleans up temp directory artifacts. |
| 218 | void Cleanup(); |
| 219 | |
Karan Bhatia | 23e67edd | 2018-06-26 20:43:01 | [diff] [blame] | 220 | // If a Declarative Net Request JSON ruleset is present, parses the JSON |
| 221 | // ruleset for the Declarative Net Request API and persists the indexed |
| 222 | // ruleset. |
Oleg Davydov | a4ffe6a | 2020-01-07 10:34:48 | [diff] [blame] | 223 | void IndexAndPersistJSONRulesetIfNeeded(); |
Karan Bhatia | 23e67edd | 2018-06-26 20:43:01 | [diff] [blame] | 224 | |
| 225 | void OnJSONRulesetIndexed( |
Karan Bhatia | 8134835 | 2019-03-25 22:50:01 | [diff] [blame] | 226 | declarative_net_request::IndexAndPersistJSONRulesetResult result); |
Karan Bhatia | 71f6a62 | 2017-10-02 19:39:10 | [diff] [blame] | 227 | |
Oleg Davydov | 795d1b60 | 2020-01-02 09:44:27 | [diff] [blame] | 228 | // Computed hashes: if requested (via ShouldComputeHashes callback in |
| 229 | // SandbloxedUnpackerClient), calculate hashes of all extensions' resources |
| 230 | // and writes them in _metadata/computed_hashes.json. This is used by content |
| 231 | // verification system for extensions outside of Chrome Web Store. |
Oleg Davydov | a4ffe6a | 2020-01-07 10:34:48 | [diff] [blame] | 232 | void CheckComputeHashes(); |
Oleg Davydov | 795d1b60 | 2020-01-02 09:44:27 | [diff] [blame] | 233 | |
Oleg Davydov | a4ffe6a | 2020-01-07 10:34:48 | [diff] [blame] | 234 | void MaybeComputeHashes(bool should_compute_hashes); |
Oleg Davydov | 795d1b60 | 2020-01-02 09:44:27 | [diff] [blame] | 235 | |
Jay Civelli | 26a8564 | 2018-01-26 21:29:39 | [diff] [blame] | 236 | // Returns a JsonParser that can be used on the |unpacker_io_task_runner|. |
| 237 | data_decoder::mojom::JsonParser* GetJsonParserPtr(); |
| 238 | |
| 239 | // Parses the JSON file at |path| and invokes |callback| when done. |callback| |
| 240 | // is called with a null parameter if parsing failed. |
| 241 | // This must be called from the |unpacker_io_task_runner_|. |
| 242 | void ParseJsonFile(const base::FilePath& path, |
| 243 | data_decoder::mojom::JsonParser::ParseCallback callback); |
| 244 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 245 | // If we unpacked a CRX file, we hold on to the path name for use |
| 246 | // in various histograms. |
asargent | c4fdad2 | 2015-08-28 22:44:39 | [diff] [blame] | 247 | base::FilePath crx_path_for_histograms_; |
ginkage | 553af320 | 2015-02-04 12:39:09 | [diff] [blame] | 248 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 249 | // Our unpacker client. |
[email protected] | f5ac274 | 2012-07-02 17:50:58 | [diff] [blame] | 250 | scoped_refptr<SandboxedUnpackerClient> client_; |
[email protected] | 5c851620 | 2010-03-18 21:43:34 | [diff] [blame] | 251 | |
[email protected] | 171ab92d | 2012-10-19 01:16:34 | [diff] [blame] | 252 | // The Extensions directory inside the profile. |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 253 | base::FilePath extensions_dir_; |
[email protected] | 171ab92d | 2012-10-19 01:16:34 | [diff] [blame] | 254 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 255 | // Temporary directory to use for unpacking. |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 256 | base::ScopedTempDir temp_dir_; |
[email protected] | 5c851620 | 2010-03-18 21:43:34 | [diff] [blame] | 257 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 258 | // Root directory of the unpacked extension (a child of temp_dir_). |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 259 | base::FilePath extension_root_; |
[email protected] | 5c851620 | 2010-03-18 21:43:34 | [diff] [blame] | 260 | |
Oleg Davydov | a4ffe6a | 2020-01-07 10:34:48 | [diff] [blame] | 261 | // Parsed original manifest of the extension. Set after unpacking the |
| 262 | // extension and working with its manifest, so after UnpackExtensionSucceeded |
| 263 | // is called. |
| 264 | base::Optional<base::Value> manifest_; |
| 265 | |
| 266 | // Checksum for the indexed ruleset, see more in |
| 267 | // SandboxedUnpackerClient::OnUnpackSuccess description. |
| 268 | base::Optional<int> dnr_ruleset_checksum_; |
| 269 | |
[email protected] | 5c851620 | 2010-03-18 21:43:34 | [diff] [blame] | 270 | // Represents the extension we're unpacking. |
[email protected] | b3fe68d | 2012-07-16 19:14:39 | [diff] [blame] | 271 | scoped_refptr<Extension> extension_; |
[email protected] | 5c851620 | 2010-03-18 21:43:34 | [diff] [blame] | 272 | |
[email protected] | 5c851620 | 2010-03-18 21:43:34 | [diff] [blame] | 273 | // The public key that was extracted from the CRX header. |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 274 | std::string public_key_; |
[email protected] | 264fda9 | 2011-04-20 15:03:55 | [diff] [blame] | 275 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 276 | // The extension's ID. This will be calculated from the public key |
| 277 | // in the CRX header. |
[email protected] | f5bf184 | 2012-02-15 02:52:26 | [diff] [blame] | 278 | std::string extension_id_; |
| 279 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 280 | // If we unpacked a CRX file, the time at which unpacking started. |
| 281 | // Used to compute the time unpacking takes. |
asargent | c4fdad2 | 2015-08-28 22:44:39 | [diff] [blame] | 282 | base::TimeTicks crx_unpack_start_time_; |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 283 | |
[email protected] | fc38935a | 2011-10-31 23:53:28 | [diff] [blame] | 284 | // Location to use for the unpacked extension. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 285 | Manifest::Location location_; |
[email protected] | fc38935a | 2011-10-31 23:53:28 | [diff] [blame] | 286 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 287 | // Creation flags to use for the extension. These flags will be used |
Istiaque Ahmed | f425834e | 2018-06-12 01:50:25 | [diff] [blame] | 288 | // when calling Extension::Create() by the CRX installer. |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 289 | int creation_flags_; |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 290 | |
noel | c8702c4 | 2017-03-16 08:51:19 | [diff] [blame] | 291 | // Sequenced task runner where file I/O operations will be performed. |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 292 | scoped_refptr<base::SequencedTaskRunner> unpacker_io_task_runner_; |
asargent | c4fdad2 | 2015-08-28 22:44:39 | [diff] [blame] | 293 | |
Jay Civelli | ea8f3df | 2018-01-24 05:17:32 | [diff] [blame] | 294 | // The normalized path of the install icon path, retrieved from the manifest. |
| 295 | base::FilePath install_icon_path_; |
| 296 | |
| 297 | // The decoded install icon. |
| 298 | SkBitmap install_icon_; |
| 299 | |
Ken Rockot | dc32df89 | 2019-11-01 06:32:10 | [diff] [blame] | 300 | // Controls our own lazily started, isolated instance of the Data Decoder |
| 301 | // service so that multiple decode operations related to this |
| 302 | // SandboxedUnpacker can share a single instance. |
| 303 | data_decoder::DataDecoder data_decoder_; |
Jay Civelli | ea8f3df | 2018-01-24 05:17:32 | [diff] [blame] | 304 | |
Miyoung Shin | 364c657 | 2019-09-11 09:02:19 | [diff] [blame] | 305 | // The JSONParser remote from the data decoder service. |
| 306 | mojo::Remote<data_decoder::mojom::JsonParser> json_parser_; |
Jay Civelli | 26a8564 | 2018-01-26 21:29:39 | [diff] [blame] | 307 | |
Jay Civelli | ea8f3df | 2018-01-24 05:17:32 | [diff] [blame] | 308 | // The ImageSanitizer used to clean-up images. |
| 309 | std::unique_ptr<ImageSanitizer> image_sanitizer_; |
| 310 | |
Jay Civelli | 6d0e68e | 2018-01-24 16:42:53 | [diff] [blame] | 311 | // Used during the message catalog rewriting phase to sanitize the extension |
| 312 | // provided message catalogs. |
| 313 | std::unique_ptr<JsonFileSanitizer> json_file_sanitizer_; |
| 314 | |
asargent | c4fdad2 | 2015-08-28 22:44:39 | [diff] [blame] | 315 | DISALLOW_COPY_AND_ASSIGN(SandboxedUnpacker); |
[email protected] | af1277b | 2009-07-28 00:47:53 | [diff] [blame] | 316 | }; |
| 317 | |
[email protected] | f5ac274 | 2012-07-02 17:50:58 | [diff] [blame] | 318 | } // namespace extensions |
| 319 | |
asargent | c4fdad2 | 2015-08-28 22:44:39 | [diff] [blame] | 320 | #endif // EXTENSIONS_BROWSER_SANDBOXED_UNPACKER_H_ |