Skip to content

Commit bb29962

Browse files
elizabethhealypflynn-virtrujakedoublevopentdf-automation[bot]dependabot[bot]
authored
fix(sdk): Additional comments and cleanup of Rewrap V2 code (#780)
* feat(sdk): Move to rewrap v2 request/response format (#774) * feat: Certificates & Obligations (#755) * - Pin `@bufbuild/buf` and `@bufbuild/protoc-gen-es` dependencies to specific versions. - Update copyright notices in `http_pb.ts` and `validate_pb.ts`. * - Pin `@bufbuild/buf` and `@bufbuild/protoc-gen-es` dependencies to specific versions. - Update copyright notices in `http_pb.ts` and `validate_pb.ts`. * Add `obligations` and `rootCerts` attributes to test fixtures and mock data. Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * feat: upgrade tdf clients to rewrap v2 proto structure Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * updates to match go behavior Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * feat: Get Namespace (#756) * - Pin `@bufbuild/buf` and `@bufbuild/protoc-gen-es` dependencies to specific versions. - Update copyright notices in `http_pb.ts` and `validate_pb.ts`. * - Pin `@bufbuild/buf` and `@bufbuild/protoc-gen-es` dependencies to specific versions. - Update copyright notices in `http_pb.ts` and `validate_pb.ts`. * Add `obligations` and `rootCerts` attributes to test fixtures and mock data. * Add `getRootCertsFromNamespace` function and include headers initialization in `authProvider` * Add input validation for `getRootCertsFromNamespace` and basic unit tests Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * feat(sdk): initial obligations support in rewrap flow (#748) * feat(core): initial obligations support in rewrap flow * 🤖 🎨 Autoformat Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * wip Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * more wip * rm unused import * 🤖 🎨 Autoformat Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * lint fix Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * tests Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * 🤖 🎨 Autoformat Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * move file * tdf3 client * cleanup * obligations method on opentdf reader classes * requiredObligations on DecoratedReadableStream in tdf3 * wip: fetch decision if obligations haven't been set on reader * wip * 🤖 🎨 Autoformat Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * bugfix in case of no data attributes leading to no obligations Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * working state Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * fix Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * 🤖 🎨 Autoformat Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * fix comments * rm example web app hardcoded attributes and obligations * unit tests for getRequiredObligations * improve nullish operators * cleanup * 🤖 🎨 Autoformat Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * improvements * fix * 🤖 🎨 Autoformat Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * improve log * put back package.json changes * pr feedback Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * 🤖 🎨 Autoformat Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> * rm rewrap header for obligations over legacy http for older platforms --------- Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * chore: release sdk 0.5.0 (#658) * chore(main): release sdk 0.5.0 * Update dependencies --------- Co-authored-by: opentdf-automation[bot] <149537512+opentdf-automation[bot]@users.noreply.github.com> Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * feat(ci): Add a workflow to update the generated code for new protocol/go versions (#767) * add a workflow to update the pbs * trigger on PR * correct platform location * add gh token to env * remove extra file after use * detect changes on regen * test with latest version * remove, test changes * test for signed commits * try with api * push the new branch * use a shorter file name in the message * fix for non existing files * run slightly after midnight to avoid queues Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * 🤖 🎨 Autoformat Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * handle rewrap response Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * formatting Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * passing unit tests Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * format Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * chore(docs): bump playwright and @playwright/test in /web-app/tests (#763) Bumps [playwright](https://github.com/microsoft/playwright) to 1.56.1 and updates ancestor dependency [@playwright/test](https://github.com/microsoft/playwright). These dependencies need to be updated together. Updates `playwright` from 1.50.1 to 1.56.1 - [Release notes](https://github.com/microsoft/playwright/releases) - [Commits](microsoft/playwright@v1.50.1...v1.56.1) Updates `@playwright/test` from 1.50.1 to 1.56.1 - [Release notes](https://github.com/microsoft/playwright/releases) - [Commits](microsoft/playwright@v1.50.1...v1.56.1) --- updated-dependencies: - dependency-name: playwright dependency-version: 1.56.1 dependency-type: indirect - dependency-name: "@playwright/test" dependency-version: 1.56.1 dependency-type: direct:development ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * chore(docs): bump vite from 6.3.6 to 6.4.1 in /web-app (#764) Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 6.3.6 to 6.4.1. - [Release notes](https://github.com/vitejs/vite/releases) - [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md) - [Commits](https://github.com/vitejs/vite/commits/create-vite@6.4.1/packages/vite) --- updated-dependencies: - dependency-name: vite dependency-version: 6.4.1 dependency-type: direct:development ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * v1 backwards compatability Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * error handling Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * cleanup Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * chore(docs): bump playwright and @playwright/test in /web-app (#775) Bumps [playwright](https://github.com/microsoft/playwright) and [@playwright/test](https://github.com/microsoft/playwright). These dependencies needed to be updated together. Updates `playwright` from 1.50.1 to 1.56.1 - [Release notes](https://github.com/microsoft/playwright/releases) - [Commits](microsoft/playwright@v1.50.1...v1.56.1) Updates `@playwright/test` from 1.50.1 to 1.56.1 - [Release notes](https://github.com/microsoft/playwright/releases) - [Commits](microsoft/playwright@v1.50.1...v1.56.1) --- updated-dependencies: - dependency-name: playwright dependency-version: 1.56.1 dependency-type: direct:development - dependency-name: "@playwright/test" dependency-version: 1.56.1 dependency-type: direct:development ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * suggestions --------- Signed-off-by: Elizabeth Healy <ehealy@virtru.com> Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Paul Flynn <43211074+pflynn-virtru@users.noreply.github.com> Co-authored-by: jakedoublev <jake.vanvorhis@virtru.com> Co-authored-by: Jake Van Vorhis <83739412+jakedoublev@users.noreply.github.com> Co-authored-by: opentdf-automation[bot] <149537512+opentdf-automation[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * additional comments and cleanup Signed-off-by: Elizabeth Healy <ehealy@virtru.com> * format * fix merge --------- Signed-off-by: Elizabeth Healy <ehealy@virtru.com> Signed-off-by: jakedoublev <jake.vanvorhis@virtru.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Paul Flynn <43211074+pflynn-virtru@users.noreply.github.com> Co-authored-by: jakedoublev <jake.vanvorhis@virtru.com> Co-authored-by: Jake Van Vorhis <83739412+jakedoublev@users.noreply.github.com> Co-authored-by: opentdf-automation[bot] <149537512+opentdf-automation[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent e7718d5 commit bb29962

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

lib/src/nanotdf/Client.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export default class Client {
273273
create(UnsignedRewrapRequest_WithPolicyRequestSchema, {
274274
keyAccessObjects: [
275275
{
276-
keyAccessObjectId: 'kao-0',
276+
keyAccessObjectId: 'kao-0', // only one kao, no bulk
277277
keyAccessObject: {
278278
header: new Uint8Array(nanoTdfHeader),
279279
kasUrl: '',
@@ -309,10 +309,16 @@ export default class Client {
309309
this.authProvider,
310310
this.fulfillableObligationFQNs
311311
);
312+
// Upgrade any V1 responses to V2
312313
upgradeRewrapResponseV1(rewrapResp);
313314

314-
// Assume only one response and one result for now (V1 style)
315-
const result = rewrapResp.responses[0].results[0];
315+
const result = rewrapResp.responses?.[0]?.results?.[0];
316+
if (!result) {
317+
// This should not happen - KAS should always return at least one response and one result
318+
// or the upgradeRewrapResponseV1 should have created them
319+
throw new DecryptError('KAS rewrap response missing expected response or result');
320+
}
321+
316322
let entityWrappedKey: Uint8Array<ArrayBufferLike>;
317323
switch (result.result.case) {
318324
case 'kasWrappedKey': {

lib/src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ export function getRequiredObligationFQNs(response: RewrapResponse) {
263263

264264
/**
265265
* Upgrades a RewrapResponse from v1 format to v2.
266+
* Note: This mutates the response in place.
266267
*/
267268
export function upgradeRewrapResponseV1(response: RewrapResponse) {
268269
if (response.responses.length > 0) {

lib/tdf3/src/tdf.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,11 +844,17 @@ async function unwrapKey({
844844
authProvider,
845845
fulfillableObligations
846846
);
847+
// Upgrade V1 response to V2 format if needed
847848
upgradeRewrapResponseV1(rewrapResp);
848849
const { sessionPublicKey } = rewrapResp;
849850
const requiredObligations = getRequiredObligationFQNs(rewrapResp);
850851
// Assume only one response and one result for now (V1 style)
851-
const result = rewrapResp.responses[0].results[0];
852+
const result = rewrapResp.responses?.[0]?.results?.[0];
853+
if (!result) {
854+
// This should not happen - KAS should always return at least one response and one result
855+
// or the upgradeRewrapResponseV1 should have created them
856+
throw new DecryptError('KAS rewrap response missing expected response or result');
857+
}
852858
const metadata = result.metadata;
853859
// Handle the different cases of result.result
854860
switch (result.result.case) {

lib/tests/server.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,27 +168,27 @@ const kas: RequestListener = async (req, res) => {
168168
res.end('{"error": "Invalid client public key"}');
169169
return;
170170
}
171-
const kaoheader = rewrap.requests?.[0]?.keyAccessObjects?.[0]?.keyAccessObject?.header;
171+
const keyAccessObject = rewrap.requests?.[0]?.keyAccessObjects?.[0]?.keyAccessObject;
172+
const kaoheader = keyAccessObject?.header;
172173
const isZTDF = !kaoheader || kaoheader.length === 0;
173174
if (isZTDF) {
174-
const wk = rewrap.requests?.[0]?.keyAccessObjects?.[0]?.keyAccessObject?.wrappedKey;
175+
const wk = keyAccessObject?.wrappedKey;
175176
if (!wk || wk.length === 0) {
176177
res.writeHead(400);
177178
res.end('{"error": "Invalid wrapped key"}');
178179
return;
179180
}
180-
const isECWrapped =
181-
rewrap.requests?.[0]?.keyAccessObjects?.[0]?.keyAccessObject?.kid == 'e1';
181+
const isECWrapped = keyAccessObject?.kid == 'e1';
182182
// Decrypt the wrapped key from TDF3
183183
let dek: Binary;
184184
if (isECWrapped) {
185-
if (!rewrap.requests?.[0]?.keyAccessObjects?.[0]?.keyAccessObject?.ephemeralPublicKey) {
185+
if (!keyAccessObject?.ephemeralPublicKey) {
186186
res.writeHead(400);
187187
res.end('{"error": "Nil ephemeral public key"}');
188188
return;
189189
}
190190
const ephemeralKey: CryptoKey = await pemPublicToCrypto(
191-
rewrap.requests?.[0]?.keyAccessObjects?.[0]?.keyAccessObject?.ephemeralPublicKey
191+
keyAccessObject?.ephemeralPublicKey
192192
);
193193
const kasPrivateKeyBytes = base64.decodeArrayBuffer(
194194
removePemFormatting(Mocks.kasECPrivateKey)

0 commit comments

Comments
 (0)