[icinga-checkins] icinga.org: icingaweb2/feature/setup-wizard-7163: Do not require the openssl extension

git at icinga.org git at icinga.org
Mon Nov 10 13:12:44 CET 2014


Module: icingaweb2
Branch: feature/setup-wizard-7163
Commit: 2bb7217d04b284367f1155aafa12b38d61891f92
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=2bb7217d04b284367f1155aafa12b38d61891f92

Author: Johannes Meyer <johannes.meyer at netways.de>
Date:   Mon Nov 10 11:20:02 2014 +0100

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 2e02407..fe44ec0 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 d2d0147..2f57c63 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);
+        }
     }
 
     /**



More information about the icinga-checkins mailing list