Skip to content

feat(sdk): add opt-in hexless policy binding - #1097

Draft
pflynn-virtru wants to merge 1 commit into
mainfrom
optin/hexless-policy-binding
Draft

pflynn-virtru wants to merge 1 commit into
mainfrom
optin/hexless-policy-binding

Conversation

@pflynn-virtru

Copy link
Copy Markdown
Member

Summary

Adds an opt-in hexless policy binding: each key access object's policy binding hash is written as Base64(HMAC), the form the TDF spec defines, instead of the legacy Base64(hex(HMAC)). Default output is unchanged. Mirrors opentdf/platform#4232 (Go).

  • hexlessPolicyBinding: true on CreateZTDFOptions (also EncryptParams), and the CLI flag --hexlessPolicyBinding.
  • tdfSpecVersion: '4.2.2' overrides the opt-in and keeps the legacy form.
  • The three per-wrapping copies of the binding computation are now one policyBindingHash helper. It uses the injected CryptoService.
  • Reader: a binding that decodes to 32 bytes is re-encoded to Base64(hex(HMAC)) in the rewrap request, so this SDK can decrypt hexless TDFs against any KAS. Legacy bindings pass through unchanged. Older readers forward the binding unchanged and need a KAS with fix(kas): accept spec-compliant policy bindings platform#4223.
  • The rewrap request now also forwards the policy binding alg. protobuf-es previously dropped it because the proto field is named algorithm. KAS ignores the field, and the Go SDK already sends it.
  • Known-answer vectors are shared with the Go SDK.

Part of opentdf/platform#3578.

Testing

  • cd lib && npm test (mocha, wtr, karma): all passing. npm run lint and make format clean.
  • cd cli && bats bin/opentdf.bats: 12/12.
  • The mock KAS in lib/tests/server.ts now rejects a 32-byte (hexless) binding, the way a KAS before fix(kas): accept spec-compliant policy bindings platform#4223 does. So the hexless round-trip tests only pass if the reader re-encodes. Removing the re-encode makes them fail.
  • New tests cover: known answers for both forms; the injected CryptoService is used; every key access object in a two-KAS split gets the hexless binding; tdfSpecVersion: '4.2.2' overrides; ML-KEM and EC wrapping honor the flag. unit/key-access.test.ts is renamed to .spec.ts so the test runners pick it up.

🤖 Generated with Claude Code

Add a hexlessPolicyBinding encrypt option (CreateZTDFOptions,
EncryptParams, EncryptConfiguration, and the CLI --hexlessPolicyBinding
flag) that writes each key access object's policy binding as Base64(HMAC)
instead of Base64(hex(HMAC)). Without the option, and whenever
tdfSpecVersion is 4.2.2, the writer output is unchanged.

On decrypt, the rewrap request re-encodes a binding that decodes to 32
bytes back to Base64(hex(HMAC)), so a KAS without dual-accept still
verifies it. The rewrap request now also forwards the policy binding alg:
protobuf-es previously dropped it because the manifest field is alg, not
algorithm. KAS ignores the field, and the Go SDK already sends it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Paul Flynn <pflynn-virtru@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Oct 19, 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

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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