Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/42/head
Maxence Lange 2018-11-20 21:38:55 -01:00
rodzic a05dfc5879
commit be907600c7
4 zmienionych plików z 27 dodań i 10 usunięć

Wyświetl plik

@ -115,7 +115,7 @@ class AccountController extends Controller {
return $this->success([]); return $this->success([]);
} catch (Exception $e) { } catch (Exception $e) {
return $this->fail($e->getMessage()); return $this->fail($e);
} }
} }

Wyświetl plik

@ -34,6 +34,7 @@ use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use Exception; use Exception;
use OCA\Social\AppInfo\Application; use OCA\Social\AppInfo\Application;
use OCA\Social\Db\NotesRequest; use OCA\Social\Db\NotesRequest;
use OCA\Social\Exceptions\SignatureException;
use OCA\Social\Exceptions\UnknownItemException; use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Service\ActivityPub\FollowService; use OCA\Social\Service\ActivityPub\FollowService;
use OCA\Social\Service\ActivityService; use OCA\Social\Service\ActivityService;
@ -131,7 +132,7 @@ class ActivityPubController extends Controller {
return $this->directSuccess($actor); return $this->directSuccess($actor);
} catch (Exception $e) { } catch (Exception $e) {
return $this->fail($e->getMessage()); return $this->fail($e);
} }
} }
@ -178,7 +179,7 @@ class ActivityPubController extends Controller {
return $this->success([]); return $this->success([]);
} catch (Exception $e) { } catch (Exception $e) {
return $this->fail($e->getMessage()); return $this->fail($e);
} }
} }
@ -214,7 +215,7 @@ class ActivityPubController extends Controller {
return $this->success([]); return $this->success([]);
} catch (Exception $e) { } catch (Exception $e) {
return $this->fail($e->getMessage()); return $this->fail($e);
} }
} }
@ -271,7 +272,7 @@ class ActivityPubController extends Controller {
return $this->directSuccess($followers); return $this->directSuccess($followers);
} catch (Exception $e) { } catch (Exception $e) {
return $this->fail($e->getMessage()); return $this->fail($e);
} }
} }

Wyświetl plik

@ -0,0 +1,8 @@
<?php
namespace OCA\Social\Exceptions;
class SignatureException extends \Exception {
}

Wyświetl plik

@ -30,6 +30,7 @@ declare(strict_types=1);
namespace OCA\Social\Service; namespace OCA\Social\Service;
use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
use daita\MySmallPhpTools\Model\Request; use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\TArrayTools; use daita\MySmallPhpTools\Traits\TArrayTools;
use DateTime; use DateTime;
@ -39,6 +40,7 @@ use OCA\Social\Db\NotesRequest;
use OCA\Social\Exceptions\ActorDoesNotExistException; use OCA\Social\Exceptions\ActorDoesNotExistException;
use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\RequestException; use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\SignatureException;
use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Activity\Create; use OCA\Social\Model\ActivityPub\Activity\Create;
@ -273,14 +275,17 @@ class ActivityService {
/** /**
* @param IRequest $request * @param IRequest $request
* *
* @throws Exception * @throws InvalidResourceException
* @throws MalformedArrayException
* @throws RequestException
* @throws SignatureException
*/ */
public function checkRequest(IRequest $request) { public function checkRequest(IRequest $request) {
$dTime = new DateTime($request->getHeader('date')); $dTime = new DateTime($request->getHeader('date'));
$dTime->format(self::DATE_FORMAT); $dTime->format(self::DATE_FORMAT);
if ($dTime->getTimestamp() < (time() - self::DATE_DELAY)) { if ($dTime->getTimestamp() < (time() - self::DATE_DELAY)) {
throw new Exception('object is too old'); throw new SignatureException('object is too old');
} }
$this->checkSignature($request); $this->checkSignature($request);
@ -308,7 +313,10 @@ class ActivityService {
/** /**
* @param IRequest $request * @param IRequest $request
* *
* @throws Exception * @throws InvalidResourceException
* @throws RequestException
* @throws SignatureException
* @throws MalformedArrayException
*/ */
private function checkSignature(IRequest $request) { private function checkSignature(IRequest $request) {
$signatureHeader = $request->getHeader('Signature'); $signatureHeader = $request->getHeader('Signature');
@ -323,8 +331,8 @@ class ActivityService {
$publicKey = $this->retrieveKey($keyId); $publicKey = $this->retrieveKey($keyId);
if (openssl_verify($estimated, $signed, $publicKey, 'sha256') !== 1) { if ($publicKey === '' || openssl_verify($estimated, $signed, $publicKey, 'sha256') !== 1) {
throw new Exception('signature cannot be checked'); throw new SignatureException('signature cannot be checked');
} }
} }