Pārlūkot izejas kodu

Update FederationController, add inbox logic

Daniel Supernault 6 gadi atpakaļ
vecāks
revīzija
0144a5fdf6
1 mainītis faili ar 23 papildinājumiem un 0 dzēšanām
  1. 23 0
      app/Http/Controllers/FederationController.php

+ 23 - 0
app/Http/Controllers/FederationController.php

@@ -170,6 +170,29 @@ XML;
 
 
     public function userInbox(Request $request, $username)
     public function userInbox(Request $request, $username)
     {
     {
+        if (config('pixelfed.activitypub_enabled') == false) {
+            abort(403);
+        }
+
+        $profile = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
+        $body = $request->getContent();
+        $bodyDecoded = json_decode($body, true);
+        $signature = $request->header('signature');
+        if(!$signature) {
+            abort(400, 'Missing signature header');
+        }
+        $signatureData = HttpSignature::parseSignatureHeader($signature);
+        $actor = Profile::whereKeyId($signatureData['keyId'])->first();
+        if(!$actor) {
+            $actor = Helpers::profileFirstOrNew($bodyDecoded['actor']);
+        }
+        $pkey = openssl_pkey_get_public($actor->public_key);
+        $inboxPath = "/users/{$profile->username}/inbox";
+        list($verified, $headers) = HTTPSignature::verify($pkey, $signatureData, $request->headers->all(), $inboxPath, $body);
+        if($verified !== 1) { 
+            abort(400, 'Invalid signature.');
+        }
+        InboxWorker::dispatch($request->headers->all(), $profile, $bodyDecoded);
         return;
         return;
     }
     }