@wireapp/core 17.20.3 → 17.22.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.
- package/CHANGELOG.md +41 -0
- package/package.json +3 -3
- package/src/main/conversation/ConversationService.d.ts +39 -5
- package/src/main/conversation/ConversationService.js +95 -38
- package/src/main/conversation/ConversationService.js.map +1 -1
- package/src/main/conversation/ConversationService.ts +110 -76
- package/src/main/conversation/message/MessageService.d.ts +19 -3
- package/src/main/conversation/message/MessageService.js +155 -119
- package/src/main/conversation/message/MessageService.js.map +1 -1
- package/src/main/conversation/message/MessageService.test.node.d.ts +1 -0
- package/src/main/conversation/message/MessageService.test.node.js +123 -0
- package/src/main/conversation/message/MessageService.test.node.js.map +1 -0
- package/src/main/conversation/message/MessageService.test.node.ts +163 -0
- package/src/main/conversation/message/MessageService.ts +176 -149
- package/src/main/cryptography/CryptographyService.d.ts +3 -3
- package/src/main/cryptography/CryptographyService.js +14 -11
- package/src/main/cryptography/CryptographyService.js.map +1 -1
- package/src/main/cryptography/CryptographyService.ts +23 -16
- package/src/main/util/TypePredicateUtil.d.ts +1 -0
- package/src/main/util/TypePredicateUtil.js +7 -3
- package/src/main/util/TypePredicateUtil.js.map +1 -1
- package/src/main/util/TypePredicateUtil.test.node.d.ts +1 -0
- package/src/main/util/TypePredicateUtil.test.node.js +42 -0
- package/src/main/util/TypePredicateUtil.test.node.js.map +1 -0
- package/src/main/util/TypePredicateUtil.test.node.ts +44 -0
- package/src/main/util/TypePredicateUtil.ts +6 -2
|
@@ -28,6 +28,7 @@ const protocol_messaging_1 = require("@wireapp/protocol-messaging");
|
|
|
28
28
|
const bazinga64_1 = require("bazinga64");
|
|
29
29
|
const logdown_1 = __importDefault(require("logdown"));
|
|
30
30
|
const conversation_1 = require("../conversation");
|
|
31
|
+
const util_1 = require("../util");
|
|
31
32
|
const CryptographyDatabaseRepository_1 = require("./CryptographyDatabaseRepository");
|
|
32
33
|
const GenericMessageMapper_1 = require("./GenericMessageMapper");
|
|
33
34
|
class CryptographyService {
|
|
@@ -92,31 +93,33 @@ class CryptographyService {
|
|
|
92
93
|
}
|
|
93
94
|
return qualifiedOTRRecipients;
|
|
94
95
|
}
|
|
95
|
-
async encrypt(plainText,
|
|
96
|
-
const recipients = {};
|
|
96
|
+
async encrypt(plainText, users, domain) {
|
|
97
97
|
const bundles = [];
|
|
98
|
-
for (const userId in
|
|
99
|
-
|
|
100
|
-
for (const clientId
|
|
101
|
-
const
|
|
98
|
+
for (const userId in users) {
|
|
99
|
+
const clientIds = (0, util_1.isUserClients)(users) ? users[userId] : Object.keys(users[userId]);
|
|
100
|
+
for (const clientId of clientIds) {
|
|
101
|
+
const base64PreKey = (0, util_1.isUserClients)(users) ? undefined : users[userId][clientId].key;
|
|
102
102
|
const sessionId = CryptographyService.constructSessionId(userId, clientId, domain || null);
|
|
103
103
|
bundles.push(this.encryptPayloadForSession(sessionId, plainText, base64PreKey));
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
const payloads = await Promise.all(bundles);
|
|
107
|
-
payloads.
|
|
107
|
+
return payloads.reduce((recipients, payload) => {
|
|
108
108
|
const { encryptedPayload, sessionId } = payload;
|
|
109
109
|
const { userId, clientId } = CryptographyService.dismantleSessionId(sessionId);
|
|
110
|
+
recipients[userId] || (recipients[userId] = {});
|
|
110
111
|
recipients[userId][clientId] = encryptedPayload;
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
return recipients;
|
|
113
|
+
}, {});
|
|
113
114
|
}
|
|
114
115
|
async encryptPayloadForSession(sessionId, plainText, base64EncodedPreKey) {
|
|
115
116
|
this.logger.log(`Encrypting payload for session ID "${sessionId}"`);
|
|
116
117
|
let encryptedPayload;
|
|
117
118
|
try {
|
|
118
|
-
const decodedPreKeyBundle =
|
|
119
|
-
|
|
119
|
+
const decodedPreKeyBundle = base64EncodedPreKey
|
|
120
|
+
? bazinga64_1.Decoder.fromBase64(base64EncodedPreKey).asBytes.buffer
|
|
121
|
+
: undefined;
|
|
122
|
+
const payloadAsArrayBuffer = await this.cryptobox.encrypt(sessionId, plainText, decodedPreKeyBundle);
|
|
120
123
|
encryptedPayload = new Uint8Array(payloadAsArrayBuffer);
|
|
121
124
|
}
|
|
122
125
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CryptographyService.js","sourceRoot":"","sources":["CryptographyService.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;
|
|
1
|
+
{"version":3,"file":"CryptographyService.js","sourceRoot":"","sources":["CryptographyService.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;AAcH,kDAA6C;AAC7C,8CAAqD;AACrD,oEAA2D;AAE3D,yCAA2C;AAC3C,sDAA8B;AAE9B,kDAAuF;AAEvF,kCAAsC;AACtC,qFAAgF;AAChF,iEAA4D;AAS5D,MAAa,mBAAmB;IAM9B,YAAqB,SAAoB,EAAmB,WAAuB;QAA9D,cAAS,GAAT,SAAS,CAAW;QAAmB,gBAAW,GAAX,WAAW,CAAY;QACjF,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACjD,IAAI,CAAC,QAAQ,GAAG,IAAI,+DAA8B,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACrE,IAAI,CAAC,MAAM,GAAG,IAAA,iBAAO,EAAC,gDAAgD,EAAE;YACtE,MAAM,EAAE,OAAO;YACf,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;IACL,CAAC;IAEM,MAAM,CAAC,kBAAkB,CAAC,MAAc,EAAE,QAAgB,EAAE,MAAqB;QACtF,MAAM,MAAM,GAAG,GAAG,MAAM,IAAI,QAAQ,EAAE,CAAC;QACvC,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;IACjD,CAAC;IAEM,MAAM,CAAC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20,7 +20,13 @@
|
|
|
20
20
|
import type {APIClient} from '@wireapp/api-client';
|
|
21
21
|
import type {PreKey as SerializedPreKey} from '@wireapp/api-client/src/auth/';
|
|
22
22
|
import type {RegisteredClient} from '@wireapp/api-client/src/client/';
|
|
23
|
-
import type {
|
|
23
|
+
import type {
|
|
24
|
+
OTRClientMap,
|
|
25
|
+
OTRRecipients,
|
|
26
|
+
QualifiedOTRRecipients,
|
|
27
|
+
QualifiedUserClients,
|
|
28
|
+
UserClients,
|
|
29
|
+
} from '@wireapp/api-client/src/conversation/';
|
|
24
30
|
import type {ConversationOtrMessageAddEvent} from '@wireapp/api-client/src/event';
|
|
25
31
|
import type {QualifiedUserPreKeyBundleMap, UserPreKeyBundleMap} from '@wireapp/api-client/src/user/';
|
|
26
32
|
import {Cryptobox} from '@wireapp/cryptobox';
|
|
@@ -32,6 +38,7 @@ import logdown from 'logdown';
|
|
|
32
38
|
|
|
33
39
|
import {GenericMessageType, PayloadBundle, PayloadBundleSource} from '../conversation';
|
|
34
40
|
import type {SessionPayloadBundle} from '../cryptography/';
|
|
41
|
+
import {isUserClients} from '../util';
|
|
35
42
|
import {CryptographyDatabaseRepository} from './CryptographyDatabaseRepository';
|
|
36
43
|
import {GenericMessageMapper} from './GenericMessageMapper';
|
|
37
44
|
|
|
@@ -118,7 +125,7 @@ export class CryptographyService {
|
|
|
118
125
|
|
|
119
126
|
public async encryptQualified(
|
|
120
127
|
plainText: Uint8Array,
|
|
121
|
-
preKeyBundles: QualifiedUserPreKeyBundleMap,
|
|
128
|
+
preKeyBundles: QualifiedUserPreKeyBundleMap | QualifiedUserClients,
|
|
122
129
|
): Promise<QualifiedOTRRecipients> {
|
|
123
130
|
const qualifiedOTRRecipients: QualifiedOTRRecipients = {};
|
|
124
131
|
|
|
@@ -131,17 +138,15 @@ export class CryptographyService {
|
|
|
131
138
|
|
|
132
139
|
public async encrypt(
|
|
133
140
|
plainText: Uint8Array,
|
|
134
|
-
|
|
141
|
+
users: UserPreKeyBundleMap | UserClients,
|
|
135
142
|
domain?: string,
|
|
136
143
|
): Promise<OTRRecipients<Uint8Array>> {
|
|
137
|
-
const recipients: OTRRecipients<Uint8Array> = {};
|
|
138
144
|
const bundles: Promise<SessionPayloadBundle>[] = [];
|
|
139
145
|
|
|
140
|
-
for (const userId in
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const {key: base64PreKey} = preKeyBundles[userId][clientId];
|
|
146
|
+
for (const userId in users) {
|
|
147
|
+
const clientIds = isUserClients(users) ? users[userId] : Object.keys(users[userId]);
|
|
148
|
+
for (const clientId of clientIds) {
|
|
149
|
+
const base64PreKey = isUserClients(users) ? undefined : users[userId][clientId].key;
|
|
145
150
|
const sessionId = CryptographyService.constructSessionId(userId, clientId, domain || null);
|
|
146
151
|
bundles.push(this.encryptPayloadForSession(sessionId, plainText, base64PreKey));
|
|
147
152
|
}
|
|
@@ -149,27 +154,29 @@ export class CryptographyService {
|
|
|
149
154
|
|
|
150
155
|
const payloads = await Promise.all(bundles);
|
|
151
156
|
|
|
152
|
-
payloads.
|
|
157
|
+
return payloads.reduce((recipients, payload) => {
|
|
153
158
|
const {encryptedPayload, sessionId} = payload;
|
|
154
159
|
const {userId, clientId} = CryptographyService.dismantleSessionId(sessionId);
|
|
160
|
+
recipients[userId] ||= {};
|
|
155
161
|
recipients[userId][clientId] = encryptedPayload;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return recipients;
|
|
162
|
+
return recipients;
|
|
163
|
+
}, {} as OTRRecipients<Uint8Array>);
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
private async encryptPayloadForSession(
|
|
162
167
|
sessionId: string,
|
|
163
168
|
plainText: Uint8Array,
|
|
164
|
-
base64EncodedPreKey
|
|
169
|
+
base64EncodedPreKey?: string,
|
|
165
170
|
): Promise<SessionPayloadBundle> {
|
|
166
171
|
this.logger.log(`Encrypting payload for session ID "${sessionId}"`);
|
|
167
172
|
|
|
168
173
|
let encryptedPayload: Uint8Array;
|
|
169
174
|
|
|
170
175
|
try {
|
|
171
|
-
const decodedPreKeyBundle =
|
|
172
|
-
|
|
176
|
+
const decodedPreKeyBundle = base64EncodedPreKey
|
|
177
|
+
? Decoder.fromBase64(base64EncodedPreKey).asBytes.buffer
|
|
178
|
+
: undefined;
|
|
179
|
+
const payloadAsArrayBuffer = await this.cryptobox.encrypt(sessionId, plainText, decodedPreKeyBundle);
|
|
173
180
|
encryptedPayload = new Uint8Array(payloadAsArrayBuffer);
|
|
174
181
|
} catch (error) {
|
|
175
182
|
this.logger.error(`Could not encrypt payload: ${(error as Error).message}`);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { QualifiedUserClients, UserClients } from '@wireapp/api-client/src/conversation/';
|
|
2
2
|
import type { QualifiedId } from '@wireapp/api-client/src/user/';
|
|
3
3
|
export declare function isStringArray(obj: any): obj is string[];
|
|
4
|
+
export declare function isQualifiedId(obj: any): obj is QualifiedId;
|
|
4
5
|
export declare function isQualifiedIdArray(obj: any): obj is QualifiedId[];
|
|
5
6
|
export declare function isQualifiedUserClients(obj: any): obj is QualifiedUserClients;
|
|
6
7
|
export declare function isUserClients(obj: any): obj is UserClients;
|
|
@@ -18,13 +18,17 @@
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.isUserClients = exports.isQualifiedUserClients = exports.isQualifiedIdArray = exports.isStringArray = void 0;
|
|
21
|
+
exports.isUserClients = exports.isQualifiedUserClients = exports.isQualifiedIdArray = exports.isQualifiedId = exports.isStringArray = void 0;
|
|
22
22
|
function isStringArray(obj) {
|
|
23
23
|
return Array.isArray(obj) && typeof obj[0] === 'string';
|
|
24
24
|
}
|
|
25
25
|
exports.isStringArray = isStringArray;
|
|
26
|
+
function isQualifiedId(obj) {
|
|
27
|
+
return typeof obj === 'object' && typeof obj['domain'] === 'string';
|
|
28
|
+
}
|
|
29
|
+
exports.isQualifiedId = isQualifiedId;
|
|
26
30
|
function isQualifiedIdArray(obj) {
|
|
27
|
-
return Array.isArray(obj) &&
|
|
31
|
+
return Array.isArray(obj) && isQualifiedId(obj[0]);
|
|
28
32
|
}
|
|
29
33
|
exports.isQualifiedIdArray = isQualifiedIdArray;
|
|
30
34
|
function isQualifiedUserClients(obj) {
|
|
@@ -35,7 +39,7 @@ function isQualifiedUserClients(obj) {
|
|
|
35
39
|
const firstClientIdArray = Object.values(firstUserClientObject)[0];
|
|
36
40
|
if (Array.isArray(firstClientIdArray)) {
|
|
37
41
|
const firstClientId = firstClientIdArray[0];
|
|
38
|
-
return typeof firstClientId === 'string';
|
|
42
|
+
return typeof firstClientId === 'string' || typeof firstClientId === 'undefined';
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypePredicateUtil.js","sourceRoot":"","sources":["TypePredicateUtil.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAKH,SAAgB,aAAa,CAAC,GAAQ;IACpC,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC;AAC1D,CAAC;AAFD,sCAEC;AAED,SAAgB,
|
|
1
|
+
{"version":3,"file":"TypePredicateUtil.js","sourceRoot":"","sources":["TypePredicateUtil.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAKH,SAAgB,aAAa,CAAC,GAAQ;IACpC,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC;AAC1D,CAAC;AAFD,sCAEC;AAED,SAAgB,aAAa,CAAC,GAAQ;IACpC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,CAAC,QAAQ,CAAC,KAAK,QAAQ,CAAC;AACtE,CAAC;AAFD,sC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* Wire
|
|
4
|
+
* Copyright (C) 2021 Wire Swiss GmbH
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU General Public License as published by
|
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* This program is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU General Public License
|
|
17
|
+
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
const TypePredicateUtil_1 = require("./TypePredicateUtil");
|
|
22
|
+
describe('TypePredicatUtil', () => {
|
|
23
|
+
describe('isQualifiedUserClients', () => {
|
|
24
|
+
it('detects QualifiedUserClients', () => {
|
|
25
|
+
const validUserClients = [
|
|
26
|
+
{ domain1: { user1: ['client1'] } },
|
|
27
|
+
{ domain1: { user1: [] } }, // When a user has no clients
|
|
28
|
+
];
|
|
29
|
+
validUserClients.forEach(payload => expect((0, TypePredicateUtil_1.isQualifiedUserClients)(payload)).toBeTrue());
|
|
30
|
+
});
|
|
31
|
+
it('rejects non QualifiedUserClients', () => {
|
|
32
|
+
const invalidUserClients = [
|
|
33
|
+
{ domain1: { user1: '' } },
|
|
34
|
+
{ domain1: { user1: {} } },
|
|
35
|
+
{ domain1: [] },
|
|
36
|
+
{ domain1: { user1: [{}] } },
|
|
37
|
+
];
|
|
38
|
+
invalidUserClients.forEach(payload => expect((0, TypePredicateUtil_1.isQualifiedUserClients)(payload)).toBeFalse());
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=Typ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
1
|
+
/*
|
|
2
|
+
* Wire
|
|
3
|
+
* Copyright (C) 2021 Wire Swiss GmbH
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU General Public License
|
|
16
|
+
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import {isQualifiedUserClients} from './TypePredicateUtil';
|
|
21
|
+
|
|
22
|
+
describe('TypePredicatUtil', () => {
|
|
23
|
+
describe('isQualifiedUserClients', () => {
|
|
24
|
+
it('detects QualifiedUserClients', () => {
|
|
25
|
+
const validUserClients = [
|
|
26
|
+
{domain1: {user1: ['client1']}},
|
|
27
|
+
{domain1: {user1: []}}, // When a user has no clients
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
validUserClients.forEach(payload => expect(isQualifiedUserClients(payload)).toBeTrue());
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('rejects non QualifiedUserClients', () => {
|
|
34
|
+
const invalidUserClients = [
|
|
35
|
+
{domain1: {user1: ''}},
|
|
36
|
+
{domain1: {user1: {}}},
|
|
37
|
+
{domain1: []},
|
|
38
|
+
{domain1: {user1: [{}]}},
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
invalidUserClients.forEach(payload => expect(isQualifiedUserClients(payload)).toBeFalse());
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -24,8 +24,12 @@ export function isStringArray(obj: any): obj is string[] {
|
|
|
24
24
|
return Array.isArray(obj) && typeof obj[0] === 'string';
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
export function isQualifiedId(obj: any): obj is QualifiedId {
|
|
28
|
+
return typeof obj === 'object' && typeof obj['domain'] === 'string';
|
|
29
|
+
}
|
|
30
|
+
|
|
27
31
|
export function isQualifiedIdArray(obj: any): obj is QualifiedId[] {
|
|
28
|
-
return Array.isArray(obj) &&
|
|
32
|
+
return Array.isArray(obj) && isQualifiedId(obj[0]);
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
export function isQualifiedUserClients(obj: any): obj is QualifiedUserClients {
|
|
@@ -35,7 +39,7 @@ export function isQualifiedUserClients(obj: any): obj is QualifiedUserClients {
|
|
|
35
39
|
const firstClientIdArray = Object.values(firstUserClientObject as object)[0];
|
|
36
40
|
if (Array.isArray(firstClientIdArray)) {
|
|
37
41
|
const firstClientId = firstClientIdArray[0];
|
|
38
|
-
return typeof firstClientId === 'string';
|
|
42
|
+
return typeof firstClientId === 'string' || typeof firstClientId === 'undefined';
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
}
|