Skip to content

x509-cert: accept v1 CRLs with omitted TBSCertList version - #2562

Open
lyn1dev wants to merge 1 commit into
RustCrypto:masterfrom
lyn1dev:fix/crl-v1-version-optional-2544
Open

lyn1dev wants to merge 1 commit into
RustCrypto:masterfrom
lyn1dev:fix/crl-v1-version-optional-2544

Conversation

@lyn1dev

@lyn1dev lyn1dev commented Nov 24, 2026

Copy link
Copy Markdown

Summary

Per RFC 5280 Section 5.1, TBSCertList.version is defined as Version OPTIONAL, where absence indicates a v1 CRL. Previously, TbsCertList.version was declared as a mandatory Version, causing decoding of v1 CRLs (which omit the version field) to fail with a DER tag error. This change marks TbsCertList.version with #[asn1(default = "Default::default")] so that absent versions decode as Version::V1 and Version::V1 is omitted during DER encoding.

Fixes #2544

Changes

  • In x509-cert/src/crl.rs, marked TbsCertList.version with #[asn1(default = "Default::default")].
  • In x509-cert/tests/crl.rs, added regression tests covering decoding and DER roundtripping of both v1 CRLs (with omitted version) and v2 CRLs (with explicit version INTEGER 1), including the test vector from x509-cert: v1 CRLs fail to decode (TBSCertList.version is OPTIONAL) #2544.

Verification

  • Running cargo test -p x509-cert --test crl against master without the fix reproduces the failure:
    thread 'decode_v1_crl_without_version' panicked at x509-cert\tests\crl.rs:35:56:
    called `Result::unwrap()` on an `Err` value: Error { kind: TagUnexpected { expected: Some(Tag(0x02: INTEGER)), actual: Tag(0x10: SEQUENCE) }, position: None }
    
  • Running cargo test -p x509-cert --test crl with the fix applied passes:
    running 2 tests
    test decode_crl ... ok
    test decode_v1_crl_without_version ... ok
    
    test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
    
  • Formatting and linter checks pass cleanly:
    • cargo fmt --check -p x509-cert
    • cargo clippy -p x509-cert --all-targets

AI was used to write this code.

RFC 5280 Section 5.1 defines TBSCertList.version as optional:
`version Version OPTIONAL, -- if present, MUST be v2`.

When absent, a v1 CRL omits the version field, but TbsCertList
previously required the field to be present during DER decoding.
Adding `#[asn1(default = "Default::default")]` allows decoding
absent versions as Version::V1 and omits Version::V1 during DER
encoding.

Closes RustCrypto#2544

This branch has not been deployed

No deployments
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.

x509-cert: v1 CRLs fail to decode (TBSCertList.version is OPTIONAL)

1 participant