From ea701dfcc1236ce15a48058a09f5717b292520d4 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Wed, 12 Aug 2015 14:11:16 +0530 Subject: [PATCH] Do not repeat the same conditions Signed-off-by: Madhura Jayaratne --- .../auth/AuthenticationCookie.class.php | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/libraries/plugins/auth/AuthenticationCookie.class.php b/libraries/plugins/auth/AuthenticationCookie.class.php index ebefa4e511..99728b4abc 100644 --- a/libraries/plugins/auth/AuthenticationCookie.class.php +++ b/libraries/plugins/auth/AuthenticationCookie.class.php @@ -28,18 +28,6 @@ if (! empty($_REQUEST['target'])) { */ require './libraries/plugins/auth/swekey/swekey.auth.lib.php'; -/** - * phpseclib - */ -if (! function_exists('openssl_encrypt') - || ! function_exists('openssl_decrypt') - || ! function_exists('openssl_random_pseudo_bytes') - || PHP_VERSION_ID < 50304 -) { - include PHPSECLIB_INC_DIR . '/Crypt/AES.php'; - include PHPSECLIB_INC_DIR . '/Crypt/Random.php'; -} - /** * Handles the cookie authentication method * @@ -721,7 +709,7 @@ class AuthenticationCookie extends AuthenticationPlugin private function _getSessionEncryptionSecret() { if (empty($_SESSION['encryption_key'])) { - if ($this->_useOpenSSL()) { + if (self::useOpenSSL()) { $_SESSION['encryption_key'] = openssl_random_pseudo_bytes(256); } else { $_SESSION['encryption_key'] = crypt_random_string(256); @@ -735,7 +723,7 @@ class AuthenticationCookie extends AuthenticationPlugin * * @return boolean */ - private function _useOpenSSL() + public static function useOpenSSL() { return ( function_exists('openssl_encrypt') @@ -756,7 +744,7 @@ class AuthenticationCookie extends AuthenticationPlugin */ public function cookieEncrypt($data, $secret) { - if ($this->_useOpenSSL()) { + if (self::useOpenSSL()) { return openssl_encrypt( $data, 'AES-128-CBC', @@ -790,7 +778,7 @@ class AuthenticationCookie extends AuthenticationPlugin $this->createIV(); } - if ($this->_useOpenSSL()) { + if (self::useOpenSSL()) { return openssl_decrypt( $encdata, 'AES-128-CBC', @@ -813,7 +801,7 @@ class AuthenticationCookie extends AuthenticationPlugin */ public function getIVSize() { - if ($this->_useOpenSSL()) { + if (self::useOpenSSL()) { return openssl_cipher_iv_length('AES-128-CBC'); } $cipher = new Crypt_AES(CRYPT_AES_MODE_CBC); @@ -830,7 +818,7 @@ class AuthenticationCookie extends AuthenticationPlugin */ public function createIV() { - if ($this->_useOpenSSL()) { + if (self::useOpenSSL()) { $this->_cookie_iv = openssl_random_pseudo_bytes( $this->getIVSize() ); @@ -869,3 +857,11 @@ class AuthenticationCookie extends AuthenticationPlugin $this->storePasswordCookie($password); } } + +/** + * phpseclib + */ +if (! AuthenticationCookie::useOpenSSL()) { + include PHPSECLIB_INC_DIR . '/Crypt/AES.php'; + include PHPSECLIB_INC_DIR . '/Crypt/Random.php'; +} \ No newline at end of file