diff --git a/application/Espo/Core/Authentication/AuthToken/EspoManager.php b/application/Espo/Core/Authentication/AuthToken/EspoManager.php index 063a5fed34..c2621ad505 100644 --- a/application/Espo/Core/Authentication/AuthToken/EspoManager.php +++ b/application/Espo/Core/Authentication/AuthToken/EspoManager.php @@ -30,17 +30,16 @@ namespace Espo\Core\Authentication\AuthToken; use Espo\ORM\EntityManager; +use Espo\ORM\Repository\RDBRepository; use Espo\Entities\AuthToken as AuthTokenEntity; use RuntimeException; -use const MCRYPT_DEV_URANDOM; - class EspoManager implements Manager { - private $entityManager; + private EntityManager $entityManager; - private $repository; + private RDBRepository $repository; private const TOKEN_RANDOM_LENGTH = 16; @@ -163,10 +162,6 @@ class EspoManager implements Manager return bin2hex(random_bytes($length)); } - if (function_exists('mcrypt_create_iv')) { - return bin2hex(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM)); - } - if (function_exists('openssl_random_pseudo_bytes')) { return bin2hex(openssl_random_pseudo_bytes($length)); } diff --git a/application/Espo/Core/FileStorage/Manager.php b/application/Espo/Core/FileStorage/Manager.php index 87b7f64037..fa1fc3e7ed 100644 --- a/application/Espo/Core/FileStorage/Manager.php +++ b/application/Espo/Core/FileStorage/Manager.php @@ -51,6 +51,7 @@ class Manager /** * @var array + * @phpstan-ignore-next-line Used to prevent deleting from memory. */ private $resourceMap = []; diff --git a/application/Espo/Core/Utils/Crypt.php b/application/Espo/Core/Utils/Crypt.php index 3848ef0df8..97f1e2159b 100644 --- a/application/Espo/Core/Utils/Crypt.php +++ b/application/Espo/Core/Utils/Crypt.php @@ -33,11 +33,11 @@ use RuntimeException; class Crypt { - private $key = null; + private string $cryptKey; - private $cryptKey = null; + private ?string $key = null; - private $iv = null; + private ?string $iv = null; public function __construct(Config $config) { @@ -51,7 +51,7 @@ class Crypt } if (!$this->key) { - throw new RuntimeException("Could not hash key."); + throw new RuntimeException("Could not hash the key."); } return $this->key; @@ -60,12 +60,11 @@ class Crypt private function getIv(): string { if ($this->iv === null) { - if (extension_loaded('openssl')) { - $this->iv = openssl_random_pseudo_bytes(16); - } - else { - $this->iv = mcrypt_create_iv(16, MCRYPT_RAND); + if (!extension_loaded('openssl')) { + throw new RuntimeException("openssl extension is not loaded."); } + + $this->iv = openssl_random_pseudo_bytes(16); } return $this->iv; @@ -75,44 +74,28 @@ class Crypt { $iv = $this->getIv(); - if (extension_loaded('openssl')) { - return base64_encode( - openssl_encrypt($string, 'aes-256-cbc', $this->getKey(), OPENSSL_RAW_DATA , $iv) . $iv - ); + if (!extension_loaded('openssl')) { + throw new RuntimeException("openssl extension is not loaded."); } - $block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, 'cbc'); - - $pad = $block - (strlen($string) % $block); - - $string .= str_repeat(chr($pad), $pad); - return base64_encode( - mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->getKey(), $string, MCRYPT_MODE_CBC, $iv) . $iv + openssl_encrypt($string, 'aes-256-cbc', $this->getKey(), OPENSSL_RAW_DATA, $iv) . $iv ); } public function decrypt(string $encryptedString): string { $encryptedStringDecoded = base64_decode($encryptedString); - $string = substr($encryptedStringDecoded, 0, strlen($encryptedStringDecoded) - 16); - $iv = substr($encryptedStringDecoded, -16); - if (extension_loaded('openssl')) { - return trim( - openssl_decrypt($string, 'aes-256-cbc', $this->getKey(), OPENSSL_RAW_DATA, $iv) - ); + if (!extension_loaded('openssl')) { + throw new RuntimeException("openssl extension is not loaded."); } - $string = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->getKey(), $string, MCRYPT_MODE_CBC, $iv); - - $len = strlen($string); - - $pad = ord($string[$len - 1]); - - return substr($string, 0, strlen($string) - $pad); + return trim( + openssl_decrypt($string, 'aes-256-cbc', $this->getKey(), OPENSSL_RAW_DATA, $iv) + ); } public function generateKey(): string diff --git a/application/Espo/ORM/SthCollection.php b/application/Espo/ORM/SthCollection.php index e841cbf994..b3c485d681 100644 --- a/application/Espo/ORM/SthCollection.php +++ b/application/Espo/ORM/SthCollection.php @@ -62,11 +62,6 @@ class SthCollection implements Collection, IteratorAggregate, Countable private ?string $sql = null; - /** - * @var Entity[] - */ - private array $entityList = []; - private function __construct(EntityManager $entityManager) { $this->entityManager = $entityManager; @@ -126,8 +121,6 @@ class SthCollection implements Collection, IteratorAggregate, Countable $this->prepareEntity($entity); - $this->entityList[] = $entity; - yield $entity; } })(); diff --git a/application/Espo/Services/App.php b/application/Espo/Services/App.php index 1440e90851..ad0c13430a 100644 --- a/application/Espo/Services/App.php +++ b/application/Espo/Services/App.php @@ -37,8 +37,6 @@ use Espo\Core\ORM\Entity as CoreEntity; use Espo\Core\{ Acl, - AclManager, - Select\SelectBuilderFactory, DataManager, InjectableFactory, Utils\Metadata, @@ -72,12 +70,8 @@ class App private $acl; - private $aclManager; - private $dataManager; - private $selectBuilderFactory; - private $injectableFactory; private $settingsService; @@ -95,9 +89,7 @@ class App EntityManager $entityManager, Metadata $metadata, Acl $acl, - AclManager $aclManager, DataManager $dataManager, - SelectBuilderFactory $selectBuilderFactory, InjectableFactory $injectableFactory, SettingsService $settingsService, User $user, @@ -109,9 +101,7 @@ class App $this->entityManager = $entityManager; $this->metadata = $metadata; $this->acl = $acl; - $this->aclManager = $aclManager; $this->dataManager = $dataManager; - $this->selectBuilderFactory = $selectBuilderFactory; $this->injectableFactory = $injectableFactory; $this->settingsService = $settingsService; $this->user = $user;