| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_EXTENSION_UNPACKER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // The magic character sequence at the beginning of each crx file. | 86 // The magic character sequence at the beginning of each crx file. |
| 87 static const char kExtensionHeaderMagic[]; | 87 static const char kExtensionHeaderMagic[]; |
| 88 | 88 |
| 89 // The current version of the crx format. | 89 // The current version of the crx format. |
| 90 static const uint32 kCurrentVersion = 2; | 90 static const uint32 kCurrentVersion = 2; |
| 91 | 91 |
| 92 // Unpacks the extension in |crx_path| into a temporary directory and calls | 92 // Unpacks the extension in |crx_path| into a temporary directory and calls |
| 93 // |client| with the result. If |rdh| is provided, unpacking is done in a | 93 // |client| with the result. If |rdh| is provided, unpacking is done in a |
| 94 // sandboxed subprocess. Otherwise, it is done in-process. | 94 // sandboxed subprocess. Otherwise, it is done in-process. |
| 95 SandboxedExtensionUnpacker(const FilePath& crx_path, | 95 SandboxedExtensionUnpacker(const FilePath& crx_path, |
| 96 const FilePath& temp_path, | |
| 97 ResourceDispatcherHost* rdh, | 96 ResourceDispatcherHost* rdh, |
| 98 SandboxedExtensionUnpackerClient* cilent); | 97 SandboxedExtensionUnpackerClient* cilent); |
| 99 | 98 |
| 100 // Start unpacking the extension. The client is called with the results. | 99 // Start unpacking the extension. The client is called with the results. |
| 101 void Start(); | 100 void Start(); |
| 102 | 101 |
| 103 private: | 102 private: |
| 104 class ProcessHostClient; | 103 class ProcessHostClient; |
| 105 friend class ProcessHostClient; | 104 friend class ProcessHostClient; |
| 106 friend class SandboxedExtensionUnpackerTest; | 105 friend class SandboxedExtensionUnpackerTest; |
| 106 FRIEND_TEST_ALL_PREFIXES(SandboxedExtensionUnpackerTest, |
| 107 CreateTempDirectory); |
| 107 | 108 |
| 108 virtual ~SandboxedExtensionUnpacker(); | 109 virtual ~SandboxedExtensionUnpacker(); |
| 109 | 110 |
| 111 // Creatye a temporary directory to unpack the extension in. |
| 112 // |unpack_path_keys| is a list of PathService keys in which |
| 113 // to place the unpack directory. A list is used in case some |
| 114 // directories are not writable for any reason. |
| 115 virtual bool CreateTempDirectory(const int unpack_path_keys[], |
| 116 size_t unpack_path_keys_size); |
| 117 |
| 110 // Validates the signature of the extension and extract the key to | 118 // Validates the signature of the extension and extract the key to |
| 111 // |public_key_|. Returns true if the signature validates, false otherwise. | 119 // |public_key_|. Returns true if the signature validates, false otherwise. |
| 112 // | 120 // |
| 113 // NOTE: Having this method here is a bit ugly. This code should really live | 121 // NOTE: Having this method here is a bit ugly. This code should really live |
| 114 // in ExtensionUnpacker as it is not specific to sandboxed unpacking. It was | 122 // in ExtensionUnpacker as it is not specific to sandboxed unpacking. It was |
| 115 // put here because we cannot run windows crypto code in the sandbox. But we | 123 // put here because we cannot run windows crypto code in the sandbox. But we |
| 116 // could still have this method statically on ExtensionUnpacker so that code | 124 // could still have this method statically on ExtensionUnpacker so that code |
| 117 // just for unpacking is there and code just for sandboxing of unpacking is | 125 // just for unpacking is there and code just for sandboxing of unpacking is |
| 118 // here. | 126 // here. |
| 119 bool ValidateSignature(); | 127 bool ValidateSignature(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 134 DictionaryValue* RewriteManifestFile(const DictionaryValue& manifest); | 142 DictionaryValue* RewriteManifestFile(const DictionaryValue& manifest); |
| 135 | 143 |
| 136 // Overwrites original files with safe results from utility process. | 144 // Overwrites original files with safe results from utility process. |
| 137 // Reports error and returns false if it fails. | 145 // Reports error and returns false if it fails. |
| 138 bool RewriteImageFiles(); | 146 bool RewriteImageFiles(); |
| 139 bool RewriteCatalogFiles(); | 147 bool RewriteCatalogFiles(); |
| 140 | 148 |
| 141 // The path to the CRX to unpack. | 149 // The path to the CRX to unpack. |
| 142 FilePath crx_path_; | 150 FilePath crx_path_; |
| 143 | 151 |
| 144 // A path to a temp dir to unpack in. | |
| 145 FilePath temp_path_; | |
| 146 | |
| 147 // Our client's thread. This is the thread we respond on. | 152 // Our client's thread. This is the thread we respond on. |
| 148 BrowserThread::ID thread_identifier_; | 153 BrowserThread::ID thread_identifier_; |
| 149 | 154 |
| 150 // ResourceDispatcherHost to pass to the utility process. | 155 // ResourceDispatcherHost to pass to the utility process. |
| 151 ResourceDispatcherHost* rdh_; | 156 ResourceDispatcherHost* rdh_; |
| 152 | 157 |
| 153 // Our client. | 158 // Our client. |
| 154 scoped_refptr<SandboxedExtensionUnpackerClient> client_; | 159 scoped_refptr<SandboxedExtensionUnpackerClient> client_; |
| 155 | 160 |
| 156 // A temporary directory to use for unpacking. | 161 // A temporary directory to use for unpacking. |
| 157 ScopedTempDir temp_dir_; | 162 ScopedTempDir temp_dir_; |
| 158 | 163 |
| 159 // The root directory of the unpacked extension. This is a child of temp_dir_. | 164 // The root directory of the unpacked extension. This is a child of temp_dir_. |
| 160 FilePath extension_root_; | 165 FilePath extension_root_; |
| 161 | 166 |
| 162 // Represents the extension we're unpacking. | 167 // Represents the extension we're unpacking. |
| 163 scoped_refptr<Extension> extension_; | 168 scoped_refptr<Extension> extension_; |
| 164 | 169 |
| 165 // Whether we've received a response from the utility process yet. | 170 // Whether we've received a response from the utility process yet. |
| 166 bool got_response_; | 171 bool got_response_; |
| 167 | 172 |
| 168 // The public key that was extracted from the CRX header. | 173 // The public key that was extracted from the CRX header. |
| 169 std::string public_key_; | 174 std::string public_key_; |
| 170 }; | 175 }; |
| 171 | 176 |
| 172 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ | 177 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ |
| OLD | NEW |