diff --git a/activitypub.php b/activitypub.php index 049d7d7..4292684 100644 --- a/activitypub.php +++ b/activitypub.php @@ -41,6 +41,7 @@ function init() { require_once \dirname( __FILE__ ) . '/includes/model/class-activity.php'; require_once \dirname( __FILE__ ) . '/includes/model/class-post.php'; + require_once \dirname( __FILE__ ) . '/includes/model/class-user.php'; require_once \dirname( __FILE__ ) . '/includes/model/class-follower.php'; require_once \dirname( __FILE__ ) . '/includes/class-migration.php'; diff --git a/includes/class-http.php b/includes/class-http.php index 247d87e..58cace9 100644 --- a/includes/class-http.php +++ b/includes/class-http.php @@ -2,6 +2,7 @@ namespace Activitypub; use WP_Error; +use Activitypub\Model\User; /** * ActivityPub HTTP Class @@ -62,7 +63,7 @@ class Http { */ public static function get( $url ) { $date = \gmdate( 'D, d M Y H:i:s T' ); - $signature = Signature::generate_signature( -1, 'get', $url, $date ); + $signature = Signature::generate_signature( User::APPLICATION_USER_ID, 'get', $url, $date ); $wp_version = \get_bloginfo( 'version' ); $user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) ); diff --git a/includes/class-signature.php b/includes/class-signature.php index f82806a..9472128 100644 --- a/includes/class-signature.php +++ b/includes/class-signature.php @@ -4,6 +4,7 @@ namespace Activitypub; use WP_Error; use DateTime; use DateTimeZone; +use Activitypub\Model\User; /** * ActivityPub Signature Class @@ -26,7 +27,7 @@ class Signature { self::generate_key_pair( $user_id ); } - if ( -1 === $user_id ) { + if ( User::APPLICATION_USER_ID === $user_id ) { $key = \get_option( 'activitypub_magic_sig_public_key' ); } else { $key = \get_user_meta( $user_id, 'magic_sig_public_key', true ); @@ -52,7 +53,7 @@ class Signature { self::generate_key_pair( $user_id ); } - if ( -1 === $user_id ) { + if ( User::APPLICATION_USER_ID === $user_id ) { $key = \get_option( 'activitypub_magic_sig_private_key' ); } else { $key = \get_user_meta( $user_id, 'magic_sig_private_key', true ); @@ -85,7 +86,7 @@ class Signature { \openssl_pkey_export( $key, $priv_key ); $detail = \openssl_pkey_get_details( $key ); - if ( -1 === $user_id ) { + if ( User::APPLICATION_USER_ID === $user_id ) { // private key \update_option( 'activitypub_magic_sig_private_key', $priv_key ); @@ -140,7 +141,7 @@ class Signature { \openssl_sign( $signed_string, $signature, $key, \OPENSSL_ALGO_SHA256 ); $signature = \base64_encode( $signature ); // phpcs:ignore - if ( -1 === $user_id ) { + if ( User::APPLICATION_USER_ID === $user_id ) { $key_id = \get_rest_url( null, 'activitypub/1.0/service#main-key' ); } else { $key_id = \get_author_posts_url( $user_id ) . '#main-key'; diff --git a/includes/model/class-user.php b/includes/model/class-user.php new file mode 100644 index 0000000..5c62473 --- /dev/null +++ b/includes/model/class-user.php @@ -0,0 +1,23 @@ +publicKey = (object) array( // phpcs:ignore WordPress.NamingConventions 'id' => \get_rest_url( null, 'activitypub/1.0/application#main-key' ), 'owner' => \get_rest_url( null, 'activitypub/1.0/application' ), - 'publicKeyPem' => Signature::get_public_key( -1 ), // phpcs:ignore WordPress.NamingConventions + 'publicKeyPem' => Signature::get_public_key( User::APPLICATION_USER_ID ), // phpcs:ignore WordPress.NamingConventions ); $response = new WP_REST_Response( $json, 200 );