From fd5dd79bd2bd47acb406cd3a93981ae53102b5cf Mon Sep 17 00:00:00 2001 From: yhirose Date: Wed, 21 Oct 2026 17:16:11 -0400 Subject: [PATCH] Ready PSA Crypto before parsing a CA store on Mbed TLS 4.x tls::create_ca_store() parses certificates, which on Mbed TLS 4.x needs PSA Crypto. A context readies it when it is created, but a store can be made before any context exists, and then a valid PEM failed to parse and the call returned NULL. Ready PSA Crypto first, as the contexts do. --- httplib.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/httplib.h b/httplib.h index f16aa141..560593b1 100644 --- a/httplib.h +++ b/httplib.h @@ -21924,6 +21924,11 @@ inline std::string error_string(uint64_t code) { } inline ca_store_t create_ca_store(const char *pem, size_t len) { +#ifdef CPPHTTPLIB_MBEDTLS_V4 + // Parsing certificates needs PSA Crypto, and no context may exist yet + if (!detail::ensure_mbedtls_psa_crypto()) { return nullptr; } +#endif + auto *ca_chain = new (std::nothrow) mbedtls_x509_crt; if (!ca_chain) { return nullptr; }