From 8fc377d83aa4f541e5f8a4ffcd056d5f11e2b2e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 20 Nov 2014 10:23:48 +0100 Subject: [PATCH] Share code for resetting IV size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- .../auth/AuthenticationCookie.class.php | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/libraries/plugins/auth/AuthenticationCookie.class.php b/libraries/plugins/auth/AuthenticationCookie.class.php index e8450c7502..8291689fdf 100644 --- a/libraries/plugins/auth/AuthenticationCookie.class.php +++ b/libraries/plugins/auth/AuthenticationCookie.class.php @@ -781,11 +781,11 @@ class AuthenticationCookie extends AuthenticationPlugin if (is_null($this->_cookie_iv)) { $this->_cookie_iv = base64_decode($_COOKIE['pma_iv'], true); } + if (strlen($this->_cookie_iv) < $this->getIVSize()) { + $this->createIV(); + } if ($this->_useOpenSSL()) { - if (strlen($this->_cookie_iv) < openssl_cipher_iv_length('AES-128-CBC')) { - $this->createIV(); - } return openssl_decrypt( $encdata, 'AES-128-CBC', @@ -801,6 +801,20 @@ class AuthenticationCookie extends AuthenticationPlugin } } + /** + * Returns size of IV for encryption. + * + * @return int + */ + public function getIVSize() + { + if ($this->_useOpenSSL()) { + return openssl_cipher_iv_length('AES-128-CBC'); + } + $cipher = new Crypt_AES(CRYPT_AES_MODE_CBC); + return $cipher->block_size; + } + /** * Initialization * Store the initialization vector because it will be needed for @@ -813,11 +827,12 @@ class AuthenticationCookie extends AuthenticationPlugin { if ($this->_useOpenSSL()) { $this->_cookie_iv = openssl_random_pseudo_bytes( - openssl_cipher_iv_length('AES-128-CBC') + $this->getIVSize() ); } else { - $cipher = new Crypt_AES(CRYPT_AES_MODE_CBC); - $this->_cookie_iv = crypt_random_string($cipher->block_size); + $this->_cookie_iv = crypt_random_string( + $this->getIVSize() + ); } $GLOBALS['PMA_Config']->setCookie( 'pma_iv',