Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: chrome/browser/extensions/extension_creator.cc

Issue 125004: Revert "BUG=12114" (Closed)
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
16 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/zip.h" 16 #include "chrome/common/zip.h"
18 #include "net/base/base64.h" 17 #include "net/base/base64.h"
19 18
20 namespace { 19 namespace {
21 const int kRSAKeySize = 1024; 20 const int kRSAKeySize = 1024;
22 }; 21 };
23 22
23 const char ExtensionCreator::kExtensionHeaderMagic[] = "Cr24";
24
24 bool ExtensionCreator::InitializeInput( 25 bool ExtensionCreator::InitializeInput(
25 const FilePath& extension_dir, 26 const FilePath& extension_dir,
26 const FilePath& private_key_path, 27 const FilePath& private_key_path,
27 const FilePath& private_key_output_path) { 28 const FilePath& private_key_output_path) {
28 // Validate input |extension_dir|. 29 // Validate input |extension_dir|.
29 if (extension_dir.value().empty() || 30 if (extension_dir.value().empty() ||
30 !file_util::DirectoryExists(extension_dir)) { 31 !file_util::DirectoryExists(extension_dir)) {
31 error_message_ = "Input directory must exist."; 32 error_message_ = "Input directory must exist.";
32 return false; 33 return false;
33 } 34 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 if (file_util::PathExists(crx_path)) 160 if (file_util::PathExists(crx_path))
160 file_util::Delete(crx_path, false); 161 file_util::Delete(crx_path, false);
161 ScopedStdioHandle crx_handle(file_util::OpenFile(crx_path, "wb")); 162 ScopedStdioHandle crx_handle(file_util::OpenFile(crx_path, "wb"));
162 163
163 std::vector<uint8> public_key; 164 std::vector<uint8> public_key;
164 if (!private_key->ExportPublicKey(&public_key)) { 165 if (!private_key->ExportPublicKey(&public_key)) {
165 error_message_ = "Failed to export public key."; 166 error_message_ = "Failed to export public key.";
166 return false; 167 return false;
167 } 168 }
168 169
169 ExtensionsService::ExtensionHeader header; 170 ExtensionCreator::ExtensionHeader header;
170 memcpy(&header.magic, ExtensionsService::kExtensionHeaderMagic, 171 memcpy(&header.magic, ExtensionCreator::kExtensionHeaderMagic,
171 ExtensionsService::kExtensionHeaderMagicSize); 172 ExtensionCreator::kExtensionHeaderMagicSize);
172 header.version = ExtensionsService::kCurrentVersion; 173 header.version = kCurrentVersion;
173 header.key_size = public_key.size(); 174 header.key_size = public_key.size();
174 header.signature_size = signature.size(); 175 header.signature_size = signature.size();
175 176
176 fwrite(&header, sizeof(ExtensionsService::ExtensionHeader), 1, 177 fwrite(&header, sizeof(ExtensionCreator::ExtensionHeader), 1,
177 crx_handle.get()); 178 crx_handle.get());
178 fwrite(&public_key.front(), sizeof(uint8), public_key.size(), 179 fwrite(&public_key.front(), sizeof(uint8), public_key.size(),
179 crx_handle.get()); 180 crx_handle.get());
180 fwrite(&signature.front(), sizeof(uint8), signature.size(), 181 fwrite(&signature.front(), sizeof(uint8), signature.size(),
181 crx_handle.get()); 182 crx_handle.get());
182 183
183 uint8 buffer[1 << 16]; 184 uint8 buffer[1 << 16];
184 int bytes_read = -1; 185 int bytes_read = -1;
185 ScopedStdioHandle zip_handle(file_util::OpenFile(zip_path, "rb")); 186 ScopedStdioHandle zip_handle(file_util::OpenFile(zip_path, "rb"));
186 while ((bytes_read = fread(buffer, 1, sizeof(buffer), 187 while ((bytes_read = fread(buffer, 1, sizeof(buffer),
(...skipping 29 matching lines...) Expand all
216 bool result = false; 217 bool result = false;
217 if (CreateZip(extension_dir, &zip_path) && 218 if (CreateZip(extension_dir, &zip_path) &&
218 SignZip(zip_path, key_pair.get(), &signature) && 219 SignZip(zip_path, key_pair.get(), &signature) &&
219 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { 220 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) {
220 result = true; 221 result = true;
221 } 222 }
222 223
223 file_util::Delete(zip_path, false); 224 file_util::Delete(zip_path, false);
224 return result; 225 return result;
225 } 226 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_creator.h ('k') | chrome/browser/extensions/extension_shelf_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698