From 97d792ac40f4577eda47812c91877ad4fdec5721 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 17 May 2021 08:28:06 -0700 Subject: [PATCH 1/3] fix: allow for null d values in RSA JWK --- src/JWK.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JWK.php b/src/JWK.php index 7632f4a4..fa819488 100644 --- a/src/JWK.php +++ b/src/JWK.php @@ -82,7 +82,7 @@ private static function parseKey(array $jwk) switch ($jwk['kty']) { case 'RSA': - if (\array_key_exists('d', $jwk)) { + if (!\empty($jwk['d'])) { throw new UnexpectedValueException('RSA private keys are not supported'); } if (!isset($jwk['n']) || !isset($jwk['e'])) { From ec2bf6bf39427b69f60cf2e2efa2508f4cbaad87 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 17 May 2021 08:32:38 -0700 Subject: [PATCH 2/3] chore: add test cases --- tests/JWKTest.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/JWKTest.php b/tests/JWKTest.php index b8b67540..6fdef33d 100644 --- a/tests/JWKTest.php +++ b/tests/JWKTest.php @@ -31,6 +31,36 @@ public function testInvalidAlgorithm() $keys = JWK::parseKeySet(array('keys' => array($badJwk))); } + public function testParsePrivateKey() + { + $this->setExpectedException( + 'UnexpectedValueException', + 'RSA private keys are not supported' + ); + + $jwkSet = json_decode( + file_get_contents(__DIR__ . '/rsa-jwkset.json'), + true + ); + $jwkSet['keys'][0]['d'] = 'privatekeyvalue'; + + JWK::parseKeySet($jwkSet); + } + + public function testParseKeyWithEmptyDValue() + { + $jwkSet = json_decode( + file_get_contents(__DIR__ . '/rsa-jwkset.json'), + true + ); + + // empty or null values are ok + $jwkSet['keys'][0]['d'] = null; + + $keys = JWK::parseKeySet($jwkSet); + $this->assertTrue(is_array($keys)); + } + public function testParseJwkKeySet() { $jwkSet = json_decode( From 765f66e896cb9c5a652e89e3502fcb1fea37f58e Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 17 May 2021 09:47:26 -0700 Subject: [PATCH 3/3] Update JWK.php --- src/JWK.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JWK.php b/src/JWK.php index fa819488..29dbbac1 100644 --- a/src/JWK.php +++ b/src/JWK.php @@ -82,7 +82,7 @@ private static function parseKey(array $jwk) switch ($jwk['kty']) { case 'RSA': - if (!\empty($jwk['d'])) { + if (!empty($jwk['d'])) { throw new UnexpectedValueException('RSA private keys are not supported'); } if (!isset($jwk['n']) || !isset($jwk['e'])) {