File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff 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 ' ])) {
Original file line number Diff line number Diff 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 (
You can’t perform that action at this time.
0 commit comments