| 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/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "chrome/browser/extensions/extensions_service.h" |
| 15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/common/zip.h" | 17 #include "chrome/common/zip.h" |
| 17 #include "net/base/base64.h" | 18 #include "net/base/base64.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 const int kRSAKeySize = 1024; | 21 const int kRSAKeySize = 1024; |
| 21 }; | 22 }; |
| 22 | 23 |
| 23 const char ExtensionCreator::kExtensionHeaderMagic[] = "Cr24"; | |
| 24 | |
| 25 bool ExtensionCreator::InitializeInput( | 24 bool ExtensionCreator::InitializeInput( |
| 26 const FilePath& extension_dir, | 25 const FilePath& extension_dir, |
| 27 const FilePath& private_key_path, | 26 const FilePath& private_key_path, |
| 28 const FilePath& private_key_output_path) { | 27 const FilePath& private_key_output_path) { |
| 29 // Validate input |extension_dir|. | 28 // Validate input |extension_dir|. |
| 30 if (extension_dir.value().empty() || | 29 if (extension_dir.value().empty() || |
| 31 !file_util::DirectoryExists(extension_dir)) { | 30 !file_util::DirectoryExists(extension_dir)) { |
| 32 error_message_ = "Input directory must exist."; | 31 error_message_ = "Input directory must exist."; |
| 33 return false; | 32 return false; |
| 34 } | 33 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 if (file_util::PathExists(crx_path)) | 159 if (file_util::PathExists(crx_path)) |
| 161 file_util::Delete(crx_path, false); | 160 file_util::Delete(crx_path, false); |
| 162 ScopedStdioHandle crx_handle(file_util::OpenFile(crx_path, "wb")); | 161 ScopedStdioHandle crx_handle(file_util::OpenFile(crx_path, "wb")); |
| 163 | 162 |
| 164 std::vector<uint8> public_key; | 163 std::vector<uint8> public_key; |
| 165 if (!private_key->ExportPublicKey(&public_key)) { | 164 if (!private_key->ExportPublicKey(&public_key)) { |
| 166 error_message_ = "Failed to export public key."; | 165 error_message_ = "Failed to export public key."; |
| 167 return false; | 166 return false; |
| 168 } | 167 } |
| 169 | 168 |
| 170 ExtensionCreator::ExtensionHeader header; | 169 ExtensionsService::ExtensionHeader header; |
| 171 memcpy(&header.magic, ExtensionCreator::kExtensionHeaderMagic, | 170 memcpy(&header.magic, ExtensionsService::kExtensionHeaderMagic, |
| 172 ExtensionCreator::kExtensionHeaderMagicSize); | 171 ExtensionsService::kExtensionHeaderMagicSize); |
| 173 header.version = kCurrentVersion; | 172 header.version = ExtensionsService::kCurrentVersion; |
| 174 header.key_size = public_key.size(); | 173 header.key_size = public_key.size(); |
| 175 header.signature_size = signature.size(); | 174 header.signature_size = signature.size(); |
| 176 | 175 |
| 177 fwrite(&header, sizeof(ExtensionCreator::ExtensionHeader), 1, | 176 fwrite(&header, sizeof(ExtensionsService::ExtensionHeader), 1, |
| 178 crx_handle.get()); | 177 crx_handle.get()); |
| 179 fwrite(&public_key.front(), sizeof(uint8), public_key.size(), | 178 fwrite(&public_key.front(), sizeof(uint8), public_key.size(), |
| 180 crx_handle.get()); | 179 crx_handle.get()); |
| 181 fwrite(&signature.front(), sizeof(uint8), signature.size(), | 180 fwrite(&signature.front(), sizeof(uint8), signature.size(), |
| 182 crx_handle.get()); | 181 crx_handle.get()); |
| 183 | 182 |
| 184 uint8 buffer[1 << 16]; | 183 uint8 buffer[1 << 16]; |
| 185 int bytes_read = -1; | 184 int bytes_read = -1; |
| 186 ScopedStdioHandle zip_handle(file_util::OpenFile(zip_path, "rb")); | 185 ScopedStdioHandle zip_handle(file_util::OpenFile(zip_path, "rb")); |
| 187 while ((bytes_read = fread(buffer, 1, sizeof(buffer), | 186 while ((bytes_read = fread(buffer, 1, sizeof(buffer), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 217 bool result = false; | 216 bool result = false; |
| 218 if (CreateZip(extension_dir, &zip_path) && | 217 if (CreateZip(extension_dir, &zip_path) && |
| 219 SignZip(zip_path, key_pair.get(), &signature) && | 218 SignZip(zip_path, key_pair.get(), &signature) && |
| 220 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { | 219 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { |
| 221 result = true; | 220 result = true; |
| 222 } | 221 } |
| 223 | 222 |
| 224 file_util::Delete(zip_path, false); | 223 file_util::Delete(zip_path, false); |
| 225 return result; | 224 return result; |
| 226 } | 225 } |
| OLD | NEW |