Skip to content

Commit d7cd1db

Browse files
authored
fix: allow for null d values in RSA JWK (#330)
1 parent 8ddb395 commit d7cd1db

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/JWK.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private static function parseKey(array $jwk)
8282

8383
switch ($jwk['kty']) {
8484
case 'RSA':
85-
if (\array_key_exists('d', $jwk)) {
85+
if (!empty($jwk['d'])) {
8686
throw new UnexpectedValueException('RSA private keys are not supported');
8787
}
8888
if (!isset($jwk['n']) || !isset($jwk['e'])) {

tests/JWKTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,36 @@ public function testInvalidAlgorithm()
3232
$keys = JWK::parseKeySet(array('keys' => array($badJwk)));
3333
}
3434

35+
public function testParsePrivateKey()
36+
{
37+
$this->setExpectedException(
38+
'UnexpectedValueException',
39+
'RSA private keys are not supported'
40+
);
41+
42+
$jwkSet = json_decode(
43+
file_get_contents(__DIR__ . '/rsa-jwkset.json'),
44+
true
45+
);
46+
$jwkSet['keys'][0]['d'] = 'privatekeyvalue';
47+
48+
JWK::parseKeySet($jwkSet);
49+
}
50+
51+
public function testParseKeyWithEmptyDValue()
52+
{
53+
$jwkSet = json_decode(
54+
file_get_contents(__DIR__ . '/rsa-jwkset.json'),
55+
true
56+
);
57+
58+
// empty or null values are ok
59+
$jwkSet['keys'][0]['d'] = null;
60+
61+
$keys = JWK::parseKeySet($jwkSet);
62+
$this->assertTrue(is_array($keys));
63+
}
64+
3565
public function testParseJwkKeySet()
3666
{
3767
$jwkSet = json_decode(

0 commit comments

Comments
 (0)