From 2bb7217d04b284367f1155aafa12b38d61891f92 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 10 Nov 2014 11:20:02 +0100 Subject: [PATCH] Do not require the openssl extension --- application/clicommands/SetupCommand.php | 7 ++++++- library/Icinga/Authentication/Backend/DbUserBackend.php | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/application/clicommands/SetupCommand.php b/application/clicommands/SetupCommand.php index 2e02407c3..fe44ec0dc 100644 --- a/application/clicommands/SetupCommand.php +++ b/application/clicommands/SetupCommand.php @@ -47,7 +47,12 @@ class SetupCommand extends Command */ public function generateTokenAction() { - $token = bin2hex(openssl_random_pseudo_bytes(8)); + if (function_exists('openssl_random_pseudo_bytes')) { + $token = bin2hex(openssl_random_pseudo_bytes(8)); + } else { + $token = substr(md5(mt_rand()), 16); + } + $filepath = $this->app->getConfigDir() . '/setup.token'; if (false === file_put_contents($filepath, $token)) { diff --git a/library/Icinga/Authentication/Backend/DbUserBackend.php b/library/Icinga/Authentication/Backend/DbUserBackend.php index d2d0147e5..2f57c63d0 100644 --- a/library/Icinga/Authentication/Backend/DbUserBackend.php +++ b/library/Icinga/Authentication/Backend/DbUserBackend.php @@ -144,7 +144,12 @@ class DbUserBackend extends UserBackend */ protected function generateSalt() { - return openssl_random_pseudo_bytes(self::SALT_LENGTH); + if (function_exists('openssl_random_pseudo_bytes')) { + return openssl_random_pseudo_bytes(self::SALT_LENGTH); + } else { + // If you know a more secure way to generate a salt, do not hesitate to change this! + return substr(md5(mt_rand()), self::SALT_LENGTH); + } } /**