@wireapp/core 42.3.1 → 42.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Account.js +2 -2
- package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts +12 -5
- package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts.map +1 -1
- package/lib/messagingProtocols/mls/MLSService/MLSService.js +29 -25
- package/lib/messagingProtocols/mls/MLSService/MLSService.test.js +50 -0
- package/package.json +3 -3
package/lib/Account.js
CHANGED
|
@@ -181,7 +181,7 @@ class Account extends TypedEventEmitter_1.TypedEventEmitter {
|
|
|
181
181
|
const client = await this.service.client.register(loginData, clientInfo, initialPreKeys);
|
|
182
182
|
if (this.service.mls) {
|
|
183
183
|
const { userId, domain = '' } = this.apiClient.context;
|
|
184
|
-
await this.service.mls.
|
|
184
|
+
await this.service.mls.initClient({ id: userId, domain }, client);
|
|
185
185
|
}
|
|
186
186
|
this.logger.info(`Created new client {mls: ${!!this.service.mls}, id: ${client.id}}`);
|
|
187
187
|
await this.service.notification.initializeNotificationStream();
|
|
@@ -204,7 +204,7 @@ class Account extends TypedEventEmitter_1.TypedEventEmitter {
|
|
|
204
204
|
const { userId, domain = '' } = this.apiClient.context;
|
|
205
205
|
if (!client) {
|
|
206
206
|
// If the client has been passed to the method, it means it also has been initialized
|
|
207
|
-
await this.service.mls.initClient({ id: userId, domain }, validClient
|
|
207
|
+
await this.service.mls.initClient({ id: userId, domain }, validClient);
|
|
208
208
|
}
|
|
209
209
|
// initialize schedulers for pending mls proposals once client is initialized
|
|
210
210
|
await this.service.mls.checkExistingPendingProposals();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RegisteredClient } from '@wireapp/api-client/lib/client';
|
|
1
2
|
import { PostMlsMessageResponse, SUBCONVERSATION_ID } from '@wireapp/api-client/lib/conversation';
|
|
2
3
|
import { Subconversation } from '@wireapp/api-client/lib/conversation/Subconversation';
|
|
3
4
|
import { ConversationMLSMessageAddEvent, ConversationMLSWelcomeEvent } from '@wireapp/api-client/lib/event';
|
|
@@ -10,6 +11,12 @@ import { KeyPackageClaimUser } from '../../../conversation';
|
|
|
10
11
|
import { TypedEventEmitter } from '../../../util/TypedEventEmitter';
|
|
11
12
|
import { CommitPendingProposalsParams, HandlePendingProposalsParams, MLSCallbacks } from '../types';
|
|
12
13
|
export declare const optionalToUint8Array: (array: Uint8Array | []) => Uint8Array;
|
|
14
|
+
interface LocalMLSServiceConfig extends MLSServiceConfig {
|
|
15
|
+
/**
|
|
16
|
+
* minimum number of key packages client should have available (configured to half of nbKeyPackages)
|
|
17
|
+
*/
|
|
18
|
+
minRequiredNumberOfAvailableKeyPackages: number;
|
|
19
|
+
}
|
|
13
20
|
export interface SubconversationEpochInfoMember {
|
|
14
21
|
userid: string;
|
|
15
22
|
clientid: string;
|
|
@@ -25,13 +32,12 @@ export declare class MLSService extends TypedEventEmitter<Events> {
|
|
|
25
32
|
private readonly apiClient;
|
|
26
33
|
private readonly coreCryptoClient;
|
|
27
34
|
logger: logdown.Logger;
|
|
28
|
-
config:
|
|
35
|
+
config: LocalMLSServiceConfig;
|
|
29
36
|
groupIdFromConversationId?: MLSCallbacks['groupIdFromConversationId'];
|
|
30
37
|
private readonly textEncoder;
|
|
31
38
|
private readonly textDecoder;
|
|
32
39
|
constructor(apiClient: APIClient, coreCryptoClient: CoreCrypto, { keyingMaterialUpdateThreshold, nbKeyPackages, defaultCiphersuite, defaultCredentialType, }: Partial<MLSServiceConfig>);
|
|
33
|
-
initClient(userId: QualifiedId,
|
|
34
|
-
createClient(userId: QualifiedId, clientId: string): Promise<void>;
|
|
40
|
+
initClient(userId: QualifiedId, client: RegisteredClient): Promise<void>;
|
|
35
41
|
private uploadCommitBundle;
|
|
36
42
|
/**
|
|
37
43
|
* Will add users to an existing MLS group and send a commit bundle to backend.
|
|
@@ -153,11 +159,12 @@ export declare class MLSService extends TypedEventEmitter<Events> {
|
|
|
153
159
|
*/
|
|
154
160
|
checkForKeyPackagesBackendSync(): void;
|
|
155
161
|
private syncKeyPackages;
|
|
162
|
+
private getRemoteMLSKeyPackageCount;
|
|
156
163
|
/**
|
|
157
|
-
* Will
|
|
164
|
+
* Will update the given client on backend with its public key.
|
|
158
165
|
*
|
|
159
166
|
* @param mlsClient Intance of the coreCrypto that represents the mls client
|
|
160
|
-
* @param
|
|
167
|
+
* @param client Backend client data
|
|
161
168
|
*/
|
|
162
169
|
private uploadMLSPublicKeys;
|
|
163
170
|
private uploadMLSKeyPackages;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MLSService.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/mls/MLSService/MLSService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MLSService.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/mls/MLSService/MLSService.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAqB,gBAAgB,EAAC,MAAM,gCAAgC,CAAC;AACzF,OAAO,EAAC,sBAAsB,EAAE,kBAAkB,EAAC,MAAM,sCAAsC,CAAC;AAChG,OAAO,EAAC,eAAe,EAAC,MAAM,sDAAsD,CAAC;AACrF,OAAO,EAAC,8BAA8B,EAAE,2BAA2B,EAAC,MAAM,+BAA+B,CAAC;AAE1G,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAGzD,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EACL,eAAe,EAIf,cAAc,EACd,UAAU,EAEV,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACpB,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAC,gBAAgB,EAAsB,MAAM,oBAAoB,CAAC;AAIzE,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAM1D,OAA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B,CAAC,EAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAC,EAAE,4BAA4B;IAoBjG;;;;;OAKG;IACU,sBAAsB,CAAC,EAAC,OAAO,EAAE,UAAkB,EAAC,EAAE,4BAA4B;IAa/F;;;;OAIG;IACU,6BAA6B;IAiB1C;;;;OAIG;IACU,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,EAAE,CAAC;IAY5F,wBAAwB,CAAC,KAAK,EAAE,8BAA8B;IAI9D,4BAA4B,CAAC,KAAK,EAAE,2BAA2B;CAG7E"}
|
|
@@ -74,19 +74,15 @@ class MLSService extends TypedEventEmitter_1.TypedEventEmitter {
|
|
|
74
74
|
nbKeyPackages,
|
|
75
75
|
defaultCiphersuite,
|
|
76
76
|
defaultCredentialType,
|
|
77
|
+
minRequiredNumberOfAvailableKeyPackages: Math.floor(nbKeyPackages / 2),
|
|
77
78
|
};
|
|
78
79
|
}
|
|
79
|
-
async initClient(userId,
|
|
80
|
-
const qualifiedClientId = (0, fullyQualifiedClientIdUtils_1.constructFullyQualifiedClientId)(userId.id,
|
|
80
|
+
async initClient(userId, client) {
|
|
81
|
+
const qualifiedClientId = (0, fullyQualifiedClientIdUtils_1.constructFullyQualifiedClientId)(userId.id, client.id, userId.domain);
|
|
81
82
|
await this.coreCryptoClient.mlsInit(this.textEncoder.encode(qualifiedClientId), [this.config.defaultCiphersuite]);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
await this.
|
|
85
|
-
// If the device is new, we need to upload keypackages and public key to the backend
|
|
86
|
-
const publicKey = await this.coreCryptoClient.clientPublicKey(this.config.defaultCiphersuite);
|
|
87
|
-
const keyPackages = await this.coreCryptoClient.clientKeypackages(this.config.defaultCiphersuite, this.config.defaultCredentialType, this.config.nbKeyPackages);
|
|
88
|
-
await this.uploadMLSPublicKeys(publicKey, clientId);
|
|
89
|
-
await this.uploadMLSKeyPackages(keyPackages, clientId);
|
|
83
|
+
// We need to make sure keypackages and public key are uploaded to the backend
|
|
84
|
+
await this.uploadMLSPublicKeys(client);
|
|
85
|
+
await this.uploadMLSKeyPackages(client.id);
|
|
90
86
|
}
|
|
91
87
|
async uploadCommitBundle(groupId, commitBundle, { regenerateCommitBundle, isExternalCommit } = {}) {
|
|
92
88
|
const { commit, groupInfo, welcome } = commitBundle;
|
|
@@ -467,31 +463,39 @@ class MLSService extends TypedEventEmitter_1.TypedEventEmitter {
|
|
|
467
463
|
}
|
|
468
464
|
async syncKeyPackages() {
|
|
469
465
|
const validKeyPackagesCount = await this.clientValidKeypackagesCount();
|
|
470
|
-
|
|
471
|
-
if (validKeyPackagesCount <= minAllowedNumberOfKeyPackages) {
|
|
466
|
+
if (validKeyPackagesCount <= this.config.minRequiredNumberOfAvailableKeyPackages) {
|
|
472
467
|
const clientId = this.apiClient.validatedClientId;
|
|
473
|
-
|
|
474
|
-
const backendKeyPackagesCount = await this.apiClient.api.client.getMLSKeyPackageCount(clientId, (0, numberToHex_1.numberToHex)(this.config.defaultCiphersuite));
|
|
475
|
-
if (backendKeyPackagesCount <= minAllowedNumberOfKeyPackages) {
|
|
476
|
-
//upload new keys
|
|
477
|
-
const newKeyPackages = await this.clientKeypackages(this.config.nbKeyPackages);
|
|
478
|
-
await this.uploadMLSKeyPackages(newKeyPackages, clientId);
|
|
479
|
-
}
|
|
468
|
+
await this.uploadMLSKeyPackages(clientId);
|
|
480
469
|
}
|
|
481
470
|
}
|
|
471
|
+
async getRemoteMLSKeyPackageCount(clientId) {
|
|
472
|
+
return this.apiClient.api.client.getMLSKeyPackageCount(clientId, (0, numberToHex_1.numberToHex)(this.config.defaultCiphersuite));
|
|
473
|
+
}
|
|
482
474
|
/**
|
|
483
|
-
* Will
|
|
475
|
+
* Will update the given client on backend with its public key.
|
|
484
476
|
*
|
|
485
477
|
* @param mlsClient Intance of the coreCrypto that represents the mls client
|
|
486
|
-
* @param
|
|
478
|
+
* @param client Backend client data
|
|
487
479
|
*/
|
|
488
|
-
async uploadMLSPublicKeys(
|
|
489
|
-
|
|
480
|
+
async uploadMLSPublicKeys(client) {
|
|
481
|
+
var _a;
|
|
482
|
+
// If we've already updated a client with its public key, there's no need to do it again.
|
|
483
|
+
if ((_a = client.mls_public_keys) === null || _a === void 0 ? void 0 : _a.ed25519) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
const publicKey = await this.coreCryptoClient.clientPublicKey(this.config.defaultCiphersuite);
|
|
487
|
+
return this.apiClient.api.client.putClient(client.id, {
|
|
490
488
|
mls_public_keys: { ed25519: btoa(bazinga64_1.Converter.arrayBufferViewToBaselineString(publicKey)) },
|
|
491
489
|
});
|
|
492
490
|
}
|
|
493
|
-
async uploadMLSKeyPackages(
|
|
494
|
-
|
|
491
|
+
async uploadMLSKeyPackages(clientId) {
|
|
492
|
+
const backendKeyPackagesCount = await this.getRemoteMLSKeyPackageCount(clientId);
|
|
493
|
+
// If we have enough keys uploaded on backend, there's no need to upload more.
|
|
494
|
+
if (backendKeyPackagesCount > this.config.minRequiredNumberOfAvailableKeyPackages) {
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
const keyPackages = await this.clientKeypackages(this.config.nbKeyPackages);
|
|
498
|
+
return this.apiClient.api.client.uploadMLSKeyPackages(clientId, keyPackages.map(keypackage => btoa(bazinga64_1.Converter.arrayBufferViewToBaselineString(keypackage))));
|
|
495
499
|
}
|
|
496
500
|
async wipeConversation(groupId) {
|
|
497
501
|
const doesConversationExist = await this.conversationExists(groupId);
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
const client_1 = require("@wireapp/api-client/lib/client");
|
|
21
22
|
const crypto_1 = require("crypto");
|
|
22
23
|
const api_client_1 = require("@wireapp/api-client");
|
|
23
24
|
const MLSService_1 = require("./MLSService");
|
|
@@ -31,6 +32,10 @@ describe('MLSService', () => {
|
|
|
31
32
|
createConversation: jest.fn(),
|
|
32
33
|
conversationExists: jest.fn(),
|
|
33
34
|
wipeConversation: jest.fn(),
|
|
35
|
+
clientValidKeypackagesCount: jest.fn(),
|
|
36
|
+
clientKeypackages: jest.fn(),
|
|
37
|
+
mlsInit: jest.fn(),
|
|
38
|
+
clientPublicKey: jest.fn(),
|
|
34
39
|
};
|
|
35
40
|
describe('registerConversation', () => {
|
|
36
41
|
let mlsService;
|
|
@@ -96,4 +101,49 @@ describe('MLSService', () => {
|
|
|
96
101
|
expect(isEstablshed).toBe(true);
|
|
97
102
|
});
|
|
98
103
|
});
|
|
104
|
+
describe('initClient', () => {
|
|
105
|
+
it('uploads public key only if it was not yet defined on client entity', async () => {
|
|
106
|
+
const mlsService = new MLSService_1.MLSService(apiClient, mockCoreCrypto, {});
|
|
107
|
+
const mockUserId = { id: 'user-1', domain: 'local.zinfra.io' };
|
|
108
|
+
const mockClientId = 'client-1';
|
|
109
|
+
const mockClient = { mls_public_keys: {}, id: mockClientId };
|
|
110
|
+
apiClient.context = { clientType: client_1.ClientType.PERMANENT, clientId: mockClientId, userId: '' };
|
|
111
|
+
const mockedClientPublicKey = new Uint8Array();
|
|
112
|
+
jest.spyOn(mockCoreCrypto, 'clientPublicKey').mockResolvedValueOnce(mockedClientPublicKey);
|
|
113
|
+
jest.spyOn(apiClient.api.client, 'putClient').mockResolvedValueOnce(undefined);
|
|
114
|
+
jest.spyOn(apiClient.api.client, 'getMLSKeyPackageCount').mockResolvedValueOnce(mlsService.config.nbKeyPackages);
|
|
115
|
+
await mlsService.initClient(mockUserId, mockClient);
|
|
116
|
+
expect(mockCoreCrypto.mlsInit).toHaveBeenCalled();
|
|
117
|
+
expect(apiClient.api.client.putClient).toHaveBeenCalledWith(mockClientId, expect.anything());
|
|
118
|
+
});
|
|
119
|
+
it('uploads key packages if there are not enough keys on backend', async () => {
|
|
120
|
+
const mlsService = new MLSService_1.MLSService(apiClient, mockCoreCrypto, {});
|
|
121
|
+
const mockUserId = { id: 'user-1', domain: 'local.zinfra.io' };
|
|
122
|
+
const mockClientId = 'client-1';
|
|
123
|
+
const mockClient = { mls_public_keys: { ed25519: 'key' }, id: mockClientId };
|
|
124
|
+
apiClient.context = { clientType: client_1.ClientType.PERMANENT, clientId: mockClientId, userId: '' };
|
|
125
|
+
const mockedClientKeyPackages = [new Uint8Array()];
|
|
126
|
+
jest.spyOn(mockCoreCrypto, 'clientKeypackages').mockResolvedValueOnce(mockedClientKeyPackages);
|
|
127
|
+
jest
|
|
128
|
+
.spyOn(apiClient.api.client, 'getMLSKeyPackageCount')
|
|
129
|
+
.mockResolvedValueOnce(mlsService.config.minRequiredNumberOfAvailableKeyPackages - 1);
|
|
130
|
+
jest.spyOn(apiClient.api.client, 'uploadMLSKeyPackages').mockResolvedValueOnce(undefined);
|
|
131
|
+
await mlsService.initClient(mockUserId, mockClient);
|
|
132
|
+
expect(mockCoreCrypto.mlsInit).toHaveBeenCalled();
|
|
133
|
+
expect(apiClient.api.client.uploadMLSKeyPackages).toHaveBeenCalledWith(mockClientId, expect.anything());
|
|
134
|
+
});
|
|
135
|
+
it('does not upload public key or key packages if both are already uploaded', async () => {
|
|
136
|
+
const mlsService = new MLSService_1.MLSService(apiClient, mockCoreCrypto, {});
|
|
137
|
+
const mockUserId = { id: 'user-1', domain: 'local.zinfra.io' };
|
|
138
|
+
const mockClientId = 'client-1';
|
|
139
|
+
const mockClient = { mls_public_keys: { ed25519: 'key' }, id: mockClientId };
|
|
140
|
+
apiClient.context = { clientType: client_1.ClientType.PERMANENT, clientId: mockClientId, userId: '' };
|
|
141
|
+
jest.spyOn(apiClient.api.client, 'getClient').mockResolvedValueOnce(mockClient);
|
|
142
|
+
jest.spyOn(apiClient.api.client, 'getMLSKeyPackageCount').mockResolvedValueOnce(mlsService.config.nbKeyPackages);
|
|
143
|
+
await mlsService.initClient(mockUserId, mockClient);
|
|
144
|
+
expect(mockCoreCrypto.mlsInit).toHaveBeenCalled();
|
|
145
|
+
expect(apiClient.api.client.uploadMLSKeyPackages).not.toHaveBeenCalled();
|
|
146
|
+
expect(apiClient.api.client.putClient).not.toHaveBeenCalled();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
99
149
|
});
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"./lib/cryptography/AssetCryptography/crypto.node": "./lib/cryptography/AssetCryptography/crypto.browser.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@wireapp/api-client": "^26.0
|
|
14
|
+
"@wireapp/api-client": "^26.1.0",
|
|
15
15
|
"@wireapp/commons": "^5.1.3",
|
|
16
16
|
"@wireapp/core-crypto": "1.0.0-rc.12",
|
|
17
17
|
"@wireapp/cryptobox": "12.8.0",
|
|
@@ -60,6 +60,6 @@
|
|
|
60
60
|
"test:coverage": "jest --coverage",
|
|
61
61
|
"watch": "tsc --watch"
|
|
62
62
|
},
|
|
63
|
-
"version": "42.3.
|
|
64
|
-
"gitHead": "
|
|
63
|
+
"version": "42.3.3",
|
|
64
|
+
"gitHead": "0738ddd4b3c2b97687b8bc11fc4b67a8a443dffa"
|
|
65
65
|
}
|