From 7d0058045a68c36b8aa64bdf4e76987d4cfec353 Mon Sep 17 00:00:00 2001 From: Mark Hamstra Date: Fri, 5 Jun 2020 14:14:24 +0200 Subject: [PATCH] Make cipher checking case-insensitive --- .../model/filelister/filelister.class.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/core/components/filelister/model/filelister/filelister.class.php b/core/components/filelister/model/filelister/filelister.class.php index b415175..9e7f46a 100644 --- a/core/components/filelister/model/filelister/filelister.class.php +++ b/core/components/filelister/model/filelister/filelister.class.php @@ -180,14 +180,18 @@ private function _encrypt($str) { $key = md5($key); /* to improve variance */ $cipher = "DES-CFB"; - if (in_array($cipher, openssl_get_cipher_methods())) - { + $available = openssl_get_cipher_methods(); + $available = array_map('strtoupper', $available); + if (in_array($cipher, $available)) { $ivlen = openssl_cipher_iv_length($cipher); $iv = openssl_random_pseudo_bytes($ivlen); $ciphertext = openssl_encrypt($str, $cipher, $key, 0, $iv); $ciphertext = $iv . $ciphertext; return urlencode($ciphertext); } + else { + $this->modx->log(modX::LOG_LEVEL_ERROR, "Cipher {$cipher} is not available on the server, FileLister cannot encrypt string."); + } } /** @@ -204,13 +208,17 @@ private function _decrypt($str) { $key = md5($key); $cipher = "DES-CFB"; - if (in_array($cipher, openssl_get_cipher_methods())) - { + $available = openssl_get_cipher_methods(); + $available = array_map('strtoupper', $available); + if (in_array($cipher, $available)) { $ivlen = openssl_cipher_iv_length($cipher); $iv = substr($str,0,$ivlen); $str = substr($str,$ivlen); return openssl_decrypt($str, $cipher, $key, 0, $iv); } + else { + $this->modx->log(modX::LOG_LEVEL_ERROR, "Cipher {$cipher} is not available on the server, FileLister cannot decrypt string."); + } } /** @@ -294,4 +302,4 @@ public function renderFile($path) { readfile($absolutePath); } } -} \ No newline at end of file +}