Skip to content
Closed
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
bcf29e1
Profiles: update followers when profile fields change
mattwiebe Oct 31, 2023
e3a78fb
use static
mattwiebe Oct 31, 2023
af3e61c
only try to merge mention inboxes when valid
mattwiebe Nov 1, 2023
3785cee
Add Server Class, known_inboxes method
mediaformat Nov 8, 2023
d64ed73
Add a server dispatch activity
mediaformat Nov 8, 2023
565a6ca
Add a delete wp user action
mediaformat Nov 8, 2023
9e8065a
lint:fix
mediaformat Nov 8, 2023
4d83e1a
Merge branch 'master' into add/ServerActivities
pfefferle Nov 10, 2023
7543884
Add blog user followers to known inboxes
mediaformat Nov 10, 2023
05b4ebf
public function
mediaformat Nov 11, 2023
2bfb930
update send_server_activity
mediaformat Nov 11, 2023
6c548bc
update delete schedulers
mediaformat Nov 11, 2023
41f05ef
get temporary key for deleted user
mediaformat Nov 11, 2023
f101daf
Merge branch 'master' into add/ServerActivities
mediaformat Nov 11, 2023
87d32cb
Merge branch 'master' into add/ServerActivities
mediaformat Nov 13, 2023
06a023e
Rename to Application class
mediaformat Nov 13, 2023
5090e84
Merge branch 'master' into add/ServerActivities
mediaformat Nov 27, 2023
8499aa4
Merge branch 'master' into add/ServerActivities
pfefferle Nov 30, 2023
96b29a3
Merge branch 'master' into add/ServerActivities
pfefferle Dec 18, 2023
76771aa
Merge branch 'master' into add/ServerActivities
pfefferle May 6, 2024
fcbfa74
Fix PHP errors and lint issues
mattwiebe May 7, 2024
ca3d1bc
Update includes/class-scheduler.php
mediaformat May 8, 2024
e894bc6
Rename action and function
mediaformat May 8, 2024
1aa30ed
Use get_all_followers for inboxes
mediaformat May 8, 2024
fb0f679
schedule_actor_delete
mediaformat May 8, 2024
61951f7
has_cap activitypub
mediaformat May 8, 2024
4cef50d
activitypub_send_actor_delete_activity
mediaformat May 8, 2024
6c1fa00
remove Application class
mediaformat May 8, 2024
01b4d09
private key already stored
mediaformat May 8, 2024
22a664e
clean up user, delete signature options key
mediaformat May 8, 2024
aa448d3
get signing keys from options for actor delete activity
mediaformat May 9, 2024
f9fee8c
Send Delete activity to shared_inboxes
mediaformat May 9, 2024
2df226e
set temp signature option
mediaformat May 9, 2024
d1e0074
cleanup
mediaformat May 9, 2024
bf50942
phpcs
mediaformat May 9, 2024
c781662
phpcbf
mediaformat May 9, 2024
39fffc7
Merge branch 'master' into add/ServerActivities
pfefferle May 16, 2024
7af4eb1
Merge branch 'master' into add/ServerActivities
pfefferle May 16, 2024
c9477d7
Merge branch 'master' into add/ServerActivities
pfefferle Jun 4, 2024
dc88d91
Merge branch 'master' into add/ServerActivities
pfefferle Jun 25, 2024
b84286e
init cli
pfefferle Jun 25, 2024
0de423a
add http gone class
pfefferle Jun 26, 2024
2f33377
add http gone
pfefferle Jun 26, 2024
39e6e71
rewrite dispatcher a bit
pfefferle Jun 26, 2024
520c3fb
mark as federated
pfefferle Jun 26, 2024
962e6dd
cleanups
pfefferle Jun 26, 2024
2730907
remove lagacy code
pfefferle Jun 26, 2024
295d5bc
fix instance of check
pfefferle Jun 26, 2024
4fcf151
better $user handling
pfefferle Jun 27, 2024
f319cac
better support of system users
pfefferle Jun 27, 2024
62714a5
better description
pfefferle Jul 9, 2024
84dbdc4
Merge branch 'master' into add/ServerActivities
pfefferle Jul 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions includes/class-activity-dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Activitypub\Collection\Users;
use Activitypub\Collection\Followers;
use Activitypub\Transformer\Factory;
use Activitypub\Transformer\Post;
use Activitypub\Transformer\Comment;

use function Activitypub\is_single_user;
Expand All @@ -33,6 +32,7 @@ public static function init() {
\add_action( 'activitypub_send_activity', array( self::class, 'send_activity' ), 10, 2 );
\add_action( 'activitypub_send_activity', array( self::class, 'send_activity_or_announce' ), 10, 2 );
\add_action( 'activitypub_send_update_profile_activity', array( self::class, 'send_profile_update' ), 10, 1 );
\add_action( 'activitypub_send_actor_delete_activity', array( self::class, 'send_actor_delete_activity' ), 10, 2 );
}

