From 146f2a1f2908fffde0d13b7e22e70d44e9b307ce Mon Sep 17 00:00:00 2001 From: David Dreschner Date: Mon, 13 Jul 2026 05:12:32 +0200 Subject: [PATCH] chore(tests): Fix failing nodb tests due to AlgorithmTest Assisted-by: ClaudeCode:claude-fable-5 Signed-off-by: David Dreschner --- .../Signature/Rfc9421/AlgorithmTest.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/lib/Security/Signature/Rfc9421/AlgorithmTest.php b/tests/lib/Security/Signature/Rfc9421/AlgorithmTest.php index ce8339c12a2c2..abcf200e76048 100644 --- a/tests/lib/Security/Signature/Rfc9421/AlgorithmTest.php +++ b/tests/lib/Security/Signature/Rfc9421/AlgorithmTest.php @@ -182,17 +182,32 @@ private function ecKeyPair(string $opensslCurve, string $jwkCurve, string $joseA $priv = ''; openssl_pkey_export($pkey, $priv); $details = openssl_pkey_get_details($pkey); + $coordinateSize = $opensslCurve === 'prime256v1' ? 32 : 48; + [$x, $y] = self::zeroPadCoordinates($details['ec']['x'], $details['ec']['y'], $coordinateSize); $key = JWK::parseKey([ 'kty' => 'EC', 'crv' => $jwkCurve, 'kid' => 'k', 'alg' => $joseAlg, - 'x' => self::b64url($details['ec']['x']), - 'y' => self::b64url($details['ec']['y']), + 'x' => self::b64url($x), + 'y' => self::b64url($y), ], $joseAlg); return [$priv, $key]; } + /** + * openssl strips leading zero bytes from EC coordinates; JWK requires them + * zero-padded to the full field size (RFC 7518 ยง6.2.1.2). + * + * @return array{0: string, 1: string} + */ + private static function zeroPadCoordinates(string $x, string $y, int $coordinateSize): array { + return [ + str_pad($x, $coordinateSize, "\x00", STR_PAD_LEFT), + str_pad($y, $coordinateSize, "\x00", STR_PAD_LEFT), + ]; + } + private static function b64url(string $bin): string { return rtrim(strtr(base64_encode($bin), '+/', '-_'), '='); }