| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/sandboxed_extension_unpacker.h" | 5 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/crypto/signature_verifier.h" | 10 #include "base/crypto/signature_verifier.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 : crx_path_(crx_path), temp_path_(temp_path), | 35 : crx_path_(crx_path), temp_path_(temp_path), |
| 36 thread_identifier_(ChromeThread::ID_COUNT), | 36 thread_identifier_(ChromeThread::ID_COUNT), |
| 37 rdh_(rdh), client_(client), got_response_(false) { | 37 rdh_(rdh), client_(client), got_response_(false) { |
| 38 } | 38 } |
| 39 | 39 |
| 40 void SandboxedExtensionUnpacker::Start() { | 40 void SandboxedExtensionUnpacker::Start() { |
| 41 // We assume that we are started on the thread that the client wants us to do | 41 // We assume that we are started on the thread that the client wants us to do |
| 42 // file IO on. | 42 // file IO on. |
| 43 CHECK(ChromeThread::GetCurrentThreadIdentifier(&thread_identifier_)); | 43 CHECK(ChromeThread::GetCurrentThreadIdentifier(&thread_identifier_)); |
| 44 | 44 |
| 45 // To understand crbug/35198, allow users who can reproduce the bug | |
| 46 // to loosen permissions on the scoped directory. | |
| 47 bool loosen_permissions = false; | |
| 48 #if defined (OS_WIN) | |
| 49 loosen_permissions = CommandLine::ForCurrentProcess()->HasSwitch( | |
| 50 switches::kIssue35198Permission); | |
| 51 LOG(INFO) << "loosen_permissions = " << loosen_permissions; | |
| 52 #endif | |
| 53 | |
| 54 // Create a temporary directory to work in. | 45 // Create a temporary directory to work in. |
| 55 if (!temp_dir_.CreateUniqueTempDirUnderPath(temp_path_, | 46 if (!temp_dir_.CreateUniqueTempDirUnderPath(temp_path_)) { |
| 56 loosen_permissions)) { | |
| 57 ReportFailure("Could not create temporary directory."); | 47 ReportFailure("Could not create temporary directory."); |
| 58 return; | 48 return; |
| 59 } | 49 } |
| 60 | 50 |
| 61 // Initialize the path that will eventually contain the unpacked extension. | 51 // Initialize the path that will eventually contain the unpacked extension. |
| 62 extension_root_ = temp_dir_.path().AppendASCII( | 52 extension_root_ = temp_dir_.path().AppendASCII( |
| 63 extension_filenames::kTempExtensionName); | 53 extension_filenames::kTempExtensionName); |
| 64 | 54 |
| 65 // To understand crbug/35198, allow users who can reproduce the bug to | |
| 66 // create the unpack directory in the browser process. | |
| 67 bool crxdir_in_browser = CommandLine::ForCurrentProcess()->HasSwitch( | |
| 68 switches::kIssue35198CrxDirBrowser); | |
| 69 LOG(INFO) << "crxdir_in_browser = " << crxdir_in_browser; | |
| 70 if (crxdir_in_browser && !file_util::CreateDirectory(extension_root_)) { | |
| 71 LOG(ERROR) << "Failed to create directory " << extension_root_.value(); | |
| 72 } | |
| 73 | |
| 74 // Extract the public key and validate the package. | 55 // Extract the public key and validate the package. |
| 75 if (!ValidateSignature()) | 56 if (!ValidateSignature()) |
| 76 return; // ValidateSignature() already reported the error. | 57 return; // ValidateSignature() already reported the error. |
| 77 | 58 |
| 78 // Copy the crx file into our working directory. | 59 // Copy the crx file into our working directory. |
| 79 FilePath temp_crx_path = temp_dir_.path().Append(crx_path_.BaseName()); | 60 FilePath temp_crx_path = temp_dir_.path().Append(crx_path_.BaseName()); |
| 80 if (!file_util::CopyFile(crx_path_, temp_crx_path)) { | 61 if (!file_util::CopyFile(crx_path_, temp_crx_path)) { |
| 81 ReportFailure("Failed to copy extension file to temporary directory."); | 62 ReportFailure("Failed to copy extension file to temporary directory."); |
| 82 return; | 63 return; |
| 83 } | 64 } |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 if (!file_util::WriteFile(path, | 389 if (!file_util::WriteFile(path, |
| 409 catalog_json.c_str(), | 390 catalog_json.c_str(), |
| 410 catalog_json.size())) { | 391 catalog_json.size())) { |
| 411 ReportFailure("Error saving catalog."); | 392 ReportFailure("Error saving catalog."); |
| 412 return false; | 393 return false; |
| 413 } | 394 } |
| 414 } | 395 } |
| 415 | 396 |
| 416 return true; | 397 return true; |
| 417 } | 398 } |
| OLD | NEW |