Update to libsignal-client v0.10.1 with zkgroup included
This commit is contained in:
parent
6445a01f2a
commit
983713003d
11 changed files with 58 additions and 348 deletions
|
@ -9,7 +9,7 @@ import {
|
|||
isNumber,
|
||||
values,
|
||||
} from 'lodash';
|
||||
import type { ClientZkGroupCipher } from 'zkgroup';
|
||||
import type { ClientZkGroupCipher } from '@signalapp/signal-client/zkgroup';
|
||||
import { v4 as getGuid } from 'uuid';
|
||||
import LRU from 'lru-cache';
|
||||
import * as log from './logging/log';
|
||||
|
|
|
@ -2,13 +2,9 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { last, sortBy } from 'lodash';
|
||||
import { AuthCredentialResponse } from 'zkgroup';
|
||||
import { AuthCredentialResponse } from '@signalapp/signal-client/zkgroup';
|
||||
|
||||
import {
|
||||
base64ToCompatArray,
|
||||
compatArrayToBase64,
|
||||
getClientZkAuthOperations,
|
||||
} from '../util/zkgroup';
|
||||
import { getClientZkAuthOperations } from '../util/zkgroup';
|
||||
|
||||
import type { GroupCredentialType } from '../textsecure/WebAPI';
|
||||
import * as durations from '../util/durations';
|
||||
|
@ -151,9 +147,9 @@ export async function maybeFetchNewCredentials(): Promise<void> {
|
|||
const authCredential = clientZKAuthOperations.receiveAuthCredential(
|
||||
uuid,
|
||||
item.redemptionTime,
|
||||
new AuthCredentialResponse(base64ToCompatArray(item.credential))
|
||||
new AuthCredentialResponse(Buffer.from(item.credential, 'base64'))
|
||||
);
|
||||
const credential = compatArrayToBase64(authCredential.serialize());
|
||||
const credential = authCredential.serialize().toString('base64');
|
||||
|
||||
return {
|
||||
redemptionTime: item.redemptionTime,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2020-2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { ProfileKeyCredentialRequestContext } from 'zkgroup';
|
||||
import type { ProfileKeyCredentialRequestContext } from '@signalapp/signal-client/zkgroup';
|
||||
import { SEALED_SENDER } from '../types/SealedSender';
|
||||
import { Address } from '../types/Address';
|
||||
import { QualifiedAddress } from '../types/QualifiedAddress';
|
||||
|
|
|
@ -564,36 +564,6 @@
|
|||
"updated": "2020-08-26T18:06:51.702Z",
|
||||
"reasonDetail": "isn't jquery"
|
||||
},
|
||||
{
|
||||
"rule": "jQuery-load(",
|
||||
"path": "node_modules/array-index/node_modules/debug/src/browser.js",
|
||||
"line": "function load() {",
|
||||
"reasonCategory": "falseMatch",
|
||||
"updated": "2020-02-21T22:10:39.074Z"
|
||||
},
|
||||
{
|
||||
"rule": "jQuery-load(",
|
||||
"path": "node_modules/array-index/node_modules/debug/src/browser.js",
|
||||
"line": "exports.enable(load());",
|
||||
"reasonCategory": "falseMatch",
|
||||
"updated": "2020-02-21T22:10:39.074Z"
|
||||
},
|
||||
{
|
||||
"rule": "jQuery-load(",
|
||||
"path": "node_modules/array-index/node_modules/debug/src/node.js",
|
||||
"line": "function load() {",
|
||||
"reasonCategory": "falseMatch",
|
||||
"updated": "2020-10-21T00:36:11.618Z",
|
||||
"reasonDetail": "isn't jquery"
|
||||
},
|
||||
{
|
||||
"rule": "jQuery-load(",
|
||||
"path": "node_modules/array-index/node_modules/debug/src/node.js",
|
||||
"line": "exports.enable(load());",
|
||||
"reasonCategory": "falseMatch",
|
||||
"updated": "2020-10-21T00:36:11.618Z",
|
||||
"reasonDetail": "isn't jquery"
|
||||
},
|
||||
{
|
||||
"rule": "jQuery-insertAfter(",
|
||||
"path": "node_modules/ast-types/lib/path.js",
|
||||
|
@ -9230,62 +9200,6 @@
|
|||
"reasonCategory": "falseMatch",
|
||||
"updated": "2021-04-05T20:48:36.065Z"
|
||||
},
|
||||
{
|
||||
"rule": "jQuery-load(",
|
||||
"path": "node_modules/ref-array-napi/node_modules/debug/src/browser.js",
|
||||
"line": "function load() {",
|
||||
"reasonCategory": "falseMatch",
|
||||
"updated": "2020-04-30T22:35:27.860Z"
|
||||
},
|
||||
{
|
||||
"rule": "jQuery-load(",
|
||||
"path": "node_modules/ref-array-napi/node_modules/debug/src/browser.js",
|
||||
"line": "exports.enable(load());",
|
||||
"reasonCategory": "falseMatch",
|
||||
"updated": "2020-04-30T22:35:27.860Z"
|
||||
},
|
||||
{
|
||||
"rule": "jQuery-load(",
|
||||
"path": "node_modules/ref-array-napi/node_modules/debug/src/node.js",
|
||||
"line": "function load() {",
|
||||
"reasonCategory": "falseMatch",
|
||||
"updated": "2020-04-30T22:35:27.860Z"
|
||||
},
|
||||
{
|
||||
"rule": "jQuery-load(",
|
||||
"path": "node_modules/ref-array-napi/node_modules/debug/src/node.js",
|
||||
"line": "exports.enable(load());",
|
||||
"reasonCategory": "falseMatch",
|
||||
"updated": "2020-04-30T22:35:27.860Z"
|
||||
},
|
||||
{
|
||||
"rule": "jQuery-load(",
|
||||
"path": "node_modules/ref-struct-di/node_modules/debug/src/browser.js",
|
||||
"line": "function load() {",
|
||||
"reasonCategory": "falseMatch",
|
||||
"updated": "2020-02-21T22:10:39.074Z"
|
||||
},
|
||||
{
|
||||
"rule": "jQuery-load(",
|
||||
"path": "node_modules/ref-struct-di/node_modules/debug/src/browser.js",
|
||||
"line": "exports.enable(load());",
|
||||
"reasonCategory": "falseMatch",
|
||||
"updated": "2020-02-21T22:10:39.074Z"
|
||||
},
|
||||
{
|
||||
"rule": "jQuery-load(",
|
||||
"path": "node_modules/ref-struct-di/node_modules/debug/src/node.js",
|
||||
"line": "function load() {",
|
||||
"reasonCategory": "falseMatch",
|
||||
"updated": "2020-02-21T22:10:39.074Z"
|
||||
},
|
||||
{
|
||||
"rule": "jQuery-load(",
|
||||
"path": "node_modules/ref-struct-di/node_modules/debug/src/node.js",
|
||||
"line": "exports.enable(load());",
|
||||
"reasonCategory": "falseMatch",
|
||||
"updated": "2020-02-21T22:10:39.074Z"
|
||||
},
|
||||
{
|
||||
"rule": "jQuery-$(",
|
||||
"path": "node_modules/regenerate/regenerate.js",
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
// Copyright 2020 Signal Messenger, LLC
|
||||
// Copyright 2020-2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type {
|
||||
FFICompatArrayType,
|
||||
ProfileKeyCredentialRequestContext,
|
||||
} from 'zkgroup';
|
||||
import type { ProfileKeyCredentialRequestContext } from '@signalapp/signal-client/zkgroup';
|
||||
import {
|
||||
AuthCredential,
|
||||
ClientZkAuthOperations,
|
||||
ClientZkGroupCipher,
|
||||
ClientZkProfileOperations,
|
||||
FFICompatArray,
|
||||
GroupMasterKey,
|
||||
GroupSecretParams,
|
||||
ProfileKey,
|
||||
|
@ -20,36 +16,11 @@ import {
|
|||
ProfileKeyCredentialResponse,
|
||||
ServerPublicParams,
|
||||
UuidCiphertext,
|
||||
} from 'zkgroup';
|
||||
import * as Bytes from '../Bytes';
|
||||
} from '@signalapp/signal-client/zkgroup';
|
||||
import { UUID } from '../types/UUID';
|
||||
import type { UUIDStringType } from '../types/UUID';
|
||||
|
||||
export * from 'zkgroup';
|
||||
|
||||
export function uint8ArrayToCompatArray(
|
||||
buffer: Uint8Array
|
||||
): FFICompatArrayType {
|
||||
return new FFICompatArray(Buffer.from(buffer));
|
||||
}
|
||||
|
||||
export function compatArrayToUint8Array(
|
||||
compatArray: FFICompatArrayType
|
||||
): Uint8Array {
|
||||
return compatArray.buffer;
|
||||
}
|
||||
|
||||
export function base64ToCompatArray(base64: string): FFICompatArrayType {
|
||||
return uint8ArrayToCompatArray(Bytes.fromBase64(base64));
|
||||
}
|
||||
|
||||
export function compatArrayToBase64(compatArray: FFICompatArrayType): string {
|
||||
return Bytes.toBase64(compatArrayToUint8Array(compatArray));
|
||||
}
|
||||
|
||||
export function compatArrayToHex(compatArray: FFICompatArrayType): string {
|
||||
return Bytes.toHex(compatArrayToUint8Array(compatArray));
|
||||
}
|
||||
export * from '@signalapp/signal-client/zkgroup';
|
||||
|
||||
// Scenarios
|
||||
|
||||
|
@ -57,9 +28,7 @@ export function decryptGroupBlob(
|
|||
clientZkGroupCipher: ClientZkGroupCipher,
|
||||
ciphertext: Uint8Array
|
||||
): Uint8Array {
|
||||
return compatArrayToUint8Array(
|
||||
clientZkGroupCipher.decryptBlob(uint8ArrayToCompatArray(ciphertext))
|
||||
);
|
||||
return clientZkGroupCipher.decryptBlob(Buffer.from(ciphertext));
|
||||
}
|
||||
|
||||
export function decryptProfileKeyCredentialPresentation(
|
||||
|
@ -67,7 +36,7 @@ export function decryptProfileKeyCredentialPresentation(
|
|||
presentationBuffer: Uint8Array
|
||||
): { profileKey: Uint8Array; uuid: UUIDStringType } {
|
||||
const presentation = new ProfileKeyCredentialPresentation(
|
||||
uint8ArrayToCompatArray(presentationBuffer)
|
||||
Buffer.from(presentationBuffer)
|
||||
);
|
||||
|
||||
const uuidCiphertext = presentation.getUuidCiphertext();
|
||||
|
@ -80,7 +49,7 @@ export function decryptProfileKeyCredentialPresentation(
|
|||
);
|
||||
|
||||
return {
|
||||
profileKey: compatArrayToUint8Array(profileKey.serialize()),
|
||||
profileKey: profileKey.serialize(),
|
||||
uuid: UUID.cast(uuid),
|
||||
};
|
||||
}
|
||||
|
@ -91,7 +60,7 @@ export function decryptProfileKey(
|
|||
uuid: UUIDStringType
|
||||
): Uint8Array {
|
||||
const profileKeyCiphertext = new ProfileKeyCiphertext(
|
||||
uint8ArrayToCompatArray(profileKeyCiphertextBuffer)
|
||||
Buffer.from(profileKeyCiphertextBuffer)
|
||||
);
|
||||
|
||||
const profileKey = clientZkGroupCipher.decryptProfileKey(
|
||||
|
@ -99,16 +68,14 @@ export function decryptProfileKey(
|
|||
uuid
|
||||
);
|
||||
|
||||
return compatArrayToUint8Array(profileKey.serialize());
|
||||
return profileKey.serialize();
|
||||
}
|
||||
|
||||
export function decryptUuid(
|
||||
clientZkGroupCipher: ClientZkGroupCipher,
|
||||
uuidCiphertextBuffer: Uint8Array
|
||||
): string {
|
||||
const uuidCiphertext = new UuidCiphertext(
|
||||
uint8ArrayToCompatArray(uuidCiphertextBuffer)
|
||||
);
|
||||
const uuidCiphertext = new UuidCiphertext(Buffer.from(uuidCiphertextBuffer));
|
||||
|
||||
return clientZkGroupCipher.decryptUuid(uuidCiphertext);
|
||||
}
|
||||
|
@ -117,7 +84,7 @@ export function deriveProfileKeyVersion(
|
|||
profileKeyBase64: string,
|
||||
uuid: UUIDStringType
|
||||
): string {
|
||||
const profileKeyArray = base64ToCompatArray(profileKeyBase64);
|
||||
const profileKeyArray = Buffer.from(profileKeyBase64, 'base64');
|
||||
const profileKey = new ProfileKey(profileKeyArray);
|
||||
|
||||
const profileKeyVersion = profileKey.getProfileKeyVersion(uuid);
|
||||
|
@ -129,42 +96,34 @@ export function deriveGroupPublicParams(
|
|||
groupSecretParamsBuffer: Uint8Array
|
||||
): Uint8Array {
|
||||
const groupSecretParams = new GroupSecretParams(
|
||||
uint8ArrayToCompatArray(groupSecretParamsBuffer)
|
||||
Buffer.from(groupSecretParamsBuffer)
|
||||
);
|
||||
|
||||
return compatArrayToUint8Array(
|
||||
groupSecretParams.getPublicParams().serialize()
|
||||
);
|
||||
return groupSecretParams.getPublicParams().serialize();
|
||||
}
|
||||
|
||||
export function deriveGroupID(groupSecretParamsBuffer: Uint8Array): Uint8Array {
|
||||
const groupSecretParams = new GroupSecretParams(
|
||||
uint8ArrayToCompatArray(groupSecretParamsBuffer)
|
||||
Buffer.from(groupSecretParamsBuffer)
|
||||
);
|
||||
|
||||
return compatArrayToUint8Array(
|
||||
groupSecretParams.getPublicParams().getGroupIdentifier().serialize()
|
||||
);
|
||||
return groupSecretParams.getPublicParams().getGroupIdentifier().serialize();
|
||||
}
|
||||
|
||||
export function deriveGroupSecretParams(
|
||||
masterKeyBuffer: Uint8Array
|
||||
): Uint8Array {
|
||||
const masterKey = new GroupMasterKey(
|
||||
uint8ArrayToCompatArray(masterKeyBuffer)
|
||||
);
|
||||
const masterKey = new GroupMasterKey(Buffer.from(masterKeyBuffer));
|
||||
const groupSecretParams = GroupSecretParams.deriveFromMasterKey(masterKey);
|
||||
|
||||
return compatArrayToUint8Array(groupSecretParams.serialize());
|
||||
return groupSecretParams.serialize();
|
||||
}
|
||||
|
||||
export function encryptGroupBlob(
|
||||
clientZkGroupCipher: ClientZkGroupCipher,
|
||||
plaintext: Uint8Array
|
||||
): Uint8Array {
|
||||
return compatArrayToUint8Array(
|
||||
clientZkGroupCipher.encryptBlob(uint8ArrayToCompatArray(plaintext))
|
||||
);
|
||||
return clientZkGroupCipher.encryptBlob(Buffer.from(plaintext));
|
||||
}
|
||||
|
||||
export function encryptUuid(
|
||||
|
@ -173,7 +132,7 @@ export function encryptUuid(
|
|||
): Uint8Array {
|
||||
const uuidCiphertext = clientZkGroupCipher.encryptUuid(uuidPlaintext);
|
||||
|
||||
return compatArrayToUint8Array(uuidCiphertext.serialize());
|
||||
return uuidCiphertext.serialize();
|
||||
}
|
||||
|
||||
export function generateProfileKeyCredentialRequest(
|
||||
|
@ -181,7 +140,7 @@ export function generateProfileKeyCredentialRequest(
|
|||
uuid: UUIDStringType,
|
||||
profileKeyBase64: string
|
||||
): { context: ProfileKeyCredentialRequestContext; requestHex: string } {
|
||||
const profileKeyArray = base64ToCompatArray(profileKeyBase64);
|
||||
const profileKeyArray = Buffer.from(profileKeyBase64, 'base64');
|
||||
const profileKey = new ProfileKey(profileKeyArray);
|
||||
|
||||
const context = clientZkProfileCipher.createProfileKeyCredentialRequestContext(
|
||||
|
@ -193,7 +152,7 @@ export function generateProfileKeyCredentialRequest(
|
|||
|
||||
return {
|
||||
context,
|
||||
requestHex: compatArrayToHex(requestArray),
|
||||
requestHex: requestArray.toString('hex'),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -203,17 +162,17 @@ export function getAuthCredentialPresentation(
|
|||
groupSecretParamsBase64: string
|
||||
): Uint8Array {
|
||||
const authCredential = new AuthCredential(
|
||||
base64ToCompatArray(authCredentialBase64)
|
||||
Buffer.from(authCredentialBase64, 'base64')
|
||||
);
|
||||
const secretParams = new GroupSecretParams(
|
||||
base64ToCompatArray(groupSecretParamsBase64)
|
||||
Buffer.from(groupSecretParamsBase64, 'base64')
|
||||
);
|
||||
|
||||
const presentation = clientZkAuthOperations.createAuthCredentialPresentation(
|
||||
secretParams,
|
||||
authCredential
|
||||
);
|
||||
return compatArrayToUint8Array(presentation.serialize());
|
||||
return presentation.serialize();
|
||||
}
|
||||
|
||||
export function createProfileKeyCredentialPresentation(
|
||||
|
@ -221,14 +180,15 @@ export function createProfileKeyCredentialPresentation(
|
|||
profileKeyCredentialBase64: string,
|
||||
groupSecretParamsBase64: string
|
||||
): Uint8Array {
|
||||
const profileKeyCredentialArray = base64ToCompatArray(
|
||||
profileKeyCredentialBase64
|
||||
const profileKeyCredentialArray = Buffer.from(
|
||||
profileKeyCredentialBase64,
|
||||
'base64'
|
||||
);
|
||||
const profileKeyCredential = new ProfileKeyCredential(
|
||||
profileKeyCredentialArray
|
||||
);
|
||||
const secretParams = new GroupSecretParams(
|
||||
base64ToCompatArray(groupSecretParamsBase64)
|
||||
Buffer.from(groupSecretParamsBase64, 'base64')
|
||||
);
|
||||
|
||||
const presentation = clientZkProfileCipher.createProfileKeyCredentialPresentation(
|
||||
|
@ -236,14 +196,14 @@ export function createProfileKeyCredentialPresentation(
|
|||
profileKeyCredential
|
||||
);
|
||||
|
||||
return compatArrayToUint8Array(presentation.serialize());
|
||||
return presentation.serialize();
|
||||
}
|
||||
|
||||
export function getClientZkAuthOperations(
|
||||
serverPublicParamsBase64: string
|
||||
): ClientZkAuthOperations {
|
||||
const serverPublicParams = new ServerPublicParams(
|
||||
base64ToCompatArray(serverPublicParamsBase64)
|
||||
Buffer.from(serverPublicParamsBase64, 'base64')
|
||||
);
|
||||
|
||||
return new ClientZkAuthOperations(serverPublicParams);
|
||||
|
@ -253,7 +213,7 @@ export function getClientZkGroupCipher(
|
|||
groupSecretParamsBase64: string
|
||||
): ClientZkGroupCipher {
|
||||
const serverPublicParams = new GroupSecretParams(
|
||||
base64ToCompatArray(groupSecretParamsBase64)
|
||||
Buffer.from(groupSecretParamsBase64, 'base64')
|
||||
);
|
||||
|
||||
return new ClientZkGroupCipher(serverPublicParams);
|
||||
|
@ -263,7 +223,7 @@ export function getClientZkProfileOperations(
|
|||
serverPublicParamsBase64: string
|
||||
): ClientZkProfileOperations {
|
||||
const serverPublicParams = new ServerPublicParams(
|
||||
base64ToCompatArray(serverPublicParamsBase64)
|
||||
Buffer.from(serverPublicParamsBase64, 'base64')
|
||||
);
|
||||
|
||||
return new ClientZkProfileOperations(serverPublicParams);
|
||||
|
@ -275,7 +235,7 @@ export function handleProfileKeyCredential(
|
|||
responseBase64: string
|
||||
): string {
|
||||
const response = new ProfileKeyCredentialResponse(
|
||||
base64ToCompatArray(responseBase64)
|
||||
Buffer.from(responseBase64, 'base64')
|
||||
);
|
||||
const profileKeyCredential = clientZkProfileCipher.receiveProfileKeyCredential(
|
||||
context,
|
||||
|
@ -284,15 +244,15 @@ export function handleProfileKeyCredential(
|
|||
|
||||
const credentialArray = profileKeyCredential.serialize();
|
||||
|
||||
return compatArrayToBase64(credentialArray);
|
||||
return credentialArray.toString('base64');
|
||||
}
|
||||
|
||||
export function deriveProfileKeyCommitment(
|
||||
profileKeyBase64: string,
|
||||
uuid: UUIDStringType
|
||||
): string {
|
||||
const profileKeyArray = base64ToCompatArray(profileKeyBase64);
|
||||
const profileKeyArray = Buffer.from(profileKeyBase64, 'base64');
|
||||
const profileKey = new ProfileKey(profileKeyArray);
|
||||
|
||||
return compatArrayToBase64(profileKey.getCommitment(uuid).contents);
|
||||
return profileKey.getCommitment(uuid).contents.toString('base64');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue