Skip to content

Commit 4a05eb0

Browse files
authored
Replace PHP_EOL with "\n" in certificate processing (#574)
* Replace PHP_EOL with "\n" in certificate processing The PHP_EOL constant used in certificate processing has been replaced with "\n". This change impacts multiple files including KeyConverter.php, ECKey.php, and X5UFactory.php. The commit ensures consistent use of line breaks across various operating systems.
1 parent 8ea122f commit 4a05eb0

File tree

13 files changed

+74
-67
lines changed

13 files changed

+74
-67
lines changed

composer.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
"ext-openssl": "*",
5454
"ext-sodium": "*",
5555
"brick/math": "^0.9|^0.10|^0.11|^0.12",
56-
"paragonie/constant_time_encoding": "^2.6",
57-
"paragonie/sodium_compat": "^1.20",
56+
"paragonie/constant_time_encoding": "^2.6|^3.0",
57+
"paragonie/sodium_compat": "^1.20|^2.0",
5858
"psr/cache": "^3.0",
5959
"psr/clock": "^1.0",
6060
"psr/event-dispatcher": "^1.0",
@@ -75,7 +75,7 @@
7575
"ext-gmp": "*",
7676
"bjeavons/zxcvbn-php": "^1.3",
7777
"ekino/phpstan-banned-code": "^1.0",
78-
"infection/infection": "^0.27",
78+
"infection/infection": "^0.29",
7979
"matthiasnoback/symfony-config-test": "^5.0",
8080
"nyholm/psr7": "^1.8",
8181
"php-http/mock-client": "^1.5",
@@ -86,17 +86,17 @@
8686
"phpstan/phpstan-deprecation-rules": "^1.0",
8787
"phpstan/phpstan-phpunit": "^1.1",
8888
"phpstan/phpstan-strict-rules": "^1.4",
89-
"phpunit/phpunit": "^10.1",
90-
"qossmic/deptrac-shim": "^1.0",
89+
"phpunit/phpunit": "^10.1|^11.0",
90+
"qossmic/deptrac": "^2.0",
9191
"rector/rector": "^1.0",
9292
"roave/security-advisories": "dev-latest",
93-
"symfony/browser-kit": "^6.1|^7.0",
94-
"symfony/finder": "^6.1|^7.0",
95-
"symfony/framework-bundle": "^6.1|^7.0",
96-
"symfony/phpunit-bridge": "^6.1|^7.0",
97-
"symfony/serializer": "^6.1|^7.0",
98-
"symfony/var-dumper": "^6.1|^7.0",
99-
"symfony/yaml": "^6.1|^7.0",
93+
"symfony/browser-kit": "^5.4|^6.0|^7.0",
94+
"symfony/finder": "^5.4|^6.0|^7.0",
95+
"symfony/framework-bundle": "^5.4|^6.0|^7.0",
96+
"symfony/phpunit-bridge": "^5.4|^6.0|^7.0",
97+
"symfony/serializer": "^5.4|^6.0|^7.0",
98+
"symfony/var-dumper": "^5.4|^6.0|^7.0",
99+
"symfony/yaml": "^5.4|^6.0|^7.0",
100100
"symplify/easy-coding-standard": "^12.0"
101101
},
102102
"replace": {

deptrac.yaml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,40 @@ parameters:
44
layers:
55
- name: 'Core'
66
collectors:
7-
- { type: className, regex: '^Jose\\Component\\Core\\' }
7+
- { type: classLike, value: '^Jose\\Component\\Core\\' }
88
- name: 'Checker'
99
collectors:
10-
- { type: className, regex: '^Jose\\Component\\Checker\\' }
10+
- { type: classLike, value: '^Jose\\Component\\Checker\\' }
1111
- name: 'Console'
1212
collectors:
13-
- { type: className, regex: '^Jose\\Component\\Console\\' }
13+
- { type: classLike, value: '^Jose\\Component\\Console\\' }
1414
- name: 'KeyManagement'
1515
collectors:
16-
- { type: className, regex: '^Jose\\Component\\KeyManagement\\' }
16+
- { type: classLike, value: '^Jose\\Component\\KeyManagement\\' }
1717
- name: 'NestedToken'
1818
collectors:
19-
- { type: className, regex: '^Jose\\Component\\NestedToken\\' }
19+
- { type: classLike, value: '^Jose\\Component\\NestedToken\\' }
2020
- name: 'Encryption'
2121
collectors:
22-
- { type: className, regex: '^Jose\\Component\\Encryption\\' }
22+
- { type: classLike, value: '^Jose\\Component\\Encryption\\' }
2323
- name: 'Signature'
2424
collectors:
25-
- { type: className, regex: '^Jose\\Component\\Signature\\' }
25+
- { type: classLike, value: '^Jose\\Component\\Signature\\' }
2626
- name: 'Bundle'
2727
collectors:
28-
- { type: className, regex: '^Jose\\Bundle\\JoseFramework\\' }
28+
- { type: classLike, value: '^Jose\\Bundle\\JoseFramework\\' }
2929
- name: 'Vendors'
3030
collectors:
31-
- { type: className, regex: '^Symfony\\' }
32-
- { type: className, regex: '^SpomkyLabs\\Pki\\' }
33-
- { type: className, regex: '^ParagonIE\\' }
34-
- { type: className, regex: '^Psr\\EventDispatcher\\' }
35-
- { type: className, regex: '^Psr\\Http\\' }
36-
- { type: className, regex: '^Brick\\Math\\' }
37-
- { type: className, regex: '^AESKW\\' }
38-
- { type: className, regex: '^ZxcvbnPhp\\' }
31+
- { type: classLike, value: '^Symfony\\' }
32+
- { type: classLike, value: '^SpomkyLabs\\Pki\\' }
33+
- { type: classLike, value: '^ParagonIE\\' }
34+
- { type: classLike, value: '^Psr\\EventDispatcher\\' }
35+
- { type: classLike, value: '^Psr\\Http\\' }
36+
- { type: classLike, value: '^Psr\\Cache\\' }
37+
- { type: classLike, value: '^Psr\\Clock\\' }
38+
- { type: classLike, value: '^Brick\\Math\\' }
39+
- { type: classLike, value: '^AESKW\\' }
40+
- { type: classLike, value: '^ZxcvbnPhp\\' }
3941
ruleset:
4042
Core:
4143
- 'Vendors'

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
backupGlobals="false"
55
processIsolation="false"
66
stopOnFailure="false"
7-
bootstrap="vendor/autoload.php"
7+
bootstrap="tests/autoload.php"
88
beStrictAboutTestsThatDoNotTestAnything="false"
99
colors="true"
1010
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"

rector.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55
use Rector\Config\RectorConfig;
66
use Rector\Doctrine\Set\DoctrineSetList;
77
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
8-
use Rector\PHPUnit\Set\PHPUnitLevelSetList;
98
use Rector\PHPUnit\Set\PHPUnitSetList;
109
use Rector\Set\ValueObject\LevelSetList;
1110
use Rector\Set\ValueObject\SetList;
12-
use Rector\Symfony\Set\SymfonyLevelSetList;
1311
use Rector\Symfony\Set\SymfonySetList;
1412
use Rector\ValueObject\PhpVersion;
1513

1614
return static function (RectorConfig $config): void {
1715
$config->import(SetList::DEAD_CODE);
1816
$config->import(LevelSetList::UP_TO_PHP_81);
19-
$config->import(SymfonyLevelSetList::UP_TO_SYMFONY_54);
17+
$config->import(SymfonySetList::SYMFONY_54);
2018
$config->import(SymfonySetList::SYMFONY_50_TYPES);
2119
$config->import(SymfonySetList::SYMFONY_52_VALIDATOR_ATTRIBUTES);
2220
$config->import(SymfonySetList::SYMFONY_CODE_QUALITY);
@@ -26,7 +24,7 @@
2624
$config->import(DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES);
2725
$config->import(PHPUnitSetList::PHPUNIT_CODE_QUALITY);
2826
$config->import(PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES);
29-
$config->import(PHPUnitLevelSetList::UP_TO_PHPUNIT_100);
27+
$config->import(PHPUnitSetList::PHPUNIT_100);
3028
$config->paths([
3129
__DIR__ . '/ecs.php',
3230
__DIR__ . '/rector.php',

src/Deprecated/Core/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"ext-json": "*",
3838
"ext-mbstring": "*",
3939
"brick/math": "^0.9|^0.10|^0.11|^0.12",
40-
"paragonie/constant_time_encoding": "^2.6",
40+
"paragonie/constant_time_encoding": "^2.6|^3.0",
4141
"spomky-labs/pki-framework": "^1.2.1",
4242
"web-token/jwt-library": "^3.3"
4343
}

src/Deprecated/SignatureAlgorithm/EdDSA/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"require": {
3636
"php": ">=8.1",
3737
"ext-sodium": "*",
38-
"paragonie/sodium_compat": "^1.20",
38+
"paragonie/sodium_compat": "^1.20|^2.0",
3939
"web-token/jwt-library": "^3.3"
4040
}
4141
}

src/Library/Core/Util/ECKey.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use function is_array;
1313
use function is_string;
1414
use const OPENSSL_KEYTYPE_EC;
15-
use const PHP_EOL;
1615
use const STR_PAD_LEFT;
1716

1817
/**
@@ -39,10 +38,10 @@ public static function convertPublicKeyToPEM(JWK $jwk): string
3938
default => throw new InvalidArgumentException('Unsupported curve.'),
4039
};
4140
$der .= self::getKey($jwk);
42-
$pem = '-----BEGIN PUBLIC KEY-----' . PHP_EOL;
43-
$pem .= chunk_split(base64_encode($der), 64, PHP_EOL);
41+
$pem = '-----BEGIN PUBLIC KEY-----' . "\n";
42+
$pem .= chunk_split(base64_encode($der), 64, "\n");
4443

45-
return $pem . ('-----END PUBLIC KEY-----' . PHP_EOL);
44+
return $pem . ('-----END PUBLIC KEY-----' . "\n");
4645
}
4746

4847
public static function convertPrivateKeyToPEM(JWK $jwk): string
@@ -55,10 +54,10 @@ public static function convertPrivateKeyToPEM(JWK $jwk): string
5554
default => throw new InvalidArgumentException('Unsupported curve.'),
5655
};
5756
$der .= self::getKey($jwk);
58-
$pem = '-----BEGIN EC PRIVATE KEY-----' . PHP_EOL;
59-
$pem .= chunk_split(base64_encode($der), 64, PHP_EOL);
57+
$pem = '-----BEGIN EC PRIVATE KEY-----' . "\n";
58+
$pem .= chunk_split(base64_encode($der), 64, "\n");
6059

61-
return $pem . ('-----END EC PRIVATE KEY-----' . PHP_EOL);
60+
return $pem . ('-----END EC PRIVATE KEY-----' . "\n");
6261
}
6362

6463
/**

src/Library/KeyManagement/KeyConverter/KeyConverter.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use const OPENSSL_KEYTYPE_EC;
2929
use const OPENSSL_KEYTYPE_RSA;
3030
use const OPENSSL_RAW_DATA;
31-
use const PHP_EOL;
3231
use const PREG_PATTERN_ORDER;
3332

3433
/**
@@ -145,10 +144,10 @@ public static function loadFromX5C(array $x5c): array
145144
throw new InvalidArgumentException('The certificate chain is empty');
146145
}
147146
foreach ($x5c as $id => $cert) {
148-
$x5c[$id] = '-----BEGIN CERTIFICATE-----' . PHP_EOL . chunk_split(
147+
$x5c[$id] = '-----BEGIN CERTIFICATE-----' . "\n" . chunk_split(
149148
(string) $cert,
150149
64,
151-
PHP_EOL
150+
"\n"
152151
) . '-----END CERTIFICATE-----';
153152
$x509 = openssl_x509_read($x5c[$id]);
154153
if ($x509 === false) {
@@ -372,9 +371,9 @@ private static function sanitizePEM(string &$pem): void
372371

373372
$ciphertext = preg_replace('#-.*-|\r|\n| #', '', $pem);
374373

375-
$pem = $matches[0][0] . PHP_EOL;
376-
$pem .= chunk_split($ciphertext ?? '', 64, PHP_EOL);
377-
$pem .= $matches[0][1] . PHP_EOL;
374+
$pem = $matches[0][0] . "\n";
375+
$pem .= chunk_split($ciphertext ?? '', 64, "\n");
376+
$pem .= $matches[0][1] . "\n";
378377
}
379378

380379
/**
@@ -405,16 +404,16 @@ private static function decodePem(string $pem, array $matches, ?string $password
405404
throw new InvalidArgumentException('Unable to load the key');
406405
}
407406

408-
$pem = $result[0][0] . PHP_EOL;
407+
$pem = $result[0][0] . "\n";
409408
$pem .= chunk_split(base64_encode($decoded), 64);
410409

411-
return $pem . ($result[0][1] . PHP_EOL);
410+
return $pem . ($result[0][1] . "\n");
412411
}
413412

414413
private static function convertDerToPem(string $der_data): string
415414
{
416-
$pem = chunk_split(base64_encode($der_data), 64, PHP_EOL);
415+
$pem = chunk_split(base64_encode($der_data), 64, "\n");
417416

418-
return '-----BEGIN CERTIFICATE-----' . PHP_EOL . $pem . '-----END CERTIFICATE-----' . PHP_EOL;
417+
return '-----BEGIN CERTIFICATE-----' . "\n" . $pem . '-----END CERTIFICATE-----' . "\n";
419418
}
420419
}

src/Library/KeyManagement/X5UFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use RuntimeException;
1212
use function is_array;
1313
use function is_string;
14-
use const PHP_EOL;
1514

1615
class X5UFactory extends UrlKeySetFactory
1716
{
@@ -29,7 +28,7 @@ public function loadFromUrl(string $url, array $header = []): JWKSet
2928
$keys = [];
3029
foreach ($data as $kid => $cert) {
3130
if (mb_strpos((string) $cert, '-----BEGIN CERTIFICATE-----') === false) {
32-
$cert = '-----BEGIN CERTIFICATE-----' . PHP_EOL . $cert . PHP_EOL . '-----END CERTIFICATE-----';
31+
$cert = '-----BEGIN CERTIFICATE-----' . "\n" . $cert . "\n" . '-----END CERTIFICATE-----';
3332
}
3433
$jwk = KeyConverter::loadKeyFromCertificate($cert);
3534
if (is_string($kid)) {

src/Library/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"ext-json": "*",
4343
"ext-mbstring": "*",
4444
"brick/math": "^0.9|^0.10|^0.11|^0.12",
45-
"paragonie/constant_time_encoding": "^2.6",
46-
"paragonie/sodium_compat": "^1.20",
45+
"paragonie/constant_time_encoding": "^2.6|^3.0",
46+
"paragonie/sodium_compat": "^1.20|^2.0",
4747
"psr/cache": "^3.0",
4848
"psr/clock": "^1.0",
4949
"psr/http-factory": "^1.0",

tests/Bundle/JoseFramework/Functional/KeyManagement/JWKSetLoaderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPUnit\Framework\Attributes\Test;
1010
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1111
use Symfony\Component\HttpClient\Response\MockResponse;
12+
use Symfony\Component\HttpFoundation\Request;
1213
use Symfony\Component\HttpFoundation\Response;
1314

1415
/**
@@ -33,7 +34,7 @@ public static function aJWKSetCanBeSharedInTheConfiguration(): void
3334
static::ensureKernelShutdown();
3435
$client = static::createClient();
3536

36-
$client->request('GET', '/keys/1.jwkset');
37+
$client->request(Request::METHOD_GET, '/keys/1.jwkset');
3738
/** @var Response $response */
3839
$response = $client->getResponse();
3940

@@ -62,7 +63,7 @@ public static function aJWKSetCanBeSharedFromAnotherBundle(): void
6263
static::ensureKernelShutdown();
6364
$client = static::createClient();
6465

65-
$client->request('GET', '/keys/2.jwkset');
66+
$client->request(Request::METHOD_GET, '/keys/2.jwkset');
6667
/** @var Response $response */
6768
$response = $client->getResponse();
6869

tests/Component/KeyManagement/JWKFactoryTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,55 +245,55 @@ public static function dataKeys(): iterable
245245
{
246246
yield [
247247
'filename' => __DIR__ . '/Keys/ED/public-ed448.pem',
248-
'values' => [
248+
'expectedValues' => [
249249
'kty' => 'OKP',
250250
'crv' => 'Ed448',
251251
'x' => 'wwHKDV7s4fBhmFSTzYorlaToGXNcsa7SakZdekT_sexD5ENj5lWP6_KX9_u--w_QSm80rNOodj0A',
252252
],
253253
];
254254
yield [
255255
'filename' => __DIR__ . '/Keys/ED/public-ed25519.pem',
256-
'values' => [
256+
'expectedValues' => [
257257
'kty' => 'OKP',
258258
'crv' => 'Ed25519',
259259
'x' => 'wrI33AEj15KHHYplueUE5cnJKtbM8oVHFf6wGnw2oOE',
260260
],
261261
];
262262
yield [
263263
'filename' => __DIR__ . '/Keys/ED/public-X448.pem',
264-
'values' => [
264+
'expectedValues' => [
265265
'kty' => 'OKP',
266266
'crv' => 'X448',
267267
'x' => 'UoPD73NQACC8A-otDUVun4IrMsk775ShMRf4ThDrq4xY2eAI-pOIVujrvBXXd9g8gUNwBT0fmnc',
268268
],
269269
];
270270
yield [
271271
'filename' => __DIR__ . '/Keys/ED/public-X25519.pem',
272-
'values' => [
272+
'expectedValues' => [
273273
'kty' => 'OKP',
274274
'crv' => 'X25519',
275275
'x' => '3OJLiffmOCQGtil23QGyn0nk9EBKoZx6P-6o-EnsBB4',
276276
],
277277
];
278278
yield [
279279
'filename' => __DIR__ . '/Keys/ED/private-ed448.pem',
280-
'values' => [
280+
'expectedValues' => [
281281
'kty' => 'OKP',
282282
'crv' => 'Ed448',
283283
'd' => '0GXSbNLOh7NQBlwoF8y2WJmjeP5Puif4_JL4ihFUzRLrb_3r4cH8l_HWJA-2ffY62LEB_ozsehG5',
284284
],
285285
];
286286
yield [
287287
'filename' => __DIR__ . '/Keys/ED/private-X448.pem',
288-
'values' => [
288+
'expectedValues' => [
289289
'kty' => 'OKP',
290290
'crv' => 'X448',
291291
'd' => 'OHZK0Fp9MAAmk0yZekiAkB8qxpCVAF4dT2x_xmFNDdCTnyDvixaiZ0NSRpAdR59tA6OJmOFfbck',
292292
],
293293
];
294294
yield [
295295
'filename' => __DIR__ . '/Keys/ED/private-ed25519.pem',
296-
'values' => [
296+
'expectedValues' => [
297297
'kty' => 'OKP',
298298
'crv' => 'Ed25519',
299299
'd' => 'Pr9AxZivB-zSq95wLrZfYa7DQ3TUPqZTkP_0w33r3rc',
@@ -302,7 +302,7 @@ public static function dataKeys(): iterable
302302
];
303303
yield [
304304
'filename' => __DIR__ . '/Keys/ED/private-secp384r1-with-public.pem',
305-
'values' => [
305+
'expectedValues' => [
306306
'kty' => 'EC',
307307
'crv' => 'P-384',
308308
'd' => '31taDOPQnlNl2aBC_EaGTqVGjGN_qg6iuLwP6cVTmhKMQ5PTL67wS6mmyKi8GdVP',
@@ -312,7 +312,7 @@ public static function dataKeys(): iterable
312312
];
313313
yield [
314314
'filename' => __DIR__ . '/Keys/ED/private-X25519.pem',
315-
'values' => [
315+
'expectedValues' => [
316316
'kty' => 'OKP',
317317
'crv' => 'X25519',
318318
'd' => 'mG-fgDwkr58hwIeqCQKZbR8HKeY4yg_AzvU6zyNaVUE',

tests/autoload.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symfony\Component\ErrorHandler\ErrorHandler;
6+
7+
require_once __DIR__ . '/../vendor/autoload.php';
8+
9+
ErrorHandler::register(null, false);

0 commit comments

Comments
 (0)