Skip to content

Allow serial number 0 for root CA certificates#9567

Merged
dgarske merged 9 commits into
wolfSSL:masterfrom
jackctj117:serial-0
May 12, 2026
Merged

Allow serial number 0 for root CA certificates#9567
dgarske merged 9 commits into
wolfSSL:masterfrom
jackctj117:serial-0

Conversation

@jackctj117

Copy link
Copy Markdown
Contributor

Fixes #8615

This pull request updates the logic for validating X.509 certificate serial numbers in wolfcrypt/src/asn.c. The main change is to improve compliance with RFC 5280 while allowing for real-world exceptions involving root CAs. The previous strict check for zero serial numbers is now more nuanced, permitting serial number 0 for self-signed CA certificates but still rejecting it for other certificates.

Certificate serial number validation improvements:

  • Moved and updated the check for serial numbers of 0 to allow self-signed CA (root) certificates to have a serial number of 0, while still treating serial 0 as an error for all other certificates. This better aligns with RFC 5280 and real-world trust store practices. [1] [2]
  • Removed the previous check that always treated a serial number of 0 as an error, regardless of certificate type.

Testing

Tested with certificates generated using OpenSSL to verify all scenarios:

  • Root CA with serial 0 loads successfully (previously failed, now passes)
  • End-entity cert with serial 0 is correctly rejected
  • Normal end-entity cert signed by root CA with serial 0 verifies successfully
  • Self-signed non-CA cert with serial 0 is correctly rejected

@jackctj117 jackctj117 self-assigned this Dec 19, 2025

@kareem-wolfssl kareem-wolfssl 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 look good.

Can you add some test cases with a CA and leaf cert with a serial of 0?

@jackctj117

Copy link
Copy Markdown
Contributor Author

@kareem-wolfssl it looks like the failures are looking for an expected failure due to a self-signed CA certificate with serial number 0.

@kareem-wolfssl

Copy link
Copy Markdown
Contributor

@kareem-wolfssl it looks like the failures are looking for an expected failure due to a self-signed CA certificate with serial number 0.

Yes, you will need to update the failing test test_MakeCertWith0Ser since we no longer expect a root CA with serial 0 to fail.

@dgarske

dgarske commented Dec 26, 2025

Copy link
Copy Markdown
Member

@jackctj117 looks like some valid unit test failures you will need to look into. All related to --enable-asn=original.

FAILURES:
   390: test_SerialNumber0_RootCA

@jackctj117

Copy link
Copy Markdown
Contributor Author

Jenkins retest this please. History lost.

1 similar comment
@jackctj117

Copy link
Copy Markdown
Contributor Author

Jenkins retest this please. History lost.

@jackctj117

Copy link
Copy Markdown
Contributor Author

Jenkins retest this please

1 similar comment
@jackctj117

Copy link
Copy Markdown
Contributor Author

Jenkins retest this please

@jackctj117

Copy link
Copy Markdown
Contributor Author

Jenkins retest this

@jackctj117

Copy link
Copy Markdown
Contributor Author

Jenkins retest this please

Comment thread tests/api/test_asn.c Outdated
Comment thread tests/api/test_asn.c Outdated
@kareem-wolfssl

kareem-wolfssl commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

Jenkins retest this please

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a 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.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated no new comments.


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

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

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

wolfcrypt/src/asn.c:23904

  • The log message for cert->serialSz == 0 is confusing: it suggests a certificate might legitimately have “no serial number”, but X.509 certificates always have a serial number and RFC 5280 requires it to be present. Consider rewording to clearly state that an empty/zero-length serial is invalid, and (if appropriate in this file) emit the verbose error macro consistently with other parse failures.

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

Comment thread wolfcrypt/src/asn.c Outdated
Comment thread tests/api/test_asn.c

@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 #9567

Scan targets checked: wolfcrypt-api_misuse, wolfcrypt-bugs, wolfcrypt-compliance, wolfcrypt-concurrency, wolfcrypt-consttime, wolfcrypt-defaults, wolfcrypt-mutation, wolfcrypt-portability, wolfcrypt-proptest, wolfcrypt-src, wolfcrypt-zeroize

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

This review was generated automatically by Fenrir. Findings are non-blocking.

Comment thread wolfcrypt/src/asn.c Outdated
Comment thread wolfcrypt/src/asn.c
@jackctj117 jackctj117 requested review from SparkiDev and removed request for douzzer April 20, 2026 15:09
SparkiDev
SparkiDev previously approved these changes Apr 20, 2026
@github-actions

github-actions Bot commented Apr 27, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

gcc-arm-cortex-m4

  • FLASH: .text +192 B (+0.1%, 197,567 B / 262,144 B, total: 75% used)

gcc-arm-cortex-m4-baremetal

  • FLASH: .text +128 B (+0.2%, 64,633 B / 262,144 B, total: 25% used)

gcc-arm-cortex-m4-min-ecc

  • FLASH: .text +128 B (+0.2%, 60,219 B / 262,144 B, total: 23% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +256 B (+0.2%, 121,051 B / 262,144 B, total: 46% used)

@dgarske

dgarske commented May 5, 2026

Copy link
Copy Markdown
Member

@jackctj117 please fix merge conflicts. Thanks

@jackctj117 jackctj117 removed their assignment May 7, 2026
@SparkiDev

Copy link
Copy Markdown
Contributor

Please resolve all comments.

@jackctj117

Copy link
Copy Markdown
Contributor Author

@SparkiDev All comments resolved.

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.

[Bug]: WolfSSL accepts a certificate whose serial number is zero

9 participants