Changed Encryption to use LibSodium instead of OpenSSL, refactored many things and overall improved the code quality and performance with magic.

This commit is contained in:
netkas 2025-01-03 12:27:04 -05:00
parent 46ad03a54d
commit 367399f0fd
44 changed files with 2971 additions and 2016 deletions

View file

@ -2,49 +2,63 @@
namespace Socialbox\Objects;
use Socialbox\Interfaces\SerializableInterface;
/**
* Represents an exported session containing cryptographic keys, identifiers, and endpoints.
*/
class ExportedSession
class ExportedSession implements SerializableInterface
{
private string $peerAddress;
private string $privateKey;
private string $publicKey;
private string $encryptionKey;
private string $serverPublicKey;
private string $rpcEndpoint;
private string $sessionUuid;
private string $sessionUUID;
private string $transportEncryptionAlgorithm;
private int $serverKeypairExpires;
private string $serverPublicSigningKey;
private string $serverPublicEncryptionKey;
private string $clientPublicSigningKey;
private string $clientPrivateSigningKey;
private string $clientPublicEncryptionKey;
private string $clientPrivateEncryptionKey;
private string $privateSharedSecret;
private string $clientTransportEncryptionKey;
private string $serverTransportEncryptionKey;
/**
* Initializes a new instance of the class with the provided data.
* Constructor method to initialize class properties from the provided data array.
*
* @param array $data An associative array containing the configuration data.
* Expected keys:
* - 'peer_address': The address of the peer.
* - 'private_key': The private key for secure communication.
* - 'public_key': The public key for secure communication.
* - 'encryption_key': The encryption key used for communication.
* - 'server_public_key': The server's public key.
* - 'rpc_endpoint': The RPC endpoint for network communication.
* - 'session_uuid': The unique identifier for the session.
* @param array $data Associative array containing the required properties such as:
* 'peer_address', 'rpc_endpoint', 'session_uuid',
* 'server_public_signing_key', 'server_public_encryption_key',
* 'client_public_signing_key', 'client_private_signing_key',
* 'client_public_encryption_key', 'client_private_encryption_key',
* 'private_shared_secret', 'client_transport_encryption_key',
* 'server_transport_encryption_key'.
*
* @return void
*/
public function __construct(array $data)
{
$this->peerAddress = $data['peer_address'];
$this->privateKey = $data['private_key'];
$this->publicKey = $data['public_key'];
$this->encryptionKey = $data['encryption_key'];
$this->serverPublicKey = $data['server_public_key'];
$this->rpcEndpoint = $data['rpc_endpoint'];
$this->sessionUuid = $data['session_uuid'];
$this->sessionUUID = $data['session_uuid'];
$this->transportEncryptionAlgorithm = $data['transport_encryption_algorithm'];
$this->serverKeypairExpires = $data['server_keypair_expires'];
$this->serverPublicSigningKey = $data['server_public_signing_key'];
$this->serverPublicEncryptionKey = $data['server_public_encryption_key'];
$this->clientPublicSigningKey = $data['client_public_signing_key'];
$this->clientPrivateSigningKey = $data['client_private_signing_key'];
$this->clientPublicEncryptionKey = $data['client_public_encryption_key'];
$this->clientPrivateEncryptionKey = $data['client_private_encryption_key'];
$this->privateSharedSecret = $data['private_shared_secret'];
$this->clientTransportEncryptionKey = $data['client_transport_encryption_key'];
$this->serverTransportEncryptionKey = $data['server_transport_encryption_key'];
}
/**
* Retrieves the address of the peer.
* Retrieves the peer address associated with the current instance.
*
* @return string The peer's address as a string.
* @return string The peer address.
*/
public function getPeerAddress(): string
{
@ -52,47 +66,7 @@
}
/**
* Retrieves the private key.
*
* @return string The private key.
*/
public function getPrivateKey(): string
{
return $this->privateKey;
}
/**
* Retrieves the public key.
*
* @return string The public key.
*/
public function getPublicKey(): string
{
return $this->publicKey;
}
/**
* Retrieves the encryption key.
*
* @return string The encryption key.
*/
public function getEncryptionKey(): string
{
return $this->encryptionKey;
}
/**
* Retrieves the public key of the server.
*
* @return string The server's public key.
*/
public function getServerPublicKey(): string
{
return $this->serverPublicKey;
}
/**
* Retrieves the RPC endpoint URL.
* Retrieves the RPC endpoint.
*
* @return string The RPC endpoint.
*/
@ -102,38 +76,150 @@
}
/**
* Retrieves the unique identifier for the current session.
* Retrieves the session UUID associated with the current instance.
*
* @return string The session UUID.
*/
public function getSessionUuid(): string
public function getSessionUUID(): string
{
return $this->sessionUuid;
return $this->sessionUUID;
}
/**
* Converts the current instance into an array representation.
* Retrieves the transport encryption algorithm being used.
*
* @return array An associative array containing the instance properties and their respective values.
* @return string The transport encryption algorithm.
*/
public function getTransportEncryptionAlgorithm(): string
{
return $this->transportEncryptionAlgorithm;
}
/**
* Retrieves the expiration time of the server key pair.
*
* @return int The expiration timestamp of the server key pair.
*/
public function getServerKeypairExpires(): int
{
return $this->serverKeypairExpires;
}
/**
* Retrieves the public signing key of the server.
*
* @return string The server's public signing key.
*/
public function getServerPublicSigningKey(): string
{
return $this->serverPublicSigningKey;
}
/**
* Retrieves the server's public encryption key.
*
* @return string The server's public encryption key.
*/
public function getServerPublicEncryptionKey(): string
{
return $this->serverPublicEncryptionKey;
}
/**
* Retrieves the client's public signing key.
*
* @return string The client's public signing key.
*/
public function getClientPublicSigningKey(): string
{
return $this->clientPublicSigningKey;
}
/**
* Retrieves the client's private signing key.
*
* @return string The client's private signing key.
*/
public function getClientPrivateSigningKey(): string
{
return $this->clientPrivateSigningKey;
}
/**
* Retrieves the public encryption key of the client.
*
* @return string The client's public encryption key.
*/
public function getClientPublicEncryptionKey(): string
{
return $this->clientPublicEncryptionKey;
}
/**
* Retrieves the client's private encryption key.
*
* @return string The client's private encryption key.
*/
public function getClientPrivateEncryptionKey(): string
{
return $this->clientPrivateEncryptionKey;
}
/**
* Retrieves the private shared secret associated with the current instance.
*
* @return string The private shared secret.
*/
public function getPrivateSharedSecret(): string
{
return $this->privateSharedSecret;
}
/**
* Retrieves the client transport encryption key.
*
* @return string The client transport encryption key.
*/
public function getClientTransportEncryptionKey(): string
{
return $this->clientTransportEncryptionKey;
}
/**
* Retrieves the server transport encryption key associated with the current instance.
*
* @return string The server transport encryption key.
*/
public function getServerTransportEncryptionKey(): string
{
return $this->serverTransportEncryptionKey;
}
/**
* @inheritDoc
*/
public function toArray(): array
{
return [
'peer_address' => $this->peerAddress,
'private_key' => $this->privateKey,
'public_key' => $this->publicKey,
'encryption_key' => $this->encryptionKey,
'server_public_key' => $this->serverPublicKey,
'rpc_endpoint' => $this->rpcEndpoint,
'session_uuid' => $this->sessionUuid
'session_uuid' => $this->sessionUUID,
'transport_encryption_algorithm' => $this->transportEncryptionAlgorithm,
'server_keypair_expires' => $this->serverKeypairExpires,
'server_public_signing_key' => $this->serverPublicSigningKey,
'server_public_encryption_key' => $this->serverPublicEncryptionKey,
'client_public_signing_key' => $this->clientPublicSigningKey,
'client_private_signing_key' => $this->clientPrivateSigningKey,
'client_public_encryption_key' => $this->clientPublicEncryptionKey,
'client_private_encryption_key' => $this->clientPrivateEncryptionKey,
'private_shared_secret' => $this->privateSharedSecret,
'client_transport_encryption_key' => $this->clientTransportEncryptionKey,
'server_transport_encryption_key' => $this->serverTransportEncryptionKey,
];
}
/**
* Creates an instance of ExportedSession from the provided array.
*
* @param array $data The input data used to construct the ExportedSession instance.
* @return ExportedSession The new ExportedSession instance created from the given data.
* @inheritDoc
*/
public static function fromArray(array $data): ExportedSession
{