Skip to content

feat(xmldsig): compute signing reference digests#79

Merged
polaz merged 7 commits into
mainfrom
feat/#78-signing-reference-digests
Jul 10, 2026
Merged

feat(xmldsig): compute signing reference digests#79
polaz merged 7 commits into
mainfrom
feat/#78-signing-reference-digests

Conversation

@polaz

@polaz polaz commented Jul 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Add signing-side reference digest computation for XMLDSig templates.
  • Add SignContext with sign_template() and sign_with_builder() for full template signing.
  • Add RustCrypto signing key adapters for RSA PKCS#1 v1.5 and ECDSA P-256/P-384 PKCS#8 private keys.
  • Fill <DigestValue>, reparse/canonicalize <SignedInfo>, sign canonical bytes, and fill <SignatureValue>.
  • Scope signing digest replacement to direct <SignedInfo>/<Reference> digest slots without touching manifest/object digest values.
  • Scope signing signature replacement to the direct <Signature>/<SignatureValue> slot without touching object payload values.
  • Keep verification parsing strict: empty <DigestValue> is accepted only by the signing-template path.
  • Use fallible signing APIs; RSA PKCS#1 v1.5 signing uses randomized private-key operations with SysRng for blinding.
  • Cover same-document, multiple-reference, enveloped-signature, missing-URI, SHA-1 rejection, RSA-SHA256 round-trip, ECDSA-P256 round-trip, and ECDSA-P384 round-trip paths.
  • Update p384 from 0.14.0-rc.15 to stable 0.14.
  • Update README status for template signing support.

Testing

  • cargo check --all-features
  • cargo fmt -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo nextest run --all-features -E 'binary(signing_digest)' — 8 passed
  • cargo nextest run --all-features — 530 passed
  • cargo test --doc --all-features — 3 passed

Closes #78

- Add signing-template digest computation and fill APIs

- Preserve strict verification parsing for populated DigestValue

- Cover same-document, multi-reference, enveloped, and SHA-1 rejection cases

- Update p384 to stable 0.14

Closes #78
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3def648b-edd5-4a4d-bc96-737134adac1a

📥 Commits

Reviewing files that changed from the base of the PR and between c764d12 and 8534220.

📒 Files selected for processing (4)
  • Cargo.toml
  • src/xmldsig/mutation.rs
  • src/xmldsig/sign.rs
  • tests/signing_digest.rs

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added XMLDSig template signing with RSA and ECDSA P-256/P-384 keys.
    • Added support for computing and filling reference digest values.
    • Added PKCS#8 PEM and DER private-key loading.
    • Added public signing APIs and safeguards against modifying nested signature values.
  • Documentation
    • Updated XMLDSig feature and implementation status documentation.
  • Bug Fixes
    • Improved targeting of digest and signature value updates to prevent unintended changes.

Walkthrough

Adds XMLDSig signing-side reference digest computation, RSA/ECDSA template signing, scoped XML mutation helpers, public API exposure, optional cryptographic dependencies, documentation updates, and integration tests.

Changes

Signing template pipeline

Layer / File(s) Summary
Signing contracts and feature setup
src/xmldsig/sign.rs, src/xmldsig/mod.rs, Cargo.toml
Adds public signing contracts, signing result types, module exports, and optional cryptographic dependencies.
Signing key implementations
src/xmldsig/sign.rs
Implements RSA, ECDSA P-256, and ECDSA P-384 PKCS#8 signing keys.
Signing template parsing
src/xmldsig/sign.rs
Validates signatures, SignedInfo, references, algorithms, required elements, and canonicalization scope.
Scoped XML value filling
src/xmldsig/mutation.rs
Fills only direct SignedInfo digest values and the selected direct SignatureValue while preserving nested XMLDSig values.
Reference digest and template signing flow
src/xmldsig/sign.rs
Computes transformed reference digests, populates templates, canonicalizes SignedInfo, signs it, and writes SignatureValue.
Validation and documentation
tests/signing_digest.rs, README.md
Tests digest computation, ordering, validation failures, transforms, and RSA/ECDSA signing round trips; updates XMLDSig status documentation.

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

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant SignContext
  participant ReferenceProcessor
  participant SigningKey
  participant XMLDocument

  Caller->>SignContext: provide signing template
  SignContext->>ReferenceProcessor: compute and fill reference digests
  ReferenceProcessor-->>SignContext: populated template
  SignContext->>SigningKey: sign canonicalized SignedInfo
  SigningKey-->>SignContext: signature bytes
  SignContext->>XMLDocument: write SignatureValue
  XMLDocument-->>Caller: signed XML
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly summarizes the main change: adding XMLDSig signing reference digest computation.
Description check ✅ Passed The description is directly related to the XMLDSig signing digest and template-signing changes.
Linked Issues check ✅ Passed The changes appear to satisfy the issue: signing digests, empty-template handling, p384 update, and tests are all covered.
Out of Scope Changes check ✅ Passed The extra README, tests, and re-exports support the signing-digest work and do not appear unrelated.
Docstring Coverage ✅ Passed Docstring coverage is 91.67% which is sufficient. The required threshold is 80.00%.
✨ 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/#78-signing-reference-digests

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.

