Skip to content

Commit 8078512

Browse files
committed
small improvements
1 parent d781011 commit 8078512

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

includes/class-signature.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use WP_Error;
55
use DateTime;
66
use DateTimeZone;
7+
use WP_REST_Request;
78
use Activitypub\Collection\Users;
89

910
/**
@@ -226,7 +227,7 @@ public static function generate_signature( $user_id, $http_method, $url, $date,
226227
/**
227228
* Verifies the http signatures
228229
*
229-
* @param WP_REQUEST|array $request The request object or $_SERVER array.
230+
* @param WP_REST_Request|array $request The request object or $_SERVER array.
230231
*
231232
* @return mixed A boolean or WP_Error.
232233
*/
@@ -323,17 +324,25 @@ public static function verify_http_signature( $request ) {
323324
*
324325
* @param string $key_id The URL to the public key.
325326
*
326-
* @return WP_Error|string The public key.
327+
* @return WP_Error|string The public key or WP_Error.
327328
*/
328329
public static function get_remote_key( $key_id ) { // phpcs:ignore
329330
$actor = get_remote_metadata_by_actor( strip_fragment_from_url( $key_id ) ); // phpcs:ignore
330331
if ( \is_wp_error( $actor ) ) {
331-
return new WP_Error( 'activitypub_no_remote_profile_found', __( 'No Profile found or Profile not accessible', 'activitypub' ), array( 'status' => 401 ) );
332+
return new WP_Error(
333+
'activitypub_no_remote_profile_found',
334+
__( 'No Profile found or Profile not accessible', 'activitypub' ),
335+
array( 'status' => 401 )
336+
);
332337
}
333338
if ( isset( $actor['publicKey']['publicKeyPem'] ) ) {
334339
return \rtrim( $actor['publicKey']['publicKeyPem'] ); // phpcs:ignore
335340
}
336-
return new WP_Error( 'activitypub_no_remote_key_found', __( 'No Public-Key found', 'activitypub' ), array( 'status' => 401 ) );
341+
return new WP_Error(
342+
'activitypub_no_remote_key_found',
343+
__( 'No Public-Key found', 'activitypub' ),
344+
array( 'status' => 401 )
345+
);
337346
}
338347

339348
/**

includes/functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function get_webfinger_resource( $user_id ) {
4242
* @param string $actor The Actor URL.
4343
* @param bool $cached If the result should be cached.
4444
*
45-
* @return array The Actor profile as array
45+
* @return array|WP_Error The Actor profile as array or WP_Error on failure.
4646
*/
4747
function get_remote_metadata_by_actor( $actor, $cached = true ) {
4848
$pre = apply_filters( 'pre_get_remote_metadata_by_actor', false, $actor );

includes/rest/class-inbox.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public static function shared_inbox_post( $request ) {
160160
'rest_invalid_param',
161161
\__( 'No recipients found', 'activitypub' ),
162162
array(
163-
'status' => 404,
163+
'status' => 400,
164164
'params' => array(
165165
'to' => \__( 'Please check/validate "to" field', 'activitypub' ),
166166
'bto' => \__( 'Please check/validate "bto" field', 'activitypub' ),

includes/rest/class-server.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Activitypub\Rest;
33

44
use stdClass;
5+
use WP_Error;
56
use WP_REST_Response;
67
use Activitypub\Signature;
78
use Activitypub\Model\Application_User;
@@ -92,13 +93,13 @@ public static function authorize_activitypub_requests( $response, $handler, $req
9293
if ( 'GET' !== $request->get_method() ) {
9394
$verified_request = Signature::verify_http_signature( $request );
9495
if ( \is_wp_error( $verified_request ) ) {
95-
return $verified_request;
96+
return new WP_Error( 'activitypub_signature_verification', $verified_request->get_error_message(), array( 'status' => 401 ) );
9697
}
9798
} elseif ( 'GET' === $request->get_method() ) { // GET-Requests are only signed in secure mode
9899
if ( ACTIVITYPUB_AUTHORIZED_FETCH ) {
99100
$verified_request = Signature::verify_http_signature( $request );
100101
if ( \is_wp_error( $verified_request ) ) {
101-
return $verified_request;
102+
return new WP_Error( 'activitypub_signature_verification', $verified_request->get_error_message(), array( 'status' => 401 ) );
102103
}
103104
}
104105
}

0 commit comments

Comments
 (0)