Skip to content

Commit 1d720f0

Browse files
authored
chore: drop eol php 8.0 (#384)
* chore: drop eol php 8.0 * chore: update dependencies Drop EOL `guzzle` https://github.com/guzzle/guzzle#version-guidance * chore: update gh action * chore: migrate to phpunit 10 add type make functions static use attributes instead of annotations add strict_types disable new feature suppression of execution warning/error * feat: run all tests, ignore other test fails * feat: add php-cs-fixer rule * fix: remove outdated polyfill for php before 7.3 `openssl_pkey_derive` is always available with current php and openssl. * fix(cs): add dangling comma
1 parent e9f7564 commit 1d720f0

16 files changed

+140
-156
lines changed

.gitattributes

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
/.gitattributes export-ignore
44
/.github export-ignore
55
/.gitignore export-ignore
6-
/.travis.yml export-ignore
7-
/phpunit.xml.dist export-ignore
6+
/.php-cs-fixer.php export-ignore
87
/README.md export-ignore
8+
/phpstan.neon export-ignore
9+
/phpunit.xml.dist export-ignore
910
/tests export-ignore

.github/workflows/tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ jobs:
1515
tests:
1616
runs-on: ubuntu-latest
1717
strategy:
18+
fail-fast: false
1819
matrix:
19-
php: ['8.0', '8.1', '8.2', '8.3']
20+
php: ['8.1', '8.2', '8.3']
2021
ext: ['curl, mbstring, openssl', 'curl, mbstring, openssl, gmp']
2122

2223
name: PHP ${{ matrix.php }} (${{ matrix.ext }})
@@ -37,7 +38,7 @@ jobs:
3738
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
3839

3940
- name: Cache Composer dependencies
40-
uses: actions/cache@v3
41+
uses: actions/cache@v4
4142
with:
4243
path: ${{ steps.composer-cache.outputs.dir }}
4344
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
@@ -49,9 +50,9 @@ jobs:
4950
- name: Setup node
5051
uses: actions/setup-node@v4
5152
with:
52-
node-version: '18'
53+
node-version: '20'
5354

54-
- name: Install web-push-testing-service
55+
- name: Install web-push-testing server
5556
run: |
5657
npm install -g web-push-testing
5758
@@ -65,7 +66,6 @@ jobs:
6566
run: composer test:typing
6667

6768
- name: Run php-cs-fixer
68-
if: ${{ matrix.php != '8.2' }} # Not supported yet.
6969
run: |
7070
composer test:syntax
7171
composer test:syntax_tests

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ cli.log
77
module.log
88
.vagrant
99
Vagrantfile # temp, may be?
10-
/.phpunit.result.cache
10+
.phpunit.cache/*
1111
.php-cs-fixer.cache
1212
.idea/

.php-cs-fixer.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
// https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/config.rst
3+
4+
$config = new PhpCsFixer\Config();
5+
$rules = [
6+
'@PSR12' => true, // The default rule.
7+
'@PHP81Migration' => true, // Must be the same as the min PHP version.
8+
'blank_line_after_opening_tag' => false, // Do not waste space between <?php and declare.
9+
'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false],
10+
'php_unit_test_class_requires_covers' => true,
11+
'php_unit_method_casing' => true,
12+
// Do not enable by default. These rules require review!! (but they are useful)
13+
// '@PHP80Migration:risky' => true,
14+
// '@PHPUnit100Migration:risky' => true,
15+
];
16+
17+
$config->setRules($rules);
18+
$config->setHideProgress(true);
19+
$config->setRiskyAllowed(true);
20+
21+
return $config;

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ As it is standardized, you don't have to worry about what server type it relies
99

1010
## Requirements
1111

12-
PHP 8.0+ and the following extensions:
12+
PHP 8.1+ and the following extensions:
1313
* gmp (optional but better for performance)
1414
* mbstring
1515
* curl
@@ -21,6 +21,7 @@ There is no support and maintenance for older PHP versions, however you are free
2121
- PHP 7.1: `v3.x-v5.x`
2222
- PHP 7.2: `v6.x`
2323
- PHP 7.3 7.4: `v7.x`
24+
- PHP 8.0: `v8.x`
2425

2526
This README is only compatible with the latest version. Each version of the library has a git tag where the corresponding README can be read.
2627

composer.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,32 @@
1515
"scripts": {
1616
"fix:syntax": "./vendor/bin/php-cs-fixer fix ./src --using-cache=no",
1717
"fix:syntax_tests": "./vendor/bin/php-cs-fixer fix ./tests --using-cache=no",
18-
"test:unit": "./vendor/bin/phpunit --color",
18+
"test:unit": "./vendor/bin/phpunit",
19+
"test:unit_offline": "./vendor/bin/phpunit --exclude-group=online",
1920
"test:typing": "./vendor/bin/phpstan analyse",
2021
"test:syntax": "./vendor/bin/php-cs-fixer fix ./src --dry-run --stop-on-violation --using-cache=no",
2122
"test:syntax_tests": "./vendor/bin/php-cs-fixer fix ./tests --dry-run --stop-on-violation --using-cache=no"
2223
},
2324
"require": {
24-
"php": ">=8.0",
25+
"php": ">=8.1",
2526
"ext-curl": "*",
2627
"ext-json": "*",
2728
"ext-mbstring": "*",
2829
"ext-openssl": "*",
29-
"guzzlehttp/guzzle": "^7.0.1|^6.2",
30-
"web-token/jwt-signature": "^2.0|^3.0.2",
31-
"web-token/jwt-key-mgmt": "^2.0|^3.0.2",
32-
"web-token/jwt-signature-algorithm-ecdsa": "^2.0|^3.0.2",
33-
"web-token/jwt-util-ecc": "^2.0|^3.0.2",
34-
"spomky-labs/base64url": "^2.0"
30+
"guzzlehttp/guzzle": "^7.4.5",
31+
"web-token/jwt-signature": "^3.2.9",
32+
"web-token/jwt-key-mgmt": "^3.2.9",
33+
"web-token/jwt-signature-algorithm-ecdsa": "^3.2.9",
34+
"web-token/jwt-util-ecc": "^3.2.9",
35+
"spomky-labs/base64url": "^2.0.4"
3536
},
3637
"suggest": {
3738
"ext-gmp": "Optional for performance."
3839
},
3940
"require-dev": {
40-
"phpunit/phpunit": "^9.5.27",
41-
"phpstan/phpstan": "^1.9.8",
42-
"friendsofphp/php-cs-fixer": "^v3.13.2"
41+
"phpunit/phpunit": "^10.5.9",
42+
"phpstan/phpstan": "^1.10.57",
43+
"friendsofphp/php-cs-fixer": "^v3.48.0"
4344
},
4445
"autoload": {
4546
"psr-4": {

phpunit.xml.dist

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
3+
backupStaticProperties="false"
44
bootstrap="vendor/autoload.php"
5+
cacheDirectory=".phpunit.cache"
56
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
97
processIsolation="false"
10-
stopOnFailure="false">
8+
stopOnFailure="false"
9+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
11+
>
12+
<source ignoreSuppressionOfDeprecations="true"
13+
ignoreSuppressionOfPhpDeprecations="true"
14+
ignoreSuppressionOfErrors="true"
15+
ignoreSuppressionOfNotices="true"
16+
ignoreSuppressionOfPhpNotices="true"
17+
ignoreSuppressionOfWarnings="true"
18+
ignoreSuppressionOfPhpWarnings="true"
19+
>
20+
<include>
21+
<directory>src</directory>
22+
</include>
23+
</source>
1124
<testsuites>
1225
<testsuite name="WebPush Test Suite">
1326
<directory suffix=".php">./tests/</directory>

src/Encryption.php

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ private static function createLocalKeyObjectUsingPurePhpMethod(): array
255255
'x' => Base64Url::encode(self::addNullPadding($publicKey->getPoint()->getX()->toBytes(false))),
256256
'y' => Base64Url::encode(self::addNullPadding($publicKey->getPoint()->getY()->toBytes(false))),
257257
'd' => Base64Url::encode(self::addNullPadding($privateKey->getSecret()->toBytes(false))),
258-
])
258+
]),
259259
];
260260
}
261261

@@ -266,7 +266,7 @@ private static function createLocalKeyObjectUsingPurePhpMethod(): array
266266
'x' => Base64Url::encode(self::addNullPadding(hex2bin(gmp_strval($publicKey->getPoint()->getX(), 16)))),
267267
'y' => Base64Url::encode(self::addNullPadding(hex2bin(gmp_strval($publicKey->getPoint()->getY(), 16)))),
268268
'd' => Base64Url::encode(self::addNullPadding(hex2bin(gmp_strval($privateKey->getSecret(), 16)))),
269-
])
269+
]),
270270
];
271271
}
272272

@@ -294,7 +294,7 @@ private static function createLocalKeyObjectUsingOpenSSL(): array
294294
'x' => Base64Url::encode(self::addNullPadding($details['ec']['x'])),
295295
'y' => Base64Url::encode(self::addNullPadding($details['ec']['y'])),
296296
'd' => Base64Url::encode(self::addNullPadding($details['ec']['d'])),
297-
])
297+
]),
298298
];
299299
}
300300

@@ -320,68 +320,14 @@ private static function getIKM(string $userAuthToken, string $userPublicKey, str
320320

321321
private static function calculateAgreementKey(JWK $private_key, JWK $public_key): string
322322
{
323-
if (function_exists('openssl_pkey_derive')) {
324-
try {
325-
$publicPem = ECKey::convertPublicKeyToPEM($public_key);
326-
$privatePem = ECKey::convertPrivateKeyToPEM($private_key);
327-
328-
$result = openssl_pkey_derive($publicPem, $privatePem, 256); // @phpstan-ignore-line
329-
if ($result === false) {
330-
throw new \Exception('Unable to compute the agreement key');
331-
}
332-
return $result;
333-
} catch (\Throwable $throwable) {
334-
//Does nothing. Will fallback to the pure PHP function
335-
}
336-
}
337-
323+
$publicPem = ECKey::convertPublicKeyToPEM($public_key);
324+
$privatePem = ECKey::convertPrivateKeyToPEM($private_key);
338325

339-
$curve = NistCurve::curve256();
340-
try {
341-
$rec_x = self::convertBase64ToBigInteger($public_key->get('x'));
342-
$rec_y = self::convertBase64ToBigInteger($public_key->get('y'));
343-
$sen_d = self::convertBase64ToBigInteger($private_key->get('d'));
344-
$priv_key = PrivateKey::create($sen_d);
345-
$pub_key = $curve->getPublicKeyFrom($rec_x, $rec_y);
346-
347-
return hex2bin(str_pad($curve->mul($pub_key->getPoint(), $priv_key->getSecret())->getX()->toBase(16), 64, '0', STR_PAD_LEFT)); // @phpstan-ignore-line
348-
} catch (\Throwable $e) {
349-
$rec_x = self::convertBase64ToGMP($public_key->get('x'));
350-
$rec_y = self::convertBase64ToGMP($public_key->get('y'));
351-
$sen_d = self::convertBase64ToGMP($private_key->get('d'));
352-
$priv_key = PrivateKey::create($sen_d); // @phpstan-ignore-line
353-
$pub_key = $curve->getPublicKeyFrom($rec_x, $rec_y); // @phpstan-ignore-line
354-
355-
return hex2bin(gmp_strval($curve->mul($pub_key->getPoint(), $priv_key->getSecret())->getX(), 16)); // @phpstan-ignore-line
326+
$result = openssl_pkey_derive($publicPem, $privatePem, 256);
327+
if ($result === false) {
328+
throw new \Exception('Unable to compute the agreement key');
356329
}
357-
}
358-
359-
/**
360-
* @throws \ErrorException
361-
*/
362-
private static function convertBase64ToBigInteger(string $value): BigInteger
363-
{
364-
$value = unpack('H*', Base64Url::decode($value));
365-
366-
if ($value === false) {
367-
throw new \ErrorException('Unable to unpack hex value from string');
368-
}
369-
370-
return BigInteger::fromBase($value[1], 16);
371-
}
372-
373-
/**
374-
* @throws \ErrorException
375-
*/
376-
private static function convertBase64ToGMP(string $value): \GMP
377-
{
378-
$value = unpack('H*', Base64Url::decode($value));
379-
380-
if ($value === false) {
381-
throw new \ErrorException('Unable to unpack hex value from string');
382-
}
383-
384-
return gmp_init($value[1], 16);
330+
return $result;
385331
}
386332

387333
private static function addNullPadding(string $data): string

src/VAPID.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public static function createVapidKeys(): array
176176

177177
return [
178178
'publicKey' => Base64Url::encode($binaryPublicKey),
179-
'privateKey' => Base64Url::encode($binaryPrivateKey)
179+
'privateKey' => Base64Url::encode($binaryPrivateKey),
180180
];
181181
}
182182
}

