From 19c6561183820819e0fc3dcd4d0655b4bbf02f1d Mon Sep 17 00:00:00 2001 From: Jonas Ockerman Date: Thu, 28 Feb 2019 13:35:58 +0100 Subject: [PATCH 1/6] Updated code to use 'random_bytes' instead of 'mcrypt_create_iv' --- src/CouponCode.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/CouponCode.php b/src/CouponCode.php index ae0be45..bc1b44f 100644 --- a/src/CouponCode.php +++ b/src/CouponCode.php @@ -233,12 +233,13 @@ protected function _normalize($string, array $options = []) { return $string; } - /** - * Generates a cryptographically secure sequence of bytes. - * - * @param integer $bytes Number of bytes to return. - * @return string - */ + /** + * Generates a cryptographically secure sequence of bytes. + * + * @param integer $bytes Number of bytes to return. + * @return string + * @throws Exception + */ protected function _random($bytes) { if (is_readable('/dev/urandom')) { $stream = fopen('/dev/urandom', 'rb'); @@ -248,7 +249,7 @@ protected function _random($bytes) { return $result; } if (function_exists('mcrypt_create_iv')) { - return mcrypt_create_iv($bytes, MCRYPT_DEV_RANDOM); + return random_bytes($bytes); } throw new Exception("No source for generating a cryptographically secure seed found."); } From 12b684c0f450c8d928215482c8203f1a944d63dd Mon Sep 17 00:00:00 2001 From: Jonas Ockerman Date: Thu, 28 Feb 2019 14:04:21 +0100 Subject: [PATCH 2/6] Updated code to use 'random_bytes' instead of 'mcrypt_create_iv' --- composer.json | 2 +- src/CouponCode.php | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index e1c2c92..1bf71d6 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "atelierdisko/coupon_code", + "name": "HYP3/coupon_code", "description": "PHP library to generate and validate coupon code strings.", "keywords": ["coupon", "voucher", "code", "token", "key"], "homepage": "https://github.com/atelierdisko/coupon_code", diff --git a/src/CouponCode.php b/src/CouponCode.php index bc1b44f..9a8a17f 100644 --- a/src/CouponCode.php +++ b/src/CouponCode.php @@ -241,13 +241,14 @@ protected function _normalize($string, array $options = []) { * @throws Exception */ protected function _random($bytes) { - if (is_readable('/dev/urandom')) { - $stream = fopen('/dev/urandom', 'rb'); - $result = fread($stream, $bytes); + //if (is_readable('/dev/urandom')) { + if ($fh = @fopen('/dev/urandom', 'rb')) { + $stream = fopen('/dev/urandom', 'rb'); + $result = fread($stream, $bytes); - fclose($stream); - return $result; - } + fclose($stream); + return $result; + } if (function_exists('mcrypt_create_iv')) { return random_bytes($bytes); } From 85c9a3f01f80e454340dc70f19641efbb3bc6dea Mon Sep 17 00:00:00 2001 From: Jonas Ockerman Date: Thu, 28 Feb 2019 14:09:03 +0100 Subject: [PATCH 3/6] openbasedir error fix --- .idea/deployment.xml | 28 +++++ .idea/dictionaries/jonas.xml | 3 + .idea/misc.xml | 6 + .idea/vcs.xml | 6 + .idea/workspace.xml | 214 +++++++++++++++++++++++++++++++++++ 5 files changed, 257 insertions(+) create mode 100644 .idea/deployment.xml create mode 100644 .idea/dictionaries/jonas.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/deployment.xml b/.idea/deployment.xml new file mode 100644 index 0000000..05f0e7d --- /dev/null +++ b/.idea/deployment.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/jonas.xml b/.idea/dictionaries/jonas.xml new file mode 100644 index 0000000..84b414e --- /dev/null +++ b/.idea/dictionaries/jonas.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..0f533f9 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,214 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - 1551357239839 - - - 1551357358782 - - - 1551359062114 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/composer.json b/composer.json index 1bf71d6..cdab91b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "HYP3/coupon_code", + "name": "atelierdisko/coupon_code", "description": "PHP library to generate and validate coupon code strings.", "keywords": ["coupon", "voucher", "code", "token", "key"], "homepage": "https://github.com/atelierdisko/coupon_code", @@ -16,9 +16,6 @@ "require-dev": { "phpunit/phpunit": ">=4.0.0" }, - "suggest": { - "ext-mcrypt": "The mcrypt extension must be installed if /dev/urandom is not available." - }, "autoload": { "psr-4": { "CouponCode\\": "src/" } } diff --git a/src/CouponCode.php b/src/CouponCode.php index 9a8a17f..87a671e 100644 --- a/src/CouponCode.php +++ b/src/CouponCode.php @@ -241,9 +241,8 @@ protected function _normalize($string, array $options = []) { * @throws Exception */ protected function _random($bytes) { - //if (is_readable('/dev/urandom')) { - if ($fh = @fopen('/dev/urandom', 'rb')) { - $stream = fopen('/dev/urandom', 'rb'); + if (is_readable('/dev/urandom')) { + $stream = @fopen('/dev/urandom', 'rb'); $result = fread($stream, $bytes); fclose($stream); From e4b358db591abb4a4e9b8239b0e942f448fa4987 Mon Sep 17 00:00:00 2001 From: Jonas Ockerman Date: Fri, 1 Mar 2019 09:49:57 +0100 Subject: [PATCH 6/6] changed fopen to @fopen && replaced mcrypt_create_iv <> with random_bytes --- .idea/deployment.xml | 28 +++++ .idea/dictionaries/jonas.xml | 3 + .idea/misc.xml | 6 + .idea/vcs.xml | 6 + .idea/workspace.xml | 206 +++++++++++++++++++++++++++++++++++ src/CouponCode.php | 7 +- 6 files changed, 253 insertions(+), 3 deletions(-) create mode 100644 .idea/deployment.xml create mode 100644 .idea/dictionaries/jonas.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/deployment.xml b/.idea/deployment.xml new file mode 100644 index 0000000..05f0e7d --- /dev/null +++ b/.idea/deployment.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/jonas.xml b/.idea/dictionaries/jonas.xml new file mode 100644 index 0000000..84b414e --- /dev/null +++ b/.idea/dictionaries/jonas.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..4e6cb79 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,206 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +