From c8fc8d17336829a4b0f8a0b187093663dda52ffb Mon Sep 17 00:00:00 2001 From: fGaillard Date: Wed, 7 Dec 2011 09:21:05 +0000 Subject: [PATCH] [-] Classes : #PSCFI-3880 : BugFix mbstring overload on Rijndael encrypt-decrypt git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11019 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Cookie.php | 9 ++++++--- classes/Rijndael.php | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/classes/Cookie.php b/classes/Cookie.php index 09d6fbfd6..957a0525f 100644 --- a/classes/Cookie.php +++ b/classes/Cookie.php @@ -254,10 +254,12 @@ class CookieCore { /* Decrypt cookie content */ $content = $this->_cipherTool->decrypt($_COOKIE[$this->_name]); - + //printf("\$content = %s
", $content); + /* Get cookie checksum */ $checksum = crc32($this->_iv.substr($content, 0, strrpos($content, '¤') + 2)); - + //printf("\$checksum = %s
", $checksum); + /* Unserialize cookie content */ $tmpTab = explode('¤', $content); foreach ($tmpTab as $keyAndValue) @@ -269,7 +271,8 @@ class CookieCore /* Blowfish fix */ if (isset($this->_content['checksum'])) $this->_content['checksum'] = (int)($this->_content['checksum']); - + //printf("\$this->_content['checksum'] = %s
", $this->_content['checksum']); + //die(); /* Check if cookie has not been modified */ if (!isset($this->_content['checksum']) || $this->_content['checksum'] != $checksum) $this->logout(); diff --git a/classes/Rijndael.php b/classes/Rijndael.php index 427f978a2..404b4371a 100644 --- a/classes/Rijndael.php +++ b/classes/Rijndael.php @@ -39,16 +39,27 @@ class RijndaelCore // Base64 is not required, but it is be more compact than urlencode public function encrypt($plaintext) { - if (($length = strlen($plaintext)) >= 1048576) + $length = (ini_get('mbstring.func_overload') & 2) ? mb_strlen($plaintext, ini_get('default_charset')) : strlen($plaintext); + + if ($length >= 1048576) return false; return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->_key, $plaintext, MCRYPT_MODE_ECB, $this->_iv)).sprintf('%06d', $length); } public function decrypt($ciphertext) { - $plainTextLength = intval(substr($ciphertext, -6)); - $ciphertext = substr($ciphertext, 0, -6); - return substr(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->_key, base64_decode($ciphertext), MCRYPT_MODE_ECB, $this->_iv), 0, $plainTextLength); + if (ini_get('mbstring.func_overload') & 2) + { + $plainTextLength = intval(mb_substr($ciphertext, -6, 6, ini_get('default_charset'))); + $ciphertext = mb_substr($ciphertext, 0, -6, ini_get('default_charset')); + return mb_substr(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->_key, base64_decode($ciphertext), MCRYPT_MODE_ECB, $this->_iv), 0, $plainTextLength, ini_get('default_charset')); + } + else + { + $plainTextLength = intval(substr($ciphertext, -6)); + $ciphertext = substr($ciphertext, 0, -6); + return substr(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->_key, base64_decode($ciphertext), MCRYPT_MODE_ECB, $this->_iv), 0, $plainTextLength); + } } }