Skip to content

feat(xmlsec1): add keys, KeyInfo, templates and signature transforms on the owned tree - #462

Merged
polaz merged 10 commits into
feat/#451-core-keys-treefrom
feat/#451-xmlsec1-keys-tree
Nov 14, 2026
Merged

polaz merged 10 commits into
feat/#451-core-keys-treefrom
feat/#451-xmlsec1-keys-tree

Conversation

@polaz

@polaz polaz commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Changes

  • Tree layer: the library policy is published as one verification and signing pair, both admitting the external reference URIs the caller's callbacks resolve, replaced as a whole by one republishing caller at a time.
  • One policy revision per operation: a KeyInfo read pins it in its context and hands it, with the read's resource budget and the URI classes admitted for each key reference, to the transform chains its references run; a run of a transform context pins its own. A chain whose transforms sign reads the signing snapshot for its shared work (transform count, reference URIs, budgets, parsing, C14N, XPath, Relationship), any other chain the verification snapshot. Key reads enforce the verification policy's key sources, key-retrieval URI classes and depth, and one key-candidate allowance shared by every key value decoded and every key-store entry inspected, through a key manager's lax search too; a key value the context's requirements refuse is not installed, and a symmetric or DER key value is bounded by the per-resource limit before it is decoded. Digest, HMAC and signature transforms admit their method and key under the operation's policy before taking input; a caller-supplied key without expected targets goes through VerificationPolicy::check_supplied_key_verification.
  • xmltree.h, templates.h, keys.h, keysdata.h (binary value, symmetric and RSA/DSA/EC/DEREncodedKeyValue klasses), keyinfo.h (KeyName, KeyValue, RetrievalMethod, KeyInfoReference), keysmngr.h (manager, store protocol, simple store), digest/HMAC/signature klasses in the built-in crypto table, xmlSecCryptoAppKeyLoadMemory. MD5 and RIPEMD-160 klasses come with the legacy-algorithms feature. Template functions fail when the tree refuses an attribute they were asked to set.
  • A buffer that grows moves its contents to a new block and wipes the old one; key material is wiped in writes the compiler keeps, and the block ciphers wipe their key schedules.
  • Functions that read or write a file themselves are not offered: xmlSecKeyReadBinaryFile, xmlSecSimpleKeysStoreLoad, xmlSecSimpleKeysStoreLoad_ex, xmlSecSimpleKeysStoreSave; the headers say so and point to the memory entry points. Templates are built in the document they belong to.

Testing

Every C program under crates/xml-sec-xmlsec1/tests/c prints the same as the libxmlsec1 oracle, a 1.3.13 pre-release snapshot (capi --xmlsec1); tests (with the xmlsec1 oracle and SoftHSM), clippy with all features, the alloc-only build, formatting, the header check and the clean C API check pass locally on macOS; CI runs the full matrix.

Related

Closes #458
Part of #451

…on the owned tree

The libxmlsec1 keys, KeyInfo, keys managers, templates, xmltree helpers and
the digest, HMAC and signature transforms run over the owned document tree
through its handles; no C library is used.

- Core: key values, incremental digests and HMAC, private key import into a
  key inventory. The owned tree keeps unlinked runs of siblings, parses a
  fragment in the namespace context of an element or the document node
  under the policy, replaces a node with such a run while handing over its
  IDs, and copies a subtree from another tree with its ID registrations and
  the bindings it uses. A fragment or copy linked away from its context, or
  unlinked from its run, declares the bindings it uses wherever it is
  linked. Only an element or the document takes children; a freed
  element's IDs are forgotten. The serializer writes text and namespace
  declarations as libxml2 does.
- Tree layer: xsFreeNodeList, xsParseInNodeContext, xsDocCopyNode,
  document::subtree, parsing under an explicit operation policy. The
  library policy is published as one verification and signing pair, both
  admitting the external reference URIs the caller's callbacks resolve,
  replaced as a whole by one republishing caller at a time.
- One policy revision per operation. A chain whose transforms sign reads
  the signing snapshot for its shared work, any other chain and every
  KeyInfo read the verification snapshot; execute_transforms_with_policy
  takes either through TransformChainPolicy. Key reads enforce key
  sources, key-retrieval URI classes and depth, and one key-candidate
  allowance shared by every key value decoded and key-store entry
  inspected. Digest, HMAC and signature transforms admit their method and
  key under the operation's policy before taking input.
- xmltree.h, templates.h, keys.h, keysdata.h, keyinfo.h, keysmngr.h,
  digest/HMAC/signature klasses in the built-in crypto table and
  xmlSecCryptoAppKeyLoadMemory. Functions that read or write files
  themselves are not offered.
- A buffer that grows moves its contents to a new block and wipes the old
  one; key material is wiped in writes the compiler keeps, and the block
  ciphers wipe their key schedules.
- CI installs the current cargo-llvm-cov, which reads Cargo's new
  build-dir layout.

Closes #458
Part of #451
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 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-14T11:11:33.481838Z d2b2986 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.

@polaz
polaz enabled auto-merge (squash) November 13, 2026 19:40

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

