Update HttpSignatures, auto generate instance actor if missing

pull/5992/head
Daniel Supernault 6 months ago
parent b303f90978
commit bb16c95b1f
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1

@ -4,6 +4,7 @@ namespace App\Util\ActivityPub;
use App\Models\InstanceActor; use App\Models\InstanceActor;
use App\Profile; use App\Profile;
use Artisan;
use Cache; use Cache;
use DateTime; use DateTime;
@ -71,14 +72,15 @@ class HttpSignature
public static function instanceActorSign($url, $body = false, $addlHeaders = [], $method = 'post') public static function instanceActorSign($url, $body = false, $addlHeaders = [], $method = 'post')
{ {
$keyId = config('app.url').'/i/actor#main-key'; $keyId = config('app.url').'/i/actor#main-key';
if(config_cache('database.default') === 'mysql') { $privateKey = Cache::rememberForever(InstanceActor::PKI_PRIVATE, function () {
$privateKey = Cache::rememberForever(InstanceActor::PKI_PRIVATE, function () { $instance = InstanceActor::first() ?: tap(Artisan::call('instance:actor'), fn () => sleep(10)) && InstanceActor::first();
return InstanceActor::first()->private_key; if (! $instance) {
}); throw new \Exception('Failed to generate or retrieve InstanceActor.');
} else { }
$privateKey = InstanceActor::first()?->private_key;
} return $instance->private_key;
abort_if(!$privateKey || empty($privateKey), 400, 'Missing instance actor key, please run php artisan instance:actor'); });
abort_if(! $privateKey || empty($privateKey), 400, 'Missing instance actor key, please run php artisan instance:actor');
if ($body) { if ($body) {
$digest = self::_digest($body); $digest = self::_digest($body);
} }

Loading…
Cancel
Save