| 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/string_util.h" | 15 #include "base/string_util.h" |
| 15 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" | 16 #include "chrome/browser/extensions/sandboxed_extension_unpacker.h" |
| 16 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/common/zip.h" | 18 #include "chrome/common/zip.h" |
| 18 #include "net/base/base64.h" | 19 #include "net/base/base64.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 const int kRSAKeySize = 1024; | 22 const int kRSAKeySize = 1024; |
| 22 }; | 23 }; |
| 23 | 24 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 pem_output.c_str(), pem_output.size())) { | 113 pem_output.c_str(), pem_output.size())) { |
| 113 error_message_ = "Failed to write private key."; | 114 error_message_ = "Failed to write private key."; |
| 114 return NULL; | 115 return NULL; |
| 115 } | 116 } |
| 116 } | 117 } |
| 117 | 118 |
| 118 return key_pair.release(); | 119 return key_pair.release(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 bool ExtensionCreator::CreateZip(const FilePath& extension_dir, | 122 bool ExtensionCreator::CreateZip(const FilePath& extension_dir, |
| 123 const FilePath& temp_path, |
| 122 FilePath* zip_path) { | 124 FilePath* zip_path) { |
| 123 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("chrome_"), zip_path); | 125 *zip_path = temp_path.Append(FILE_PATH_LITERAL("extension.zip")); |
| 124 *zip_path = zip_path->Append(FILE_PATH_LITERAL("extension.zip")); | |
| 125 | 126 |
| 126 if (!Zip(extension_dir, *zip_path, false)) { // no hidden files | 127 if (!Zip(extension_dir, *zip_path, false)) { // no hidden files |
| 127 error_message_ = "Failed to create temporary zip file during packaging."; | 128 error_message_ = "Failed to create temporary zip file during packaging."; |
| 128 return false; | 129 return false; |
| 129 } | 130 } |
| 130 | 131 |
| 131 return true; | 132 return true; |
| 132 } | 133 } |
| 133 | 134 |
| 134 bool ExtensionCreator::SignZip(const FilePath& zip_path, | 135 bool ExtensionCreator::SignZip(const FilePath& zip_path, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 215 |
| 215 // Initialize Key Pair | 216 // Initialize Key Pair |
| 216 scoped_ptr<base::RSAPrivateKey> key_pair; | 217 scoped_ptr<base::RSAPrivateKey> key_pair; |
| 217 if (!private_key_path.value().empty()) | 218 if (!private_key_path.value().empty()) |
| 218 key_pair.reset(ReadInputKey(private_key_path)); | 219 key_pair.reset(ReadInputKey(private_key_path)); |
| 219 else | 220 else |
| 220 key_pair.reset(GenerateKey(output_private_key_path)); | 221 key_pair.reset(GenerateKey(output_private_key_path)); |
| 221 if (!key_pair.get()) | 222 if (!key_pair.get()) |
| 222 return false; | 223 return false; |
| 223 | 224 |
| 225 ScopedTempDir temp_dir; |
| 226 if (!temp_dir.CreateUniqueTempDir()) |
| 227 return false; |
| 228 |
| 224 // Zip up the extension. | 229 // Zip up the extension. |
| 225 FilePath zip_path; | 230 FilePath zip_path; |
| 226 std::vector<uint8> signature; | 231 std::vector<uint8> signature; |
| 227 bool result = false; | 232 bool result = false; |
| 228 if (CreateZip(extension_dir, &zip_path) && | 233 if (CreateZip(extension_dir, temp_dir.path(), &zip_path) && |
| 229 SignZip(zip_path, key_pair.get(), &signature) && | 234 SignZip(zip_path, key_pair.get(), &signature) && |
| 230 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { | 235 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { |
| 231 result = true; | 236 result = true; |
| 232 } | 237 } |
| 233 | 238 |
| 234 file_util::Delete(zip_path, false); | 239 file_util::Delete(zip_path, false); |
| 235 return result; | 240 return result; |
| 236 } | 241 } |
| OLD | NEW |