Skip to content

feat(xmldsig): verify x509 certificate chains - #63

Merged
polaz merged 10 commits into
mainfrom
feat/#62-x509-chain-verification
Jun 27, 2026
Merged

polaz merged 10 commits into
mainfrom
feat/#62-x509-chain-verification

Conversation

@polaz

@polaz polaz commented Jun 27, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add pure-Rust X.509 certificate-chain verification over parsed X509Data chains.
  • Require explicit DER trust anchors, replace untrusted embedded rollover roots, try every matching anchor through full path validation, and enforce validity, CA basic constraints, KeyUsage, path length, signatures, and maximum depth.
  • Optionally authenticate embedded CRLs and reject certificates revoked at the selected verification time.
  • Add real-fixture integration coverage for valid, untrusted, expired, tampered, depth-limited, malformed-CRL, and revoked paths.

Security invariants

  • Embedded self-signed certificates are not trusted unless byte-identical to a configured anchor.
  • Embedded rollover roots are replaced only after they are authenticated as the issuer of the preceding certificate.
  • Leaf certificates with KeyUsage must permit digitalSignature or nonRepudiation; issuer certificates with KeyUsage must permit keyCertSign.
  • Certificate and CRL DER is parsed strictly with trailing-data rejection.
  • CRL entries are applied only after issuer, signature, and validity checks.
  • Unsupported certificate/CRL signature algorithms fail closed.

Testing

  • cargo fmt -- --check
  • cargo check --workspace
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run --test x509_chain_integration (19/19)
  • cargo nextest run --workspace (453/453)
  • cargo test --doc --workspace (3/3)
  • cargo build --workspace

Closes #62

- Validate trust anchors, validity periods, CA constraints, and path depth
- Authenticate optional CRLs and reject revoked certificates
- Cover valid and rejected paths with real certificate fixtures

Closes #62
@coderabbitai

coderabbitai Bot commented Jun 27, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5dc08817-43c2-42a6-8020-0bef697d185d

📥 Commits

Reviewing files that changed from the base of the PR and between a2faea0 and b07e108.

📒 Files selected for processing (2)
  • src/xmldsig/x509.rs
  • tests/x509_chain_integration.rs

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added opt-in X.509 certificate-chain validation for XML signatures, including explicit trust anchors, certificate validity-window checks, CA/basic constraints and path-length enforcement, and optional CRL-based revocation checking.
    • Exposed a new public verification API for certificate-chain validation.
  • Bug Fixes

    • Improved trust-anchor selection, certificate handling, and error reporting for malformed inputs, invalid signatures, key-usage/CA violations, and revoked or expired certificates.
  • Documentation

    • Updated README “Status” to reflect the new X.509 validation capability.
  • Tests

    • Added integration tests covering success and multiple failure and CRL scenarios.

Walkthrough

This PR adds X.509 certificate-chain validation for XMLDSIG X509Data, including trust-anchor termination, verification-time and depth checks, Basic Constraints enforcement, optional CRL revocation checks, API exposure, and integration tests.

Changes

X.509 chain verification

Layer / File(s) Summary
Public API and options
Cargo.toml, src/xmldsig/mod.rs, src/xmldsig/x509.rs, README.md
x509-parser enables verify, xmldsig exports the new x509 module and chain-verification API, the public options/error types are added, and the status list is updated.
Certificate chain construction and validation
src/xmldsig/x509.rs
The verifier builds a certificate path from X509DataInfo, matches or appends trust anchors, parses certificates and verification time values, and enforces leaf and CA constraints before CRL handling.
CRL validation
src/xmldsig/x509.rs
CRLs are parsed with strict DER checks, matched to issuer certificates, authenticated with issuer keys, and used to report revocation at the selected verification time.
Successful chains and anchor selection
tests/x509_chain_integration.rs
Fixture helpers and generated chains cover successful validation, incomplete chains completed by an explicit anchor, malformed configured anchors, and anchor selection when multiple candidates share a subject.
Validation failures and CRL behavior
tests/x509_chain_integration.rs
Tests cover leaf usage, CA and path-length constraints, untrusted roots, expiration, depth limits, tampered signatures, CRL revocation, malformed CRLs, disabled CRL checks, and CRL signer key-usage failures.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: X.509 certificate-chain verification for xmldsig.
Description check ✅ Passed The description directly matches the implemented certificate-chain verification and test coverage.
Linked Issues check ✅ Passed The code and tests cover the linked issue requirements: trust anchors, validity time, depth, CA constraints, signatures, CRLs, and fail-closed behavior.
Out of Scope Changes check ✅ Passed The changes stay within the X.509 verification feature and supporting docs/tests, with no clear unrelated additions.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/#62-x509-chain-verification

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jun 27, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR adds opt-in X.509 certificate-chain validation for XMLDSig. The main changes are:

  • Pure-Rust chain verification against explicit DER trust anchors.
  • Certificate validity, CA basic constraints, key usage, path length, and signature checks.
  • Replacement of authenticated embedded rollover roots with configured anchors.
  • Optional authenticated CRL checks for revoked certificates.
  • Public API exports and integration tests for success and rejection paths.

Confidence Score: 5/5

The X.509 verification changes appear safe to merge.

The implementation includes explicit trust-anchor handling, strict parsing, certificate and CRL validation checks, and broad integration coverage for success and rejection cases.

T-Rex T-Rex Logs

What T-Rex did

  • T-Rex ran the requested verification for the pull request.
  • T-Rex attempted to upload local artifact references, but they were not uploaded.

