Skip to content

Reject certificates with trailing data. Avoid copying trailing data to WOLFSSL_X509 structs.#10755

Open
kareem-wolfssl wants to merge 2 commits into
wolfSSL:masterfrom
kareem-wolfssl:zd22010
Open

Reject certificates with trailing data. Avoid copying trailing data to WOLFSSL_X509 structs.#10755
kareem-wolfssl wants to merge 2 commits into
wolfSSL:masterfrom
kareem-wolfssl:zd22010

Conversation

@kareem-wolfssl

Copy link
Copy Markdown
Contributor

Description

Fixes zd#22010

Testing

Provided reproducer, built-in tests

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

In addition, only copy the certificate itself to WOLFSSL_X509, omitting trailing bytes.

Thanks to Lucca Hirschi (Inria, France) and the tlspuffin team for the report.

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.

Pull request overview

This PR tightens X.509 parsing behavior to prevent accepting and re-emitting certificates that have extra trailing bytes beyond the certificate’s outer ASN.1 SEQUENCE, while preserving support for OpenSSL/RFC “TRUSTED CERTIFICATE” blobs that legitimately carry auxiliary trust data after the cert.

Changes:

  • Add strict-mode detection/rejection of trailing bytes after the certificate’s outer SEQUENCE (with an internal opt-out for TRUSTED_CERT_TYPE).
  • Ensure WOLFSSL_X509 DER storage never includes trailing bytes by truncating copies to the parsed outer-SEQUENCE end.
  • Adjust TRUSTED_CERT_TYPE handling to be recognized centrally in ParseCertRelative and fix an API test to use the actual DER length.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
wolfssl/wolfcrypt/asn.h Adds DecodedCert.allowTrailing bit to permit trusted-cert auxiliary trailing data internally.
wolfcrypt/src/asn.c Rejects trailing bytes in strict builds; centralizes TRUSTED_CERT_TYPE handling to allow aux trailing data.
tests/api.c Fixes a test to use the returned DER length (avoids unintended trailing bytes).
src/x509.c Uses ParseCertRelative’s TRUSTED_CERT_TYPE handling and clarifies trusted-cert truncation behavior.
src/internal.c Truncates stored DER in X509/ACERT objects to the end of the outer SEQUENCE (prevents re-emitting trailing bytes).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread wolfcrypt/src/asn.c
Comment on lines +22040 to +22044
if ((ret == 0) && (!done) && (!stopAtPubKey) && (!stopAfterPubKey) &&
(!cert->allowTrailing) && (cert->srcIdx != cert->maxIdx)
#ifdef WOLFSSL_CERT_REQ
&& (!cert->isCSR)
#endif
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

gcc-arm-cortex-m0plus

  • FLASH: .text +84 B (+0.1%, 63,579 B / 262,144 B, total: 24% used)

gcc-arm-cortex-m3

  • FLASH: .text +48 B (+0.0%, 121,457 B / 262,144 B, total: 46% used)

gcc-arm-cortex-m4

  • FLASH: .text +64 B (+0.0%, 199,116 B / 262,144 B, total: 76% used)

gcc-arm-cortex-m4-baremetal

  • FLASH: .text +64 B (+0.1%, 66,123 B / 262,144 B, total: 25% used)

gcc-arm-cortex-m4-crypto-only

  • FLASH: .text +64 B (+0.0%, 173,738 B / 262,144 B, total: 66% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +64 B (+0.0%, 179,864 B / 1,048,576 B, total: 17% used)

gcc-arm-cortex-m4-min-ecc

  • FLASH: .text +64 B (+0.1%, 61,101 B / 262,144 B, total: 23% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .text +128 B (+0.0%, 768,260 B / 1,048,576 B, total: 73% used)

gcc-arm-cortex-m4-pkcs7

  • FLASH: .text +64 B (+0.0%, 211,437 B / 262,144 B, total: 81% used)

gcc-arm-cortex-m4-pq

  • FLASH: .text +64 B (+0.0%, 278,000 B / 1,048,576 B, total: 27% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .text +64 B (+0.0%, 323,536 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m4-sp-math

  • FLASH: .text +64 B (+0.1%, 61,101 B / 262,144 B, total: 23% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +64 B (+0.0%, 234,750 B / 262,144 B, total: 90% used)

gcc-arm-cortex-m7

  • FLASH: .text +64 B (+0.0%, 199,116 B / 262,144 B, total: 76% used)

gcc-arm-cortex-m7-pq

  • FLASH: .text +64 B (+0.0%, 278,576 B / 1,048,576 B, total: 27% used)

gcc-arm-cortex-m7-tls13

  • FLASH: .text +64 B (+0.0%, 234,814 B / 262,144 B, total: 90% used)

stm32-sim-stm32h753

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