Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
Bug fixed
Browse files Browse the repository at this point in the history
Fixed: Try statement catch JWT checker exceptions
  • Loading branch information
Florent Morselli committed Dec 16, 2015
1 parent 84b27b8 commit ad8de46
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
17 changes: 9 additions & 8 deletions src/Decrypter.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function decrypt(JWEInterface &$jwe, JWKSetInterface $jwk_set)
$this->checkCompleteHeader($jwe);
$key_encryption_algorithm = $this->getKeyEncryptionAlgorithm($jwe->getHeader('alg'));
$content_encryption_algorithm = $this->getContentEncryptionAlgorithm($jwe->getHeader('enc'));

$decrypted = false;
foreach ($jwk_set as $jwk) {
if (!$this->checkKeyUsage($jwk, 'decryption')) {
continue;
Expand All @@ -81,14 +81,16 @@ public function decrypt(JWEInterface &$jwe, JWKSetInterface $jwk_set)
$cek = $this->decryptCEK($key_encryption_algorithm, $content_encryption_algorithm, $jwk, $jwe->getEncryptedKey(), $jwe->getHeaders());

if (null !== $cek) {
if (true === $this->decryptPayload($jwe, $cek, $content_encryption_algorithm)) {
$this->getCheckerManager()->checkJWT($jwe);

return true;
}
$decrypted = $this->decryptPayload($jwe, $cek, $content_encryption_algorithm);
}
} catch (\Exception $e) {
//We do nothing, we continue with other keys
continue;
}
if (true === $decrypted) {
$this->getCheckerManager()->checkJWT($jwe);

return true;
}
}

Expand Down Expand Up @@ -124,7 +126,7 @@ private function decryptCEK(JWAInterface $key_encryption_algorithm, ContentEncry
* @param string $cek
* @param \Jose\Algorithm\ContentEncryption\ContentEncryptionInterface $content_encryption_algorithm
*
* @return \Jose\Object\JWEInterface
* @return bool
*/
private function decryptPayload(JWEInterface &$jwe, $cek, $content_encryption_algorithm)
{
Expand Down Expand Up @@ -164,7 +166,6 @@ private function decryptPayload(JWEInterface &$jwe, $cek, $content_encryption_al
);

$jwe = $result;
//jwe = $jwe->withPayload($payload);

return true;
}
Expand Down
13 changes: 8 additions & 5 deletions src/Verifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function verify(JWSInterface $jws, JWKSetInterface $jwk_set, $detached_pa
if (0 === count($jwk_set)) {
return false;
}
$verified = false;
foreach ($jwk_set->getKeys() as $jwk) {
$algorithm = $this->getAlgorithm($jws);
if (!$this->checkKeyUsage($jwk, 'verification')) {
Expand All @@ -66,13 +67,15 @@ public function verify(JWSInterface $jws, JWKSetInterface $jwk_set, $detached_pa
continue;
}
try {
if (true === $algorithm->verify($jwk, $input, $jws->getSignature())) {
$this->getCheckerManager()->checkJWT($jws);

return true;
}
$verified = $algorithm->verify($jwk, $input, $jws->getSignature());
} catch (\Exception $e) {
//We do nothing, we continue with other keys
continue;
}
if (true === $verified) {
$this->getCheckerManager()->checkJWT($jws);

return true;
}
}

Expand Down

0 comments on commit ad8de46

Please sign in to comment.