T-Rex Ran code and verified through T-Rex

Reviews (6): Last reviewed commit: "fix(xmldsig): validate rollover root lin..." | Re-trigger Greptile

Comment thread src/xmldsig/x509.rs Resolved
Comment thread src/xmldsig/x509.rs Resolved

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/xmldsig/x509.rs`:
- Around line 99-111: The trust-anchor selection in the X509 path builder is too
permissive because it skips malformed anchors and returns the first subject-DN
match, which can make validation order-dependent. In the block around the
embedded_anchor check, parse and validate all configured entries from
options.trusted_certs up front, then select the anchor only if it actually
verifies the current chain rather than relying on cert.subject() ==
last.issuer() alone. Update the lookup logic used with parse_certificate, last,
and path_der so malformed anchors fail closed and multiple anchors with the same
subject are disambiguated by successful signature/path verification.

In `@tests/x509_chain_integration.rs`:
- Around line 83-179: The current tests in
validates_unordered_chain_against_explicit_anchor and the related
chain-validation helpers do not cover the external-anchor append path in
verify_x509_certificate_chain() or the BasicConstraints failures in
validate_ca_constraints(). Add fixture-based tests that drive the explicit
trust-anchor termination branch and separately trigger IssuerNotCa and
PathLengthExceeded so these core security checks are exercised and regressions
are caught.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d64651e2-d960-4d6b-964e-fe9dbccc40dd

📥 Commits

Reviewing files that changed from the base of the PR and between 72cc4fd and 57a85c6.

📒 Files selected for processing (5)
  • Cargo.toml
  • README.md
  • src/xmldsig/mod.rs
  • src/xmldsig/x509.rs
  • tests/x509_chain_integration.rs

Comment thread src/xmldsig/x509.rs Resolved
Comment thread tests/x509_chain_integration.rs Resolved

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/xmldsig/x509.rs`:
- Around line 116-122: The anchor selection in the X509 path-building flow is
too eager: `trusted_anchors.iter().find(...)` in the certificate validation
logic picks the first signature-matching anchor before full checks. Update the
anchor lookup in this path to consider all matching anchors and run each through
the complete validation pipeline (validity, CA, key usage, and path-length
checks), accepting the first fully valid candidate instead of the first
signature match.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0b4efc31-0a5f-4c87-aae5-42e12511a9bc

📥 Commits

Reviewing files that changed from the base of the PR and between 57a85c6 and a5ae136.

📒 Files selected for processing (3)
  • Cargo.toml
  • src/xmldsig/x509.rs
  • tests/x509_chain_integration.rs

Comment thread src/xmldsig/x509.rs Resolved
Comment thread src/xmldsig/x509.rs Resolved
polaz added 2 commits June 27, 2026 17:11
- Reproduce rollover anchors sharing signing keys
- Reject leaf certificates without signature key usage

Refs #62
- Try every signature-matching anchor through full path validation
- Enforce digital signature usage on leaf certificates

Refs #62

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/xmldsig/x509.rs`:
- Around line 177-185: Update validate_leaf_key_usage in x509.rs so a missing
KeyUsage extension is rejected when signature usage is required: currently only
an present KeyUsage with the wrong bits fails, while None passes. Adjust the
match/condition around cert.key_usage() so that both absent KeyUsage and present
KeyUsage without digital_signature or non_repudiation return the appropriate
X509ChainError, keeping the existing error mapping for invalid DER.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7411fc95-72f3-487d-bee8-017459fe0f94

📥 Commits

Reviewing files that changed from the base of the PR and between a5ae136 and e7a7a09.

📒 Files selected for processing (2)
  • src/xmldsig/x509.rs
  • tests/x509_chain_integration.rs

Comment thread src/xmldsig/x509.rs Resolved
Comment thread src/xmldsig/x509.rs Resolved
polaz added 2 commits June 27, 2026 18:12
Reproduce replacement of an expired embedded root by a trusted renewed certificate sharing its subject and signing key.

Refs #62
- Replace an untrusted self-signed path tail with a matching configured anchor
- Document RFC 5280 semantics for absent leaf KeyUsage

Refs #62

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/xmldsig/x509.rs`:
- Around line 119-126: The `replace_untrusted_root` logic in
`src/xmldsig/x509.rs` is too permissive because it drops any self-signed अंतिम
certificate even when it did not issue the preceding cert. Update the
chain-checking in the `replace_untrusted_root` block so it only strips the last
cert when it is self-signed, matches the child’s issuer/subject relationship,
and successfully verifies the preceding certificate’s signature; otherwise keep
the full `path_der` so invalid ordered chains fail closed. Make the change near
`candidate_base` using the existing `path_der`/`last` validation flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 906cf928-e7e8-48e7-b3ec-b07606a907a6

📥 Commits

Reviewing files that changed from the base of the PR and between e7a7a09 and a2faea0.

📒 Files selected for processing (2)
  • src/xmldsig/x509.rs
  • tests/x509_chain_integration.rs

Comment thread src/xmldsig/x509.rs Resolved
polaz added 2 commits June 27, 2026 19:11
Prove that an unrelated self-signed certificate cannot be discarded while completing a path to a trusted anchor.

Refs #62
Require an embedded self-signed rollover root to match and verify the preceding certificate before replacing it with a configured anchor.

Refs #62
@polaz
polaz merged commit 771ac22 into main Jun 27, 2026
9 checks passed
@polaz
polaz deleted the feat/#62-x509-chain-verification branch June 27, 2026 18:35
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.

feat(xmldsig): verify X.509 certificate chains

1 participant