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

Closed
netkas wants to merge 421 commits from master into dev
2 changed files with 37 additions and 4 deletions
Showing only changes of commit 508d4565d9 - Show all commits

View file

@ -7,6 +7,9 @@
use ncc\ThirdParty\Symfony\Uid\Uuid;
use Socialbox\Abstracts\Method;
use Socialbox\Enums\StandardError;
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\SigningKeysManager;
@ -22,23 +25,28 @@
{
if(!$rpcRequest->containsParameter('uuid'))
{
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'uuid' parameter");
throw new MissingRpcArgumentException('uuid');
}
try
{
$uuid = Uuid::fromString($rpcRequest->getParameter('uuid'));
}
catch(InvalidArgumentException $e)
catch(InvalidArgumentException)
{
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'Invalid UUID', $e);
throw new InvalidRpcArgumentException('uuid');
}
try
{
if(!SigningKeysManager::signingKeyExists($request->getPeer()->getUuid(), $uuid))
{
return $rpcRequest->produceResponse(false);
}
SigningKeysManager::deleteSigningKey($request->getPeer()->getUuid(), $uuid);
}
catch(Exception $e)
catch(DatabaseOperationException $e)
{
throw new StandardRpcException('Failed to delete the signing key', StandardError::INTERNAL_SERVER_ERROR, $e);
}

View file

@ -195,6 +195,31 @@
}
}
/**
* Checks if a signing key exists in the database using the provided UUID.
*
* @param string $peerUuid The UUID of the peer associated with the signing key.
* @param string $uuid The UUID of the signing key to check.
* @return bool True if the signing key exists, false otherwise.
* @throws DatabaseOperationException If a database error occurs during the operation.
*/
public static function signingKeyExists(string $peerUuid, string $uuid): bool
{
try
{
$statement = Database::getConnection()->prepare("SELECT COUNT(*) FROM signing_keys WHERE uuid=:uuid AND peer_uuid=:peer_uuid");
$statement->bindParam(':uuid', $uuid);
$statement->bindParam(':peer_uuid', $peerUuid);
$statement->execute();
return $statement->fetchColumn() > 0;
}
catch (PDOException $e)
{
throw new DatabaseOperationException('Failed to check if the signing key exists in the database', $e);
}
}
/**
* Deletes a signing key from the database using the provided UUID.
*