@wireapp/core 38.15.0 → 38.15.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"MessageService.d.ts","sourceRoot":"","sources":["../../../src/conversation/message/MessageService.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,cAAc,EACd,oBAAoB,EAIpB,oBAAoB,EACpB,WAAW,EACZ,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAC,WAAW,EAAE,4BAA4B,EAAE,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AAQ5G,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAS9C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,kCAAkC,CAAC;AAKrE,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,SAAS;IAAa,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAArD,SAAS,EAAE,SAAS,EAAmB,cAAc,EAAE,cAAc;IAElG;;;;;;;;;;;OAWG;IACU,WAAW,CACtB,eAAe,EAAE,MAAM,EACvB,UAAU,EAAE,WAAW,GAAG,mBAAmB,EAC7C,SAAS,EAAE,UAAU,EACrB,OAAO,GAAE;QACP,cAAc,CAAC,EAAE,WAAW,CAAC;QAC7B,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAC;QACnC,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;KAC/E,GACL,OAAO,CAAC,cAAc,GAAG;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAC,CAAC;IAgCjD;;;;;;;;;;;OAWG;IACU,oBAAoB,CAC/B,eAAe,EAAE,MAAM,EACvB,UAAU,EAAE,oBAAoB,GAAG,4B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OAAO,GAAE;QACP,cAAc,CAAC,EAAE,WAAW,CAAC;QAC7B,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAC;QACnC,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;KAC/E,GACL,OAAO,CAAC,cAAc,GAAG;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAC,CAAC;IAkCjD;;;;;;;;;;;OAWG;IACU,oBAAoB,CAC/B,eAAe,EAAE,MAAM,EACvB,UAAU,EAAE,oBAAoB,GAAG,4BAA4B,EAC/D,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE;QACP,SAAS,CAAC,EAAE,UAAU,CAAC;QACvB,cAAc,CAAC,EAAE,WAAW,CAAC;QAC7B,aAAa,CAAC,EAAE,OAAO,GAAG,WAAW,EAAE,CAAC;QACxC,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;KAC1F,GACA,OAAO,CAAC,oBAAoB,GAAG;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAC,CAAC;YA2BzC,uBAAuB;YAiEvB,cAAc;YAmCd,uBAAuB;IAiBrC,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,qBAAqB;YAIf,sBAAsB;IAiBpC;;;;;;;OAOG;YACW,+BAA+B;YAqB/B,sBAAsB;CAoDrC"}
@@ -59,11 +59,12 @@ class MessageService {
59
59
  plainTextPayload = externalPayload.text;
60
60
  cipherText = externalPayload.cipherText;
61
61
  }
