From 3f1b9154af9dc6cd9a282a715e00f768ca83cc04 Mon Sep 17 00:00:00 2001 From: Claudio DeSouza Date: Wed, 25 Jun 2025 16:04:00 +0100 Subject: [PATCH] [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 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 Auto-Submit: Elly FJ Reviewed-by: Devlin Cronin Cr-Commit-Position: refs/heads/main@{#1478295} --- .../components/crx_file/crx_creator.cc | 18 ++++++++++-------- chromium_src/components/crx_file/crx_creator.h | 9 +++++---- .../extensions/browser/extension_creator.cc | 11 +++++------ .../components-crx_file-crx_creator.cc.patch | 8 ++++---- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/chromium_src/components/crx_file/crx_creator.cc b/chromium_src/components/crx_file/crx_creator.cc index 83c7c1fdbb0..6cd39311610 100644 --- a/chromium_src/components/crx_file/crx_creator.cc +++ b/chromium_src/components/crx_file/crx_creator.cc @@ -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 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 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 keys) { +CreatorResult CreateWithMultipleKeys( + const base::FilePath& output_path, + const base::FilePath& zip_path, + base::span 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); diff --git a/chromium_src/components/crx_file/crx_creator.h b/chromium_src/components/crx_file/crx_creator.h index 8b40c0edfca..144a07d97dc 100644 --- a/chromium_src/components/crx_file/crx_creator.h +++ b/chromium_src/components/crx_file/crx_creator.h @@ -8,13 +8,14 @@ #include // IWYU pragma: export -#include +#include "base/containers/span.h" namespace crx_file { -CreatorResult CreateWithMultipleKeys(const base::FilePath& output_path, - const base::FilePath& zip_path, - std::vector keys); +CreatorResult CreateWithMultipleKeys( + const base::FilePath& output_path, + const base::FilePath& zip_path, + base::span keys); } // namespace crx_file #endif // BRAVE_CHROMIUM_SRC_COMPONENTS_CRX_FILE_CRX_CREATOR_H_ diff --git a/chromium_src/extensions/browser/extension_creator.cc b/chromium_src/extensions/browser/extension_creator.cc index 6fc23a423be..e63f358f451 100644 --- a/chromium_src/extensions/browser/extension_creator.cc +++ b/chromium_src/extensions/browser/extension_creator.cc @@ -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 keys{signing_key}; \ - std::vector> keep_keys_alive; \ + std::vector 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 key = \ + std::optional 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 diff --git a/patches/components-crx_file-crx_creator.cc.patch b/patches/components-crx_file-crx_creator.cc.patch index 2a88f89ad3c..1e96f2d894d 100644 --- a/patches/components-crx_file-crx_creator.cc.patch +++ b/patches/components-crx_file-crx_creator.cc.patch @@ -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 =