Add get_remote_key method

This commit is contained in:
Django Doucet 2023-05-05 23:54:29 -06:00
parent dc8e1e0f3e
commit afafdf1543

View file

@ -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 ) ) { if ( \is_wp_error( $public_key ) ) {
return $public_key; return $public_key;
} else { } else {
@ -200,6 +200,24 @@ class Signature {
return $verified; return $verified;
} }
/**
* Get public key from key_id
*
* @param string $key_id
* @return string $publicKeyPem
* @author Django Doucet <django.doucet@webdevstudios.com>
*/
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 * Gets the signature algorithm from the signature header
* *