Skip to content

feat(xmldsig): expose KeyInfo candidates of verified signatures - #329

Merged
polaz merged 2 commits into
mainfrom
feat/#251-key-info-candidates
Oct 28, 2026
Merged

polaz merged 2 commits into
mainfrom
feat/#251-key-info-candidates

Conversation

@polaz

@polaz polaz commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

A consumer that validates certificate paths with its own trust inputs can now get the key material a verified signature's KeyInfo offered, bound to exactly what core verification read. Before, verification parsed KeyInfo only for key selection and dropped it, and a retained XmlDocument gave no way back to the nodes.

Session API

VerifiedSession::visit_key_info_candidates_in(signature, work, visitor) (or SelectedSignature::visit_key_info_candidates) visits the candidates of an authenticated Signature in document order, as verification parsed and materialized them under the operation's policy, budgets and provider. There is no second parse and no trust decision: the selected-key receipt still tells which key verified.

  • KeyInfoMaterial: Certificate (DER from X509Certificate or a raw certificate RetrievalMethod), SubjectPublicKeyInfo (dsig11:DEREncodedKeyValue), KeyValue (parsed parameters, including unusable ones) and Unmaterialized (a RetrievalMethod verification did not read). KeyName offers no material and is not a candidate.
  • KeyInfoOrigin::Element names the material's own element: each certificate its X509Certificate, also when a same-document KeyInfoReference or X509Data RetrievalMethod led to it. KeyInfoOrigin::Retrieved names the KeyInfoReference or RetrievalMethod that read material from a caller-supplied resource.
  • A RetrievalMethod an external KeyInfo left unread is still visited as Unmaterialized, attributed to the KeyInfoReference that read that KeyInfo, after the document-order candidates. It never reaches key selection, which would resolve it against the wrong document.
  • KeyInfoReading, KeyInfoOrigin, KeyInfoMaterial and KeyInfoCandidate are #[non_exhaustive].
  • The call returns KeyInfoReading: Read, Absent, or NotRead when the key came from the caller, a resolver ignoring document hints or a recipient mechanism. An unread KeyInfo is never reported as an empty one. An unauthenticated Signature is not selectable.

Retention

Scoped verification moves the parsed buffers into the session after the SignatureValue verifies and reserves their capacity on the session's account until it ends; nothing is copied. Collecting verification retains nothing: element tracking is gated at compile time by the capture type. No policy is added; the existing KeyInfo ingestion limits bound retention, and each visit charges the query Work. Public parse types are unchanged.

docs/xmldsig.md documents the API in a new "KeyInfo Candidates" section.

Testing

  • cargo fmt --check; cargo clippy --workspace --all-targets -D warnings with all features and with defaults; library clippy for the verification-only xmldsig graph; node scripts/check-pedantic-lints.mjs stable; scripts/check-features.sh for dsig-roxmltree and dsig-xmloxide.
  • cargo nextest run --workspace --all-features with the pinned xmlsec1 1.3.13 oracle: 5709 passed; the PKCS#11 test passed separately through scripts/test-pkcs11.sh with a disposable SoftHSM store.
  • cargo test --doc --workspace --all-features; RUSTDOCFLAGS=-D warnings cargo doc --workspace --all-features --no-deps.
  • New tests/key_info_candidates.rs: every material with its own element, caller key (NotRead) and missing KeyInfo (Absent), same-document KeyInfoReference and X509Data RetrievalMethod, external KeyInfoReference and raw certificate retrieval attributed to their instruction with an unsupplied resource left unmaterialized, an unread hint inside an external KeyInfo, unauthenticated Signature refused, exhausted query work and visitor errors kept distinct, and retained capacity charged until the session ends.

Closes #251

A verified session now visits the key material an authenticated
Signature's KeyInfo offered, as core verification parsed and
materialized it: no second parse and no trust decision.

- VerifiedSession::visit_key_info_candidates_in and
  SelectedSignature::visit_key_info_candidates visit certificate DER,
  DEREncodedKeyValue SPKI, parsed KeyValue and unmaterialized
  RetrievalMethod candidates in document order.
- Each candidate names its own element (each certificate its
  X509Certificate) or, for material read from a caller-supplied
  resource, the KeyInfoReference or RetrievalMethod that read it.
  Element provenance travels with the sources through reference
  expansion and retrieval.
- KeyInfoReading tells Read, Absent, or NotRead (caller, resolver or
  recipient key), so an unread KeyInfo is never an empty list.
- Scoped verification moves the parsed buffers into the session and
  reserves their capacity on its account; collecting verification
  retains nothing. Each visit charges the query Work.

Closes #251
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T16:02:48.319982Z 86cbdfc New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 40 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 16e3bab and 86cbdfc.

Files selected for processing: 5
  • docs/xmldsig.md
  • src/xmldsig/verify.rs
  • src/xmldsig/verify/capture.rs
  • src/xmldsig/verify/session/key_info.rs
  • tests/key_info_candidates.rs
Walkthrough

The change records the origins of parsed and materialized KeyInfo sources, retains supported candidate material in scoped sessions after authentication, and adds public visitor methods for inspecting candidates. It also adds tests and API documentation.

Changes: KeyInfo Candidate Inspection

