Update FederationController, add inbox logic

This commit is contained in:
Daniel Supernault 2018-12-17 23:27:07 -07:00
parent 75c7fcd182
commit 0144a5fdf6
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -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;
} }