Skip to content

tls: fix WolfSSL CA certificate buffer loading#3440

Merged
scaprile merged 1 commit intocesanta:masterfrom
leopoldch:fix/wolfssl-ca-loading
Feb 16, 2026
Merged

tls: fix WolfSSL CA certificate buffer loading#3440
scaprile merged 1 commit intocesanta:masterfrom
leopoldch:fix/wolfssl-ca-loading

Conversation

@leopoldch
Copy link
Contributor

Issue: #2821

Why ?

When using WolfSSL with Mongoose, loading CA certificates from a memory buffer often failed with "Invalid file" or ASN.1 parsing errors.

  • The Cause: Mongoose was using a manual parsing logic (load_ca_certs) based on a stack of X509_INFO structures.
  • The Conflict: WolfSSL's OpenSSL compatibility layer does not always handle these manual internal structure operations identically to OpenSSL, leading to parsing failures even with valid PEM buffers.

What ? (the implemented fix)

The patch transitions from manual OpenSSL-style parsing to the native WolfSSL API for memory-based certificate loading.
Used wolfSSL_CTX_load_verify_buffer directly when MG_TLS_WOLFSSL is defined. This required implementing a forward declaration (extern) for the native WolfSSL function, which avoids including <wolfssl/ssl.h> and thereby prevents macro/type collisions with the OpenSSL compatibility headers already used by Mongoose.

Finally, encapsulated OpenSSL-specific helpers (load_ca_certs, add_ca_certs) within #if MG_TLS != MG_TLS_WOLFSSL. This keeps the binary lean and avoids "undefined symbol" errors for structures not used by WolfSSL.


Tested on macOS, Apple Silicon (arm64), WolfSSL (Homebrew).

@cpq
Copy link
Member

cpq commented Feb 16, 2026

Thank you!
Can you sign the CLA please https://cesanta.com/cla.html in order to get this integrated

@leopoldch
Copy link
Contributor Author

This feels a bit intrusive in terms of personal information, but it’s done 🙂

@scaprile scaprile merged commit ed0423f into cesanta:master Feb 16, 2026
@scaprile
Copy link
Collaborator

Mac tests now pass.
Linux and other tests continue passing.
Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants