@wireapp/core 38.3.2 → 38.4.0
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.d.ts +1 -1
- package/lib/Account.d.ts.map +1 -1
- package/lib/Account.js +27 -26
- package/lib/client/ClientService.d.ts +2 -2
- package/lib/client/ClientService.d.ts.map +1 -1
- package/lib/conversation/ConversationService/ConversationService.d.ts +3 -2
- package/lib/conversation/ConversationService/ConversationService.d.ts.map +1 -1
- package/lib/conversation/ConversationService/ConversationService.js +8 -2
- package/lib/conversation/ConversationService/ConversationService.test.js +1 -1
- package/lib/messagingProtocols/mls/types.d.ts +1 -0
- package/lib/messagingProtocols/mls/types.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper.d.ts +40 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper.d.ts.map +1 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper.js +98 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.d.ts +12 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.d.ts.map +1 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.js +29 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.d.ts +31 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.d.ts.map +1 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.js +22 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper.d.ts +40 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper.d.ts.map +1 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper.js +108 -0
- package/lib/messagingProtocols/proteus/ProteusService/{PrekeysGenerator/PrekeysGenerator.d.ts → CryptoClient/PrekeysTracker/PrekeysTracker.d.ts} +6 -14
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/PrekeysTracker/PrekeysTracker.d.ts.map +1 -0
- package/lib/messagingProtocols/proteus/ProteusService/{PrekeysGenerator/PrekeysGenerator.js → CryptoClient/PrekeysTracker/PrekeysTracker.js} +9 -23
- package/lib/messagingProtocols/proteus/ProteusService/{PrekeysGenerator/PrekeysGenerator.store.d.ts → CryptoClient/PrekeysTracker/PrekeysTracker.store.d.ts} +3 -3
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/PrekeysTracker/PrekeysTracker.store.d.ts.map +1 -0
- package/lib/messagingProtocols/proteus/ProteusService/{PrekeysGenerator/PrekeysGenerator.store.js → CryptoClient/PrekeysTracker/PrekeysTracker.store.js} +3 -3
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/PrekeysTracker/PrekeysTracker.test.d.ts +2 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/PrekeysTracker/PrekeysTracker.test.d.ts.map +1 -0
- package/lib/messagingProtocols/proteus/ProteusService/{PrekeysGenerator/PrekeysGenerator.test.js → CryptoClient/PrekeysTracker/PrekeysTracker.test.js} +11 -17
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/PrekeysTracker/index.d.ts +2 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/PrekeysTracker/index.d.ts.map +1 -0
- package/lib/messagingProtocols/proteus/ProteusService/{PrekeysGenerator → CryptoClient/PrekeysTracker}/index.js +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/index.d.ts +3 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/index.d.ts.map +1 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/index.js +36 -0
- package/lib/messagingProtocols/proteus/ProteusService/DecryptionErrorGenerator/DecryptionErrorGenerator.js +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts +5 -6
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.js +39 -60
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.test.js +3 -3
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.types.d.ts +0 -4
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.types.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/cryptoMigrationStateStore.d.ts +11 -0
- package/lib/messagingProtocols/proteus/ProteusService/cryptoMigrationStateStore.d.ts.map +1 -0
- package/lib/messagingProtocols/proteus/ProteusService/cryptoMigrationStateStore.js +53 -0
- package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts +7 -7
- package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.js +22 -22
- package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.test.js +4 -3
- package/lib/notification/NotificationService.d.ts +2 -2
- package/lib/notification/NotificationService.d.ts.map +1 -1
- package/lib/notification/NotificationService.js +5 -5
- package/lib/notification/NotificationService.test.js +4 -4
- package/lib/util/encryptedStore.js +1 -1
- package/package.json +5 -4
- package/lib/messagingProtocols/proteus/ProteusService/PrekeysGenerator/PrekeysGenerator.d.ts.map +0 -1
- package/lib/messagingProtocols/proteus/ProteusService/PrekeysGenerator/PrekeysGenerator.store.d.ts.map +0 -1
- package/lib/messagingProtocols/proteus/ProteusService/PrekeysGenerator/PrekeysGenerator.test.d.ts +0 -2
- package/lib/messagingProtocols/proteus/ProteusService/PrekeysGenerator/PrekeysGenerator.test.d.ts.map +0 -1
- package/lib/messagingProtocols/proteus/ProteusService/PrekeysGenerator/index.d.ts +0 -2
- package/lib/messagingProtocols/proteus/ProteusService/PrekeysGenerator/index.d.ts.map +0 -1
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Wire
|
|
4
|
+
* Copyright (C) 2023 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
|
+
exports.CryptoboxWrapper = void 0;
|
|
22
|
+
const cryptobox_1 = require("@wireapp/cryptobox");
|
|
23
|
+
const CryptoClient_types_1 = require("./CryptoClient.types");
|
|
24
|
+
class CryptoboxWrapper {
|
|
25
|
+
constructor(cryptobox, config) {
|
|
26
|
+
this.cryptobox = cryptobox;
|
|
27
|
+
this.cryptobox.on(cryptobox_1.Cryptobox.TOPIC.NEW_PREKEYS, prekeys => {
|
|
28
|
+
const serializedPreKeys = prekeys.map(prekey => this.cryptobox.serialize_prekey(prekey));
|
|
29
|
+
config.onNewPrekeys(serializedPreKeys);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async encrypt(sessions, plainText) {
|
|
33
|
+
const encryptedPayloads = [];
|
|
34
|
+
for (const sessionId of sessions) {
|
|
35
|
+
const encrypted = await this.cryptobox.encrypt(sessionId, plainText);
|
|
36
|
+
encryptedPayloads.push([sessionId, new Uint8Array(encrypted)]);
|
|
37
|
+
}
|
|
38
|
+
return new Map(encryptedPayloads);
|
|
39
|
+
}
|
|
40
|
+
decrypt(sessionId, message) {
|
|
41
|
+
return this.cryptobox.decrypt(sessionId, message.buffer);
|
|
42
|
+
}
|
|
43
|
+
async init() {
|
|
44
|
+
await this.cryptobox.load();
|
|
45
|
+
}
|
|
46
|
+
async create(_nbPrekeys, entropy) {
|
|
47
|
+
const initialPrekeys = await this.cryptobox.create(entropy);
|
|
48
|
+
const prekeys = initialPrekeys
|
|
49
|
+
.map(preKey => {
|
|
50
|
+
const preKeyJson = this.cryptobox.serialize_prekey(preKey);
|
|
51
|
+
if (preKeyJson.id !== CryptoClient_types_1.LAST_PREKEY_ID) {
|
|
52
|
+
return preKeyJson;
|
|
53
|
+
}
|
|
54
|
+
return { id: -1, key: '' };
|
|
55
|
+
})
|
|
56
|
+
.filter(serializedPreKey => serializedPreKey.key);
|
|
57
|
+
return {
|
|
58
|
+
prekeys,
|
|
59
|
+
lastPrekey: this.cryptobox.serialize_prekey(this.cryptobox.lastResortPreKey),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async getFingerprint() {
|
|
63
|
+
return this.cryptobox.getIdentity().public_key.fingerprint();
|
|
64
|
+
}
|
|
65
|
+
async getRemoteFingerprint(sessionId) {
|
|
66
|
+
const session = await this.cryptobox.session_load(sessionId);
|
|
67
|
+
return session.fingerprint_remote();
|
|
68
|
+
}
|
|
69
|
+
sessionFromMessage(sessionId, message) {
|
|
70
|
+
return this.decrypt(sessionId, message);
|
|
71
|
+
}
|
|
72
|
+
async consumePrekey() {
|
|
73
|
+
// Cryptobox is keeping track of consumed prekeys internally
|
|
74
|
+
}
|
|
75
|
+
async sessionFromPrekey(sessionId, prekey) {
|
|
76
|
+
return void (await this.cryptobox.session_from_prekey(sessionId, prekey.buffer));
|
|
77
|
+
}
|
|
78
|
+
async sessionExists(sessionId) {
|
|
79
|
+
try {
|
|
80
|
+
return !!(await this.cryptobox.session_load(sessionId));
|
|
81
|
+
}
|
|
82
|
+
catch (_a) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async saveSession() {
|
|
87
|
+
// Cryptobox saves sessions automatically
|
|
88
|
+
}
|
|
89
|
+
async deleteSession(sessionId) {
|
|
90
|
+
await this.cryptobox.session_delete(sessionId);
|
|
91
|
+
}
|
|
92
|
+
async newPrekey(id) {
|
|
93
|
+
// CryptoBox is generating prekeys internally
|
|
94
|
+
return { id, key: '' };
|
|
95
|
+
}
|
|
96
|
+
async debugBreakSession(sessionId) {
|
|
97
|
+
const session = await this.cryptobox.session_load(sessionId);
|
|
98
|
+
session.session.session_states = {};
|
|
99
|
+
this.cryptobox['cachedSessions'].set(sessionId, session);
|
|
100
|
+
}
|
|
101
|
+
async migrateToCoreCrypto() {
|
|
102
|
+
// No migration needed for cryptobox
|
|
103
|
+
}
|
|
104
|
+
get isCoreCrypto() {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.CryptoboxWrapper = CryptoboxWrapper;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { PreKey } from '@wireapp/api-client/lib/auth';
|
|
2
|
-
import {
|
|
3
|
-
import type { CoreDatabase } from '
|
|
4
|
-
|
|
5
|
-
type CoreCryptoPrekeyGenerator = Pick<CoreCrypto, 'proteusNewPrekey'>;
|
|
2
|
+
import { CryptoClient } from '..';
|
|
3
|
+
import type { CoreDatabase } from '../../../../../storage/CoreDB';
|
|
4
|
+
type CoreCryptoPrekeyGenerator = Pick<CryptoClient, 'newPrekey'>;
|
|
6
5
|
interface PrekeysGeneratorConfig {
|
|
7
6
|
/**
|
|
8
7
|
* The number of prekeys that will be generated for a new device and refilled when the low threshold is hit
|
|
@@ -14,22 +13,15 @@ interface PrekeysGeneratorConfig {
|
|
|
14
13
|
*/
|
|
15
14
|
onNewPrekeys: (prekeys: PreKey[]) => void;
|
|
16
15
|
}
|
|
17
|
-
export declare
|
|
18
|
-
export declare class PrekeyGenerator {
|
|
16
|
+
export declare class PrekeyTracker {
|
|
19
17
|
private readonly generator;
|
|
20
18
|
private config;
|
|
21
19
|
private prekeyState;
|
|
22
20
|
constructor(generator: CoreCryptoPrekeyGenerator, db: CoreDatabase, config: PrekeysGeneratorConfig);
|
|
23
|
-
private generatePrekey;
|
|
24
21
|
private generatePrekeys;
|
|
25
22
|
consumePrekey(): Promise<void>;
|
|
23
|
+
setInitialState(nbInitialPrekeys: number): Promise<void>;
|
|
26
24
|
private numberOfMissingPrekeys;
|
|
27
|
-
/**
|
|
28
|
-
* Will generate the initial set of prekeys for a new device
|
|
29
|
-
* @param nbPrekeys the number of prekeys to generate
|
|
30
|
-
* @param generator the class that will be used to generate a single prekey
|
|
31
|
-
*/
|
|
32
|
-
generateInitialPrekeys(): Promise<NewDevicePrekeys>;
|
|
33
25
|
}
|
|
34
26
|
export {};
|
|
35
|
-
//# sourceMappingURL=
|
|
27
|
+
//# sourceMappingURL=PrekeysTracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrekeysTracker.d.ts","sourceRoot":"","sources":["../../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/PrekeysTracker/PrekeysTracker.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AAIpD,OAAO,EAAC,YAAY,EAAC,MAAM,IAAI,CAAC;AAChC,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,+BAA+B,CAAC;AAEhE,KAAK,yBAAyB,GAAG,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;AAEjE,UAAU,sBAAsB;IAC9B;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAC3C;AAED,qBAAa,aAAa;IAItB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAE1B,OAAO,CAAC,MAAM;IALhB,OAAO,CAAC,WAAW,CAAsB;gBAGtB,SAAS,EAAE,yBAAyB,EACrD,EAAE,EAAE,YAAY,EACR,MAAM,EAAE,sBAAsB;YAK1B,eAAe;IASvB,aAAa;IAUb,eAAe,CAAC,gBAAgB,EAAE,MAAM;IAI9C,OAAO,CAAC,sBAAsB;CAK/B"}
|
|
@@ -18,25 +18,19 @@
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
exports.LAST_PREKEY_ID = 65535;
|
|
25
|
-
class PrekeyGenerator {
|
|
21
|
+
exports.PrekeyTracker = void 0;
|
|
22
|
+
const PrekeysTracker_store_1 = require("./PrekeysTracker.store");
|
|
23
|
+
class PrekeyTracker {
|
|
26
24
|
constructor(generator, db, config) {
|
|
27
25
|
this.generator = generator;
|
|
28
26
|
this.config = config;
|
|
29
|
-
this.prekeyState = new
|
|
30
|
-
}
|
|
31
|
-
async generatePrekey(id) {
|
|
32
|
-
const key = await this.generator.proteusNewPrekey(id);
|
|
33
|
-
return { id, key: bazinga64_1.Encoder.toBase64(key).asString };
|
|
27
|
+
this.prekeyState = new PrekeysTracker_store_1.PrekeysTrackerStore(db);
|
|
34
28
|
}
|
|
35
29
|
async generatePrekeys(nb) {
|
|
36
30
|
const prekeys = [];
|
|
37
31
|
const ids = await this.prekeyState.createIds(nb);
|
|
38
32
|
for (const id of ids) {
|
|
39
|
-
prekeys.push(await this.
|
|
33
|
+
prekeys.push(await this.generator.newPrekey(id));
|
|
40
34
|
}
|
|
41
35
|
return prekeys;
|
|
42
36
|
}
|
|
@@ -49,21 +43,13 @@ class PrekeyGenerator {
|
|
|
49
43
|
this.config.onNewPrekeys(newPrekeys);
|
|
50
44
|
}
|
|
51
45
|
}
|
|
46
|
+
async setInitialState(nbInitialPrekeys) {
|
|
47
|
+
await this.prekeyState.createIds(nbInitialPrekeys);
|
|
48
|
+
}
|
|
52
49
|
numberOfMissingPrekeys(currentNumberOfPrekeys) {
|
|
53
50
|
const threshold = Math.ceil(this.config.nbPrekeys / 2);
|
|
54
51
|
const hasHitThreshold = currentNumberOfPrekeys <= threshold;
|
|
55
52
|
return hasHitThreshold ? this.config.nbPrekeys - currentNumberOfPrekeys : 0;
|
|
56
53
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Will generate the initial set of prekeys for a new device
|
|
59
|
-
* @param nbPrekeys the number of prekeys to generate
|
|
60
|
-
* @param generator the class that will be used to generate a single prekey
|
|
61
|
-
*/
|
|
62
|
-
async generateInitialPrekeys() {
|
|
63
|
-
return {
|
|
64
|
-
prekeys: await this.generatePrekeys(this.config.nbPrekeys),
|
|
65
|
-
lastPrekey: await this.generatePrekey(exports.LAST_PREKEY_ID),
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
54
|
}
|
|
69
|
-
exports.
|
|
55
|
+
exports.PrekeyTracker = PrekeyTracker;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CoreDatabase } from '
|
|
2
|
-
export declare class
|
|
1
|
+
import { CoreDatabase } from '../../../../../storage/CoreDB';
|
|
2
|
+
export declare class PrekeysTrackerStore {
|
|
3
3
|
private readonly db;
|
|
4
4
|
constructor(db: CoreDatabase);
|
|
5
5
|
private getState;
|
|
@@ -16,4 +16,4 @@ export declare class PrekeysGeneratorStore {
|
|
|
16
16
|
*/
|
|
17
17
|
createIds(nbIds: number): Promise<number[]>;
|
|
18
18
|
}
|
|
19
|
-
//# sourceMappingURL=
|
|
19
|
+
//# sourceMappingURL=PrekeysTracker.store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrekeysTracker.store.d.ts","sourceRoot":"","sources":["../../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/PrekeysTracker/PrekeysTracker.store.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,YAAY,EAAC,MAAM,+BAA+B,CAAC;AAQ3D,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,YAAY;YAE/B,QAAQ;YAIR,SAAS;IAIvB;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAOhC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAK3C;;;OAGG;IACG,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAMlD"}
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.
|
|
21
|
+
exports.PrekeysTrackerStore = void 0;
|
|
22
22
|
const STATE_PRIMARY_KEY = 'prekeys_state';
|
|
23
|
-
class
|
|
23
|
+
class PrekeysTrackerStore {
|
|
24
24
|
constructor(db) {
|
|
25
25
|
this.db = db;
|
|
26
26
|
}
|
|
@@ -55,4 +55,4 @@ class PrekeysGeneratorStore {
|
|
|
55
55
|
return Array.from(new Array(nbIds)).map((_, i) => currentState.highestId + 1 + i);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
exports.
|
|
58
|
+
exports.PrekeysTrackerStore = PrekeysTrackerStore;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrekeysTracker.test.d.ts","sourceRoot":"","sources":["../../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/PrekeysTracker/PrekeysTracker.test.ts"],"names":[],"mappings":""}
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
const
|
|
22
|
-
const CoreDB_1 = require("
|
|
21
|
+
const PrekeysTracker_1 = require("./PrekeysTracker");
|
|
22
|
+
const CoreDB_1 = require("../../../../../storage/CoreDB");
|
|
23
23
|
describe('PrekeysGenerator', () => {
|
|
24
24
|
let db;
|
|
25
25
|
const baseConfig = {
|
|
26
26
|
nbPrekeys: 10,
|
|
27
27
|
onNewPrekeys: jest.fn(),
|
|
28
28
|
};
|
|
29
|
-
const
|
|
30
|
-
|
|
29
|
+
const mockPrekeyTracker = {
|
|
30
|
+
newPrekey: jest.fn().mockResolvedValue(Uint8Array.from([])),
|
|
31
31
|
};
|
|
32
32
|
beforeEach(async () => {
|
|
33
33
|
db = await (0, CoreDB_1.openDB)('test');
|
|
@@ -35,22 +35,16 @@ describe('PrekeysGenerator', () => {
|
|
|
35
35
|
afterEach(async () => {
|
|
36
36
|
await db.clear('prekeys');
|
|
37
37
|
});
|
|
38
|
-
it('generates initial device prekeys', async () => {
|
|
39
|
-
const prekeyGenerator = new PrekeysGenerator_1.PrekeyGenerator(mockPrekeyGenerator, db, baseConfig);
|
|
40
|
-
const { prekeys, lastPrekey } = await prekeyGenerator.generateInitialPrekeys();
|
|
41
|
-
expect(prekeys).toHaveLength(baseConfig.nbPrekeys);
|
|
42
|
-
expect(lastPrekey.id).toBe(PrekeysGenerator_1.LAST_PREKEY_ID);
|
|
43
|
-
});
|
|
44
38
|
it('triggers the threshold callback when number of prekeys hits the limit', async () => {
|
|
45
|
-
const
|
|
46
|
-
await
|
|
39
|
+
const prekeyTracker = new PrekeysTracker_1.PrekeyTracker(mockPrekeyTracker, db, baseConfig);
|
|
40
|
+
await prekeyTracker.setInitialState(baseConfig.nbPrekeys);
|
|
47
41
|
expect(baseConfig.onNewPrekeys).not.toHaveBeenCalled();
|
|
48
|
-
await
|
|
49
|
-
await
|
|
50
|
-
await
|
|
51
|
-
await
|
|
42
|
+
await prekeyTracker.consumePrekey();
|
|
43
|
+
await prekeyTracker.consumePrekey();
|
|
44
|
+
await prekeyTracker.consumePrekey();
|
|
45
|
+
await prekeyTracker.consumePrekey();
|
|
52
46
|
expect(baseConfig.onNewPrekeys).not.toHaveBeenCalled();
|
|
53
|
-
await
|
|
47
|
+
await prekeyTracker.consumePrekey();
|
|
54
48
|
expect(baseConfig.onNewPrekeys).toHaveBeenCalledTimes(1);
|
|
55
49
|
});
|
|
56
50
|
});
|
package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/PrekeysTracker/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/PrekeysTracker/index.ts"],"names":[],"mappings":"AAmBA,cAAc,kBAAkB,CAAC"}
|
|
@@ -32,4 +32,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
32
32
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
__exportStar(require("./
|
|
35
|
+
__exportStar(require("./PrekeysTracker"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/index.ts"],"names":[],"mappings":"AAmBA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Wire
|
|
4
|
+
* Copyright (C) 2023 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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(o, k2, desc);
|
|
27
|
+
}) : (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
}));
|
|
31
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
32
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
__exportStar(require("./CryptoClient"), exports);
|
|
36
|
+
__exportStar(require("./CryptoClient.types"), exports);
|
|
@@ -57,7 +57,7 @@ const getErrorMessage = (code, userId, clientId, error) => {
|
|
|
57
57
|
};
|
|
58
58
|
const generateDecryptionError = (senderInfo, error) => {
|
|
59
59
|
const { clientId: remoteClientId, userId } = senderInfo;
|
|
60
|
-
const code = mapCoreCryptoError(error);
|
|
60
|
+
const code = error.code || mapCoreCryptoError(error);
|
|
61
61
|
const message = getErrorMessage(code, userId, remoteClientId, error);
|
|
62
62
|
return new DecryptionError_1.DecryptionError(message, code);
|
|
63
63
|
};
|
|
@@ -2,7 +2,8 @@ import type { APIClient } from '@wireapp/api-client/lib/APIClient';
|
|
|
2
2
|
import type { PreKey, Context } from '@wireapp/api-client/lib/auth';
|
|
3
3
|
import type { Conversation, OTRRecipients, QualifiedOTRRecipients, QualifiedUserClients, UserClients } from '@wireapp/api-client/lib/conversation';
|
|
4
4
|
import type { QualifiedId, QualifiedUserPreKeyBundleMap, UserPreKeyBundleMap } from '@wireapp/api-client/lib/user';
|
|
5
|
-
import
|
|
5
|
+
import { CoreCrypto } from '@wireapp/core-crypto';
|
|
6
|
+
import { Cryptobox } from '@wireapp/cryptobox';
|
|
6
7
|
import { CRUDEngine } from '@wireapp/store-engine';
|
|
7
8
|
import type { AddUsersToProteusConversationParams, CreateProteusConversationParams, ProteusServiceConfig, SendProteusMessageParams } from './ProteusService.types';
|
|
8
9
|
import { SendResult } from '../../../conversation';
|
|
@@ -11,15 +12,14 @@ import type { EventHandlerResult } from '../../common.types';
|
|
|
11
12
|
import { EventHandlerParams } from '../EventHandler';
|
|
12
13
|
export declare class ProteusService {
|
|
13
14
|
private readonly apiClient;
|
|
14
|
-
private readonly coreCryptoClient;
|
|
15
15
|
private readonly config;
|
|
16
16
|
private readonly messageService;
|
|
17
17
|
private readonly logger;
|
|
18
|
-
private readonly
|
|
19
|
-
constructor(apiClient: APIClient,
|
|
18
|
+
private readonly cryptoClient;
|
|
19
|
+
constructor(apiClient: APIClient, cryptoClient: CoreCrypto | Cryptobox, db: CoreDatabase, config: ProteusServiceConfig);
|
|
20
20
|
handleEvent(params: Pick<EventHandlerParams, 'event' | 'source' | 'dryRun'>): EventHandlerResult;
|
|
21
21
|
initClient(storeEngine: CRUDEngine, context: Context): Promise<void>;
|
|
22
|
-
createClient(): Promise<import("./
|
|
22
|
+
createClient(entropy?: Uint8Array): Promise<import("./CryptoClient").InitialPrekeys>;
|
|
23
23
|
/**
|
|
24
24
|
* Get the fingerprint of the local client.
|
|
25
25
|
*/
|
|
@@ -40,6 +40,5 @@ export declare class ProteusService {
|
|
|
40
40
|
encrypt(plainText: Uint8Array, recipients: UserPreKeyBundleMap | UserClients, domain?: string): Promise<OTRRecipients<Uint8Array>>;
|
|
41
41
|
deleteSession(userId: QualifiedId, clientId: string): Promise<void>;
|
|
42
42
|
encryptQualified(plainText: Uint8Array, preKeyBundles: QualifiedUserPreKeyBundleMap | QualifiedUserClients): Promise<QualifiedOTRRecipients>;
|
|
43
|
-
private migrateToCoreCrypto;
|
|
44
43
|
}
|
|
45
44
|
//# 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;AAGjH,OAAO,
|
|
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;AAGjH,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAKjD,OAAO,KAAK,EACV,mCAAmC,EACnC,+BAA+B,EAC/B,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAA0C,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAE1F,OAAO,EAAC,YAAY,EAAC,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAC,kBAAkB,EAAqB,MAAM,iBAAiB,CAAC;AAWvE,qBAAa,cAAc;IAMvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAG1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IARzB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2C;IAClE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;gBAGzB,SAAS,EAAE,SAAS,EACrC,YAAY,EAAE,UAAU,GAAG,SAAS,EACpC,EAAE,EAAE,YAAY,EACC,MAAM,EAAE,oBAAoB;IAMlC,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC,GAAG,kBAAkB;IAiBhG,UAAU,CAAC,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO;IA0B1D,YAAY,CAAC,OAAO,CAAC,EAAE,UAAU;IAIxC;;OAEG;IACI,mBAAmB;IAInB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;IAIlG;;;;;;OAMG;IACU,oBAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAQ3E,kBAAkB,CAAC,EAC9B,gBAAgB,EAChB,YAAY,GACb,EAAE,+BAA+B,GAAG,OAAO,CAAC,YAAY,CAAC;IAiB7C,sBAAsB,CAAC,EAAC,cAAc,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;YA2CnC,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;CAUnC"}
|
|
@@ -24,8 +24,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
24
24
|
exports.ProteusService = void 0;
|
|
25
25
|
const logdown_1 = __importDefault(require("logdown"));
|
|
26
26
|
const protocol_messaging_1 = require("@wireapp/protocol-messaging");
|
|
27
|
+
const CryptoClient_1 = require("./CryptoClient");
|
|
28
|
+
const cryptoMigrationStateStore_1 = require("./cryptoMigrationStateStore");
|
|
27
29
|
const DecryptionErrorGenerator_1 = require("./DecryptionErrorGenerator");
|
|
28
|
-
const PrekeysGenerator_1 = require("./PrekeysGenerator");
|
|
29
30
|
const sessionIdMigrator_1 = require("./sessionIdMigrator");
|
|
30
31
|
const conversation_1 = require("../../../conversation");
|
|
31
32
|
const MessageService_1 = require("../../../conversation/message/MessageService");
|
|
@@ -33,25 +34,13 @@ const EventHandler_1 = require("../EventHandler");
|
|
|
33
34
|
const getGenericMessageParams_1 = require("../Utility/getGenericMessageParams");
|
|
34
35
|
const isClearFromMismatch_1 = require("../Utility/isClearFromMismatch");
|
|
35
36
|
const SessionHandler_1 = require("../Utility/SessionHandler");
|
|
36
|
-
function getLocalStorage() {
|
|
37
|
-
try {
|
|
38
|
-
return window.localStorage;
|
|
39
|
-
}
|
|
40
|
-
catch (_a) {
|
|
41
|
-
return { setItem: () => { }, getItem: () => { }, removeItem: () => { } };
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
37
|
class ProteusService {
|
|
45
|
-
constructor(apiClient,
|
|
38
|
+
constructor(apiClient, cryptoClient, db, config) {
|
|
46
39
|
this.apiClient = apiClient;
|
|
47
|
-
this.coreCryptoClient = coreCryptoClient;
|
|
48
40
|
this.config = config;
|
|
49
41
|
this.logger = (0, logdown_1.default)('@wireapp/core/ProteusService');
|
|
50
42
|
this.messageService = new MessageService_1.MessageService(this.apiClient, this);
|
|
51
|
-
this.
|
|
52
|
-
nbPrekeys: config.nbPrekeys,
|
|
53
|
-
onNewPrekeys: config.onNewPrekeys,
|
|
54
|
-
});
|
|
43
|
+
this.cryptoClient = (0, CryptoClient_1.wrapCryptoClient)(cryptoClient, db, config);
|
|
55
44
|
}
|
|
56
45
|
async handleEvent(params) {
|
|
57
46
|
const handledEvent = await (0, EventHandler_1.handleBackendEvent)(Object.assign(Object.assign({}, params), { decryptMessage: (payload, userId, clientId) => this.decrypt(payload, userId, clientId) }));
|
|
@@ -60,23 +49,43 @@ class ProteusService {
|
|
|
60
49
|
if (isSessionReset) {
|
|
61
50
|
this.logger.debug('A session was reset from a remote device');
|
|
62
51
|
// If a session reset message was received, we need to count a consumed prekey (because the sender has created a new session from a new prekey)
|
|
63
|
-
await this.
|
|
52
|
+
await this.cryptoClient.consumePrekey();
|
|
64
53
|
}
|
|
65
54
|
}
|
|
66
55
|
return handledEvent;
|
|
67
56
|
}
|
|
68
57
|
async initClient(storeEngine, context) {
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
const dbName = storeEngine.storeName;
|
|
59
|
+
if (context.domain && this.config.useQualifiedIds) {
|
|
60
|
+
// We want sessions to be fully qualified from now on
|
|
61
|
+
if (!cryptoMigrationStateStore_1.cryptoMigrationStore.qualifiedSessions.isReady(dbName)) {
|
|
62
|
+
this.logger.info(`Migrating existing session ids to qualified ids.`);
|
|
63
|
+
await (0, sessionIdMigrator_1.migrateToQualifiedSessionIds)(storeEngine, context.domain);
|
|
64
|
+
cryptoMigrationStateStore_1.cryptoMigrationStore.qualifiedSessions.markAsReady(dbName);
|
|
65
|
+
this.logger.info(`Successfully migrated session ids to qualified ids.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!cryptoMigrationStateStore_1.cryptoMigrationStore.coreCrypto.isReady(dbName) && this.cryptoClient.isCoreCrypto) {
|
|
69
|
+
this.logger.info(`Migrating data from cryptobox store (${dbName}) to corecrypto.`);
|
|
70
|
+
try {
|
|
71
|
+
await this.cryptoClient.migrateToCoreCrypto(dbName);
|
|
72
|
+
cryptoMigrationStateStore_1.cryptoMigrationStore.coreCrypto.markAsReady(dbName);
|
|
73
|
+
this.logger.info(`Successfully migrated from cryptobox store (${dbName}) to corecrypto.`);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
this.logger.error('Client was not able to perform DB migration: ', error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return this.cryptoClient.init();
|
|
71
80
|
}
|
|
72
|
-
createClient() {
|
|
73
|
-
return this.
|
|
81
|
+
createClient(entropy) {
|
|
82
|
+
return this.cryptoClient.create(this.config.nbPrekeys, entropy);
|
|
74
83
|
}
|
|
75
84
|
/**
|
|
76
85
|
* Get the fingerprint of the local client.
|
|
77
86
|
*/
|
|
78
87
|
getLocalFingerprint() {
|
|
79
|
-
return this.
|
|
88
|
+
return this.cryptoClient.getFingerprint();
|
|
80
89
|
}
|
|
81
90
|
constructSessionId(userId, clientId, domain) {
|
|
82
91
|
return (0, SessionHandler_1.constructSessionId)({ clientId, userId, domain, useQualifiedIds: this.config.useQualifiedIds });
|
|
@@ -89,8 +98,8 @@ class ProteusService {
|
|
|
89
98
|
* If not provided and the session doesn't exists it will fetch a new prekey from the backend
|
|
90
99
|
*/
|
|
91
100
|
async getRemoteFingerprint(userId, clientId, prekey) {
|
|
92
|
-
const sessionId = await (0, SessionHandler_1.initSession)({ userId, clientId, initialPrekey: prekey }, {
|
|
93
|
-
return this.
|
|
101
|
+
const sessionId = await (0, SessionHandler_1.initSession)({ userId, clientId, initialPrekey: prekey }, { cryptoClient: this.cryptoClient, apiClient: this.apiClient });
|
|
102
|
+
return this.cryptoClient.getRemoteFingerprint(sessionId);
|
|
94
103
|
}
|
|
95
104
|
async createConversation({ conversationData, otherUserIds, }) {
|
|
96
105
|
let payload;
|
|
@@ -145,14 +154,13 @@ class ProteusService {
|
|
|
145
154
|
async decrypt(encryptedText, userId, clientId) {
|
|
146
155
|
var _a, _b;
|
|
147
156
|
const sessionId = this.constructSessionId(userId, clientId);
|
|
148
|
-
const sessionExists = await this.
|
|
157
|
+
const sessionExists = await this.cryptoClient.sessionExists(sessionId);
|
|
149
158
|
try {
|
|
150
159
|
const decryptedMessage = !sessionExists
|
|
151
|
-
? await this.
|
|
152
|
-
: await this.
|
|
160
|
+
? await this.cryptoClient.sessionFromMessage(sessionId, encryptedText)
|
|
161
|
+
: await this.cryptoClient.decrypt(sessionId, encryptedText);
|
|
153
162
|
if (!sessionExists) {
|
|
154
|
-
await this.
|
|
155
|
-
await this.prekeyGenerator.consumePrekey();
|
|
163
|
+
await this.cryptoClient.saveSession(sessionId);
|
|
156
164
|
(_b = (_a = this.config).onNewClient) === null || _b === void 0 ? void 0 : _b.call(_a, { userId, clientId });
|
|
157
165
|
this.logger.info(`Created a new session from message for session ID "${sessionId}" and decrypted the message`);
|
|
158
166
|
}
|
|
@@ -170,10 +178,10 @@ class ProteusService {
|
|
|
170
178
|
recipients,
|
|
171
179
|
domain,
|
|
172
180
|
apiClient: this.apiClient,
|
|
173
|
-
|
|
181
|
+
cryptoClient: this.cryptoClient,
|
|
174
182
|
logger: this.logger,
|
|
175
183
|
});
|
|
176
|
-
const payload = await this.
|
|
184
|
+
const payload = await this.cryptoClient.encrypt(sessions, plainText);
|
|
177
185
|
return (0, SessionHandler_1.buildEncryptedPayloads)(payload);
|
|
178
186
|
}
|
|
179
187
|
deleteSession(userId, clientId) {
|
|
@@ -181,7 +189,7 @@ class ProteusService {
|
|
|
181
189
|
userId,
|
|
182
190
|
clientId,
|
|
183
191
|
useQualifiedIds: this.config.useQualifiedIds,
|
|
184
|
-
|
|
192
|
+
cryptoClient: this.cryptoClient,
|
|
185
193
|
});
|
|
186
194
|
}
|
|
187
195
|
async encryptQualified(plainText, preKeyBundles) {
|
|
@@ -192,34 +200,5 @@ class ProteusService {
|
|
|
192
200
|
}
|
|
193
201
|
return qualifiedOTRRecipients;
|
|
194
202
|
}
|
|
195
|
-
async migrateToCoreCrypto(storeEngine, context) {
|
|
196
|
-
var _a;
|
|
197
|
-
const dbName = storeEngine.storeName;
|
|
198
|
-
const migrationFlag = `${dbName}-corecrypto-ready`;
|
|
199
|
-
const localStorage = getLocalStorage();
|
|
200
|
-
if (localStorage.getItem(migrationFlag)) {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
// We want sessions to be fully qualified from now on
|
|
204
|
-
await (0, sessionIdMigrator_1.migrateToQualifiedSessionIds)(storeEngine, (_a = context.domain) !== null && _a !== void 0 ? _a : '');
|
|
205
|
-
this.logger.log(`Migrating data from cryptobox store (${dbName}) to corecrypto.`);
|
|
206
|
-
try {
|
|
207
|
-
await this.coreCryptoClient.proteusCryptoboxMigrate(dbName);
|
|
208
|
-
// We can clear 3 stores (keys - local identity, prekeys and sessions) from wire db.
|
|
209
|
-
// They will be stored in corecrypto database now.
|
|
210
|
-
/* TODO uncomment this code when we are sure migration for wire.com has happened successfully for enough users
|
|
211
|
-
const storesToClear = ['keys', 'prekeys', 'sessions'] as const;
|
|
212
|
-
|
|
213
|
-
for (const storeName of storesToClear) {
|
|
214
|
-
await this.storeEngine?.deleteAll(storeName);
|
|
215
|
-
}
|
|
216
|
-
*/
|
|
217
|
-
this.logger.log(`Successfully migrated from cryptobox store (${dbName}) to corecrypto.`);
|
|
218
|
-
localStorage.setItem(migrationFlag, '1');
|
|
219
|
-
}
|
|
220
|
-
catch (error) {
|
|
221
|
-
this.logger.error('Client was not able to perform DB migration: ', error);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
203
|
}
|
|
225
204
|
exports.ProteusService = ProteusService;
|
|
@@ -51,9 +51,9 @@ const SessionHandler_1 = require("../Utility/SessionHandler");
|
|
|
51
51
|
const notification_1 = require("../../../notification");
|
|
52
52
|
const event_1 = require("@wireapp/api-client/lib/event");
|
|
53
53
|
const protocol_messaging_1 = require("@wireapp/protocol-messaging");
|
|
54
|
-
jest.mock('./
|
|
54
|
+
jest.mock('./CryptoClient/PrekeysTracker', () => {
|
|
55
55
|
return {
|
|
56
|
-
|
|
56
|
+
PrekeyTracker: jest.fn().mockImplementation(() => {
|
|
57
57
|
return {
|
|
58
58
|
consumePrekey: jest.fn(),
|
|
59
59
|
getNumberOfPrekeys: jest.fn().mockResolvedValue(0),
|
|
@@ -148,7 +148,7 @@ describe('ProteusService', () => {
|
|
|
148
148
|
expect(result).toBe(expectedFingerprint);
|
|
149
149
|
});
|
|
150
150
|
it('create a session from given prekey if session does not exists', async () => {
|
|
151
|
-
const [proteusService, { apiClient, coreCrypto }] = await
|
|
151
|
+
const [proteusService, { apiClient, coreCrypto }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
152
152
|
const expectedFingerprint = 'fingerprint-client1';
|
|
153
153
|
const getPrekeyMock = jest.spyOn(apiClient.api.user, 'getClientPreKey');
|
|
154
154
|
jest.spyOn(coreCrypto, 'proteusFingerprintRemote').mockResolvedValue(expectedFingerprint);
|
|
@@ -12,10 +12,6 @@ export type ProteusServiceConfig = {
|
|
|
12
12
|
nbPrekeys: number;
|
|
13
13
|
onNewPrekeys: (prekeys: PreKey[]) => void;
|
|
14
14
|
};
|
|
15
|
-
export type NewDevicePrekeys = {
|
|
16
|
-
prekeys: PreKey[];
|
|
17
|
-
lastPrekey: PreKey;
|
|
18
|
-
};
|
|
19
15
|
export type SendProteusMessageParams = SendCommonParams & MessageSendingOptions & {
|
|
20
16
|
conversationId: QualifiedId;
|
|
21
17
|
/**
|