Skip to content

feat(xmldsig): generate exclusive canonicalization, honour implicit one and declined recipients - #488

Merged
polaz merged 5 commits into
mainfrom
fix/#474-builder-retrieved-recipients
Nov 20, 2026
Merged

polaz merged 5 commits into
mainfrom
fix/#474-builder-retrieved-recipients

Conversation

@polaz

@polaz polaz commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Signing completes a Reference whose chain ends in a node set with an explicit Exclusive C14N transform: XMLDSig 1.1 section 3.1.1 asks generators not to rely on the implicit conversion and names C14N 1.1 only where inclusive canonicalization is desired, while Exclusive C14N is verified by libxmlsec1, .NET and Java alike and keeps a signed subset independent of its ancestors' namespaces and xml:* attributes.
  • The template builder honours a signing policy that leaves a node set's conversion implicit: it writes no generated transform for such a Reference (XMLDSig 1.1 section 4.4.3.2), so a builder template matches what the policy signs.
  • A decryption whose resolver declines the EncryptedKey recipients neither preflights nor resolves any recipient, inline or reached through a RetrievalMethod.
  • RustCryptoRsaPublicKey::from_spki_der refuses an id-RSASSA-PSS key, which RFC 4055 section 1.2 reserves for signatures, as a key-transport key.
  • An internal subset written back out keeps an attribute default holding a quote a valid literal (XML 1.0 section 2.3), so a fragment parsed with the document's subset sees it.

Changes

  • GeneratedCanonicalization::ExplicitExclusiveC14n (formerly ExplicitC14n11) is the default of every profile; signing and SignatureBuilder write the transform from one shared mode. The libxmlsec1 C library and the xmlsec1 command keep the implicit conversion.
  • SignatureBuilder passes the policy's generated_canonicalization to the transforms it writes and validates.
  • CipherReferenceContext carries the operation's recipient decision into metadata parsing; a declined recipient's method and CipherReference are neither admitted nor resolved, while the content CipherReference keeps its checks.
  • A key-transport key is read from an rsaEncryption SPKI alone; signature verification keeps accepting both identifiers.
  • The libxmlsec1 oracle pin follows upstream master, with the C library behaviour it brought: xmlSecReplaceNodeAndReturn refuses a replacement by the node itself, a node of another kind or a relative of the node, so an XML encryption whose template lies inside the element it encrypts is refused and leaves the template unwritten; xmlSecTmplTransformAddRsaOaepParam writes an empty OAEPparams for empty parameters; key unwrap and RSA key transport decryption, and key derivation and agreement transforms, mark the buffers holding keys as secure; a Base64 node read that fails to decode leaves the buffer empty; the xmlsec1 command keeps a dotfile input name whole in an output template.

Testing

Tests, lints and formatting run in CI on macOS, Linux and Windows.

Part of #474

Summary by CodeRabbit

  • New Features
    • Generated XML signatures now use Exclusive C14N for eligible references by default; implicit mode continues to add no canonicalization transform.
    • RSA-OAEP templates support empty parameters, and output paths preserve leading-dot filenames.
  • Bug Fixes
    • Improved handling of quoted DTD defaults, skipped encrypted-key recipients, RSA key types, and invalid Base64 input.
    • Encryption and XML tree operations now reject unsafe cases and protect sensitive key material more consistently.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changes update generated XML signature canonicalization, DTD serialization, RSA transport-key parsing, encrypted-key processing, xmlsec transform and tree behavior, parser internals, compatibility records, and CLI output-path expansion.

Changes: Generated signing canonicalization

