Skip to content

Add four X509 OpenSSL compatibility APIs - #12285

Open
julek-wolfssl wants to merge 4 commits into
wolfSSL:masterfrom
julek-wolfssl:compat/store-ctx-ip-hostflags
Open

julek-wolfssl wants to merge 4 commits into
wolfSSL:masterfrom
julek-wolfssl:compat/store-ctx-ip-hostflags

Conversation

@julek-wolfssl

Copy link
Copy Markdown
Member

No description provided.

X509_VERIFY_PARAM_get_hostflags() returns the flags stored by
X509_VERIFY_PARAM_set_hostflags(), or 0 for a NULL param.

X509_check_ip() is the binary counterpart of X509_check_ip_asc(). The 4
byte IPv4 or 16 byte IPv6 address is printed in the form the certificate
parser gives iPAddress names and checked with X509_check_ip_asc(), so
both share one matching path and return 1 on a match and 0 otherwise.
The uncompressed IPv6 form also matches without the inet_pton() based
comparison, which WOLFSSL_USER_IO builds lack. Any other length returns
0. OpenSSL compares lengths, so it never matches either. NULL arguments
return 0 like X509_check_ip_asc(); OpenSSL returns -2 for a NULL
address.

X509_STORE_CTX_get_ex_new_index() is CRYPTO_get_ex_new_index() with
CRYPTO_EX_INDEX_X509_STORE_CTX in OpenSSL. That class now has its own
counter, shared by both calls, so CRYPTO_get_ex_new_index() returns an
index for it too. Counting starts at 1. During verification the
handshake keeps the WOLFSSL object at index 0, the value of
SSL_get_ex_data_X509_STORE_CTX_idx(), and an application index must not
alias it. OpenSSL never hands out 0 either. As for the SSL, SSL_CTX and
X509 classes, the new, dup and free callbacks are not used.

X509_STORE_CTX_get0_untrusted() returns ctxIntermediates, the stack
passed as the chain argument of X509_STORE_CTX_init(). It is the only
stack in the context that holds the untrusted certificates as the caller
set them up. The others are owned (issuers the context decoded and
frees), chain (the path X509_verify_cert() built) and setTrustedSk (the
trusted override from X509_STORE_CTX_trusted_stack()).
X509_verify_cert() works on a private shallow copy and leaves
ctxIntermediates unchanged.

Ownership matches OpenSSL: the pointer is returned as is, the context
never copies or frees the stack, and the caller of init keeps ownership.
A new init replaces it. X509_STORE_CTX_cleanup() resets it with the rest
of the context, while OpenSSL keeps the pointer across cleanup. The
handshake sets up its store context without an untrusted stack, so the
call returns NULL in a TLS verify callback, where OpenSSL gives the peer
chain.

.wolfssl_known_macro_extras gains 27 options that users or CI
configurations set and check-source-text rejected as unknown: the
sources test them, but nothing the check scans defines them. It drops
WC_NO_STATIC_ASSERT, WOLFSSL_ALLOW_NO_SUITES and
WOLFSSL_SP_FAST_MODEXP_COPY, which the tree defines.
Copilot AI balanced review requested due to automatic review settings November 26, 2026 14:34
@julek-wolfssl julek-wolfssl self-assigned this Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +192 B (+0.0%, 804,424 B / 1,048,576 B, total: 77% used)
  • RAM: .data +4 B (+0.0%, 121,764 B / 262,144 B, total: 46% used)

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +108 B, text +13,864 B (+4.9%, 296,444 B / 67,108,864 B, total: 0% used)
  • RAM: bss +49 B, datas +16 B (+0.1%, 58,423 B / 983,040 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The unsynchronized process-wide ex-data index counter can allocate duplicate indices during concurrent registration, causing independent users’ store-context values to overwrite one another.

4 open issues
What changed in this PR

Extends wolfSSL’s OpenSSL compatibility layer with four X509 APIs for binary IP matching, hostname-check flags, untrusted certificate stacks, and store-context external-data indexes.

Changes:

  • Adds implementations, public declarations, and OpenSSL-compatible aliases.
  • Adds API tests and updates external-data class expectations.
  • Updates documentation references and the known-macro list.
File Description
wolfssl/​ssl.h Declares the four new public APIs.
wolfssl/​openssl/​ssl.h Adds OpenSSL-compatible aliases.
tests/​api/​test_ossl_x509.h Registers the binary IP-check test.
tests/​api/​test_ossl_x509.c Tests IPv4/IPv6 matching and invalid inputs.
tests/​api/​test_ossl_x509_vp.h Registers the host-flags getter test.
tests/​api/​test_ossl_x509_vp.c Tests flag retrieval, copying, and inheritance.
tests/​api/​test_ossl_x509_str.h Registers the new store-context tests.
tests/​api/​test_ossl_x509_str.c Tests external-data indexes and untrusted-stack ownership.
tests/​api.c Removes the unsupported-class expectation for store contexts.
src/​x509.c Implements host-flags retrieval and binary IP matching.
src/​x509_str.c Implements the two store-context APIs.
src/​ssl.c Adds store-context index allocation, reserving index zero.
doc/​dox_comments/​header_files/​ssl.h Adds an English documentation reference to the index API.
doc/​dox_comments/​header_files-ja/​ssl.h Adds the corresponding Japanese documentation reference.
.wolfssl_known_macro_extras Refreshes the known-macro list.

Review effort: Balanced

Comment thread src/ssl.c Resolved
Comment thread src/x509_str.c Resolved
Comment thread tests/api/test_ossl_x509.c Resolved
Comment thread wolfssl/ssl.h Resolved
…in verify callbacks

The handshake verify callback context keeps the peer certs as DER buffers,
not in ctxIntermediates. Build a ctx owned stack from them on demand.
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.

2 participants