From 3bad63290d2b73649d0ffc860999332b9dc96740 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 29 Mar 2011 16:31:30 +0000 Subject: [PATCH] Swapped code, moved/renamed classes and interfaces: - Swapped code between TestUnitSource and CryptoRandomUnitMessageHelper, the helper is now encapsulating and the source is now a source for the helper - Introduced generic Helper interface to existing helper interfaces (from latest 'core' changes) - Renamed/moved some classes/interfaces - TODOs.txt updated --- .gitattributes | 3 + application/hub/config.php | 2 +- .../helper/hub/class_HelpableHub.php | 2 +- .../hub/interfaces/helper/messages/.htaccess | 1 + .../helper/messages/class_MessageHelper.php | 28 +++++++ .../messages/class_MessageHelper.php | 27 +------ .../tcp/class_TcpConnectionHelper.php | 2 +- .../udp/class_UdpConnectionHelper.php | 2 +- .../class_CryptoRandomMessageHelper.php | 76 +------------------ .../class_CryptoRandomUnitMessageHelper.php | 70 +++++++++++++++++ .../hub/main/producer/class_BaseProducer.php | 28 +------ .../class_CruncherTestUnitProducer.php | 8 +- .../source/units/class_TestUnitSource.php | 27 ++++--- docs/TODOs.txt | 12 ++- 14 files changed, 137 insertions(+), 151 deletions(-) create mode 100644 application/hub/interfaces/helper/messages/.htaccess create mode 100644 application/hub/interfaces/helper/messages/class_MessageHelper.php create mode 100644 application/hub/main/helper/messages/crypto/class_CryptoRandomUnitMessageHelper.php diff --git a/.gitattributes b/.gitattributes index 420e1e446..463b9931a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -46,6 +46,8 @@ application/hub/interfaces/handler/task/class_HandleableTask.php -text svneol=un application/hub/interfaces/helper/.htaccess -text svneol=unset#text/plain application/hub/interfaces/helper/hub/.htaccess -text svneol=unset#text/plain application/hub/interfaces/helper/hub/class_HelpableHub.php svneol=native#text/plain +application/hub/interfaces/helper/messages/.htaccess svneol=native#text/plain +application/hub/interfaces/helper/messages/class_MessageHelper.php svneol=native#text/plain application/hub/interfaces/listener/.htaccess -text svneol=unset#text/plain application/hub/interfaces/listener/class_Listenable.php -text svneol=unset#text/plain application/hub/interfaces/lists/.htaccess -text svneol=unset#text/plain @@ -291,6 +293,7 @@ application/hub/main/helper/messages/class_ -text application/hub/main/helper/messages/class_BaseMessageHelper.php svneol=native#text/plain application/hub/main/helper/messages/crypto/.htaccess svneol=native#text/plain application/hub/main/helper/messages/crypto/class_CryptoRandomMessageHelper.php svneol=native#text/plain +application/hub/main/helper/messages/crypto/class_CryptoRandomUnitMessageHelper.php svneol=native#text/plain application/hub/main/helper/work_units/.htaccess svneol=native#text/plain application/hub/main/helper/work_units/class_ -text application/hub/main/helper/work_units/class_BaseWorkUnitHelper.php svneol=native#text/plain diff --git a/application/hub/config.php b/application/hub/config.php index 88fefc51f..50351b2a3 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -574,7 +574,7 @@ $cfg->setConfigEntry('random_secret_key_length', 8); $cfg->setConfigEntry('test_unit_source_class', 'TestUnitSource'); // CFG: CRYPTO-RANDOM-MESSAGE-HELPER-CLASS -$cfg->setConfigEntry('crypto_random_message_helper_class', 'CryptoRandomMessageHelper'); +$cfg->setConfigEntry('crypto_random_message_helper_class', 'CryptoRandomUnitMessageHelper'); // [EOF] ?> diff --git a/application/hub/interfaces/helper/hub/class_HelpableHub.php b/application/hub/interfaces/helper/hub/class_HelpableHub.php index 5ee605b3c..4fa719ff5 100644 --- a/application/hub/interfaces/helper/hub/class_HelpableHub.php +++ b/application/hub/interfaces/helper/hub/class_HelpableHub.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface HelpableHub extends FrameworkInterface { +interface HelpableHub extends Helper { /** * Loads the descriptor XML file * diff --git a/application/hub/interfaces/helper/messages/.htaccess b/application/hub/interfaces/helper/messages/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/helper/messages/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/helper/messages/class_MessageHelper.php b/application/hub/interfaces/helper/messages/class_MessageHelper.php new file mode 100644 index 000000000..81057a706 --- /dev/null +++ b/application/hub/interfaces/helper/messages/class_MessageHelper.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +interface MessageHelper extends Helper { +} + +// [EOF] +?> diff --git a/application/hub/interfaces/messages/class_MessageHelper.php b/application/hub/interfaces/messages/class_MessageHelper.php index 987d10dcf..f551ef47b 100644 --- a/application/hub/interfaces/messages/class_MessageHelper.php +++ b/application/hub/interfaces/messages/class_MessageHelper.php @@ -1,28 +1,3 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -interface MessageHelper extends FrameworkInterface { -} - -// [EOF] +// @DEPRECATED ?> diff --git a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php index 0a820872f..9d6b55015 100644 --- a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php +++ b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php @@ -22,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class TcpConnectionHelper extends BaseConnectionHelper { +class TcpConnectionHelper extends BaseConnectionHelper implements Helper { /** * Protected constructor * diff --git a/application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php b/application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php index 0e70ca2c9..01761f96a 100644 --- a/application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php +++ b/application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php @@ -22,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class UdpConnectionHelper extends BaseConnectionHelper { +class UdpConnectionHelper extends BaseConnectionHelper implements Helper { /** * Protected constructor * diff --git a/application/hub/main/helper/messages/crypto/class_CryptoRandomMessageHelper.php b/application/hub/main/helper/messages/crypto/class_CryptoRandomMessageHelper.php index 758006d52..f551ef47b 100644 --- a/application/hub/main/helper/messages/crypto/class_CryptoRandomMessageHelper.php +++ b/application/hub/main/helper/messages/crypto/class_CryptoRandomMessageHelper.php @@ -1,77 +1,3 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class CryptoRandomMessageHelper extends BaseMessageHelper implements MessageHelper { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this class - * - * @return $messageInstance An instance of a UnitHelper class - */ - public final static function createCryptoRandomMessageHelper () { - // Get new instance - $messageInstance = new CryptoRandomMessageHelper(); - - // Create a RNG instance and set it in this class - $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class'); - $messageInstance->setRngInstance($rngInstance); - - // And also a crypto instance (for our encrypted messages) - $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class'); - $messageInstance->setCryptoInstance($cryptoInstance); - - // Return the prepared instance - return $messageInstance; - } - - /** - * Generates an encrypted random message - * - * @return $encryptedMessage The encrypted random message - */ - public function generateRandomMessage () { - // Get a very secret message by encoding and random string with BASE64 - $secretMessage = base64_encode($this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('random_secret_message_length'))); - - // Get a random, secret key - $secretKey = $this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('random_secret_key_length')); - - // Now encrypt the message with our key and a good (strong) cipher - $encryptedMessage = base64_encode($this->getCryptoInstance()->encryptString($secretMessage, $secretKey)); - - // Return it - return $encryptedMessage; - } -} - -// [EOF] +// @DEPRECATED ?> diff --git a/application/hub/main/helper/messages/crypto/class_CryptoRandomUnitMessageHelper.php b/application/hub/main/helper/messages/crypto/class_CryptoRandomUnitMessageHelper.php new file mode 100644 index 000000000..9ec203cb7 --- /dev/null +++ b/application/hub/main/helper/messages/crypto/class_CryptoRandomUnitMessageHelper.php @@ -0,0 +1,70 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class CryptoRandomUnitMessageHelper extends BaseMessageHelper implements MessageHelper { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $sourceType Type of the source + * @return $messageInstance An instance of a UnitHelper class + */ + public final static function createCryptoRandomUnitMessageHelper ($sourceType) { + // Get new instance + $messageInstance = new CryptoRandomUnitMessageHelper(); + + // Generate a source instance + $sourceInstance = UnitSourceFactory::createUnitSourceInstance($sourceType); + + // Set the source instance + $messageInstance->setSourceInstance($sourceInstance); + + // Return the prepared instance + return $messageInstance; + } + + /** + * Generates an encrypted random message + * + * @return $encryptedMessage The encrypted random message + */ + public function generateRandomMessage () { + // Get the message from our source + $encryptedMessage = $this->getSourceInstance()->generateMessageFromSource(); + + // Return it + return $encryptedMessage; + } +} + +// [EOF] +?> diff --git a/application/hub/main/producer/class_BaseProducer.php b/application/hub/main/producer/class_BaseProducer.php index 81c21284a..920c38b66 100644 --- a/application/hub/main/producer/class_BaseProducer.php +++ b/application/hub/main/producer/class_BaseProducer.php @@ -27,11 +27,6 @@ abstract class BaseProducer extends BaseFrameworkSystem { */ private $outgoingQueueInstance = null; - /** - * Every procuded item/unit/etc. usually have a source - */ - private $sourceInstance = null; - /** * Protected constructor * @@ -55,7 +50,7 @@ abstract class BaseProducer extends BaseFrameworkSystem { * @param $outgoingQueueInstance The out-going work queue instance * @return void */ - private function setOutgoingQueueInstance (Stackable $outgoingQueueInstance) { + private final function setOutgoingQueueInstance (Stackable $outgoingQueueInstance) { $this->outgoingQueueInstance = $outgoingQueueInstance; } @@ -64,29 +59,10 @@ abstract class BaseProducer extends BaseFrameworkSystem { * * @param $outgoingQueueInstance The out-going work queue instance */ - protected function getOutgoingQueueInstance () { + protected final function getOutgoingQueueInstance () { return $this->outgoingQueueInstance; } - /** - * Setter for a Sourceable instance - * - * @param $sourceInstance The Sourceable instance - * @return void - */ - protected function setSourceInstance (Sourceable $sourceInstance) { - $this->sourceInstance = $sourceInstance; - } - - /** - * Getter for a Sourceable instance - * - * @param $sourceInstance The Sourceable instance - */ - protected function getSourceInstance () { - return $this->sourceInstance; - } - /** * Initializes this producer, this method must be overwritten. * diff --git a/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php b/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php index f735b6be6..0f2b55b73 100644 --- a/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php +++ b/application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php @@ -41,11 +41,11 @@ class CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer, // Get new instance $producerInstance = new CruncherTestUnitProducer(); - // Test units have a 'test' source - $sourceInstance = UnitSourceFactory::createUnitSourceInstance('test'); + // Test units have a helper class that wraps the source + $helperInstance = ObjectFactory::createObjectByConfiguredName('crypto_random_message_helper_class', array('test')); // So set it in the producer - $producerInstance->setSourceInstance($sourceInstance); + $producerInstance->setHelperInstance($helperInstance); // Return the prepared instance return $producerInstance; @@ -99,7 +99,7 @@ class CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer, $this->debugInstance(); } else { // Get an encrypted, random message from our source - $encryptedMessage = $this->getSourceInstance()->generateMessageFromSource(); + $encryptedMessage = $this->getHelperInstance()->generateRandomMessage(); die($encryptedMessage."\n"); } } diff --git a/application/hub/main/source/units/class_TestUnitSource.php b/application/hub/main/source/units/class_TestUnitSource.php index 8aaac2f4e..804b06c2e 100644 --- a/application/hub/main/source/units/class_TestUnitSource.php +++ b/application/hub/main/source/units/class_TestUnitSource.php @@ -22,11 +22,6 @@ * along with this program. If not, see . */ class TestUnitSource extends BaseSource implements Sourceable { - /** - * Message helper instance - */ - private $messageInstance = null; - /** * Protected constructor * @@ -46,6 +41,14 @@ class TestUnitSource extends BaseSource implements Sourceable { // Get new instance $sourceInstance = new TestUnitSource(); + // Create a RNG instance and set it in this class + $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class'); + $sourceInstance->setRngInstance($rngInstance); + + // And also a crypto instance (for our encrypted messages) + $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class'); + $sourceInstance->setCryptoInstance($cryptoInstance); + // Return the prepared instance return $sourceInstance; } @@ -56,14 +59,14 @@ class TestUnitSource extends BaseSource implements Sourceable { * @return $encryptedMessage The encrypted random message */ public function generateMessageFromSource () { - // Is the instance set? - if (is_null($this->messageInstance)) { - // No, then create a new instance - $this->messageInstance = ObjectFactory::createObjectByConfiguredName('crypto_random_message_helper_class'); - } // END - if + // Get a very secret message by encoding and random string with BASE64 + $secretMessage = base64_encode($this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('random_secret_message_length'))); + + // Get a random, secret key + $secretKey = $this->getRngInstance()->randomString($this->getConfigInstance()->getConfigEntry('random_secret_key_length')); - // Get the message from the message helper - $encryptedMessage = $this->messageInstance->generateRandomMessage(); + // Now encrypt the message with our key and a good (strong) cipher + $encryptedMessage = base64_encode($this->getCryptoInstance()->encryptString($secretMessage, $secretKey)); // Return it return $encryptedMessage; diff --git a/docs/TODOs.txt b/docs/TODOs.txt index 9d26adc3c..7096d7682 100644 --- a/docs/TODOs.txt +++ b/docs/TODOs.txt @@ -97,10 +97,10 @@ ./inc/classes/exceptions/main/class_MissingMethodException.php:13: * @todo Try to rewrite user/guest login classes and mark this exception as deprecated ./inc/classes/exceptions/main/class_NoConfigEntryException.php:10: * @todo Rename this class to NoFoundEntryException ./inc/classes/interfaces/class_FrameworkInterface.php:11: * @todo Find a better name for this interface -./inc/classes/main/class_BaseFrameworkSystem.php:1168: * @todo Write a logging mechanism for productive mode -./inc/classes/main/class_BaseFrameworkSystem.php:1182: // @TODO Finish this part! -./inc/classes/main/class_BaseFrameworkSystem.php:159: // @todo Try to clean these constants up -./inc/classes/main/class_BaseFrameworkSystem.php:345: * @todo SearchableResult and UpdateableResult shall have a super interface to use here +./inc/classes/main/class_BaseFrameworkSystem.php:1178: * @todo Write a logging mechanism for productive mode +./inc/classes/main/class_BaseFrameworkSystem.php:1192: // @TODO Finish this part! +./inc/classes/main/class_BaseFrameworkSystem.php:169: // @todo Try to clean these constants up +./inc/classes/main/class_BaseFrameworkSystem.php:355: * @todo SearchableResult and UpdateableResult shall have a super interface to use here ./inc/classes/main/commands/web/class_WebLoginAreaCommand.php:64: * @todo Add some stuff here: Some personal data, app/game related data ./inc/classes/main/commands/web/class_WebProblemCommand.php:58: * @todo 0% done ./inc/classes/main/commands/web/class_WebStatusCommand.php:58: * @todo 0% done @@ -201,6 +201,7 @@ ./inc/selector.php:11: * @todo We should minimize these includes ./index.php:59: * @todo This method is old code and needs heavy rewrite ### ### DEPRECATION FOLLOWS: ### ### +./application/hub/interfaces/messages/class_MessageHelper.php:2:// @DEPRECATED ./application/hub/main/database/wrapper/class_NodeInformationDatabaseWrapper.php:2:// @DEPRECATED ./application/hub/main/database/wrapper/class_NodeListDatabaseWrapper.php:2:// @DEPRECATED ./application/hub/main/database/wrapper/class_PeerStateLookupDatabaseWrapper.php:2:// @DEPRECATED @@ -223,6 +224,7 @@ ./application/hub/main/filter/task/class_CruncherTaskHandlerInitializerFilter.php:2:// @DEPRECATED ./application/hub/main/filter/task/class_HubTaskHandlerInitializerFilter.php:2:// @DEPRECATED ./application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php:2:// @DEPRECATED +./application/hub/main/helper/messages/crypto/class_CryptoRandomMessageHelper.php:2:// @DEPRECATED ./application/hub/main/nodes/class_BaseHubNode.php:50: * @deprecated ./application/hub/main/template/announcement/class_AnnouncementTemplateEngine.php:2:// @DEPRECATED ./application/hub/main/template/connect/class_SelfConnectTemplateEngine.php:2:// @DEPRECATED @@ -234,6 +236,8 @@ ./inc/classes/exceptions/language/class_MissingLanguageHandlerException.php:2:// @DEPRECATED ./inc/classes/exceptions/main/class_ClassNotFoundException.php:2:// @DEPRECATED ./inc/classes/exceptions/main/class_ConfigEntryNotFoundException.php:2:// @DEPRECATED +./inc/classes/interfaces/helper/class_HelpableLogin.php:2:// @DEPRECATED +./inc/classes/interfaces/helper/class_HelpableTemplate.php:2:// @DEPRECATED ./inc/classes.php:9: * @deprecated ./inc/database.php:10: * @deprecated ./inc/file_io.php:2:// @DEPRECATED -- 2.39.5