Fix CDS fetches; use proper hashing mechanism
This commit is contained in:
parent
e4db9358cf
commit
a1c534ec0c
3 changed files with 22 additions and 7 deletions
|
@ -8,6 +8,7 @@ import {
|
|||
CipherType,
|
||||
encrypt,
|
||||
decrypt,
|
||||
HashType,
|
||||
hash,
|
||||
sign,
|
||||
} from './util/synchronousCrypto';
|
||||
|
@ -470,8 +471,8 @@ export async function decryptAesGcm(
|
|||
|
||||
// Hashing
|
||||
|
||||
export async function sha256(data: ArrayBuffer): Promise<ArrayBuffer> {
|
||||
return hash(data);
|
||||
export function sha256(data: ArrayBuffer): ArrayBuffer {
|
||||
return hash(HashType.size256, data);
|
||||
}
|
||||
|
||||
// Utility
|
||||
|
@ -628,7 +629,7 @@ export async function encryptCdsDiscoveryRequest(
|
|||
});
|
||||
const queryDataPlaintext = concatenateBytes(nonce, numbersArray.buffer);
|
||||
const queryDataKey = getRandomBytes(32);
|
||||
const commitment = await sha256(queryDataPlaintext);
|
||||
const commitment = sha256(queryDataPlaintext);
|
||||
const iv = getRandomBytes(12);
|
||||
const queryDataCiphertext = await encryptAesGcm(
|
||||
queryDataKey,
|
||||
|
|
|
@ -5,12 +5,21 @@ import { assert } from 'chai';
|
|||
import crypto from 'crypto';
|
||||
|
||||
import { typedArrayToArrayBuffer as toArrayBuffer } from '../../Crypto';
|
||||
import { hash, sign, encrypt, decrypt } from '../../util/synchronousCrypto';
|
||||
import {
|
||||
HashType,
|
||||
hash,
|
||||
sign,
|
||||
encrypt,
|
||||
decrypt,
|
||||
} from '../../util/synchronousCrypto';
|
||||
|
||||
describe('synchronousCrypto', () => {
|
||||
describe('hash', () => {
|
||||
it('returns SHA512 hash of the input', () => {
|
||||
const result = hash(toArrayBuffer(Buffer.from('signal')));
|
||||
const result = hash(
|
||||
HashType.size512,
|
||||
toArrayBuffer(Buffer.from('signal'))
|
||||
);
|
||||
assert.strictEqual(
|
||||
Buffer.from(result).toString('base64'),
|
||||
'WxneQjrfSlY95Bi+SAzDAr2cf3mxUXePeNYn6DILN4a8NFr9VelTbP5tGHdthi+' +
|
||||
|
|
|
@ -14,9 +14,14 @@ export function sign(key: ArrayBuffer, data: ArrayBuffer): ArrayBuffer {
|
|||
);
|
||||
}
|
||||
|
||||
export function hash(data: ArrayBuffer): ArrayBuffer {
|
||||
export enum HashType {
|
||||
size256 = 'sha256',
|
||||
size512 = 'sha512',
|
||||
}
|
||||
|
||||
export function hash(type: HashType, data: ArrayBuffer): ArrayBuffer {
|
||||
return toArrayBuffer(
|
||||
crypto.createHash('sha512').update(Buffer.from(data)).digest()
|
||||
crypto.createHash(type).update(Buffer.from(data)).digest()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue