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

Side by Side Diff: chrome/browser/extensions/startup_helper.cc

Issue 829583002: Validate hash_sha256 checksum on .crx update. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add histogram description. Created 5 years, 11 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 #include "chrome/browser/extensions/startup_helper.h" 5 #include "chrome/browser/extensions/startup_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 pack_job_->Start(); 114 pack_job_->Start();
115 115
116 return pack_job_succeeded_; 116 return pack_job_succeeded_;
117 } 117 }
118 118
119 namespace { 119 namespace {
120 120
121 class ValidateCrxHelper : public SandboxedUnpackerClient { 121 class ValidateCrxHelper : public SandboxedUnpackerClient {
122 public: 122 public:
123 ValidateCrxHelper(const base::FilePath& crx_file, 123 ValidateCrxHelper(const base::FilePath& crx_file,
124 const std::string& package_hash,
124 const base::FilePath& temp_dir, 125 const base::FilePath& temp_dir,
125 base::RunLoop* run_loop) 126 base::RunLoop* run_loop)
126 : crx_file_(crx_file), temp_dir_(temp_dir), run_loop_(run_loop), 127 : crx_file_(crx_file),
127 finished_(false), success_(false) {} 128 package_hash_(package_hash),
129 temp_dir_(temp_dir),
130 run_loop_(run_loop),
131 finished_(false),
132 success_(false) {}
128 133
129 bool finished() { return finished_; } 134 bool finished() { return finished_; }
130 bool success() { return success_; } 135 bool success() { return success_; }
131 const base::string16& error() { return error_; } 136 const base::string16& error() { return error_; }
132 137
133 void Start() { 138 void Start() {
134 BrowserThread::PostTask(BrowserThread::FILE, 139 BrowserThread::PostTask(BrowserThread::FILE,
135 FROM_HERE, 140 FROM_HERE,
136 base::Bind(&ValidateCrxHelper::StartOnFileThread, 141 base::Bind(&ValidateCrxHelper::StartOnFileThread,
137 this)); 142 this));
(...skipping 30 matching lines...) Expand all
168 if (run_loop_->running()) 173 if (run_loop_->running())
169 run_loop_->Quit(); 174 run_loop_->Quit();
170 } 175 }
171 176
172 void StartOnFileThread() { 177 void StartOnFileThread() {
173 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 178 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
174 scoped_refptr<base::MessageLoopProxy> file_thread_proxy = 179 scoped_refptr<base::MessageLoopProxy> file_thread_proxy =
175 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); 180 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
176 181
177 scoped_refptr<SandboxedUnpacker> unpacker( 182 scoped_refptr<SandboxedUnpacker> unpacker(
178 new SandboxedUnpacker(crx_file_, 183 new SandboxedUnpacker(crx_file_, package_hash_, Manifest::INTERNAL,
179 Manifest::INTERNAL,
180 0, /* no special creation flags */ 184 0, /* no special creation flags */
181 temp_dir_, 185 temp_dir_, file_thread_proxy.get(), this));
182 file_thread_proxy.get(),
183 this));
184 unpacker->Start(); 186 unpacker->Start();
185 } 187 }
186 188
187 // The file being validated. 189 // The file being validated.
188 const base::FilePath& crx_file_; 190 const base::FilePath& crx_file_;
189 191
192 // SHA256 hash returned from WebStore.
193 const std::string& package_hash_;
194
190 // The temporary directory where the sandboxed unpacker will do work. 195 // The temporary directory where the sandboxed unpacker will do work.
191 const base::FilePath& temp_dir_; 196 const base::FilePath& temp_dir_;
192 197
193 // Unowned pointer to a runloop, so our consumer can wait for us to finish. 198 // Unowned pointer to a runloop, so our consumer can wait for us to finish.
194 base::RunLoop* run_loop_; 199 base::RunLoop* run_loop_;
195 200
196 // Whether we're finished unpacking; 201 // Whether we're finished unpacking;
197 bool finished_; 202 bool finished_;
198 203
199 // Whether the unpacking was successful. 204 // Whether the unpacking was successful.
(...skipping 14 matching lines...) Expand all
214 switches::kValidateCrx); 219 switches::kValidateCrx);
215 return false; 220 return false;
216 } 221 }
217 base::ScopedTempDir temp_dir; 222 base::ScopedTempDir temp_dir;
218 223
219 if (!temp_dir.CreateUniqueTempDir()) { 224 if (!temp_dir.CreateUniqueTempDir()) {
220 *error = std::string("Failed to create temp dir"); 225 *error = std::string("Failed to create temp dir");
221 return false; 226 return false;
222 } 227 }
223 228
229 std::string hash = cmd_line.GetSwitchValueASCII(switches::kValidateCrxHash);
230
224 base::RunLoop run_loop; 231 base::RunLoop run_loop;
225 scoped_refptr<ValidateCrxHelper> helper( 232 scoped_refptr<ValidateCrxHelper> helper(
226 new ValidateCrxHelper(path, temp_dir.path(), &run_loop)); 233 new ValidateCrxHelper(path, hash, temp_dir.path(), &run_loop));
227 helper->Start(); 234 helper->Start();
228 if (!helper->finished()) 235 if (!helper->finished())
229 run_loop.Run(); 236 run_loop.Run();
230 237
231 bool success = helper->success(); 238 bool success = helper->success();
232 if (!success) 239 if (!success)
233 *error = base::UTF16ToUTF8(helper->error()); 240 *error = base::UTF16ToUTF8(helper->error());
234 return success; 241 return success;
235 } 242 }
236 243
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } else { 298 } else {
292 error_ = "Not a supported ephemeral app installation."; 299 error_ = "Not a supported ephemeral app installation.";
293 done_callback_.Run(); 300 done_callback_.Run();
294 } 301 }
295 } 302 }
296 303
297 void AppInstallHelper::OnAppInstallComplete(bool success, 304 void AppInstallHelper::OnAppInstallComplete(bool success,
298 const std::string& error, 305 const std::string& error,
299 webstore_install::Result result) { 306 webstore_install::Result result) {
300 success_ = success; 307 success_ = success;
301 error_= error; 308 error_ = error;
302 done_callback_.Run(); 309 done_callback_.Run();
303 } 310 }
304 311
305 } // namespace 312 } // namespace
306 313
307 bool StartupHelper::InstallEphemeralApp(const base::CommandLine& cmd_line, 314 bool StartupHelper::InstallEphemeralApp(const base::CommandLine& cmd_line,
308 Profile* profile) { 315 Profile* profile) {
309 std::string id = 316 std::string id =
310 cmd_line.GetSwitchValueASCII(switches::kInstallEphemeralAppFromWebstore); 317 cmd_line.GetSwitchValueASCII(switches::kInstallEphemeralAppFromWebstore);
311 if (!crx_file::id_util::IdIsValid(id)) { 318 if (!crx_file::id_util::IdIsValid(id)) {
(...skipping 11 matching lines...) Expand all
323 LOG(ERROR) << "InstallFromWebstore failed with error: " << helper.error(); 330 LOG(ERROR) << "InstallFromWebstore failed with error: " << helper.error();
324 return helper.success(); 331 return helper.success();
325 } 332 }
326 333
327 StartupHelper::~StartupHelper() { 334 StartupHelper::~StartupHelper() {
328 if (pack_job_.get()) 335 if (pack_job_.get())
329 pack_job_->ClearClient(); 336 pack_job_->ClearClient();
330 } 337 }
331 338
332 } // namespace extensions 339 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698