Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Add PHP 8.0 support, require PHP 7.3 or newer #11

Merged
merged 6 commits into from
Feb 11, 2021
Merged

Add PHP 8.0 support, require PHP 7.3 or newer #11

merged 6 commits into from
Feb 11, 2021

Conversation

bfoosness
Copy link
Contributor

Q A
New Feature yes

Description

Close #10

@@ -27,8 +27,8 @@ public function setUp(): void

public function testCalc()
{
if (! extension_loaded('mhash')) {
$this->markTestSkipped('The mhash extension is not available');
if (! extension_loaded('hash')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.php.net/manual/en/intro.mhash.php

As of PHP 7.0.0 the Mhash extension has been fully integrated into the Hash extension. Therefore, it is no longer possible to detect Mhash support with extension_loaded(); use function_exists() instead. Furthermore, Mhash is no longer reported by get_loaded_extensions() and related features.

A check is still needed for 7.3: https://www.php.net/manual/en/hash.installation.php

As of PHP 7.4.0, the Hash extension is a core PHP extension, so it is always enabled.

Given that, I think this is the correct solution, but let me know if this should change.

Copy link
Contributor Author

@bfoosness bfoosness Dec 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though looking at the failed tests (Use of undefined constant MHASH_ADLER32 - assumed 'MHASH_ADLER32') in my build and #8, I suspect there's a better solution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we need to check for both 'hash' && PHP_VERSION_ID >= 80000 and 'mhash' && PHP_VERSION_ID < 80000?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue I'm having is that I can't reproduce this locally in either 7.3 or 7.4 using the official php docker images. This test isn't skipped for me, but I'm not seeing the same error either.

If I'm understanding the docs correctly, checking for the mhash extension is no longer possible as of PHP 7.0 (you should check for hash instead), and checking for hash is only necessary for <= PHP 7.3 because it's always enabled in later versions.

1) LaminasTest\Crypt\Key\Derivation\SaltedS2kTest::testCalc
Use of undefined constant MHASH_ADLER32 - assumed 'MHASH_ADLER32' (this will throw an Error in a future version of PHP)

It seems like this error is due strictly to the presence of the MHASH_ADLER32 constant because this test isn't even using that algo, and presumably the next constant in the list would trigger the same error.

It seems like SaltedS2k::calc should be ported to the Hash extension instead, but there's no equivalent to mhash_keygen_s2k in that extension. I think we're in a weird spot where mhash_keygen_s2k is still available, but none of its constants are. Would it be acceptable to drop support for the salted S2K algo? Or should we attempt a userland solution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add to this, I believe this issue has been a problem for awhile, but this test was always being skipped:

55) LaminasTest\Crypt\Key\Derivation\SaltedS2kTest::testCalc
The mhash extension is not available

{
public function setUp(): void
{
if (PHP_VERSION_ID >= 70100) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed any skipped tests like this.

composer.json Show resolved Hide resolved
@glensc
Copy link

glensc commented Jan 14, 2021

As you changed requirements with the changes in this PR, can you fill such details to PR body?

@Ocramius Ocramius changed the title Add PHP 8.0 support Add PHP 8.0 support, require PHP 7.3 or newer Jan 18, 2021
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patch looks good, but we do indeed need to fix these before merging:

There were 4 errors:

1) LaminasTest\Crypt\Key\Derivation\SaltedS2kTest::testCalc

Use of undefined constant MHASH_ADLER32 - assumed 'MHASH_ADLER32' (this will throw an Error in a future version of PHP)

/home/travis/build/laminas/laminas-crypt/src/Key/Derivation/SaltedS2k.php:68

/home/travis/build/laminas/laminas-crypt/test/Key/Derivation/SaltedS2kTest.php:35

2) LaminasTest\Crypt\Key\Derivation\SaltedS2kTest::testCalcWithWrongHash

Use of undefined constant MHASH_ADLER32 - assumed 'MHASH_ADLER32' (this will throw an Error in a future version of PHP)

/home/travis/build/laminas/laminas-crypt/src/Key/Derivation/SaltedS2k.php:68

/home/travis/build/laminas/laminas-crypt/test/Key/Derivation/SaltedS2kTest.php:52

3) LaminasTest\Crypt\Key\Derivation\SaltedS2kTest::testCalcWithWrongSalt

Use of undefined constant MHASH_ADLER32 - assumed 'MHASH_ADLER32' (this will throw an Error in a future version of PHP)

/home/travis/build/laminas/laminas-crypt/src/Key/Derivation/SaltedS2k.php:68

/home/travis/build/laminas/laminas-crypt/test/Key/Derivation/SaltedS2kTest.php:64

4) LaminasTest\Crypt\Symmetric\OpensslAeadTest::testCcmEncryptWithTagSize

openssl_encrypt(): Setting tag length for AEAD cipher failed

/home/travis/build/laminas/laminas-crypt/src/Symmetric/Openssl.php:570

/home/travis/build/laminas/laminas-crypt/test/Symmetric/OpensslAeadTest.php:196

@@ -27,8 +27,8 @@ public function setUp(): void

public function testCalc()
{
if (! extension_loaded('mhash')) {
$this->markTestSkipped('The mhash extension is not available');
if (! extension_loaded('hash')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we need to check for both 'hash' && PHP_VERSION_ID >= 80000 and 'mhash' && PHP_VERSION_ID < 80000?

@bfoosness
Copy link
Contributor Author

Thanks, I'll take a look today. In the meantime, laminas/laminas-math#5 is a blocker and I think it's ready to go.

@@ -190,11 +190,11 @@ public function testCcmEncryptWithTagSize()
$this->crypt->setMode('ccm');
$this->crypt->setKey(random_bytes($this->crypt->getKeySize()));
$this->crypt->setSalt(random_bytes($this->crypt->getSaltSize()));
$this->crypt->setTagSize(24);
$this->crypt->setTagSize(14);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test has also been broken for awhile now, but this change fixes it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i saw that before and wondered how it ever worked, the tag size is max 16 for that
"In CCM, the authentication tag τ is of variable length: it is permitted to be 4, 6, 8, 10, 12, 14, or 16 bytes long."
https://csrc.nist.gov/CSRC/media/Projects/Block-Cipher-Techniques/documents/BCM/Comments/800-38-series-drafts/CCM/RW_CCM_comments.pdf

@weierophinney weierophinney changed the base branch from master to 3.4.x February 11, 2021 18:12
Signed-off-by: Matthew Weier O'Phinney <[email protected]>
Exclusions are no longer relevant, as they target PHP versions no longer supported with this patch.

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
@weierophinney weierophinney added this to the 3.4.0 milestone Feb 11, 2021
@weierophinney
Copy link
Member

@bfoosness I've rebased your branch off the new 3.4.x branch, which contains our GHA CI workflow, and pushed the changes back; make sure you pull!

Because I rebased... I'm not sure if you've incorporated all feedback yet. Can you drop me a note and let me know?

@bfoosness
Copy link
Contributor Author

@weierophinney: Thank you! I believe #11 (review) was the only outstanding issue, and it's related to the conversation at #11 (comment)

I couldn't reproduce these failures locally, and the tests now appear to pass with the GHA CI workflow.

@weierophinney weierophinney merged commit a058eeb into laminas:3.4.x Feb 11, 2021
@bfoosness bfoosness deleted the php-8.0 branch February 11, 2021 20:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PHP 8.0 support
5 participants