diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2012-10-14 17:17:06 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2012-10-14 17:18:30 +0200 |
commit | 2c427f050e2bc263b5c4c2faabf73e3993f1d29d (patch) | |
tree | 3dc42693fe0853e2235194b7e3846b2ae15736c3 /lib/util.php | |
parent | d6c4b83f13976b19f471ce3a02c5b872c2f79bdc (diff) | |
download | nextcloud-server-2c427f050e2bc263b5c4c2faabf73e3993f1d29d.tar.gz nextcloud-server-2c427f050e2bc263b5c4c2faabf73e3993f1d29d.zip |
Show a warning in the installer if no secure RNG is available
Diffstat (limited to 'lib/util.php')
-rwxr-xr-x | lib/util.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/util.php b/lib/util.php index 748886083dd..9fde98c1972 100755 --- a/lib/util.php +++ b/lib/util.php @@ -559,6 +559,7 @@ class OC_Util { * @brief Generates a cryptographical secure pseudorandom string * @param Int with the length of the random string * @return String + * Please also update secureRNG_available if you change something here */ public static function generate_random_bytes($length = 30) { @@ -589,4 +590,27 @@ class OC_Util { } return $pseudo_byte; } + + /* + * @brief Checks if a secure random number generator is available + * @return bool + */ + public static function secureRNG_available() { + + // Check openssl_random_pseudo_bytes + if(function_exists('openssl_random_pseudo_bytes')) { + openssl_random_pseudo_bytes(1, $strong); + if($strong == TRUE) { + return true; + } + } + + // Check /dev/random + $fp = @file_get_contents('/dev/random', false, null, 0, 1); + if ($fp !== FALSE) { + return true; + } + + return false; + } } |