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:
parent
46ad03a54d
commit
367399f0fd
44 changed files with 2971 additions and 2016 deletions
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Classes\Configuration;
|
||||
|
||||
class CryptographyConfiguration
|
||||
{
|
||||
private ?int $hostKeyPairExpires;
|
||||
private ?string $hostPublicKey;
|
||||
private ?string $hostPrivateKey;
|
||||
private ?array $internalEncryptionKeys;
|
||||
private int $encryptionKeysCount;
|
||||
private string $encryptionKeysAlgorithm;
|
||||
private string $transportEncryptionAlgorithm;
|
||||
|
||||
/**
|
||||
* Constructor to initialize encryption and transport keys from provided data.
|
||||
*
|
||||
* @param array $data An associative array containing key-value pairs for encryption keys, algorithms, and expiration settings.
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->hostKeyPairExpires = $data['host_keypair_expires'] ?? null;
|
||||
$this->hostPublicKey = $data['host_public_key'] ?? null;
|
||||
$this->hostPrivateKey = $data['host_private_key'] ?? null;
|
||||
$this->internalEncryptionKeys = $data['internal_encryption_keys'] ?? null;
|
||||
$this->encryptionKeysCount = $data['encryption_keys_count'];
|
||||
$this->encryptionKeysAlgorithm = $data['encryption_keys_algorithm'];
|
||||
$this->transportEncryptionAlgorithm = $data['transport_encryption_algorithm'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the expiration timestamp of the host key pair.
|
||||
*
|
||||
* @return int|null The expiration timestamp of the host key pair, or null if not set.
|
||||
*/
|
||||
public function getHostKeyPairExpires(): ?int
|
||||
{
|
||||
return $this->hostKeyPairExpires;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the host's public key.
|
||||
*
|
||||
* @return string|null The host's public key, or null if not set.
|
||||
*/
|
||||
public function getHostPublicKey(): ?string
|
||||
{
|
||||
return $this->hostPublicKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the private key associated with the host.
|
||||
*
|
||||
* @return string|null The host's private key, or null if not set.
|
||||
*/
|
||||
public function getHostPrivateKey(): ?string
|
||||
{
|
||||
return $this->hostPrivateKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the internal encryption keys.
|
||||
*
|
||||
* @return array|null Returns an array of internal encryption keys if set, or null if no keys are available.
|
||||
*/
|
||||
public function getInternalEncryptionKeys(): ?array
|
||||
{
|
||||
return $this->internalEncryptionKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a random internal encryption key from the available set of encryption keys.
|
||||
*
|
||||
* @return string|null Returns a randomly selected encryption key as a string, or null if no keys are available.
|
||||
*/
|
||||
public function getRandomInternalEncryptionKey(): ?string
|
||||
{
|
||||
return $this->internalEncryptionKeys[array_rand($this->internalEncryptionKeys)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total count of encryption keys.
|
||||
*
|
||||
* @return int The number of encryption keys.
|
||||
*/
|
||||
public function getEncryptionKeysCount(): int
|
||||
{
|
||||
return $this->encryptionKeysCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the algorithm used for the encryption keys.
|
||||
*
|
||||
* @return string The encryption keys algorithm.
|
||||
*/
|
||||
public function getEncryptionKeysAlgorithm(): string
|
||||
{
|
||||
return $this->encryptionKeysAlgorithm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the transport encryption algorithm being used.
|
||||
*
|
||||
* @return string The transport encryption algorithm.
|
||||
*/
|
||||
public function getTransportEncryptionAlgorithm(): string
|
||||
{
|
||||
return $this->transportEncryptionAlgorithm;
|
||||
}
|
||||
}
|
|
@ -5,13 +5,9 @@
|
|||
class InstanceConfiguration
|
||||
{
|
||||
private bool $enabled;
|
||||
private string $name;
|
||||
private ?string $domain;
|
||||
private ?string $rpcEndpoint;
|
||||
private int $encryptionKeysCount;
|
||||
private int $encryptionRecordsCount;
|
||||
private ?string $privateKey;
|
||||
private ?string $publicKey;
|
||||
private ?array $encryptionKeys;
|
||||
|
||||
/**
|
||||
* Constructor that initializes object properties with the provided data.
|
||||
|
@ -22,13 +18,9 @@
|
|||
public function __construct(array $data)
|
||||
{
|
||||
$this->enabled = (bool)$data['enabled'];
|
||||
$this->name = $data['name'];
|
||||
$this->domain = $data['domain'];
|
||||
$this->rpcEndpoint = $data['rpc_endpoint'];
|
||||
$this->encryptionKeysCount = $data['encryption_keys_count'];
|
||||
$this->encryptionRecordsCount = $data['encryption_records_count'];
|
||||
$this->privateKey = $data['private_key'];
|
||||
$this->publicKey = $data['public_key'];
|
||||
$this->encryptionKeys = $data['encryption_keys'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,6 +33,11 @@
|
|||
return $this->enabled;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the domain.
|
||||
*
|
||||
|
@ -58,62 +55,4 @@
|
|||
{
|
||||
return $this->rpcEndpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the number of encryption keys.
|
||||
*
|
||||
* @return int The number of encryption keys.
|
||||
*/
|
||||
public function getEncryptionKeysCount(): int
|
||||
{
|
||||
return $this->encryptionKeysCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the number of encryption records.
|
||||
*
|
||||
* @return int The number of encryption records.
|
||||
*/
|
||||
public function getEncryptionRecordsCount(): int
|
||||
{
|
||||
return $this->encryptionRecordsCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the private key.
|
||||
*
|
||||
* @return string|null The private key.
|
||||
*/
|
||||
public function getPrivateKey(): ?string
|
||||
{
|
||||
return $this->privateKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the public key.
|
||||
*
|
||||
* @return string|null The public key.
|
||||
*/
|
||||
public function getPublicKey(): ?string
|
||||
{
|
||||
return $this->publicKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the encryption keys.
|
||||
*
|
||||
* @return array|null The encryption keys.
|
||||
*/
|
||||
public function getEncryptionKeys(): ?array
|
||||
{
|
||||
return $this->encryptionKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRandomEncryptionKey(): string
|
||||
{
|
||||
return $this->encryptionKeys[array_rand($this->encryptionKeys)];
|
||||
}
|
||||
}
|
52
src/Socialbox/Classes/Configuration/StorageConfiguration.php
Normal file
52
src/Socialbox/Classes/Configuration/StorageConfiguration.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Classes\Configuration;
|
||||
|
||||
class StorageConfiguration
|
||||
{
|
||||
private string $path;
|
||||
private string $userDisplayImagesPath;
|
||||
private int $userDisplayImagesMaxSize;
|
||||
|
||||
/**
|
||||
* Constructor method to initialize the class properties with provided data.
|
||||
*
|
||||
* @param array $data An associative array containing configuration values
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->path = $data['path'];
|
||||
$this->userDisplayImagesPath = $data['user_display_images_path'];
|
||||
$this->userDisplayImagesMaxSize = $data['user_display_images_max_size'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the base path value.
|
||||
*
|
||||
* @return string The base path.
|
||||
*/
|
||||
public function getPath(): string
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the path for user display images.
|
||||
*
|
||||
* @return string The path where user display images are stored.
|
||||
*/
|
||||
public function getUserDisplayImagesPath(): string
|
||||
{
|
||||
return $this->path . DIRECTORY_SEPARATOR . $this->userDisplayImagesPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the maximum size allowed for user display images.
|
||||
*
|
||||
* @return int The maximum size in bytes.
|
||||
*/
|
||||
public function getUserDisplayImagesMaxSize(): int
|
||||
{
|
||||
return $this->userDisplayImagesMaxSize;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue