Quellcode durchsuchen

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.
yhirose vor 23 Stunden
Ursprung
Commit
fd5dd79bd2
1 geänderte Dateien mit 5 neuen und 0 gelöschten Zeilen
  1. 5 0
      httplib.h

+ 5 - 0
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; }