aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2024-05-31 19:09:24 +0200
committerGitHub <noreply@github.com>2024-05-31 19:09:24 +0200
commit7dee0361726788e0a7b1e7de47d0d9fc47b4915f (patch)
tree0c98718687b30485ca376af7e3f1f2645df881cb /lib
parent8cf845d31b7ecbed601a02a10506089587a3abe6 (diff)
parent7f745a1ed00c18414146a685256df43614679586 (diff)
downloadnextcloud-server-7dee0361726788e0a7b1e7de47d0d9fc47b4915f.tar.gz
nextcloud-server-7dee0361726788e0a7b1e7de47d0d9fc47b4915f.zip
Merge pull request #40124 from summersab/refactor/OC-Server-getSecureRandom
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Cache/File.php2
-rw-r--r--lib/private/DB/Connection.php3
-rw-r--r--lib/private/Security/SecureRandom.php2
-rw-r--r--lib/private/Setup/PostgreSQL.php2
-rw-r--r--lib/private/Share20/ProviderFactory.php7
-rw-r--r--lib/private/legacy/OC_Util.php3
-rw-r--r--lib/public/Security/ISecureRandom.php2
7 files changed, 12 insertions, 9 deletions
diff --git a/lib/private/Cache/File.php b/lib/private/Cache/File.php
index 33fa1c00e98..10152d0966b 100644
--- a/lib/private/Cache/File.php
+++ b/lib/private/Cache/File.php
@@ -83,7 +83,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 8d300123a40..c886cb20235 100644
--- a/lib/private/DB/Connection.php
+++ b/lib/private/DB/Connection.php
@@ -28,6 +28,7 @@ use OCP\Diagnostics\IEventLogger;
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 @@ class Connection extends PrimaryReadReplicaConnection {
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 f6257779486..459d43475b7 100644
--- a/lib/private/Security/SecureRandom.php
+++ b/lib/private/Security/SecureRandom.php
@@ -16,7 +16,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/PostgreSQL.php b/lib/private/Setup/PostgreSQL.php
index 9cee614b7fa..4ece8957ce6 100644
--- a/lib/private/Setup/PostgreSQL.php
+++ b/lib/private/Setup/PostgreSQL.php
@@ -48,7 +48,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 fde63a4c394..9716d1e7556 100644
--- a/lib/private/Share20/ProviderFactory.php
+++ b/lib/private/Share20/ProviderFactory.php
@@ -25,6 +25,7 @@ use OCP\IServerContainer;
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 @@ class ProviderFactory implements IProviderFactory {
$this->serverContainer->get(LoggerInterface::class),
);
$tokenHandler = new TokenHandler(
- $this->serverContainer->getSecureRandom()
+ $this->serverContainer->get(ISecureRandom::class)
);
$this->federatedProvider = new FederatedShareProvider(
@@ -169,7 +170,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->get(IRootFolder::class),
$this->serverContainer->getL10N('sharebymail'),
@@ -211,7 +212,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->get(IRootFolder::class),
$this->serverContainer->getL10N('circles'),
diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php
index 14918dfe89a..b7836e86d7b 100644
--- a/lib/private/legacy/OC_Util.php
+++ b/lib/private/legacy/OC_Util.php
@@ -15,6 +15,7 @@ use OCP\IGroupManager;
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 @@ 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;
diff --git a/lib/public/Security/ISecureRandom.php b/lib/public/Security/ISecureRandom.php
index 2422fb8b7d6..188236dd3f9 100644
--- a/lib/public/Security/ISecureRandom.php
+++ b/lib/public/Security/ISecureRandom.php
@@ -14,7 +14,7 @@ namespace OCP\Security;
* use a fallback.
*
* Usage:
- * \OC::$server->getSecureRandom()->generate(10);
+ * \OC::$server->get(ISecureRandom::class)->generate(10);
*
* @since 8.0.0
*/