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 } |
84 | 65 |
85 // The utility process will have access to the directory passed to | 66 // The utility process will have access to the directory passed to |
86 // SandboxedExtensionUnpacker. That directory should not contain a | 67 // SandboxedExtensionUnpacker. That directory should not contain a |
87 // symlink or NTFS junction, because when the path is used, following | 68 // symlink or NTFS junction, because when the path is used, following |
88 // the link will cause file system access outside the sandbox path. | 69 // the link will cause file system access outside the sandbox path. |
89 FilePath normalized_crx_path; | 70 FilePath normalized_crx_path; |
90 if (!file_util::NormalizeFilePath(temp_crx_path, &normalized_crx_path)) { | 71 if (!file_util::NormalizeFilePath(temp_crx_path, &normalized_crx_path)) { |
| 72 // TODO(skerner): Remove this logging once crbug/13044 is fixed. |
| 73 // This bug is starred by many users who have some kind of link. |
| 74 // If NormalizeFilePath() fails we want to see it in the logs they send. |
91 LOG(ERROR) << "Could not get the normalized path of " | 75 LOG(ERROR) << "Could not get the normalized path of " |
92 << temp_crx_path.value(); | 76 << temp_crx_path.value(); |
93 normalized_crx_path = temp_crx_path; | 77 normalized_crx_path = temp_crx_path; |
94 } else { | 78 } else { |
95 LOG(INFO) << "RealFilePath: from " << temp_crx_path.value() | 79 LOG(INFO) << "RealFilePath: from " << temp_crx_path.value() |
96 << " to " << normalized_crx_path.value(); | 80 << " to " << normalized_crx_path.value(); |
97 } | 81 } |
98 | 82 |
99 // If we are supposed to use a subprocess, kick off the subprocess. | 83 // If we are supposed to use a subprocess, kick off the subprocess. |
100 // | 84 // |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 if (!file_util::WriteFile(path, | 392 if (!file_util::WriteFile(path, |
409 catalog_json.c_str(), | 393 catalog_json.c_str(), |
410 catalog_json.size())) { | 394 catalog_json.size())) { |
411 ReportFailure("Error saving catalog."); | 395 ReportFailure("Error saving catalog."); |
412 return false; | 396 return false; |
413 } | 397 } |
414 } | 398 } |
415 | 399 |
416 return true; | 400 return true; |
417 } | 401 } |
OLD | NEW |