Skip to content

Signatures: Improve support for hs2019 algorithm #1848

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

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from

Conversation

obenland
Copy link
Member

@obenland obenland commented Jun 23, 2025

Improves handling of hs2019 signatures by deriving the signature algorithm from the actor's public key.

Proposed changes:

  • Moves public key retrieval to earlier in the function, so it can be passed to get_signature_algorithm() and inspected.
  • Extends get_signature_algorithm() to accept a public key and return a WP_Error.
  • Updates error return after get_signature_algorithm() to return the generated error rather than a generic one.
  • Updates hs2019 case to inspect the public key and derive the algorithm used.

Other information:

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

Testing instructions:

  • Beyond unit tests, it would be good to find a Fediverse instance that signs their outgoing requests with hs2019 to test against.

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

hs2019 signatures for incoming REST API requests now have their algorithm determined based on their public key.

obenland added 3 commits June 23, 2025 12:04
Prefixed is_wp_error with a backslash to ensure the global function is used. Added 'secp256r1' as an alias for 'prime256v1' in the curve name switch statement to improve compatibility.
Introduce a fixture with EC and RSA test keys and expand signature verification tests to cover multiple EC curves and RSA key sizes for the hs2019 algorithm. Add tests for valid and invalid signatures, unsupported curves, and update the signature algorithm provider to expect WP_Error for missing or empty algorithms. Refactor test setup to load keys from a JSON fixture for consistency and maintainability.
@obenland obenland requested a review from pfefferle June 23, 2025 19:20
@obenland obenland marked this pull request as ready for review June 23, 2025 19:20
@Copilot Copilot AI review requested due to automatic review settings June 23, 2025 19:20
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 enhances the handling of hs2019 signatures by deriving the signature algorithm from the actor’s public key and improving error reporting. Key changes include moving public key retrieval earlier in the signature verification flow, extending the get_signature_algorithm() method to accept a public key and return a WP_Error when appropriate, and adding comprehensive tests for various EC and RSA key scenarios.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/includes/class-test-signature.php Added test keys storage and expanded test cases for EC and RSA hs2019 signatures.
tests/fixtures/http-signature-keys.json Added fixture file with EC and RSA keys for testing signature verification.
includes/class-signature.php Updated signature verification flow and signature algorithm derivation logic.
Comments suppressed due to low confidence (2)

includes/class-signature.php:377

  • [nitpick] Consider removing or rephrasing the comment about nested switch statements to maintain a professional codebase and avoid potential confusion.
							// 3 levels switch statements are fine, right?

includes/class-signature.php:366

  • Ensure that KB_IN_BYTES is defined or consider using an explicit literal value to improve clarity and avoid potential undefined constant issues.
							if ( $bits >= 4 * KB_IN_BYTES ) {

}

return new \WP_Error( 'unsupported_key_type', 'Unsupported key type (only RSA and EC keys are supported).', array( 'status' => 401 ) );

Copy link
Member Author

Choose a reason for hiding this comment

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

@vpzomtrrfrt I'm curious if you'd have any advice on how this could be improved to switch algorithm="hs2019" support for wordpress-activitypub to "Yes"?

Choose a reason for hiding this comment

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

I haven't followed this space as closely lately, the last I heard was that there was no consensus on how keys should indicate their supported algorithms

@obenland
Copy link
Member Author

@mediaformat Curious if you had any thoughts on this change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants