diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-12-19 16:50:17 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2018-12-19 16:50:17 -0100 |
commit | a636ec03a3418a1c0ba22d11d68f7473727905fd (patch) | |
tree | e9d8b73a9029869f71795fafbeeaad4b01be4bd4 /lib | |
parent | 1dda85adaad533ffd2570a1cbd49323ee4fba04f (diff) |
set the source of the signature (header or ld-json signature)
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/ActivityPubController.php | 6 | ||||
-rw-r--r-- | lib/Model/ActivityPub/Item.php | 16 | ||||
-rw-r--r-- | lib/Service/SignatureService.php | 7 |
3 files changed, 23 insertions, 6 deletions
diff --git a/lib/Controller/ActivityPubController.php b/lib/Controller/ActivityPubController.php index 39862334..9e0a9a84 100644 --- a/lib/Controller/ActivityPubController.php +++ b/lib/Controller/ActivityPubController.php @@ -167,9 +167,9 @@ class ActivityPubController extends Controller { $activity = $this->importService->importFromJson($body); if (!$this->signatureService->checkObject($activity)) { - $activity->setOrigin($origin); + $activity->setOrigin($origin, SignatureService::ORIGIN_HEADER); } - + try { $this->importService->parseIncomingRequest($activity); } catch (UnknownItemException $e) { @@ -208,7 +208,7 @@ class ActivityPubController extends Controller { $activity = $this->importService->importFromJson($body); if (!$this->signatureService->checkObject($activity)) { - $activity->setOrigin($origin); + $activity->setOrigin($origin, SignatureService::ORIGIN_HEADER); } try { diff --git a/lib/Model/ActivityPub/Item.php b/lib/Model/ActivityPub/Item.php index 1b70038e..f2c0f89f 100644 --- a/lib/Model/ActivityPub/Item.php +++ b/lib/Model/ActivityPub/Item.php @@ -103,6 +103,9 @@ class Item { /** @var string */ private $origin = ''; + /** @var int */ + private $originSource = 0; + /** * @return string @@ -433,12 +436,22 @@ class Item { } /** + * @return int + */ + public function getOriginSource(): int { + return $this->originSource; + } + + /** * @param string $origin * + * @param int $source + * * @return Item */ - public function setOrigin(string $origin): Item { + public function setOrigin(string $origin, int $source): Item { $this->origin = $origin; + $this->originSource = $source; return $this; } @@ -512,7 +525,6 @@ class Item { } - /** * @return string */ diff --git a/lib/Service/SignatureService.php b/lib/Service/SignatureService.php index 1c8d2628..f9eb5c64 100644 --- a/lib/Service/SignatureService.php +++ b/lib/Service/SignatureService.php @@ -56,6 +56,10 @@ class SignatureService { use TArrayTools; + const ORIGIN_HEADER = 1; + const ORIGIN_SIGNATURE = 2; + + const DATE_FORMAT = 'D, d M Y H:i:s T'; const DATE_DELAY = 30; @@ -165,7 +169,7 @@ class SignatureService { $signature->import(json_decode($object->getSource(), true)); $signature->setPublicKey($this->retrieveKey($actorId)); if ($signature->verify()) { - $object->setOrigin($this->getKeyOrigin($actorId)); + $object->setOrigin($this->getKeyOrigin($actorId), SignatureService::ORIGIN_SIGNATURE); return true; } @@ -294,6 +298,7 @@ class SignatureService { * @throws SocialAppConfigException * @throws UnknownItemException * @throws RedundancyLimitException + * @throws InvalidOriginException */ private function retrieveKey($keyId): string { $actor = $this->cacheActorService->getFromId($keyId); |