/**
Expand Down Expand Up @@ -174,8 +174,26 @@ private static function send_activity_to_followers( $activity, $user_id, $wp_obj
foreach ( $inboxes as $inbox ) {
safe_remote_post( $inbox, $json, $user_id );
}
}

set_wp_object_state( $wp_object, 'federated' );
/**
* Send an Activity to all known (shared_)inboxes.
*
* @param Activity $activity The ActivityPub Activity.
*
* @return void
*/
public static function send_actor_delete_activity( $activity, $user_id = Users::APPLICATION_USER_ID ) {
$json = $activity->to_json();
$followers = Followers::get_all_followers();
$known_inboxes = [];
foreach ( $followers as $follower ) {
$known_inboxes[] = $follower->get_shared_inbox();
}
$inboxes = array_unique( $known_inboxes );
foreach ( $inboxes as $inbox ) {
safe_remote_post( $inbox, $json, $user_id );
}
}

/**
Expand Down
32 changes: 31 additions & 1 deletion includes/class-scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
use Activitypub\Transformer\Post;
use Activitypub\Collection\Users;
use Activitypub\Collection\Followers;
use Activitypub\Activity\Activity;

use function Activitypub\was_comment_sent;
use function Activitypub\get_private_key_for;
use function Activitypub\is_user_type_disabled;
use function Activitypub\was_comment_sent;
use function Activitypub\should_comment_be_federated;
use function Activitypub\get_remote_metadata_by_actor;

Expand Down Expand Up @@ -75,6 +77,7 @@ function ( $comment_id ) {

// profile updates for user options
if ( ! is_user_type_disabled( 'user' ) ) {
\add_action( 'delete_user', array( self::class, 'schedule_actor_delete' ), 10, 3 );
\add_action( 'wp_update_user', array( self::class, 'user_update' ) );
\add_action( 'updated_user_meta', array( self::class, 'user_meta_update' ), 10, 3 );
// @todo figure out a feasible way of updating the header image since it's not unique to any user.
Expand Down Expand Up @@ -330,4 +333,31 @@ public static function schedule_profile_update( $user_id ) {
array( $user_id )
);
}

/**
* Send an Actor Delete activity.
* @param int $user_id The user ID to Delete.
*/
public static function schedule_actor_delete( $user_id ) {
$user = get_userdata( $user_id );
if ( $user->has_cap( 'activitypub' ) ) {
$author_url = \get_author_posts_url( $user->ID );
add_option(
'activitypub_temp_sig_' . $user_id,
array(
'key_id' => $author_url . '#main-key',
'private_key' => Signature::get_private_key_for( $user_id ),
)
);

$activity = new Activity();
$activity->set_id( $author_url . '#delete' );
$activity->set_type( 'Delete' );
$activity->set_actor( $author_url );
$activity->set_object( $author_url );
$activity->set_to( [ 'https://www.w3.org/ns/activitystreams#Public' ] );

\wp_schedule_single_event( \time(), 'activitypub_send_actor_delete_activity', array( $activity, $user_id ) );
}
}
}
11 changes: 8 additions & 3 deletions includes/class-signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,14 @@ protected static function check_legacy_key_pair_for( $user_id ) {
*/
public static function generate_signature( $user_id, $http_method, $url, $date, $digest = null ) {
$user = Users::get_by_id( $user_id );
$key = self::get_private_key_for( $user->get__id() );
if ( ! is_wp_error( $user ) ) {
$key = self::get_private_key_for( $user->get__id() );
$key_id = $user->get_url() . '#main-key';
} else {
$temp_sig_options = get_option( 'activitypub_temp_sig_' . $user_id );
Copy link
Member

Choose a reason for hiding this comment

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

this feels a bit hacky and might break things in the future, if we maybe introduce key rotation: https://swicg.github.io/activitypub-http-signature/#key-rotation

Copy link
Member

Choose a reason for hiding this comment

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

Do we need a sig for deletes at all? The remote server is not able to verify it anyways!?!

This is very confusing https://swicg.github.io/activitypub-http-signature/#handling-deletes-of-actors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed it is very hacky! In my previous tests Mastodon ignored actor deletes signed by the instance actor, but I will do some more tests and report back.

Copy link
Member

Choose a reason for hiding this comment

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

or maybe we do it as you mentioned it here: #552 (comment)

So a workaround would be to store key pair in an option during delete_user action and delete the option during deleted_user.

Copy link
Member

Choose a reason for hiding this comment

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

or we store the complete delete object in the schedule on the delete?!?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So a workaround would be to store key pair in an option during delete_user action and delete the option during deleted_user.

The first part is the hack I've implemented, the problem with the second part is that deleted_user will occur almost immediately, and the Delete activities will fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or we store the complete delete object in the schedule on the delete?!?

Hmm, the scheduler runs before signature generation.

$key = $temp_sig_options['private_key'];
$key_id = $temp_sig_options['key_id'];
}

$url_parts = \wp_parse_url( $url );

Expand Down Expand Up @@ -215,8 +222,6 @@ public static function generate_signature( $user_id, $http_method, $url, $date,
\openssl_sign( $signed_string, $signature, $key, \OPENSSL_ALGO_SHA256 );
$signature = \base64_encode( $signature ); // phpcs:ignore

$key_id = $user->get_url() . '#main-key';

if ( ! empty( $digest ) ) {
return \sprintf( 'keyId="%s",algorithm="rsa-sha256",headers="(request-target) host date digest",signature="%s"', $key_id, $signature );
} else {
Expand Down