Skip to content

fix(sdk): DSPX-1561 align TDF manifest parsing and assertion verification across SDKs - #4301

Closed
dmihalcik-virtru wants to merge 4 commits into
mainfrom
DSPX-1561-go-sdk-pluggable-assertion-validation-and-trust-an
Closed

dmihalcik-virtru wants to merge 4 commits into
mainfrom
DSPX-1561-go-sdk-pluggable-assertion-validation-and-trust-an

Conversation

@dmihalcik-virtru

@dmihalcik-virtru dmihalcik-virtru commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

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:

    • duplicate member names, including escaped spellings;
    • member names that differ from a known manifest member only in case;
    • invalid UTF-8;
    • inside assertions, lone surrogates, Unicode noncharacters, and out-of-range numbers.

    One historical spelling, IsStreamable, is accepted. The checks run in LoadTDF, IsValidTdf, and Manifest.UnmarshalJSON. LoadTDF remains parse-only.

  • Assertion hashing. The assertion hash covers the assertion exactly as it appears in the manifest, minus its top-level binding. The new ComputeAssertionHash exposes the calculation, and experimental/tdf re-exports it. Writers hash the object they write.

  • Binding forms. A missing binding.method means jws. jws and JWS are 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.

    • The JWS alg must match that key's algorithm.
    • An embedded jwk or x5c is accepted only when it matches that key.
    • Claims other than assertionHash and assertionSig are not validated.
    • JWS verification uses crypto/rsa and crypto/hmac directly.
  • Errors. ErrAssertionFailure gains a Reason (AssertionFailureReason constants). It still unwraps to ErrTampered, and its message includes reason=<code>.

  • Key access. Reading a TDF that has no key access objects fails with ErrNoKeyAccessObjects before any KAS request. IsValidTdf is 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/jcs v1.0.1 → v1.0.2, which brings testify v1.12.1.

Compatibility

  • Manifests with duplicate or case-variant member names no longer load.
  • Assertions are verified against the hash of their stored form. Files whose writer hashed a different form fail with reason=binding-mismatch.
  • A configured default key applies to every assertion without a per-ID key. That includes payload-key assertions such as the system-metadata assertion that Java writers add, so those files fail verification when only a default key is configured.

Checklist

  • 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, cd otdfctl && go test ./..., and cd sdk && go test -run TestREADMECodeBlocks.
  • The shared vectors are vendored as sdk/testdata/assertion-vectors-phase0.json and run by sdk/assertion_vectors_test.go.
  • Cross-SDK xtest with this branch: forced run and released/branch interop run, both passing. To run it, dispatch xtest.yml with force-supports=assertion_header_key_pinning,assertion_hash_raw,reject_empty_key_access.

Related pull requests

…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>
@coderabbitai

coderabbitai Bot commented Nov 9, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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

@github-actions github-actions Bot added comp:sdk A software development kit, including library, for client applications and inter-service communicati size/xl labels Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
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.

Comment thread sdk/assertion_json.go
}
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
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor
Benchmark results, click to expand

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 259.689155ms
Throughput 385.08 requests/second

TDF3 Benchmark Results

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 25.556855871s
Average Latency 254.999395ms
Throughput 195.64 requests/second

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

  • otdfctl
  • sdk
  • service
  • tests-bdd

See the workflow run for details.

@dmihalcik-virtru

Copy link
Copy Markdown
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:sdk A software development kit, including library, for client applications and inter-service communicati size/xl

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants