[cr140] Update GetCrxId to spanified definition
This only affects the arguments for this override. Chromium changes: https://chromium.googlesource.com/chromium/src/+/8ff5b0d783a0415593ecf400b2c829463289d25a commit 8ff5b0d783a0415593ecf400b2c829463289d25a Author: Elly <ellyjones@chromium.org> Date: Tue Jun 24 17:52:27 2025 -0700 crx_file: migrate to crypto/keypair and crypto/sign The new APIs are a bit more ergonomic, have fewer failure cases, and are not deprecated. This change also fixes some unsafe buffer usage (of argv) in crx3_build_action. Bug: 372283556 Change-Id: I8220ff7499385001f7ba83e8eb638ee7dd987541 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6663109 Commit-Queue: Elly FJ <ellyjones@chromium.org> Auto-Submit: Elly FJ <ellyjones@chromium.org> Reviewed-by: Devlin Cronin <rdevlin.cronin@chromium.org> Cr-Commit-Position: refs/heads/main@{#1478295}
This commit is contained in:
@@ -11,7 +11,8 @@ namespace crx_file {
|
||||
|
||||
class CrxFileHeader;
|
||||
|
||||
std::string GetCrxId_BraveImpl(const std::string& key, CrxFileHeader* header);
|
||||
std::string GetCrxId_BraveImpl(base::span<const uint8_t> key,
|
||||
CrxFileHeader* header);
|
||||
|
||||
} // namespace crx_file
|
||||
|
||||
@@ -21,21 +22,22 @@ namespace crx_file {
|
||||
|
||||
// Override for GetCrxId() in SignArchiveAndCreateHeader() to generate the
|
||||
// correct signed data for the second signature.
|
||||
std::string GetCrxId_BraveImpl(const std::string& key, CrxFileHeader* header) {
|
||||
std::string GetCrxId_BraveImpl(base::span<const uint8_t> key,
|
||||
CrxFileHeader* header) {
|
||||
if (header->sha256_with_rsa_size() > 0) {
|
||||
const AsymmetricKeyProof& first_proof = header->sha256_with_rsa()[0];
|
||||
return GetCrxId(first_proof.public_key());
|
||||
return GetCrxId(base::as_byte_span(first_proof.public_key()));
|
||||
}
|
||||
return GetCrxId(key);
|
||||
}
|
||||
|
||||
CreatorResult CreateWithMultipleKeys(const base::FilePath& output_path,
|
||||
const base::FilePath& zip_path,
|
||||
std::vector<crypto::RSAPrivateKey*> keys) {
|
||||
CreatorResult CreateWithMultipleKeys(
|
||||
const base::FilePath& output_path,
|
||||
const base::FilePath& zip_path,
|
||||
base::span<const crypto::keypair::PrivateKey> keys) {
|
||||
CrxFileHeader header;
|
||||
base::File file(zip_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
|
||||
for (auto key : keys) {
|
||||
CHECK(key);
|
||||
for (const auto& key : keys) {
|
||||
file.Seek(base::File::Whence::FROM_BEGIN, 0);
|
||||
const CreatorResult signing_result =
|
||||
SignArchiveAndCreateHeader(output_path, &file, key, &header);
|
||||
|
||||
@@ -8,13 +8,14 @@
|
||||
|
||||
#include <components/crx_file/crx_creator.h> // IWYU pragma: export
|
||||
|
||||
#include <vector>
|
||||
#include "base/containers/span.h"
|
||||
|
||||
namespace crx_file {
|
||||
|
||||
CreatorResult CreateWithMultipleKeys(const base::FilePath& output_path,
|
||||
const base::FilePath& zip_path,
|
||||
std::vector<crypto::RSAPrivateKey*> keys);
|
||||
CreatorResult CreateWithMultipleKeys(
|
||||
const base::FilePath& output_path,
|
||||
const base::FilePath& zip_path,
|
||||
base::span<const crypto::keypair::PrivateKey> keys);
|
||||
} // namespace crx_file
|
||||
|
||||
#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_CRX_FILE_CRX_CREATOR_H_
|
||||
|
||||
@@ -19,21 +19,20 @@ constexpr char kAltPublisherKeySwitch[] = "brave-extension-publisher-key-alt";
|
||||
} // namespace
|
||||
|
||||
#define BRAVE_CREATE_CRX(output_path, zip_path, signing_key) \
|
||||
std::vector<crypto::RSAPrivateKey*> keys{signing_key}; \
|
||||
std::vector<std::unique_ptr<crypto::RSAPrivateKey>> keep_keys_alive; \
|
||||
std::vector<crypto::keypair::PrivateKey> keys{signing_key}; \
|
||||
const auto* cmd = base::CommandLine::ForCurrentProcess(); \
|
||||
const char* switches[] = {kPublisherKeySwitch, kAltPublisherKeySwitch}; \
|
||||
for (const char* switch_name : switches) { \
|
||||
if (cmd->HasSwitch(switch_name)) { \
|
||||
std::unique_ptr<crypto::RSAPrivateKey> key = \
|
||||
std::optional<crypto::keypair::PrivateKey> key = \
|
||||
ReadInputKey(cmd->GetSwitchValuePath(switch_name)); \
|
||||
if (!key) \
|
||||
return false; /* error_message_ was set by ReadInputKey() */ \
|
||||
keys.push_back(key.get()); \
|
||||
keep_keys_alive.push_back(std::move(key)); \
|
||||
keys.push_back(std::move(key).value()); \
|
||||
} \
|
||||
} \
|
||||
result = crx_file::CreateWithMultipleKeys(output_path, zip_path, keys);
|
||||
result = crx_file::CreateWithMultipleKeys(output_path, zip_path, \
|
||||
base::span(keys));
|
||||
|
||||
#include <extensions/browser/extension_creator.cc>
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
diff --git a/components/crx_file/crx_creator.cc b/components/crx_file/crx_creator.cc
|
||||
index 419ce3d0b6efa0d68109dd0b86568b99919e238e..a0daca2b896bdef86f81415532acf2491b0e0ff3 100644
|
||||
index cb90c22f3566a581946553a3cf07b6ad7e90bf87..db558ae734723ce6705c4ed328b01c0a7ca0d968 100644
|
||||
--- a/components/crx_file/crx_creator.cc
|
||||
+++ b/components/crx_file/crx_creator.cc
|
||||
@@ -73,7 +73,7 @@ CreatorResult SignArchiveAndCreateHeader(const base::FilePath& output_path,
|
||||
@@ -70,7 +70,7 @@ CreatorResult SignArchiveAndCreateHeader(
|
||||
|
||||
// Assemble SignedData section.
|
||||
SignedData signed_header_data;
|
||||
- signed_header_data.set_crx_id(GetCrxId(public_key_str));
|
||||
+ signed_header_data.set_crx_id(GetCrxId_BraveImpl(public_key_str, header));
|
||||
- signed_header_data.set_crx_id(GetCrxId(public_key));
|
||||
+ signed_header_data.set_crx_id(GetCrxId_BraveImpl(public_key, header));
|
||||
const std::string signed_header_data_str =
|
||||
signed_header_data.SerializeAsString();
|
||||
const auto signed_header_size_octets =
|
||||
|
||||
Reference in New Issue
Block a user