1
0
mirror of https://github.com/danog/tgseclib.git synced 2025-01-22 05:51:20 +01:00

RSA, BigInteger: add more openssl checks

This commit is contained in:
terrafrost 2013-09-10 11:07:56 -05:00
parent 56f1b6f411
commit 54f0f2131b
2 changed files with 49 additions and 3 deletions

View File

@ -469,7 +469,31 @@ class Crypt_RSA {
if ( !defined('CRYPT_RSA_MODE') ) {
switch (true) {
case extension_loaded('openssl') && version_compare(PHP_VERSION, '4.2.0', '>=') && file_exists($this->configFile):
define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_OPENSSL);
// some versions of XAMPP have mismatched versions of OpenSSL which causes it not to work
ob_start();
phpinfo();
$content = ob_get_contents();
ob_end_clean();
preg_match_all('#OpenSSL (Header|Library) Version(.*)#im', $content, $matches);
$versions = array();
if (!empty($matches[1])) {
for ($i = 0; $i < count($matches[1]); $i++) {
$versions[$matches[1][$i]] = trim(str_replace('=>', '', strip_tags($matches[2][$i])));
}
}
switch (true) {
case !isset($versions['Header']):
case !isset($versions['Library']):
case $versions['Header'] != $versions['Library']:
define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);
define('MATH_BIGINTEGER_OPENSSL_DISABLE', true);
break;
default:
define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_OPENSSL);
}
break;
default:
define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);

View File

@ -272,7 +272,30 @@ class Math_BigInteger {
}
if (function_exists('openssl_public_encrypt') && !defined('MATH_BIGINTEGER_OPENSSL_DISABLE') && !defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) {
define('MATH_BIGINTEGER_OPENSSL_ENABLED', true);
// some versions of XAMPP have mismatched versions of OpenSSL which causes it not to work
ob_start();
phpinfo();
$content = ob_get_contents();
ob_end_clean();
preg_match_all('#OpenSSL (Header|Library) Version(.*)#im', $content, $matches);
$versions = array();
if (!empty($matches[1])) {
for ($i = 0; $i < count($matches[1]); $i++) {
$versions[$matches[1][$i]] = trim(str_replace('=>', '', strip_tags($matches[2][$i])));
}
}
switch (true) {
case !isset($versions['Header']):
case !isset($versions['Library']):
case $versions['Header'] != $versions['Library']:
define('MATH_BIGINTEGER_OPENSSL_DISABLE', true);
break;
default:
define('MATH_BIGINTEGER_OPENSSL_ENABLED', true);
}
}
if (!defined('PHP_INT_SIZE')) {
@ -438,7 +461,6 @@ class Math_BigInteger {
}
$x = str_pad($x, strlen($x) + ((MATH_BIGINTEGER_MAX10_LEN - 1) * strlen($x)) % MATH_BIGINTEGER_MAX10_LEN, 0, STR_PAD_LEFT);
while (strlen($x)) {
$temp = $temp->multiply($multiplier);
$temp = $temp->add(new Math_BigInteger($this->_int2bytes(substr($x, 0, MATH_BIGINTEGER_MAX10_LEN)), 256));