Skip to content

Signature: Add option to use RFC-9421 signatures #1858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Jun 26, 2025

Conversation

obenland
Copy link
Member

@obenland obenland commented Jun 25, 2025

Follow-up to #1849.

Proposed changes:

  • Updated tests to expect deprecation warnings and use the new signature class.
  • Added registration for the new RFC‑9421 signature option.
  • Added a new settings field to toggle the modern signature format.
  • Extended the interface to include RFC‑9421 signature and digest generation.
  • Introduced RFC‑9421 compliant signing with updated signature base string.
  • Updated draft signature implementation with its own digest generation.
  • Refactored request signing to choose between the two signature methods.
  • Reworked HTTP request creation to integrate the new signing approach.

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Apply this PR to a site with followers.
  • Publish a post or make a change to an actor.
  • Make sure the Outbox item gets processed and sent successfully.

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Optional support for RFC-9421 style signatures for outgoing activities, including retry with Draft-Cavage-style signature.

obenland and others added 23 commits June 22, 2025 11:53
Refactored the signature verification logic in Signature::verify_http_signature to delegate to new standard-specific classes. Added Draft_Cavage_Signature and Http_Message_Signature classes implementing a new Signature_Standard interface, supporting both the legacy draft-cavage and new HTTP Message Signature (RFC 9421) standards. Deprecated and stubbed out legacy parsing and verification helpers in class-signature.php. This improves maintainability and prepares for broader signature standard support.
Refactored the signature verification logic to support multiple signature labels by parsing and verifying each label individually. Extracted parsing and verification steps into dedicated private methods for better modularity and maintainability. Improved error handling and signature base string construction.
Replaces unqualified WP_Error references with fully qualified \WP_Error in the Signature class.
Renamed class-draft-cavenage-signature.php to class-draft-cavage-signature.php to correct a typo. Updated date header handling for better clarity and reliability, and fixed regex modifiers for 'created' and 'expires' fields.
Moved digest verification logic into a new private method verify_content_digest, which now supports the Content-Digest header with multiple algorithms.
This update adds handling for the '@scheme' and '@request-target' pseudo-headers in the HTTP message signature base construction. It also improves query string handling and ensures correct formatting of signature parameters, quoting non-numeric values as needed.
Adds support for the @query-param component in signature base string construction and ensures all components are quoted in the @signature-params field. Also updates parameter quoting to properly escape backslashes and double quotes per RFC 9421.
Introduced a call to reset the $_SERVER superglobal in tear_down to ensure test isolation. Also set specific $_SERVER values in the signature header test to better simulate HTTP request context.
Refines parsing of signature components to support query parameters per RFC-9421, updates signature base construction, and enhances test coverage for GET requests with query parameters. Also updates test URIs to use dynamic REST prefixes and namespaces for better compatibility.
Co-authored-by: Copilot <[email protected]>
@obenland
Copy link
Member Author

obenland commented Jun 25, 2025

Does not do double-knocking yet Fixed!

obenland added 2 commits June 25, 2025 12:27
Updated both Draft_Cavage_Signature and Http_Message_Signature classes to consistently use fully qualified PHP function names (e.g., \is_wp_error, \explode, \array_map). Changed several protected methods to private for encapsulation. Moved RSA-PSS algorithm version check into the verify_algorithm method for better separation of concerns and renamed resolve_algorithm to verify_algorithm for clarity.
Base automatically changed from add/basic-rfc-9421 to trunk June 26, 2025 12:55
@obenland obenland marked this pull request as ready for review June 26, 2025 13:45
@Copilot Copilot AI review requested due to automatic review settings June 26, 2025 13:45
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds optional support for RFC‑9421 compliant signatures for outgoing ActivityPub requests and provides a fallback using the Draft‑Cavage signature method. Key changes include updating the test suite to use the new signature routines, adding a new admin setting for toggling signature format, and introducing updated implementations for the signature interfaces and classes.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/includes/class-test-signature.php Updated tests to expect deprecation warnings and use the new signature class
includes/wp-admin/class-settings.php Added registration for the new RFC‑9421 signature option
includes/wp-admin/class-advanced-settings-fields.php Added a new settings field to toggle the modern signature format
includes/signature/interface-signature-standard.php Extended the interface to include RFC‑9421 signature and digest generation
includes/signature/class-http-message-signature.php Introduced RFC‑9421 compliant signing with updated signature base string
includes/signature/class-draft-cavage-signature.php Updated draft signature implementation with its own digest generation
includes/class-signature.php Refactored request signing to choose between the two signature methods
includes/class-http.php Reworked HTTP request creation to integrate the new signing approach
Comments suppressed due to low confidence (2)

includes/signature/class-http-message-signature.php:319

  • Consider updating the docblock for get_signature_base_string to clarify how the $headers argument is merged with $params when $components is a list, ensuring the behavior aligns with the intended RFC‑9421 specifications.
	private function get_signature_base_string( $components, $params, $headers = array() ) {

includes/signature/class-draft-cavage-signature.php:129

  • Verify that the digest format returned here (using 'sha256=' without surrounding colons) is the intended format for draft signatures and remains consistent with how the rest of the system expects the digest to be formatted.
		return 'sha256=' . \base64_encode( \hash( 'sha256', $body, true ) );

obenland and others added 3 commits June 26, 2025 11:05
Co-authored-by: Matthias Pfefferle <[email protected]>
In sign_request, return immediately if 'key_id' or 'private_key' are not set in the arguments. This prevents potential errors when required signing information is absent.

Props @pfefferle.
@obenland obenland requested a review from pfefferle June 26, 2025 16:46
Copy link
Member

@pfefferle pfefferle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@obenland obenland merged commit 22332e7 into trunk Jun 26, 2025
11 checks passed
@obenland obenland deleted the add/rfc-9421-signature-creation branch June 26, 2025 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants