Made message signing in Cryptography use SHA512 as the message content for... #1
3 changed files with 25 additions and 14 deletions
|
@ -21,17 +21,24 @@
|
|||
*/
|
||||
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||
{
|
||||
$session = $request->getSession();
|
||||
try
|
||||
{
|
||||
$session = $request->getSession();
|
||||
}
|
||||
catch (DatabaseOperationException $e)
|
||||
{
|
||||
throw new StandardRpcException('An error occurred while trying to get the session', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||
}
|
||||
|
||||
// Check for session conditions
|
||||
if(!$session->flagExists(SessionFlags::VER_IMAGE_CAPTCHA))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::METHOD_NOT_ALLOWED, 'Solving an image captcha is not required at this time');
|
||||
}
|
||||
|
||||
$peer = $request->getPeer();
|
||||
|
||||
try
|
||||
{
|
||||
$peer = $request->getPeer();
|
||||
if(CaptchaManager::captchaExists($peer))
|
||||
{
|
||||
$captchaRecord = CaptchaManager::getCaptcha($peer);
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
use Socialbox\Enums\Flags\SessionFlags;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Exceptions\CryptographyException;
|
||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Managers\OneTimePasswordManager;
|
||||
|
@ -25,18 +27,18 @@
|
|||
{
|
||||
if(!$rpcRequest->containsParameter('code'))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'code' parameter");
|
||||
throw new MissingRpcArgumentException('code');
|
||||
}
|
||||
|
||||
if(strlen($rpcRequest->getParameter('code')) !== Configuration::getSecurityConfiguration()->getOtpDigits())
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Invalid 'code' parameter length");
|
||||
throw new InvalidRpcArgumentException('code', 'Invalid OTP code length');
|
||||
}
|
||||
|
||||
$session = $request->getSession();
|
||||
if(!$session->flagExists(SessionFlags::VER_OTP))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'One Time Password verification is not required at this time');
|
||||
return $rpcRequest->produceError(StandardError::METHOD_NOT_ALLOWED, 'One Time Password verification is not required at this time');
|
||||
}
|
||||
|
||||
try
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
use Socialbox\Enums\Flags\SessionFlags;
|
||||
use Socialbox\Enums\StandardError;
|
||||
use Socialbox\Exceptions\CryptographyException;
|
||||
use Socialbox\Exceptions\Standard\InvalidRpcArgumentException;
|
||||
use Socialbox\Exceptions\Standard\MissingRpcArgumentException;
|
||||
use Socialbox\Exceptions\Standard\StandardRpcException;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Managers\PasswordManager;
|
||||
|
@ -25,22 +27,22 @@
|
|||
{
|
||||
if(!$rpcRequest->containsParameter('password'))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'password' parameter");
|
||||
throw new MissingRpcArgumentException('password');
|
||||
}
|
||||
|
||||
if(!Cryptography::validateSha512($rpcRequest->getParameter('password')))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Invalid 'password' parameter, must be a valid SHA-512 hash");
|
||||
}
|
||||
|
||||
$session = $request->getSession();
|
||||
if(!$session->flagExists(SessionFlags::VER_PASSWORD))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Password verification is not required at this time');
|
||||
throw new InvalidRpcArgumentException('password', 'Invalid SHA-512 hash');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$session = $request->getSession();
|
||||
if(!$session->flagExists(SessionFlags::VER_PASSWORD))
|
||||
{
|
||||
return $rpcRequest->produceError(StandardError::METHOD_NOT_ALLOWED, 'Password verification is not required at this time');
|
||||
}
|
||||
|
||||
$result = PasswordManager::verifyPassword($request->getPeer()->getUuid(), $rpcRequest->getParameter('password'));
|
||||
|
||||
if($result)
|
||||
|
|
Loading…
Add table
Reference in a new issue