Made message signing in Cryptography use SHA512 as the message content for... #1
1 changed files with 28 additions and 3 deletions
|
@ -5,15 +5,18 @@
|
||||||
use DateMalformedStringException;
|
use DateMalformedStringException;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
use LogLib\Log;
|
||||||
use PDO;
|
use PDO;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use Socialbox\Classes\Configuration;
|
use Socialbox\Classes\Configuration;
|
||||||
use Socialbox\Classes\Cryptography;
|
use Socialbox\Classes\Cryptography;
|
||||||
use Socialbox\Classes\Database;
|
use Socialbox\Classes\Database;
|
||||||
|
use Socialbox\Classes\Logger;
|
||||||
use Socialbox\Enums\SessionState;
|
use Socialbox\Enums\SessionState;
|
||||||
use Socialbox\Enums\StandardError;
|
use Socialbox\Enums\StandardError;
|
||||||
use Socialbox\Exceptions\DatabaseOperationException;
|
use Socialbox\Exceptions\DatabaseOperationException;
|
||||||
use Socialbox\Exceptions\StandardException;
|
use Socialbox\Exceptions\StandardException;
|
||||||
|
use Socialbox\Objects\Database\RegisteredPeerRecord;
|
||||||
use Socialbox\Objects\Database\SessionRecord;
|
use Socialbox\Objects\Database\SessionRecord;
|
||||||
use Symfony\Component\Uid\Uuid;
|
use Symfony\Component\Uid\Uuid;
|
||||||
|
|
||||||
|
@ -92,6 +95,8 @@
|
||||||
*/
|
*/
|
||||||
public static function getSession(string $uuid): SessionRecord
|
public static function getSession(string $uuid): SessionRecord
|
||||||
{
|
{
|
||||||
|
Logger::getLogger()->verbose(sprintf("Retrieving session %s from the database", $uuid));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$statement = Database::getConnection()->prepare("SELECT * FROM sessions WHERE uuid=?");
|
$statement = Database::getConnection()->prepare("SELECT * FROM sessions WHERE uuid=?");
|
||||||
|
@ -106,7 +111,15 @@
|
||||||
|
|
||||||
// Convert the timestamp fields to DateTime objects
|
// Convert the timestamp fields to DateTime objects
|
||||||
$data['created'] = new DateTime($data['created']);
|
$data['created'] = new DateTime($data['created']);
|
||||||
|
|
||||||
|
if(isset($data['last_request']) && $data['last_request'] !== null)
|
||||||
|
{
|
||||||
$data['last_request'] = new DateTime($data['last_request']);
|
$data['last_request'] = new DateTime($data['last_request']);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$data['last_request'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
return SessionRecord::fromArray($data);
|
return SessionRecord::fromArray($data);
|
||||||
|
|
||||||
|
@ -121,15 +134,23 @@
|
||||||
* Update the authenticated peer associated with the given session UUID.
|
* Update the authenticated peer associated with the given session UUID.
|
||||||
*
|
*
|
||||||
* @param string $uuid The UUID of the session to update.
|
* @param string $uuid The UUID of the session to update.
|
||||||
|
* @param RegisteredPeerRecord|string $registeredPeerUuid
|
||||||
* @return void
|
* @return void
|
||||||
* @throws DatabaseOperationException
|
* @throws DatabaseOperationException
|
||||||
*/
|
*/
|
||||||
public static function updateAuthenticatedPeer(string $uuid): void
|
public static function updateAuthenticatedPeer(string $uuid, RegisteredPeerRecord|string $registeredPeerUuid): void
|
||||||
{
|
{
|
||||||
|
if($registeredPeerUuid instanceof RegisteredPeerRecord)
|
||||||
|
{
|
||||||
|
$registeredPeerUuid = $registeredPeerUuid->getUuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::getLogger()->verbose(sprintf("Assigning peer %s to session %s", $registeredPeerUuid, $uuid));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$statement = Database::getConnection()->prepare("UPDATE sessions SET authenticated_peer_uuid=? WHERE uuid=?");
|
$statement = Database::getConnection()->prepare("UPDATE sessions SET authenticated_peer_uuid=? WHERE uuid=?");
|
||||||
$statement->bindParam(1, $uuid);
|
$statement->bindParam(1, $registeredPeerUuid);
|
||||||
$statement->bindParam(2, $uuid);
|
$statement->bindParam(2, $uuid);
|
||||||
$statement->execute();
|
$statement->execute();
|
||||||
}
|
}
|
||||||
|
@ -148,6 +169,8 @@
|
||||||
*/
|
*/
|
||||||
public static function updateLastRequest(string $uuid): void
|
public static function updateLastRequest(string $uuid): void
|
||||||
{
|
{
|
||||||
|
Logger::getLogger()->verbose(sprintf("Updating last request timestamp for session %s", $uuid));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$formattedTime = (new DateTime('@' . time()))->format('Y-m-d H:i:s');
|
$formattedTime = (new DateTime('@' . time()))->format('Y-m-d H:i:s');
|
||||||
|
@ -172,6 +195,8 @@
|
||||||
*/
|
*/
|
||||||
public static function updateState(string $uuid, SessionState $state): void
|
public static function updateState(string $uuid, SessionState $state): void
|
||||||
{
|
{
|
||||||
|
Logger::getLogger()->verbose(sprintf("Updating state of session %s to %s", $uuid, $state->value));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$state_value = $state->value;
|
$state_value = $state->value;
|
||||||
|
|
Loading…
Add table
Reference in a new issue