Made message signing in Cryptography use SHA512 as the message content for... #1
11 changed files with 43 additions and 25 deletions
|
@ -38,7 +38,7 @@
|
|||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
throw new InvalidRpcArgumentException('peer', $e->getMessage());
|
||||
throw new InvalidRpcArgumentException('peer', $e);
|
||||
}
|
||||
|
||||
if($rpcRequest->containsParameter('relationship'))
|
||||
|
@ -46,7 +46,7 @@
|
|||
$relationship = ContactRelationshipType::tryFrom(strtoupper($rpcRequest->getParameter('relationship')));
|
||||
if($relationship === null)
|
||||
{
|
||||
throw new InvalidRpcArgumentException('peer', 'Invalid relationship type');
|
||||
throw new InvalidRpcArgumentException('relationship');
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
throw new InvalidRpcArgumentException('peer', $e->getMessage());
|
||||
throw new InvalidRpcArgumentException('peer', $e);
|
||||
}
|
||||
|
||||
try
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
throw new InvalidRpcArgumentException('peer', $e->getMessage());
|
||||
throw new InvalidRpcArgumentException('peer', $e);
|
||||
}
|
||||
|
||||
try
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
throw new InvalidRpcArgumentException('peer', $e->getMessage());
|
||||
throw new InvalidRpcArgumentException('peer', $e);
|
||||
}
|
||||
|
||||
try
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
throw new InvalidRpcArgumentException('peer', $e->getMessage());
|
||||
throw new InvalidRpcArgumentException('peer', $e);
|
||||
}
|
||||
|
||||
if(!$rpcRequest->containsParameter('uuid'))
|
||||
|
@ -48,7 +48,7 @@
|
|||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
throw new InvalidRpcArgumentException('uuid', $e->getMessage());
|
||||
throw new InvalidRpcArgumentException('uuid', $e);
|
||||
}
|
||||
|
||||
try
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
throw new InvalidRpcArgumentException('peer', $e->getMessage());
|
||||
throw new InvalidRpcArgumentException('peer', $e);
|
||||
}
|
||||
|
||||
if(!$rpcRequest->containsParameter('uuid'))
|
||||
|
@ -50,7 +50,7 @@
|
|||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
throw new InvalidRpcArgumentException('uuid', $e->getMessage());
|
||||
throw new InvalidRpcArgumentException('uuid', $e);
|
||||
}
|
||||
|
||||
$signingKey = Socialbox::resolvePeerSignature($address, $uuid);
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
}
|
||||
catch(InvalidArgumentException $e)
|
||||
{
|
||||
throw new InvalidRpcArgumentException('peer', 'Invalid peer address');
|
||||
throw new InvalidRpcArgumentException('peer');
|
||||
}
|
||||
|
||||
if(!$rpcRequest->containsParameter('relationship'))
|
||||
|
@ -44,7 +44,7 @@
|
|||
$relationship = ContactRelationshipType::tryFrom(strtoupper($rpcRequest->getParameter('relationship')));
|
||||
if($relationship === null)
|
||||
{
|
||||
throw new InvalidRpcArgumentException('relationship', 'Invalid relationship type');
|
||||
throw new InvalidRpcArgumentException('relationship');
|
||||
}
|
||||
|
||||
try
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Enums\Types\InformationFieldName;
|
||||
use Socialbox\Exceptions\DatabaseOperationException;
|
||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Managers\PeerInformationManager;
|
||||
|
@ -20,29 +22,30 @@
|
|||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @noinspection DuplicatedCode
|
||||
*/
|
||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
// Field parameter is required
|
||||
if(!$rpcRequest->containsParameter('field'))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'The required field parameter is missing');
|
||||
throw new MissingRpcArgumentException('field');
|
||||
}
|
||||
$fieldName = InformationFieldName::tryFrom(strtoupper($rpcRequest->getParameter('field')));
|
||||
if($fieldName === null)
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'The provided field parameter is invalid');
|
||||
throw new InvalidRpcArgumentException('field');
|
||||
}
|
||||
|
||||
// Value parameter is required
|
||||
if(!$rpcRequest->containsParameter('value'))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'The required value parameter is missing');
|
||||
throw new MissingRpcArgumentException('value');
|
||||
}
|
||||
$value = $rpcRequest->getParameter('value');
|
||||
if(!$fieldName->validate($value))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'The provided value parameter is invalid');
|
||||
throw new InvalidRpcArgumentException('value');
|
||||
}
|
||||
|
||||
// Privacy parameter is optional
|
||||
|
@ -52,7 +55,7 @@
|
|||
$privacy = PrivacyState::tryFrom(strtoupper($rpcRequest->getParameter('privacy')));
|
||||
if($privacy === null)
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'The provided privacy parameter is invalid');
|
||||
throw new InvalidRpcArgumentException('privacy');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,14 +65,15 @@
|
|||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
throw new StandardRpcException('Failed to retrieve current peer information', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
throw new StandardRpcException('Failed to retrieve peer information', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (PeerInformationManager::fieldExists($peer, $fieldName))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'The provided field parameter is already registered, use settingsUpdateInformationField or settingsUpdateInformationPrivacy instead');
|
||||
// Return False, because the field already exists
|
||||
return $rpcRequest->produceResponse(false);
|
||||
}
|
||||
|
||||
PeerInformationManager::addField($peer, $fieldName, $value, $privacy);
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
{
|
||||
$expires = (int)$rpcRequest->getParameter('expires');
|
||||
}
|
||||
|
||||
if(!$rpcRequest->containsParameter('name'))
|
||||
{
|
||||
throw new MissingRpcArgumentException('name');
|
||||
|
@ -43,10 +42,9 @@
|
|||
$name = $rpcRequest->getParameter('name');
|
||||
}
|
||||
|
||||
$peerUuid = $request->getPeer()->getUuid();
|
||||
|
||||
try
|
||||
{
|
||||
$peerUuid = $request->getPeer()->getUuid();
|
||||
if(SigningKeysManager::getSigningKeyCount($peerUuid) >= Configuration::getPoliciesConfiguration()->getMaxSigningKeys())
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'The maximum number of signing keys has been reached');
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Enums\Types\InformationFieldName;
|
||||
use Socialbox\Exceptions\DatabaseOperationException;
|
||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Managers\PeerInformationManager;
|
||||
|
@ -23,12 +25,12 @@
|
|||
// Field parameter is required
|
||||
if(!$rpcRequest->containsParameter('field'))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'The required field parameter is missing');
|
||||
throw new MissingRpcArgumentException('field');
|
||||
}
|
||||
$fieldName = InformationFieldName::tryFrom(strtoupper($rpcRequest->getParameter('field')));
|
||||
if($fieldName === null)
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'The provided field parameter is invalid');
|
||||
throw new InvalidRpcArgumentException('field');
|
||||
}
|
||||
|
||||
try
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Socialbox\Exceptions\Standard;
|
||||
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use Socialbox\Enums\StandardError;
|
||||
|
||||
class InvalidRpcArgumentException extends StandardRpcException
|
||||
|
@ -10,10 +12,22 @@
|
|||
* Thrown when a required parameter is missing
|
||||
*
|
||||
* @param string $parameterName The name of the parameter that is missing
|
||||
* @param string $reason The reason why the parameter is invalid
|
||||
* @param string|Exception|null $reason The reason why the parameter is invalid can be a string or an exception or null
|
||||
*/
|
||||
public function __construct(string $parameterName, string $reason)
|
||||
public function __construct(string $parameterName, null|string|Exception $reason=null)
|
||||
{
|
||||
if(is_null($reason))
|
||||
{
|
||||
parent::__construct(sprintf('Invalid parameter %s', $parameterName), StandardError::RPC_INVALID_ARGUMENTS);
|
||||
return;
|
||||
}
|
||||
|
||||
if($reason instanceof InvalidArgumentException)
|
||||
{
|
||||
parent::__construct(sprintf('Invalid parameter %s: %s', $parameterName, $reason->getMessage()), StandardError::RPC_INVALID_ARGUMENTS, $reason);
|
||||
return;
|
||||
}
|
||||
|
||||
parent::__construct(sprintf('Invalid parameter %s: %s', $parameterName, $reason), StandardError::RPC_INVALID_ARGUMENTS);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue