Skip to content

x509:reject certificates with a zero serial number (RFC 5280) - #10839

Open
dwivedys wants to merge 1 commit into
Mbed-TLS:developmentfrom
dwivedys:fix-zero-serial-10763
Open

x509:reject certificates with a zero serial number (RFC 5280)#10839
dwivedys wants to merge 1 commit into
Mbed-TLS:developmentfrom
dwivedys:fix-zero-serial-10763

Conversation

@dwivedys

Copy link
Copy Markdown

Description

Fixes #10763

Per RFC 5280 (and Errata #3200), a certificate's serial number
MUST be a positive, non-zero integer. This adds a check in
mbedtls_x509_crt_parse_der_core() (library/x509_crt.c) that rejects a certificate
whose serial number is entirely zero bytes, returning
MBEDTLS_ERR_X509_INVALID_SERIAL.

A new test case is added in test_suite_x509parse.data covering
this.

Note: this change causes ~12 pre-existing tests to fail, because
several existing test certificates in the test suite were
generated with a serial number of zero and were previously
accepted.

I have not modified those test fixtures.
Flagging this for maintainer input — happy to regenerate the
affected test certs in a follow-up commit if that's the
preferred approach.

PR checklist

Please remove the segment/s on either side of the | symbol as appropriate, and add any relevant link/s to the end of the line.
If the provided content is part of the present PR remove the # symbol.

  • changelog provided | not required because:
  • framework PR provided Mbed-TLS/mbedtls-framework# | not required
  • TF-PSA-Crypto development PR provided Mbed-TLS/TF-PSA-Crypto# | not required because:
  • TF-PSA-Crypto 1.1 PR provided Mbed-TLS/TF-PSA-Crypto# | not required because:
  • mbedtls development PR provided # | not required because:
  • mbedtls 4.1 PR provided # | not required because:
  • mbedtls 3.6 PR provided # | not required because:
  • tests provided | not required because:

Notes for the submitter

Please refer to the contributing guidelines, especially the
checklist for PR contributors.

Help make review efficient:

  • Multiple simple commits
    • please structure your PR into a series of small commits, each of which does one thing
  • Avoid force-push
    • please do not force-push to update your PR - just add new commit(s)
  • See our Guidelines for Contributors for more details about the review process.

@bensze01 bensze01 self-assigned this Jul 23, 2026
@bensze01

Copy link
Copy Markdown
Contributor

Thank you for your contribution.

To quote RFC 5280

Note: Non-conforming CAs may issue certificates with serial numbers
that are negative or zero. Certificate users SHOULD be prepared to
gracefully handle such certificates.

As such, I don't think it's useful to reject zero-serial certificates.

@dwivedys

Copy link
Copy Markdown
Author

Sorry since this was my first time working on an open source project may be I am not fully conversant with how you all handle these things. What I do want to understand is that I worked on this basis my understanding of the ask that zero certs need to be rejected so I did it. Now you are saying its not useful to do so and they should be handled gracefully. What does this mean? Meaning we wont reject them but perhaps send a useful message back to the user saying the cert is invalid which to me is tantamount to rejecting 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.

MbedTLS accepts a certificate whose serial number is zero

2 participants