Skip to content

Commit b763278

Browse files
authored
fix: signingKey should not be part of the computed hash (#696)
In some flows it appears that `signingKey` is set and then serialized to `null` and messes up the signature.
1 parent f0d9719 commit b763278

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/tdf3/src/assertions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export type AssertionPayload = {
4343
* @returns the hexadecimal string representation of the hash
4444
*/
4545
export async function hash(a: Assertion): Promise<string> {
46-
const result = canonicalizeEx(a, { exclude: ['binding', 'hash', 'sign', 'verify'] });
46+
const result = canonicalizeEx(a, {
47+
exclude: ['binding', 'hash', 'sign', 'verify', 'signingKey'],
48+
});
4749

4850
const hash = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(result));
4951
return hex.encodeArrayBuffer(hash);

lib/tests/mocha/unit/assertions.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,34 @@ describe('assertions', () => {
2121
})
2222
).to.be.true;
2323
});
24+
25+
it('normalizes assertions', async () => {
26+
let assertion: any = {
27+
appliesToState: 'unencrypted',
28+
id: 'system-metadata',
29+
binding: {
30+
method: 'jws',
31+
signature: 'test-signature',
32+
},
33+
signingKey: {
34+
alg: 'ES256',
35+
key: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
36+
},
37+
scope: 'payload',
38+
statement: {
39+
format: 'json',
40+
schema: 'system-metadata-v1',
41+
value:
42+
'{"tdf_spec_version":"4.3.0","creation_date":"2025-07-23T09:25:51.255364+02:00","operating_system":"Mac OS X","sdk_version":"Java-0.8.2-SNAPSHOT","java_version":"17.0.14","architecture":"aarch64"}',
43+
},
44+
type: 'other',
45+
};
46+
47+
let h1 = await assertions.hash(assertion);
48+
delete assertion.signingKey;
49+
let h2 = await assertions.hash(assertion);
50+
51+
expect(h1).to.equal(h2);
52+
});
2453
});
2554
});

0 commit comments

Comments
 (0)