| 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/extension_creator.h" | 5 #include "chrome/browser/extensions/extension_creator.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/crypto/rsa_private_key.h" | 10 #include "base/crypto/rsa_private_key.h" |
| 11 #include "base/crypto/signature_creator.h" | 11 #include "base/crypto/signature_creator.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/scoped_handle.h" | 13 #include "base/scoped_handle.h" |
| 14 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "chrome/browser/extensions/extension_file_util.h" |
| 16 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" | 17 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" |
| 17 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
| 18 #include "chrome/common/zip.h" | 19 #include "chrome/common/zip.h" |
| 19 #include "net/base/base64.h" | 20 #include "net/base/base64.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 const int kRSAKeySize = 1024; | 23 const int kRSAKeySize = 1024; |
| 23 }; | 24 }; |
| 24 | 25 |
| 25 bool ExtensionCreator::InitializeInput( | 26 bool ExtensionCreator::InitializeInput( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 43 // If an |output_private_key| path is given, make sure it doesn't over-write | 44 // If an |output_private_key| path is given, make sure it doesn't over-write |
| 44 // an existing private key. | 45 // an existing private key. |
| 45 if (private_key_path.value().empty() && | 46 if (private_key_path.value().empty() && |
| 46 !private_key_output_path.value().empty() && | 47 !private_key_output_path.value().empty() && |
| 47 file_util::PathExists(private_key_output_path)) { | 48 file_util::PathExists(private_key_output_path)) { |
| 48 error_message_ = "A private key for specified extension already exists. " | 49 error_message_ = "A private key for specified extension already exists. " |
| 49 "Reuse that key or delete it first."; | 50 "Reuse that key or delete it first."; |
| 50 return false; | 51 return false; |
| 51 } | 52 } |
| 52 | 53 |
| 54 // Load the extension once. We don't really need it, but this does a lot of |
| 55 // useful validation of the structure. |
| 56 scoped_ptr<Extension> extension( |
| 57 extension_file_util::LoadExtension(extension_dir, |
| 58 false, // key not required |
| 59 &error_message_)); |
| 60 if (!extension.get()) |
| 61 return false; // LoadExtension already set error_message_. |
| 62 |
| 53 return true; | 63 return true; |
| 54 } | 64 } |
| 55 | 65 |
| 56 base::RSAPrivateKey* ExtensionCreator::ReadInputKey(const FilePath& | 66 base::RSAPrivateKey* ExtensionCreator::ReadInputKey(const FilePath& |
| 57 private_key_path) { | 67 private_key_path) { |
| 58 if (!file_util::PathExists(private_key_path)) { | 68 if (!file_util::PathExists(private_key_path)) { |
| 59 error_message_ = "Input value for private key must exist."; | 69 error_message_ = "Input value for private key must exist."; |
| 60 return false; | 70 return false; |
| 61 } | 71 } |
| 62 | 72 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 bool result = false; | 242 bool result = false; |
| 233 if (CreateZip(extension_dir, temp_dir.path(), &zip_path) && | 243 if (CreateZip(extension_dir, temp_dir.path(), &zip_path) && |
| 234 SignZip(zip_path, key_pair.get(), &signature) && | 244 SignZip(zip_path, key_pair.get(), &signature) && |
| 235 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { | 245 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { |
| 236 result = true; | 246 result = true; |
| 237 } | 247 } |
| 238 | 248 |
| 239 file_util::Delete(zip_path, false); | 249 file_util::Delete(zip_path, false); |
| 240 return result; | 250 return result; |
| 241 } | 251 } |
| OLD | NEW |