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; |
107 | 106 |
108 virtual ~SandboxedExtensionUnpacker(); | 107 virtual ~SandboxedExtensionUnpacker(); |
109 | 108 |
| 109 // Set |temp_dir_| as a temporary directory to unpack the extension in. |
| 110 // Return true on success. |
| 111 virtual bool CreateTempDirectory(); |
| 112 |
110 // Validates the signature of the extension and extract the key to | 113 // Validates the signature of the extension and extract the key to |
111 // |public_key_|. Returns true if the signature validates, false otherwise. | 114 // |public_key_|. Returns true if the signature validates, false otherwise. |
112 // | 115 // |
113 // NOTE: Having this method here is a bit ugly. This code should really live | 116 // 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 | 117 // 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 | 118 // 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 | 119 // 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 | 120 // just for unpacking is there and code just for sandboxing of unpacking is |
118 // here. | 121 // here. |
119 bool ValidateSignature(); | 122 bool ValidateSignature(); |
(...skipping 14 matching lines...) Expand all Loading... |
134 DictionaryValue* RewriteManifestFile(const DictionaryValue& manifest); | 137 DictionaryValue* RewriteManifestFile(const DictionaryValue& manifest); |
135 | 138 |
136 // Overwrites original files with safe results from utility process. | 139 // Overwrites original files with safe results from utility process. |
137 // Reports error and returns false if it fails. | 140 // Reports error and returns false if it fails. |
138 bool RewriteImageFiles(); | 141 bool RewriteImageFiles(); |
139 bool RewriteCatalogFiles(); | 142 bool RewriteCatalogFiles(); |
140 | 143 |
141 // The path to the CRX to unpack. | 144 // The path to the CRX to unpack. |
142 FilePath crx_path_; | 145 FilePath crx_path_; |
143 | 146 |
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. | 147 // Our client's thread. This is the thread we respond on. |
148 BrowserThread::ID thread_identifier_; | 148 BrowserThread::ID thread_identifier_; |
149 | 149 |
150 // ResourceDispatcherHost to pass to the utility process. | 150 // ResourceDispatcherHost to pass to the utility process. |
151 ResourceDispatcherHost* rdh_; | 151 ResourceDispatcherHost* rdh_; |
152 | 152 |
153 // Our client. | 153 // Our client. |
154 scoped_refptr<SandboxedExtensionUnpackerClient> client_; | 154 scoped_refptr<SandboxedExtensionUnpackerClient> client_; |
155 | 155 |
156 // A temporary directory to use for unpacking. | 156 // A temporary directory to use for unpacking. |
157 ScopedTempDir temp_dir_; | 157 ScopedTempDir temp_dir_; |
158 | 158 |
159 // The root directory of the unpacked extension. This is a child of temp_dir_. | 159 // The root directory of the unpacked extension. This is a child of temp_dir_. |
160 FilePath extension_root_; | 160 FilePath extension_root_; |
161 | 161 |
162 // Represents the extension we're unpacking. | 162 // Represents the extension we're unpacking. |
163 scoped_refptr<Extension> extension_; | 163 scoped_refptr<Extension> extension_; |
164 | 164 |
165 // Whether we've received a response from the utility process yet. | 165 // Whether we've received a response from the utility process yet. |
166 bool got_response_; | 166 bool got_response_; |
167 | 167 |
168 // The public key that was extracted from the CRX header. | 168 // The public key that was extracted from the CRX header. |
169 std::string public_key_; | 169 std::string public_key_; |
170 }; | 170 }; |
171 | 171 |
172 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ | 172 #endif // CHROME_BROWSER_EXTENSIONS_SANDBOXED_EXTENSION_UNPACKER_H_ |
OLD | NEW |