diff options
author | Andrew Summers <18727110+summersab@users.noreply.github.com> | 2023-08-29 16:29:33 -0500 |
---|---|---|
committer | Andrew Summers <18727110+summersab@users.noreply.github.com> | 2023-08-29 21:32:40 -0500 |
commit | 1395a5360274a6c6c0b4084d22da53466998c954 (patch) | |
tree | 01f3f8d5b532b0ccff57b4f4a806f11d94e87ce6 /lib/private | |
parent | 9d1547f59d53b46ba401ddf0e7f4c6e4f067004e (diff) | |
download | nextcloud-server-1395a5360274a6c6c0b4084d22da53466998c954.tar.gz nextcloud-server-1395a5360274a6c6c0b4084d22da53466998c954.zip |
Refactor `OC\Server::getSecureRandom`
Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Cache/File.php | 2 | ||||
-rw-r--r-- | lib/private/DB/Connection.php | 3 | ||||
-rw-r--r-- | lib/private/Security/SecureRandom.php | 2 | ||||
-rw-r--r-- | lib/private/Setup.php | 2 | ||||
-rw-r--r-- | lib/private/Setup/PostgreSQL.php | 2 | ||||
-rw-r--r-- | lib/private/Share20/ProviderFactory.php | 7 | ||||
-rw-r--r-- | lib/private/legacy/OC_Util.php | 5 |
7 files changed, 13 insertions, 10 deletions
diff --git a/lib/private/Cache/File.php b/lib/private/Cache/File.php index 72fc95a802b..9b0493da38b 100644 --- a/lib/private/Cache/File.php +++ b/lib/private/Cache/File.php @@ -105,7 +105,7 @@ class File implements ICache { $storage = $this->getStorage(); $result = false; // unique id to avoid chunk collision, just in case - $uniqueId = \OC::$server->getSecureRandom()->generate( + $uniqueId = \OC::$server->get(ISecureRandom::class)->generate( 16, ISecureRandom::CHAR_ALPHANUMERIC ); diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index 85c6a72dfdb..6150e4b2045 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -52,6 +52,7 @@ use OCP\Diagnostics\IEventLogger; use OCP\IRequestId; use OCP\PreConditionNotMetException; use OCP\Profiler\IProfiler; +use OCP\Security\ISecureRandom; use OC\DB\QueryBuilder\QueryBuilder; use OC\SystemConfig; use Psr\Log\LoggerInterface; @@ -592,7 +593,7 @@ class Connection extends \Doctrine\DBAL\Connection { private function getMigrator() { // TODO properly inject those dependencies - $random = \OC::$server->getSecureRandom(); + $random = \OC::$server->get(ISecureRandom::class); $platform = $this->getDatabasePlatform(); $config = \OC::$server->getConfig(); $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class); diff --git a/lib/private/Security/SecureRandom.php b/lib/private/Security/SecureRandom.php index cbd1dc8db6d..dcf50f00629 100644 --- a/lib/private/Security/SecureRandom.php +++ b/lib/private/Security/SecureRandom.php @@ -35,7 +35,7 @@ use OCP\Security\ISecureRandom; * use a fallback. * * Usage: - * \OC::$server->getSecureRandom()->generate(10); + * \OC::$server->get(ISecureRandom::class)->generate(10); * @package OC\Security */ class SecureRandom implements ISecureRandom { diff --git a/lib/private/Setup.php b/lib/private/Setup.php index 0993fe54f47..5c7cd10a2a7 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -510,7 +510,7 @@ class Setup { \OC::$server->getL10N('lib'), \OCP\Server::get(Defaults::class), \OC::$server->get(LoggerInterface::class), - \OC::$server->getSecureRandom(), + \OC::$server->get(ISecureRandom::class), \OCP\Server::get(Installer::class) ); diff --git a/lib/private/Setup/PostgreSQL.php b/lib/private/Setup/PostgreSQL.php index 490cbba69a9..d400bbf7e8b 100644 --- a/lib/private/Setup/PostgreSQL.php +++ b/lib/private/Setup/PostgreSQL.php @@ -69,7 +69,7 @@ class PostgreSQL extends AbstractDatabase { //add prefix to the postgresql user name to prevent collisions $this->dbUser = 'oc_' . strtolower($username); //create a new password so we don't need to store the admin config in the config file - $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, ISecureRandom::CHAR_ALPHANUMERIC); + $this->dbPassword = \OC::$server->get(ISecureRandom::class)->generate(30, ISecureRandom::CHAR_ALPHANUMERIC); $this->createDBUser($connection); diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index 8c01d660915..03284b6d78d 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -44,6 +44,7 @@ use OCA\Talk\Share\RoomShareProvider; use OCP\Defaults; use OCP\EventDispatcher\IEventDispatcher; use OCP\IServerContainer; +use OCP\Security\ISecureRandom; use OCP\Share\IManager; use OCP\Share\IProviderFactory; use OCP\Share\IShare; @@ -146,7 +147,7 @@ class ProviderFactory implements IProviderFactory { $this->serverContainer->get(LoggerInterface::class), ); $tokenHandler = new TokenHandler( - $this->serverContainer->getSecureRandom() + $this->serverContainer->get(ISecureRandom::class) ); $this->federatedProvider = new FederatedShareProvider( @@ -188,7 +189,7 @@ class ProviderFactory implements IProviderFactory { $this->shareByMailProvider = new ShareByMailProvider( $this->serverContainer->getConfig(), $this->serverContainer->getDatabaseConnection(), - $this->serverContainer->getSecureRandom(), + $this->serverContainer->get(ISecureRandom::class), $this->serverContainer->getUserManager(), $this->serverContainer->getLazyRootFolder(), $this->serverContainer->getL10N('sharebymail'), @@ -230,7 +231,7 @@ class ProviderFactory implements IProviderFactory { if ($this->shareByCircleProvider === null) { $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( $this->serverContainer->getDatabaseConnection(), - $this->serverContainer->getSecureRandom(), + $this->serverContainer->get(ISecureRandom::class), $this->serverContainer->getUserManager(), $this->serverContainer->getLazyRootFolder(), $this->serverContainer->getL10N('circles'), diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index 9d62c46137e..a0575c4bef3 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -71,6 +71,7 @@ use OCP\IConfig; use OCP\IGroupManager; use OCP\IURLGenerator; use OCP\IUser; +use OCP\Security\ISecureRandom; use OCP\Share\IManager; use Psr\Log\LoggerInterface; @@ -518,7 +519,7 @@ class OC_Util { \OC::$server->getL10N('lib'), \OC::$server->get(\OCP\Defaults::class), \OC::$server->get(LoggerInterface::class), - \OC::$server->getSecureRandom(), + \OC::$server->get(ISecureRandom::class), \OC::$server->get(\OC\Installer::class) ); @@ -845,7 +846,7 @@ class OC_Util { $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); if (is_null($id)) { // We need to guarantee at least one letter in instanceid so it can be used as the session_name - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); + $id = 'oc' . \OC::$server->get(ISecureRandom::class)->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); \OC::$server->getSystemConfig()->setValue('instanceid', $id); } return $id; |