diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2018-09-13 09:29:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-13 09:29:42 +0200 |
commit | a1c969a17056f14fd165642f6c19cad160e32212 (patch) | |
tree | c4da5745f4ab7909481bcf4f29f92f5eaca2347c /settings | |
parent | 10351cb9daaae22c7d6b5c57299198987e2b3316 (diff) | |
parent | 8d8189c9321ebc4b7049e6060a4d2e3611051aea (diff) | |
download | nextcloud-server-a1c969a17056f14fd165642f6c19cad160e32212.tar.gz nextcloud-server-a1c969a17056f14fd165642f6c19cad160e32212.zip |
Merge pull request #10840 from webfoersterei/refactor/5530-urandom-check
Refactor secure randomness check
Diffstat (limited to 'settings')
-rw-r--r-- | settings/Controller/CheckSetupController.php | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/settings/Controller/CheckSetupController.php b/settings/Controller/CheckSetupController.php index 9169808456f..54a23d336d8 100644 --- a/settings/Controller/CheckSetupController.php +++ b/settings/Controller/CheckSetupController.php @@ -55,6 +55,7 @@ use OCP\ILogger; use OCP\IRequest; use OCP\IURLGenerator; use OCP\Lock\ILockingProvider; +use OCP\Security\ISecureRandom; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; @@ -86,6 +87,8 @@ class CheckSetupController extends Controller { private $dateTimeFormatter; /** @var MemoryInfo */ private $memoryInfo; + /** @var ISecureRandom */ + private $secureRandom; public function __construct($AppName, IRequest $request, @@ -100,7 +103,8 @@ class CheckSetupController extends Controller { IDBConnection $db, ILockingProvider $lockingProvider, IDateTimeFormatter $dateTimeFormatter, - MemoryInfo $memoryInfo) { + MemoryInfo $memoryInfo, + ISecureRandom $secureRandom) { parent::__construct($AppName, $request); $this->config = $config; $this->clientService = $clientService; @@ -114,6 +118,7 @@ class CheckSetupController extends Controller { $this->lockingProvider = $lockingProvider; $this->dateTimeFormatter = $dateTimeFormatter; $this->memoryInfo = $memoryInfo; + $this->secureRandom = $secureRandom; } /** @@ -167,20 +172,17 @@ class CheckSetupController extends Controller { } /** - * Whether /dev/urandom is available to the PHP controller + * Whether PHP can generate "secure" pseudorandom integers * * @return bool */ - private function isUrandomAvailable() { - if(@file_exists('/dev/urandom')) { - $file = fopen('/dev/urandom', 'rb'); - if($file) { - fclose($file); - return true; - } + private function isRandomnessSecure() { + try { + $this->secureRandom->generate(1); + } catch (\Exception $ex) { + return false; } - - return false; + return true; } /** @@ -601,7 +603,7 @@ Raw output 'serverHasInternetConnection' => $this->isInternetConnectionWorking(), 'isMemcacheConfigured' => $this->isMemcacheConfigured(), 'memcacheDocs' => $this->urlGenerator->linkToDocs('admin-performance'), - 'isUrandomAvailable' => $this->isUrandomAvailable(), + 'isRandomnessSecure' => $this->isRandomnessSecure(), 'securityDocs' => $this->urlGenerator->linkToDocs('admin-security'), 'isUsedTlsLibOutdated' => $this->isUsedTlsLibOutdated(), 'phpSupported' => $this->isPhpSupported(), |