Skip to content

Commit fd5dd79

Browse files
committed
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.
1 parent 6304fc6 commit fd5dd79

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎httplib.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21924,6 +21924,11 @@ inline std::string error_string(uint64_t code) {
2192421924
}
2192521925

2192621926
inline ca_store_t create_ca_store(const char *pem, size_t len) {
21927+
#ifdef CPPHTTPLIB_MBEDTLS_V4
21928+
// Parsing certificates needs PSA Crypto, and no context may exist yet
21929+
if (!detail::ensure_mbedtls_psa_crypto()) { return nullptr; }
21930+
#endif
21931+
2192721932
auto *ca_chain = new (std::nothrow) mbedtls_x509_crt;
2192821933
if (!ca_chain) { return nullptr; }
2192921934

0 commit comments

Comments
 (0)