Layer / File(s) Summary
Canonicalization policy and builder wiring
src/policy.rs, crates/xml-sec-config/src/settings.rs, crates/xml-sec-config/tests/configuration.rs, docs/policy-schema-v1.md, docs/xmldsig.md, src/xmldsig/builder.rs
The generated canonicalization option is now ExplicitExclusiveC14n. The builder uses this setting when it constructs reference transform chains.
Signing transform generation and validation
src/xmldsig/sign.rs, src/xmldsig/sign/*, tests/signing_digest.rs, tests/signature_builder.rs, tests/donor_interop_suite.rs, tests/external_tree.rs, tests/policy_profiles.rs, tests/rust_api.rs, tests/capability_ledger.rs, tests/fixtures/xmldsig/README.md
Signing inserts and materializes Exclusive C14N for eligible reference chains. Tests and documentation cover generated transforms and Implicit mode, which adds no generated transform.

DTD attribute default serialization

Layer / File(s) Summary
Default literal serialization and fragment test
src/parser_xmloxide/validation/dtd.rs, src/document/owned_tree/tests.rs
Default literals select a quote delimiter that is absent when possible. If both quote types occur, embedded double quotes are escaped. A fragment test covers ordinary and #FIXED defaults.

RSA transport-key parsing

Layer / File(s) Summary
SPKI parsing rules and provider validation
src/rsa_encoding.rs, src/provider.rs, tests/rsa_encoding.rs
The transport-key parser rejects id-RSASSA-PSS SPKIs while accepting rsaEncryption SPKIs. The general RSA public-key decoder continues to accept the tested PSS-labeled key.

Declined encrypted-key recipients

Layer / File(s) Summary
Recipient state and encrypted-key processing
src/xmlenc/cipher_reference.rs, src/xmlenc/decrypt.rs, src/xmlenc/parse.rs, tests/cipher_reference.rs
The decryption context records when recipients are declined. In that case, encrypted-key retrieval and preflight skip nested cipher-reference processing. Tests cover direct-key decryption when an unused recipient contains an unresolved or disallowed reference.

xmlsec transform and buffer handling

Layer / File(s) Summary
Secure buffer marking and checks
crates/xml-sec-xmlsec1/src/ffi/transforms.rs, crates/xml-sec-xmlsec1/src/ffi/transforms/ciphers.rs, crates/xml-sec-xmlsec1/src/ffi/transforms/transport.rs, crates/xml-sec-xmlsec1/src/ffi/transforms/*/tests.rs, crates/xml-sec-xmlsec1/tests/c/ciphers.c
Selected key-derivation, key-agreement, key-wrap, and decryption paths mark buffers secure. Rust and C tests inspect output-buffer security state.
Empty RSA-OAEP parameters
crates/xml-sec-xmlsec1/src/ffi/templates.rs, crates/xml-sec-xmlsec1/src/ffi/templates/tests.rs, crates/xml-sec-xmlsec1/tests/c/templates.c
The template API accepts a null buffer when the size is zero and creates empty OAEP parameters. Tests verify the zero-size and nonzero-size cases.
Base64 buffer failure behavior
crates/xml-sec-xmlsec1/src/ffi/buffer.rs, crates/xml-sec-xmlsec1/src/ffi/buffer/tests.rs, crates/xml-sec-xmlsec1/tests/c/keysdata.c
Base64 decode failure now leaves the buffer empty. Tests cover valid input replacing prior contents and invalid input.

xmlsec encryption and tree replacement

Layer / File(s) Summary
Encryption template and node replacement checks
crates/xml-sec-xmlsec1/src/ffi/xmlenc/process.rs, crates/xml-sec-xmlsec1/src/ffi/xmlenc/tests.rs, crates/xml-sec-xmlsec1/src/ffi/xmltree/edit.rs, crates/xml-sec-xmlsec1/src/ffi/xmltree/edit/tests.rs, crates/xml-sec-xmlsec1/tests/c/xmltree.c
Encryption refuses templates inside replaced content. Node replacement rejects identical, different-kind, and ancestor/descendant node pairs before changing the tree.

xmloxide parser and DTD patch

Layer / File(s) Summary
Storage-aware DTD parsing and validation
scripts/patches/xmloxide-0.5.0.patch, src/parser_xmloxide/documentation_tests.rs
The patch moves DTD parsing and validation to storage-aware, fallible operations. Entity and content-model traversal use iterative processing. Tests cover limits, long chains, and serialization.

Compatibility records and headers

Layer / File(s) Summary
Backend capability records and header comments
compatibility/libxmlsec1.json, compatibility/libxmlsec1-donor-commit.txt, crates/xml-sec-xmlsec1/include/xmlsec/exports.h
The compatibility snapshot separates AWS-LC and BoringSSL capability conditions and adds a backend API item. The donor commit identifier and two header comments also change.
Error formatting fallback
crates/xml-sec-xmlsec1/src/ffi/errors.rs, crates/xml-sec-xmlsec1/src/ffi/errors/tests.rs
The fallback error text and its test expectation change to “Cannot format error message.”

CLI dotfile output naming

Layer / File(s) Summary
Dotfile expansion and CLI regression test
tools/xmlsec1/src/commands.rs, tools/xmlsec1/tests/process_contract.rs
Output-path expansion retains a leading-dot basename as the {inputfile} stem. A CLI test checks the resulting filename.

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant SigningPolicy
  participant SignatureBuilder
  participant Signer
  SigningPolicy->>SignatureBuilder: generated_canonicalization setting
  SignatureBuilder->>Signer: reference chain and configured transform
  Signer->>Signer: materialize transform and prepare digest
Loading

Possibly related PRs

Merge Risk: Minimal · up to b933c

