From f5d2d95e76a8e685f35b5148803bdb96a7e09a7f Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 28 Mar 2026 05:21:42 -0600 Subject: [PATCH] Lint --- app/Console/Commands/UserAccountDelete.php | 10 +++- app/Util/ActivityPub/HttpSignature.php | 70 +++++++++++----------- 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/app/Console/Commands/UserAccountDelete.php b/app/Console/Commands/UserAccountDelete.php index 57b899452..f3ee11a71 100644 --- a/app/Console/Commands/UserAccountDelete.php +++ b/app/Console/Commands/UserAccountDelete.php @@ -287,12 +287,18 @@ class UserAccountDelete extends Command $httpFailed = []; $retryable = collect(); - $requests = function () use ($client, $urls, $digest, $payload) { + $version = config('pixelfed.version'); + $appUrl = config('app.url'); + $userAgent = "(Pixelfed/{$version}; +{$appUrl})"; + + $requests = function () use ($client, $urls, $digest, $payload, $userAgent) { foreach ($urls as $url) { $headers = HttpSignature::instanceActorSignWithDigest($url, $digest, [ 'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', ]); + $headers['User-Agent'] = $userAgent; + yield function () use ($client, $url, $headers, $payload) { return $client->postAsync($url, [ 'curl' => [ @@ -355,6 +361,8 @@ class UserAccountDelete extends Command 'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', ]); + $headers['User-Agent'] = $userAgent; + $this->info('Target: '.$url); $this->newLine(); diff --git a/app/Util/ActivityPub/HttpSignature.php b/app/Util/ActivityPub/HttpSignature.php index adb6dbd01..3a3650d44 100644 --- a/app/Util/ActivityPub/HttpSignature.php +++ b/app/Util/ActivityPub/HttpSignature.php @@ -98,41 +98,6 @@ class HttpSignature return $headers; } - public static function instanceActorSignWithDigest( - string $url, - string $digest, - array $addlHeaders = [], - string $method = 'post' - ): array { - $keyId = config('app.url').'/i/actor#main-key'; - $privateKey = Cache::rememberForever(InstanceActor::PKI_PRIVATE, function () { - $instance = InstanceActor::first() - ?: tap(Artisan::call('instance:actor'), fn () => sleep(10)) && InstanceActor::first(); - if (! $instance) { - throw new \Exception('Failed to generate or retrieve InstanceActor.'); - } - - return $instance->private_key; - }); - - abort_if(! $privateKey, 400, 'Missing instance actor key, please run php artisan instance:actor'); - - $headers = self::_headersToSign($url, $digest, $method); - $headers = array_merge($headers, $addlHeaders); - $stringToSign = self::_headersToSigningString($headers); - $signedHeaders = implode(' ', array_map('strtolower', array_keys($headers))); - - $key = openssl_pkey_get_private($privateKey); - openssl_sign($stringToSign, $signature, $key, OPENSSL_ALGO_SHA256); - $signature = base64_encode($signature); - - $signatureHeader = 'keyId="'.$keyId.'",headers="'.$signedHeaders.'",algorithm="rsa-sha256",signature="'.$signature.'"'; - unset($headers['(request-target)']); - $headers['Signature'] = $signatureHeader; - - return self::_headersToCurlArray($headers); - } - public static function parseSignatureHeader($signature) { $parts = explode(',', $signature); @@ -191,6 +156,41 @@ class HttpSignature return [$verified, $signingString]; } + public static function instanceActorSignWithDigest( + string $url, + string $digest, + array $addlHeaders = [], + string $method = 'post' + ): array { + $keyId = config('app.url').'/i/actor#main-key'; + $privateKey = Cache::rememberForever(InstanceActor::PKI_PRIVATE, function () { + $instance = InstanceActor::first() + ?: tap(Artisan::call('instance:actor'), fn () => sleep(10)) && InstanceActor::first(); + if (! $instance) { + throw new \Exception('Failed to generate or retrieve InstanceActor.'); + } + + return $instance->private_key; + }); + + abort_if(! $privateKey, 400, 'Missing instance actor key, please run php artisan instance:actor'); + + $headers = self::_headersToSign($url, $digest, $method); + $headers = array_merge($headers, $addlHeaders); + $stringToSign = self::_headersToSigningString($headers); + $signedHeaders = implode(' ', array_map('strtolower', array_keys($headers))); + + $key = openssl_pkey_get_private($privateKey); + openssl_sign($stringToSign, $signature, $key, OPENSSL_ALGO_SHA256); + $signature = base64_encode($signature); + + $signatureHeader = 'keyId="'.$keyId.'",headers="'.$signedHeaders.'",algorithm="rsa-sha256",signature="'.$signature.'"'; + unset($headers['(request-target)']); + $headers['Signature'] = $signatureHeader; + + return $headers; + } + private static function _headersToSigningString($headers) { return implode("\n", array_map(function ($k, $v) {