Require Mbstring and OpenSSL extensions (#1490415) - remove redundant code
1 files deleted
10 files modified
| | |
| | | CHANGELOG Roundcube Webmail |
| | | =========================== |
| | | |
| | | - Require Mbstring and OpenSSL extensions (#1490415) |
| | | - Get rid of Mail_mimeDecode package dependency (#1490416) |
| | | - Add --config and --type options to moduserprefs.sh script (#1490051) |
| | | - Implemented memcache_debug and apc_debug options |
| | |
| | | * The Apache, Lighttpd, Cherokee or Hiawatha web server |
| | | * .htaccess support allowing overrides for DirectoryIndex |
| | | * PHP Version 5.3.7 or greater including |
| | | - PCRE, DOM, JSON, Session, Sockets (required) |
| | | - PCRE, DOM, JSON, Session, Sockets, OpenSSL, Mbstring (required) |
| | | - PHP Data Objects (PDO) with driver for either MySQL, PostgreSQL or SQLite (required) |
| | | - Libiconv, Zip (recommended) |
| | | - OpenSSL, Fileinfo, Mcrypt, mbstring (optional) |
| | | - Libiconv, Zip, Fileinfo (recommended) |
| | | * PEAR packages distributed with Roundcube or external: |
| | | - Mail_Mime 1.8.1 or newer |
| | | - Net_SMTP (latest from https://github.com/pear/Net_SMTP/) |
| | |
| | | "pear-pear.php.net/net_idna2": ">=0.1.1", |
| | | "pear-pear.php.net/net_sieve": ">=1.3.2", |
| | | "pear/mail_mime": ">=1.8.9", |
| | | "pear/net_smtp": "dev-master", |
| | | "patchwork/utf8": "1.2.x" |
| | | "pear/net_smtp": "dev-master" |
| | | }, |
| | | "require-dev": { |
| | | "pear-pear.php.net/crypt_gpg": "*", |
| | |
| | | 'XML' => 'xml', |
| | | 'JSON' => 'json', |
| | | 'PDO' => 'PDO', |
| | | 'Multibyte' => 'mbstring', |
| | | 'OpenSSL' => 'openssl', |
| | | ); |
| | | |
| | | $optional_php_exts = array( |
| | | 'FileInfo' => 'fileinfo', |
| | | 'Libiconv' => 'iconv', |
| | | 'Multibyte' => 'mbstring', |
| | | 'OpenSSL' => 'openssl', |
| | | 'Mcrypt' => 'mcrypt', |
| | | 'Intl' => 'intl', |
| | | 'Exif' => 'exif', |
| | | 'LDAP' => 'ldap', |
| | |
| | | 'FileInfo' => 'http://www.php.net/manual/en/book.fileinfo.php', |
| | | 'Libiconv' => 'http://www.php.net/manual/en/book.iconv.php', |
| | | 'Multibyte' => 'http://www.php.net/manual/en/book.mbstring.php', |
| | | 'Mcrypt' => 'http://www.php.net/manual/en/book.mcrypt.php', |
| | | 'OpenSSL' => 'http://www.php.net/manual/en/book.openssl.php', |
| | | 'JSON' => 'http://www.php.net/manual/en/book.json.php', |
| | | 'DOM' => 'http://www.php.net/manual/en/book.dom.php', |
| | |
| | | // backward compatybility (to be removed) |
| | | require_once INSTALL_PATH . 'program/include/bc.php'; |
| | | |
| | | // load the UTF-8 portability layers from Patchwork |
| | | // don't load mbstring layer as it conflicts with Roundcube Framework (#1490280) |
| | | if (!function_exists('iconv')) { |
| | | \Patchwork\Utf8\Bootup::initIconv(); |
| | | } |
| | | if (!function_exists('utf8_encode')) { |
| | | \Patchwork\Utf8\Bootup::initUtf8Encode(); |
| | | } |
| | | |
| | | /** |
| | | * PHP5 autoloader routine for dynamic class loading |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * mbstring replacement functions |
| | | */ |
| | | if (!extension_loaded('mbstring')) |
| | | { |
| | | function mb_strlen($str) |
| | | { |
| | | return strlen($str); |
| | | } |
| | | |
| | | function mb_strtolower($str) |
| | | { |
| | | return strtolower($str); |
| | | } |
| | | |
| | | function mb_strtoupper($str) |
| | | { |
| | | return strtoupper($str); |
| | | } |
| | | |
| | | function mb_substr($str, $start, $len=null) |
| | | { |
| | | return substr($str, $start, $len); |
| | | } |
| | | |
| | | function mb_strpos($haystack, $needle, $offset=0) |
| | | { |
| | | return strpos($haystack, $needle, $offset); |
| | | } |
| | | |
| | | function mb_strrpos($haystack, $needle, $offset=0) |
| | | { |
| | | return strrpos($haystack, $needle, $offset); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * intl replacement functions |
| | | */ |
| | | |
| | |
| | | // upon decryption; see http://php.net/mcrypt_generic#68082. |
| | | $clear = pack("a*H2", $clear, "80"); |
| | | $ckey = $this->config->get_crypto_key($key); |
| | | |
| | | if (function_exists('openssl_encrypt')) { |
| | | $method = 'DES-EDE3-CBC'; |
| | | $opts = defined('OPENSSL_RAW_DATA') ? OPENSSL_RAW_DATA : true; |
| | | $iv = $this->create_iv(openssl_cipher_iv_length($method)); |
| | | $iv = rcube_utils::random_bytes(openssl_cipher_iv_length($method), true); |
| | | $cipher = $iv . openssl_encrypt($clear, $method, $ckey, $opts, $iv); |
| | | } |
| | | else if (function_exists('mcrypt_module_open') && |
| | | ($td = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_CBC, "")) |
| | | ) { |
| | | $iv = $this->create_iv(mcrypt_enc_get_iv_size($td)); |
| | | mcrypt_generic_init($td, $ckey, $iv); |
| | | $cipher = $iv . mcrypt_generic($td, $clear); |
| | | mcrypt_generic_deinit($td); |
| | | mcrypt_module_close($td); |
| | | } |
| | | else { |
| | | @include_once 'des.inc'; |
| | | |
| | | if (function_exists('des')) { |
| | | $des_iv_size = 8; |
| | | $iv = $this->create_iv($des_iv_size); |
| | | $cipher = $iv . des($ckey, $clear, 1, 1, $iv); |
| | | } |
| | | else { |
| | | self::raise_error(array( |
| | | 'code' => 500, 'type' => 'php', |
| | | 'file' => __FILE__, 'line' => __LINE__, |
| | | 'message' => "Could not perform encryption; make sure OpenSSL or Mcrypt or lib/des.inc is available" |
| | | ), true, true); |
| | | } |
| | | } |
| | | |
| | | return $base64 ? base64_encode($cipher) : $cipher; |
| | | } |
| | |
| | | $cipher = $base64 ? base64_decode($cipher) : $cipher; |
| | | $ckey = $this->config->get_crypto_key($key); |
| | | |
| | | if (function_exists('openssl_decrypt')) { |
| | | $method = 'DES-EDE3-CBC'; |
| | | $opts = defined('OPENSSL_RAW_DATA') ? OPENSSL_RAW_DATA : true; |
| | | $iv_size = openssl_cipher_iv_length($method); |
| | |
| | | |
| | | $cipher = substr($cipher, $iv_size); |
| | | $clear = openssl_decrypt($cipher, $method, $ckey, $opts, $iv); |
| | | } |
| | | else if (function_exists('mcrypt_module_open') && |
| | | ($td = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_CBC, "")) |
| | | ) { |
| | | $iv_size = mcrypt_enc_get_iv_size($td); |
| | | $iv = substr($cipher, 0, $iv_size); |
| | | |
| | | // session corruption? (#1485970) |
| | | if (strlen($iv) < $iv_size) { |
| | | return ''; |
| | | } |
| | | |
| | | $cipher = substr($cipher, $iv_size); |
| | | mcrypt_generic_init($td, $ckey, $iv); |
| | | $clear = mdecrypt_generic($td, $cipher); |
| | | mcrypt_generic_deinit($td); |
| | | mcrypt_module_close($td); |
| | | } |
| | | else { |
| | | @include_once 'des.inc'; |
| | | |
| | | if (function_exists('des')) { |
| | | $des_iv_size = 8; |
| | | $iv = substr($cipher, 0, $des_iv_size); |
| | | $cipher = substr($cipher, $des_iv_size); |
| | | $clear = des($ckey, $cipher, 0, 1, $iv); |
| | | } |
| | | else { |
| | | self::raise_error(array( |
| | | 'code' => 500, 'type' => 'php', |
| | | 'file' => __FILE__, 'line' => __LINE__, |
| | | 'message' => "Could not perform decryption; make sure OpenSSL or Mcrypt or lib/des.inc is available" |
| | | ), true, true); |
| | | } |
| | | } |
| | | |
| | | // Trim PHP's padding and the canary byte; see note in |
| | | // rcube::encrypt() and http://php.net/mcrypt_generic#68082 |
| | | $clear = substr(rtrim($clear, "\0"), 0, -1); |
| | | |
| | | return $clear; |
| | | } |
| | | |
| | | /** |
| | | * Generates encryption initialization vector (IV) |
| | | * |
| | | * @param int $size Vector size |
| | | * |
| | | * @return string Vector string |
| | | */ |
| | | private function create_iv($size) |
| | | { |
| | | // mcrypt_create_iv() can be slow when system lacks entrophy |
| | | // we'll generate IV vector manually |
| | | $iv = ''; |
| | | for ($i = 0; $i < $size; $i++) { |
| | | $iv .= chr(mt_rand(0, 255)); |
| | | } |
| | | |
| | | return $iv; |
| | | } |
| | | |
| | | /** |
| | |
| | | // Note: Never try to use iconv instead of mbstring functions here |
| | | // Iconv's substr/strlen are 100x slower (#1489113) |
| | | |
| | | if ($charset && $charset != RCUBE_CHARSET && function_exists('mb_internal_encoding')) { |
| | | if ($charset && $charset != RCUBE_CHARSET) { |
| | | mb_internal_encoding($charset); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | if ($charset && $charset != RCUBE_CHARSET && function_exists('mb_internal_encoding')) { |
| | | if ($charset && $charset != RCUBE_CHARSET) { |
| | | mb_internal_encoding(RCUBE_CHARSET); |
| | | } |
| | | |
| | |
| | | /** |
| | | * Generate a ramdom string |
| | | * |
| | | * @param int String length |
| | | * @param int $length String length |
| | | * @param bool $raw Return RAW data instead of hex |
| | | * |
| | | * @return string The generated random string |
| | | */ |
| | | public static function random_bytes($length) |
| | | public static function random_bytes($length, $raw = false) |
| | | { |
| | | if (function_exists('openssl_random_pseudo_bytes')) { |
| | | $random = openssl_random_pseudo_bytes(ceil($length / 2)); |
| | | $rlen = $raw ? $length : ceil($length / 2); |
| | | $random = openssl_random_pseudo_bytes($rlen); |
| | | |
| | | if ($raw) { |
| | | return $random; |
| | | } |
| | | |
| | | $random = bin2hex($random); |
| | | |
| | | // if the length wasn't even... |
| | | if ($length < strlen($random)) { |
| | | $random = substr($random, 0, $length); |
| | | } |
| | | } |
| | | else { |
| | | $alpha = 'ABCDEFGHIJKLMNOPQERSTUVXYZabcdefghijklmnopqrtsuvwxyz0123456789+*%&?!$-_='; |
| | | $random = ''; |
| | | |
| | | for ($i = 0; $i < $length; $i++) { |
| | | $random .= $alpha[rand(0, strlen($alpha)-1)]; |
| | | } |
| | | } |
| | | |
| | | return $random; |
| | |
| | | function test_random_bytes() |
| | | { |
| | | $this->assertSame(15, strlen(rcube_utils::random_bytes(15))); |
| | | $this->assertSame(15, strlen(rcube_utils::random_bytes(15, true))); |
| | | $this->assertSame(1, strlen(rcube_utils::random_bytes(1))); |
| | | $this->assertSame(0, strlen(rcube_utils::random_bytes(0))); |
| | | $this->assertSame(0, strlen(rcube_utils::random_bytes(-1))); |