This change switches generated signature canonicalization to Exclusive C14N, skips unused decryption recipients, and tightens several key-handling and tree-replacement checks. Targeted tests cover each behavior and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: signing now generates an explicit Exclusive C14N transform, replacing C14N 1.1 (ExplicitC14n11 renamed to ExplicitExclusiveC14n in src/policy.rs and src/xmldsig/sign.r…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: signing now generates an explicit Exclusive C14N transform, replacing C14N 1.1 (ExplicitC14n11 renamed to ExplicitExclusiveC14n in src/policy.rs and src/xmldsig/sign.rs). It also names the implicit-mode behavior (no generated transform when conversion stays implicit) and the declined-recipients decryption change, both of which appear in the changeset. The title is specific and accurate, though long at 95 characters and covers several changes beyond the main one.

Finishing Touches

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a84fbf2 and b933c15.

Files selected for processing: 10

  • compatibility/libxmlsec1-donor-commit.txt
  • compatibility/libxmlsec1.json
  • crates/xml-sec-xmlsec1/src/ffi/buffer.rs
  • crates/xml-sec-xmlsec1/src/ffi/buffer/tests.rs
  • crates/xml-sec-xmlsec1/src/ffi/errors.rs
  • crates/xml-sec-xmlsec1/src/ffi/errors/tests.rs
  • crates/xml-sec-xmlsec1/tests/c/keysdata.c
  • tests/capability_ledger.rs
  • tools/xmlsec1/src/commands.rs
  • tools/xmlsec1/tests/process_contract.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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T08:34:33.059674Z b933c15 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.

@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no actionable new defects were found.

Summary

Signing now generates Exclusive C14N by default, and SignatureBuilder respects policies that leave conversion implicit.

  • Signing writes Exclusive C14N for node-set references by default.
  • Decryption skips recipient metadata when the resolver declines recipients.
  • RSA key transport accepts only keys marked for encryption.
  • The libxmlsec1-compatible helpers follow updated upstream behavior.
  • Written DTD defaults keep quote characters inside valid literals.

No actionable new issues or repository-rule violations were found. No tests were run during this review.

Reviews (12) · Last reviewed commit: "feat(xmlsec1): follow libxmlsec1 master ..." · Reviewed by Greptile

@polaz
polaz force-pushed the feat/#474-xmlsec1-contexts branch from 232ab36 to 48a0921 Compare November 18, 2026 13:50
@polaz
polaz force-pushed the fix/#474-builder-retrieved-recipients branch from 05a304b to 42e0729 Compare November 18, 2026 16:42
@polaz polaz changed the title fix(xmldsig): honour implicit canonicalization and declined recipients feat(xmldsig): generate exclusive canonicalization, honour implicit one and declined recipients Nov 18, 2026
@polaz
polaz force-pushed the feat/#474-xmlsec1-contexts branch from d87251a to 4d21664 Compare November 18, 2026 22:27
@polaz
polaz force-pushed the fix/#474-builder-retrieved-recipients branch from 80a0382 to 2ade773 Compare November 19, 2026 08:28
@polaz
polaz force-pushed the feat/#474-xmlsec1-contexts branch from bc49bc5 to 0a7e84d Compare November 19, 2026 12:28
Base automatically changed from feat/#474-xmlsec1-contexts to main November 19, 2026 22:03
…ne and declined recipients

- Signing completes a Reference whose chain ends in a node set with an
  explicit Exclusive C14N transform: XMLDSig 1.1 section 3.1.1 asks
  generators not to rely on the implicit conversion and names C14N 1.1
  only where inclusive canonicalization is desired, while Exclusive C14N
  is verified by libxmlsec1, .NET and Java alike and keeps a signed subset
  independent of its ancestors' namespaces and xml:* attributes. The
  template builder writes the same transform from one shared mode, and
  honours a policy that leaves the conversion implicit.
- A decryption whose resolver declines the EncryptedKey recipients neither
  preflights nor resolves any recipient, inline or reached through a
  RetrievalMethod.
- RustCryptoRsaPublicKey::from_spki_der refuses an id-RSASSA-PSS key,
  which RFC 4055 section 1.2 reserves for signatures, as a key-transport
  key.

Part of #474
An internal subset written back out put every attribute default between
double quotes, so a default declared as 'say "hi"' became an invalid
literal and a fragment parsed with the document's subset failed. The
default is written between quotes it does not contain (XML 1.0 section
2.3), with a regression test through a fragment parsed in context.

Part of #474
@polaz
polaz force-pushed the fix/#474-builder-retrieved-recipients branch from 0560fad to c058790 Compare November 19, 2026 23:38
The maintained xmloxide source is checked against the upstream crate
plus scripts/patches/xmloxide-0.5.0.patch, so the attribute default
literal fix in validation/dtd.rs belongs in that delta. The delta is
regenerated with the import script, which also moves the line numbers
the embedded documentation examples cite.

Part of #474
The oracle pin moves to upstream 6a6dd7ef, and the C library takes the
behaviour upstream changed since c62324b3:

- xmlSecReplaceNodeAndReturn refuses a replacement by the node itself,
  by a node of another kind, or by an ancestor or descendant of the
  node, before anything moves. An XML encryption whose Element template
  lies inside the element it encrypts is therefore refused, as a
  Content template inside its content already was, and leaves the
  template unwritten; the admission no longer measures that case apart.
- xmlSecTmplTransformAddRsaOaepParam takes no buffer and no size as
  empty parameters and writes an empty OAEPparams.
- Key unwrap and RSA key transport decryption mark their output buffer
  as holding a secret, and a key derivation or agreement transform is
  created with both buffers marked, as libxmlsec1 marks them. Every
  buffer was already wiped; the flag is what xmlSecBufferIsSecure
  reports.

Upstream's node set namespace walk rewrite and its typed list item
methods need no change here: the walk differs only on an explicit
xmlns:xml declaration, which the tree never holds, and the list klasses
are typed. The ledger, the capability counts and exports.h follow the
new revision.

Tests: regression tests for each behaviour; the differential C programs
compare the secure flags, a replacement by a relative and empty OAEP
parameters with the oracle.

Part of #474

@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

scripts/patches/xmloxide-0.5.0.patch-8977-8977: 1

8977-8977: Minor · Performance & Scalability · Quick win

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

Admit work before scanning the default literal.

If the remaining serialization allowance covers only the declaration prefix, a large quote-free default is still scanned completely by contains before the next output write reports refusal. The new quote-selection scans have no work charge. Output formatting does not admit those earlier scans. (raw.githubusercontent.com)

Charge the scan work before each contains and before the split traversal, as write_entity_value does. Add a low-allowance test with a large retained default. This preserves the generated literal when sufficient work is available. (raw.githubusercontent.com)

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c058790 and a84fbf2.

Files selected for processing: 21

  • compatibility/libxmlsec1-donor-commit.txt
  • compatibility/libxmlsec1.json
  • crates/xml-sec-xmlsec1/include/xmlsec/exports.h
  • crates/xml-sec-xmlsec1/src/ffi/templates.rs
  • crates/xml-sec-xmlsec1/src/ffi/templates/tests.rs
  • crates/xml-sec-xmlsec1/src/ffi/transforms.rs
  • crates/xml-sec-xmlsec1/src/ffi/transforms/ciphers.rs
  • crates/xml-sec-xmlsec1/src/ffi/transforms/ciphers/tests.rs
  • crates/xml-sec-xmlsec1/src/ffi/transforms/tests.rs
  • crates/xml-sec-xmlsec1/src/ffi/transforms/transport.rs
  • crates/xml-sec-xmlsec1/src/ffi/transforms/transport/tests.rs
  • crates/xml-sec-xmlsec1/src/ffi/xmlenc/process.rs
  • crates/xml-sec-xmlsec1/src/ffi/xmlenc/tests.rs
  • crates/xml-sec-xmlsec1/src/ffi/xmltree/edit.rs
  • crates/xml-sec-xmlsec1/src/ffi/xmltree/edit/tests.rs
  • crates/xml-sec-xmlsec1/tests/c/ciphers.c
  • crates/xml-sec-xmlsec1/tests/c/templates.c
  • crates/xml-sec-xmlsec1/tests/c/xmltree.c
  • scripts/patches/xmloxide-0.5.0.patch
  • src/parser_xmloxide/documentation_tests.rs
  • tests/capability_ledger.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.

The oracle pin moves to upstream ba711db9, and the C library and the
xmlsec1 command take the behaviour upstream changed since 6a6dd7ef:

- The message replacing one too long to format reads "Cannot format
  error message".
- xmlSecBufferBase64NodeContentRead leaves the buffer empty when the
  node content fails to decode, instead of resized over partly decoded
  bytes.
- An output template's {inputfile} keeps a dotfile name such as
  ".hidden" whole: a leading dot is not an extension separator.

Upstream's refusal of an ECKeyValue whose NamedCurve is empty after the
urn:oid: prefix is already the core parser's; its BN node value change
touches functions this library does not implement. The ledger and its
category counts follow the new MSCrypto DES setter.

Tests: regression tests for each behaviour; the differential keysdata
program compares a failed Base64 node read with the oracle.

Part of #474
@polaz
polaz enabled auto-merge (squash) November 20, 2026 08:48
@polaz
polaz merged commit 1db42b3 into main Nov 20, 2026
32 checks passed
@polaz
polaz deleted the fix/#474-builder-retrieved-recipients branch November 20, 2026 08:58
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.

1 participant