Skip to content

Commit e9690f5

Browse files
chore: remove jwt incorrect key warning (#560)
1 parent 1b9e871 commit e9690f5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/JWT.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ public static function sign(
251251
return \hash_hmac($algorithm, $msg, $key, true);
252252
case 'openssl':
253253
$signature = '';
254+
if (!\is_resource($key) && !openssl_pkey_get_private($key)) {
255+
throw new DomainException('OpenSSL unable to validate key');
256+
}
254257
$success = \openssl_sign($msg, $signature, $key, $algorithm); // @phpstan-ignore-line
255258
if (!$success) {
256259
throw new DomainException('OpenSSL unable to sign data');

tests/JWTTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public function testMalformedUtf8StringsFail()
2626
JWT::encode(['message' => pack('c', 128)], 'a', 'HS256');
2727
}
2828

29+
public function testInvalidKeyOpensslSignFail()
30+
{
31+
$this->expectException(DomainException::class);
32+
JWT::sign('message', 'invalid key', 'openssl');
33+
}
34+
2935
public function testMalformedJsonThrowsException()
3036
{
3137
$this->expectException(DomainException::class);

0 commit comments

Comments
 (0)