tests/EncryptionTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
<?php
2-
3-
declare(strict_types=1);
4-
1+
<?php declare(strict_types=1);
52
/*
63
* This file is part of the WebPush library.
74
*
@@ -15,7 +12,11 @@
1512
use Jose\Component\Core\JWK;
1613
use Minishlink\WebPush\Encryption;
1714
use Minishlink\WebPush\Utils;
15+
use PHPUnit\Framework\Attributes\DataProvider;
1816

17+
/**
18+
* @covers \Minishlink\WebPush\Encryption
19+
*/
1920
final class EncryptionTest extends PHPUnit\Framework\TestCase
2021
{
2122
public function testDeterministicEncrypt(): void
@@ -75,10 +76,9 @@ public function testGetContentCodingHeader(): void
7576
}
7677

7778
/**
78-
* @dataProvider payloadProvider
79-
*
8079
* @throws ErrorException
8180
*/
81+
#[dataProvider('payloadProvider')]
8282
public function testPadPayload(string $payload, int $maxLengthToPad, int $expectedResLength): void
8383
{
8484
$res = Encryption::padPayload($payload, $maxLengthToPad, "aesgcm");
@@ -87,7 +87,7 @@ public function testPadPayload(string $payload, int $maxLengthToPad, int $expect
8787
$this->assertEquals($expectedResLength, Utils::safeStrlen($res));
8888
}
8989

90-
public function payloadProvider(): array
90+
public static function payloadProvider(): array
9191
{
9292
return [
9393
['testé', 0, 8],

0 commit comments

Comments
 (0)