Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit tests Encryption_test::test_initialize_encrypt_decrypt fails with OpenSSL3 #6171

Closed
tenzap opened this issue Nov 5, 2022 · 3 comments
Closed

Comments

@tenzap
Copy link
Contributor

tenzap commented Nov 5, 2022

running the unit tests of CI3 leads to 1 error and 9 deprecation notices:

Deprecation notices:

There were 9 errors:

1) URI_test::test_filter_uri_passing
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property URI_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41
PHP Deprecated:  Creation of dynamic property Mock_Core_URI::$config is deprecated in /path_to_ci/CodeIgniter/tests/mocks/core/uri.php on line 19
PHP Deprecated:  Creation of dynamic property URI_test::$uri is deprecated in /path_to_ci/CodeIgniter/tests/codeigniter/core/URI_test.php on line 7

2) URI_test::test_filter_uri_throws_error
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property URI_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41
PHP Deprecated:  Creation of dynamic property Mock_Core_URI::$config is deprecated in /path_to_ci/CodeIgniter/tests/mocks/core/uri.php on line 19
PHP Deprecated:  Creation of dynamic property URI_test::$uri is deprecated in /path_to_ci/CodeIgniter/tests/codeigniter/core/URI_test.php on line 7

3) Utf8_test::test___constructUTF8_ENABLED
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property Utf8_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41

4) Utf8_test::test__constructUTF8_DISABLED
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property Utf8_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41

5) Utf8_test::test_is_ascii
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property Utf8_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41

6) Utf8_test::test_convert_to_utf8
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property Utf8_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41

7) Text_helper_test::test_highlight_phrase
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property Text_helper_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41

8) Url_helper_test::test_url_title
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property Url_helper_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41

9) Url_helper_test::test_url_title_extra_dashes
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property Url_helper_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41

--

Failures

There was 1 failure:

1) Encryption_test::test_initialize_encrypt_decrypt
Failed asserting that false matches expected 'This is a plain-text message.'.

/path_to_ci/CodeIgniter/tests/codeigniter/libraries/Encryption_test.php:212
/path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php:351

ERRORS!
Tests: 337, Assertions: 1076, Errors: 9, Failures: 1, Skipped: 25.

@tenzap
Copy link
Contributor Author

tenzap commented Nov 6, 2022

PR #6173 fixes the deprecation warnings.
However, concerning the failure, it is different, so I will rename the title so that it is related to OpenSSL3.

With OpenSSL3, some ciphers are not available anymore when the legacy
provider is not enabled. Especially, 'des' cypher is provided by the legacy
provider in OpenSSL3, and the legacy provider is not enabled by default.

This leads to the failure of Encryption_test::test_initialize_encrypt_decrypt test.

See: https://wiki.openssl.org/index.php/OpenSSL_3.0#Providers

The legacy provider. This is a collection of legacy algorithms that are either no longer in common use or strongly discouraged from use. However some applications may need to use these algorithms for backwards compatibility reasons. This provider is NOT loaded by default. This may mean that some applications upgrading from earlier versions of OpenSSL may find that some algorithms are no longer available unless they load the legacy provider explicitly. Algorithms in the legacy provider include MD2, MD4, MDC2, RMD160, CAST5, BF (Blowfish), IDEA, SEED, RC2, RC4, RC5 and DES (but not 3DES).

Since the test uses

$this->encryption->initialize(array('cipher' => 'des', 'mode' => 'ecb', 'key' => substr($key, 0, 8)));

it fails.

So a solution would be to use another cipher: "tripledes" instead of "des"

--- a/tests/codeigniter/libraries/Encryption_test.php
+++ b/tests/codeigniter/libraries/Encryption_test.php
@@ -208,7 +208,7 @@ class Encryption_test extends CI_TestCase {
 		$this->assertEquals($message, $this->encryption->decrypt($this->encryption->encrypt($message)));
 
 		// Try DES in ECB mode, just for the sake of changing stuff
-		$this->encryption->initialize(array('cipher' => 'des', 'mode' => 'ecb', 'key' => substr($key, 0, 8)));
+		$this->encryption->initialize(array('cipher' => 'tripledes', 'mode' => 'ecb', 'key' => substr($key, 0, 8)));
 		$this->assertEquals($message, $this->encryption->decrypt($this->encryption->encrypt($message)));
 	}
 

@tenzap tenzap changed the title unit tests with php8.2 failures unit tests Encryption_test::test_initialize_encrypt_decrypt files with OpenSSL3 Nov 6, 2022
@tenzap tenzap changed the title unit tests Encryption_test::test_initialize_encrypt_decrypt files with OpenSSL3 unit tests Encryption_test::test_initialize_encrypt_decrypt fails with OpenSSL3 Nov 6, 2022
@tenzap
Copy link
Contributor Author

tenzap commented Jun 24, 2023

Another solution which would make it work for both openssl 1 & 3

--- a/tests/codeigniter/libraries/Encryption_test.php
+++ b/tests/codeigniter/libraries/Encryption_test.php
@@ -208,7 +208,11 @@
 		$this->assertEquals($message, $this->encryption->decrypt($this->encryption->encrypt($message)));
 
 		// Try DES in ECB mode, just for the sake of changing stuff
-		$this->encryption->initialize(array('cipher' => 'des', 'mode' => 'ecb', 'key' => substr($key, 0, 8)));
+		if(OPENSSL_VERSION_NUMBER >= 0x3000000f) {
+			$this->encryption->initialize(array('cipher' => 'tripledes', 'mode' => 'ecb', 'key' => substr($key, 0, 8)));
+		} else {
+			$this->encryption->initialize(array('cipher' => 'des', 'mode' => 'ecb', 'key' => substr($key, 0, 8)));
+		}
 		$this->assertEquals($message, $this->encryption->decrypt($this->encryption->encrypt($message)));
 	}
 

@gxgpet
Copy link
Contributor

gxgpet commented Jan 14, 2024

Fixed via #6261.

We might consider the OpenSSL version/similar solution in the future, but for now, I marked the test as skipped for older PHP versions only.

@gxgpet gxgpet closed this as completed Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants