Skip to content

Commit

Permalink
Merge pull request #575 from web-token/temp-8e9fdc
Browse files Browse the repository at this point in the history
Merge up 3.4.4 to 4.0.x
  • Loading branch information
Spomky authored Jun 24, 2024
2 parents dd3b4f8 + 6c72178 commit 4a382fc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
12 changes: 3 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
"ext-sodium": "*",
"ekino/phpstan-banned-code": "^1.0",
"ergebnis/phpunit-slow-test-detector": "^2.14",
"infection/infection": "^0.28|^0.29",
"matthiasnoback/symfony-config-test": "dev-phpunit-11",
"infection/infection": "^0.29",
"matthiasnoback/symfony-config-test": "5.1.x-dev",
"paragonie/sodium_compat": "^1.20|^2.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpbench/phpbench": "^1.2",
Expand All @@ -86,7 +86,7 @@
"spomky-labs/aes-key-wrap": "^7.0",
"staabm/phpstan-dba": "^0.2.79",
"staabm/phpstan-todo-by": "^0.1.25",
"struggle-for-php/sfp-phpstan-psr-log": "^0.20.0 || ^0.21.0",
"struggle-for-php/sfp-phpstan-psr-log": "^0.20|^0.21",
"symfony/browser-kit": "^7.0",
"symfony/http-client": "^7.0",
"symfony/clock": "^7.0",
Expand Down Expand Up @@ -118,11 +118,5 @@
"php-http/discovery": true,
"infection/extension-installer": false
}
},
"repositories": {
"wickedOne_SymfonyConfigTest": {
"type": "vcs",
"url": "[email protected]:wickedOne/SymfonyConfigTest.git"
}
}
}
13 changes: 6 additions & 7 deletions src/Library/Core/Util/ECKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use function is_array;
use function is_string;
use const OPENSSL_KEYTYPE_EC;
use const PHP_EOL;
use const STR_PAD_LEFT;

/**
Expand All @@ -38,10 +37,10 @@ public static function convertPublicKeyToPEM(JWK $jwk): string
default => throw new InvalidArgumentException('Unsupported curve.'),
};
$der .= self::getKey($jwk);
$pem = '-----BEGIN PUBLIC KEY-----' . PHP_EOL;
$pem .= chunk_split(base64_encode($der), 64, PHP_EOL);
$pem = '-----BEGIN PUBLIC KEY-----' . "\n";
$pem .= chunk_split(base64_encode($der), 64, "\n");

return $pem . ('-----END PUBLIC KEY-----' . PHP_EOL);
return $pem . ('-----END PUBLIC KEY-----' . "\n");
}

public static function convertPrivateKeyToPEM(JWK $jwk): string
Expand All @@ -54,10 +53,10 @@ public static function convertPrivateKeyToPEM(JWK $jwk): string
default => throw new InvalidArgumentException('Unsupported curve.'),
};
$der .= self::getKey($jwk);
$pem = '-----BEGIN EC PRIVATE KEY-----' . PHP_EOL;
$pem .= chunk_split(base64_encode($der), 64, PHP_EOL);
$pem = '-----BEGIN EC PRIVATE KEY-----' . "\n";
$pem .= chunk_split(base64_encode($der), 64, "\n");

return $pem . ('-----END EC PRIVATE KEY-----' . PHP_EOL);
return $pem . ('-----END EC PRIVATE KEY-----' . "\n");
}

/**
Expand Down
21 changes: 10 additions & 11 deletions src/Library/KeyManagement/KeyConverter/KeyConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use const OPENSSL_KEYTYPE_EC;
use const OPENSSL_KEYTYPE_RSA;
use const OPENSSL_RAW_DATA;
use const PHP_EOL;
use const PREG_PATTERN_ORDER;

/**
Expand Down Expand Up @@ -163,11 +162,11 @@ public static function loadFromX5C(array $x5c): array
throw new InvalidArgumentException('The certificate chain is empty');
}
foreach ($x5c as $id => $cert) {
assert(is_string($cert), 'Invalid certificate');
$x5c[$id] = '-----BEGIN CERTIFICATE-----' . PHP_EOL . chunk_split(
assert(is_string($cert), 'Invalid certificate chain');
$x5c[$id] = '-----BEGIN CERTIFICATE-----' . "\n" . chunk_split(
$cert,
64,
PHP_EOL
"\n"
) . '-----END CERTIFICATE-----';
$x509 = openssl_x509_read($x5c[$id]);
if ($x509 === false) {
Expand Down Expand Up @@ -403,9 +402,9 @@ private static function sanitizePEM(string &$pem): void

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

$pem = $matches[0][0] . PHP_EOL;
$pem .= chunk_split($ciphertext ?? '', 64, PHP_EOL);
$pem .= $matches[0][1] . PHP_EOL;
$pem = $matches[0][0] . "\n";
$pem .= chunk_split($ciphertext ?? '', 64, "\n");
$pem .= $matches[0][1] . "\n";
}

/**
Expand Down Expand Up @@ -436,16 +435,16 @@ private static function decodePem(string $pem, array $matches, ?string $password
throw new InvalidArgumentException('Unable to load the key');
}

$pem = $result[0][0] . PHP_EOL;
$pem = $result[0][0] . "\n";
$pem .= chunk_split(base64_encode($decoded), 64);

return $pem . ($result[0][1] . PHP_EOL);
return $pem . ($result[0][1] . "\n");
}

private static function convertDerToPem(string $der_data): string
{
$pem = chunk_split(base64_encode($der_data), 64, PHP_EOL);
$pem = chunk_split(base64_encode($der_data), 64, "\n");

return '-----BEGIN CERTIFICATE-----' . PHP_EOL . $pem . '-----END CERTIFICATE-----' . PHP_EOL;
return '-----BEGIN CERTIFICATE-----' . "\n" . $pem . '-----END CERTIFICATE-----' . "\n";
}
}
3 changes: 1 addition & 2 deletions src/Library/KeyManagement/X5UFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use function assert;
use function is_array;
use function is_string;
use const PHP_EOL;

class X5UFactory extends UrlKeySetFactory
{
Expand All @@ -33,7 +32,7 @@ public function loadFromUrl(string $url, array $header = []): JWKSet
foreach ($data as $kid => $cert) {
assert(is_string($cert), 'Invalid content.');
if (mb_strpos($cert, '-----BEGIN CERTIFICATE-----') === false) {
$cert = '-----BEGIN CERTIFICATE-----' . PHP_EOL . $cert . PHP_EOL . '-----END CERTIFICATE-----';
$cert = '-----BEGIN CERTIFICATE-----' . "\n" . $cert . "\n" . '-----END CERTIFICATE-----';
}
$jwk = KeyConverter::loadKeyFromCertificate($cert);
if (is_string($kid)) {
Expand Down

0 comments on commit 4a382fc

Please sign in to comment.