feat(xmldsig): compute signing reference digests#79
Conversation
- 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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds 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. ChangesSigning template pipeline
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
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
| 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
- 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
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
Cargo.tomlsrc/xmldsig/mod.rssrc/xmldsig/sign.rstests/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
|
@coderabbitai review |
✅ Action performedReview finished.
|
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 `@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
📒 Files selected for processing (4)
Cargo.tomlREADME.mdsrc/xmldsig/sign.rstests/signing_digest.rs
Summary
SignContextwithsign_template()andsign_with_builder()for full template signing.<DigestValue>, reparse/canonicalize<SignedInfo>, sign canonical bytes, and fill<SignatureValue>.<SignedInfo>/<Reference>digest slots without touching manifest/object digest values.<Signature>/<SignatureValue>slot without touching object payload values.<DigestValue>is accepted only by the signing-template path.SysRngfor blinding.p384from0.14.0-rc.15to stable0.14.Testing
cargo check --all-featurescargo fmt -- --checkcargo clippy --all-targets --all-features -- -D warningscargo nextest run --all-features -E 'binary(signing_digest)'— 8 passedcargo nextest run --all-features— 530 passedcargo test --doc --all-features— 3 passedCloses #78