
Description
Version(s) affected
3.2.7
Description
We have a specific URL, a signature and a set JWKs from Google https://play.google.com/newsstand/api/v3/articleaccess/publicsigningkey/dev to verify the signature.
When trying to verify the signature,
throws the warningWarning: openssl_verify(): Supplied key param cannot be coerced into a public key
thus verifying the signature always fails.
We compared how web-token/jwt-framework
converts the JWK into a public key to how https://8gwifi.org/jwkconvertfunctions.jsp and how https://www.npmjs.com/package/jwk-to-pem does it and while https://8gwifi.org/jwkconvertfunctions.jsp and https://www.npmjs.com/package/jwk-to-pem create the same public key, that openssl ec -inform PEM -pubin -in public.pem -text -noout
can properly process, web-token/jwt-framework
creates an invalid public key, that openssl fails to read:
read EC key
Could not read public key from public.pem
80E0D9FA01000000:error:1608010C:STORE routines:ossl_store_handle_load_result:unsupported:crypto/store/store_result.c:151:
80E0D9FA01000000:error:1608010C:STORE routines:ossl_store_handle_load_result:unsupported:crypto/store/store_result.c:151:
unable to load Key
The same problem also arises when JWKs from https://play.google.com/newsstand/api/v3/articleaccess/publicsigningkey are converted.
How to reproduce
Execute
$signKeys = json_decode(
file_get_contents('https://play.google.com/newsstand/api/v3/articleaccess/publicsigningkey/dev'),
associative: true,
)['keys'];
$jwks = array_map(static fn($key) => new \Jose\Component\Core\JWK($key), $signKeys);
foreach ($jwks as $jwk) {
echo json_encode($jwk->jsonSerialize()) . "<br><br>";
echo nl2br(\Jose\Component\Core\Util\ECKey::convertPublicKeyToPEM($jwk)) . "<br><br>";
}
and try verifying the keys with openssl ec -inform PEM -pubin -in public.pem -text -noout
, compare keys to https://8gwifi.org/jwkconvertfunctions.jsp.
Possible Solution
No response
Additional Context
Example conversion comparison:
{"kty":"EC","crv":"P-256","x":"GDDdmNtwNvlXN04SEUp20BZJ9im6SQqkP8u4d8G6RAk","y":"AIAxkBwTTqbCcNbqbpk8l_Eh-4KtpgyyHkNJ6K4jnvOv","use":"sig","alg":"ES256","kid":"ayRrlw","key_ops":["verify"]}
web-token/jwt-framework:
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEGDDdmNtwNvlXN04SEUp20BZJ9im6
SQqkP8u4d8G6RAkAgDGQHBNOpsJw1upumTyX8SH7gq2mDLIeQ0noriOe868=
-----END PUBLIC KEY-----
https://8gwifi.org/jwkconvertfunctions.jsp:
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEGDDdmNtwNvlXN04SEUp20BZJ9im6
SQqkP8u4d8G6RAmAMZAcE06mwnDW6m6ZPJfxIfuCraYMsh5DSeiuI57zrw==
-----END PUBLIC KEY-----
node jwk-to-pem:
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEGDDdmNtwNvlXN04SEUp20BZJ9im6
SQqkP8u4d8G6RAmAMZAcE06mwnDW6m6ZPJfxIfuCraYMsh5DSeiuI57zrw==
-----END PUBLIC KEY-----