Skip to content

Commit 9a51a79

Browse files
feat(sdk): require kid for ML-KEM key access (DSPX-3229)
ML-KEM wrapped key access objects must carry a kid so the KAS can identify which encapsulation key to unwrap with; unlike RSA/EC there is no way to recover the key without it. Previously MlKemWrapped accepted an optional kid and only emitted it when truthy, silently producing an unusable KAO. - MlKemWrapped now requires kid: string, rejects missing/blank values with a ConfigurationError, and always emits kid in the KAO. - buildKeyAccess guards the ML-KEM branch so callers get a clear ConfigurationError before constructing MlKemWrapped. - RSA (Wrapped) and EC (ECWrapped) keep kid optional, unchanged. Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
1 parent 819fe70 commit 9a51a79

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

lib/tdf3/src/models/key-access.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { base64, hex } from '../../../src/encodings/index.js';
2+
import { ConfigurationError } from '../../../src/errors.js';
23
import { Binary } from '../binary.js';
34
import type { CryptoService, KeyPair, SymmetricKey } from '../crypto/declarations.js';
45
import { getZtdfSalt } from '../crypto/salt.js';
@@ -160,13 +161,16 @@ export class MlKemWrapped {
160161

161162
constructor(
162163
public readonly url: string,
163-
public readonly kid: string | undefined,
164+
public readonly kid: string,
164165
public readonly publicKey: string,
165166
public readonly metadata: unknown,
166167
public readonly cryptoService: CryptoService,
167168
public readonly sid: string | undefined,
168169
public readonly alg: 'mlkem:512' | 'mlkem:768' | 'mlkem:1024'
169170
) {
171+
if (!kid?.trim()) {
172+
throw new ConfigurationError('MlKemWrapped requires a non-empty kid');
173+
}
170174
this.level = parseInt(alg.split(':')[1], 10) as 512 | 768 | 1024;
171175
}
172176

@@ -230,9 +234,7 @@ export class MlKemWrapped {
230234
},
231235
schemaVersion,
232236
};
233-
if (this.kid) {
234-
kao.kid = this.kid;
235-
}
237+
kao.kid = this.kid;
236238
if (this.sid?.length) {
237239
kao.sid = this.sid;
238240
}

lib/tdf3/src/tdf.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ export async function buildKeyAccess({
283283
switch (type) {
284284
case 'wrapped':
285285
if (alg === 'mlkem:512' || alg === 'mlkem:768' || alg === 'mlkem:1024') {
286+
if (!kid?.trim()) {
287+
throw new ConfigurationError(
288+
`buildKeyAccess: kid is required for ML-KEM algorithm [${alg}]`
289+
);
290+
}
286291
return new MlKemWrapped(url, kid, pubKey, metadata, cryptoService, sid, alg);
287292
}
288293
return new Wrapped(url, kid, pubKey, metadata, cryptoService, sid);

0 commit comments

Comments
 (0)