Skip to content

Commit 5de4323

Browse files
authored
feat: add support for P-384 curve (#515)
1 parent 15d579a commit 5de4323

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

Diff for: src/JWK.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class JWK
2727
private const EC_CURVES = [
2828
'P-256' => '1.2.840.10045.3.1.7', // Len: 64
2929
'secp256k1' => '1.3.132.0.10', // Len: 64
30-
// 'P-384' => '1.3.132.0.34', // Len: 96 (not yet supported)
30+
'P-384' => '1.3.132.0.34', // Len: 96
3131
// 'P-521' => '1.3.132.0.35', // Len: 132 (not supported)
3232
];
3333

@@ -182,7 +182,7 @@ public static function parseKey(array $jwk, string $defaultAlg = null): ?Key
182182
/**
183183
* Converts the EC JWK values to pem format.
184184
*
185-
* @param string $crv The EC curve (only P-256 is supported)
185+
* @param string $crv The EC curve (only P-256 & P-384 is supported)
186186
* @param string $x The EC x-coordinate
187187
* @param string $y The EC y-coordinate
188188
*

Diff for: tests/JWKTest.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ public function testDecodeByJwkKeySetTokenExpired()
129129
/**
130130
* @dataProvider provideDecodeByJwkKeySet
131131
*/
132-
public function testDecodeByJwkKeySet($pemFile, $jwkFile, $alg)
132+
public function testDecodeByJwkKeySet($pemFile, $jwkFile, $alg, $keyId)
133133
{
134134
$privKey1 = file_get_contents(__DIR__ . '/data/' . $pemFile);
135135
$payload = ['sub' => 'foo', 'exp' => strtotime('+10 seconds')];
136-
$msg = JWT::encode($payload, $privKey1, $alg, 'jwk1');
136+
$msg = JWT::encode($payload, $privKey1, $alg, $keyId);
137137

138138
$jwkSet = json_decode(
139139
file_get_contents(__DIR__ . '/data/' . $jwkFile),
@@ -149,9 +149,10 @@ public function testDecodeByJwkKeySet($pemFile, $jwkFile, $alg)
149149
public function provideDecodeByJwkKeySet()
150150
{
151151
return [
152-
['rsa1-private.pem', 'rsa-jwkset.json', 'RS256'],
153-
['ecdsa256-private.pem', 'ec-jwkset.json', 'ES256'],
154-
['ed25519-1.sec', 'ed25519-jwkset.json', 'EdDSA'],
152+
['rsa1-private.pem', 'rsa-jwkset.json', 'RS256', 'jwk1'],
153+
['ecdsa256-private.pem', 'ec-jwkset.json', 'ES256', 'jwk1'],
154+
['ecdsa384-private.pem', 'ec-jwkset.json', 'ES384', 'jwk4'],
155+
['ed25519-1.sec', 'ed25519-jwkset.json', 'EdDSA', 'jwk1'],
155156
];
156157
}
157158

Diff for: tests/data/ec-jwkset.json

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
"x": "EFpwNuP322bU3WP1DtJgx67L0CUV1MxNixqPVMH2L9Q",
2727
"y": "_fSTbijIJjpsqL16cIEvxxf3MaYMY8MbqEq066yV9ls",
2828
"alg": "ES256K"
29+
},
30+
{
31+
"kty": "EC",
32+
"use": "sig",
33+
"crv": "P-384",
34+
"kid": "jwk4",
35+
"x": "FhXXcyKmWkTkdVbWYYU3dtJqpJ0JmLGftEdNzUEFEKSU5MlnLr_FjcneszvXAqEB",
36+
"y": "M4veJF_dO_zhFk44bh_ELXbp0_nn9QaViVtQpuTvpu29eefx6PfUMqX0K--IS4NQ",
37+
"alg": "ES384"
2938
}
3039
]
3140
}

0 commit comments

Comments
 (0)