X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=framework%2Fmain%2Fclasses%2Fcrypto%2Fclass_CryptoHelper.php;h=7ef8d3f3adab43aab9ab033cf5e0a86f2ef3fd35;hb=f7795764503a5eba4ce861d8601c0707dd97778a;hp=6ee9c1717c11ab2b0e6d03f9f03b1a07cfa1a35e;hpb=70ec39842bea8dca606bcc513f7d905dfcecacac;p=core.git diff --git a/framework/main/classes/crypto/class_CryptoHelper.php b/framework/main/classes/crypto/class_CryptoHelper.php index 6ee9c171..7ef8d3f3 100644 --- a/framework/main/classes/crypto/class_CryptoHelper.php +++ b/framework/main/classes/crypto/class_CryptoHelper.php @@ -1,18 +1,20 @@ * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.shipsimu.org * @@ -49,6 +51,11 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { */ private $salt = ''; + /** + * Instance of a RNG + */ + private $rngInstance = NULL; + /** * Protected constructor * @@ -94,6 +101,25 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { return self::$selfInstance; } + /** + * Setter for RNG instance + * + * @param $rngInstance An instance of a random number generator (RNG) + * @return void + */ + protected final function setRngInstance (RandomNumberGenerator $rngInstance) { + $this->rngInstance = $rngInstance; + } + + /** + * Getter for RNG instance + * + * @return $rngInstance An instance of a random number generator (RNG) + */ + public final function getRngInstance () { + return $this->rngInstance; + } + /** * Attaches a crypto stream to this crypto helper by detecting loaded * modules. @@ -105,13 +131,13 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { // Do we have openssl/mcrypt loaded? if ($this->isPhpExtensionLoaded('mcrypt')) { // Then use it - $this->cryptoStreamInstance = ObjectFactory::createObjectByName('CoreFramework\Stream\Crypto\McryptStream', array($this->getRngInstance())); + $this->cryptoStreamInstance = ObjectFactory::createObjectByConfiguredName('crypto_mcrypt_stream_class', array($this->getRngInstance())); } elseif ($this->isPhpExtensionLoaded('openssl')) { // Then use it - $this->cryptoStreamInstance = ObjectFactory::createObjectByName('CoreFramework\Stream\Crypto\OpenSslStream', array($this->getRngInstance())); + $this->cryptoStreamInstance = ObjectFactory::createObjectByConfiguredName('crypto_openssl_stream_class', array($this->getRngInstance())); } else { // If nothing works ... - $this->cryptoStreamInstance = ObjectFactory::createObjectByName('CoreFramework\Stream\Crypto\NullCryptoStream'); + $this->cryptoStreamInstance = ObjectFactory::createObjectByConfiguredName('crypto_null_stream_class'); } } @@ -138,7 +164,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { $randomString = $this->getRngInstance()->randomString() . $this->createUuid(); // Get config entry for salt length - $length = $this->getConfigInstance()->getConfigEntry('salt_length'); + $length = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('salt_length'); // Keep only defined number of characters $this->salt = substr(sha1($randomString), -$length, $length); @@ -155,7 +181,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { $uuid = ''; // Is the UUID extension loaded and enabled? (see pecl) - if ($this->getConfigInstance()->getConfigEntry('extension_uuid_loaded') === true) { + if (FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('extension_uuid_loaded') === true) { // Then add it as well $uuid = uuid_create(); } // END - if @@ -185,7 +211,7 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { // Is the old password set? if (!empty($oldHash)) { // Use the salt from hash, first get length - $length = $this->getConfigInstance()->getConfigEntry('salt_length'); + $length = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('salt_length'); // Then extract the X first characters from the hash as our salt $salt = substr($oldHash, 0, $length); @@ -195,14 +221,14 @@ class CryptoHelper extends BaseFrameworkSystem implements Cryptable { //* DEBUG: */ echo "salt=".$salt."/plain=".$str."
\n"; if ($withFixed === true) { // Use additional fixed salt - $hashed = $salt . md5(sprintf($this->getConfigInstance()->getConfigEntry('hash_extra_mask'), + $hashed = $salt . md5(sprintf(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('hash_extra_mask'), $salt, $this->getRngInstance()->getFixedSalt(), $str )); } else { // Use salt+string to hash - $hashed = $salt . md5(sprintf($this->getConfigInstance()->getConfigEntry('hash_normal_mask'), + $hashed = $salt . md5(sprintf(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('hash_normal_mask'), $salt, $str ));