Repository navigation
fix(sdk): DSPX-1561 align TDF manifest parsing and assertion verification across SDKs - #4301
Closed
dmihalcik-virtru wants to merge 4 commits into
Closed
dmihalcik-virtru wants to merge 4 commits into
dmihalcik-virtru wants to merge 4 commits into
Conversation
…eceived Apply the parsing rules of the ZTDF assertions specification, Section 3, before LoadTDF or IsValidTdf decodes a manifest, and in Manifest.UnmarshalJSON, whether or not assertion verification is enabled. Duplicate member names anywhere in the manifest fail with duplicate-member, and case variants of modelled member names at the manifest root and in assertion, statement and binding objects fail with ambiguous-member. Invalid UTF-8 anywhere, and lone surrogates, noncharacters and out-of-range numbers inside an assertion object, fail with invalid-json. encoding/json keeps the last of duplicate members, folds case when matching names, and replaces invalid Unicode, so a scanner reads the raw bytes first. LoadTDF still only parses. Keep the raw JSON of each decoded assertion and compute assertionHash over it, minus only the top-level binding (Section 4), instead of re-marshalling the typed struct. Members the SDK does not model are now covered, and an object-valued statement value is hashed as an object. ComputeAssertionHash exposes the calculation, also from sdk/experimental/tdf. Update gowebpki/jcs to v1.0.2, whose canonicalization is O(n log n) in members and linear in size, since the hashed object now comes from the file. Writers hash the wire object they write, and refuse with ErrInvalidAssertion an assertion that readers would reject: an empty id, or JSON that breaks Section 3. ErrAssertionFailure gains a Reason holding a Section 9 code, and its message carries reason=<code>, with the id escaped and length-capped. The id and binding members are decoded leniently so that verification, not decoding, reports them. Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
…tion only Verify each assertion under the ZTDF assertions specification, Sections 5 to 8, with exactly one key: the per-ID key for its exact id, else the default key, else the payload key with HS256. A failure with the selected key is final, and an empty or unusable selected entry, including an HS256 key given as PEM text, fails with configuration-error instead of falling through to the next source. Check the binding's JWS directly rather than through jwt.Parse: compact serialization in strict base64url, no crit header, an alg this SDK supports that equals the selected key's algorithm, and a signature under that key. A jwk or x5c header must hold the selected public key (RFC 7638 thumbprint) and is refused with an HMAC key. A jwk must be well formed for its key type, with minimal RSA integers and exact EC coordinate lengths, and every x5c entry must be padded base64. Claims other than assertionHash and assertionSig are ignored. A missing binding method means jws; STANAG 4778 binding objects, unknown methods, and bindings with both forms or neither fail with their own reasons. Every failure is an ErrAssertionFailure carrying the exact id and a Section 9 reason. Vendor the DSPX-5520 shared conformance vectors and run them in a data-driven test. Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
…o the SDK The decrypt command's assertion verification keys file accepts a "defaultKey" alongside "keys", but that key was never converted from its PEM or secret text, so the SDK could not use it. Convert it like the per-ID keys. Report with reason=configuration-error a key that cannot be used, an HS256 key given as PEM text, and any top-level member other than "keys" and "defaultKey". Also stop dereferencing a nil key when an RSA PRIVATE KEY block fails to parse, and document defaultKey. Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
Decrypting a TDF whose encryptionInformation.keyAccess is empty or absent
now fails with ErrNoKeyAccessObjects ("no key access objects") when the
reader first needs the payload key: before any KAS call, integrity check,
or assertion check, from Read, ReadAt, WriteTo, or UnencryptedMetadata.
Loading the TDF, inspecting its manifest, and IsValidTdf are unchanged.
Key reconstruction also refuses to continue when no key split was
returned, so no path proceeds without a payload key.
Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
Contributor
|
This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
This was referenced Nov 9, 2026
| } | ||
| s.small = append(s.small, name) | ||
| if len(s.small) > nameSetMapThreshold { | ||
| s.big = make(map[string]struct{}, len(s.small)*2) //nolint:mnd // headroom for growth |
Contributor
Benchmark results, click to expandBulk Benchmark Results
TDF3 Benchmark Results
|
Contributor
|
Contributor
This was referenced Nov 9, 2026
Member
Author
|
Too big; split |
mmaudet
pushed a commit
to mmaudet/platform
that referenced
this pull request
Nov 27, 2026
…tdf#4302) ### Proposed Changes * Decrypting a TDF whose `encryptionInformation.keyAccess` is empty or absent now fails with the new `ErrNoKeyAccessObjects` (message contains `no key access objects`; unwraps to `ErrTampered`). The check runs when the reader first needs the payload key (`Read`, `ReadAt`, `WriteTo`, `UnencryptedMetadata`), before any KAS call, integrity check, or assertion check. * Key reconstruction also refuses to continue when no key split was returned, so no path proceeds without a payload key. * `LoadTDF`, manifest inspection, and `IsValidTdf` are unchanged. Split out of opentdf#4301 (draft; the complete change). Cross-SDK counterparts: opentdf/java-sdk#433, opentdf/web-sdk#1136; xtest: opentdf/tests#703. **Compatibility:** such a file could never be decrypted; it now fails early with a specific error instead of later with a KAS or integrity error. ### Checklist - [x] I have added or updated unit tests - [ ] I have added or updated integration tests (if appropriate) - [ ] I have added or updated documentation ### Testing Instructions * `cd sdk && go test ./... -race` (new: `sdk/no_key_access_test.go`). * xtest: `test_empty_key_access.py`, forced with `XT_FORCE_SUPPORTS=reject_empty_key_access`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Decryption now stops with a clear error when a file has no usable key-access information, instead of proceeding without a recovered payload key. * In these cases, the reader does not contact the key access service or release plaintext. Null key-access data is rejected as invalid. * Loading and inspecting files without key-access information remain available. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
This aligns the Go SDK and otdfctl with the Java and JS SDKs on how TDF manifests are parsed and how assertions are hashed and verified. All three SDKs run the same shared conformance vectors from opentdf/tests.
Manifest parsing. Manifests are checked while parsing. Each of the following is rejected:
One historical spelling,
IsStreamable, is accepted. The checks run inLoadTDF,IsValidTdf, andManifest.UnmarshalJSON.LoadTDFremains parse-only.Assertion hashing. The assertion hash covers the assertion exactly as it appears in the manifest, minus its top-level
binding. The newComputeAssertionHashexposes the calculation, andexperimental/tdfre-exports it. Writers hash the object they write.Binding forms. A missing
binding.methodmeansjws.jwsandJWSare accepted. Other methods, and binding objects, are reported as unsupported.Verification keys. Each assertion is verified with one key from configuration: its per-ID key, otherwise
DefaultKey, otherwise the payload key with HS256.algmust match that key's algorithm.jwkorx5cis accepted only when it matches that key.assertionHashandassertionSigare not validated.crypto/rsaandcrypto/hmacdirectly.Errors.
ErrAssertionFailuregains aReason(AssertionFailureReasonconstants). It still unwraps toErrTampered, and its message includesreason=<code>.Key access. Reading a TDF that has no key access objects fails with
ErrNoKeyAccessObjectsbefore any KAS request.IsValidTdfis unchanged.otdfctl. The assertion verification keys file supports
defaultKey. Unknown top-level members, PEM text as an HS256 key, and unknown algorithms are configuration errors. The man page notes that a default key also applies to payload-key assertions.Dependencies.
github.com/gowebpki/jcsv1.0.1 → v1.0.2, which bringstestifyv1.12.1.Compatibility
reason=binding-mismatch.system-metadataassertion that Java writers add, so those files fail verification when only a default key is configured.Checklist
Testing Instructions
cd sdk && go test ./... -race,cd otdfctl && go test ./..., andcd sdk && go test -run TestREADMECodeBlocks.sdk/testdata/assertion-vectors-phase0.jsonand run bysdk/assertion_vectors_test.go.xtest.ymlwithforce-supports=assertion_header_key_pinning,assertion_hash_raw,reject_empty_key_access.Related pull requests