Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: extensions/browser/sandboxed_unpacker.h

Issue 829583002: Validate hash_sha256 checksum on .crx update. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix histogram value. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_SANDBOXED_UNPACKER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_SANDBOXED_UNPACKER_H_
6 #define CHROME_BROWSER_EXTENSIONS_SANDBOXED_UNPACKER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_SANDBOXED_UNPACKER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "content/public/browser/utility_process_host_client.h" 14 #include "content/public/browser/utility_process_host_client.h"
15 #include "extensions/browser/crx_file_info.h"
15 #include "extensions/common/manifest.h" 16 #include "extensions/common/manifest.h"
16 17
17 class SkBitmap; 18 class SkBitmap;
18 19
19 namespace base { 20 namespace base {
20 class DictionaryValue; 21 class DictionaryValue;
21 class SequencedTaskRunner; 22 class SequencedTaskRunner;
22 } 23 }
23 24
25 namespace crypto {
26 class SecureHash;
27 }
28
24 namespace extensions { 29 namespace extensions {
25 class Extension; 30 class Extension;
26 31
27 class SandboxedUnpackerClient 32 class SandboxedUnpackerClient
28 : public base::RefCountedThreadSafe<SandboxedUnpackerClient> { 33 : public base::RefCountedThreadSafe<SandboxedUnpackerClient> {
29 public: 34 public:
30 // temp_dir - A temporary directory containing the results of the extension 35 // temp_dir - A temporary directory containing the results of the extension
31 // unpacking. The client is responsible for deleting this directory. 36 // unpacking. The client is responsible for deleting this directory.
32 // 37 //
33 // extension_root - The path to the extension root inside of temp_dir. 38 // extension_root - The path to the extension root inside of temp_dir.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // long enough to receive the result of unpacking. 77 // long enough to receive the result of unpacking.
73 // 78 //
74 // 79 //
75 // NOTE: This class should only be used on the file thread. 80 // NOTE: This class should only be used on the file thread.
76 class SandboxedUnpacker : public content::UtilityProcessHostClient { 81 class SandboxedUnpacker : public content::UtilityProcessHostClient {
77 public: 82 public:
78 // Unpacks the extension in |crx_path| into a temporary directory and calls 83 // Unpacks the extension in |crx_path| into a temporary directory and calls
79 // |client| with the result. If |run_out_of_process| is provided, unpacking 84 // |client| with the result. If |run_out_of_process| is provided, unpacking
80 // is done in a sandboxed subprocess. Otherwise, it is done in-process. 85 // is done in a sandboxed subprocess. Otherwise, it is done in-process.
81 SandboxedUnpacker( 86 SandboxedUnpacker(
82 const base::FilePath& crx_path, 87 const CRXFileInfo& file,
83 Manifest::Location location, 88 Manifest::Location location,
84 int creation_flags, 89 int creation_flags,
85 const base::FilePath& extensions_dir, 90 const base::FilePath& extensions_dir,
86 const scoped_refptr<base::SequencedTaskRunner>& unpacker_io_task_runner, 91 const scoped_refptr<base::SequencedTaskRunner>& unpacker_io_task_runner,
87 SandboxedUnpackerClient* client); 92 SandboxedUnpackerClient* client);
88 93
89 // Start unpacking the extension. The client is called with the results. 94 // Start unpacking the extension. The client is called with the results.
90 void Start(); 95 void Start();
91 96
92 private: 97 private:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 ERROR_SAVING_THEME_IMAGE, 146 ERROR_SAVING_THEME_IMAGE,
142 ABORTED_DUE_TO_SHUTDOWN, 147 ABORTED_DUE_TO_SHUTDOWN,
143 148
144 // SandboxedUnpacker::RewriteCatalogFiles() 149 // SandboxedUnpacker::RewriteCatalogFiles()
145 COULD_NOT_READ_CATALOG_DATA_FROM_DISK, 150 COULD_NOT_READ_CATALOG_DATA_FROM_DISK,
146 INVALID_CATALOG_DATA, 151 INVALID_CATALOG_DATA,
147 INVALID_PATH_FOR_CATALOG, 152 INVALID_PATH_FOR_CATALOG,
148 ERROR_SERIALIZING_CATALOG, 153 ERROR_SERIALIZING_CATALOG,
149 ERROR_SAVING_CATALOG, 154 ERROR_SAVING_CATALOG,
150 155
156 // SandboxedUnpacker::ValidateSignature()
157 CRX_HASH_VERIFICATION_FAILED,
158
151 NUM_FAILURE_REASONS 159 NUM_FAILURE_REASONS
152 }; 160 };
153 161
154 friend class ProcessHostClient; 162 friend class ProcessHostClient;
155 friend class SandboxedUnpackerTest; 163 friend class SandboxedUnpackerTest;
156 164
157 ~SandboxedUnpacker() override; 165 ~SandboxedUnpacker() override;
158 166
159 // Set |temp_dir_| as a temporary directory to unpack the extension in. 167 // Set |temp_dir_| as a temporary directory to unpack the extension in.
160 // Return true on success. 168 // Return true on success.
161 virtual bool CreateTempDirectory(); 169 virtual bool CreateTempDirectory();
162 170
171 // Finalizes hash calculation and checks the result against the expected
172 // package hash. In case of mismatch, depending on the command-line option,
173 // we will either fail installation, or just update histograms.
174 bool FinalizeHash(scoped_ptr<crypto::SecureHash>& hash);
175
163 // Validates the signature of the extension and extract the key to 176 // Validates the signature of the extension and extract the key to
164 // |public_key_|. Returns true if the signature validates, false otherwise. 177 // |public_key_|. Returns true if the signature validates, false otherwise.
165 // 178 //
166 // NOTE: Having this method here is a bit ugly. This code should really live 179 // NOTE: Having this method here is a bit ugly. This code should really live
167 // in extensions::Unpacker as it is not specific to sandboxed unpacking. It 180 // in extensions::Unpacker as it is not specific to sandboxed unpacking. It
168 // was put here because we cannot run windows crypto code in the sandbox. But 181 // was put here because we cannot run windows crypto code in the sandbox. But
169 // we could still have this method statically on extensions::Unpacker so that 182 // we could still have this method statically on extensions::Unpacker so that
170 // code just for unpacking is there and code just for sandboxing of unpacking 183 // code just for unpacking is there and code just for sandboxing of unpacking
171 // is here. 184 // is here.
172 bool ValidateSignature(); 185 bool ValidateSignature();
(...skipping 22 matching lines...) Expand all
195 // Reports error and returns false if it fails. 208 // Reports error and returns false if it fails.
196 bool RewriteImageFiles(SkBitmap* install_icon); 209 bool RewriteImageFiles(SkBitmap* install_icon);
197 bool RewriteCatalogFiles(); 210 bool RewriteCatalogFiles();
198 211
199 // Cleans up temp directory artifacts. 212 // Cleans up temp directory artifacts.
200 void Cleanup(); 213 void Cleanup();
201 214
202 // The path to the CRX to unpack. 215 // The path to the CRX to unpack.
203 base::FilePath crx_path_; 216 base::FilePath crx_path_;
204 217
218 // The package hash that was reported from the Web Store.
219 std::string package_hash_;
220
221 // Whether we need to check the .crx hash sum.
222 bool check_crx_hash_;
223
205 // Our client. 224 // Our client.
206 scoped_refptr<SandboxedUnpackerClient> client_; 225 scoped_refptr<SandboxedUnpackerClient> client_;
207 226
208 // The Extensions directory inside the profile. 227 // The Extensions directory inside the profile.
209 base::FilePath extensions_dir_; 228 base::FilePath extensions_dir_;
210 229
211 // A temporary directory to use for unpacking. 230 // A temporary directory to use for unpacking.
212 base::ScopedTempDir temp_dir_; 231 base::ScopedTempDir temp_dir_;
213 232
214 // The root directory of the unpacked extension. This is a child of temp_dir_. 233 // The root directory of the unpacked extension. This is a child of temp_dir_.
(...skipping 22 matching lines...) Expand all
237 // when calling Extenion::Create() by the crx installer. 256 // when calling Extenion::Create() by the crx installer.
238 int creation_flags_; 257 int creation_flags_;
239 258
240 // Sequenced task runner where file I/O operations will be performed at. 259 // Sequenced task runner where file I/O operations will be performed at.
241 scoped_refptr<base::SequencedTaskRunner> unpacker_io_task_runner_; 260 scoped_refptr<base::SequencedTaskRunner> unpacker_io_task_runner_;
242 }; 261 };
243 262
244 } // namespace extensions 263 } // namespace extensions
245 264
246 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_UNPACKER_H_ 265 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_UNPACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698