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

Closed
netkas wants to merge 421 commits from master into dev
Showing only changes of commit 413d04a02d - Show all commits

View file

@ -3,7 +3,9 @@
namespace Socialbox; namespace Socialbox;
use Exception; use Exception;
use LogLib\Log;
use Socialbox\Classes\Configuration; use Socialbox\Classes\Configuration;
use Socialbox\Classes\Logger;
use Socialbox\Classes\RpcHandler; use Socialbox\Classes\RpcHandler;
use Socialbox\Classes\Utilities; use Socialbox\Classes\Utilities;
use Socialbox\Enums\StandardError; use Socialbox\Enums\StandardError;
@ -21,11 +23,14 @@
} }
catch(RpcException $e) catch(RpcException $e)
{ {
Logger::getLogger()->error('Failed to parse the client request', $e);
http_response_code($e->getCode()); http_response_code($e->getCode());
print($e->getMessage()); print($e->getMessage());
return; return;
} }
Logger::getLogger()->verbose(sprintf('Received %d RPC request(s) from %s', count($clientRequest->getRequests()), $_SERVER['REMOTE_ADDR']));
$results = []; $results = [];
foreach($clientRequest->getRequests() as $rpcRequest) foreach($clientRequest->getRequests() as $rpcRequest)
{ {
@ -33,20 +38,24 @@
if($method === false) if($method === false)
{ {
Logger::getLogger()->warning('The requested method does not exist');
$response = $rpcRequest->produceError(StandardError::RPC_METHOD_NOT_FOUND, 'The requested method does not exist'); $response = $rpcRequest->produceError(StandardError::RPC_METHOD_NOT_FOUND, 'The requested method does not exist');
} }
else else
{ {
try try
{ {
Logger::getLogger()->debug(sprintf('Processing RPC request for method %s', $rpcRequest->getMethod()));
$response = $method->execute($clientRequest, $rpcRequest); $response = $method->execute($clientRequest, $rpcRequest);
} }
catch(StandardException $e) catch(StandardException $e)
{ {
Logger::getLogger()->error('An error occurred while processing the RPC request', $e);
$response = $e->produceError($rpcRequest); $response = $e->produceError($rpcRequest);
} }
catch(Exception $e) catch(Exception $e)
{ {
Logger::getLogger()->error('An internal error occurred while processing the RPC request', $e);
if(Configuration::getConfiguration()['security']['display_internal_exceptions']) if(Configuration::getConfiguration()['security']['display_internal_exceptions'])
{ {
$response = $rpcRequest->produceError(StandardError::INTERNAL_SERVER_ERROR, Utilities::throwableToString($e)); $response = $rpcRequest->produceError(StandardError::INTERNAL_SERVER_ERROR, Utilities::throwableToString($e));
@ -60,22 +69,26 @@
if($response !== null) if($response !== null)
{ {
Logger::getLogger()->debug(sprintf('Producing response for method %s', $rpcRequest->getMethod()));
$results[] = $response->toArray(); $results[] = $response->toArray();
} }
} }
if(count($results) == 0) if(count($results) == 0)
{ {
Logger::getLogger()->verbose('No results to return');
http_response_code(204); http_response_code(204);
return; return;
} }
if(count($results) == 1) if(count($results) == 1)
{ {
Logger::getLogger()->verbose('Returning single result');
print(json_encode($results[0])); print(json_encode($results[0]));
return; return;
} }
Logger::getLogger()->verbose('Returning multiple results');
print(json_encode($results)); print(json_encode($results));
} }
} }