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

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

Issue 2874503002: Refactor CRX verification in preparation to support CRX₃ files. (Closed)
Patch Set: through #44 Created 3 years, 7 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
« no previous file with comments | « no previous file | components/crx_file/BUILD.gn » ('j') | extensions/browser/sandboxed_unpacker.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/files/scoped_file.h" 15 #include "base/files/scoped_file.h"
16 #include "base/files/scoped_temp_dir.h" 16 #include "base/files/scoped_temp_dir.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "chrome/browser/extensions/extension_creator_filter.h" 18 #include "chrome/browser/extensions/extension_creator_filter.h"
19 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
20 #include "components/crx_file/crx_file.h" 20 #include "components/crx_file/crx2_file.h"
21 #include "components/crx_file/id_util.h" 21 #include "components/crx_file/id_util.h"
22 #include "crypto/rsa_private_key.h" 22 #include "crypto/rsa_private_key.h"
23 #include "crypto/signature_creator.h" 23 #include "crypto/signature_creator.h"
24 #include "extensions/common/extension.h" 24 #include "extensions/common/extension.h"
25 #include "extensions/common/file_util.h" 25 #include "extensions/common/file_util.h"
26 #include "third_party/zlib/google/zip.h" 26 #include "third_party/zlib/google/zip.h"
27 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
28 28
29 namespace { 29 namespace {
30 const int kRSAKeySize = 2048; 30 const int kRSAKeySize = 2048;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 base::DeleteFile(crx_path, false); 245 base::DeleteFile(crx_path, false);
246 base::ScopedFILE crx_handle(base::OpenFile(crx_path, "wb")); 246 base::ScopedFILE crx_handle(base::OpenFile(crx_path, "wb"));
247 if (!crx_handle.get()) { 247 if (!crx_handle.get()) {
248 error_message_ = l10n_util::GetStringUTF8(IDS_EXTENSION_SHARING_VIOLATION); 248 error_message_ = l10n_util::GetStringUTF8(IDS_EXTENSION_SHARING_VIOLATION);
249 return false; 249 return false;
250 } 250 }
251 251
252 std::vector<uint8_t> public_key; 252 std::vector<uint8_t> public_key;
253 CHECK(private_key->ExportPublicKey(&public_key)); 253 CHECK(private_key->ExportPublicKey(&public_key));
254 254
255 crx_file::CrxFile::Error error; 255 crx_file::Crx2File::Error error = crx_file::Crx2File::kMaxValue;
256 std::unique_ptr<crx_file::CrxFile> crx( 256 auto crx =
Devlin 2017/05/16 22:55:02 nit: IMO, this reduces readability, since it's not
waffles 2017/05/17 17:18:22 Done.
257 crx_file::CrxFile::Create(public_key.size(), signature.size(), &error)); 257 crx_file::Crx2File::Create(public_key.size(), signature.size(), &error);
258 if (!crx) { 258 if (!crx) {
259 LOG(ERROR) << "cannot create CrxFileHeader: " << error; 259 LOG(ERROR) << "cannot create Crx2FileHeader: " << error;
260 return false;
Devlin 2017/05/16 22:55:02 this is a behavior change - maybe worth mentioning
waffles 2017/05/17 17:18:22 Done.
260 } 261 }
261 const crx_file::CrxFile::Header header = crx->header(); 262 const crx_file::Crx2File::Header header = crx->header();
262 263
263 if (fwrite(&header, sizeof(header), 1, crx_handle.get()) != 1) { 264 if (fwrite(&header, sizeof(header), 1, crx_handle.get()) != 1) {
264 PLOG(ERROR) << "fwrite failed to write header"; 265 PLOG(ERROR) << "fwrite failed to write header";
266 return false;
265 } 267 }
266 if (fwrite(&public_key.front(), sizeof(uint8_t), public_key.size(), 268 if (fwrite(&public_key.front(), sizeof(uint8_t), public_key.size(),
267 crx_handle.get()) != public_key.size()) { 269 crx_handle.get()) != public_key.size()) {
268 PLOG(ERROR) << "fwrite failed to write public_key.front"; 270 PLOG(ERROR) << "fwrite failed to write public_key.front";
271 return false;
269 } 272 }
270 if (fwrite(&signature.front(), sizeof(uint8_t), signature.size(), 273 if (fwrite(&signature.front(), sizeof(uint8_t), signature.size(),
271 crx_handle.get()) != signature.size()) { 274 crx_handle.get()) != signature.size()) {
272 PLOG(ERROR) << "fwrite failed to write signature.front"; 275 PLOG(ERROR) << "fwrite failed to write signature.front";
276 return false;
273 } 277 }
274 278
275 size_t buffer_size = 1 << 16; 279 size_t buffer_size = 1 << 16;
276 std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); 280 std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]);
277 size_t bytes_read = 0; 281 size_t bytes_read = 0;
278 base::ScopedFILE zip_handle(base::OpenFile(zip_path, "rb")); 282 base::ScopedFILE zip_handle(base::OpenFile(zip_path, "rb"));
279 while ((bytes_read = fread(buffer.get(), 1, buffer_size, 283 while ((bytes_read = fread(buffer.get(), 1, buffer_size,
280 zip_handle.get())) > 0) { 284 zip_handle.get())) > 0) {
281 if (fwrite(buffer.get(), sizeof(char), bytes_read, crx_handle.get()) != 285 if (fwrite(buffer.get(), sizeof(char), bytes_read, crx_handle.get()) !=
282 bytes_read) { 286 bytes_read) {
283 PLOG(ERROR) << "fwrite failed to write buffer"; 287 PLOG(ERROR) << "fwrite failed to write buffer";
288 return false;
284 } 289 }
285 } 290 }
286 291
287 return true; 292 return true;
288 } 293 }
289 294
290 bool ExtensionCreator::Run(const base::FilePath& extension_dir, 295 bool ExtensionCreator::Run(const base::FilePath& extension_dir,
291 const base::FilePath& crx_path, 296 const base::FilePath& crx_path,
292 const base::FilePath& private_key_path, 297 const base::FilePath& private_key_path,
293 const base::FilePath& output_private_key_path, 298 const base::FilePath& output_private_key_path,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 SignZip(zip_path, key_pair.get(), &signature) && 330 SignZip(zip_path, key_pair.get(), &signature) &&
326 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { 331 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) {
327 result = true; 332 result = true;
328 } 333 }
329 334
330 base::DeleteFile(zip_path, false); 335 base::DeleteFile(zip_path, false);
331 return result; 336 return result;
332 } 337 }
333 338
334 } // namespace extensions 339 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | components/crx_file/BUILD.gn » ('j') | extensions/browser/sandboxed_unpacker.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698