@wireapp/core 17.31.5 → 17.33.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/CHANGELOG.md +38 -0
- package/package.json +4 -4
- package/src/main/conversation/AssetService.js +2 -21
- package/src/main/conversation/ConversationService.d.ts +10 -0
- package/src/main/conversation/ConversationService.js +36 -21
- package/src/main/conversation/content/FileContent.d.ts +2 -1
- package/src/main/conversation/content/ImageContent.d.ts +1 -1
- package/src/main/conversation/message/MessageService.js +2 -2
- package/src/main/cryptography/{EncryptedAsset.d.ts → AssetCryptography/EncryptedAsset.d.ts} +0 -0
- package/src/main/cryptography/{EncryptedAsset.js → AssetCryptography/EncryptedAsset.js} +0 -0
- package/src/main/cryptography/AssetCryptography/crypto.browser.d.ts +2 -0
- package/src/main/cryptography/AssetCryptography/crypto.browser.js +46 -0
- package/src/main/cryptography/AssetCryptography/crypto.node.d.ts +2 -0
- package/src/main/cryptography/AssetCryptography/crypto.node.js +68 -0
- package/src/main/cryptography/{AssetCryptography.node.d.ts → AssetCryptography/index.d.ts} +3 -3
- package/src/main/cryptography/{AssetCryptography.browser.js → AssetCryptography/index.js} +15 -21
- package/src/main/cryptography/AssetCryptography/interfaces.d.ts +10 -0
- package/src/main/cryptography/AssetCryptography/interfaces.js +21 -0
- package/src/main/cryptography/index.d.ts +1 -1
- package/src/main/cryptography/index.js +1 -1
- package/src/main/cryptography/AssetCryptography.browser.d.ts +0 -6
- package/src/main/cryptography/AssetCryptography.node.js +0 -80
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,44 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [17.33.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@17.32.0...@wireapp/core@17.33.0) (2021-12-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **core:** Add a method to get all participants/clients of a conversation ([#4193](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4193)) ([e6a1a90](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/e6a1a90a5c3115c3a2c1c1a793897605eb54da8e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [17.32.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@17.31.7...@wireapp/core@17.32.0) (2021-12-06)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **core:** Add image metadata to file metadata payload ([#4194](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4194)) ([fa5bc52](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/fa5bc52f2824471b0e853e66d708eb4c2722fb50))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## [17.31.7](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@17.31.6...@wireapp/core@17.31.7) (2021-12-03)
|
|
29
|
+
|
|
30
|
+
**Note:** Version bump only for package @wireapp/core
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## [17.31.6](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@17.31.5...@wireapp/core@17.31.6) (2021-12-02)
|
|
37
|
+
|
|
38
|
+
**Note:** Version bump only for package @wireapp/core
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
6
44
|
## [17.31.5](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@17.31.4...@wireapp/core@17.31.5) (2021-12-02)
|
|
7
45
|
|
|
8
46
|
**Note:** Version bump only for package @wireapp/core
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"browser": {
|
|
3
|
-
"./src/main/cryptography/AssetCryptography.node": "./src/main/cryptography/AssetCryptography.browser.js"
|
|
3
|
+
"./src/main/cryptography/AssetCryptography/crypto.node": "./src/main/cryptography/AssetCryptography/crypto.browser.js"
|
|
4
4
|
},
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@types/long": "4.0.1",
|
|
7
7
|
"@types/node": "~14",
|
|
8
|
-
"@wireapp/api-client": "15.
|
|
8
|
+
"@wireapp/api-client": "15.11.0",
|
|
9
9
|
"@wireapp/cryptobox": "12.7.1",
|
|
10
10
|
"bazinga64": "5.10.0",
|
|
11
11
|
"hash.js": "1.1.7",
|
|
@@ -69,6 +69,6 @@
|
|
|
69
69
|
"test:project": "yarn dist && yarn test",
|
|
70
70
|
"test:node": "nyc jasmine --config=jasmine.json"
|
|
71
71
|
},
|
|
72
|
-
"version": "17.
|
|
73
|
-
"gitHead": "
|
|
72
|
+
"version": "17.33.0",
|
|
73
|
+
"gitHead": "bcbc4dc285bee59367258659ad0d9a9e85bbf6fa"
|
|
74
74
|
}
|
|
@@ -17,34 +17,15 @@
|
|
|
17
17
|
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
23
|
-
}) : (function(o, m, k, k2) {
|
|
24
|
-
if (k2 === undefined) k2 = k;
|
|
25
|
-
o[k2] = m[k];
|
|
26
|
-
}));
|
|
27
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
-
}) : function(o, v) {
|
|
30
|
-
o["default"] = v;
|
|
31
|
-
});
|
|
32
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
21
|
exports.AssetService = void 0;
|
|
41
|
-
const
|
|
22
|
+
const AssetCryptography_1 = require("../cryptography/AssetCryptography");
|
|
42
23
|
class AssetService {
|
|
43
24
|
constructor(apiClient) {
|
|
44
25
|
this.apiClient = apiClient;
|
|
45
26
|
}
|
|
46
27
|
async postAsset(plainText, options, progressCallback) {
|
|
47
|
-
const { cipherText, keyBytes, sha256 } = await
|
|
28
|
+
const { cipherText, keyBytes, sha256 } = await (0, AssetCryptography_1.encryptAsset)({
|
|
48
29
|
plainText,
|
|
49
30
|
algorithm: options === null || options === void 0 ? void 0 : options.algorithm,
|
|
50
31
|
hash: options === null || options === void 0 ? void 0 : options.hash,
|
|
@@ -109,6 +109,16 @@ export declare class ConversationService {
|
|
|
109
109
|
private generateCallGenericMessage;
|
|
110
110
|
private generateTextGenericMessage;
|
|
111
111
|
clearConversation(conversationId: string, timestamp?: number | Date, messageId?: string, sendAsProtobuf?: boolean, conversationDomain?: string): Promise<ClearConversationMessage>;
|
|
112
|
+
/**
|
|
113
|
+
* Get a fresh list from backend of clients for all the participants of the conversation.
|
|
114
|
+
* This is a hacky way of getting all the clients for a conversation.
|
|
115
|
+
* The idea is to send an empty message to the backend to absolutely no users and let backend reply with a mismatch error.
|
|
116
|
+
* We then get the missing members in the mismatch, that is our fresh list of participants' clients.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} conversationId
|
|
119
|
+
* @param {string} conversationDomain? - If given will send the message to the new qualified endpoint
|
|
120
|
+
*/
|
|
121
|
+
getAllParticipantsClients(conversationId: string, conversationDomain?: string): Promise<UserClients | QualifiedUserClients>;
|
|
112
122
|
deleteMessageLocal(conversationId: string, messageIdToHide: string, sendAsProtobuf?: boolean, conversationDomain?: string): Promise<HideMessage>;
|
|
113
123
|
deleteMessageEveryone(conversationId: string, messageIdToDelete: string, userIds?: string[] | QualifiedId[] | UserClients | QualifiedUserClients, sendAsProtobuf?: boolean, conversationDomain?: string, callbacks?: MessageSendingCallbacks): Promise<DeleteMessage>;
|
|
114
124
|
leaveConversation(conversationId: string): Promise<ConversationMemberLeaveEvent>;
|
|
@@ -17,32 +17,13 @@
|
|
|
17
17
|
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
23
|
-
}) : (function(o, m, k, k2) {
|
|
24
|
-
if (k2 === undefined) k2 = k;
|
|
25
|
-
o[k2] = m[k];
|
|
26
|
-
}));
|
|
27
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
-
}) : function(o, v) {
|
|
30
|
-
o["default"] = v;
|
|
31
|
-
});
|
|
32
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
21
|
exports.ConversationService = exports.MessageTargetMode = void 0;
|
|
41
22
|
const conversation_1 = require("@wireapp/api-client/src/conversation/");
|
|
42
23
|
const data_1 = require("@wireapp/api-client/src/conversation/data/");
|
|
43
24
|
const protocol_messaging_1 = require("@wireapp/protocol-messaging");
|
|
44
25
|
const conversation_2 = require("../conversation/");
|
|
45
|
-
const
|
|
26
|
+
const AssetCryptography_1 = require("../cryptography/AssetCryptography");
|
|
46
27
|
const TypePredicateUtil_1 = require("../util/TypePredicateUtil");
|
|
47
28
|
const MessageBuilder_1 = require("./message/MessageBuilder");
|
|
48
29
|
const MessageService_1 = require("./message/MessageService");
|
|
@@ -476,6 +457,40 @@ class ConversationService {
|
|
|
476
457
|
type: conversation_2.PayloadBundleType.CONVERSATION_CLEAR,
|
|
477
458
|
};
|
|
478
459
|
}
|
|
460
|
+
/**
|
|
461
|
+
* Get a fresh list from backend of clients for all the participants of the conversation.
|
|
462
|
+
* This is a hacky way of getting all the clients for a conversation.
|
|
463
|
+
* The idea is to send an empty message to the backend to absolutely no users and let backend reply with a mismatch error.
|
|
464
|
+
* We then get the missing members in the mismatch, that is our fresh list of participants' clients.
|
|
465
|
+
*
|
|
466
|
+
* @param {string} conversationId
|
|
467
|
+
* @param {string} conversationDomain? - If given will send the message to the new qualified endpoint
|
|
468
|
+
*/
|
|
469
|
+
getAllParticipantsClients(conversationId, conversationDomain) {
|
|
470
|
+
const sendingClientId = this.apiClient.validatedClientId;
|
|
471
|
+
const recipients = {};
|
|
472
|
+
const text = new Uint8Array();
|
|
473
|
+
return new Promise(async (resolve) => {
|
|
474
|
+
const onClientMismatch = (mismatch) => {
|
|
475
|
+
resolve(mismatch.missing);
|
|
476
|
+
// When the mismatch happens, we ask the messageService to cancel the sending
|
|
477
|
+
return false;
|
|
478
|
+
};
|
|
479
|
+
if (conversationDomain) {
|
|
480
|
+
await this.messageService.sendFederatedMessage(sendingClientId, recipients, text, {
|
|
481
|
+
conversationId: { id: conversationId, domain: conversationDomain },
|
|
482
|
+
onClientMismatch,
|
|
483
|
+
reportMissing: true,
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
await this.messageService.sendMessage(sendingClientId, recipients, text, {
|
|
488
|
+
conversationId,
|
|
489
|
+
onClientMismatch,
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
}
|
|
479
494
|
async deleteMessageLocal(conversationId, messageIdToHide, sendAsProtobuf, conversationDomain) {
|
|
480
495
|
const messageId = MessageBuilder_1.MessageBuilder.createId();
|
|
481
496
|
const content = protocol_messaging_1.MessageHide.create({
|
|
@@ -565,7 +580,7 @@ class ConversationService {
|
|
|
565
580
|
async getAsset({ assetId, assetToken, otrKey, sha256 }) {
|
|
566
581
|
const request = await this.apiClient.asset.api.getAssetV3(assetId, assetToken);
|
|
567
582
|
const encryptedBuffer = (await request.response).buffer;
|
|
568
|
-
return
|
|
583
|
+
return (0, AssetCryptography_1.decryptAsset)({
|
|
569
584
|
cipherText: Buffer.from(encryptedBuffer),
|
|
570
585
|
keyBytes: Buffer.from(otrKey),
|
|
571
586
|
sha256: Buffer.from(sha256),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { AudioMetaData, VideoMetaData } from './AssetContent';
|
|
2
|
+
import type { AudioMetaData, VideoMetaData, ImageMetaData } from './AssetContent';
|
|
3
3
|
export interface FileContent {
|
|
4
4
|
data: Buffer;
|
|
5
5
|
}
|
|
@@ -9,4 +9,5 @@ export interface FileMetaDataContent {
|
|
|
9
9
|
name: string;
|
|
10
10
|
type: string;
|
|
11
11
|
video?: VideoMetaData;
|
|
12
|
+
image?: ImageMetaData;
|
|
12
13
|
}
|
|
@@ -27,7 +27,7 @@ const otr_1 = require("@wireapp/protocol-messaging/web/otr");
|
|
|
27
27
|
const long_1 = __importDefault(require("long"));
|
|
28
28
|
const StringUtil_1 = require("@wireapp/commons/src/main/util/StringUtil");
|
|
29
29
|
const bazinga64_1 = require("bazinga64");
|
|
30
|
-
const
|
|
30
|
+
const AssetCryptography_1 = require("../../cryptography/AssetCryptography");
|
|
31
31
|
const cryptography_1 = require("../../cryptography");
|
|
32
32
|
const MessageBuilder_1 = require("./MessageBuilder");
|
|
33
33
|
const protocol_messaging_1 = require("@wireapp/protocol-messaging");
|
|
@@ -182,7 +182,7 @@ class MessageService {
|
|
|
182
182
|
: this.apiClient.conversation.api.postOTRMessage(sendingClientId, options.conversationId, message, ignoreMissing);
|
|
183
183
|
}
|
|
184
184
|
async generateExternalPayload(plainText) {
|
|
185
|
-
const asset = await (0,
|
|
185
|
+
const asset = await (0, AssetCryptography_1.encryptAsset)({ plainText });
|
|
186
186
|
const { cipherText, keyBytes, sha256 } = asset;
|
|
187
187
|
const messageId = MessageBuilder_1.MessageBuilder.createId();
|
|
188
188
|
const externalMessage = {
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* 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
|
+
exports.crypto = void 0;
|
|
22
|
+
const cryptoLib = window.crypto;
|
|
23
|
+
exports.crypto = {
|
|
24
|
+
async digest(cipherText) {
|
|
25
|
+
const checksum = await cryptoLib.subtle.digest('SHA-256', cipherText);
|
|
26
|
+
return Buffer.from(checksum);
|
|
27
|
+
},
|
|
28
|
+
async decrypt(cipherText, keyBytes) {
|
|
29
|
+
const key = await cryptoLib.subtle.importKey('raw', keyBytes, 'AES-CBC', false, ['decrypt']);
|
|
30
|
+
const initializationVector = cipherText.slice(0, 16);
|
|
31
|
+
const assetCipherText = cipherText.slice(16);
|
|
32
|
+
const decipher = await cryptoLib.subtle.decrypt({ iv: initializationVector, name: 'AES-CBC' }, key, assetCipherText);
|
|
33
|
+
return Buffer.from(decipher);
|
|
34
|
+
},
|
|
35
|
+
getRandomValues(size) {
|
|
36
|
+
return Buffer.from(cryptoLib.getRandomValues(new Uint8Array(size)));
|
|
37
|
+
},
|
|
38
|
+
async encrypt(plainText, keyBytes, initializationVector) {
|
|
39
|
+
const key = await cryptoLib.subtle.importKey('raw', keyBytes, 'AES-CBC', true, ['encrypt']);
|
|
40
|
+
return {
|
|
41
|
+
key: Buffer.from(await cryptoLib.subtle.exportKey('raw', key)),
|
|
42
|
+
cipher: await cryptoLib.subtle.encrypt({ iv: initializationVector, name: 'AES-CBC' }, key, plainText),
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=crypto.browser.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* 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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.crypto = void 0;
|
|
41
|
+
const cryptoLib = __importStar(require("crypto"));
|
|
42
|
+
exports.crypto = {
|
|
43
|
+
async digest(cipherText) {
|
|
44
|
+
return cryptoLib.createHash('SHA256').update(cipherText).digest();
|
|
45
|
+
},
|
|
46
|
+
async decrypt(cipherText, keyBytes) {
|
|
47
|
+
const initializationVector = cipherText.slice(0, 16);
|
|
48
|
+
const assetCipherText = cipherText.slice(16);
|
|
49
|
+
const decipher = cryptoLib.createDecipheriv('AES-256-CBC', keyBytes, initializationVector);
|
|
50
|
+
const decipherUpdated = decipher.update(assetCipherText);
|
|
51
|
+
const decipherFinal = decipher.final();
|
|
52
|
+
return Buffer.concat([decipherUpdated, decipherFinal]);
|
|
53
|
+
},
|
|
54
|
+
getRandomValues(size) {
|
|
55
|
+
return cryptoLib.randomBytes(size);
|
|
56
|
+
},
|
|
57
|
+
async encrypt(plainText, keyBytes, initializationVector, algorithm) {
|
|
58
|
+
const cipher = cryptoLib.createCipheriv(algorithm, keyBytes, initializationVector);
|
|
59
|
+
const cipherUpdated = cipher.update(plainText);
|
|
60
|
+
const cipherFinal = cipher.final();
|
|
61
|
+
const cipherText = Buffer.concat([cipherUpdated, cipherFinal]);
|
|
62
|
+
return {
|
|
63
|
+
key: keyBytes,
|
|
64
|
+
cipher: cipherText,
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=crypto.node.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import
|
|
3
|
-
import type { EncryptedAsset } from '
|
|
2
|
+
import { CipherOptions } from '@wireapp/api-client/src/asset';
|
|
3
|
+
import type { EncryptedAsset } from './EncryptedAsset';
|
|
4
4
|
interface EncryptOptions extends CipherOptions {
|
|
5
5
|
plainText: Buffer | Uint8Array;
|
|
6
6
|
}
|
|
7
7
|
export declare const decryptAsset: ({ cipherText, keyBytes, sha256: referenceSha256, }: EncryptedAsset) => Promise<Buffer>;
|
|
8
|
-
export declare const encryptAsset: ({ plainText, algorithm
|
|
8
|
+
export declare const encryptAsset: ({ plainText, algorithm }: EncryptOptions) => Promise<EncryptedAsset>;
|
|
9
9
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
3
|
* Wire
|
|
4
|
-
* Copyright (C)
|
|
4
|
+
* Copyright (C) 2021 Wire Swiss GmbH
|
|
5
5
|
*
|
|
6
6
|
* This program is free software: you can redistribute it and/or modify
|
|
7
7
|
* it under the terms of the GNU General Public License as published by
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
exports.encryptAsset = exports.decryptAsset = void 0;
|
|
22
|
-
const
|
|
22
|
+
const crypto_node_1 = require("./crypto.node");
|
|
23
23
|
const isEqual = (a, b) => {
|
|
24
24
|
const arrayA = new Uint32Array(a);
|
|
25
25
|
const arrayB = new Uint32Array(b);
|
|
@@ -28,32 +28,26 @@ const isEqual = (a, b) => {
|
|
|
28
28
|
return hasSameLength && hasSameValues;
|
|
29
29
|
};
|
|
30
30
|
const decryptAsset = async ({ cipherText, keyBytes, sha256: referenceSha256, }) => {
|
|
31
|
-
const computedSha256 = await crypto.
|
|
32
|
-
if (!isEqual(
|
|
31
|
+
const computedSha256 = await crypto_node_1.crypto.digest(cipherText);
|
|
32
|
+
if (!isEqual(computedSha256, referenceSha256)) {
|
|
33
33
|
throw new Error('Encrypted asset does not match its SHA-256 hash');
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
const initializationVector = cipherText.slice(0, 16);
|
|
37
|
-
const assetCipherText = cipherText.slice(16);
|
|
38
|
-
const decipher = await crypto.subtle.decrypt({ iv: initializationVector, name: 'AES-CBC' }, key, assetCipherText);
|
|
39
|
-
return Buffer.from(decipher);
|
|
35
|
+
return crypto_node_1.crypto.decrypt(cipherText, keyBytes);
|
|
40
36
|
};
|
|
41
37
|
exports.decryptAsset = decryptAsset;
|
|
42
|
-
const encryptAsset = async (
|
|
43
|
-
const initializationVector = crypto.getRandomValues(
|
|
44
|
-
const rawKeyBytes = crypto.getRandomValues(
|
|
45
|
-
const key = await crypto.
|
|
46
|
-
const
|
|
47
|
-
const ivCipherText = new Uint8Array(cipherText.byteLength + initializationVector.byteLength);
|
|
38
|
+
const encryptAsset = async ({ plainText, algorithm = 'AES-256-CBC' }) => {
|
|
39
|
+
const initializationVector = crypto_node_1.crypto.getRandomValues(16);
|
|
40
|
+
const rawKeyBytes = crypto_node_1.crypto.getRandomValues(32);
|
|
41
|
+
const { key, cipher } = await crypto_node_1.crypto.encrypt(plainText, rawKeyBytes, initializationVector, algorithm);
|
|
42
|
+
const ivCipherText = new Uint8Array(cipher.byteLength + initializationVector.byteLength);
|
|
48
43
|
ivCipherText.set(initializationVector, 0);
|
|
49
|
-
ivCipherText.set(new Uint8Array(
|
|
50
|
-
const
|
|
51
|
-
const keyBytes = await crypto.subtle.exportKey('raw', key);
|
|
44
|
+
ivCipherText.set(new Uint8Array(cipher), initializationVector.byteLength);
|
|
45
|
+
const sha256 = await crypto_node_1.crypto.digest(ivCipherText);
|
|
52
46
|
return {
|
|
53
47
|
cipherText: Buffer.from(ivCipherText.buffer),
|
|
54
|
-
keyBytes:
|
|
55
|
-
sha256
|
|
48
|
+
keyBytes: key,
|
|
49
|
+
sha256,
|
|
56
50
|
};
|
|
57
51
|
};
|
|
58
52
|
exports.encryptAsset = encryptAsset;
|
|
59
|
-
//# sourceMappingURL=
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export interface Crypto {
|
|
3
|
+
digest(cipherText: Buffer | Uint8Array): Promise<Buffer>;
|
|
4
|
+
decrypt(cipherText: Buffer | Uint8Array, keyBytes: Buffer): Promise<Buffer>;
|
|
5
|
+
getRandomValues(size: number): Buffer;
|
|
6
|
+
encrypt(plainText: Buffer | Uint8Array, keyBytes: Buffer, initializationVector: Buffer, algorithm: string): Promise<{
|
|
7
|
+
key: Buffer;
|
|
8
|
+
cipher: Buffer;
|
|
9
|
+
}>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* 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
|
+
//# sourceMappingURL=interfaces.js.map
|
|
@@ -29,7 +29,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
31
|
__exportStar(require("./CryptographyService"), exports);
|
|
32
|
-
__exportStar(require("./EncryptedAsset"), exports);
|
|
32
|
+
__exportStar(require("./AssetCryptography/EncryptedAsset"), exports);
|
|
33
33
|
__exportStar(require("./SessionPayloadBundle"), exports);
|
|
34
34
|
__exportStar(require("./MessageHashService"), exports);
|
|
35
35
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { EncryptedAsset } from '../cryptography/';
|
|
3
|
-
export declare const decryptAsset: ({ cipherText, keyBytes, sha256: referenceSha256, }: EncryptedAsset) => Promise<Buffer>;
|
|
4
|
-
export declare const encryptAsset: (options: {
|
|
5
|
-
plaintext: ArrayBuffer;
|
|
6
|
-
}) => Promise<EncryptedAsset>;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Wire
|
|
4
|
-
* Copyright (C) 2018 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
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
23
|
-
}) : (function(o, m, k, k2) {
|
|
24
|
-
if (k2 === undefined) k2 = k;
|
|
25
|
-
o[k2] = m[k];
|
|
26
|
-
}));
|
|
27
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
-
}) : function(o, v) {
|
|
30
|
-
o["default"] = v;
|
|
31
|
-
});
|
|
32
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.encryptAsset = exports.decryptAsset = void 0;
|
|
41
|
-
const crypto = __importStar(require("crypto"));
|
|
42
|
-
const isEqual = (a, b) => {
|
|
43
|
-
const arrayA = new Uint32Array(a);
|
|
44
|
-
const arrayB = new Uint32Array(b);
|
|
45
|
-
const hasSameLength = arrayA.length === arrayB.length;
|
|
46
|
-
const hasSameValues = arrayA.every((value, index) => value === arrayB[index]);
|
|
47
|
-
return hasSameLength && hasSameValues;
|
|
48
|
-
};
|
|
49
|
-
const decryptAsset = async ({ cipherText, keyBytes, sha256: referenceSha256, }) => {
|
|
50
|
-
const computedSha256 = crypto.createHash('SHA256').update(cipherText).digest();
|
|
51
|
-
if (!isEqual(computedSha256, referenceSha256)) {
|
|
52
|
-
throw new Error('Encrypted asset does not match its SHA-256 hash');
|
|
53
|
-
}
|
|
54
|
-
const initializationVector = cipherText.slice(0, 16);
|
|
55
|
-
const assetCipherText = cipherText.slice(16);
|
|
56
|
-
const decipher = crypto.createDecipheriv('AES-256-CBC', keyBytes, initializationVector);
|
|
57
|
-
const decipherUpdated = decipher.update(assetCipherText);
|
|
58
|
-
const decipherFinal = decipher.final();
|
|
59
|
-
return Buffer.concat([decipherUpdated, decipherFinal]);
|
|
60
|
-
};
|
|
61
|
-
exports.decryptAsset = decryptAsset;
|
|
62
|
-
const encryptAsset = async ({ plainText, algorithm = 'AES-256-CBC', hash, }) => {
|
|
63
|
-
const initializationVector = crypto.randomBytes(16);
|
|
64
|
-
const keyBytes = crypto.randomBytes(32);
|
|
65
|
-
const cipher = crypto.createCipheriv(algorithm, keyBytes, initializationVector);
|
|
66
|
-
const cipherUpdated = cipher.update(plainText);
|
|
67
|
-
const cipherFinal = cipher.final();
|
|
68
|
-
const cipherText = Buffer.concat([cipherUpdated, cipherFinal]);
|
|
69
|
-
const ivCipherText = new Uint8Array(initializationVector.byteLength + cipherText.byteLength);
|
|
70
|
-
ivCipherText.set(initializationVector, 0);
|
|
71
|
-
ivCipherText.set(cipherText, initializationVector.byteLength);
|
|
72
|
-
const computedHash = hash || crypto.createHash('SHA256').update(Buffer.from(ivCipherText.buffer)).digest();
|
|
73
|
-
return {
|
|
74
|
-
cipherText: Buffer.from(ivCipherText.buffer),
|
|
75
|
-
keyBytes,
|
|
76
|
-
sha256: computedHash,
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
exports.encryptAsset = encryptAsset;
|
|
80
|
-
//# sourceMappingURL=AssetCryptography.node.js.map
|