Repository navigation
feat(xmlsec1): add keys, KeyInfo, templates and signature transforms on the owned tree - #462
Conversation
…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
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
- 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.
There was a problem hiding this comment.
💡 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.
There was a problem hiding this comment.
💡 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
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.
There was a problem hiding this comment.
💡 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".
| // SAFETY: a klass, a key, the caller's bytes and a context. | ||
| unsafe { | ||
| adopt_value( |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
mainonce feat(key-manager)!: import keys and edit trees on the shared primitives #463 merges.Changes
VerificationPolicy::check_supplied_key_verification.xmlSecCryptoAppKeyLoadMemory. MD5 and RIPEMD-160 klasses come with thelegacy-algorithmsfeature. Template functions fail when the tree refuses an attribute they were asked to set.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/cprints 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