From 43de9af71f7f4ca5731b94a06d688ae8412ba427 Mon Sep 17 00:00:00 2001 From: M.Gergo Date: Fri, 6 Jul 2018 11:14:41 +0200 Subject: 2018/Feb/28 -i állapot hozzáadva, mint a módosítások kiindulási állapota --- .../McryptPseudoRandomStringGenerator.php | 68 ++++++++++++++ .../OpenSslPseudoRandomStringGenerator.php | 67 ++++++++++++++ .../PseudoRandomStringGeneratorFactory.php | 101 +++++++++++++++++++++ .../PseudoRandomStringGeneratorInterface.php | 45 +++++++++ .../PseudoRandomStringGeneratorTrait.php | 58 ++++++++++++ .../RandomBytesPseudoRandomStringGenerator.php | 59 ++++++++++++ .../UrandomPseudoRandomStringGenerator.php | 89 ++++++++++++++++++ 7 files changed, 487 insertions(+) create mode 100644 mayor-orig/www/include/share/facebook/PseudoRandomString/McryptPseudoRandomStringGenerator.php create mode 100644 mayor-orig/www/include/share/facebook/PseudoRandomString/OpenSslPseudoRandomStringGenerator.php create mode 100644 mayor-orig/www/include/share/facebook/PseudoRandomString/PseudoRandomStringGeneratorFactory.php create mode 100644 mayor-orig/www/include/share/facebook/PseudoRandomString/PseudoRandomStringGeneratorInterface.php create mode 100644 mayor-orig/www/include/share/facebook/PseudoRandomString/PseudoRandomStringGeneratorTrait.php create mode 100644 mayor-orig/www/include/share/facebook/PseudoRandomString/RandomBytesPseudoRandomStringGenerator.php create mode 100644 mayor-orig/www/include/share/facebook/PseudoRandomString/UrandomPseudoRandomStringGenerator.php (limited to 'mayor-orig/www/include/share/facebook/PseudoRandomString') diff --git a/mayor-orig/www/include/share/facebook/PseudoRandomString/McryptPseudoRandomStringGenerator.php b/mayor-orig/www/include/share/facebook/PseudoRandomString/McryptPseudoRandomStringGenerator.php new file mode 100644 index 00000000..bf573745 --- /dev/null +++ b/mayor-orig/www/include/share/facebook/PseudoRandomString/McryptPseudoRandomStringGenerator.php @@ -0,0 +1,68 @@ +validateLength($length); + + $binaryString = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM); + + if ($binaryString === false) { + throw new FacebookSDKException( + static::ERROR_MESSAGE . + 'mcrypt_create_iv() returned an error.' + ); + } + + return $this->binToHex($binaryString, $length); + } +} diff --git a/mayor-orig/www/include/share/facebook/PseudoRandomString/OpenSslPseudoRandomStringGenerator.php b/mayor-orig/www/include/share/facebook/PseudoRandomString/OpenSslPseudoRandomStringGenerator.php new file mode 100644 index 00000000..4b4276dc --- /dev/null +++ b/mayor-orig/www/include/share/facebook/PseudoRandomString/OpenSslPseudoRandomStringGenerator.php @@ -0,0 +1,67 @@ +validateLength($length); + + $wasCryptographicallyStrong = false; + $binaryString = openssl_random_pseudo_bytes($length, $wasCryptographicallyStrong); + + if ($binaryString === false) { + throw new FacebookSDKException(static::ERROR_MESSAGE . 'openssl_random_pseudo_bytes() returned an unknown error.'); + } + + if ($wasCryptographicallyStrong !== true) { + throw new FacebookSDKException(static::ERROR_MESSAGE . 'openssl_random_pseudo_bytes() returned a pseudo-random string but it was not cryptographically secure and cannot be used.'); + } + + return $this->binToHex($binaryString, $length); + } +} diff --git a/mayor-orig/www/include/share/facebook/PseudoRandomString/PseudoRandomStringGeneratorFactory.php b/mayor-orig/www/include/share/facebook/PseudoRandomString/PseudoRandomStringGeneratorFactory.php new file mode 100644 index 00000000..412f4813 --- /dev/null +++ b/mayor-orig/www/include/share/facebook/PseudoRandomString/PseudoRandomStringGeneratorFactory.php @@ -0,0 +1,101 @@ +validateLength($length); + + return $this->binToHex(random_bytes($length), $length); + } +} diff --git a/mayor-orig/www/include/share/facebook/PseudoRandomString/UrandomPseudoRandomStringGenerator.php b/mayor-orig/www/include/share/facebook/PseudoRandomString/UrandomPseudoRandomStringGenerator.php new file mode 100644 index 00000000..5ab434e6 --- /dev/null +++ b/mayor-orig/www/include/share/facebook/PseudoRandomString/UrandomPseudoRandomStringGenerator.php @@ -0,0 +1,89 @@ +validateLength($length); + + $stream = fopen('/dev/urandom', 'rb'); + if (!is_resource($stream)) { + throw new FacebookSDKException( + static::ERROR_MESSAGE . + 'Unable to open stream to /dev/urandom.' + ); + } + + if (!defined('HHVM_VERSION')) { + stream_set_read_buffer($stream, 0); + } + + $binaryString = fread($stream, $length); + fclose($stream); + + if (!$binaryString) { + throw new FacebookSDKException( + static::ERROR_MESSAGE . + 'Stream to /dev/urandom returned no data.' + ); + } + + return $this->binToHex($binaryString, $length); + } +} -- cgit v1.2.3