From cf10e0766029375198e6c37550113653835b6e42 Mon Sep 17 00:00:00 2001 From: Vitaliy Zaytsev Date: Mon, 25 Aug 2014 19:03:24 +0700 Subject: [PATCH 1/2] Error: "Constant CRYPT_RSA_MODE already defined" It happens if defined(MATH_BIGINTEGER_OPENSSL_DISABLE) && !function_exists('openssl_pkey_get_details') --- phpseclib/Crypt/RSA.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index 9a4a600d..d2f22be1 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -493,14 +493,13 @@ class Crypt_RSA $this->configFile = CRYPT_RSA_OPENSSL_CONFIG; if ( !defined('CRYPT_RSA_MODE') ) { - // Math/BigInteger's openssl requirements are a little less stringent than Crypt/RSA's. in particular, - // Math/BigInteger doesn't require an openssl.cfg file whereas Crypt/RSA does. so if Math/BigInteger - // can't use OpenSSL it can be pretty trivially assumed, then, that Crypt/RSA can't either. - if ( defined('MATH_BIGINTEGER_OPENSSL_DISABLE') ) { - define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL); - } - - switch ( !defined('CRYPT_RSA_MODE') ) { // ie. only run this if the above didn't set CRYPT_RSA_MODE already + switch (true) { + // Math/BigInteger's openssl requirements are a little less stringent than Crypt/RSA's. in particular, + // Math/BigInteger doesn't require an openssl.cfg file whereas Crypt/RSA does. so if Math/BigInteger + // can't use OpenSSL it can be pretty trivially assumed, then, that Crypt/RSA can't either. + case defined('MATH_BIGINTEGER_OPENSSL_DISABLE'): + define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL); + break; // openssl_pkey_get_details - which is used in the only place Crypt/RSA.php uses OpenSSL - was introduced in PHP 5.2.0 case !function_exists('openssl_pkey_get_details'): define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL); From 2ee0529c9d65154b7092a729dfc198da0290d952 Mon Sep 17 00:00:00 2001 From: Vitaliy Zaytsev Date: Mon, 25 Aug 2014 19:58:38 +0700 Subject: [PATCH 2/2] Replaced "case true:" with "default:" --- phpseclib/Crypt/RSA.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index d2f22be1..dd18bc26 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -532,7 +532,7 @@ class Crypt_RSA define('MATH_BIGINTEGER_OPENSSL_DISABLE', true); } break; - case true: + default: define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL); } }