diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2012-10-14 19:17:06 +0400 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2012-10-14 19:17:06 +0400 |
commit | 7f06f93e9e4f402d5ed0826149d1effa47ccaa15 (patch) | |
tree | 54e9be40911fb65b4d970ce6231b7a3b10937757 /lib | |
parent | e99cf5cf4948d568c43a0386244cefd7e27b6052 (diff) |
Show a warning in the installer if no secure RNG is available
Diffstat (limited to 'lib')
-rw-r--r-- | lib/setup.php | 2 | ||||
-rw-r--r-- | lib/util.php | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/setup.php b/lib/setup.php index 9e7129da5b5..8d80e9d9789 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -4,11 +4,13 @@ $hasSQLite = (is_callable('sqlite_open') or class_exists('SQLite3')); $hasMySQL = is_callable('mysql_connect'); $hasPostgreSQL = is_callable('pg_connect'); $datadir = OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data'); + $opts = array( 'hasSQLite' => $hasSQLite, 'hasMySQL' => $hasMySQL, 'hasPostgreSQL' => $hasPostgreSQL, 'directory' => $datadir, + 'secureRNG' => OC_Util::secureRNG_available(), 'errors' => array(), ); diff --git a/lib/util.php b/lib/util.php index 127570e9f3d..8db3c307f95 100644 --- a/lib/util.php +++ b/lib/util.php @@ -463,6 +463,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) { @@ -493,4 +494,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; + } +}
\ No newline at end of file |