Skip to content

Adding or make functional OpenSSL compat APIs - #11363

Open
SparkiDev wants to merge 1 commit into
wolfSSL:masterfrom
SparkiDev:openssl_compat_api
Open

SparkiDev wants to merge 1 commit into
wolfSSL:masterfrom
SparkiDev:openssl_compat_api

Conversation

@SparkiDev

@SparkiDev SparkiDev commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

X509_check_purpose
SSL_CTX_set0_tmp_dh_pkey
SSL_get1_peer_certificate
EVP_aes_*_wrap, EVP_aes_*_wrap_pad
EVP_PKEY_get_raw_private_key, EVP_PKEY_get_raw_public_key
EVP_CIPHER_CTX_iv, EVP_CIPHER_CTX_iv_noconst
OCSP_crl_reason_str
X509_get_default_cert_dir, X509_get_default_cert_dir_env
X509_get_default_cert_file, X509_get_default_cert_file_env
SSL_add_dir_cert_subjects_to_stack, SSL_add_file_cert_subjects_to_stack
EVP_md_null
SSL_CTX_set_client_hello_cb, SSL_client_hello_get0_ext
i2a_ASN1_STRING
SSL_CTX_load_verify_file, SSL_CTX_load_verify_dir

Testing

Regression tested TLS and OpenSSL API configurations.

@SparkiDev SparkiDev self-assigned this Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

