Made message signing in Cryptography use SHA512 as the message content for... #1
15 changed files with 98 additions and 16 deletions
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
namespace Socialbox\Classes;
|
namespace Socialbox\Classes;
|
||||||
|
|
||||||
use mysqli;
|
|
||||||
use mysqli_sql_exception;
|
|
||||||
use PDO;
|
use PDO;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Socialbox\Classes;
|
namespace Socialbox\Classes;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use Socialbox\Enums\DatabaseObjects;
|
use Socialbox\Enums\DatabaseObjects;
|
||||||
|
|
||||||
class Resources
|
class Resources
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
use Socialbox\Classes\Resources;
|
use Socialbox\Classes\Resources;
|
||||||
use Socialbox\Enums\StandardError;
|
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
use Socialbox\Objects\ClientRequest;
|
use Socialbox\Objects\ClientRequest;
|
||||||
use Socialbox\Objects\RpcRequest;
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
use Socialbox\Classes\Resources;
|
use Socialbox\Classes\Resources;
|
||||||
use Socialbox\Enums\StandardError;
|
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
use Socialbox\Objects\ClientRequest;
|
use Socialbox\Objects\ClientRequest;
|
||||||
use Socialbox\Objects\RpcRequest;
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
use Socialbox\Abstracts\Method;
|
use Socialbox\Abstracts\Method;
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
use Socialbox\Classes\Resources;
|
use Socialbox\Classes\Resources;
|
||||||
use Socialbox\Enums\StandardError;
|
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
use Socialbox\Objects\ClientRequest;
|
use Socialbox\Objects\ClientRequest;
|
||||||
use Socialbox\Objects\RpcRequest;
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Socialbox\Classes\StandardMethods;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Socialbox\Abstracts\Method;
|
||||||
|
use Socialbox\Enums\Flags\SessionFlags;
|
||||||
|
use Socialbox\Enums\StandardError;
|
||||||
|
use Socialbox\Exceptions\StandardException;
|
||||||
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
use Socialbox\Managers\RegisteredPeerManager;
|
||||||
|
use Socialbox\Managers\SessionManager;
|
||||||
|
use Socialbox\Objects\ClientRequest;
|
||||||
|
use Socialbox\Objects\RpcRequest;
|
||||||
|
|
||||||
|
class SettingsSetDisplayName extends Method
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
||||||
|
{
|
||||||
|
if(!$rpcRequest->containsParameter('name'))
|
||||||
|
{
|
||||||
|
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'name' parameter");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Set the password
|
||||||
|
RegisteredPeerManager::updateDisplayName($request->getPeer(), $rpcRequest->getParameter('name'));
|
||||||
|
|
||||||
|
// Remove the SET_PASSWORD flag
|
||||||
|
SessionManager::removeFlags($request->getSessionUuid(), [SessionFlags::SET_DISPLAY_NAME]);
|
||||||
|
|
||||||
|
// Check & update the session flow
|
||||||
|
SessionManager::updateFlow($request->getSession());
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
throw new StandardException('Failed to set password due to an internal exception', StandardError::INTERNAL_SERVER_ERROR, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rpcRequest->produceResponse(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,12 +2,10 @@
|
||||||
|
|
||||||
namespace Socialbox\Classes;
|
namespace Socialbox\Classes;
|
||||||
|
|
||||||
use DateTime;
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use JsonException;
|
use JsonException;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Socialbox\Enums\StandardHeaders;
|
use Socialbox\Enums\StandardHeaders;
|
||||||
use Socialbox\Objects\PeerAddress;
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class Utilities
|
class Utilities
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
namespace Socialbox\Enums\Flags;
|
namespace Socialbox\Enums\Flags;
|
||||||
|
|
||||||
use Socialbox\Classes\Logger;
|
|
||||||
|
|
||||||
enum PeerFlags : string
|
enum PeerFlags : string
|
||||||
{
|
{
|
||||||
// Administrative Flags
|
// Administrative Flags
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Socialbox\Managers;
|
namespace Socialbox\Managers;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
use PDO;
|
use PDO;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
|
@ -317,6 +318,50 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the display name of a registered peer based on the given unique identifier or RegisteredPeerRecord object.
|
||||||
|
*
|
||||||
|
* @param string|RegisteredPeerRecord $peer The unique identifier of the registered peer, or an instance of RegisteredPeerRecord.
|
||||||
|
* @param string $name The new
|
||||||
|
*/
|
||||||
|
public static function updateDisplayName(string|RegisteredPeerRecord $peer, string $name): void
|
||||||
|
{
|
||||||
|
if(empty($name))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The display name cannot be empty');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strlen($name) > 256)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('The display name cannot exceed 256 characters');
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_string($peer))
|
||||||
|
{
|
||||||
|
$peer = self::getPeer($peer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($peer->isExternal())
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException('Cannot update the display name of an external peer');
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::getLogger()->verbose(sprintf("Updating display name of peer %s to %s", $peer->getUuid(), $name));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$statement = Database::getConnection()->prepare('UPDATE `registered_peers` SET display_name=? WHERE uuid=?');
|
||||||
|
$statement->bindParam(1, $name);
|
||||||
|
$uuid = $peer->getUuid();
|
||||||
|
$statement->bindParam(2, $uuid);
|
||||||
|
$statement->execute();
|
||||||
|
}
|
||||||
|
catch(PDOException $e)
|
||||||
|
{
|
||||||
|
throw new DatabaseOperationException('Failed to update the display name of the peer in the database', $e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the password authentication record associated with the given unique peer identifier or a RegisteredPeerRecord object.
|
* Retrieves the password authentication record associated with the given unique peer identifier or a RegisteredPeerRecord object.
|
||||||
*
|
*
|
||||||
|
|
|
@ -460,6 +460,13 @@
|
||||||
*/
|
*/
|
||||||
public static function updateFlow(SessionRecord $session): void
|
public static function updateFlow(SessionRecord $session): void
|
||||||
{
|
{
|
||||||
|
// Don't do anything if the session is already authenticated
|
||||||
|
if(!in_array(SessionFlags::REGISTRATION_REQUIRED, $session->getFlags()) || !in_array(SessionFlags::AUTHENTICATION_REQUIRED, $session->getFlags()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if all registration/authentication requirements are met
|
||||||
if(SessionFlags::isComplete($session->getFlags()))
|
if(SessionFlags::isComplete($session->getFlags()))
|
||||||
{
|
{
|
||||||
SessionManager::setAuthenticated($session->getUuid(), true);
|
SessionManager::setAuthenticated($session->getUuid(), true);
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Socialbox\Classes\Cryptography;
|
use Socialbox\Classes\Cryptography;
|
||||||
use Socialbox\Classes\Logger;
|
|
||||||
use Socialbox\Classes\Utilities;
|
use Socialbox\Classes\Utilities;
|
||||||
use Socialbox\Enums\SessionState;
|
use Socialbox\Enums\SessionState;
|
||||||
use Socialbox\Enums\StandardHeaders;
|
use Socialbox\Enums\StandardHeaders;
|
||||||
|
|
|
@ -4,7 +4,6 @@ namespace Socialbox\Objects\Database;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
use Socialbox\Classes\Logger;
|
|
||||||
use Socialbox\Enums\Status\CaptchaStatus;
|
use Socialbox\Enums\Status\CaptchaStatus;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
use Socialbox\Classes\SecuredPassword;
|
use Socialbox\Classes\SecuredPassword;
|
||||||
use Socialbox\Exceptions\CryptographyException;
|
use Socialbox\Exceptions\CryptographyException;
|
||||||
use Socialbox\Managers\EncryptionRecordsManager;
|
|
||||||
|
|
||||||
class EncryptionRecord
|
class EncryptionRecord
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
namespace Socialbox\Objects;
|
namespace Socialbox\Objects;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Expr\BinaryOp\BooleanOr;
|
|
||||||
use Socialbox\Classes\Logger;
|
use Socialbox\Classes\Logger;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\RpcException;
|
|
||||||
use Socialbox\Exceptions\StandardException;
|
use Socialbox\Exceptions\StandardException;
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
namespace Socialbox\Objects\Standard;
|
namespace Socialbox\Objects\Standard;
|
||||||
|
|
||||||
use Socialbox\Interfaces\SerializableInterface;
|
use Socialbox\Interfaces\SerializableInterface;
|
||||||
use Socialbox\Objects\Database\CaptchaRecord;
|
|
||||||
|
|
||||||
class ImageCaptcha implements SerializableInterface
|
class ImageCaptcha implements SerializableInterface
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue