Skip to content

Signature: Make key management Actor-specific #1832

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 11 commits into
base: trunk
Choose a base branch
from

Conversation

obenland
Copy link
Member

Minor house keeping item in preparation for #1808, separating the key management bits out from the signature functionality itself. I'm hoping it'll make it easier to update the Signature class in the future.

Proposed changes:

  • Moves key management functions to Actors class.
  • Updates all references to those functions.
  • Deprecates public functions in Signature class.
  • Moves unit tests.

Other information:

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

Testing instructions:

  • Subscribe to your test site from the Fediverse.
  • Publish a new post.
  • Make sure it still gets delivered to your subscriber and signature management still works.

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

Management of public/private keys for Actors now lives in the Actors collection, in preparation for Signature improvements down the line.

@obenland obenland requested a review from pfefferle June 18, 2025 16:58
@obenland obenland self-assigned this Jun 18, 2025
@Copilot Copilot AI review requested due to automatic review settings June 18, 2025 16:58
@obenland
Copy link
Member Author

@pfefferle Is Actors the best place for this?

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 pull request refactors key management functions by moving them from the Signature class into the Actors collection, deprecating the older public methods in Signature. Key changes include:

  • Updating references from Signature to Actors across tests and core model files.
  • Adding new key generation and retrieval methods in the Actors class.
  • Removing deprecated key management functionality from the Signature class.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/includes/rest/class-test-signature-verification.php Updated key lookups from Signature to Actors to use the new API.
tests/includes/collection/class-test-actors.php Added tear_down method and extended test coverage for key generation and legacy handling.
tests/includes/class-test-signature.php Removed tests for deprecated key management functions.
includes/model/class-user.php, class-blog.php, class-application.php Replaced references to Signature-based key fetching with Actors-based calls.
includes/collection/class-actors.php Introduced new methods for retrieving public/private keys as well as key pair generation.
includes/class-signature.php Deprecated key management functions now proxy to Actors with deprecation warnings.

@pfefferle
Copy link
Member

Is Actors the best place for this?

I would think so!

Maybe we can unify the get_public_key functions a bit to allow a similar functionality for remote users?

Either in the same function:

  • if $id is an URI, check for the public key in the ap_actor post_content
  • if it is an ID, use the current function

Or a dedicated get_remote_public_key!?

@@ -194,7 +81,7 @@ protected static function check_legacy_key_pair_for( $user_id ) {
*/
public static function generate_signature( $user_id, $http_method, $url, $date, $digest = null ) {
Copy link
Member

@pfefferle pfefferle Jun 19, 2025

Choose a reason for hiding this comment

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

it would be awesome to pass the private key as a param instead of the $user_id, to be completely user agnostic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed!

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 2a0373c. This turned out to be a bit more invasive than I hoped, since there are two data points dependent on the user.

Long term, I wonder if we should move Signature from being static to being an object that we'd instantiate with the user stuff and then call generate_signature() with just the request information

@obenland
Copy link
Member Author

Maybe we can unify the get_public_key functions a bit to allow a similar functionality for remote users?

I was wondering about that, too, but couldn't think of a use case. To verify signatures on incoming requests I think we should always make remote requests to the keyId provided in the signature itself, even if it's from an actor in the db. I wouldn't want to rely on a cached version.

@obenland obenland requested a review from pfefferle June 19, 2025 13:39
@obenland obenland changed the title Signature: Make key management Actor specific Signature: Make key management Actor-specific Jun 19, 2025
$user = Actors::get_by_id( $user_id );
$key = self::get_private_key_for( $user->get__id() );

public static function generate_signature( $key_id, $private_key, $http_method, $url, $date, $digest = null ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Heads up that replacing $user_id with the required values changes the function signature.

Appends '#main-key' to actor_id when generating signatures in HTTP requests and tests.

Props @pfefferle.
@obenland obenland requested a review from pfefferle June 25, 2025 12:42
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