Layer / File(s) Summary
Track KeyInfo source origins
src/xmldsig/parse.rs, src/xmldsig/verify.rs, src/xmldsig/verify/tests.rs
Parsing and materialization track source origins alongside KeyInfo sources, including references and retrieval methods. Existing helper calls pass the new optional origin argument.
Retain candidates after authentication
src/xmldsig/verify.rs, src/xmldsig/verify/capture.rs
Verification passes KeyInfo state, sources, and origins to scoped capture after successful authentication. Scoped capture retains supported material and accounts for retained memory.
Expose candidate visitors and validate behavior
src/xmldsig/verify/session/key_info.rs, src/xmldsig/verify/session.rs, src/xmldsig/mod.rs, tests/key_info_candidates.rs, docs/xmldsig.md
Public types and visitor methods expose retained candidates with work accounting. Tests cover material, origins, read states, authentication, work limits, and retention lifetime. The documentation describes the API and its outcomes.

Priority: Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant verify_signature_node
  participant parse_key_info_in_session
  participant materialize_verification_hints
  participant ScopedCapture
  verify_signature_node->>parse_key_info_in_session: parse sources and collect origins
  verify_signature_node->>materialize_verification_hints: materialize sources with origins
  verify_signature_node->>ScopedCapture: pass KeyInfo state and origins after authentication
  ScopedCapture->>ScopedCapture: retain candidate material with memory accounting
Loading
Merge Risk: Minimal · previous review 16e3b

No demonstrated merge-blocking issue remains; the public-type suggestion concerns possible future API changes.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 24.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: exposing KeyInfo candidates from verified signatures.
Linked Issues check Passed Issue [#251] asks for bounded, identity-bound access to the materialized KeyInfo of an authenticated signature, without reparsing or making a trust decision. The new session and selected-signature v…
Out of Scope Changes check Passed The parser and verification changes track source origins and preserve parsed material for the #251 visitor. The capture changes implement scoped, accounted retention. The API documentation and candida…
Full details: Linked Issues check

Explanation

Issue [#251] asks for bounded, identity-bound access to the materialized KeyInfo of an authenticated signature, without reparsing or making a trust decision. The new session and selected-signature visitors expose certificate DER, KeyValue, SPKI, and unmaterialized retrieval entries with origins and Read/Absent/NotRead outcomes. Capture moves parsed material into scoped retention, accounts for retained capacity, and charges query work during visits. The new tests cover direct and retrieved origins, unread and absent KeyInfo, unauthenticated signatures, work limits, and retention lifetime. The API leaves trust decisions to the consumer, as requested.

Full details: Out of Scope Changes check

Explanation

The parser and verification changes track source origins and preserve parsed material for the #251 visitor. The capture changes implement scoped, accounted retention. The API documentation and candidate tests cover the same behavior. No unrelated change is evident.

Full details: Docstring Coverage

Explanation

Docstring coverage is 24.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 25 functions across 8 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 16e3babd3e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/xmldsig/verify.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.

🔇 Additional comments: 1
src/xmldsig/verify/session/key_info.rs: 1

8-9: Trivial · Maintainability & Code Quality · Quick win

⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Mark the new public types #[non_exhaustive].

KeyInfoReading, KeyInfoOrigin and KeyInfoCandidate are public. They are re-exported from xmldsig. Only KeyInfoMaterial has #[non_exhaustive].

The related public types in this crate, such as ReferenceCoverage and ExternalPayload, use #[non_exhaustive]. Without it, adding a KeyInfoReading or KeyInfoOrigin variant, or a KeyInfoCandidate field, is a breaking change.

♻️ Proposed change
 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
+#[non_exhaustive]
 pub enum KeyInfoReading {
 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
+#[non_exhaustive]
 pub enum KeyInfoOrigin {
 #[derive(Clone, Copy, Debug)]
+#[non_exhaustive]
 pub struct KeyInfoCandidate<'a> {

tests/key_info_candidates.rs matches KeyInfoReading only through assert_eq!. It does not break with this change.

Also applies to: 21-22, 54-55


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 7e1e985 and 16e3bab.

Files selected for processing: 9
  • docs/xmldsig.md
  • src/xmldsig/mod.rs
  • src/xmldsig/parse.rs
  • src/xmldsig/verify.rs
  • src/xmldsig/verify/capture.rs
  • src/xmldsig/verify/session.rs
  • src/xmldsig/verify/session/key_info.rs
  • src/xmldsig/verify/tests.rs
  • tests/key_info_candidates.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

- A RetrievalMethod an external KeyInfo left unread was dropped before
  candidate retention, so a visit could report Read while omitting an
  offered hint. Scoped verification now keeps those hints apart from
  key selection and visits them as Unmaterialized, attributed to the
  KeyInfoReference that read that KeyInfo, after the document-order
  candidates. Collecting verification still discards them.
- KeyInfoReading, KeyInfoOrigin and KeyInfoCandidate are
  #[non_exhaustive], like KeyInfoMaterial.

Regression test: an_unread_hint_inside_external_key_info_is_still_a_candidate.

Part of #251
@polaz
polaz merged commit 3826acb into main Oct 28, 2026
29 checks passed
@polaz
polaz deleted the feat/#251-key-info-candidates branch October 28, 2026 17:53
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): expose the KeyInfo certificates of a verified signature

1 participant