Composer package update
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
// basic class test file
|
// basic class test file
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
// turn on all error reporting
|
// turn on all error reporting
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
// turn on all error reporting
|
// turn on all error reporting
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
// turn on all error reporting
|
// turn on all error reporting
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
// turn on all error reporting
|
// turn on all error reporting
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
// turn on all error reporting
|
// turn on all error reporting
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
// turn on all error reporting
|
// turn on all error reporting
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ $PRINT_ALL = false;
|
|||||||
$ECHO_ALL = true;
|
$ECHO_ALL = true;
|
||||||
$DB_DEBUG = true;
|
$DB_DEBUG = true;
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
@@ -18,6 +18,7 @@ require 'config.php';
|
|||||||
$LOG_FILE_ID = 'classTest-encryption';
|
$LOG_FILE_ID = 'classTest-encryption';
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
|
|
||||||
|
use CoreLibs\Security\AsymmetricAnonymousEncryption;
|
||||||
use CoreLibs\Security\SymmetricEncryption;
|
use CoreLibs\Security\SymmetricEncryption;
|
||||||
use CoreLibs\Security\CreateKey;
|
use CoreLibs\Security\CreateKey;
|
||||||
|
|
||||||
@@ -36,6 +37,8 @@ print "<body>";
|
|||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||||
|
|
||||||
|
print "<h2>Symmetric Encryption</h2>";
|
||||||
|
|
||||||
$key = CreateKey::generateRandomKey();
|
$key = CreateKey::generateRandomKey();
|
||||||
print "Secret Key: " . $key . "<br>";
|
print "Secret Key: " . $key . "<br>";
|
||||||
|
|
||||||
@@ -105,6 +108,49 @@ try {
|
|||||||
// $encrypted = $se->encrypt($string);
|
// $encrypted = $se->encrypt($string);
|
||||||
// $decrypted = $se->decrypt($encrypted);
|
// $decrypted = $se->decrypt($encrypted);
|
||||||
|
|
||||||
|
echo "<hr>";
|
||||||
|
print "<h2>Asymmetric Encryption</h2>";
|
||||||
|
|
||||||
|
$key_pair = CreateKey::createKeyPair();
|
||||||
|
$public_key = CreateKey::getPublicKey($key_pair);
|
||||||
|
|
||||||
|
$string = "I am some asymmetric secret";
|
||||||
|
print "Message: " . $string . "<br>";
|
||||||
|
$encrypted = sodium_crypto_box_seal($string, CreateKey::hex2bin($public_key));
|
||||||
|
$message = sodium_bin2base64($encrypted, SODIUM_BASE64_VARIANT_ORIGINAL);
|
||||||
|
print "Encrypted PL: " . $message . "<br>";
|
||||||
|
$result = sodium_base642bin($message, SODIUM_BASE64_VARIANT_ORIGINAL);
|
||||||
|
$decrypted = sodium_crypto_box_seal_open($result, CreateKey::hex2bin($key_pair));
|
||||||
|
print "Decrypted PL: " . $decrypted . "<br>";
|
||||||
|
|
||||||
|
$encrypted = AsymmetricAnonymousEncryption::encryptKey($string, $public_key);
|
||||||
|
print "Encrypted ST: " . $encrypted . "<br>";
|
||||||
|
$decrypted = AsymmetricAnonymousEncryption::decryptKey($encrypted, $key_pair);
|
||||||
|
print "Decrypted ST: " . $decrypted . "<br>";
|
||||||
|
|
||||||
|
$aa_crypt = new AsymmetricAnonymousEncryption($key_pair, $public_key);
|
||||||
|
$encrypted = $aa_crypt->encrypt($string);
|
||||||
|
print "Encrypted: " . $encrypted . "<br>";
|
||||||
|
$decrypted = $aa_crypt->decrypt($encrypted);
|
||||||
|
print "Decrypted: " . $decrypted . "<br>";
|
||||||
|
|
||||||
|
print "Base64 encode: " . base64_encode('Some text here') . "<Br>";
|
||||||
|
|
||||||
|
/// this has to fail
|
||||||
|
$crypt = new AsymmetricAnonymousEncryption();
|
||||||
|
$crypt->setPublicKey(CreateKey::getPublicKey(CreateKey::createKeyPair()));
|
||||||
|
print "Public Key: " . $crypt->getPublicKey() . "<br>";
|
||||||
|
try {
|
||||||
|
$crypt->setPublicKey(CreateKey::createKeyPair());
|
||||||
|
} catch (RangeException $e) {
|
||||||
|
print "Invalid range: <pre>$e</pre>";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$crypt->setKeyPair(CreateKey::getPublicKey(CreateKey::createKeyPair()));
|
||||||
|
} catch (RangeException $e) {
|
||||||
|
print "Invalid range: <pre>$e</pre>";
|
||||||
|
}
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
|
|||||||
2
www/composer.lock
generated
2
www/composer.lock
generated
@@ -12,7 +12,7 @@
|
|||||||
"dist": {
|
"dist": {
|
||||||
"type": "path",
|
"type": "path",
|
||||||
"url": "/storage/var/www/html/developers/clemens/core_data/composer-packages/CoreLibs-Composer-All",
|
"url": "/storage/var/www/html/developers/clemens/core_data/composer-packages/CoreLibs-Composer-All",
|
||||||
"reference": "7e01152bb4a33538bb0bbf0e3f2b22b900baba02"
|
"reference": "4ee141f8df16ecf8b4d32fb8763959e88ccc6914"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.2",
|
"php": ">=8.2",
|
||||||
|
|||||||
2
www/vendor/composer/installed.json
vendored
2
www/vendor/composer/installed.json
vendored
@@ -7,7 +7,7 @@
|
|||||||
"dist": {
|
"dist": {
|
||||||
"type": "path",
|
"type": "path",
|
||||||
"url": "/storage/var/www/html/developers/clemens/core_data/composer-packages/CoreLibs-Composer-All",
|
"url": "/storage/var/www/html/developers/clemens/core_data/composer-packages/CoreLibs-Composer-All",
|
||||||
"reference": "7e01152bb4a33538bb0bbf0e3f2b22b900baba02"
|
"reference": "4ee141f8df16ecf8b4d32fb8763959e88ccc6914"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.2",
|
"php": ">=8.2",
|
||||||
|
|||||||
2
www/vendor/composer/installed.php
vendored
2
www/vendor/composer/installed.php
vendored
@@ -13,7 +13,7 @@
|
|||||||
'egrajp/corelibs-composer-all' => array(
|
'egrajp/corelibs-composer-all' => array(
|
||||||
'pretty_version' => 'dev-development',
|
'pretty_version' => 'dev-development',
|
||||||
'version' => 'dev-development',
|
'version' => 'dev-development',
|
||||||
'reference' => '7e01152bb4a33538bb0bbf0e3f2b22b900baba02',
|
'reference' => '4ee141f8df16ecf8b4d32fb8763959e88ccc6914',
|
||||||
'type' => 'library',
|
'type' => 'library',
|
||||||
'install_path' => __DIR__ . '/../egrajp/corelibs-composer-all',
|
'install_path' => __DIR__ . '/../egrajp/corelibs-composer-all',
|
||||||
'aliases' => array(),
|
'aliases' => array(),
|
||||||
|
|||||||
@@ -4,4 +4,9 @@
|
|||||||
verbose="true"
|
verbose="true"
|
||||||
bootstrap="test/phpunit/bootstrap.php"
|
bootstrap="test/phpunit/bootstrap.php"
|
||||||
>
|
>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="deploy">
|
||||||
|
<directory>test/phpunit</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
9.23.3
|
9.24.1
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class Login
|
|||||||
private ?int $edit_user_id;
|
private ?int $edit_user_id;
|
||||||
/** @var ?string the user cuid (note will be super seeded with uuid v4 later) */
|
/** @var ?string the user cuid (note will be super seeded with uuid v4 later) */
|
||||||
private ?string $edit_user_cuid;
|
private ?string $edit_user_cuid;
|
||||||
/** @var ?string UUIDv4, will superseed the ecuid and replace euid as login id */
|
/** @var ?string UUIDv4, will superseed the eucuid and replace euid as login id */
|
||||||
private ?string $edit_user_cuuid;
|
private ?string $edit_user_cuuid;
|
||||||
/** @var string _GET/_POST loginUserId parameter for non password login */
|
/** @var string _GET/_POST loginUserId parameter for non password login */
|
||||||
private string $login_user_id = '';
|
private string $login_user_id = '';
|
||||||
@@ -2138,10 +2138,10 @@ body {
|
|||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
input.login-input-text {
|
input.login-input-text {
|
||||||
font-size: 1.5em;
|
font-size: 1.3em;
|
||||||
}
|
}
|
||||||
button.login-button {
|
button.login-button {
|
||||||
font-size: 1.5em;
|
font-size: 1.3em;
|
||||||
}
|
}
|
||||||
.login-visible {
|
.login-visible {
|
||||||
visibility: visible;
|
visibility: visible;
|
||||||
@@ -2371,7 +2371,7 @@ HTML;
|
|||||||
}
|
}
|
||||||
$q = <<<SQL
|
$q = <<<SQL
|
||||||
INSERT INTO {DB_SCHEMA}.edit_log (
|
INSERT INTO {DB_SCHEMA}.edit_log (
|
||||||
username, euid, ecuid, ecuuid, event_date, event, error, data, data_binary, page,
|
username, euid, eucuid, eucuuid, event_date, event, error, data, data_binary, page,
|
||||||
ip, ip_address, user_agent, referer, script_name, query_string, request_scheme, server_name,
|
ip, ip_address, user_agent, referer, script_name, query_string, request_scheme, server_name,
|
||||||
http_host, http_data, session_id,
|
http_host, http_data, session_id,
|
||||||
action_data
|
action_data
|
||||||
@@ -2727,7 +2727,7 @@ HTML;
|
|||||||
return $this->session->get('LOGIN_PAGES');
|
return $this->session->get('LOGIN_PAGES');
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: logged in uid(pk)/cuid/ecuuid
|
// MARK: logged in uid(pk)/eucuid/eucuuid
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current set EUID (edit user id)
|
* Get the current set EUID (edit user id)
|
||||||
@@ -2938,7 +2938,7 @@ HTML;
|
|||||||
if (empty($this->edit_user_cuuid)) {
|
if (empty($this->edit_user_cuuid)) {
|
||||||
return $this->permission_okay;
|
return $this->permission_okay;
|
||||||
}
|
}
|
||||||
// euid must match ecuid and ecuuid
|
// euid must match eucuid and eucuuid
|
||||||
// bail for previous wrong page match, eg if method is called twice
|
// bail for previous wrong page match, eg if method is called twice
|
||||||
if ($this->login_error == 103) {
|
if ($this->login_error == 103) {
|
||||||
return $this->permission_okay;
|
return $this->permission_okay;
|
||||||
|
|||||||
@@ -358,7 +358,7 @@ class Backend
|
|||||||
}
|
}
|
||||||
$q = <<<SQL
|
$q = <<<SQL
|
||||||
INSERT INTO {DB_SCHEMA}.edit_log (
|
INSERT INTO {DB_SCHEMA}.edit_log (
|
||||||
username, euid, ecuid, ecuuid, event_date, event, error, data, data_binary, page,
|
username, euid, eucuid, eucuuid, event_date, event, error, data, data_binary, page,
|
||||||
ip, user_agent, referer, script_name, query_string, server_name, http_host,
|
ip, user_agent, referer, script_name, query_string, server_name, http_host,
|
||||||
http_accept, http_accept_charset, http_accept_encoding, session_id,
|
http_accept, http_accept_charset, http_accept_encoding, session_id,
|
||||||
action, action_id, action_sub_id, action_yes, action_flag, action_menu, action_loaded,
|
action, action_id, action_sub_id, action_yes, action_flag, action_menu, action_loaded,
|
||||||
|
|||||||
@@ -527,7 +527,9 @@ class ArrayHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* From the array with key -> anything values return only the matching entries from key list
|
* From the array with key -> mixed values,
|
||||||
|
* return only the entries where the key matches the key given in the key list parameter
|
||||||
|
*
|
||||||
* key list is a list[string]
|
* key list is a list[string]
|
||||||
* if key list is empty, return array as is
|
* if key list is empty, return array as is
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -35,14 +35,39 @@ class CreateKey
|
|||||||
return random_bytes(SODIUM_CRYPTO_SECRETBOX_KEYBYTES);
|
return random_bytes(SODIUM_CRYPTO_SECRETBOX_KEYBYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates a sodium cyptobox keypair as hex string
|
||||||
|
*
|
||||||
|
* @return string hex string for the keypair
|
||||||
|
*/
|
||||||
|
public static function createKeyPair(): string
|
||||||
|
{
|
||||||
|
return self::bin2hex(sodium_crypto_box_keypair());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* extracts the public key and returns it as hex string from the hex keypari
|
||||||
|
*
|
||||||
|
* @param string $hex_keypair hex encoded keypair
|
||||||
|
* @return string hex encoded public key
|
||||||
|
*/
|
||||||
|
public static function getPublicKey(
|
||||||
|
#[\SensitiveParameter]
|
||||||
|
string $hex_keypair
|
||||||
|
): string {
|
||||||
|
return self::bin2hex(sodium_crypto_box_publickey(self::hex2bin($hex_keypair)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* convert binary key to hex string
|
* convert binary key to hex string
|
||||||
*
|
*
|
||||||
* @param string $hex_key Convert binary key string to hex
|
* @param string $hex_key Convert binary key string to hex
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function bin2hex(string $hex_key): string
|
public static function bin2hex(
|
||||||
{
|
#[\SensitiveParameter]
|
||||||
|
string $hex_key
|
||||||
|
): string {
|
||||||
return sodium_bin2hex($hex_key);
|
return sodium_bin2hex($hex_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,8 +77,10 @@ class CreateKey
|
|||||||
* @param string $string_key Convery hex key string to binary
|
* @param string $string_key Convery hex key string to binary
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function hex2bin(string $string_key): string
|
public static function hex2bin(
|
||||||
{
|
#[\SensitiveParameter]
|
||||||
|
string $string_key
|
||||||
|
): string {
|
||||||
return sodium_hex2bin($string_key);
|
return sodium_hex2bin($string_key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ class Password
|
|||||||
* @param string $password password
|
* @param string $password password
|
||||||
* @return string hashed password
|
* @return string hashed password
|
||||||
*/
|
*/
|
||||||
public static function passwordSet(string $password): string
|
public static function passwordSet(
|
||||||
{
|
#[\SensitiveParameter]
|
||||||
|
string $password
|
||||||
|
): string {
|
||||||
// always use the PHP default for the password
|
// always use the PHP default for the password
|
||||||
// password options ca be set in the password init,
|
// password options ca be set in the password init,
|
||||||
// but should be kept as default
|
// but should be kept as default
|
||||||
@@ -31,8 +33,11 @@ class Password
|
|||||||
* @param string $hash password hash
|
* @param string $hash password hash
|
||||||
* @return bool true or false
|
* @return bool true or false
|
||||||
*/
|
*/
|
||||||
public static function passwordVerify(string $password, string $hash): bool
|
public static function passwordVerify(
|
||||||
{
|
#[\SensitiveParameter]
|
||||||
|
string $password,
|
||||||
|
string $hash
|
||||||
|
): bool {
|
||||||
if (password_verify($password, $hash)) {
|
if (password_verify($password, $hash)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -24,19 +24,19 @@ class SymmetricEncryption
|
|||||||
/** @var SymmetricEncryption self instance */
|
/** @var SymmetricEncryption self instance */
|
||||||
private static SymmetricEncryption $instance;
|
private static SymmetricEncryption $instance;
|
||||||
|
|
||||||
/** @var string bin hex key */
|
/** @var ?string bin hex key */
|
||||||
private string $key = '';
|
private ?string $key = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* init class
|
* init class
|
||||||
* if key not passed, key must be set with createKey
|
* if key not passed, key must be set with createKey
|
||||||
*
|
*
|
||||||
* @param string|null|null $key
|
* @param string|null $key encryption key
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string|null $key = null
|
?string $key = null
|
||||||
) {
|
) {
|
||||||
if ($key != null) {
|
if ($key !== null) {
|
||||||
$this->setKey($key);
|
$this->setKey($key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,9 +45,10 @@ class SymmetricEncryption
|
|||||||
* Returns the singleton self object.
|
* Returns the singleton self object.
|
||||||
* For function wrapper use
|
* For function wrapper use
|
||||||
*
|
*
|
||||||
|
* @param string|null $key encryption key
|
||||||
* @return SymmetricEncryption object
|
* @return SymmetricEncryption object
|
||||||
*/
|
*/
|
||||||
public static function getInstance(string|null $key = null): self
|
public static function getInstance(?string $key = null): self
|
||||||
{
|
{
|
||||||
// new if no instsance or key is different
|
// new if no instsance or key is different
|
||||||
if (
|
if (
|
||||||
@@ -59,6 +60,34 @@ class SymmetricEncryption
|
|||||||
return self::$instance;
|
return self::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clean up
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __deconstruct()
|
||||||
|
{
|
||||||
|
if (empty($this->key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// would set it to null, but we we do not want to make key null
|
||||||
|
sodium_memzero($this->key);
|
||||||
|
return;
|
||||||
|
} catch (SodiumException) {
|
||||||
|
// empty catch
|
||||||
|
}
|
||||||
|
if (is_null($this->key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$zero = str_repeat("\0", mb_strlen($this->key, '8bit'));
|
||||||
|
$this->key = $this->key ^ (
|
||||||
|
$zero ^ $this->key
|
||||||
|
);
|
||||||
|
unset($zero);
|
||||||
|
unset($this->key); /** @phan-suppress-current-line PhanTypeObjectUnsetDeclaredProperty */
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************
|
/* ************************************************************************
|
||||||
* MARK: PRIVATE
|
* MARK: PRIVATE
|
||||||
* *************************************************************************/
|
* *************************************************************************/
|
||||||
@@ -66,11 +95,19 @@ class SymmetricEncryption
|
|||||||
/**
|
/**
|
||||||
* create key and check validity
|
* create key and check validity
|
||||||
*
|
*
|
||||||
* @param string $key The key from which the binary key will be created
|
* @param ?string $key The key from which the binary key will be created
|
||||||
* @return string Binary key string
|
* @return string Binary key string
|
||||||
|
* @throws \UnexpectedValueException empty key
|
||||||
|
* @throws \UnexpectedValueException invalid hex key
|
||||||
|
* @throws \RangeException invalid length
|
||||||
*/
|
*/
|
||||||
private function createKey(string $key): string
|
private function createKey(
|
||||||
{
|
#[\SensitiveParameter]
|
||||||
|
?string $key
|
||||||
|
): string {
|
||||||
|
if (empty($key)) {
|
||||||
|
throw new \UnexpectedValueException('Key cannot be empty');
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$key = CreateKey::hex2bin($key);
|
$key = CreateKey::hex2bin($key);
|
||||||
} catch (SodiumException $e) {
|
} catch (SodiumException $e) {
|
||||||
@@ -91,36 +128,42 @@ class SymmetricEncryption
|
|||||||
* @param string $encrypted Text to decrypt
|
* @param string $encrypted Text to decrypt
|
||||||
* @param ?string $key Mandatory encryption key, will throw exception if empty
|
* @param ?string $key Mandatory encryption key, will throw exception if empty
|
||||||
* @return string Plain text
|
* @return string Plain text
|
||||||
* @throws \RangeException
|
* @throws \UnexpectedValueException key cannot be empty
|
||||||
* @throws \UnexpectedValueException
|
* @throws \UnexpectedValueException decipher message failed
|
||||||
* @throws \UnexpectedValueException
|
* @throws \UnexpectedValueException invalid key
|
||||||
*/
|
*/
|
||||||
private function decryptData(string $encrypted, ?string $key): string
|
private function decryptData(
|
||||||
{
|
#[\SensitiveParameter]
|
||||||
if (empty($key)) {
|
string $encrypted,
|
||||||
throw new \UnexpectedValueException('Key not set');
|
#[\SensitiveParameter]
|
||||||
|
?string $key
|
||||||
|
): string {
|
||||||
|
if (empty($encrypted)) {
|
||||||
|
throw new \UnexpectedValueException('Encrypted string cannot be empty');
|
||||||
}
|
}
|
||||||
$key = $this->createKey($key);
|
$key = $this->createKey($key);
|
||||||
$decoded = base64_decode($encrypted);
|
$decoded = base64_decode($encrypted);
|
||||||
$nonce = mb_substr($decoded, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit');
|
$nonce = mb_substr($decoded, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit');
|
||||||
$ciphertext = mb_substr($decoded, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit');
|
$ciphertext = mb_substr($decoded, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit');
|
||||||
|
|
||||||
$plain = false;
|
$plaintext = false;
|
||||||
try {
|
try {
|
||||||
$plain = sodium_crypto_secretbox_open(
|
$plaintext = sodium_crypto_secretbox_open(
|
||||||
$ciphertext,
|
$ciphertext,
|
||||||
$nonce,
|
$nonce,
|
||||||
$key
|
$key
|
||||||
);
|
);
|
||||||
} catch (SodiumException $e) {
|
} catch (SodiumException $e) {
|
||||||
|
sodium_memzero($ciphertext);
|
||||||
|
sodium_memzero($key);
|
||||||
throw new \UnexpectedValueException('Decipher message failed: ' . $e->getMessage());
|
throw new \UnexpectedValueException('Decipher message failed: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
if (!is_string($plain)) {
|
|
||||||
throw new \UnexpectedValueException('Invalid Key');
|
|
||||||
}
|
|
||||||
sodium_memzero($ciphertext);
|
sodium_memzero($ciphertext);
|
||||||
sodium_memzero($key);
|
sodium_memzero($key);
|
||||||
return $plain;
|
if (!is_string($plaintext)) {
|
||||||
|
throw new \UnexpectedValueException('Invalid Key');
|
||||||
|
}
|
||||||
|
return $plaintext;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,15 +171,15 @@ class SymmetricEncryption
|
|||||||
*
|
*
|
||||||
* @param string $message Message to encrypt
|
* @param string $message Message to encrypt
|
||||||
* @param ?string $key Mandatory encryption key, will throw exception if empty
|
* @param ?string $key Mandatory encryption key, will throw exception if empty
|
||||||
* @return string
|
* @return string Ciphered text
|
||||||
* @throws \Exception
|
* @throws \UnexpectedValueException create message failed
|
||||||
* @throws \RangeException
|
|
||||||
*/
|
*/
|
||||||
private function encryptData(string $message, ?string $key): string
|
private function encryptData(
|
||||||
{
|
#[\SensitiveParameter]
|
||||||
if ($key === null) {
|
string $message,
|
||||||
throw new \UnexpectedValueException('Key not set');
|
#[\SensitiveParameter]
|
||||||
}
|
?string $key
|
||||||
|
): string {
|
||||||
$key = $this->createKey($key);
|
$key = $this->createKey($key);
|
||||||
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
|
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
|
||||||
try {
|
try {
|
||||||
@@ -149,6 +192,8 @@ class SymmetricEncryption
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
} catch (SodiumException $e) {
|
} catch (SodiumException $e) {
|
||||||
|
sodium_memzero($message);
|
||||||
|
sodium_memzero($key);
|
||||||
throw new \UnexpectedValueException("Create encrypted message failed: " . $e->getMessage());
|
throw new \UnexpectedValueException("Create encrypted message failed: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
sodium_memzero($message);
|
sodium_memzero($message);
|
||||||
@@ -160,19 +205,48 @@ class SymmetricEncryption
|
|||||||
* MARK: PUBLIC
|
* MARK: PUBLIC
|
||||||
* *************************************************************************/
|
* *************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set a new key for encryption
|
* set a new key for encryption
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws \UnexpectedValueException key cannot be empty
|
||||||
*/
|
*/
|
||||||
public function setKey(string $key)
|
public function setKey(
|
||||||
{
|
#[\SensitiveParameter]
|
||||||
|
string $key
|
||||||
|
) {
|
||||||
if (empty($key)) {
|
if (empty($key)) {
|
||||||
throw new \UnexpectedValueException('Key cannot be empty');
|
throw new \UnexpectedValueException('Key cannot be empty');
|
||||||
}
|
}
|
||||||
|
// check that this is a valid key
|
||||||
|
$this->createKey($key);
|
||||||
|
// set key
|
||||||
$this->key = $key;
|
$this->key = $key;
|
||||||
|
sodium_memzero($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if set key is equal to parameter key
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function compareKey(
|
||||||
|
#[\SensitiveParameter]
|
||||||
|
string $key
|
||||||
|
): bool {
|
||||||
|
return $key === $this->key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the current set key, null if not set
|
||||||
|
*
|
||||||
|
* @return ?string
|
||||||
|
*/
|
||||||
|
public function getKey(): ?string
|
||||||
|
{
|
||||||
|
return $this->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,13 +256,13 @@ class SymmetricEncryption
|
|||||||
* @param string $encrypted Message encrypted with safeEncrypt()
|
* @param string $encrypted Message encrypted with safeEncrypt()
|
||||||
* @param string $key Encryption key (as hex string)
|
* @param string $key Encryption key (as hex string)
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \Exception
|
|
||||||
* @throws \RangeException
|
|
||||||
* @throws \UnexpectedValueException
|
|
||||||
* @throws \UnexpectedValueException
|
|
||||||
*/
|
*/
|
||||||
public static function decryptKey(string $encrypted, string $key): string
|
public static function decryptKey(
|
||||||
{
|
#[\SensitiveParameter]
|
||||||
|
string $encrypted,
|
||||||
|
#[\SensitiveParameter]
|
||||||
|
string $key
|
||||||
|
): string {
|
||||||
return self::getInstance()->decryptData($encrypted, $key);
|
return self::getInstance()->decryptData($encrypted, $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,12 +271,11 @@ class SymmetricEncryption
|
|||||||
*
|
*
|
||||||
* @param string $encrypted Message encrypted with safeEncrypt()
|
* @param string $encrypted Message encrypted with safeEncrypt()
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \RangeException
|
|
||||||
* @throws \UnexpectedValueException
|
|
||||||
* @throws \UnexpectedValueException
|
|
||||||
*/
|
*/
|
||||||
public function decrypt(string $encrypted): string
|
public function decrypt(
|
||||||
{
|
#[\SensitiveParameter]
|
||||||
|
string $encrypted
|
||||||
|
): string {
|
||||||
return $this->decryptData($encrypted, $this->key);
|
return $this->decryptData($encrypted, $this->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,11 +286,13 @@ class SymmetricEncryption
|
|||||||
* @param string $message Message to encrypt
|
* @param string $message Message to encrypt
|
||||||
* @param string $key Encryption key (as hex string)
|
* @param string $key Encryption key (as hex string)
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \Exception
|
|
||||||
* @throws \RangeException
|
|
||||||
*/
|
*/
|
||||||
public static function encryptKey(string $message, string $key): string
|
public static function encryptKey(
|
||||||
{
|
#[\SensitiveParameter]
|
||||||
|
string $message,
|
||||||
|
#[\SensitiveParameter]
|
||||||
|
string $key
|
||||||
|
): string {
|
||||||
return self::getInstance()->encryptData($message, $key);
|
return self::getInstance()->encryptData($message, $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,11 +301,11 @@ class SymmetricEncryption
|
|||||||
*
|
*
|
||||||
* @param string $message Message to encrypt
|
* @param string $message Message to encrypt
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \Exception
|
|
||||||
* @throws \RangeException
|
|
||||||
*/
|
*/
|
||||||
public function encrypt(string $message): string
|
public function encrypt(
|
||||||
{
|
#[\SensitiveParameter]
|
||||||
|
string $message
|
||||||
|
): string {
|
||||||
return $this->encryptData($message, $this->key);
|
return $this->encryptData($message, $this->key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -652,8 +652,8 @@ CREATE TABLE edit_log (
|
|||||||
edit_log_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
edit_log_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
||||||
euid INT, -- this is a foreign key, but I don't nedd to reference to it
|
euid INT, -- this is a foreign key, but I don't nedd to reference to it
|
||||||
FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL,
|
FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL,
|
||||||
ecuid VARCHAR,
|
eucuid VARCHAR,
|
||||||
ecuuid UUID, -- this is the one we want to use, full UUIDv4 from the edit user table
|
eucuuid UUID, -- this is the one we want to use, full UUIDv4 from the edit user table
|
||||||
-- date_created equal, but can be overridden
|
-- date_created equal, but can be overridden
|
||||||
event_date TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
event_date TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
-- session ID if set
|
-- session ID if set
|
||||||
|
|||||||
@@ -15,6 +15,77 @@ use CoreLibs\Security\SymmetricEncryption;
|
|||||||
*/
|
*/
|
||||||
final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
||||||
{
|
{
|
||||||
|
// MARK: key set compare
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::compareKey
|
||||||
|
* @covers ::getKey
|
||||||
|
* @testdox Check if init class set key matches to created key
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testKeyInitGetCompare(): void
|
||||||
|
{
|
||||||
|
$key = CreateKey::generateRandomKey();
|
||||||
|
$crypt = new SymmetricEncryption($key);
|
||||||
|
$this->assertTrue(
|
||||||
|
$crypt->compareKey($key),
|
||||||
|
'set key not equal to original key'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$key,
|
||||||
|
$crypt->getKey(),
|
||||||
|
'set key returned not equal to original key'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::setKey
|
||||||
|
* @covers ::compareKey
|
||||||
|
* @covers ::getKey
|
||||||
|
* @testdox Check if set key after class init matches to created key
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testKeySetGetCompare(): void
|
||||||
|
{
|
||||||
|
$key = CreateKey::generateRandomKey();
|
||||||
|
$crypt = new SymmetricEncryption();
|
||||||
|
$crypt->setKey($key);
|
||||||
|
$this->assertTrue(
|
||||||
|
$crypt->compareKey($key),
|
||||||
|
'set key not equal to original key'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$key,
|
||||||
|
$crypt->getKey(),
|
||||||
|
'set key returned not equal to original key'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: empty encrypted string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::decryptKey
|
||||||
|
* @covers ::decrypt
|
||||||
|
* @testdox Test empty encrypted string to decrypt
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testEmptyDecryptionString(): void
|
||||||
|
{
|
||||||
|
$this->expectExceptionMessage('Encrypted string cannot be empty');
|
||||||
|
SymmetricEncryption::decryptKey('', CreateKey::generateRandomKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: encrypt/decrypt compare
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -88,8 +159,8 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
* test encrypt/decrypt produce correct output
|
* test encrypt/decrypt produce correct output
|
||||||
*
|
*
|
||||||
* @covers ::generateRandomKey
|
* @covers ::generateRandomKey
|
||||||
* @covers ::encrypt
|
* @covers ::encryptKey
|
||||||
* @covers ::decrypt
|
* @covers ::decryptKey
|
||||||
* @dataProvider providerEncryptDecryptSuccess
|
* @dataProvider providerEncryptDecryptSuccess
|
||||||
* @testdox encrypt/decrypt static $input must be $expected [$_dataName]
|
* @testdox encrypt/decrypt static $input must be $expected [$_dataName]
|
||||||
*
|
*
|
||||||
@@ -111,6 +182,8 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: invalid key
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -180,8 +253,8 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
* Test decryption with wrong key
|
* Test decryption with wrong key
|
||||||
*
|
*
|
||||||
* @covers ::generateRandomKey
|
* @covers ::generateRandomKey
|
||||||
* @covers ::encrypt
|
* @covers ::encryptKey
|
||||||
* @covers ::decrypt
|
* @covers ::decryptKey
|
||||||
* @dataProvider providerEncryptFailed
|
* @dataProvider providerEncryptFailed
|
||||||
* @testdox decrypt static with wrong key $input throws $exception_message [$_dataName]
|
* @testdox decrypt static with wrong key $input throws $exception_message [$_dataName]
|
||||||
*
|
*
|
||||||
@@ -200,6 +273,8 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
SymmetricEncryption::decryptKey($encrypted, $wrong_key);
|
SymmetricEncryption::decryptKey($encrypted, $wrong_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: wrong key
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -216,6 +291,10 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
'key' => '1cabd5cba9e042f12522f4ff2de5c31d233b',
|
'key' => '1cabd5cba9e042f12522f4ff2de5c31d233b',
|
||||||
'excpetion_message' => 'Key is not the correct size (must be '
|
'excpetion_message' => 'Key is not the correct size (must be '
|
||||||
],
|
],
|
||||||
|
'empty key' => [
|
||||||
|
'key' => '',
|
||||||
|
'excpetion_message' => 'Key cannot be empty'
|
||||||
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,6 +315,7 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
$enc_key = CreateKey::generateRandomKey();
|
$enc_key = CreateKey::generateRandomKey();
|
||||||
|
|
||||||
// class
|
// class
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
$crypt = new SymmetricEncryption($key);
|
$crypt = new SymmetricEncryption($key);
|
||||||
$this->expectExceptionMessage($exception_message);
|
$this->expectExceptionMessage($exception_message);
|
||||||
$crypt->encrypt('test');
|
$crypt->encrypt('test');
|
||||||
@@ -244,22 +324,6 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
$this->expectExceptionMessage($exception_message);
|
$this->expectExceptionMessage($exception_message);
|
||||||
$crypt->setKey($key);
|
$crypt->setKey($key);
|
||||||
$crypt->decrypt($encrypted);
|
$crypt->decrypt($encrypted);
|
||||||
|
|
||||||
// class instance
|
|
||||||
$this->expectExceptionMessage($exception_message);
|
|
||||||
SymmetricEncryption::getInstance($key)->encrypt('test');
|
|
||||||
// we must encrypt valid thing first so we can fail with the wrong key
|
|
||||||
$encrypted = SymmetricEncryption::getInstance($enc_key)->encrypt('test');
|
|
||||||
$this->expectExceptionMessage($exception_message);
|
|
||||||
SymmetricEncryption::getInstance($key)->decrypt($encrypted);
|
|
||||||
|
|
||||||
// class static
|
|
||||||
$this->expectExceptionMessage($exception_message);
|
|
||||||
SymmetricEncryption::encryptKey('test', $key);
|
|
||||||
// we must encrypt valid thing first so we can fail with the wrong key
|
|
||||||
$encrypted = SymmetricEncryption::encryptKey('test', $enc_key);
|
|
||||||
$this->expectExceptionMessage($exception_message);
|
|
||||||
SymmetricEncryption::decryptKey($encrypted, $key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -290,8 +354,8 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* test invalid key provided to decrypt or encrypt
|
* test invalid key provided to decrypt or encrypt
|
||||||
*
|
*
|
||||||
* @covers ::encrypt
|
* @covers ::encryptKey
|
||||||
* @covers ::decrypt
|
* @covers ::decryptKey
|
||||||
* @dataProvider providerWrongKey
|
* @dataProvider providerWrongKey
|
||||||
* @testdox wrong key static $key throws $exception_message [$_dataName]
|
* @testdox wrong key static $key throws $exception_message [$_dataName]
|
||||||
*
|
*
|
||||||
@@ -312,6 +376,8 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
SymmetricEncryption::decryptKey($encrypted, $key);
|
SymmetricEncryption::decryptKey($encrypted, $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: wrong input
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -358,7 +424,7 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @covers ::decrypt
|
* @covers ::decryptKey
|
||||||
* @dataProvider providerWrongCiphertext
|
* @dataProvider providerWrongCiphertext
|
||||||
* @testdox too short ciphertext indirect $input throws $exception_message [$_dataName]
|
* @testdox too short ciphertext indirect $input throws $exception_message [$_dataName]
|
||||||
*
|
*
|
||||||
@@ -382,7 +448,7 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @covers ::decrypt
|
* @covers ::decryptKey
|
||||||
* @dataProvider providerWrongCiphertext
|
* @dataProvider providerWrongCiphertext
|
||||||
* @testdox too short ciphertext static $input throws $exception_message [$_dataName]
|
* @testdox too short ciphertext static $input throws $exception_message [$_dataName]
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user