Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/memory/ptr_util.h" | |
|
Sorin Jianu
2017/05/16 20:54:50
we don't need this anymore now.
waffles
2017/05/16 22:34:52
Done.
| |
| 17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 18 #include "chrome/browser/extensions/extension_creator_filter.h" | 19 #include "chrome/browser/extensions/extension_creator_filter.h" |
| 19 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
| 20 #include "components/crx_file/crx_file.h" | 21 #include "components/crx_file/crx2_file.h" |
| 21 #include "components/crx_file/id_util.h" | 22 #include "components/crx_file/id_util.h" |
| 22 #include "crypto/rsa_private_key.h" | 23 #include "crypto/rsa_private_key.h" |
| 23 #include "crypto/signature_creator.h" | 24 #include "crypto/signature_creator.h" |
| 24 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
| 25 #include "extensions/common/file_util.h" | 26 #include "extensions/common/file_util.h" |
| 26 #include "third_party/zlib/google/zip.h" | 27 #include "third_party/zlib/google/zip.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 const int kRSAKeySize = 2048; | 31 const int kRSAKeySize = 2048; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 base::DeleteFile(crx_path, false); | 246 base::DeleteFile(crx_path, false); |
| 246 base::ScopedFILE crx_handle(base::OpenFile(crx_path, "wb")); | 247 base::ScopedFILE crx_handle(base::OpenFile(crx_path, "wb")); |
| 247 if (!crx_handle.get()) { | 248 if (!crx_handle.get()) { |
| 248 error_message_ = l10n_util::GetStringUTF8(IDS_EXTENSION_SHARING_VIOLATION); | 249 error_message_ = l10n_util::GetStringUTF8(IDS_EXTENSION_SHARING_VIOLATION); |
| 249 return false; | 250 return false; |
| 250 } | 251 } |
| 251 | 252 |
| 252 std::vector<uint8_t> public_key; | 253 std::vector<uint8_t> public_key; |
| 253 CHECK(private_key->ExportPublicKey(&public_key)); | 254 CHECK(private_key->ExportPublicKey(&public_key)); |
| 254 | 255 |
| 255 crx_file::CrxFile::Error error; | 256 crx_file::Crx2File::Error error = crx_file::Crx2File::kMaxValue; |
| 256 std::unique_ptr<crx_file::CrxFile> crx( | 257 auto crx = |
| 257 crx_file::CrxFile::Create(public_key.size(), signature.size(), &error)); | 258 crx_file::Crx2File::Create(public_key.size(), signature.size(), &error); |
| 258 if (!crx) { | 259 if (!crx) { |
| 259 LOG(ERROR) << "cannot create CrxFileHeader: " << error; | 260 LOG(ERROR) << "cannot create Crx2FileHeader: " << error; |
| 261 return false; | |
| 260 } | 262 } |
| 261 const crx_file::CrxFile::Header header = crx->header(); | 263 const crx_file::Crx2File::Header header = crx->header(); |
| 262 | 264 |
| 263 if (fwrite(&header, sizeof(header), 1, crx_handle.get()) != 1) { | 265 if (fwrite(&header, sizeof(header), 1, crx_handle.get()) != 1) { |
| 264 PLOG(ERROR) << "fwrite failed to write header"; | 266 PLOG(ERROR) << "fwrite failed to write header"; |
| 267 return false; | |
| 265 } | 268 } |
| 266 if (fwrite(&public_key.front(), sizeof(uint8_t), public_key.size(), | 269 if (fwrite(&public_key.front(), sizeof(uint8_t), public_key.size(), |
| 267 crx_handle.get()) != public_key.size()) { | 270 crx_handle.get()) != public_key.size()) { |
| 268 PLOG(ERROR) << "fwrite failed to write public_key.front"; | 271 PLOG(ERROR) << "fwrite failed to write public_key.front"; |
| 272 return false; | |
| 269 } | 273 } |
| 270 if (fwrite(&signature.front(), sizeof(uint8_t), signature.size(), | 274 if (fwrite(&signature.front(), sizeof(uint8_t), signature.size(), |
| 271 crx_handle.get()) != signature.size()) { | 275 crx_handle.get()) != signature.size()) { |
| 272 PLOG(ERROR) << "fwrite failed to write signature.front"; | 276 PLOG(ERROR) << "fwrite failed to write signature.front"; |
| 277 return false; | |
| 273 } | 278 } |
| 274 | 279 |
| 275 size_t buffer_size = 1 << 16; | 280 size_t buffer_size = 1 << 16; |
| 276 std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); | 281 std::unique_ptr<uint8_t[]> buffer(new uint8_t[buffer_size]); |
| 277 size_t bytes_read = 0; | 282 size_t bytes_read = 0; |
| 278 base::ScopedFILE zip_handle(base::OpenFile(zip_path, "rb")); | 283 base::ScopedFILE zip_handle(base::OpenFile(zip_path, "rb")); |
| 279 while ((bytes_read = fread(buffer.get(), 1, buffer_size, | 284 while ((bytes_read = fread(buffer.get(), 1, buffer_size, |
| 280 zip_handle.get())) > 0) { | 285 zip_handle.get())) > 0) { |
| 281 if (fwrite(buffer.get(), sizeof(char), bytes_read, crx_handle.get()) != | 286 if (fwrite(buffer.get(), sizeof(char), bytes_read, crx_handle.get()) != |
| 282 bytes_read) { | 287 bytes_read) { |
| 283 PLOG(ERROR) << "fwrite failed to write buffer"; | 288 PLOG(ERROR) << "fwrite failed to write buffer"; |
| 289 return false; | |
| 284 } | 290 } |
| 285 } | 291 } |
| 286 | 292 |
| 287 return true; | 293 return true; |
| 288 } | 294 } |
| 289 | 295 |
| 290 bool ExtensionCreator::Run(const base::FilePath& extension_dir, | 296 bool ExtensionCreator::Run(const base::FilePath& extension_dir, |
| 291 const base::FilePath& crx_path, | 297 const base::FilePath& crx_path, |
| 292 const base::FilePath& private_key_path, | 298 const base::FilePath& private_key_path, |
| 293 const base::FilePath& output_private_key_path, | 299 const base::FilePath& output_private_key_path, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 SignZip(zip_path, key_pair.get(), &signature) && | 331 SignZip(zip_path, key_pair.get(), &signature) && |
| 326 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { | 332 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { |
| 327 result = true; | 333 result = true; |
| 328 } | 334 } |
| 329 | 335 |
| 330 base::DeleteFile(zip_path, false); | 336 base::DeleteFile(zip_path, false); |
| 331 return result; | 337 return result; |
| 332 } | 338 } |
| 333 | 339 |
| 334 } // namespace extensions | 340 } // namespace extensions |
| OLD | NEW |