410 and gone signature/account

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/69/head
Maxence Lange 2018-11-28 14:26:28 -01:00
rodzic e8b80e8502
commit 005a8c57d0
6 zmienionych plików z 43 dodań i 5 usunięć

Wyświetl plik

@ -32,9 +32,10 @@ namespace OCA\Social\Controller;
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use Exception;
use OC\AppFramework\Http;
use OCA\Social\AppInfo\Application;
use OCA\Social\Db\NotesRequest;
use OCA\Social\Exceptions\SignatureException;
use OCA\Social\Exceptions\SignatureIsGoneException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Service\ActivityPub\FollowService;
use OCA\Social\Service\ActivityService;
@ -184,6 +185,8 @@ class ActivityPubController extends Controller {
}
return $this->success([]);
} catch (SignatureIsGoneException $e) {
return $this->fail($e, [], Http::STATUS_GONE);
} catch (Exception $e) {
return $this->fail($e);
}
@ -220,6 +223,8 @@ class ActivityPubController extends Controller {
}
return $this->success([]);
} catch (SignatureIsGoneException $e) {
return $this->fail($e, [], Http::STATUS_GONE);
} catch (Exception $e) {
return $this->fail($e);
}

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

@ -38,6 +38,7 @@ use OCA\Social\Db\CacheDocumentsRequest;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Exceptions\CacheDocumentDoesNotExistException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\Request410Exception;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UrlCloudException;
@ -124,6 +125,7 @@ class PersonService implements ICoreService {
* @throws RequestException
* @throws SocialAppConfigException
* @throws UrlCloudException
* @throws Request410Exception
*/
public function getFromId(string $id, bool $refresh = false): Person {

Wyświetl plik

@ -43,8 +43,10 @@ use OCA\Social\Exceptions\EmptyQueueException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\NoHighPriorityRequestException;
use OCA\Social\Exceptions\QueueStatusException;
use OCA\Social\Exceptions\Request410Exception;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Exceptions\SignatureException;
use OCA\Social\Exceptions\SignatureIsGoneException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Model\ActivityPub\ACore;
@ -385,6 +387,9 @@ class ActivityService {
* @throws MalformedArrayException
* @throws RequestException
* @throws SignatureException
* @throws SocialAppConfigException
* @throws UrlCloudException
* @throws SignatureIsGoneException
*/
public function checkRequest(IRequest $request) {
$dTime = new DateTime($request->getHeader('date'));
@ -394,7 +399,12 @@ class ActivityService {
throw new SignatureException('object is too old');
}
$this->checkSignature($request);
try {
$this->checkSignature($request);
} catch (Request410Exception $e) {
throw new SignatureIsGoneException();
}
}
@ -429,9 +439,12 @@ class ActivityService {
* @param IRequest $request
*
* @throws InvalidResourceException
* @throws MalformedArrayException
* @throws Request410Exception
* @throws RequestException
* @throws SignatureException
* @throws MalformedArrayException
* @throws SocialAppConfigException
* @throws UrlCloudException
* @throws Exception
*/
private function checkSignature(IRequest $request) {
@ -508,6 +521,7 @@ class ActivityService {
* @throws RequestException
* @throws SocialAppConfigException
* @throws UrlCloudException
* @throws Request410Exception
*/
private function retrieveKey($keyId): string {
$actor = $this->personService->getFromId($keyId);

Wyświetl plik

@ -35,6 +35,7 @@ use daita\MySmallPhpTools\Model\Request;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TPathTools;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\Request410Exception;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\Instance;
@ -83,8 +84,7 @@ class InstanceService {
public function retrieveAccount(string $account) {
$account = $this->withoutBeginAt($account);
if (strstr(substr($account, 0, -3), '@') === false)
{
if (strstr(substr($account, 0, -3), '@') === false) {
throw new InvalidResourceException();
}
list($username, $host) = explode('@', $account);
@ -113,6 +113,7 @@ class InstanceService {
*
* @return mixed
* @throws RequestException
* @throws Request410Exception
*/
public function retrieveObject($id) {
$url = parse_url($id);