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

Closed
netkas wants to merge 421 commits from master into dev
3 changed files with 65 additions and 16 deletions
Showing only changes of commit 9ebf3f641f - Show all commits

View file

@ -2,6 +2,8 @@
namespace Socialbox\Managers;
use DateMalformedStringException;
use Exception;
use InvalidArgumentException;
use PDO;
use PDOException;
@ -140,7 +142,7 @@
return new RegisteredPeerRecord($result);
}
catch(PDOException | \DateMalformedStringException $e)
catch(Exception $e)
{
throw new DatabaseOperationException('Failed to get the peer from the database', $e);
}
@ -175,7 +177,7 @@
return new RegisteredPeerRecord($result);
}
catch(PDOException | \DateMalformedStringException $e)
catch(PDOException | DateMalformedStringException $e)
{
throw new DatabaseOperationException('Failed to get the peer from the database', $e);
}
@ -446,7 +448,7 @@
return new SecurePasswordRecord($result);
}
catch(PDOException | \DateMalformedStringException $e)
catch(PDOException | DateMalformedStringException $e)
{
throw new DatabaseOperationException('Failed to get the secure password record from the database', $e);
}

View file

@ -6,6 +6,7 @@
use Socialbox\Classes\Configuration;
use Socialbox\Enums\Flags\SessionFlags;
use Socialbox\Enums\SessionState;
use Socialbox\Exceptions\DatabaseOperationException;
use Socialbox\Interfaces\SerializableInterface;
use Socialbox\Managers\RegisteredPeerManager;
@ -185,13 +186,26 @@
return $this->created;
}
/**
* @return DateTime
*/
public function getExpires(): DateTime
{
return new DateTime('@' . time() + Configuration::getPoliciesConfiguration()->getSessionInactivityExpires());
}
/**
* Retrieves the list of flags associated with the current instance.
*
* @return array Returns an array of flags.
*/
public function getFlags(): array
public function getFlags(bool $asString): array
{
if($asString)
{
return array_map(fn(SessionFlags $flag) => $flag->value, $this->flags);
}
return $this->flags;
}
@ -252,16 +266,9 @@
*/
public function toStandardSessionState(): \Socialbox\Objects\Standard\SessionState
{
return new \Socialbox\Objects\Standard\SessionState([
'uuid' => $this->uuid,
'identified_as' => RegisteredPeerManager::getPeer($this->peerUuid)->getAddress(),
'authenticated' => $this->authenticated,
'flags' => $this->flags,
'created' => $this->created
]);
return \Socialbox\Objects\Standard\SessionState::fromSessionRecord($this);
}
/**
* @inheritDoc
*/

View file

@ -5,6 +5,8 @@
use DateTime;
use Socialbox\Enums\Flags\SessionFlags;
use Socialbox\Interfaces\SerializableInterface;
use Socialbox\Managers\RegisteredPeerManager;
use Socialbox\Objects\Database\SessionRecord;
class SessionState implements SerializableInterface
{
@ -16,6 +18,7 @@
*/
private ?array $flags;
private int $created;
private int $expires;
/**
* Constructor for initializing the object with the provided data.
@ -57,6 +60,19 @@
{
$this->created = time();
}
if(is_int($data['expires']))
{
$this->expires = $data['expires'];
}
elseif($data['expires'] instanceof DateTime)
{
$this->expires = $data['expires']->getTimestamp();
}
else
{
$this->expires = time();
}
}
/**
@ -130,6 +146,16 @@
return $this->created;
}
/**
* Retrieves the expiration timestamp of the current instance.
*
* @return int The expiration timestamp as an integer.
*/
public function getExpires(): int
{
return $this->expires;
}
/**
* Creates a new instance of SessionState from the provided array.
*
@ -142,9 +168,22 @@
}
/**
* Converts the current instance into an associative array.
*
* @return array An associative array representation of the instance, including UUID, identification, authentication status, flags, and creation date.
* @inheritDoc
*/
public static function fromSessionRecord(SessionRecord $sessionRecord): SessionState
{
return new self([
'uuid' => $sessionRecord->getUuid(),
'identified_as' => RegisteredPeerManager::getPeer($sessionRecord->getPeerUuid())->getAddress(),
'authenticated' => $sessionRecord->isAuthenticated(),
'flags' => $sessionRecord->getFlags(true),
'created' => $sessionRecord->getCreated()->getTimestamp(),
'expires' => $sessionRecord->getExpires()->getTimestamp()
]);
}
/**
* @inheritDoc
*/
public function toArray(): array
{
@ -154,6 +193,7 @@
'authenticated' => $this->authenticated,
'flags' => $this->flags,
'created' => $this->created,
'expires' => $this->expires
];
}
}