use const instead of -1
This commit is contained in:
parent
7d5cfb3078
commit
7456d36834
5 changed files with 33 additions and 6 deletions
|
@ -41,6 +41,7 @@ function init() {
|
||||||
|
|
||||||
require_once \dirname( __FILE__ ) . '/includes/model/class-activity.php';
|
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-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/model/class-follower.php';
|
||||||
|
|
||||||
require_once \dirname( __FILE__ ) . '/includes/class-migration.php';
|
require_once \dirname( __FILE__ ) . '/includes/class-migration.php';
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
namespace Activitypub;
|
namespace Activitypub;
|
||||||
|
|
||||||
use WP_Error;
|
use WP_Error;
|
||||||
|
use Activitypub\Model\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub HTTP Class
|
* ActivityPub HTTP Class
|
||||||
|
@ -62,7 +63,7 @@ class Http {
|
||||||
*/
|
*/
|
||||||
public static function get( $url ) {
|
public static function get( $url ) {
|
||||||
$date = \gmdate( 'D, d M Y H:i:s T' );
|
$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' );
|
$wp_version = \get_bloginfo( 'version' );
|
||||||
$user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) );
|
$user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) );
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Activitypub;
|
||||||
use WP_Error;
|
use WP_Error;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
|
use Activitypub\Model\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Signature Class
|
* ActivityPub Signature Class
|
||||||
|
@ -26,7 +27,7 @@ class Signature {
|
||||||
self::generate_key_pair( $user_id );
|
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' );
|
$key = \get_option( 'activitypub_magic_sig_public_key' );
|
||||||
} else {
|
} else {
|
||||||
$key = \get_user_meta( $user_id, 'magic_sig_public_key', true );
|
$key = \get_user_meta( $user_id, 'magic_sig_public_key', true );
|
||||||
|
@ -52,7 +53,7 @@ class Signature {
|
||||||
self::generate_key_pair( $user_id );
|
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' );
|
$key = \get_option( 'activitypub_magic_sig_private_key' );
|
||||||
} else {
|
} else {
|
||||||
$key = \get_user_meta( $user_id, 'magic_sig_private_key', true );
|
$key = \get_user_meta( $user_id, 'magic_sig_private_key', true );
|
||||||
|
@ -85,7 +86,7 @@ class Signature {
|
||||||
\openssl_pkey_export( $key, $priv_key );
|
\openssl_pkey_export( $key, $priv_key );
|
||||||
$detail = \openssl_pkey_get_details( $key );
|
$detail = \openssl_pkey_get_details( $key );
|
||||||
|
|
||||||
if ( -1 === $user_id ) {
|
if ( User::APPLICATION_USER_ID === $user_id ) {
|
||||||
// private key
|
// private key
|
||||||
\update_option( 'activitypub_magic_sig_private_key', $priv_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 );
|
\openssl_sign( $signed_string, $signature, $key, \OPENSSL_ALGO_SHA256 );
|
||||||
$signature = \base64_encode( $signature ); // phpcs:ignore
|
$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' );
|
$key_id = \get_rest_url( null, 'activitypub/1.0/service#main-key' );
|
||||||
} else {
|
} else {
|
||||||
$key_id = \get_author_posts_url( $user_id ) . '#main-key';
|
$key_id = \get_author_posts_url( $user_id ) . '#main-key';
|
||||||
|
|
23
includes/model/class-user.php
Normal file
23
includes/model/class-user.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
namespace Activitypub\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ActivityPub User Class
|
||||||
|
*
|
||||||
|
* @author Matthias Pfefferle
|
||||||
|
*/
|
||||||
|
class User {
|
||||||
|
/**
|
||||||
|
* The ID of the Blog User
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
const BLOG_USER_ID = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ID of the Application User
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
const APPLICATION_USER_ID = -1;
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ namespace Activitypub\Rest;
|
||||||
|
|
||||||
use WP_REST_Response;
|
use WP_REST_Response;
|
||||||
use Activitypub\Signature;
|
use Activitypub\Signature;
|
||||||
|
use Activitypub\Model\User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Server REST-Class
|
* ActivityPub Server REST-Class
|
||||||
|
@ -57,7 +58,7 @@ class Server {
|
||||||
$json->publicKey = (object) array( // phpcs:ignore WordPress.NamingConventions
|
$json->publicKey = (object) array( // phpcs:ignore WordPress.NamingConventions
|
||||||
'id' => \get_rest_url( null, 'activitypub/1.0/application#main-key' ),
|
'id' => \get_rest_url( null, 'activitypub/1.0/application#main-key' ),
|
||||||
'owner' => \get_rest_url( null, 'activitypub/1.0/application' ),
|
'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 );
|
$response = new WP_REST_Response( $json, 200 );
|
||||||
|
|
Loading…
Reference in a new issue