mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #40124 from summersab/refactor/OC-Server-getSecureRandom
This commit is contained in:
commit
7dee036172
9 changed files with 15 additions and 11 deletions
|
|
@ -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
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use OC\DB\OracleMigrator;
|
|||
use OC\DB\SQLiteMigrator;
|
||||
use OCP\DB\Types;
|
||||
use OCP\IConfig;
|
||||
use OCP\Security\ISecureRandom;
|
||||
|
||||
/**
|
||||
* Class MigratorTest
|
||||
|
|
@ -56,7 +57,7 @@ class MigratorTest extends \Test\TestCase {
|
|||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
|
|||
* @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
|
||||
|
|
|
|||
Loading…
Reference in a new issue