From 99b12ca8c05ddc235ed5256ae13c72484c42899f Mon Sep 17 00:00:00 2001 From: aB0t Date: Tue, 24 Oct 2023 10:36:46 +0200 Subject: [PATCH] update 2023-10-24 10:36:32 --- .../README.md | 1 + .../code.php | 17 +- .../code.power | 17 +- .../README.md | 4 +- .../code.php | 13 +- .../code.power | 12 +- .../README.md | 3 +- .../code.php | 102 +++++++++-- .../code.power | 98 +++++++++-- .../settings.json | 4 +- .../README.md | 11 +- .../README.md | 4 +- .../code.php | 15 +- .../code.power | 12 +- .../settings.json | 5 +- .../README.md | 11 +- .../README.md | 4 +- .../code.php | 9 +- .../code.power | 8 +- .../README.md | 41 +---- .../code.php | 166 ++---------------- .../code.power | 160 ++--------------- .../settings.json | 15 +- .../README.md | 1 + 24 files changed, 295 insertions(+), 438 deletions(-) diff --git a/src/11be6be3-ee3e-4771-8663-5545b76b73ab/README.md b/src/11be6be3-ee3e-4771-8663-5545b76b73ab/README.md index 9d3d4be..a1e9355 100644 --- a/src/11be6be3-ee3e-4771-8663-5545b76b73ab/README.md +++ b/src/11be6be3-ee3e-4771-8663-5545b76b73ab/README.md @@ -13,6 +13,7 @@ class Ftp #Gold { # ?FtpClient $client # ?object $details + + iables $signature + set(object $details) : Ftp + move(string $localPath, string $fileName) : bool - connected() : bool diff --git a/src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.php b/src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.php index 792332f..d981017 100644 --- a/src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.php +++ b/src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.php @@ -114,12 +114,13 @@ class Ftp implements Serverinterface // make sure we have a string and it is not default or empty if (StringHelper::check($this->details->signature)) { - // turn into variables - parse_str((string) $this->details->signature); + // turn into array of variables + $signature = []; + parse_str((string) $this->details->signature, $signature); // set options - if (isset($options) && ArrayHelper::check($options)) + if (isset($signature['options']) && ArrayHelper::check($signature['options'])) { - foreach ($options as $o__p0t1on => $vAln3) + foreach ($signature['options'] as $o__p0t1on => $vAln3) { if ('timeout' === $o__p0t1on) { @@ -136,10 +137,10 @@ class Ftp implements Serverinterface $options = []; } // get ftp object - if (isset($host) && $host != 'HOSTNAME' && - isset($port) && $port != 'PORT_INT' && - isset($username) && $username != 'user@name.com' && - isset($password) && $password != 'password') + if (isset($signature['host']) && $signature['host'] != 'HOSTNAME' && + isset($signature['port']) && $signature['port'] != 'PORT_INT' && + isset($signature['username']) && $signature['username'] != 'user@name.com' && + isset($signature['password']) && $signature['password'] != 'password') { // this is a singleton return FtpClient::getInstance($host, $port, $options, $username, $password); diff --git a/src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.power b/src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.power index b3909c0..af9d72e 100644 --- a/src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.power +++ b/src/11be6be3-ee3e-4771-8663-5545b76b73ab/code.power @@ -86,12 +86,13 @@ // make sure we have a string and it is not default or empty if (StringHelper::check($this->details->signature)) { - // turn into variables - parse_str((string) $this->details->signature); + // turn into array of variables + $signature = []; + parse_str((string) $this->details->signature, $signature); // set options - if (isset($options) && ArrayHelper::check($options)) + if (isset($signature['options']) && ArrayHelper::check($signature['options'])) { - foreach ($options as $o__p0t1on => $vAln3) + foreach ($signature['options'] as $o__p0t1on => $vAln3) { if ('timeout' === $o__p0t1on) { @@ -108,10 +109,10 @@ $options = []; } // get ftp object - if (isset($host) && $host != 'HOSTNAME' && - isset($port) && $port != 'PORT_INT' && - isset($username) && $username != 'user@name.com' && - isset($password) && $password != 'password') + if (isset($signature['host']) && $signature['host'] != 'HOSTNAME' && + isset($signature['port']) && $signature['port'] != 'PORT_INT' && + isset($signature['username']) && $signature['username'] != 'user@name.com' && + isset($signature['password']) && $signature['password'] != 'password') { // this is a singleton return FtpClient::getInstance($host, $port, $options, $username, $password); diff --git a/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/README.md b/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/README.md index eb93926..a497d73 100644 --- a/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/README.md +++ b/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/README.md @@ -15,7 +15,7 @@ class Legacy #Gold { # int $size + __construct(BASEAES $aes) + encrypt(string $string, string $key) : string - + decrypt(string $string, string $key) : string + + decrypt(string $string, string $key) : ?string } note right of Legacy::__construct @@ -35,7 +35,7 @@ note right of Legacy::decrypt Decrypt a string as needed since: 3.2.0 - return: string + return: ?string end note @enduml diff --git a/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.php b/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.php index e73c5bd..f7f4c8e 100644 --- a/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.php +++ b/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.php @@ -90,10 +90,10 @@ class Legacy implements Cryptinterface * @param string $string The string to decrypt * @param string $key The decryption key * - * @return string + * @return string|null * @since 3.2.0 **/ - public function decrypt(string $string, string $key): string + public function decrypt(string $string, string $key): ?string { // remove base 64 encoding $string = base64_decode($string); @@ -110,8 +110,11 @@ class Legacy implements Cryptinterface // set the password $this->aes->setPassword($key, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt'); - return $this->aes->decrypt($string); - } - + try { + return $this->aes->decrypt($string); + } catch (\Exception $ex) { + return null; + } + } } diff --git a/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.power b/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.power index 9940635..285cafc 100644 --- a/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.power +++ b/src/437af6b0-ca02-49d7-8739-4edfc8a9ccb0/code.power @@ -65,10 +65,10 @@ * @param string $string The string to decrypt * @param string $key The decryption key * - * @return string + * @return string|null * @since 3.2.0 **/ - public function decrypt(string $string, string $key): string + public function decrypt(string $string, string $key): ?string { // remove base 64 encoding $string = base64_decode($string); @@ -85,5 +85,9 @@ // set the password $this->aes->setPassword($key, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt'); - return $this->aes->decrypt($string); - } + try { + return $this->aes->decrypt($string); + } catch (\Exception $ex) { + return null; + } + } \ No newline at end of file diff --git a/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/README.md b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/README.md index afe5495..1d8cc56 100644 --- a/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/README.md +++ b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/README.md @@ -14,7 +14,8 @@ class Sftp #Gold { # KeyLoader $key # ?SftpClient $client # ?object $details - + __construct(KeyLoader $key) + # CMSApplication $app + + __construct(KeyLoader $key, ?CMSApplication $app = null) + set(object $details) : Sftp + move(string $localPath, string $fileName) : bool - connected() : bool diff --git a/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.php b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.php index d272460..27772b8 100644 --- a/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.php +++ b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.php @@ -12,6 +12,9 @@ namespace VDM\Joomla\Componentbuilder\Server; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Application\CMSApplication; use phpseclib3\Net\SFTP as SftpClient; use VDM\Joomla\Componentbuilder\Crypt\KeyLoader; use VDM\Joomla\Utilities\StringHelper; @@ -51,16 +54,26 @@ class Sftp implements Serverinterface **/ protected ?object $details = null; + /** + * Application object. + * + * @var CMSApplication + * @since 3.2.0 + **/ + protected CMSApplication $app; + /** * Constructor * * @param KeyLoader $key The key loader object. + * @param CMSApplication|null $app The app object. * * @since 3.2.0 */ - public function __construct(KeyLoader $key) + public function __construct(KeyLoader $key, ?CMSApplication $app = null) { $this->key = $key; + $this->app = $app ?: Factory::getApplication(); } /** @@ -106,10 +119,21 @@ class Sftp implements Serverinterface StringHelper::check($this->details->path) && $this->details->path !== '/') { - $path = '/' . trim((string) $this->details->path, '/'); + $path = trim((string) $this->details->path); + $path = '/' . trim($path, '/') . '/'; } - return $this->client->put($path . '/' . $fileName, $data); + try + { + return $this->client->put($path . trim($fileName), $data); + } + catch(\Exception $e) + { + $this->app->enqueueMessage( + Text::sprintf('COM_COMPONENTBUILDER_MOVING_OF_THE_S_FAILED', $fileName) . ': ' . $e->getMessage(), + 'Error' + ); + } } return false; @@ -147,24 +171,23 @@ class Sftp implements Serverinterface isset($this->details->username) && StringHelper::check($this->details->username)) { // insure the port is set - $port = (isset($this->details->port) && is_numeric($this->details->port) && $this->details->port > 0) - ? (int) $this->details->port : 22; + $port = (int)($this->details->port ?? 22); // open the connection $sftp = new SftpClient($this->details->host, $port); // set the passphrase if it exist - $passphrase = $this->details->secret ?? null; + $passphrase = (isset($this->details->secret) && StringHelper::check(trim($this->details->secret))) ? trim($this->details->secret) : false; // set the password if it exist - $password = $this->details->password ?? null; + $password = (isset($this->details->password) && StringHelper::check(trim($this->details->password))) ? trim($this->details->password) : false; // now login based on authentication type $key = null; switch($this->details->authentication) { case 1: // password - $key = $this->details->password ?? null; + $key = $password ?? null; $password = null; break; case 2: // private key file @@ -172,28 +195,77 @@ class Sftp implements Serverinterface if (isset($this->details->private) && StringHelper::check($this->details->private) && ($private_key = FileHelper::getContent($this->details->private, null)) !== null) { - $key = $this->key::load($private_key, $passphrase); + try + { + $key = $this->key::load(trim($private_key), $passphrase); + } + catch(\Exception $e) + { + $this->app->enqueueMessage( + Text::_('COM_COMPONENTBUILDER_LOADING_THE_PRIVATE_KEY_FILE_FAILED') . ': ' . $e->getMessage(), + 'Error' + ); + $key = null; + } } break; case 4: // private key field case 5: // both password and private key field if (isset($this->details->private_key) && StringHelper::check($this->details->private_key)) { - $key = $this->key::load($this->details->private_key, $passphrase); + try + { + $key = $this->key::load(trim($this->details->private_key), $passphrase); + } + catch(\Exception $e) + { + $this->app->enqueueMessage( + Text::_('COM_COMPONENTBUILDER_LOADING_THE_PRIVATE_KEY_TEXT_FAILED') . ': ' . $e->getMessage(), + 'Error' + ); + $key = null; + } } break; } + // remove any null bites from the username + $this->details->username = trim($this->details->username); + // login - if ((!empty($key) && !empty($password) && $sftp->login($this->details->username, $key, $password)) || - (!empty($key) && $sftp->login($this->details->username, $key))) + if (!empty($key) && !empty($password)) { - return $sftp; + try + { + $sftp->login($this->details->username, $key, $password); + return $sftp; + } + catch(\Exception $e) + { + $this->app->enqueueMessage( + Text::_('COM_COMPONENTBUILDER_LOGIN_FAILED') . ': ' . $e->getMessage(), + 'Error' + ); + } + } + elseif (!empty($key)) + { + try + { + $sftp->login($this->details->username, $key); + return $sftp; + } + catch(\Exception $e) + { + $this->app->enqueueMessage( + Text::_('COM_COMPONENTBUILDER_LOGIN_FAILED') . ': ' . $e->getMessage(), + 'Error' + ); + } } } return null; - } - + } } diff --git a/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.power b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.power index dd9fd6f..4adfe70 100644 --- a/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.power +++ b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/code.power @@ -22,16 +22,26 @@ **/ protected ?object $details = null; + /** + * Application object. + * + * @var CMSApplication + * @since 3.2.0 + **/ + protected CMSApplication $app; + /** * Constructor * * @param KeyLoader $key The key loader object. + * @param CMSApplication|null $app The app object. * * @since 3.2.0 */ - public function __construct(KeyLoader $key) + public function __construct(KeyLoader $key, ?CMSApplication $app = null) { $this->key = $key; + $this->app = $app ?: Factory::getApplication(); } /** @@ -77,10 +87,21 @@ StringHelper::check($this->details->path) && $this->details->path !== '/') { - $path = '/' . trim((string) $this->details->path, '/'); + $path = trim((string) $this->details->path); + $path = '/' . trim($path, '/') . '/'; } - return $this->client->put($path . '/' . $fileName, $data); + try + { + return $this->client->put($path . trim($fileName), $data); + } + catch(\Exception $e) + { + $this->app->enqueueMessage( + Text::sprintf('Moving of the %s failed', $fileName) . ': ' . $e->getMessage(), + 'Error' + ); + } } return false; @@ -118,24 +139,23 @@ isset($this->details->username) && StringHelper::check($this->details->username)) { // insure the port is set - $port = (isset($this->details->port) && is_numeric($this->details->port) && $this->details->port > 0) - ? (int) $this->details->port : 22; + $port = (int)($this->details->port ?? 22); // open the connection $sftp = new SftpClient($this->details->host, $port); // set the passphrase if it exist - $passphrase = $this->details->secret ?? null; + $passphrase = (isset($this->details->secret) && StringHelper::check(trim($this->details->secret))) ? trim($this->details->secret) : false; // set the password if it exist - $password = $this->details->password ?? null; + $password = (isset($this->details->password) && StringHelper::check(trim($this->details->password))) ? trim($this->details->password) : false; // now login based on authentication type $key = null; switch($this->details->authentication) { case 1: // password - $key = $this->details->password ?? null; + $key = $password ?? null; $password = null; break; case 2: // private key file @@ -143,25 +163,75 @@ if (isset($this->details->private) && StringHelper::check($this->details->private) && ($private_key = FileHelper::getContent($this->details->private, null)) !== null) { - $key = $this->key::load($private_key, $passphrase); + try + { + $key = $this->key::load(trim($private_key), $passphrase); + } + catch(\Exception $e) + { + $this->app->enqueueMessage( + Text::_('Loading the private key file failed') . ': ' . $e->getMessage(), + 'Error' + ); + $key = null; + } } break; case 4: // private key field case 5: // both password and private key field if (isset($this->details->private_key) && StringHelper::check($this->details->private_key)) { - $key = $this->key::load($this->details->private_key, $passphrase); + try + { + $key = $this->key::load(trim($this->details->private_key), $passphrase); + } + catch(\Exception $e) + { + $this->app->enqueueMessage( + Text::_('Loading the private key text failed') . ': ' . $e->getMessage(), + 'Error' + ); + $key = null; + } } break; } + // remove any null bites from the username + $this->details->username = trim($this->details->username); + // login - if ((!empty($key) && !empty($password) && $sftp->login($this->details->username, $key, $password)) || - (!empty($key) && $sftp->login($this->details->username, $key))) + if (!empty($key) && !empty($password)) { - return $sftp; + try + { + $sftp->login($this->details->username, $key, $password); + return $sftp; + } + catch(\Exception $e) + { + $this->app->enqueueMessage( + Text::_('Login failed') . ': ' . $e->getMessage(), + 'Error' + ); + } + } + elseif (!empty($key)) + { + try + { + $sftp->login($this->details->username, $key); + return $sftp; + } + catch(\Exception $e) + { + $this->app->enqueueMessage( + Text::_('Login failed') . ': ' . $e->getMessage(), + 'Error' + ); + } } } return null; - } + } \ No newline at end of file diff --git a/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/settings.json b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/settings.json index cfe41f2..f6a0787 100644 --- a/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/settings.json +++ b/src/490b6aa5-5de7-4be5-a61a-f634f6e004c0/settings.json @@ -1,5 +1,5 @@ { - "add_head": "0", + "add_head": "1", "add_licensing_template": "2", "extends": "0", "guid": "490b6aa5-5de7-4be5-a61a-f634f6e004c0", @@ -32,7 +32,7 @@ "namespace": "VDM\\Joomla\\Componentbuilder.Server.Sftp", "description": "Sftp Class\r\n\r\n@since 3.2.0", "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", - "head": "", + "head": "use Joomla\\CMS\\Factory;\r\nuse Joomla\\CMS\\Language\\Text;\r\nuse Joomla\\CMS\\Application\\CMSApplication;", "composer": { "composer0": { "access_point": "phpseclib3\/vendor\/autoload.php", diff --git a/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/README.md b/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/README.md index 8e5d4c1..d9d4e30 100644 --- a/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/README.md +++ b/src/6da44dff-a221-4f22-b9d9-b2fc2a724b4b/README.md @@ -6,7 +6,16 @@ ██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ ``` -> Error adding class diagram +# class KeyLoader (Details) +> namespace: **VDM\Joomla\Componentbuilder\Crypt** +> extends: **PublicKeyLoader** +```uml +@startuml +class KeyLoader #Gold { +} + +@enduml +``` --- ``` diff --git a/src/a25c82c8-14c2-40df-adae-f832709ab49b/README.md b/src/a25c82c8-14c2-40df-adae-f832709ab49b/README.md index 907ab40..2185778 100644 --- a/src/a25c82c8-14c2-40df-adae-f832709ab49b/README.md +++ b/src/a25c82c8-14c2-40df-adae-f832709ab49b/README.md @@ -16,7 +16,7 @@ class Aes #Gold { # int $size + __construct(BASEAES $aes, Random $random) + encrypt(string $string, string $key) : string - + decrypt(string $string, string $key) : string + + decrypt(string $string, string $key) : ?string } note right of Aes::__construct @@ -36,7 +36,7 @@ note right of Aes::decrypt Decrypt a string as needed since: 3.2.0 - return: string + return: ?string end note @enduml diff --git a/src/a25c82c8-14c2-40df-adae-f832709ab49b/code.php b/src/a25c82c8-14c2-40df-adae-f832709ab49b/code.php index e940f57..893691e 100644 --- a/src/a25c82c8-14c2-40df-adae-f832709ab49b/code.php +++ b/src/a25c82c8-14c2-40df-adae-f832709ab49b/code.php @@ -12,7 +12,9 @@ namespace VDM\Joomla\Componentbuilder\Crypt; + use phpseclib3\Crypt\AES as BASEAES; +use phpseclib3\Exception\BadDecryptionException; use VDM\Joomla\Componentbuilder\Crypt\Random; use VDM\Joomla\Componentbuilder\Interfaces\Cryptinterface; @@ -101,10 +103,10 @@ class Aes implements Cryptinterface * @param string $string The string to decrypt * @param string $key The decryption key * - * @return string + * @return string|null * @since 3.2.0 **/ - public function decrypt(string $string, string $key): string + public function decrypt(string $string, string $key): ?string { // we get the IV length $iv_length = (int) $this->aes->getBlockLength() >> 3; @@ -124,8 +126,11 @@ class Aes implements Cryptinterface // set the password $this->aes->setPassword($key, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt'); - return $this->aes->decrypt($string); - } - + try { + return $this->aes->decrypt($string); + } catch (\Exception $ex) { + return null; + } + } } diff --git a/src/a25c82c8-14c2-40df-adae-f832709ab49b/code.power b/src/a25c82c8-14c2-40df-adae-f832709ab49b/code.power index 0b8b103..2c869c0 100644 --- a/src/a25c82c8-14c2-40df-adae-f832709ab49b/code.power +++ b/src/a25c82c8-14c2-40df-adae-f832709ab49b/code.power @@ -75,10 +75,10 @@ * @param string $string The string to decrypt * @param string $key The decryption key * - * @return string + * @return string|null * @since 3.2.0 **/ - public function decrypt(string $string, string $key): string + public function decrypt(string $string, string $key): ?string { // we get the IV length $iv_length = (int) $this->aes->getBlockLength() >> 3; @@ -98,5 +98,9 @@ // set the password $this->aes->setPassword($key, 'pbkdf2', 'sha256', 'VastDevelopmentMethod/salt'); - return $this->aes->decrypt($string); - } + try { + return $this->aes->decrypt($string); + } catch (\Exception $ex) { + return null; + } + } \ No newline at end of file diff --git a/src/a25c82c8-14c2-40df-adae-f832709ab49b/settings.json b/src/a25c82c8-14c2-40df-adae-f832709ab49b/settings.json index 4f54f93..83e4158 100644 --- a/src/a25c82c8-14c2-40df-adae-f832709ab49b/settings.json +++ b/src/a25c82c8-14c2-40df-adae-f832709ab49b/settings.json @@ -1,5 +1,5 @@ { - "add_head": "0", + "add_head": "1", "add_licensing_template": "2", "extends": "0", "guid": "a25c82c8-14c2-40df-adae-f832709ab49b", @@ -27,6 +27,9 @@ "namespace": { "namespace0": { "use": "phpseclib3\\Crypt\\AES as BASEAES" + }, + "namespace1": { + "use": "phpseclib3\\Exception\\BadDecryptionException" } } } diff --git a/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/README.md b/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/README.md index 8e5d4c1..32f02e8 100644 --- a/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/README.md +++ b/src/c46a42b4-b0d3-48e7-a6fa-af0399e1e66c/README.md @@ -6,7 +6,16 @@ ██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ ``` -> Error adding class diagram +# class Random (Details) +> namespace: **VDM\Joomla\Componentbuilder\Crypt** +> extends: **CryptRandom** +```uml +@startuml +class Random #Gold { +} + +@enduml +``` --- ``` diff --git a/src/d357e796-9f22-4615-9ebc-970b42cbd280/README.md b/src/d357e796-9f22-4615-9ebc-970b42cbd280/README.md index 18106a7..b9ac7aa 100644 --- a/src/d357e796-9f22-4615-9ebc-970b42cbd280/README.md +++ b/src/d357e796-9f22-4615-9ebc-970b42cbd280/README.md @@ -19,7 +19,7 @@ class Crypt #Gold { # array $passwords + __construct(FOF $fof, Aes $aes, ...) + encrypt(string $string, string $method, ...) : string - + decrypt(string $string, string $method, ...) : string + + decrypt(string $string, string $method, ...) : ?string + exist(string $method) : bool - getClassName(string $method) : ?string - getClassNameFromRegistry(string $method) : ?string @@ -57,7 +57,7 @@ note right of Crypt::decrypt Decrypt a string as needed since: 3.2.0 - return: string + return: ?string arguments: string $string diff --git a/src/d357e796-9f22-4615-9ebc-970b42cbd280/code.php b/src/d357e796-9f22-4615-9ebc-970b42cbd280/code.php index 27ad5fb..f126084 100644 --- a/src/d357e796-9f22-4615-9ebc-970b42cbd280/code.php +++ b/src/d357e796-9f22-4615-9ebc-970b42cbd280/code.php @@ -127,11 +127,11 @@ class Crypt * @param string $method The encryption method to use * @param string|null $default The default password * - * @return string + * @return string|null * @since 3.2.0 **/ public function decrypt(string $string, string $method, - ?string $default = null): string + ?string $default = null): ?string { if (($password = $this->getPassword($method, $default)) !== null && ($name = $this->getClassName($method)) !== null) @@ -139,7 +139,7 @@ class Crypt return $this->{$name}->decrypt($string, $password); } - return $string; + return null; } /** @@ -279,7 +279,6 @@ class Crypt } return $method; - } - + } } diff --git a/src/d357e796-9f22-4615-9ebc-970b42cbd280/code.power b/src/d357e796-9f22-4615-9ebc-970b42cbd280/code.power index 19e0e6e..957768d 100644 --- a/src/d357e796-9f22-4615-9ebc-970b42cbd280/code.power +++ b/src/d357e796-9f22-4615-9ebc-970b42cbd280/code.power @@ -98,11 +98,11 @@ * @param string $method The encryption method to use * @param string|null $default The default password * - * @return string + * @return string|null * @since 3.2.0 **/ public function decrypt(string $string, string $method, - ?string $default = null): string + ?string $default = null): ?string { if (($password = $this->getPassword($method, $default)) !== null && ($name = $this->getClassName($method)) !== null) @@ -110,7 +110,7 @@ return $this->{$name}->decrypt($string, $password); } - return $string; + return null; } /** @@ -250,4 +250,4 @@ } return $method; - } + } \ No newline at end of file diff --git a/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/README.md b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/README.md index 7e869b9..488d839 100644 --- a/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/README.md +++ b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/README.md @@ -11,22 +11,10 @@ ```uml @startuml class FOF #Gold { - # AES $aes - # Random $random - # int $size - + __construct(AES $aes, Random $random) + encrypt(string $string, string $key) : string - + decrypt(string $string, string $key) : string - # getExpandedKey(string $key, int $blockSize, ...) : string - # resizeKey(string $key, int $size) : ?string + + decrypt(string $string, string $key) : ?string } -note right of FOF::__construct - Constructor - - since: 3.2.0 -end note - note right of FOF::encrypt Encrypt a string as needed @@ -37,33 +25,6 @@ end note note right of FOF::decrypt Decrypt a string as needed - since: 3.2.0 - return: string -end note - -note right of FOF::getExpandedKey - Function taken from FOFEncryptAes -changed a little but basically the same -to ensure we get the same passwords (not ideal) -we should use `$this->aes->setPassword(...)` instead -but can't for backwards compatibility issues with already encrypted string - - since: 3.2.0 - return: string - - arguments: - string $key - int $blockSize - string $iv -end note - -note right of FOF::resizeKey - Function taken from FOFEncryptAes -changed a little but basically the same -to ensure we get the same passwords (not ideal) -we should use `$this->aes->setPassword(...)` instead -but can't for backwards compatibility issues with already encrypted string - since: 3.2.0 return: ?string end note diff --git a/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.php b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.php index f6493d8..d964692 100644 --- a/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.php +++ b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.php @@ -12,59 +12,17 @@ namespace VDM\Joomla\Componentbuilder\Crypt; -use phpseclib3\Crypt\AES; -use VDM\Joomla\Componentbuilder\Crypt\Random; +use VDM\Joomla\FOF\Encrypt\AES; use VDM\Joomla\Componentbuilder\Interfaces\Cryptinterface; /** - * Replacement Class for FOFEncryptAes + * Temp Class for FOFEncryptAes * * @since 3.2.0 */ class FOF implements Cryptinterface { - /** - * The Aes class - * - * @var AES - * @since 3.2.0 - */ - protected AES $aes; - - /** - * The Random class - * - * @var Random - * @since 3.2.0 - */ - protected Random $random; - - /** - * The block size - * - * @var int - * @since 3.2.0 - */ - protected int $size = 128; - - /** - * Constructor - * - * @param AES $aes The Aes class - * @param Random $random The Random class - * - * @since 3.2.0 - */ - public function __construct(AES $aes, Random $random) - { - $this->aes = $aes; - $this->random = $random; - - // we set the length once - $this->aes->setKeyLength($this->size); - } - /** * Encrypt a string as needed * @@ -76,19 +34,10 @@ class FOF implements Cryptinterface **/ public function encrypt(string $string, string $key): string { - // we get the IV length - $iv_length = (int) $this->aes->getBlockLength() >> 3; + // Get the encryption object. + $aes = new Aes($key, 128); - // get the IV value - $iv = $this->random::string($iv_length); - // Load the IV - $this->aes->setIV($iv); - - // load the key - $this->aes->setKey($this->getExpandedKey($key, $iv_length, $iv)); - - // encrypt the string, and base 64 encode the result - return base64_encode($iv . $this->aes->encrypt($string)); + return $aes->decryptString($string); } /** @@ -97,108 +46,19 @@ class FOF implements Cryptinterface * @param string $string The string to decrypt * @param string $key The decryption key * - * @return string + * @return string|null * @since 3.2.0 **/ - public function decrypt(string $string, string $key): string + public function decrypt(string $string, string $key): ?string { - // we get the IV length - $iv_length = (int) $this->aes->getBlockLength() >> 3; + // Get the encryption object. + $aes = new Aes($key, 128); - // remove base 64 encoding - $string = base64_decode($string); - - // get the IV - $iv = substr($string, 0, $iv_length); - // remove the IV - $string = substr($string, $iv_length); - - // set the key - $this->aes->setKey($this->getExpandedKey($key, $iv_length, $iv)); - - // set the IV - $this->aes->setIV($iv); - - return $this->aes->decrypt($string); - } - - /** - * Function taken from FOFEncryptAes - * changed a little but basically the same - * to ensure we get the same passwords (not ideal) - * we should use `$this->aes->setPassword(...)` instead - * but can't for backwards compatibility issues with already encrypted string - * - * @param string $key The key to expand - * @param int $blockSize The size of the block - * @param string $iv The IV used - * - * @return string - * @since 3.2.0 - */ - protected function getExpandedKey(string $key, int $blockSize, string $iv): string - { - $pass_length = strlen($key); - - if (function_exists('mb_strlen')) - { - $pass_length = mb_strlen($key, 'ASCII'); - } - - if ($pass_length != $blockSize) - { - $iterations = 1000; - $salt = $this->resizeKey($iv, 16); - $key = hash_pbkdf2('sha256', $key, $salt, $iterations, $blockSize, true); - } - - return $key; - } - - /** - * Function taken from FOFEncryptAes - * changed a little but basically the same - * to ensure we get the same passwords (not ideal) - * we should use `$this->aes->setPassword(...)` instead - * but can't for backwards compatibility issues with already encrypted string - * - * @param string $key The key to resize - * @param int $size The size of the block - * - * @return string|null - * @since 3.2.0 - */ - protected function resizeKey(string $key, int $size): ?string - { - if (empty($key)) - { + try { + return $aes->decryptString($string); + } catch (\Exception $ex) { return null; } - - $key_length = strlen($key); - - if (function_exists('mb_strlen')) - { - $key_length = mb_strlen($key, 'ASCII'); - } - - if ($key_length == $size) - { - return $key; - } - - if ($key_length > $size) - { - if (function_exists('mb_substr')) - { - return mb_substr($key, 0, $size, 'ASCII'); - } - - return substr($key, 0, $size); - } - - return $key . str_repeat("\0", ($size - $key_length)); - } - + } } diff --git a/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.power b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.power index 3438b56..52b997f 100644 --- a/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.power +++ b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/code.power @@ -1,44 +1,3 @@ - /** - * The Aes class - * - * @var AES - * @since 3.2.0 - */ - protected AES $aes; - - /** - * The Random class - * - * @var Random - * @since 3.2.0 - */ - protected Random $random; - - /** - * The block size - * - * @var int - * @since 3.2.0 - */ - protected int $size = 128; - - /** - * Constructor - * - * @param AES $aes The Aes class - * @param Random $random The Random class - * - * @since 3.2.0 - */ - public function __construct(AES $aes, Random $random) - { - $this->aes = $aes; - $this->random = $random; - - // we set the length once - $this->aes->setKeyLength($this->size); - } - /** * Encrypt a string as needed * @@ -50,19 +9,10 @@ **/ public function encrypt(string $string, string $key): string { - // we get the IV length - $iv_length = (int) $this->aes->getBlockLength() >> 3; + // Get the encryption object. + $aes = new Aes($key, 128); - // get the IV value - $iv = $this->random::string($iv_length); - // Load the IV - $this->aes->setIV($iv); - - // load the key - $this->aes->setKey($this->getExpandedKey($key, $iv_length, $iv)); - - // encrypt the string, and base 64 encode the result - return base64_encode($iv . $this->aes->encrypt($string)); + return $aes->decryptString($string); } /** @@ -71,105 +21,17 @@ * @param string $string The string to decrypt * @param string $key The decryption key * - * @return string + * @return string|null * @since 3.2.0 **/ - public function decrypt(string $string, string $key): string + public function decrypt(string $string, string $key): ?string { - // we get the IV length - $iv_length = (int) $this->aes->getBlockLength() >> 3; + // Get the encryption object. + $aes = new Aes($key, 128); - // remove base 64 encoding - $string = base64_decode($string); - - // get the IV - $iv = substr($string, 0, $iv_length); - // remove the IV - $string = substr($string, $iv_length); - - // set the key - $this->aes->setKey($this->getExpandedKey($key, $iv_length, $iv)); - - // set the IV - $this->aes->setIV($iv); - - return $this->aes->decrypt($string); - } - - /** - * Function taken from FOFEncryptAes - * changed a little but basically the same - * to ensure we get the same passwords (not ideal) - * we should use `$this->aes->setPassword(...)` instead - * but can't for backwards compatibility issues with already encrypted string - * - * @param string $key The key to expand - * @param int $blockSize The size of the block - * @param string $iv The IV used - * - * @return string - * @since 3.2.0 - */ - protected function getExpandedKey(string $key, int $blockSize, string $iv): string - { - $pass_length = strlen($key); - - if (function_exists('mb_strlen')) - { - $pass_length = mb_strlen($key, 'ASCII'); - } - - if ($pass_length != $blockSize) - { - $iterations = 1000; - $salt = $this->resizeKey($iv, 16); - $key = hash_pbkdf2('sha256', $key, $salt, $iterations, $blockSize, true); - } - - return $key; - } - - /** - * Function taken from FOFEncryptAes - * changed a little but basically the same - * to ensure we get the same passwords (not ideal) - * we should use `$this->aes->setPassword(...)` instead - * but can't for backwards compatibility issues with already encrypted string - * - * @param string $key The key to resize - * @param int $size The size of the block - * - * @return string|null - * @since 3.2.0 - */ - protected function resizeKey(string $key, int $size): ?string - { - if (empty($key)) - { + try { + return $aes->decryptString($string); + } catch (\Exception $ex) { return null; } - - $key_length = strlen($key); - - if (function_exists('mb_strlen')) - { - $key_length = mb_strlen($key, 'ASCII'); - } - - if ($key_length == $size) - { - return $key; - } - - if ($key_length > $size) - { - if (function_exists('mb_substr')) - { - return mb_substr($key, 0, $size, 'ASCII'); - } - - return substr($key, 0, $size); - } - - return $key . str_repeat("\0", ($size - $key_length)); - } + } \ No newline at end of file diff --git a/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/settings.json b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/settings.json index 1cf7e3e..e460ca5 100644 --- a/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/settings.json +++ b/src/e98b4edc-25b9-49d7-98a0-e42ad3b75efe/settings.json @@ -13,22 +13,13 @@ "type": "class", "use_selection": { "use_selection0": { - "use": "c46a42b4-b0d3-48e7-a6fa-af0399e1e66c", + "use": "99175f6d-dba8-4086-8a65-5c4ec175e61d", "as": "default" } }, "namespace": "VDM\\Joomla\\Componentbuilder.Crypt.FOF", - "description": "Replacement Class for FOFEncryptAes\r\n\r\n@since 3.2.0", + "description": "Temp Class for FOFEncryptAes\r\n\r\n@since 3.2.0", "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", "head": "", - "composer": { - "composer0": { - "access_point": "phpseclib3\/vendor\/autoload.php", - "namespace": { - "namespace0": { - "use": "phpseclib3\\Crypt\\AES" - } - } - } - } + "composer": "" } \ No newline at end of file diff --git a/src/f37ee8b7-2909-4319-bdf8-769bd7635490/README.md b/src/f37ee8b7-2909-4319-bdf8-769bd7635490/README.md index e13b232..69f2fc8 100644 --- a/src/f37ee8b7-2909-4319-bdf8-769bd7635490/README.md +++ b/src/f37ee8b7-2909-4319-bdf8-769bd7635490/README.md @@ -8,6 +8,7 @@ ``` # class Load (Details) > namespace: **VDM\Joomla\Componentbuilder\Server\Model** +> extends: **Model** ```uml @startuml class Load #Gold {