gcc-arm-cortex-m4

  • FLASH: .rodata.wolfSSL_ERR_reason_error_string.str1.1 +38 B (+0.0%, 214,270 B / 262,144 B, total: 82% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .rodata +208 B, .text +3,840 B (+0.5%, 811,448 B / 1,048,576 B, total: 77% used)

gcc-arm-cortex-m4-pq

  • FLASH: .rodata +32 B (+0.0%, 320,256 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .rodata +32 B (+0.0%, 350,008 B / 1,048,576 B, total: 33% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .rodata.wolfSSL_ERR_reason_error_string.str1.1 +38 B (+0.0%, 256,728 B / 262,144 B, total: 98% used)

gcc-arm-cortex-m7

  • FLASH: .rodata.wolfSSL_ERR_reason_error_string.str1.1 +38 B (+0.0%, 214,270 B / 262,144 B, total: 82% used)

gcc-arm-cortex-m7-pq

  • FLASH: .rodata +32 B (+0.0%, 321,088 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m7-tls13

  • FLASH: .rodata.wolfSSL_ERR_reason_error_string.str1.1 +38 B (+0.0%, 256,728 B / 262,144 B, total: 98% used)

zephyr-frdm_rw612

  • FLASH: datas +16 B, log_const_area -8 B, rodata +140 B, text +14,496 B (+5.2%, 297,108 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.

@SparkiDev
SparkiDev force-pushed the openssl_compat_api branch 4 times, most recently from 3857c52 to 1ead3c0 Compare September 4, 2026 04:07
@SparkiDev

Copy link
Copy Markdown
Contributor Author

Jenkins: retest this please

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11363

Scan targets checked: wolfcrypt-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src

Findings: 5
5 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Comment thread wolfcrypt/src/evp_pk.c Resolved
Comment thread wolfcrypt/src/evp.c Resolved
Comment thread tests/api/test_evp_cipher.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/ssl.c Resolved
Comment thread wolfcrypt/src/evp_pk.c Resolved
Comment thread tests/api/test_evp_cipher.c Resolved
Comment thread wolfcrypt/src/evp.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/ssl.c Resolved
@SparkiDev
SparkiDev force-pushed the openssl_compat_api branch 2 times, most recently from 84bb3a3 to ea54e15 Compare September 6, 2026 21:09
@SparkiDev

Copy link
Copy Markdown
Contributor Author

Jenkins: retest this please

@SparkiDev
SparkiDev force-pushed the openssl_compat_api branch 2 times, most recently from 270c3da to e08d01c Compare September 7, 2026 02:05
@SparkiDev

Copy link
Copy Markdown
Contributor Author

Jenkins: retest this please

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11363

Scan targets checked: wolfcrypt-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src

Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Comment thread tests/api/test_tls.c Resolved
Comment thread src/ssl.c Resolved
Comment thread tests/api/test_tls.c Resolved
Comment thread src/ssl.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11363

Scan targets checked: wolfcrypt-bugs, wolfcrypt-rs-bugs, wolfcrypt-src, wolfssl-bugs, wolfssl-src

Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Comment thread wolfcrypt/src/evp_pk.c Resolved
Comment thread wolfcrypt/src/evp_pk.c Resolved
Comment thread src/x509.c Resolved
Comment thread src/x509.c Resolved
Comment thread wolfcrypt/src/evp_pk.c Resolved
@SparkiDev
SparkiDev force-pushed the openssl_compat_api branch 3 times, most recently from 3b762b0 to 89239e9 Compare November 6, 2026 01:21
@SparkiDev SparkiDev assigned SparkiDev and unassigned julek-wolfssl Nov 6, 2026
@julek-wolfssl
julek-wolfssl self-requested a review November 6, 2026 17:33
@SparkiDev
SparkiDev force-pushed the openssl_compat_api branch 2 times, most recently from 074caaf to f3c2741 Compare November 8, 2026 22:39
@SparkiDev SparkiDev assigned julek-wolfssl and unassigned SparkiDev Nov 9, 2026

@julek-wolfssl julek-wolfssl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please address reviews in new commits instead of amending existing ones.

Comment thread wolfcrypt/src/evp.c Outdated
#if defined(WOLFSSL_EVP_AES_KEYWRAP)
/* Wrap or unwrap a key with AES-KW (RFC 3394).
*
* Not a streaming operation - hence no Update in the name: the whole key must

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* Not a streaming operation - hence no Update in the name: the whole key must
* One-shot helper function: the whole key must

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread wolfcrypt/src/evp_pk.c
Comment on lines +920 to +1051
int wolfSSL_EVP_PKEY_get_raw_private_key(const WOLFSSL_EVP_PKEY* pkey,
unsigned char* priv, size_t* len)
{
#ifdef WOLFSSL_EVP_HAVE_RAW_KEYS
int ret = 0;
byte buf[128];
word32 bufLen = (word32)sizeof(buf);
#endif

WOLFSSL_ENTER("wolfSSL_EVP_PKEY_get_raw_private_key");

if (pkey == NULL || len == NULL) {
return 0;
}

#ifndef WOLFSSL_EVP_HAVE_RAW_KEYS
(void)priv;
WOLFSSL_MSG("build has no key type with a raw form");
return 0;
#else

switch (pkey->type) {
#if defined(HAVE_ED25519) && defined(HAVE_ED25519_KEY_EXPORT)
case WC_EVP_PKEY_ED25519:
if (pkey->ed25519 == NULL) {
break;
}
/* Checked here rather than left to the export below: the
* released FIPS modules copy the private key buffer without
* checking that it holds a key, and so would answer with zeros
* for a key built from a public key alone. */
if (!pkey->ed25519->privKeySet) {
WOLFSSL_MSG("ed25519 key has no private key to report");
break;
}
if (wc_ed25519_export_private_only(pkey->ed25519, buf, &bufLen)
!= 0) {
WOLFSSL_MSG("wc_ed25519_export_private_only failed");
break;
}
if (wolfssl_evp_pkey_raw_cached(pkey)) {
ret = wolfssl_evp_pkey_raw_out((const byte*)pkey->pkey.ptr,
(word32)pkey->pkey_sz, priv, len);
}
else {
ret = wolfssl_evp_pkey_raw_out(buf, bufLen, priv, len);
}
break;
#endif
#if defined(HAVE_ED448) && defined(HAVE_ED448_KEY_EXPORT)
case WC_EVP_PKEY_ED448:
if (pkey->ed448 == NULL) {
break;
}
/* As for Ed25519 above: the released FIPS modules do not check
* that the key has a private part before copying it out. */
if (!pkey->ed448->privKeySet) {
WOLFSSL_MSG("ed448 key has no private key to report");
break;
}
if (wc_ed448_export_private_only(pkey->ed448, buf, &bufLen) != 0) {
WOLFSSL_MSG("wc_ed448_export_private_only failed");
break;
}
if (wolfssl_evp_pkey_raw_cached(pkey)) {
ret = wolfssl_evp_pkey_raw_out((const byte*)pkey->pkey.ptr,
(word32)pkey->pkey_sz, priv, len);
}
else {
ret = wolfssl_evp_pkey_raw_out(buf, bufLen, priv, len);
}
break;
#endif
#if defined(HAVE_CURVE25519) && defined(HAVE_CURVE25519_KEY_EXPORT)
case WC_EVP_PKEY_X25519:
if (pkey->curve25519 == NULL) {
break;
}
/* Raw X25519 keys are little-endian (RFC 7748). */
if (wc_curve25519_export_private_raw_ex(pkey->curve25519, buf,
&bufLen, EC25519_LITTLE_ENDIAN) != 0) {
WOLFSSL_MSG("wc_curve25519_export_private_raw_ex failed");
break;
}
if (wolfssl_evp_pkey_raw_cached(pkey)) {
ret = wolfssl_evp_pkey_raw_out((const byte*)pkey->pkey.ptr,
(word32)pkey->pkey_sz, priv, len);
}
else {
#ifdef HAVE_CURVE25519_KEY_IMPORT
/* The export above clamped the scalar; prefer the bytes the key
* was decoded from, which is what OpenSSL reports. */
(void)wolfssl_evp_pkey_orig_scalar(pkey, X25519k, buf, bufLen);
#endif
ret = wolfssl_evp_pkey_raw_out(buf, bufLen, priv, len);
}
break;
#endif
#if defined(HAVE_CURVE448) && defined(HAVE_CURVE448_KEY_EXPORT)
case WC_EVP_PKEY_X448:
if (pkey->curve448 == NULL) {
break;
}
if (wc_curve448_export_private_raw_ex(pkey->curve448, buf, &bufLen,
EC448_LITTLE_ENDIAN) != 0) {
WOLFSSL_MSG("wc_curve448_export_private_raw_ex failed");
break;
}
if (wolfssl_evp_pkey_raw_cached(pkey)) {
ret = wolfssl_evp_pkey_raw_out((const byte*)pkey->pkey.ptr,
(word32)pkey->pkey_sz, priv, len);
}
else {
#ifdef HAVE_CURVE448_KEY_IMPORT
/* The export above clamped the scalar; prefer the bytes the key
* was decoded from, which is what OpenSSL reports. */
(void)wolfssl_evp_pkey_orig_scalar(pkey, X448k, buf, bufLen);
#endif
ret = wolfssl_evp_pkey_raw_out(buf, bufLen, priv, len);
}
break;
#endif
default:
WOLFSSL_MSG("key type has no raw private form");
break;
}

ForceZero(buf, sizeof(buf));

return ret;
#endif /* WOLFSSL_EVP_HAVE_RAW_KEYS */
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we export to buf when we return the cached version when available?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cached check hoisted above the export

Comment thread src/x509.c
Comment on lines +4236 to 4253
*/
const char* wolfSSL_X509_get_default_cert_file_env(void)
{
WOLFSSL_STUB("X509_get_default_cert_file_env");
return "";
return "SSL_CERT_FILE";
}

const char* wolfSSL_X509_get_default_cert_file(void)
/* Get the name of the environment variable that overrides the default CA
* certificate directory.
*
* Returns the same name as OpenSSL's function of this name, and is the
* variable wolfSSL_CTX_load_system_CA_certs() already reads.
*
* @return Environment variable name.
*/
const char* wolfSSL_X509_get_default_cert_dir_env(void)
{
WOLFSSL_STUB("X509_get_default_cert_file");
return "";
return "SSL_CERT_DIR";
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should these be defined as macros somewhere instead of repeating the string literal everywhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think that is necessary. No real repetition.

Comment thread src/x509.c
return 0;
}

keyOID = wolfssl_x509_sig_key_type(x->sigOID);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not use SigOidMatchesKeyOid instead of creating a whole new function just for this check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call, but it's static in wolfcrypt/src/asn.c:18501, so src/x509.c can't call it without exposing it first. Happy to do that as a follow-up; it's not a drop-in substitution.

Comment thread src/x509.c
Comment on lines +17892 to +17911
static int wolfssl_x509_self_signed(WOLFSSL_X509* x)
{
int keyOID;

if (wolfSSL_X509_NAME_cmp(&x->issuer, &x->subject) != 0) {
return 0;
}

keyOID = wolfssl_x509_sig_key_type(x->sigOID);
if (keyOID == 0) {
/* An algorithm that cannot be mapped cannot be shown to match. */
return 0;
}
/* An RSA key produces both PKCS #1 v1.5 and PSS signatures. */
if ((keyOID == RSAPSSk) && (x->pubKeyOID == RSAk)) {
return 1;
}

return keyOID == x->pubKeyOID;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy over the value from dCert->selfSigned instead of re-implementing the check here.

@SparkiDev SparkiDev Dec 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Two obstacles. It's never copied to WOLFSSL_X509, so this needs a new field plus a copy in CopyDecodedToX509(). More importantly the two aren't equivalent: dCert->selfSigned is selfIssued && (src/internal.c:18768), whereas wolfssl_x509_self_signed() only compares issuer/subject and matches the sig algorithm to the key type — it never verifies a signature. Yours is stricter and more correct, but only for certs that went through the verify path; a standalone parsed X509 wouldn't have it set. Worth doing deliberately rather than as a swap.

Comment thread src/x509.c
Comment on lines +17997 to +18162
int wolfSSL_X509_check_purpose(WOLFSSL_X509* x, int id, int ca)
{
byte ekuWanted;
word16 kuWanted;
byte nsWanted;
/* Which of OpenSSL's CA rules this role applies when ca is set. */
enum { CA_RULE_SSL, CA_RULE_SMIME, CA_RULE_PLAIN } caRule = CA_RULE_PLAIN;

WOLFSSL_ENTER("wolfSSL_X509_check_purpose");

if (x == NULL) {
return WOLFSSL_FATAL_ERROR;
}

/* -1 asks only that the extensions be readable. wolfSSL parses them when
* the certificate is decoded, so there is nothing to populate. */
if (id == -1) {
return 1;
}

switch (id) {
case WOLFSSL_X509_PURPOSE_ANY:
/* Constrains nothing, for a CA as much as for a leaf. */
return 1;
case WOLFSSL_X509_PURPOSE_OCSP_HELPER:
/* A leaf is left to the OCSP code to check, but a CA still has to
* be a valid one. */
if (!ca) {
return 1;
}
/* OpenSSL returns check_ca()'s own value here, not a boolean. */
return wolfssl_x509_check_ca(x);
case WOLFSSL_X509_PURPOSE_SSL_CLIENT:
ekuWanted = EXTKEYUSE_CLIENT_AUTH;
caRule = CA_RULE_SSL;
kuWanted = KEYUSE_DIGITAL_SIG | KEYUSE_KEY_AGREE;
nsWanted = WC_NS_SSL_CLIENT;
break;
case WOLFSSL_X509_PURPOSE_SSL_SERVER:
ekuWanted = EXTKEYUSE_SERVER_AUTH;
caRule = CA_RULE_SSL;
kuWanted = KEYUSE_DIGITAL_SIG | KEYUSE_KEY_ENCIPHER |
KEYUSE_KEY_AGREE;
nsWanted = WC_NS_SSL_SERVER;
break;
case WOLFSSL_X509_PURPOSE_NS_SSL_SERVER:
ekuWanted = EXTKEYUSE_SERVER_AUTH;
caRule = CA_RULE_SSL;
kuWanted = KEYUSE_KEY_ENCIPHER;
nsWanted = WC_NS_SSL_SERVER;
break;
case WOLFSSL_X509_PURPOSE_SMIME_SIGN:
ekuWanted = EXTKEYUSE_EMAILPROT;
caRule = CA_RULE_SMIME;
kuWanted = KEYUSE_DIGITAL_SIG | KEYUSE_CONTENT_COMMIT;
/* WC_NS_SSL_CLIENT is accepted alongside WC_NS_SMIME to match
* OpenSSL's workaround for certificates that set only the
* former. */
nsWanted = WC_NS_SMIME | WC_NS_SSL_CLIENT;
break;
case WOLFSSL_X509_PURPOSE_SMIME_ENCRYPT:
ekuWanted = EXTKEYUSE_EMAILPROT;
caRule = CA_RULE_SMIME;
kuWanted = KEYUSE_KEY_ENCIPHER;
nsWanted = WC_NS_SMIME | WC_NS_SSL_CLIENT;
break;
case WOLFSSL_X509_PURPOSE_CRL_SIGN:
/* No extendedKeyUsage or netscape type is defined for CRL
* signing. */
ekuWanted = 0;
kuWanted = KEYUSE_CRL_SIGN;
nsWanted = 0;
break;
case WOLFSSL_X509_PURPOSE_CODE_SIGN:
/* A CA for code signing is just a CA. */
if (ca) {
return wolfssl_x509_check_ca(x);
}
/* CA/Browser Forum baseline requirements, as OpenSSL checks them:
* keyUsage has to be there, critical, allow digital signatures and
* allow neither certificate nor CRL signing; extendedKeyUsage has
* to be there, allow code signing, and allow neither any use nor
* server authentication. */
if ((!x->keyUsageSet) || (!x->keyUsageCrit) ||
((x->keyUsage & KEYUSE_DIGITAL_SIG) == 0) ||
((x->keyUsage &
(KEYUSE_KEY_CERT_SIGN | KEYUSE_CRL_SIGN)) != 0)) {
WOLFSSL_MSG("Key usage does not allow code signing");
return 0;
}
if ((x->extKeyUsageSrc == NULL) ||
((x->extKeyUsage & EXTKEYUSE_CODESIGN) == 0) ||
((x->extKeyUsage &
(EXTKEYUSE_ANY | EXTKEYUSE_SERVER_AUTH)) != 0)) {
WOLFSSL_MSG("Extended key usage does not allow code signing");
return 0;
}
return 1;
case WOLFSSL_X509_PURPOSE_TIMESTAMP_SIGN:
/* A CA for timestamping is just a CA; the leaf rule below cannot
* be applied, so it is refused there. */
if (ca) {
return wolfssl_x509_check_ca(x);
}
/* Needs the extendedKeyUsage to be exactly timeStamping and
* critical, which is not recorded when a certificate is parsed. */
WOLFSSL_MSG("Cannot check timestamp signing on a leaf");
return 0;
default:
/* A purpose this build does not know. Report "not permitted"
* rather than an error: OpenSSL answers 0 for these, and callers
* commonly write "if (X509_check_purpose(...))", where a negative
* return would read as permission granted. */
WOLFSSL_MSG("Unsupported X509 purpose");
return 0;
}

/* extendedKeyUsage: present and naming none of the accepted uses. This
* is checked before the CA rules, as OpenSSL does, so a CA whose
* extendedKeyUsage excludes the role is refused for it.
* anyExtendedKeyUsage deliberately does not satisfy a specific purpose:
* OpenSSL's xku_reject() treats it as its own bit and rejects such a
* certificate, and this is an authorization decision, so match it. */
if ((ekuWanted != 0) && (x->extKeyUsageSrc != NULL) &&
((x->extKeyUsage & ekuWanted) == 0)) {
WOLFSSL_MSG("Certificate extended key usage does not allow purpose");
return 0;
}

if (ca) {
int caRet;

if (caRule == CA_RULE_SSL) {
return wolfssl_x509_check_ssl_ca(x) != 0;
}
caRet = wolfssl_x509_check_ca(x);
if (caRet == 0) {
return 0;
}
#ifndef IGNORE_NETSCAPE_CERT_TYPE
/* A certificate only a netscape type vouched for has to have named
* the S/MIME CA type specifically. */
if ((caRule == CA_RULE_SMIME) && (caRet == 5) &&
((x->nsCertType & WC_NS_SMIME_CA) == 0)) {
return 0;
}
#endif
/* Report how the decision was reached, as OpenSSL does: a caller may
* distinguish a certificate that only a netscape type vouched for
* from one basicConstraints named. */
return caRet;
}

/* keyUsage: present and naming none of the accepted uses. */
if ((kuWanted != 0) && x->keyUsageSet &&
((x->keyUsage & kuWanted) == 0)) {
WOLFSSL_MSG("Certificate key usage does not allow purpose");
return 0;
}

if ((nsWanted != 0) && !wolfssl_x509_check_ns_cert_type(x, nsWanted)) {
return 0;
}

return 1;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few problems in wolfSSL_X509_check_purpose() and its helpers:

1. An empty extendedKeyUsage is treated as absent (L18120, src/internal.c:16576)

CopyDecodedToX509() copies the EKU only when extExtKeyUsageSz > 0. The purpose check then reads extKeyUsageSrc == NULL as "no EKU". A leaf with extendedKeyUsage = SEQUENCE {} and keyUsage digitalSignature passes SSL_CLIENT, SSL_SERVER and SMIME_SIGN. OpenSSL refuses it, and RFC 5280 4.2.1.12 requires SIZE (1..MAX). With ca=1 the EKU check is skipped too.

Please add an EKU-present flag to WOLFSSL_X509 (from dCert->extExtKeyUsageSet) and test that. Consider also rejecting an empty EKU when decoding.

2. TIMESTAMP_SIGN always returns 0 for a leaf (L18095)

The comment says EKU criticality "is not recorded when a certificate is parsed". It is: extKeyUsageCrit, extKeyUsage and extKeyUsageCount are all filled in. As written, a compliant RFC 3161 TSA cert is refused, where OpenSSL says yes.

Please implement it like OpenSSL's check_purpose_timestamp_sign():

  • EKU present and critical, and timeStamping is the only purpose (extKeyUsageCount == 1 matches RFC 3161 2.3 exactly);
  • keyUsage, if present, has digitalSignature and/or nonRepudiation and nothing else.

3. wolfSSL_X509_check_ca() disagrees with the new wolfssl_x509_check_ca() (L18164)

It returns 1 for any isCa and 4 for any critical EKU. Some results:

  • CA:FALSE with a critical serverAuth EKU gives 4.
  • CA:TRUE with keyUsage digitalSignature only gives 1. It should be 0 (RFC 5280 4.2.1.3).
  • A v1 self-signed root gives 0. It should be 3.

This code predates the PR, but the correct helper now sits right next to it. Can wolfSSL_X509_check_ca() call wolfssl_x509_check_ca()?

Minor / compat (no change needed, just noting):

  • SSL_SERVER does not accept the legacy SGC EKUs (msSGC/nsSGC), which OpenSSL does. This matches RFC 5280, so it's fine, but maybe say so in a comment.
  • For certs OpenSSL flags invalid (e.g. empty keyUsage), OpenSSL returns -1 and this returns 0/1.

Tests for 1–3 would help: an empty-EKU leaf, a critical timeStamping-only leaf, and X509_check_ca() on a CA:FALSE leaf with a critical EKU.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. New extKeyUsageSet flag, plumbed and consumed.
  2. Implemented the leaf rule; deleted the false comment.
  3. Confirmed on all three cases, and wolfssl_x509_check_ca() would indeed fix them. But it's pre-existing (no +/- line in this PR touches it) and changing it alters long-standing public-API behaviour, which would make this branch non-additive. Proposing a separate PR for this fix.

Added tests.

Comment thread src/ssl_api_cert.c Outdated
Comment on lines +1860 to +1875
ReadDirCtx* readCtx;

WOLFSSL_ENTER("wolfSSL_add_dir_cert_subjects_to_stack");

if ((list == NULL) || (dir == NULL)) {
WOLFSSL_MSG("Bad parameter");
return 0;
}

/* ReadDirCtx holds a full path buffer - keep it off the stack. */
readCtx = (ReadDirCtx*)XMALLOC(sizeof(ReadDirCtx), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (readCtx == NULL) {
WOLFSSL_MSG("Memory error");
return 0;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we want to use WC_DECLARE_VAR to reduce allocations?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@SparkiDev
SparkiDev requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot December 4, 2026 01:54
@SparkiDev

Copy link
Copy Markdown
Contributor Author

@claude review

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.

Comment thread src/tls13.c Resolved
Comment thread src/ssl.c Resolved
Comment thread src/ssl_load.c Resolved
Comment thread src/ssl_load.c Resolved
Comment thread src/x509.c Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Findings marked 🟡 are optional suggestions and need no follow-up push.

Comment thread wolfcrypt/src/evp_pk.c Resolved
Comment thread wolfcrypt/src/evp.c Resolved
Comment thread src/x509.c Resolved
Comment thread src/x509.c Resolved
Comment thread wolfssl/openssl/evp.h Resolved
Comment thread wolfssl/ssl.h Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11363

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/configs/os-check-linux.json, certs/any-eku-cert.pem, certs/check_cert_chains.sh, certs/code-sign-cert.pem, certs/empty-eku-cert.pem, certs/include.am, certs/ns-ca-only-cert.pem, certs/ns-cert-type-cert.pem, certs/ns-zero-mask-cert.pem, certs/renewcerts.sh, certs/renewcerts/wolfssl.cnf, certs/statickeys/gen-static.sh, certs/statickeys/include.am, certs/statickeys/x448-pub.der, certs/statickeys/x448-pub.pem, certs/statickeys/x448.der, certs/statickeys/x448.pem, certs/v1-root-cert.pem, certs/v1-self-issued-cert.pem, doc/dox_comments/header_files/evp.h and 10 more
Coverage: 21 of 33 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_aes.c, tests/api/test_evp_cipher.c, tests/api/test_evp_digest.c, tests/api/test_evp_pkey.c, tests/api/test_ocsp.c, tests/api/test_ossl_asn1.c, tests/api/test_ossl_obj.c, tests/api/test_ossl_rsa.c, tests/api/test_ssl_cert.c, tests/api/test_tls_bounds.c and 2 more

Findings: 4
4 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Max

Comment thread wolfcrypt/src/evp_pk.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/x509.c Resolved
Comment thread tests/api/test_tls.c Resolved
@SparkiDev

Copy link
Copy Markdown
Contributor Author

@claude review

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 API test helper references the SNI-only TLSX_SERVER_NAME constant, causing compilation to fail with OPENSSL_EXTRA and SSLv3 enabled but SNI disabled.

1 open issue
5 resolved since last review

Review effort: Balanced

Comment thread tests/api/test_tls.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11363

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/configs/os-check-linux.json, certs/any-eku-cert.pem, certs/check_cert_chains.sh, certs/code-sign-cert.pem, certs/empty-eku-cert.pem, certs/include.am, certs/ns-ca-only-cert.pem, certs/ns-cert-type-cert.pem, certs/ns-zero-mask-cert.pem, certs/renewcerts.sh, certs/renewcerts/wolfssl.cnf, certs/statickeys/gen-static.sh, certs/statickeys/include.am, certs/statickeys/x448-pub.der, certs/statickeys/x448-pub.pem, certs/statickeys/x448.der, certs/statickeys/x448.pem, certs/v1-root-cert.pem, certs/v1-self-issued-cert.pem, doc/dox_comments/header_files/evp.h and 10 more
Coverage: 6 of 9 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_evp_pkey.c, tests/api/test_ossl_x509.c, wolfssl/openssl/evp.h

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

Comment thread src/internal.c Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Findings marked 🟡 are optional suggestions and need no follow-up push.

Comment thread wolfcrypt/src/evp.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/ssl_asn1.c Resolved
@SparkiDev

Copy link
Copy Markdown
Contributor Author

@claude review

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

Context switching can cause an ECH use-after-free, and regenerating DER-decoded keys can export mismatched private and public keys.

3 open issues
1 resolved since last review

Review effort: Balanced

Comment thread tests/api/test_evp_pkey.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/tls13.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #11363

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/configs/os-check-linux.json, certs/any-eku-cert.pem, certs/check_cert_chains.sh, certs/code-sign-cert.pem, certs/empty-eku-cert.pem, certs/include.am, certs/ns-ca-only-cert.pem, certs/ns-cert-type-cert.pem, certs/ns-zero-mask-cert.pem, certs/renewcerts.sh, certs/renewcerts/wolfssl.cnf, certs/statickeys/gen-static.sh, certs/statickeys/include.am, certs/statickeys/x448-pub.der, certs/statickeys/x448-pub.pem, certs/statickeys/x448.der, certs/statickeys/x448.pem, certs/v1-root-cert.pem, certs/v1-self-issued-cert.pem, doc/dox_comments/header_files/evp.h and 10 more
Coverage: 4 of 6 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_evp_cipher.c, tests/api/test_tls.c

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

Comment thread wolfcrypt/src/evp.c Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Findings marked 🟡 are optional suggestions and need no follow-up push.

Comment thread src/tls13.c Resolved
Comment thread wolfcrypt/src/evp.c Resolved
Comment thread src/x509.c Resolved
X509_check_purpose
SSL_CTX_set0_tmp_dh_pkey
SSL_get1_peer_certificate
EVP_aes_*_wrap, EVP_aes_*_wrap_pad
EVP_PKEY_get_raw_private_key, EVP_PKEY_get_raw_public_key
EVP_CIPHER_CTX_iv, EVP_CIPHER_CTX_iv_noconst
OCSP_crl_reason_str
X509_get_default_cert_dir, X509_get_default_cert_dir_env
X509_get_default_cert_file_env
SSL_add_dir_cert_subjects_to_stack, SSL_add_file_cert_subjects_to_stack
EVP_md_null
SSL_CTX_set_client_hello_cb, SSL_client_hello_get0_ext
i2a_ASN1_STRING
SSL_CTX_load_verify_file, SSL_CTX_load_verify_dir

WOLFSSL_X509 gains a flag recording whether the extendedKeyUsage
extension was present, taken from DecodedCert's extExtKeyUsageSet.

X509_check_purpose checks timestamp signing on a leaf rather than
refusing it.

The extendedKeyUsage set through X509_add_ext arrives as a bitmask with
no KeyPurposeId list behind it, so the count the purpose checks use is
derived from the bits, and any encoding left from a previous value is
dropped rather than left to disagree with them.

X509_set_ns_cert_type records a zero mask as an absent extension rather
than one permitting nothing, since that is what the encoder writes.

SSL_client_hello_get0_ext widens the stored extension type instead of
narrowing the requested one, so a value no extension can carry reports
absence instead of aliasing onto one that was sent.

The ClientHello callback also runs for a ClientHello whose extensions
the extension code declines to parse - an SSLv3 one - which otherwise
let a client skip the application's policy by offering that version.

EVP_PKEY_keygen drops the encoding a key was built from before
regenerating into it, raw or DER, so the raw getters report the key that
was generated rather than the one it replaced.  A DER encoding left in
place gave X25519 and X448 a private key read back out of the old key
and a public key from the new one, a pair that does not go together.

EVP_CIPHER_CTX_iv reports the working IV for SM4-CBC and SM4-CTR, which
keep it in the cipher as the AES and DES modes do.

SSL_CTX_load_verify_dir reports a resource failure while still treating
a missing, empty or unreadable directory as success, as OpenSSL does.

EVP_CIPHER_CTX_FLAG_WRAP_ALLOW is defined; the wrap ciphers here need no
opt-in, so it is accepted and ignored.

The ClientHello callback also runs for an SSLv2 format CLIENT-HELLO,
handled by ProcessOldClientHello rather than DoClientHello, which
otherwise let a client skip the application's policy by sending that
format where OLD_HELLO_ALLOWED is built.

An AES key wrap init that carries a key establishes the integrity check
value: given one it is used, and without one the RFC default applies
even where the context held a custom value before, as OpenSSL's
aes_wrap_init_key does.  Whether the caller passed one is recorded
before a NULL IV is replaced with the context's own buffer, which on a
reused context still held the previous value.

An AES key wrap init that names a cipher takes that cipher.  A context
already set to a different wrap cipher kept its own, so re-initialising
an AES-128-WRAP context for AES-256-WRAP wrapped under the first 16
bytes of the new KEK; the stored cipher is now read only by a partial
re-init that names none.

The extendedKeyUsage presence readers test the flag recording that the
extension was there rather than the KeyPurposeId list, so a usage set
through X509_add_ext as a bitmask, which has no list behind it, and a
decoded empty extension both read as present.

The ClientHello callback runs once per ClientHello the peer sent rather
than once per pass over one: an accepted ECH hello is parsed twice, the
outer hello and then the inner one it carried, and the inner pass no
longer calls the callback again.

The callback's documentation records what selecting a context from it
cannot do, both of them properties of SSL_set_SSL_CTX: carry over the
settings cached on the WOLFSSL, the ALPN selection callback among them,
and admit a protocol version the original context refused, which is
decided before the callback is reached.
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.

5 participants