Repository navigation
feat(xmldsig): verify x509 certificate chains - #63
Conversation
- 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
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR adds X.509 certificate-chain validation for XMLDSIG ChangesX.509 chain verification
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
Cargo.tomlREADME.mdsrc/xmldsig/mod.rssrc/xmldsig/x509.rstests/x509_chain_integration.rs
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
Cargo.tomlsrc/xmldsig/x509.rstests/x509_chain_integration.rs
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
src/xmldsig/x509.rstests/x509_chain_integration.rs
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
src/xmldsig/x509.rstests/x509_chain_integration.rs
Summary
X509Datachains.Security invariants
digitalSignatureornonRepudiation; issuer certificates with KeyUsage must permitkeyCertSign.Testing
cargo fmt -- --checkcargo check --workspacecargo clippy --workspace --all-targets --all-features -- -D warningscargo nextest run --test x509_chain_integration(19/19)cargo nextest run --workspace(453/453)cargo test --doc --workspace(3/3)cargo build --workspaceCloses #62