diff --git a/lib/private/Cache/File.php b/lib/private/Cache/File.php index 33fa1c00e9833..10152d0966b4b 100644 --- a/lib/private/Cache/File.php +++ b/lib/private/Cache/File.php @@ -83,7 +83,7 @@ public function set($key, $value, $ttl = 0) { $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 8d300123a4035..c886cb202353f 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -28,6 +28,7 @@ use OCP\IRequestId; use OCP\PreConditionNotMetException; use OCP\Profiler\IProfiler; +use OCP\Security\ISecureRandom; use OCP\Server; use Psr\Clock\ClockInterface; use Psr\Log\LoggerInterface; @@ -666,7 +667,7 @@ public function migrateToSchema(Schema $toSchema, bool $dryRun = false) { 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 = Server::get(\OCP\EventDispatcher\IEventDispatcher::class); diff --git a/lib/private/Security/SecureRandom.php b/lib/private/Security/SecureRandom.php index f625777948659..459d43475b7c6 100644 --- a/lib/private/Security/SecureRandom.php +++ b/lib/private/Security/SecureRandom.php @@ -16,7 +16,7 @@ * 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/PostgreSQL.php b/lib/private/Setup/PostgreSQL.php index 9cee614b7fa82..4ece8957ce63a 100644 --- a/lib/private/Setup/PostgreSQL.php +++ b/lib/private/Setup/PostgreSQL.php @@ -48,7 +48,7 @@ public function setupDatabase($username) { //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 fde63a4c3949e..9716d1e755686 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -25,6 +25,7 @@ use OCP\L10N\IFactory; use OCP\Mail\IMailer; use OCP\Security\IHasher; +use OCP\Security\ISecureRandom; use OCP\Share\IManager; use OCP\Share\IProviderFactory; use OCP\Share\IShare; @@ -127,7 +128,7 @@ protected function federatedShareProvider() { $this->serverContainer->get(LoggerInterface::class), ); $tokenHandler = new TokenHandler( - $this->serverContainer->getSecureRandom() + $this->serverContainer->get(ISecureRandom::class) ); $this->federatedProvider = new FederatedShareProvider( @@ -169,7 +170,7 @@ protected function getShareByMailProvider() { $this->shareByMailProvider = new ShareByMailProvider( $this->serverContainer->getConfig(), $this->serverContainer->getDatabaseConnection(), - $this->serverContainer->getSecureRandom(), + $this->serverContainer->get(ISecureRandom::class), $this->serverContainer->getUserManager(), $this->serverContainer->get(IRootFolder::class), $this->serverContainer->getL10N('sharebymail'), @@ -211,7 +212,7 @@ protected function getShareByCircleProvider() { 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->get(IRootFolder::class), $this->serverContainer->getL10N('circles'), diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index 14918dfe89ad8..b7836e86d7b7b 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -15,6 +15,7 @@ use OCP\IURLGenerator; use OCP\IUser; use OCP\L10N\IFactory; +use OCP\Security\ISecureRandom; use OCP\Share\IManager; use Psr\Log\LoggerInterface; @@ -782,7 +783,7 @@ public static function getInstanceId() { $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; diff --git a/lib/public/Security/ISecureRandom.php b/lib/public/Security/ISecureRandom.php index 2422fb8b7d64d..188236dd3f9b5 100644 --- a/lib/public/Security/ISecureRandom.php +++ b/lib/public/Security/ISecureRandom.php @@ -14,7 +14,7 @@ * use a fallback. * * Usage: - * \OC::$server->getSecureRandom()->generate(10); + * \OC::$server->get(ISecureRandom::class)->generate(10); * * @since 8.0.0 */ diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php index 4714b569d81af..eaa6540b93bd6 100644 --- a/tests/lib/DB/MigratorTest.php +++ b/tests/lib/DB/MigratorTest.php @@ -19,6 +19,7 @@ use OC\DB\SQLiteMigrator; use OCP\DB\Types; use OCP\IConfig; +use OCP\Security\ISecureRandom; /** * Class MigratorTest @@ -56,7 +57,7 @@ protected function setUp(): void { private function getMigrator(): Migrator { $platform = $this->connection->getDatabasePlatform(); - $random = \OC::$server->getSecureRandom(); + $random = \OC::$server->get(ISecureRandom::class); $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class); if ($platform instanceof SqlitePlatform) { return new SQLiteMigrator($this->connection, $this->config, $dispatcher); diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index 5732e981ec73b..8c97c184c6fda 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -264,7 +264,7 @@ protected static function invokePrivate($object, $methodName, array $parameters * @return string */ protected static function getUniqueID($prefix = '', $length = 13) { - return $prefix . \OC::$server->getSecureRandom()->generate( + return $prefix . \OC::$server->get(ISecureRandom::class)->generate( $length, // Do not use dots and slashes as we use the value for file names ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER