Allow serial number 0 for root CA certificates#9567
Allow serial number 0 for root CA certificates#9567jackctj117 wants to merge 1 commit intowolfSSL:masterfrom
Conversation
kareem-wolfssl
left a comment
There was a problem hiding this comment.
Changes look good.
Can you add some test cases with a CA and leaf cert with a serial of 0?
|
@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 |
|
@jackctj117 looks like some valid unit test failures you will need to look into. All related to |
|
Jenkins retest this please. History lost. |
1 similar comment
|
Jenkins retest this please. History lost. |
|
Jenkins retest this please |
1 similar comment
|
Jenkins retest this please |
|
Jenkins retest this |
|
Jenkins retest this please |
|
Jenkins retest this please |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 == 0is 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.
|
@jackctj117 please resolve merge conflicts. Thanks |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
wolfcrypt/src/asn.c:1
- Avoid returning directly from the middle of
ParseCertRelative(). This function typically accumulates errors inretand exits through a common path (often needed for consistent cleanup, logging, and state handling). Instead ofreturn ASN_PARSE_E;, setret = ASN_PARSE_E;and follow the function’s existing error-exit pattern (e.g.,goto exit;/break;depending on structure) so resources/state are handled uniformly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
retest this please |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (6)
wolfcrypt/src/asn.c:1
- The PR description is focused on certificate serial-number validation, but this hunk also changes BIT STRING parsing behavior by removing the previous compile-time guard around the zero-length check. If the guard existed to preserve behavior for selftests/FIPS (or specific configurations), this could be an unintended behavior change; consider restoring the conditional compilation (or narrowing the change) unless this is explicitly part of the intended fix.
wolfcrypt/src/asn.c:1 - The comment states the exception is for certs “being loaded as trust anchors”, but the condition implemented here only checks
cert->isCA && cert->selfSigned(i.e., it’s not tied to a “trust-anchor load” context). Either adjust the comment to match the actual behavior, or tighten the condition so the exception is only applied in the trust-anchor loading path (to avoid misleading future maintainers).
wolfcrypt/src/asn.c:1 - The “serial number == 0” policy appears implemented in multiple places (e.g., both decoding and relative parsing paths) with slightly different context checks and error handling (
ret = ASN_PARSE_Evsreturn ASN_PARSE_E). Consider centralizing this into a shared helper (or a single policy function) so future tweaks don’t drift and so messaging/behavior stays consistent across code paths.
tests/api.c:1 - This change makes the test depend on RSA (
!defined(NO_RSA)) where it previously depended on ECC (defined(HAVE_ECC)). On configurations that build ECC but disable RSA, this test will no longer compile/run, reducing coverage for serial-0 certificate generation/decoding scenarios. If the intent is just to switch algorithms, consider supporting both (conditional RSA/ECC branches) so the test continues to exercise the behavior across common build configurations.
tests/api.c:1 - This change makes the test depend on RSA (
!defined(NO_RSA)) where it previously depended on ECC (defined(HAVE_ECC)). On configurations that build ECC but disable RSA, this test will no longer compile/run, reducing coverage for serial-0 certificate generation/decoding scenarios. If the intent is just to switch algorithms, consider supporting both (conditional RSA/ECC branches) so the test continues to exercise the behavior across common build configurations.
tests/api.c:1 - This change makes the test depend on RSA (
!defined(NO_RSA)) where it previously depended on ECC (defined(HAVE_ECC)). On configurations that build ECC but disable RSA, this test will no longer compile/run, reducing coverage for serial-0 certificate generation/decoding scenarios. If the intent is just to switch algorithms, consider supporting both (conditional RSA/ECC branches) so the test continues to exercise the behavior across common build configurations.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Jenkins retest this please |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /* Check for serial number of 0. RFC 5280 section 4.1.2.2 requires | ||
| * positive serial numbers. However, allow zero for self-signed CA | ||
| * certificates (root CAs) being loaded as trust anchors since they | ||
| * are explicitly trusted and some legacy root CAs in real-world | ||
| * trust stores have serial number 0. */ |
There was a problem hiding this comment.
The comment here says the serial-0 exception is for root CAs “being loaded as trust anchors”, but DecodeCertInternal() doesn’t have enough context to know how the cert will be used and will allow serial 0 for any self-signed CA that reaches this code path. Consider rewording to avoid implying it is limited to trust-anchor loading (or explicitly note that additional call-site checks may further restrict acceptance).
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:
Testing
Tested with certificates generated using OpenSSL to verify all scenarios: