From 37dd4f763ecdf7cea43587e79ef32242e987d4f3 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 12 Jun 2019 16:34:56 -0100 Subject: more loggin Signed-off-by: Maxence Lange --- lib/Controller/ActivityPubController.php | 2 +- lib/Model/ActivityPub/ACore.php | 12 +++++++----- lib/Service/CacheActorService.php | 8 +++++--- lib/Service/CurlService.php | 4 +++- lib/Service/SignatureService.php | 10 ++++++++-- lib/Service/StreamQueueService.php | 5 ++++- 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/Controller/ActivityPubController.php b/lib/Controller/ActivityPubController.php index a1d50d22..c752fb85 100644 --- a/lib/Controller/ActivityPubController.php +++ b/lib/Controller/ActivityPubController.php @@ -36,8 +36,8 @@ use daita\MySmallPhpTools\Traits\TStringTools; use Exception; use OC\AppFramework\Http; use OCA\Social\AppInfo\Application; -use OCA\Social\Exceptions\SignatureIsGoneException; use OCA\Social\Exceptions\ItemUnknownException; +use OCA\Social\Exceptions\SignatureIsGoneException; use OCA\Social\Exceptions\UrlCloudException; use OCA\Social\Service\CacheActorService; use OCA\Social\Service\FediverseService; diff --git a/lib/Model/ActivityPub/ACore.php b/lib/Model/ActivityPub/ACore.php index 14d55973..89515e11 100644 --- a/lib/Model/ActivityPub/ACore.php +++ b/lib/Model/ActivityPub/ACore.php @@ -279,21 +279,23 @@ class ACore extends Item implements JsonSerializable { */ public function checkOrigin($id) { $host = parse_url($id, PHP_URL_HOST); - if ($this->getRoot() - ->getOrigin() === $host) { + $origin = $this->getRoot() + ->getOrigin(); + + if ($origin === $host) { return; } - throw new InvalidOriginException(); + throw new InvalidOriginException('ACore::checkOrigin - id: ' . $id . ' - origin: ' . $origin); } /** - * @deprecated - * * @param string $url * * @throws ActivityCantBeVerifiedException + * @deprecated + * */ public function verify(string $url) { // TODO - Compare this with checkOrigin() - and delete this method. diff --git a/lib/Service/CacheActorService.php b/lib/Service/CacheActorService.php index d900741c..2aed18e6 100644 --- a/lib/Service/CacheActorService.php +++ b/lib/Service/CacheActorService.php @@ -144,7 +144,9 @@ class CacheActorService { } if ($id !== $actor->getId()) { - throw new InvalidOriginException(); + throw new InvalidOriginException( + 'CacheActorService::getFromId - id: ' . $id . ' - actorId: ' . $actor->getId() + ); } $actor->setAccount($actor->getPreferredUsername() . '@' . $this->get('_host', $object)); @@ -227,8 +229,8 @@ class CacheActorService { /** - * @throws Exception * @return int + * @throws Exception */ public function missingCacheRemoteActors(): int { // TODO - looking for missing cache remote actors... @@ -246,8 +248,8 @@ class CacheActorService { /** - * @throws Exception * @return int + * @throws Exception */ public function manageCacheRemoteActors(): int { $update = $this->cacheActorsRequest->getRemoteActorsToUpdate(); diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php index 01eabb30..ef12a93e 100644 --- a/lib/Service/CurlService.php +++ b/lib/Service/CurlService.php @@ -175,7 +175,9 @@ class CurlService { } if (strtolower($actor->getId()) !== strtolower($id)) { - throw new InvalidOriginException(); + throw new InvalidOriginException( + 'CurlService::retrieveAccount - id: ' . $id . ' - actorId: ' . $actor->getId() + ); } return $actor; diff --git a/lib/Service/SignatureService.php b/lib/Service/SignatureService.php index d7e2e0d8..ac0cdc1e 100644 --- a/lib/Service/SignatureService.php +++ b/lib/Service/SignatureService.php @@ -126,7 +126,7 @@ class SignatureService { public function generateKeys(Person &$actor) { $res = openssl_pkey_new( [ - "digest_alg" => "rsa", + "digest_alg" => "rsa", "private_key_bits" => 2048, "private_key_type" => OPENSSL_KEYTYPE_RSA, ] @@ -374,6 +374,10 @@ class SignatureService { $entries = explode(',', $signatureHeader); foreach ($entries as $entry) { + if ($entry === '' || !strpos($entry, '=')) { + continue; + } + list($k, $v) = explode('=', $entry, 2); preg_match('/"([^"]+)"/', $v, $varr); $v = trim($varr[0], '"'); @@ -422,7 +426,9 @@ class SignatureService { return $host; } - throw new InvalidOriginException(); + throw new InvalidOriginException( + 'SignatureService::getKeyOrigin - host: ' . $host . ' - id: ' . $id + ); } diff --git a/lib/Service/StreamQueueService.php b/lib/Service/StreamQueueService.php index 63a59beb..de4edb61 100644 --- a/lib/Service/StreamQueueService.php +++ b/lib/Service/StreamQueueService.php @@ -320,7 +320,10 @@ class StreamQueueService { $object->setOrigin($origin, SignatureService::ORIGIN_REQUEST, time()); if ($object->getId() !== $item->getUrl()) { - throw new InvalidOriginException(); + throw new InvalidOriginException( + 'StreamQueueService::cacheItem - objectId: ' . $object->getId() . ' - itemUrl: ' + . $item->getUrl() + ); } if ($object->getType() !== Note::TYPE) { -- cgit v1.2.3