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 #include "chrome/browser/extensions/extension_creator.h" | 5 #include "chrome/browser/extensions/extension_creator.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 } | 143 } |
144 | 144 |
145 return crypto::RSAPrivateKey::CreateFromPrivateKeyInfo( | 145 return crypto::RSAPrivateKey::CreateFromPrivateKeyInfo( |
146 std::vector<uint8>(private_key_bytes.begin(), private_key_bytes.end())); | 146 std::vector<uint8>(private_key_bytes.begin(), private_key_bytes.end())); |
147 } | 147 } |
148 | 148 |
149 crypto::RSAPrivateKey* ExtensionCreator::GenerateKey(const base::FilePath& | 149 crypto::RSAPrivateKey* ExtensionCreator::GenerateKey(const base::FilePath& |
150 output_private_key_path) { | 150 output_private_key_path) { |
151 scoped_ptr<crypto::RSAPrivateKey> key_pair( | 151 scoped_ptr<crypto::RSAPrivateKey> key_pair( |
152 crypto::RSAPrivateKey::Create(kRSAKeySize)); | 152 crypto::RSAPrivateKey::Create(kRSAKeySize)); |
153 if (!key_pair.get()) { | 153 if (!key_pair) { |
154 error_message_ = | 154 error_message_ = |
155 l10n_util::GetStringUTF8(IDS_EXTENSION_PRIVATE_KEY_FAILED_TO_GENERATE); | 155 l10n_util::GetStringUTF8(IDS_EXTENSION_PRIVATE_KEY_FAILED_TO_GENERATE); |
156 return NULL; | 156 return NULL; |
157 } | 157 } |
158 | 158 |
159 std::vector<uint8> private_key_vector; | 159 std::vector<uint8> private_key_vector; |
160 if (!key_pair->ExportPrivateKey(&private_key_vector)) { | 160 if (!key_pair->ExportPrivateKey(&private_key_vector)) { |
161 error_message_ = | 161 error_message_ = |
162 l10n_util::GetStringUTF8(IDS_EXTENSION_PRIVATE_KEY_FAILED_TO_EXPORT); | 162 l10n_util::GetStringUTF8(IDS_EXTENSION_PRIVATE_KEY_FAILED_TO_EXPORT); |
163 return NULL; | 163 return NULL; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 error_message_ = l10n_util::GetStringUTF8(IDS_EXTENSION_SHARING_VIOLATION); | 243 error_message_ = l10n_util::GetStringUTF8(IDS_EXTENSION_SHARING_VIOLATION); |
244 return false; | 244 return false; |
245 } | 245 } |
246 | 246 |
247 std::vector<uint8> public_key; | 247 std::vector<uint8> public_key; |
248 CHECK(private_key->ExportPublicKey(&public_key)); | 248 CHECK(private_key->ExportPublicKey(&public_key)); |
249 | 249 |
250 CrxFile::Error error; | 250 CrxFile::Error error; |
251 scoped_ptr<CrxFile> crx( | 251 scoped_ptr<CrxFile> crx( |
252 CrxFile::Create(public_key.size(), signature.size(), &error)); | 252 CrxFile::Create(public_key.size(), signature.size(), &error)); |
253 if (!crx.get()) { | 253 if (!crx) { |
254 LOG(ERROR) << "cannot create CrxFileHeader: " << error; | 254 LOG(ERROR) << "cannot create CrxFileHeader: " << error; |
255 } | 255 } |
256 const CrxFile::Header header = crx->header(); | 256 const CrxFile::Header header = crx->header(); |
257 | 257 |
258 if (fwrite(&header, sizeof(header), 1, crx_handle.get()) != 1) { | 258 if (fwrite(&header, sizeof(header), 1, crx_handle.get()) != 1) { |
259 PLOG(ERROR) << "fwrite failed to write header"; | 259 PLOG(ERROR) << "fwrite failed to write header"; |
260 } | 260 } |
261 if (fwrite(&public_key.front(), sizeof(uint8), public_key.size(), | 261 if (fwrite(&public_key.front(), sizeof(uint8), public_key.size(), |
262 crx_handle.get()) != public_key.size()) { | 262 crx_handle.get()) != public_key.size()) { |
263 PLOG(ERROR) << "fwrite failed to write public_key.front"; | 263 PLOG(ERROR) << "fwrite failed to write public_key.front"; |
(...skipping 28 matching lines...) Expand all Loading... |
292 output_private_key_path, run_flags)) { | 292 output_private_key_path, run_flags)) { |
293 return false; | 293 return false; |
294 } | 294 } |
295 | 295 |
296 // Initialize Key Pair | 296 // Initialize Key Pair |
297 scoped_ptr<crypto::RSAPrivateKey> key_pair; | 297 scoped_ptr<crypto::RSAPrivateKey> key_pair; |
298 if (!private_key_path.value().empty()) | 298 if (!private_key_path.value().empty()) |
299 key_pair.reset(ReadInputKey(private_key_path)); | 299 key_pair.reset(ReadInputKey(private_key_path)); |
300 else | 300 else |
301 key_pair.reset(GenerateKey(output_private_key_path)); | 301 key_pair.reset(GenerateKey(output_private_key_path)); |
302 if (!key_pair.get()) | 302 if (!key_pair) |
303 return false; | 303 return false; |
304 | 304 |
305 // Perform some extra validation by loading the extension. | 305 // Perform some extra validation by loading the extension. |
306 // TODO(aa): Can this go before creating the key pair? This would mean not | 306 // TODO(aa): Can this go before creating the key pair? This would mean not |
307 // passing ID into LoadExtension which seems OK. | 307 // passing ID into LoadExtension which seems OK. |
308 if (!ValidateManifest(extension_dir, key_pair.get(), run_flags)) | 308 if (!ValidateManifest(extension_dir, key_pair.get(), run_flags)) |
309 return false; | 309 return false; |
310 | 310 |
311 base::ScopedTempDir temp_dir; | 311 base::ScopedTempDir temp_dir; |
312 if (!temp_dir.CreateUniqueTempDir()) | 312 if (!temp_dir.CreateUniqueTempDir()) |
313 return false; | 313 return false; |
314 | 314 |
315 // Zip up the extension. | 315 // Zip up the extension. |
316 base::FilePath zip_path; | 316 base::FilePath zip_path; |
317 std::vector<uint8> signature; | 317 std::vector<uint8> signature; |
318 bool result = false; | 318 bool result = false; |
319 if (CreateZip(extension_dir, temp_dir.path(), &zip_path) && | 319 if (CreateZip(extension_dir, temp_dir.path(), &zip_path) && |
320 SignZip(zip_path, key_pair.get(), &signature) && | 320 SignZip(zip_path, key_pair.get(), &signature) && |
321 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { | 321 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { |
322 result = true; | 322 result = true; |
323 } | 323 } |
324 | 324 |
325 file_util::Delete(zip_path, false); | 325 file_util::Delete(zip_path, false); |
326 return result; | 326 return result; |
327 } | 327 } |
328 | 328 |
329 } // namespace extensions | 329 } // namespace extensions |
OLD | NEW |