From afafdf1543f451a28b7ecc993bcc978edb199a89 Mon Sep 17 00:00:00 2001 From: Django Doucet Date: Fri, 5 May 2023 23:54:29 -0600 Subject: [PATCH] Add get_remote_key method --- includes/class-signature.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/includes/class-signature.php b/includes/class-signature.php index 2a4ea53..05d2165 100644 --- a/includes/class-signature.php +++ b/includes/class-signature.php @@ -187,7 +187,7 @@ class Signature { } } - $public_key = \Activitypub\get_remote_metadata_by_actor( strtok( strip_fragment_from_url( $signature_block['keyId'] ), '?' ) ); // phpcs:ignore + $public_key = self::get_remote_key( $signature_block['keyId'] ); if ( \is_wp_error( $public_key ) ) { return $public_key; } else { @@ -200,6 +200,24 @@ class Signature { return $verified; } + /** + * Get public key from key_id + * + * @param string $key_id + * @return string $publicKeyPem + * @author Django Doucet + */ + public static function get_remote_key( $key_id ) { // phpcs:ignore + $actor = \Activitypub\get_remote_metadata_by_actor( strtok( strip_fragment_from_url( $key_id ), '?' ) ); // phpcs:ignore + if ( \is_wp_error( $actor ) ) { + return $actor; + } + if ( isset( $actor['publicKey']['publicKeyPem'] ) ) { + return \rtrim( $actor['publicKey']['publicKeyPem'] ); // phpcs:ignore + } + return null; + } + /** * Gets the signature algorithm from the signature header *