62
- const encryptedPayload = await this.proteusService.encrypt(plainTextPayload, recipients);
63
- const send = (payload) => {
64
- return options.sendAsProtobuf
65
- ? this.sendOTRProtobufMessage(sendingClientId, payload, Object.assign(Object.assign({}, options), { assetData: cipherText }))
66
- : this.sendOTRMessage(sendingClientId, payload, Object.assign(Object.assign({}, options), { assetData: cipherText }));
62
+ const { payloads: encryptedPayload, unknowns } = await this.proteusService.encrypt(plainTextPayload, recipients);
63
+ const send = async (payload) => {
64
+ const result = options.sendAsProtobuf
65
+ ? await this.sendOTRProtobufMessage(sendingClientId, payload, Object.assign(Object.assign({}, options), { assetData: cipherText }))
66
+ : await this.sendOTRMessage(sendingClientId, payload, Object.assign(Object.assign({}, options), { assetData: cipherText }));
67
+ return unknowns ? Object.assign(Object.assign({}, result), { deleted: Object.assign(Object.assign({}, result.deleted), unknowns) }) : result;
67
68
  };
68
69
  try {
69
70
  return await send(encryptedPayload);
@@ -94,10 +95,11 @@ class MessageService {
94
95
  * @return the MessageSendingStatus returned by the backend
95
96
  */
96
97
  async sendFederatedMessage(sendingClientId, recipients, plainText, options) {
97
- const send = (payload) => {
98
- return this.sendFederatedOtrMessage(sendingClientId, payload, options);
98
+ const { payloads: encryptedPayload, unknowns: unknows } = await this.proteusService.encryptQualified(plainText, recipients);
99
+ const send = async (payload) => {
100
+ const result = await this.sendFederatedOtrMessage(sendingClientId, payload, options);
101
+ return unknows ? Object.assign(Object.assign({}, result), { deleted: Object.assign(Object.assign({}, result.deleted), unknows) }) : result;
99
102
  };
100
- const encryptedPayload = await this.proteusService.encryptQualified(plainText, recipients);
101
103
  try {
102
104
  return await send(encryptedPayload);
103
105
  }
@@ -212,8 +214,8 @@ class MessageService {
212
214
  // remove deleted clients to the recipients
213
215
  deleted.forEach(({ userId, data }) => data.forEach(clientId => delete recipients[userId.id][clientId]));
214
216
  if (Object.keys(mismatch.missing).length) {
215
- const encrypted = await this.proteusService.encrypt(plainText, mismatch.missing);
216
- const reEncryptedPayloads = (0, UserClientsUtil_1.flattenUserClients)(encrypted);
217
+ const { payloads } = await this.proteusService.encrypt(plainText, mismatch.missing);
218
+ const reEncryptedPayloads = (0, UserClientsUtil_1.flattenUserClients)(payloads);
217
219
  // add missing clients to the recipients
218
220
  reEncryptedPayloads.forEach(({ data, userId }) => (recipients[userId.id] = Object.assign(Object.assign({}, recipients[userId.id]), data)));
219
221
  }
@@ -232,8 +234,8 @@ class MessageService {
232
234
  // remove deleted clients to the recipients
233
235
  deleted.forEach(({ userId, data }) => data.forEach(clientId => delete recipients[userId.domain][userId.id][clientId]));
234
236
  if (Object.keys(mismatch.missing).length) {
235
- const encrypted = await this.proteusService.encryptQualified(plainText, mismatch.missing);
236
- const reEncryptedPayloads = (0, UserClientsUtil_1.flattenQualifiedUserClients)(encrypted);
237
+ const { payloads } = await this.proteusService.encryptQualified(plainText, mismatch.missing);
238
+ const reEncryptedPayloads = (0, UserClientsUtil_1.flattenQualifiedUserClients)(payloads);
237
239
  reEncryptedPayloads.forEach(({ data, userId }) => (recipients[userId.domain][userId.id] = Object.assign(Object.assign({}, recipients[userId.domain][userId.id]), data)));
238
240
  }
239
241
  return recipients;
@@ -67,7 +67,7 @@ function fakeEncryptQualified(_, recipients) {
67
67
  }, {});
68
68
  return acc;
69
69
  }, {});
70
- return Promise.resolve(encryptedPayload);
70
+ return Promise.resolve({ payloads: encryptedPayload });
71
71
  }
72
72
  function fakeEncrypt(_, recipients) {
73
73
  const encryptedPayload = Object.entries(recipients).reduce((userClients, [userId, clients]) => {
@@ -77,7 +77,7 @@ function fakeEncrypt(_, recipients) {
77
77
  }, {}));
78
78
  return userClients;
79
79
  }, {});
80
- return Promise.resolve(encryptedPayload);
80
+ return Promise.resolve({ payloads: encryptedPayload });
81
81
  }
82
82
  const buildMessageService = async () => {
83
83
  const apiClient = new api_client_1.APIClient();
@@ -85,7 +85,7 @@ const buildMessageService = async () => {
85
85
  const messageService = new MessageService_1.MessageService(apiClient, proteusService);
86
86
  jest.spyOn(proteusService, 'encryptQualified').mockImplementation(fakeEncryptQualified);
87
87
  jest.spyOn(proteusService, 'encrypt').mockImplementation(fakeEncrypt);
88
- return [messageService, { apiClient }];
88
+ return [messageService, { apiClient, proteusService }];
89
89
  };
90
90
  describe('MessageService', () => {
91
91
  describe('sendFederatedMessage', () => {
@@ -151,6 +151,27 @@ describe('MessageService', () => {
151
151
  expect(apiClient.api.conversation.postOTRMessageV2).toHaveBeenCalledTimes(2);
152
152
  expect(onClientMismatch).toHaveBeenCalledWith(clientMismatch);
153
153
  });
154
+ it('warns the consumer if they try to send a message to a deleted client', async () => {
155
+ const [messageService, { apiClient, proteusService }] = await buildMessageService();
156
+ const onClientMismatch = jest.fn().mockReturnValue(true);
157
+ const recipients = generateQualifiedRecipients([user1, user2]);
158
+ const unknowns = {
159
+ [user1.domain]: {
160
+ [user1.id]: [user1.clients[0]],
161
+ },
162
+ };
163
+ jest.spyOn(proteusService, 'encryptQualified').mockResolvedValue({
164
+ payloads: {},
165
+ unknowns,
166
+ });
167
+ jest.spyOn(apiClient.api.conversation, 'postOTRMessageV2').mockResolvedValue(baseMessageSendingStatus);
168
+ const result = await messageService.sendFederatedMessage('senderclientid', recipients, new Uint8Array(), {
169
+ reportMissing: true,
170
+ onClientMismatch,
171
+ conversationId: { id: 'convid', domain: '' },
172
+ });
173
+ expect(result.deleted).toEqual(unknowns);
174
+ });
154
175
  it('stops message sending if onClientMismatch returns false', async () => {
155
176
  const [messageService, { apiClient }] = await buildMessageService();
156
177
  const onClientMismatch = jest.fn().mockReturnValue(false);
@@ -8,6 +8,12 @@ import type { AddUsersToProteusConversationParams, CreateProteusConversationPara
8
8
  import { SendResult } from '../../../conversation';
9
9
  import type { EventHandlerResult } from '../../common.types';
10
10
  import { EventHandlerParams } from '../EventHandler';
11
+ type EncryptionResult = {
12
+ /** the encrypted payloads for the clients that have a valid sessions */
13
+ payloads: OTRRecipients<Uint8Array>;
14
+ /** user-client that do not have prekeys on backend (deleted clients) */
15
+ unknowns?: UserClients;
16
+ };
11
17
  export declare class ProteusService {
12
18
  private readonly apiClient;
13
19
  private readonly cryptoClient;
@@ -35,9 +41,13 @@ export declare class ProteusService {
35
41
  addUsersToConversation({ conversationId, qualifiedUserIds }: AddUsersToProteusConversationParams): Promise<import("@wireapp/api-client/lib/event").ConversationMemberJoinEvent>;
36
42
  sendMessage({ userIds, sendAsProtobuf, conversationId, nativePush, targetMode, payload, onClientMismatch, }: SendProteusMessageParams): Promise<SendResult>;
37
43
  private decrypt;
38
- encrypt(plainText: Uint8Array, recipients: UserPreKeyBundleMap | UserClients, domain?: string): Promise<OTRRecipients<Uint8Array>>;
44
+ encrypt(plainText: Uint8Array, recipients: UserPreKeyBundleMap | UserClients, domain?: string): Promise<EncryptionResult>;
39
45
  deleteSession(userId: QualifiedId, clientId: string): Promise<void>;
40
- encryptQualified(plainText: Uint8Array, preKeyBundles: QualifiedUserPreKeyBundleMap | QualifiedUserClients): Promise<QualifiedOTRRecipients>;
46
+ encryptQualified(plainText: Uint8Array, preKeyBundles: QualifiedUserPreKeyBundleMap | QualifiedUserClients): Promise<{
47
+ payloads: QualifiedOTRRecipients;
48
+ unknowns?: QualifiedUserClients;
49
+ }>;
41
50
  wipe(storeEngine?: CRUDEngine): Promise<void>;
42
51
  }
52
+ export {};
43
53
  //# sourceMappingURL=ProteusService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ProteusService.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EACV,YAAY,EAEZ,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,WAAW,EACZ,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAC,WAAW,EAAE,4BAA4B,EAAE,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AAIjH,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAEj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EAAE,gBAAgB,EAAC,EAAE,mCAAmC;IAI9F,WAAW,CAAC,EACvB,OAAO,EACP,cAAc,EACd,cAAc,EACd,UAAU,EACV,UAAU,EACV,OAAO,EACP,gBAAgB,GACjB,EAAE,wBAAwB,GAAG,OAAO,CAAC,UAAU,CAAC;YAmDnC,OAAO;IAuBR,OAAO,CAClB,SAAS,EAAE,UAAU,EACrB,UAAU,EAAE,mBAAmB,GAAG,WAAW,EAC7C,MAAM,GAAE,MAAW,GAClB,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAc9B,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM;IAS7C,gBAAgB,CAC3B,SAAS,EAAE,UAAU,EACrB,aAAa,EAAE,4BAA4B,GAAG,oBAAoB,GACjE,OAAO,CAAC,sBAAsB,CAAC;IAW5B,IAAI,CAAC,WAAW,CAAC,EAAE,UAAU;CAMpC"}
1
+ {"version":3,"file":"ProteusService.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EACV,YAAY,EAEZ,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,WAAW,EACZ,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAC,WAAW,EAAE,4BAA4B,EAAE,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AAIjH,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAI5C,OAAO,KAAK,EACV,mCAAmC,EACnC,+BAA+B,EAC/B,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAA0C,UAAU,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E,mCAAmC;IAI9F,WAAW,CAAC,EACvB,OAAO,EACP,cAAc,EACd,cAAc,EACd,UAAU,EACV,UAAU,EACV,OAAO,EACP,gBAAgB,GACjB,EAAE,wBAAwB,GAAG,OAAO,CAAC,UAAU,CAAC;YAmDnC,OAAO;IAuBR,OAAO,CAClB,SAAS,EAAE,UAAU,EACrB,UAAU,EAAE,mBAAmB,GAAG,WAAW,EAC7C,MAAM,GAAE,MAAW,GAClB,OAAO,CAAC,gBAAgB,CAAC;IAcrB,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM;IAS7C,gBAAgB,CAC3B,SAAS,EAAE,UAAU,EACrB,aAAa,EAAE,4BAA4B,GAAG,oBAAoB,GACjE,OAAO,CAAC;QAAC,QAAQ,EAAE,sBAAsB,CAAC;QAAC,QAAQ,CAAC,EAAE,oBAAoB,CAAA;KAAC,CAAC;IAkBzE,IAAI,CAAC,WAAW,CAAC,EAAE,UAAU;CAMpC"}
@@ -179,7 +179,7 @@ class ProteusService {
179
179
  }
180
180
  }
181
181
  async encrypt(plainText, recipients, domain = '') {
182
- const sessions = await (0, SessionHandler_1.initSessions)({
182
+ const { sessions, unknowns } = await (0, SessionHandler_1.initSessions)({
183
183
  recipients,
184
184
  domain,
185
185
  apiClient: this.apiClient,
@@ -187,7 +187,7 @@ class ProteusService {
187
187
  logger: this.logger,
188
188
  });
189
189
  const payload = await this.cryptoClient.encrypt(sessions, plainText);
190
- return (0, SessionHandler_1.buildEncryptedPayloads)(payload);
190
+ return { payloads: (0, SessionHandler_1.buildEncryptedPayloads)(payload), unknowns };
191
191
  }
192
192
  deleteSession(userId, clientId) {
193
193
  return (0, SessionHandler_1.deleteSession)({
@@ -199,11 +199,18 @@ class ProteusService {
199
199
  }
200
200
  async encryptQualified(plainText, preKeyBundles) {
201
201
  const qualifiedOTRRecipients = {};
202
+ const missingRecipients = {};
202
203
  for (const [domain, preKeyBundleMap] of Object.entries(preKeyBundles)) {
203
- const result = await this.encrypt(plainText, preKeyBundleMap, domain);
204
- qualifiedOTRRecipients[domain] = result;
204
+ const { unknowns, payloads } = await this.encrypt(plainText, preKeyBundleMap, domain);
205
+ qualifiedOTRRecipients[domain] = payloads;
206
+ if (unknowns) {
207
+ missingRecipients[domain] = unknowns;
208
+ }
205
209
  }
206
- return qualifiedOTRRecipients;
210
+ return {
211
+ payloads: qualifiedOTRRecipients,
212
+ unknowns: Object.keys(missingRecipients).length > 0 ? missingRecipients : undefined,
213
+ };
207
214
  }
208
215
  async wipe(storeEngine) {
209
216
  if (storeEngine) {
@@ -231,9 +231,9 @@ describe('ProteusService', () => {
231
231
  ]);
232
232
  jest.spyOn(services.cryptoClient, 'sessionExists').mockResolvedValue(true);
233
233
  jest.spyOn(services.cryptoClient, 'encrypt').mockImplementationOnce(() => Promise.resolve(encryptedPayload));
234
- const encrypted = await services.proteusService.encrypt(messageBuffer, userClients);
234
+ const { payloads } = await services.proteusService.encrypt(messageBuffer, userClients);
235
235
  expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second], messageBuffer);
236
- expect(encrypted).toEqual({
236
+ expect(payloads).toEqual({
237
237
  [firstUser.id]: {
238
238
  [firstUser.clients.first]: encryptedMessageBuffer,
239
239
  [firstUser.clients.second]: encryptedMessageBuffer,
@@ -253,9 +253,9 @@ describe('ProteusService', () => {
253
253
  ]);
254
254
  jest.spyOn(services.cryptoClient, 'sessionExists').mockResolvedValue(true);
255
255
  jest.spyOn(services.cryptoClient, 'encrypt').mockResolvedValueOnce(encryptedPayload);
256
- const encrypted = await services.proteusService.encrypt(messageBuffer, userClients);
256
+ const { payloads } = await services.proteusService.encrypt(messageBuffer, userClients);
257
257
  expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second, secondUser.sessions.first], messageBuffer);
258
- expect(encrypted).toEqual({
258
+ expect(payloads).toEqual({
259
259
  [firstUser.id]: {
260
260
  [firstUser.clients.first]: encryptedMessageBuffer,
261
261
  [firstUser.clients.second]: encryptedMessageBuffer,
@@ -280,10 +280,10 @@ describe('ProteusService', () => {
280
280
  ]);
281
281
  jest.spyOn(services.cryptoClient, 'sessionExists').mockResolvedValue(true);
282
282
  jest.spyOn(services.cryptoClient, 'encrypt').mockResolvedValueOnce(encryptedPayload);
283
- const encrypted = await services.proteusService.encryptQualified(messageBuffer, userClients);
283
+ const { payloads } = await services.proteusService.encryptQualified(messageBuffer, userClients);
284
284
  // console.log({encrypted, missing});
285
285
  expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second], messageBuffer);
286
- expect(encrypted).toEqual({
286
+ expect(payloads).toEqual({
287
287
  [domain]: {
288
288
  [firstUser.id]: {
289
289
  [firstUser.clients.first]: encryptedMessageBuffer,
@@ -307,9 +307,62 @@ describe('ProteusService', () => {
307
307
  ]);
308
308
  jest.spyOn(services.cryptoClient, 'sessionExists').mockResolvedValue(true);
309
309
  jest.spyOn(services.cryptoClient, 'encrypt').mockResolvedValueOnce(encryptedPayload);
310
- const encrypted = await services.proteusService.encryptQualified(messageBuffer, userClients);
310
+ const { payloads } = await services.proteusService.encryptQualified(messageBuffer, userClients);
311
311
  expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second, secondUser.sessions.first], messageBuffer);
312
- expect(encrypted).toEqual({
312
+ expect(payloads).toEqual({
313
+ [domain]: {
314
+ [firstUser.id]: {
315
+ [firstUser.clients.first]: encryptedMessageBuffer,
316
+ [firstUser.clients.second]: encryptedMessageBuffer,
317
+ },
318
+ [secondUser.id]: {
319
+ [secondUser.clients.first]: encryptedMessageBuffer,
320
+ },
321
+ },
322
+ });
323
+ });
324
+ it('returns the unknown clients that are deleted on backend', async () => {
325
+ const { services, data: { firstUser, secondUser, encryptedMessageBuffer, messageBuffer, domain }, } = await prepareDataForEncryption();
326
+ const userClients = {
327
+ [domain]: {
328
+ [firstUser.id]: [firstUser.clients.first, firstUser.clients.second],
329
+ [secondUser.id]: [secondUser.clients.first],
330
+ },
331
+ };
332
+ const encryptedPayload = new Map([
333
+ [firstUser.sessions.first, encryptedMessageBuffer],
334
+ [firstUser.sessions.second, encryptedMessageBuffer],
335
+ [secondUser.sessions.first, encryptedMessageBuffer],
336
+ ]);
337
+ jest.spyOn(services.apiClient.api.user, 'postQualifiedMultiPreKeyBundles').mockResolvedValue({
338
+ [domain]: {
339
+ [firstUser.id]: {
340
+ [firstUser.clients.first]: null,
341
+ [firstUser.clients.second]: {
342
+ id: 123,
343
+ key: 'pQABARhIAqEAWCCaJpFa9c626ORmjj1aV6OnOYgmTjfoiE3ynOfNfGAOmgOhAKEAWCD60VMzRrLfO+1GSjgyhnVp2N7L58DM+eeJhZJi1tBLfQT2',
344
+ },
345
+ },
346
+ [secondUser.id]: {
347
+ [secondUser.clients.first]: {
348
+ id: 123,
349
+ key: 'pQABARhIAqEAWCCaJpFa9c626ORmjj1aV6OnOYgmTjfoiE3ynOfNfGAOmgOhAKEAWCD60VMzRrLfO+1GSjgyhnVp2N7L58DM+eeJhZJi1tBLfQT2',
350
+ },
351
+ },
352
+ },
353
+ });
354
+ jest.spyOn(services.cryptoClient, 'sessionExists').mockResolvedValue(false);
355
+ jest.spyOn(services.cryptoClient, 'encrypt').mockResolvedValueOnce(encryptedPayload);
356
+ jest.spyOn(services.cryptoClient, 'sessionFromPrekey').mockResolvedValue();
357
+ jest.spyOn(services.cryptoClient, 'saveSession').mockResolvedValue();
358
+ const { payloads, unknowns } = await services.proteusService.encryptQualified(messageBuffer, userClients);
359
+ expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.second, secondUser.sessions.first], messageBuffer);
360
+ expect(unknowns).toEqual({
361
+ [domain]: {
362
+ [firstUser.id]: [firstUser.clients.first],
363
+ },
364
+ });
365
+ expect(payloads).toEqual({
313
366
  [domain]: {
314
367
  [firstUser.id]: {
315
368
  [firstUser.clients.first]: encryptedMessageBuffer,
@@ -10,6 +10,12 @@ interface ConstructSessionIdParams {
10
10
  useQualifiedIds: boolean;
11
11
  domain?: string;
12
12
  }
13
+ type InitSessionsResult = {
14
+ /** valid sessions that either already existed or have been freshly created */
15
+ sessions: string[];
16
+ /** client that do we do not have sessions with and that do not have existence on backend (deleted clients) */
17
+ unknowns?: UserClients;
18
+ };
13
19
  declare const constructSessionId: ({ userId, clientId, useQualifiedIds, domain }: ConstructSessionIdParams) => string;
14
20
  /**
15
21
  * Will make sure the session is available in cryptoClient
@@ -33,7 +39,7 @@ interface GetSessionsAndClientsFromRecipientsProps {
33
39
  /**
34
40
  * Will make sure all the sessions need to encrypt for those user/clients pair are set
35
41
  */
36
- declare const initSessions: ({ recipients, domain, apiClient, cryptoClient, logger, }: GetSessionsAndClientsFromRecipientsProps) => Promise<string[]>;
42
+ declare const initSessions: ({ recipients, domain, apiClient, cryptoClient, logger, }: GetSessionsAndClientsFromRecipientsProps) => Promise<InitSessionsResult>;
37
43
  interface DeleteSessionParams {
38
44
  userId: QualifiedId;
39
45
  clientId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"SessionHandler.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAC,WAAW,EAAC,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AAE9E,OAAO,EAAC,MAAM,EAAC,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAK9C,OAAO,EAAC,YAAY,EAAC,MAAM,mCAAmC,CAAC;AAE/D,UAAU,wBAAwB;IAChC,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,QAAA,MAAM,kBAAkB,kDAAiD,wBAAwB,KAAG,MAKnG,CAAC;AAuFF;;;GAGG;AACH,QAAA,MAAM,WAAW;YAC6B,WAAW;cAAY,MAAM;;;eAClC,SAAS;kBAAgB,YAAY;MAC3E,QAAQ,MAAM,CAShB,CAAC;AAyBF,UAAU,wCAAwC;IAChD,UAAU,EAAE,WAAW,GAAG,mBAAmB,CAAC;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,QAAA,MAAM,YAAY,6DAMf,wCAAwC,KAAG,QAAQ,MAAM,EAAE,CA+C7D,CAAC;AAEF,UAAU,mBAAmB;IAC3B,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;CAC1B;AACD,iBAAe,aAAa,CAAC,MAAM,EAAE,mBAAmB,iBAGvD;AA+CD,KAAK,iBAAiB,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9D;;GAEG;AACH,QAAA,MAAM,sBAAsB,uDAO3B,CAAC;AAEF,OAAO,EAAC,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAC,CAAC"}
1
+ {"version":3,"file":"SessionHandler.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAC,WAAW,EAAC,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAC,MA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MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9D;;GAEG;AACH,QAAA,MAAM,sBAAsB,uDAO3B,CAAC;AAEF,OAAO,EAAC,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAC,CAAC"}
@@ -43,13 +43,12 @@ const parseSessionId = (sessionId) => {
43
43
  }
44
44
  return match.groups;
45
45
  };
46
- const createLegacySessions = async ({ userClients, apiClient, cryptoClient, logger, }) => {
46
+ const createLegacySessions = async ({ userClients, apiClient, cryptoClient, }) => {
47
47
  const preKeyBundleMap = await apiClient.api.user.postMultiPreKeyBundles(userClients);
48
48
  const sessions = await createSessionsFromPreKeys({
49
49
  preKeyBundleMap,
50
50
  useQualifiedIds: false,
51
51
  cryptoClient,
52
- logger,
53
52
  });
54
53
  return sessions;
55
54
  };
@@ -57,21 +56,22 @@ const createLegacySessions = async ({ userClients, apiClient, cryptoClient, logg
57
56
  * Create sessions for the qualified clients.
58
57
  * @param {userClientMap} map of domain to (map of user IDs to client IDs)
59
58
  */
60
- const createQualifiedSessions = async ({ userClientMap, domain, apiClient, cryptoClient, logger, }) => {
59
+ const createQualifiedSessions = async ({ userClientMap, domain, apiClient, cryptoClient, }) => {
61
60
  const prekeyBundleMap = await apiClient.api.user.postQualifiedMultiPreKeyBundles({ [domain]: userClientMap });
62
61
  const sessions = [];
62
+ let unknowns = {};
63
63
  for (const domain in prekeyBundleMap) {
64
64
  const domainUsers = prekeyBundleMap[domain];
65
- const domainSessions = await createSessionsFromPreKeys({
65
+ const { sessions: createdSessions, unknowns: domainUnknowns } = await createSessionsFromPreKeys({
66
66
  preKeyBundleMap: domainUsers,
67
67
  domain,
68
68
  useQualifiedIds: true,
69
69
  cryptoClient,
70
- logger,
71
70
  });
72
- sessions.push(...domainSessions);
71
+ sessions.push(...createdSessions);
72
+ unknowns = Object.assign(Object.assign({}, unknowns), domainUnknowns);
73
73
  }
74
- return sessions;
74
+ return { sessions, unknowns };
75
75
  };
76
76
  /**
77
77
  * Will make sure the session is available in cryptoClient
@@ -79,7 +79,7 @@ const createQualifiedSessions = async ({ userClientMap, domain, apiClient, crypt
79
79
  */
80
80
  const initSession = async ({ userId, clientId, initialPrekey }, { cryptoClient, apiClient }) => {
81
81
  const recipients = initialPrekey ? { [userId.id]: { [clientId]: initialPrekey } } : { [userId.id]: [clientId] };
82
- const sessions = await initSessions({
82
+ const { sessions } = await initSessions({
83
83
  recipients,
84
84
  domain: userId.domain,
85
85
  apiClient,
@@ -93,16 +93,14 @@ exports.initSession = initSession;
93
93
  * Will call createQualifiedSessions or createLegacySessions based on passed userClientMap.
94
94
  * @param {userClientMap} map of domain to (map of user IDs to client IDs) or map of user IDs containg the lists of clients
95
95
  */
96
- const createSessions = async ({ userClientMap, domain, apiClient, cryptoClient, logger, }) => {
97
- if (domain) {
98
- return await createQualifiedSessions({ userClientMap, domain, apiClient, cryptoClient, logger });
99
- }
100
- return await createLegacySessions({
101
- userClients: userClientMap,
102
- apiClient,
103
- cryptoClient,
104
- logger,
105
- });
96
+ const createSessions = async ({ userClientMap, domain, apiClient, cryptoClient, logger }) => {
97
+ return domain
98
+ ? createQualifiedSessions({ userClientMap, domain, apiClient, cryptoClient, logger })
99
+ : createLegacySessions({
100
+ userClients: userClientMap,
101
+ apiClient,
102
+ cryptoClient,
103
+ });
106
104
  };
107
105
  /**
108
106
  * Will make sure all the sessions need to encrypt for those user/clients pair are set
@@ -130,15 +128,15 @@ const initSessions = async ({ recipients, domain = '', apiClient, cryptoClient,
130
128
  missingClients[userId.id].push(clientId);
131
129
  }
132
130
  }
133
- const newPrekeySessions = Object.keys(missingClientsWithPrekeys).length > 0
131
+ const { sessions: prekeyCreated, unknowns: prekeyUnknows } = Object.keys(missingClientsWithPrekeys).length > 0
134
132
  ? await createSessionsFromPreKeys({
135
133
  preKeyBundleMap: missingClientsWithPrekeys,
136
134
  domain,
137
135
  useQualifiedIds: !!domain,
138
136
  cryptoClient,
139
137
  })
140
- : [];
141
- const newSessions = Object.keys(missingClients).length > 0
138
+ : { sessions: [], unknowns: {} };
139
+ const { sessions: created, unknowns } = Object.keys(missingClients).length > 0
142
140
  ? await createSessions({
143
141
  userClientMap: missingClients,
144
142
  domain,
@@ -146,8 +144,12 @@ const initSessions = async ({ recipients, domain = '', apiClient, cryptoClient,
146
144
  cryptoClient,
147
145
  logger,
148
146
  })
149
- : [];
150
- return [...existingSessions, ...newPrekeySessions, ...newSessions];
147
+ : { sessions: [], unknowns: {} };
148
+ const allUnknowns = Object.assign(Object.assign({}, prekeyUnknows), unknowns);
149
+ return {
150
+ sessions: [...existingSessions, ...prekeyCreated, ...created],
151
+ unknowns: Object.keys(allUnknowns).length > 0 ? allUnknowns : undefined,
152
+ };
151
153
  };
152
154
  exports.initSessions = initSessions;
153
155
  async function deleteSession(params) {
@@ -155,15 +157,17 @@ async function deleteSession(params) {
155
157
  await params.cryptoClient.deleteSession(sessionId);
156
158
  }
157
159
  exports.deleteSession = deleteSession;
158
- const createSessionsFromPreKeys = async ({ preKeyBundleMap, domain = '', useQualifiedIds, cryptoClient, logger, }) => {
160
+ const createSessionsFromPreKeys = async ({ preKeyBundleMap, domain = '', useQualifiedIds, cryptoClient, }) => {
159
161
  const sessions = [];
162
+ const unknowns = {};
160
163
  for (const userId in preKeyBundleMap) {
161
164
  const userClients = preKeyBundleMap[userId];
162
165
  for (const clientId in userClients) {
163
166
  const sessionId = constructSessionId({ userId, clientId, domain, useQualifiedIds });
164
167
  const prekey = userClients[clientId];
165
168
  if (!prekey) {
166
- logger === null || logger === void 0 ? void 0 : logger.warn(`A prekey for client ${clientId} of user ${userId}${domain ? ` on domain ${domain}` : ''} was not found, session won't be created.`);
169
+ unknowns[userId] = unknowns[userId] || [];
170
+ unknowns[userId].push(clientId);
167
171
  continue;
168
172
  }
169
173
  const prekeyBuffer = bazinga64_1.Decoder.fromBase64(prekey.key).asBytes;
@@ -172,7 +176,7 @@ const createSessionsFromPreKeys = async ({ preKeyBundleMap, domain = '', useQual
172
176
  sessions.push(sessionId);
173
177
  }
174
178
  }
175
- return sessions;
179
+ return { sessions, unknowns };
176
180
  };
177
181
  /**
178
182
  * creates an encrypted payload that can be sent to backend from a bunch of sessionIds/encrypted payload
@@ -27,9 +27,7 @@ function generatePrekeys(userId, clientIds) {
27
27
  key: 'pQABARn//wKhAFggJ1Fbpg5l6wnzKOJE+vXpRnkqUYhIvVnR5lNXEbO2o/0DoQChAFggHxZvgvtDktY/vqBcpjjo6rQnXvcNQhfwmy8AJQJKlD0E9g==',
28
28
  } });
29
29
  }, {});
30
- return {
31
- [userId.id]: Object.assign({}, clients),
32
- };
30
+ return { [userId.id]: clients };
33
31
  }
34
32
  describe('SessionHandler', () => {
35
33
  const cryptoClient = {
@@ -134,7 +132,7 @@ describe('SessionHandler', () => {
134
132
  .spyOn(cryptoClient, 'sessionExists')
135
133
  .mockImplementation(sessionId => Promise.resolve(sessionId.includes('missing')));
136
134
  const sessionFromPrekeySpy = jest.spyOn(cryptoClient, 'sessionFromPrekey');
137
- const sessions = await (0, SessionHandler_1.initSessions)({
135
+ const { sessions } = await (0, SessionHandler_1.initSessions)({
138
136
  recipients: Object.assign(Object.assign({}, existingUserClients), missingUserClients),
139
137
  apiClient,
140
138
  cryptoClient,
@@ -142,5 +140,20 @@ describe('SessionHandler', () => {
142
140
  expect(sessionFromPrekeySpy).toHaveBeenCalledTimes(3);
143
141
  expect(sessions).toHaveLength(6);
144
142
  });
143
+ it('returns the list of deleted clients (clients with null prekeys)', async () => {
144
+ const userClients = {
145
+ 'existing-user1': ['client1', 'deleteclient'],
146
+ };
147
+ const allKeys = generatePrekeys({ id: 'existing-user1', domain: '' }, ['client1']);
148
+ allKeys['existing-user1']['deleteclient'] = null;
149
+ jest.spyOn(apiClient.api.user, 'postMultiPreKeyBundles').mockResolvedValue(allKeys);
150
+ const { sessions, unknowns } = await (0, SessionHandler_1.initSessions)({
151
+ recipients: userClients,
152
+ apiClient,
153
+ cryptoClient,
154
+ });
155
+ expect(sessions).toEqual(['existing-user1@client1']);
156
+ expect(unknowns).toEqual({ 'existing-user1': ['deleteclient'] });
157
+ });
145
158
  });
146
159
  });
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": "^22.17.0",
14
+ "@wireapp/api-client": "^22.17.1",
15
15
  "@wireapp/commons": "^5.0.4",
16
16
  "@wireapp/core-crypto": "0.6.2",
17
17
  "@wireapp/cryptobox": "12.8.0",
@@ -19,7 +19,7 @@
19
19
  "@wireapp/protocol-messaging": "1.44.0",
20
20
  "@wireapp/store-engine": "5.0.3",
21
21
  "@wireapp/store-engine-dexie": "^2.0.5",
22
- "axios": "1.3.3",
22
+ "axios": "1.3.4",
23
23
  "bazinga64": "6.0.4",
24
24
  "hash.js": "1.1.7",
25
25
  "http-status-codes": "2.2.0",
@@ -60,6 +60,6 @@
60
60
  "test:coverage": "jest --coverage",
61
61
  "watch": "tsc --watch"
62
62
  },
63
- "version": "38.15.0",
64
- "gitHead": "fecbe29ae0f1962a04e978cd0e9a96cf60fa4f30"
63
+ "version": "38.15.1",
64
+ "gitHead": "353f67900d1a7019061fa656574f3c5fd7a285c6"
65
65
  }