|
|
@ -23,6 +23,9 @@ class InboxValidator implements ShouldQueue
|
|
|
|
protected $headers;
|
|
|
|
protected $headers;
|
|
|
|
protected $payload;
|
|
|
|
protected $payload;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public $timeout = 5;
|
|
|
|
|
|
|
|
public $tries = 1;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -48,18 +51,24 @@ class InboxValidator implements ShouldQueue
|
|
|
|
|
|
|
|
|
|
|
|
$profile = Profile::whereNull('domain')->whereUsername($username)->first();
|
|
|
|
$profile = Profile::whereNull('domain')->whereUsername($username)->first();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!isset($headers['signature']) || !isset($headers['date'])) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(empty($profile) || empty($headers) || empty($payload)) {
|
|
|
|
if(empty($profile) || empty($headers) || empty($payload)) {
|
|
|
|
return true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if($profile->status != null) {
|
|
|
|
if($profile->status != null) {
|
|
|
|
return true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if($this->verifySignature($headers, $profile, $payload) == true) {
|
|
|
|
if($this->verifySignature($headers, $profile, $payload) == true) {
|
|
|
|
InboxWorker::dispatchNow($headers, $profile, $payload)->onQueue('high');
|
|
|
|
(new Inbox($headers, $profile, $payload))->handle();
|
|
|
|
|
|
|
|
return;
|
|
|
|
} else if($this->blindKeyRotation($headers, $profile, $payload) == true) {
|
|
|
|
} else if($this->blindKeyRotation($headers, $profile, $payload) == true) {
|
|
|
|
InboxWorker::dispatchNow($headers, $profile, $payload)->onQueue('high');
|
|
|
|
(new Inbox($headers, $profile, $payload))->handle();
|
|
|
|
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -73,13 +82,15 @@ class InboxValidator implements ShouldQueue
|
|
|
|
$signature = is_array($headers['signature']) ? $headers['signature'][0] : $headers['signature'];
|
|
|
|
$signature = is_array($headers['signature']) ? $headers['signature'][0] : $headers['signature'];
|
|
|
|
$date = is_array($headers['date']) ? $headers['date'][0] : $headers['date'];
|
|
|
|
$date = is_array($headers['date']) ? $headers['date'][0] : $headers['date'];
|
|
|
|
if(!$signature) {
|
|
|
|
if(!$signature) {
|
|
|
|
abort(400, 'Missing signature header');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!$date) {
|
|
|
|
if(!$date) {
|
|
|
|
abort(400, 'Missing date header');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!now()->parse($date)->gt(now()->subDays(1)) || !now()->parse($date)->lt(now()->addDays(1))) {
|
|
|
|
if(!now()->parse($date)->gt(now()->subDays(1)) ||
|
|
|
|
abort(400, 'Invalid date');
|
|
|
|
!now()->parse($date)->lt(now()->addDays(1))
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$signatureData = HttpSignature::parseSignatureHeader($signature);
|
|
|
|
$signatureData = HttpSignature::parseSignatureHeader($signature);
|
|
|
|
$keyId = Helpers::validateUrl($signatureData['keyId']);
|
|
|
|
$keyId = Helpers::validateUrl($signatureData['keyId']);
|
|
|
@ -91,10 +102,12 @@ class InboxValidator implements ShouldQueue
|
|
|
|
&& isset($bodyDecoded['object']['attributedTo'])
|
|
|
|
&& isset($bodyDecoded['object']['attributedTo'])
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
if(parse_url($bodyDecoded['object']['attributedTo'], PHP_URL_HOST) !== $keyDomain) {
|
|
|
|
if(parse_url($bodyDecoded['object']['attributedTo'], PHP_URL_HOST) !== $keyDomain) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
abort(400, 'Invalid request');
|
|
|
|
abort(400, 'Invalid request');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!$keyDomain || !$idDomain || $keyDomain !== $idDomain) {
|
|
|
|
if(!$keyDomain || !$idDomain || $keyDomain !== $idDomain) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
abort(400, 'Invalid request');
|
|
|
|
abort(400, 'Invalid request');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$actor = Profile::whereKeyId($keyId)->first();
|
|
|
|
$actor = Profile::whereKeyId($keyId)->first();
|
|
|
@ -103,11 +116,11 @@ class InboxValidator implements ShouldQueue
|
|
|
|
$actor = Helpers::profileFirstOrNew($actorUrl);
|
|
|
|
$actor = Helpers::profileFirstOrNew($actorUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!$actor) {
|
|
|
|
if(!$actor) {
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$pkey = openssl_pkey_get_public($actor->public_key);
|
|
|
|
$pkey = openssl_pkey_get_public($actor->public_key);
|
|
|
|
$inboxPath = "/users/{$profile->username}/inbox";
|
|
|
|
$inboxPath = "/users/{$profile->username}/inbox";
|
|
|
|
list($verified, $headers) = HTTPSignature::verify($pkey, $signatureData, $headers, $inboxPath, $body);
|
|
|
|
list($verified, $headers) = HttpSignature::verify($pkey, $signatureData, $headers, $inboxPath, $body);
|
|
|
|
if($verified == 1) {
|
|
|
|
if($verified == 1) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -120,22 +133,24 @@ class InboxValidator implements ShouldQueue
|
|
|
|
$signature = is_array($headers['signature']) ? $headers['signature'][0] : $headers['signature'];
|
|
|
|
$signature = is_array($headers['signature']) ? $headers['signature'][0] : $headers['signature'];
|
|
|
|
$date = is_array($headers['date']) ? $headers['date'][0] : $headers['date'];
|
|
|
|
$date = is_array($headers['date']) ? $headers['date'][0] : $headers['date'];
|
|
|
|
if(!$signature) {
|
|
|
|
if(!$signature) {
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!$date) {
|
|
|
|
if(!$date) {
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!now()->parse($date)->gt(now()->subDays(1)) || !now()->parse($date)->lt(now()->addDays(1))) {
|
|
|
|
if(!now()->parse($date)->gt(now()->subDays(1)) ||
|
|
|
|
return false;
|
|
|
|
!now()->parse($date)->lt(now()->addDays(1))
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$signatureData = HttpSignature::parseSignatureHeader($signature);
|
|
|
|
$signatureData = HttpSignature::parseSignatureHeader($signature);
|
|
|
|
$keyId = Helpers::validateUrl($signatureData['keyId']);
|
|
|
|
$keyId = Helpers::validateUrl($signatureData['keyId']);
|
|
|
|
$actor = Profile::whereKeyId($keyId)->whereNotNull('remote_url')->first();
|
|
|
|
$actor = Profile::whereKeyId($keyId)->whereNotNull('remote_url')->first();
|
|
|
|
if(!$actor) {
|
|
|
|
if(!$actor) {
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(Helpers::validateUrl($actor->remote_url) == false) {
|
|
|
|
if(Helpers::validateUrl($actor->remote_url) == false) {
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$res = Zttp::timeout(5)->withHeaders([
|
|
|
|
$res = Zttp::timeout(5)->withHeaders([
|
|
|
|
'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
|
|
|
'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
|
|
@ -143,7 +158,7 @@ class InboxValidator implements ShouldQueue
|
|
|
|
])->get($actor->remote_url);
|
|
|
|
])->get($actor->remote_url);
|
|
|
|
$res = json_decode($res->body(), true, 8);
|
|
|
|
$res = json_decode($res->body(), true, 8);
|
|
|
|
if($res['publicKey']['id'] !== $actor->key_id) {
|
|
|
|
if($res['publicKey']['id'] !== $actor->key_id) {
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$actor->public_key = $res['publicKey']['publicKeyPem'];
|
|
|
|
$actor->public_key = $res['publicKey']['publicKeyPem'];
|
|
|
|
$actor->save();
|
|
|
|
$actor->save();
|
|
|
|