Skip to content

Commit

Permalink
fix(sdk): Sets schemaVersion, not tdf_spec_version (#414)
Browse files Browse the repository at this point in the history
* fix(cli): Lets allowedKases default to kasEndpoint
* fix(sdk): Prefer using schemaVersion

The latest spec (4.3.0) consolidates on a single `schemaVersion` field in the manifest, instead of `tdf_spec_version` and/or independent versions for policy and kao objects
  • Loading branch information
dmihalcik-virtru authored Jan 17, 2025
1 parent ec4a55a commit 74d326b
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
6 changes: 5 additions & 1 deletion cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,11 @@ export const handleArgs = (args: string[]) => {
},
async (argv) => {
log('DEBUG', 'Running decrypt command');
const allowedKases = argv.allowList?.split(',');
let allowedKases = argv.allowList?.split(',');
if (!allowedKases) {
allowedKases = argv.kasEndpoint ? [argv.kasEndpoint] : [];
}
log('DEBUG', `Allowed KASes: ${allowedKases}`);
const ignoreAllowList = !!argv.ignoreAllowList;
const authProvider = await processAuth(argv);
log('DEBUG', `Initialized auth provider ${JSON.stringify(authProvider)}`);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/opentdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class RewrapCache {
}

close() {
if (this.closer) {
if (this.closer !== undefined) {
clearInterval(this.closer);
delete this.closer;
delete this.cache;
Expand Down
3 changes: 0 additions & 3 deletions lib/src/tdf/AttributeObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ export interface AttributeObject {
/** PEM encoded public key */
readonly pubKey: string;
readonly kasUrl: string;
/** The most recent version 1.1.0. */
readonly schemaVersion?: string;
}

export async function createAttribute(
Expand All @@ -22,6 +20,5 @@ export async function createAttribute(
displayName: '',
pubKey: pubKey.publicKey,
kasUrl,
schemaVersion: '1.1.0',
};
}
1 change: 0 additions & 1 deletion lib/src/tdf/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export class Policy {
private uuidStr = uuid();
private dataAttributesList: AttributeObject[] = [];
private dissemList: string[] = [];
// private schemaVersionStr = Policy.CURRENT_VERSION;

/**
* Adds a group of entities, to the Policy's dissem list
Expand Down
1 change: 0 additions & 1 deletion lib/src/tdf/PolicyObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ export interface PolicyObjectBody {
export interface PolicyObject {
readonly uuid: string;
readonly body: PolicyObjectBody;
readonly schemaVersion?: string;
}
4 changes: 3 additions & 1 deletion lib/tdf3/src/models/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ export type Manifest = {
payload: Payload;
encryptionInformation: EncryptionInformation;
assertions: Assertion[];
tdf_spec_version: string;
schemaVersion: string;
// Deprecated
tdf_spec_version?: string;
};
1 change: 0 additions & 1 deletion lib/tdf3/src/models/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export type PolicyBody = {
};

export type Policy = {
tdf_spec_version?: string;
uuid?: string;
body?: PolicyBody;
};
Expand Down
6 changes: 3 additions & 3 deletions lib/tdf3/src/tdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ async function _generateManifest(
url: '0.payload',
protocol: 'zip',
isEncrypted: true,
schemaVersion: '3.0.0',
...(mimeType && { mimeType }),
};

Expand All @@ -272,7 +271,7 @@ async function _generateManifest(
// generate the manifest first, then insert integrity information into it
encryptionInformation: encryptionInformationStr,
assertions: assertions,
tdf_spec_version: tdfSpecVersion,
schemaVersion: tdfSpecVersion,
};
}

Expand Down Expand Up @@ -887,7 +886,8 @@ export async function readStream(cfg: DecryptConfiguration) {
const encryptedSegmentSizeDefault = defaultSegmentSize || DEFAULT_SEGMENT_SIZE;

// check if the TDF is a legacy TDF
const isLegacyTDF = !manifest.tdf_spec_version;
const specVersion = manifest.schemaVersion || manifest.tdf_spec_version;
const isLegacyTDF = !specVersion || specVersion.startsWith('3.');

// Decode each hash and store it in an array of Uint8Array
const segmentHashList = segments.map(
Expand Down

0 comments on commit 74d326b

Please sign in to comment.