Skip to content

Commit 86142ba

Browse files
fix(sdk): Update ec-wrapped salt value (#464)
1 parent 5c0b171 commit 86142ba

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

lib/tdf3/src/crypto/salt.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const generateSalt = async () => {
2+
const encoder = new TextEncoder();
3+
const data = encoder.encode('TDF');
4+
5+
// Generate hash
6+
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
7+
8+
return new Uint8Array(hashBuffer);
9+
};
10+
11+
export const ztdfSalt = generateSalt();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { pemPublicToCrypto } from '../../../src/nanotdf-crypto/pemPublicToCrypto
55
import { cryptoPublicToPem } from '../../../src/utils.js';
66
import { Binary } from '../binary.js';
77
import * as cryptoService from '../crypto/index.js';
8+
import { ztdfSalt } from '../crypto/salt.js';
89
import { Policy } from './policy.js';
910

1011
export type KeyAccessType = 'remote' | 'wrapped' | 'ec-wrapped';
@@ -44,7 +45,7 @@ export class ECWrapped {
4445
pemPublicToCrypto(this.publicKey),
4546
]);
4647
const kek = await keyAgreement(ek.privateKey, clientPublicKey, {
47-
hkdfSalt: new TextEncoder().encode('salt'),
48+
hkdfSalt: await ztdfSalt,
4849
hkdfHash: 'SHA-256',
4950
});
5051
const iv = generateRandomNumber(12);

lib/tdf3/src/tdf.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
import { unsigned } from './utils/buffer-crc32.js';
5555
import { ZipReader, ZipWriter, keyMerge, concatUint8 } from './utils/index.js';
5656
import { CentralDirectory } from './utils/zip-reader.js';
57+
import { ztdfSalt } from './crypto/salt.js';
5758

5859
// TODO: input validation on manifest JSON
5960
const DEFAULT_SEGMENT_SIZE = 1024 * 1024;
@@ -707,7 +708,7 @@ async function unwrapKey({
707708
const serverEphemeralKey: CryptoKey = await pemPublicToCrypto(sessionPublicKey);
708709
const ekr = ephemeralEncryptionKeysRaw as CryptoKeyPair;
709710
const kek = await keyAgreement(ekr.privateKey, serverEphemeralKey, {
710-
hkdfSalt: new TextEncoder().encode('salt'),
711+
hkdfSalt: await ztdfSalt,
711712
hkdfHash: 'SHA-256',
712713
});
713714
const wrappedKeyAndNonce = base64.decodeArrayBuffer(entityWrappedKey);

lib/tests/server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Binary } from '../tdf3/index.js';
1212
import { type KeyAccessObject } from '../tdf3/src/models/index.js';
1313
import { valueFor } from './web/policy/mock-attrs.js';
1414
import { AttributeAndValue } from '../src/policy/attributes.js';
15+
import { ztdfSalt } from '../tdf3/src/crypto/salt.js';
1516

1617
const Mocks = getMocks();
1718

@@ -185,7 +186,7 @@ const kas: RequestListener = async (req, res) => {
185186
['deriveBits', 'deriveKey']
186187
);
187188
const kek = await keyAgreement(kasPrivateKey, ephemeralKey, {
188-
hkdfSalt: new TextEncoder().encode('salt'),
189+
hkdfSalt: await ztdfSalt,
189190
hkdfHash: 'SHA-256',
190191
});
191192
const iv = wk.slice(0, 12);
@@ -214,7 +215,7 @@ const kas: RequestListener = async (req, res) => {
214215
['deriveBits', 'deriveKey']
215216
);
216217
const kek = await keyAgreement(sessionKeyPair.privateKey, clientPublicKey, {
217-
hkdfSalt: new TextEncoder().encode('salt'),
218+
hkdfSalt: await ztdfSalt,
218219
hkdfHash: 'SHA-256',
219220
});
220221
const iv = generateRandomNumber(12);

0 commit comments

Comments
 (0)