ℹ️ 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/key_manager/openssl.rs Resolved
Comment thread src/document/owned_tree/ids.rs Resolved
- xmlSecKeysMngrGetKey pins the operation for the whole lookup, so the
  lax key search after a KeyInfo read spends the same candidate allowance
  under the same policy revision instead of starting a fresh tally.
- Freeing elements that repeat one ID removes each further carrier from an
  ordered set rather than scanning the value's carrier list, so deleting a
  subtree is no longer quadratic in the number of repeats (20 000 repeats:
  385 ms before, 11 ms after, release build).
- The HMAC signature methods run on structured_cms::hmac: IncrementalHmac
  maps the XMLDSig method onto it and returns an HmacTag whose truncated
  comparison, the partial last octet included, is the shared primitive's;
  HMAC verification and signing keys and the xmlsec1 HMAC transforms use
  it instead of their own digest dispatch and comparison.

Regression test: a_lax_key_search_spends_the_candidates_of_its_lookup.
- structured-asn1, -pkix, -cms, -base64, -dstu4145, -ltv and -xades 0.22
  across the workspace, the fuzz and WASM harnesses and the vendored SXD
  document crate.
- structured_pkix::path::WorkingKey is EffectiveKey in 0.22.
- The vendored SXD document crate drops typed-arena, which it never used.
…ared primitive

- The traditional PEM envelope (RFC 1421 headers, EVP_BytesToKey,
  AES/DES-CBC) and the normalization of SEC1 EC and OpenSSL DSA keys to
  PKCS#8 are structured_cms::openssl's. The adapter keeps the container
  selection, the inventory import and the resource budget: the primitive's
  work is charged to the policy's X.509 work, its exact PKCS#8 length is
  reserved before the one wiping buffer it writes into.
- A SEC1 key without curve parameters takes the curve its scalar length
  names (RFC 5915 section 3).
- The MAC, KDF and cipher work of PKCS#12 import is
  structured_cms::personal::password's: Authentication and Decryption
  plans state their cost before the password and after it, and run in
  caller-owned wiping scratch. The adapter keeps the password callback,
  the admission of each cost under the policy, the bags and the key it
  keeps. PBMAC1 and scrypt-protected bundles now import too.
- The policy's key-import KDF work counts what the engine states for each
  PKCS#12 step; a step that alone exceeds the whole limit, or whose count
  the engine cannot represent, is an iteration count outside it. The
  reader's work account also holds the KDF budget the engine charges to it.
- pkcs12 and pbkdf2 are test-only dependencies; the tests derive their
  KDF budgets from what an import spends instead of fixed counts.

@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: 9c541bcccc

ℹ️ 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".

- signature-primitives 0.22.1: the password engine states each step's
  key-derivation parameters (kdf_cost). PKCS#12 and encrypted PKCS#8
  admit them in the policy's units again: hash rounds times output blocks
  for PBKDF2 and the PKCS#12 KDF, N·r·p and the stated B/V/T workspace for
  scrypt, and password-hashing units; a round count over the limit is
  outside it. The engine's own execution work stays charged to the reader.
- Encrypted PKCS#8 in the key inventory is read and decrypted by the same
  engine (new pkcs8_import), into one wiping buffer; its reader's
  bookkeeping is bounded as one resource.
- A symmetric KeyValue (HMAC, AES, DES) read from a document is bounded by
  the policy's per-resource octets before its Base64 is decoded, as a
  DEREncodedKeyValue is; both readers share key_value_within.
- A CLI test uses ResourcePolicy::default(), as the pedantic lint asks.

Regression test:
a_symmetric_value_past_the_resource_limit_is_refused_before_decoding.

@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: 558667af50

ℹ️ 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".

# Conflicts:
#	crates/xml-sec-libxml2/src/document.rs
@polaz
polaz changed the base branch from main to feat/#451-core-keys-tree November 14, 2026 10:21
RSA, DSA and EC KeyValue readers hand the read's pinned resource policy
to the core parser, which admits their decoded components against
max_external_resource_bytes before decoding, as the DEREncodedKeyValue
and symmetric readers do.

Regression test: an_rsa_key_value_past_the_resource_limit_is_refused.
@polaz
polaz merged commit a38761a into feat/#451-core-keys-tree Nov 14, 2026
19 of 22 checks passed
@polaz
polaz deleted the feat/#451-xmlsec1-keys-tree branch November 14, 2026 11:07

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

ℹ️ 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 on lines +450 to +452
// SAFETY: a klass, a key, the caller's bytes and a context.
unsafe {
adopt_value(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enforce the import byte limit for binary symmetric keys

When max_external_resource_bytes is smaller than a supplied symmetric key, the binary reader still installs the entire key: neither xmlSecKeyDataBinRead nor adopt_value checks the resource policy. For example, xmlSecKeyReadMemory with the HMAC klass accepts a 32-byte secret under a 16-byte limit, whereas the XML reader now rejects that material. This leaves the same import ceiling bypassable through the public binary-loading APIs and permits oversized key-buffer copies. Obtain the context's pinned policy and reject size above its import limit before calling adopt_value; also check before the intermediate copy in xmlSecKeyReadMemory.

AGENTS.md reference: AGENTS.md:L25-L28

Useful? React with 👍 / 👎.

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.

Wipe the old bytes when a libxmlsec1 buffer grows

1 participant