@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds XMLDSig template signing support. The main changes are:

  • Reference digest computation and filling for signing templates.
  • SignContext APIs for signing existing templates or builder-generated templates.
  • RSA PKCS#1 v1.5 and ECDSA P-256/P-384 signing key adapters.
  • Scoped XML mutation for direct SignedInfo digest slots and direct SignatureValue slots.
  • Tests for digest filling, scoped mutation, SHA-1 rejection, and RSA/ECDSA round trips.
  • README and feature dependency updates for the new signing path.

Confidence Score: 5/5

Safe to merge with minimal risk.

The new signing path has focused tests for reference digest computation, scoped XML mutation, SHA-1 rejection, and RSA/ECDSA verification round trips. No concrete functional or security issues were found in the changed code.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • T-Rex attempted to validate the signing_digest test by running cargo test --all-features --test signing_digest from the repository after the cargo-nextest availability check failed, and saved the full transcript to the signing digest validation log.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
Cargo.toml Adds getrandom for signing RNG support and updates the optional p384 dependency used by the new P-384 signing adapter.
src/xmldsig/sign.rs Implements signing-side reference digest computation, SignedInfo canonicalization, signature filling, and RSA/ECDSA private key adapters.
src/xmldsig/mutation.rs Adds scoped mutation helpers for direct SignedInfo reference digests and direct Signature signature values.
tests/signing_digest.rs Adds coverage for digest filling, signing round trips, SHA-1 rejection, scoped mutation, and RSA/ECDSA signing paths.
src/xmldsig/mod.rs Exports the new signing module types and helpers through the XMLDSig public API.
README.md Updates project status to describe template signing support and remaining signing-related gaps.

Reviews (7): Last reviewed commit: "fix(xmldsig): scope signature replacemen..." | Re-trigger Greptile

Comment thread Cargo.toml
- Add SignContext for template and builder-based signing

- Add RSA PKCS1v15 and ECDSA P-256/P-384 signing keys

- Fill SignatureValue after SignedInfo canonicalization

- Verify RSA-SHA256 and ECDSA-P256 signing round trips
@polaz

polaz commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@polaz

polaz commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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: 3

🤖 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/sign.rs`:
- Around line 178-192: The RSA signing paths in SignatureAlgorithm::RsaSha256,
SignatureAlgorithm::RsaSha384, and SignatureAlgorithm::RsaSha512 currently use
the non-randomized pkcs1v15::SigningKey::sign flow, which may skip blinding on
the private-key operation. Update the signing logic in src/xmldsig/sign.rs to
use the randomized signing API (RandomizedSigner::try_sign_with_rng with a
secure RNG) for the RSA variants, and verify that this still preserves the
expected PKCS#1 v1.5 signature output interoperability.
- Around line 177-197: The signing flow in `Signer::sign` currently uses the
infallible `sign` method for RSA, which can panic on real failures; update the
`SignatureAlgorithm::RsaSha256`, `RsaSha384`, and `RsaSha512` branches to use
`try_sign` and propagate errors. Add a `SigningFailed` variant to
`SigningKeyError` so failures are returned instead of unwrapping, and apply the
same `try_sign`-based error handling in the ECDSA signing paths for consistency.

In `@tests/signing_digest.rs`:
- Around line 175-203: Add a round-trip test for the publicly exported
EcdsaP384SigningKey to close the coverage gap: mirror the existing
signs_ecdsa_p256_template_and_verifies_round_trip test, but use the P-384 key
fixtures, SignatureAlgorithm::EcdsaP384Sha384, and the same
SignContext::new/sign_with_builder plus verify_signature_with_pem_key flow. Keep
the assertions consistent so the new test validates that the P-384 signing and
verification pipeline works end to end.
🪄 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: 7064a3a1-ff6f-403c-a110-3b9d1b0eeadd

📥 Commits

Reviewing files that changed from the base of the PR and between 4cece9e and 366b795.

📒 Files selected for processing (4)
  • Cargo.toml
  • src/xmldsig/mod.rs
  • src/xmldsig/sign.rs
  • tests/signing_digest.rs

Comment thread src/xmldsig/sign.rs
Comment thread src/xmldsig/sign.rs Outdated
Comment thread tests/signing_digest.rs
- Use randomized RSA PKCS1v15 signing with SysRng

- Propagate signing failures instead of using infallible sign

- Add P-384 signing round-trip coverage

- Update README signing status
@polaz

polaz commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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 `@Cargo.toml`:
- Line 34: The xmldsig dependency on crypto-common is missing the getrandom
feature, which prevents crypto_common::getrandom::SysRng from compiling in
src/xmldsig/sign.rs. Update the crypto-common entry in Cargo.toml to enable the
getrandom feature alongside dep:crypto-common so the SysRng path is available
when xmldsig is built.
🪄 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: 61e329c0-b360-4907-a0d1-c078f131c146

📥 Commits

Reviewing files that changed from the base of the PR and between 366b795 and 0f66d59.

📒 Files selected for processing (4)
  • Cargo.toml
  • README.md
  • src/xmldsig/sign.rs
  • tests/signing_digest.rs

Comment thread Cargo.toml Outdated
Comment thread src/xmldsig/sign.rs
Comment thread src/xmldsig/sign.rs
Comment thread src/xmldsig/sign.rs Outdated
@polaz polaz merged commit fa33d34 into main Jul 10, 2026
10 checks passed
@polaz polaz deleted the feat/#78-signing-reference-digests branch July 10, 2026 08:33
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: compute signing reference digests

1 participant