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/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 Loading... | |
| 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; |
|
Sorin Jianu
2017/05/15 19:49:51
initialize?
waffles
2017/05/16 00:29:01
Done.
| |
| 256 std::unique_ptr<crx_file::CrxFile> crx( | 256 std::unique_ptr<crx_file::Crx2File> crx( |
|
Sorin Jianu
2017/05/15 19:49:51
consider using the assignment syntax for initializ
Sorin Jianu
2017/05/15 19:49:51
Could use auto.
waffles
2017/05/16 00:29:01
Done.
waffles
2017/05/16 00:29:01
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; |
|
Sorin Jianu
2017/05/15 19:49:51
If this error handling sufficient? It looks to me
waffles
2017/05/16 00:29:01
Hm, I agree. Seems strange. PTAL?
| |
| 260 } | 260 } |
| 261 const crx_file::CrxFile::Header header = crx->header(); | 261 const crx_file::Crx2File::Header header = crx->header(); |
| 262 | 262 |
| 263 if (fwrite(&header, sizeof(header), 1, crx_handle.get()) != 1) { | 263 if (fwrite(&header, sizeof(header), 1, crx_handle.get()) != 1) { |
| 264 PLOG(ERROR) << "fwrite failed to write header"; | 264 PLOG(ERROR) << "fwrite failed to write header"; |
| 265 } | 265 } |
| 266 if (fwrite(&public_key.front(), sizeof(uint8_t), public_key.size(), | 266 if (fwrite(&public_key.front(), sizeof(uint8_t), public_key.size(), |
| 267 crx_handle.get()) != public_key.size()) { | 267 crx_handle.get()) != public_key.size()) { |
| 268 PLOG(ERROR) << "fwrite failed to write public_key.front"; | 268 PLOG(ERROR) << "fwrite failed to write public_key.front"; |
| 269 } | 269 } |
| 270 if (fwrite(&signature.front(), sizeof(uint8_t), signature.size(), | 270 if (fwrite(&signature.front(), sizeof(uint8_t), signature.size(), |
| 271 crx_handle.get()) != signature.size()) { | 271 crx_handle.get()) != signature.size()) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 SignZip(zip_path, key_pair.get(), &signature) && | 325 SignZip(zip_path, key_pair.get(), &signature) && |
| 326 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { | 326 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { |
| 327 result = true; | 327 result = true; |
| 328 } | 328 } |
| 329 | 329 |
| 330 base::DeleteFile(zip_path, false); | 330 base::DeleteFile(zip_path, false); |
| 331 return result; | 331 return result; |
| 332 } | 332 } |
| 333 | 333 |
| 334 } // namespace extensions | 334 } // namespace extensions |
| OLD | NEW |