From 9e1878c78180b435f669c324e671e7941eb4af34 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be>
Date: Thu, 27 Jun 2019 15:46:42 +0200
Subject: [PATCH] :sparkles: feat(core) Bump PHP min version to PHP7 and remove
 fallback
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Bumped minimum PHP version to 7.0.0 because we use strict typing.
Removed fallback for random_int.

issue #6002
---
 include/functions.inc           | 32 --------------------------------
 include/variables_common.inc    |  2 +-
 setup/class_setupStepChecks.inc |  8 --------
 3 files changed, 1 insertion(+), 41 deletions(-)

diff --git a/include/functions.inc b/include/functions.inc
index 7c2dcfb11..0d8768596 100644
--- a/include/functions.inc
+++ b/include/functions.inc
@@ -1931,38 +1931,6 @@ function load_all_classes ()
   }
 }
 
-if (!function_exists('random_int')) {
-  // PHP<7, we fallback on openssl_random_pseudo_bytes
-  function random_int ($min, $max)
-  {
-    $range = $max - $min;
-    if ($range <= 0) {
-      throw new Exception('Invalid range passed to random_int');
-    }
-
-    $log      = log($range, 2);
-    // length in bytes
-    $nbBytes  = (int) ($log / 8) + 1;
-    // length in bits
-    $nbBits   = (int) $log + 1;
-    // set all lower bits to 1
-    $filter   = pow(2, $nbBits) - 1;
-    if ($filter >= PHP_INT_MAX) {
-      $filter = PHP_INT_MAX;
-    }
-    do {
-      $randomBytes = openssl_random_pseudo_bytes($nbBytes, $strong);
-      if (!$strong || ($randomBytes === FALSE)) {
-        throw new Exception('Failed to get random bytes');
-      }
-      $rnd = hexdec(bin2hex($randomBytes));
-      // discard irrelevant bits
-      $rnd = $rnd & $filter;
-    } while ($rnd > $range);
-    return $min + $rnd;
-  }
-}
-
 function ldap_escape_f ($str, $ignore = '')
 {
   return ldap_escape($str, $ignore, LDAP_ESCAPE_FILTER);
diff --git a/include/variables_common.inc b/include/variables_common.inc
index ad2547b51..f79605da8 100644
--- a/include/variables_common.inc
+++ b/include/variables_common.inc
@@ -73,7 +73,7 @@ define("CONFIGRDN", "cn=config,ou=fusiondirectory,"); /*! Define FusionDirectory
 /*!
  * \brief Minimum PHP version
  */
-define('PHP_MIN_VERSION', '5.6.0');
+define('PHP_MIN_VERSION', '7.0.0');
 
 /*!
  * \brief Toggle crashing on PHP error, used for test suites
diff --git a/setup/class_setupStepChecks.inc b/setup/class_setupStepChecks.inc
index 6d9ecd4b6..fda940146 100644
--- a/setup/class_setupStepChecks.inc
+++ b/setup/class_setupStepChecks.inc
@@ -95,14 +95,6 @@ class setupStepChecks extends setupStep
     $M = TRUE;
     $basic_checks[] = ['NAME' => $N , 'DESC' => $D , 'RESULT' => $R , 'SOLUTION' => $S , 'MUST' => $M ];
 
-    /* Pseudo-random check */
-    $N = _('Checking cryptographically secure pseudo-random integers');
-    $D = _('You must use PHP>=7 or have openssl module activated so that FusionDirectory can generate cryptographically secure pseudo-random integers.');
-    $S = _('Please upgrade to PHP7 or activate openssl module.');
-    $R = (is_callable('random_int') || is_callable('openssl_random_pseudo_bytes'));
-    $M = TRUE;
-    $basic_checks[] = ['NAME' => $N , 'DESC' => $D , 'RESULT' => $R , 'SOLUTION' => $S , 'MUST' => $M ];
-
     /* Check for json support */
     $N = msgPool::checkingFor('json');
     $D = _('FusionDirectory requires this module to encode variables for javascript use.');
-- 
GitLab