Made message signing in Cryptography use SHA512 as the message content for... #1
3 changed files with 103 additions and 4 deletions
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Classes\StandardMethods;
|
||||
|
||||
use Socialbox\Abstracts\Method;
|
||||
use Socialbox\Enums\Flags\PeerFlags;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Exceptions\DatabaseOperationException;
|
||||
use Socialbox\Exceptions\StandardException;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Managers\CaptchaManager;
|
||||
use Socialbox\Managers\RegisteredPeerManager;
|
||||
use Socialbox\Managers\SessionManager;
|
||||
use Socialbox\Objects\ClientRequest;
|
||||
use Socialbox\Objects\RpcRequest;
|
||||
|
||||
class VerificationAnswerImageCaptcha extends Method
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
// Check if the request has a Session UUID
|
||||
if($request->getSessionUuid() === null)
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::SESSION_REQUIRED);
|
||||
}
|
||||
|
||||
// Get the session and check if it's already authenticated
|
||||
try
|
||||
{
|
||||
$session = SessionManager::getSession($request->getSessionUuid());
|
||||
}
|
||||
catch(DatabaseOperationException $e)
|
||||
{
|
||||
throw new StandardException("There was an unexpected error while trying to get the session", StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
// Check for session conditions
|
||||
if($session->getPeerUuid() === null)
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::AUTHENTICATION_REQUIRED);
|
||||
}
|
||||
|
||||
// Get the peer
|
||||
try
|
||||
{
|
||||
$peer = RegisteredPeerManager::getPeer($session->getPeerUuid());
|
||||
}
|
||||
catch(DatabaseOperationException $e)
|
||||
{
|
||||
throw new StandardException("There was unexpected error while trying to get the peer", StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
// Check if the VER_SOLVE_IMAGE_CAPTCHA flag exists.
|
||||
if(!$peer->flagExists(PeerFlags::VER_SOLVE_IMAGE_CAPTCHA))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::CAPTCHA_NOT_AVAILABLE, 'You are not required to complete a captcha at this time');
|
||||
}
|
||||
|
||||
if(!$rpcRequest->containsParameter('answer'))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'The answer parameter is required');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if(CaptchaManager::getCaptcha($session->getPeerUuid())->isExpired())
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::CAPTCHA_EXPIRED, 'The captcha has expired');
|
||||
}
|
||||
}
|
||||
catch(DatabaseOperationException $e)
|
||||
{
|
||||
throw new StandardException("There was an unexpected error while trying to get the captcha", StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$result = CaptchaManager::answerCaptcha($session->getPeerUuid(), $rpcRequest->getParameter('answer'));
|
||||
|
||||
if($result)
|
||||
{
|
||||
RegisteredPeerManager::removeFlag($session->getPeerUuid(), PeerFlags::VER_SOLVE_IMAGE_CAPTCHA);
|
||||
}
|
||||
|
||||
return $rpcRequest->produceResponse($result);
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
throw new StandardException("There was an unexpected error while trying to answer the captcha", StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ use Socialbox\Objects\ClientRequest;
|
|||
use Socialbox\Objects\RpcRequest;
|
||||
use Socialbox\Objects\Standard\ImageCaptcha;
|
||||
|
||||
class VerificationGetCaptcha extends Method
|
||||
class VerificationGetImageCaptcha extends Method
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
|
@ -3,7 +3,8 @@
|
|||
namespace Socialbox\Enums;
|
||||
|
||||
use Socialbox\Classes\StandardMethods\CreateSession;
|
||||
use Socialbox\Classes\StandardMethods\VerificationGetCaptcha;
|
||||
use Socialbox\Classes\StandardMethods\VerificationAnswerImageCaptcha;
|
||||
use Socialbox\Classes\StandardMethods\VerificationGetImageCaptcha;
|
||||
use Socialbox\Classes\StandardMethods\GetMe;
|
||||
use Socialbox\Classes\StandardMethods\Ping;
|
||||
use Socialbox\Classes\StandardMethods\Register;
|
||||
|
@ -18,7 +19,8 @@ enum StandardMethods : string
|
|||
case CREATE_SESSION = 'createSession';
|
||||
case REGISTER = 'register';
|
||||
case GET_ME = 'getMe';
|
||||
case VERIFICATION_GET_CAPTCHA = 'verificationGetCaptcha';
|
||||
case VERIFICATION_GET_IMAGE_CAPTCHA = 'verificationGetImageCaptcha';
|
||||
case VERIFICATION_ANSWER_IMAGE_CAPTCHA = 'verificationAnswerImageCaptcha';
|
||||
|
||||
/**
|
||||
* @param ClientRequest $request
|
||||
|
@ -34,7 +36,8 @@ enum StandardMethods : string
|
|||
self::CREATE_SESSION => CreateSession::execute($request, $rpcRequest),
|
||||
self::REGISTER => Register::execute($request, $rpcRequest),
|
||||
self::GET_ME => GetMe::execute($request, $rpcRequest),
|
||||
self::VERIFICATION_GET_CAPTCHA => VerificationGetCaptcha::execute($request, $rpcRequest),
|
||||
self::VERIFICATION_GET_IMAGE_CAPTCHA => VerificationGetImageCaptcha::execute($request, $rpcRequest),
|
||||
self::VERIFICATION_ANSWER_IMAGE_CAPTCHA => VerificationAnswerImageCaptcha::execute($request, $rpcRequest),
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue