1
0

1752063697.v14-7-g5aaaaf6.openssl-handle-null-in-jose-openssl-jwk-from-ec-key-gracefully-172.patch 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. Subject: Openssl: handle NULL in jose_openssl_jwk_from_EC_KEY gracefully (#172)
  2. Origin: upstream, commit v14-7-g5aaaaf6 <https://github.com/latchset/jose/commit/v14-7-g5aaaaf6>
  3. Author: Ahmad Fatoum <ahmad@a3f.at>
  4. Date: Wed Jul 9 14:21:37 2025 +0200
  5. We already check that the RSA *key is not NULL in
  6. jose_openssl_jwk_from_RSA(), but fail to do so for EC_KEY *key in
  7. jose_openssl_jwk_from_EC_KEY().
  8. But EVP_PKEY_get0_EC_KEY() can return NULL too, e.g., if
  9. the EVP_PKEY comes from an OpenSSL provider that is not creating a
  10. keymgmt instance for a public key and the default provider is not
  11. loaded[1].
  12. Instead of crashing inside OpenSSL when we pass a NULL pointer to
  13. EC_KEY_get0_private_key(), detect this case and return gracefully.
  14. [1]: https://github.com/openssl/openssl/discussions/25679
  15. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
  16. --- a/lib/openssl/jwk.c
  17. +++ b/lib/openssl/jwk.c
  18. @@ -140,6 +140,9 @@
  19. json_t *
  20. jose_openssl_jwk_from_EC_KEY(jose_cfg_t *cfg, const EC_KEY *key)
  21. {
  22. + if (!key)
  23. + return NULL;
  24. +
  25. return jose_openssl_jwk_from_EC_POINT(
  26. cfg,
  27. EC_KEY_get0_group(key),