| OLD | NEW |
| 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/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // extension_root - The path to the extension root inside of temp_dir. | 29 // extension_root - The path to the extension root inside of temp_dir. |
| 30 // | 30 // |
| 31 // original_manifest - The parsed but unmodified version of the manifest, | 31 // original_manifest - The parsed but unmodified version of the manifest, |
| 32 // with no modifications such as localization, etc. | 32 // with no modifications such as localization, etc. |
| 33 // | 33 // |
| 34 // extension - The extension that was unpacked. The client is responsible | 34 // extension - The extension that was unpacked. The client is responsible |
| 35 // for deleting this memory. | 35 // for deleting this memory. |
| 36 virtual void OnUnpackSuccess(const FilePath& temp_dir, | 36 virtual void OnUnpackSuccess(const FilePath& temp_dir, |
| 37 const FilePath& extension_root, | 37 const FilePath& extension_root, |
| 38 const base::DictionaryValue* original_manifest, | 38 const base::DictionaryValue* original_manifest, |
| 39 const extensions::Extension* extension) = 0; | 39 const Extension* extension) = 0; |
| 40 virtual void OnUnpackFailure(const string16& error) = 0; | 40 virtual void OnUnpackFailure(const string16& error) = 0; |
| 41 | 41 |
| 42 protected: | 42 protected: |
| 43 friend class base::RefCountedThreadSafe<SandboxedUnpackerClient>; | 43 friend class base::RefCountedThreadSafe<SandboxedUnpackerClient>; |
| 44 | 44 |
| 45 virtual ~SandboxedUnpackerClient() {} | 45 virtual ~SandboxedUnpackerClient() {} |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 // SandboxedUnpacker unpacks extensions from the CRX format into a | 48 // SandboxedUnpacker unpacks extensions from the CRX format into a |
| 49 // directory. This is done in a sandboxed subprocess to protect the browser | 49 // directory. This is done in a sandboxed subprocess to protect the browser |
| (...skipping 17 matching lines...) Expand all Loading... |
| 67 // | 67 // |
| 68 // NOTE: This class should only be used on the file thread. | 68 // NOTE: This class should only be used on the file thread. |
| 69 class SandboxedUnpacker : public content::UtilityProcessHostClient { | 69 class SandboxedUnpacker : public content::UtilityProcessHostClient { |
| 70 public: | 70 public: |
| 71 | 71 |
| 72 // Unpacks the extension in |crx_path| into a temporary directory and calls | 72 // Unpacks the extension in |crx_path| into a temporary directory and calls |
| 73 // |client| with the result. If |run_out_of_process| is provided, unpacking | 73 // |client| with the result. If |run_out_of_process| is provided, unpacking |
| 74 // is done in a sandboxed subprocess. Otherwise, it is done in-process. | 74 // is done in a sandboxed subprocess. Otherwise, it is done in-process. |
| 75 SandboxedUnpacker(const FilePath& crx_path, | 75 SandboxedUnpacker(const FilePath& crx_path, |
| 76 bool run_out_of_process, | 76 bool run_out_of_process, |
| 77 extensions::Extension::Location location, | 77 Extension::Location location, |
| 78 int creation_flags, | 78 int creation_flags, |
| 79 SandboxedUnpackerClient* client); | 79 SandboxedUnpackerClient* client); |
| 80 | 80 |
| 81 // Start unpacking the extension. The client is called with the results. | 81 // Start unpacking the extension. The client is called with the results. |
| 82 void Start(); | 82 void Start(); |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 class ProcessHostClient; | 85 class ProcessHostClient; |
| 86 | 86 |
| 87 // Enumerate all the ways unpacking can fail. Calls to ReportFailure() | 87 // Enumerate all the ways unpacking can fail. Calls to ReportFailure() |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 virtual ~SandboxedUnpacker(); | 148 virtual ~SandboxedUnpacker(); |
| 149 | 149 |
| 150 // Set |temp_dir_| as a temporary directory to unpack the extension in. | 150 // Set |temp_dir_| as a temporary directory to unpack the extension in. |
| 151 // Return true on success. | 151 // Return true on success. |
| 152 virtual bool CreateTempDirectory(); | 152 virtual bool CreateTempDirectory(); |
| 153 | 153 |
| 154 // Validates the signature of the extension and extract the key to | 154 // Validates the signature of the extension and extract the key to |
| 155 // |public_key_|. Returns true if the signature validates, false otherwise. | 155 // |public_key_|. Returns true if the signature validates, false otherwise. |
| 156 // | 156 // |
| 157 // NOTE: Having this method here is a bit ugly. This code should really live | 157 // NOTE: Having this method here is a bit ugly. This code should really live |
| 158 // in ExtensionUnpacker as it is not specific to sandboxed unpacking. It was | 158 // in extensions::Unpacker as it is not specific to sandboxed unpacking. It |
| 159 // put here because we cannot run windows crypto code in the sandbox. But we | 159 // was put here because we cannot run windows crypto code in the sandbox. But |
| 160 // could still have this method statically on ExtensionUnpacker so that code | 160 // we could still have this method statically on extensions::Unpacker so that |
| 161 // just for unpacking is there and code just for sandboxing of unpacking is | 161 // code just for unpacking is there and code just for sandboxing of unpacking |
| 162 // here. | 162 // is here. |
| 163 bool ValidateSignature(); | 163 bool ValidateSignature(); |
| 164 | 164 |
| 165 // Starts the utility process that unpacks our extension. | 165 // Starts the utility process that unpacks our extension. |
| 166 void StartProcessOnIOThread(const FilePath& temp_crx_path); | 166 void StartProcessOnIOThread(const FilePath& temp_crx_path); |
| 167 | 167 |
| 168 // UtilityProcessHostClient | 168 // UtilityProcessHostClient |
| 169 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 169 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 170 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | 170 virtual void OnProcessCrashed(int exit_code) OVERRIDE; |
| 171 | 171 |
| 172 // IPC message handlers. | 172 // IPC message handlers. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 198 // Our client. | 198 // Our client. |
| 199 scoped_refptr<SandboxedUnpackerClient> client_; | 199 scoped_refptr<SandboxedUnpackerClient> client_; |
| 200 | 200 |
| 201 // A temporary directory to use for unpacking. | 201 // A temporary directory to use for unpacking. |
| 202 ScopedTempDir temp_dir_; | 202 ScopedTempDir temp_dir_; |
| 203 | 203 |
| 204 // The root directory of the unpacked extension. This is a child of temp_dir_. | 204 // The root directory of the unpacked extension. This is a child of temp_dir_. |
| 205 FilePath extension_root_; | 205 FilePath extension_root_; |
| 206 | 206 |
| 207 // Represents the extension we're unpacking. | 207 // Represents the extension we're unpacking. |
| 208 scoped_refptr<extensions::Extension> extension_; | 208 scoped_refptr<Extension> extension_; |
| 209 | 209 |
| 210 // Whether we've received a response from the utility process yet. | 210 // Whether we've received a response from the utility process yet. |
| 211 bool got_response_; | 211 bool got_response_; |
| 212 | 212 |
| 213 // The public key that was extracted from the CRX header. | 213 // The public key that was extracted from the CRX header. |
| 214 std::string public_key_; | 214 std::string public_key_; |
| 215 | 215 |
| 216 // The extension's ID. This will be calculated from the public key in the crx | 216 // The extension's ID. This will be calculated from the public key in the crx |
| 217 // header. | 217 // header. |
| 218 std::string extension_id_; | 218 std::string extension_id_; |
| 219 | 219 |
| 220 // Time at which unpacking started. Used to compute the time unpacking takes. | 220 // Time at which unpacking started. Used to compute the time unpacking takes. |
| 221 base::TimeTicks unpack_start_time_; | 221 base::TimeTicks unpack_start_time_; |
| 222 | 222 |
| 223 // Location to use for the unpacked extension. | 223 // Location to use for the unpacked extension. |
| 224 extensions::Extension::Location location_; | 224 Extension::Location location_; |
| 225 | 225 |
| 226 // Creation flags to use for the extension. These flags will be used | 226 // Creation flags to use for the extension. These flags will be used |
| 227 // when calling Extenion::Create() by the crx installer. | 227 // when calling Extenion::Create() by the crx installer. |
| 228 int creation_flags_; | 228 int creation_flags_; |
| 229 }; | 229 }; |
| 230 | 230 |
| 231 } // namespace extensions | 231 } // namespace extensions |
| 232 | 232 |
| 233 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_UNPACKER_H_ | 233 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_UNPACKER_H_ |
| OLD | NEW |