Skip to content

Add Mbed TLS 3.6 pk_parse_key and a complete x509_crt_profile - #92

Open
padelsbach wants to merge 1 commit into
wolfSSL:masterfrom
padelsbach:pk-parse-profile
Open

padelsbach wants to merge 1 commit into
wolfSSL:masterfrom
padelsbach:pk-parse-profile

Conversation

@padelsbach

Copy link
Copy Markdown
Contributor

Applications that use the 3.x API to parse keys do not build due to extra params in 3.6's mbedtls_pk_parse_key and mbedtls_pk_parse_keyfile. Add a remap macro (similar to the method done in #87) to provide the 3.x definition. Also, publish mbedtls_x509_crt_profile in the public header file since it is used by applications.

Copilot AI balanced review requested due to automatic review settings December 2, 2026 06:06

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the Mbed TLS compatibility updates.

No open issues 🎉

What changed in this PR

Improves the Mbed TLS compatibility layer by adding 3.6-compatible key-parsing signatures and exposing the certificate-profile structure.

Changes:

  • Adds inline wrappers accepting 3.6’s RNG arguments without using them.
  • Publishes certificate-profile fields while preserving existing behavior: profiles are not applied.
  • Adds regression tests and updates compatibility documentation.
File Description
wolfpsa/​mbedtls/​pk.h Adds 3.6 key-parsing wrappers and remapping macros.
wolfpsa/​mbedtls_compat/​mbedtls/​x509_crt.h Exposes the complete certificate-profile structure.
test/​mbedtls_compat/​ssl_test.c Tests custom profile construction and unchanged handshake behavior.
test/​mbedtls_compat/​mbedtls3_test.c Tests RNG-accepting parsing signatures, parsed keys, and errors.
src/​mbedtls/​x509.c Removes the private placeholder profile definition.
docs/​mbedtls-compatibility.md Documents parsing wrappers, profile fields, and limitations.

Review effort: Balanced

@Frauschi Frauschi 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.

These macros break master's mbedtls3_test.c once rebased onto #84, and the now-public cert profile raises two questions.

Comment thread wolfpsa/mbedtls/pk.h
(void)p_rng;
return mbedtls_pk_parse_key(ctx, key, keylen, pwd, pwdlen);
}
#define mbedtls_pk_parse_key wolfPSA_MbedPkParseKey

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.

Since #84 landed, mbedtls3_test.c calls mbedtls_pk_parse_key with 5 args and mbedtls_pk_parse_keyfile with 3 (around lines 1079, 1082 and 1160), and these macros make them fail to compile after the merge. Please rebase and pass TestRng, NULL there.

#define MBEDTLS_X509_ID_FLAG(id) (UINT32_C(1) << ((id) - 1))

/* Not used: wolfSSL applies its own key and hash limits. Presets are 0. */
typedef struct mbedtls_x509_crt_profile {

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.

With the struct public, an application's stricter profile now compiles but mbedtls_ssl_conf_cert_profile still ignores it, where before the opaque type failed the build. Either keep it opaque or apply at least rsa_min_bitlen through wolfSSL's minimum key sizes.

Comment thread src/mbedtls/x509.c
char unused;
};

const mbedtls_x509_crt_profile mbedtls_x509_crt_profile_default = { 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.

Now that applications can read _default, _next and _suiteb, their all-zero fields say nothing is allowed and there is no RSA minimum. Please initialize them with Mbed TLS 3.6's values, or say in the header that the fields are not Mbed TLS's limits.

mbedtls_pk_init(&byBuf);
mbedtls_pk_init(&byFile);
len = ReadPem(keys[i].file, pem, sizeof(pem));
ok = mbedtls_pk_parse_key(&byBuf, pem, len, NULL, 0, TestRng,

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.

The docs say these wrappers never call f_rng, but TestRng always succeeds, so this would still pass if they did. An RNG that counts its calls and returns an error would check it.

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