Made message signing in Cryptography use SHA512 as the message content for... #1

Closed
netkas wants to merge 421 commits from master into dev
11 changed files with 43 additions and 25 deletions
Showing only changes of commit 0ed6a36d50 - Show all commits

View file

@ -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

View file

@ -35,7 +35,7 @@
}
catch(InvalidArgumentException $e)
{
throw new InvalidRpcArgumentException('peer', $e->getMessage());
throw new InvalidRpcArgumentException('peer', $e);
}
try

View file

@ -36,7 +36,7 @@
}
catch(InvalidArgumentException $e)
{
throw new InvalidRpcArgumentException('peer', $e->getMessage());
throw new InvalidRpcArgumentException('peer', $e);
}
try

View file

@ -35,7 +35,7 @@
}
catch(InvalidArgumentException $e)
{
throw new InvalidRpcArgumentException('peer', $e->getMessage());
throw new InvalidRpcArgumentException('peer', $e);
}
try

View file

@ -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

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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');

View file

@ -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

View file

@ -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);
}
}