@wireapp/core 17.31.2 → 17.31.6
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 +32 -0
- package/package.json +5 -5
- package/src/main/conversation/AssetService.js +2 -21
- package/src/main/conversation/ConversationService.js +2 -21
- 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,38 @@
|
|
|
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.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)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @wireapp/core
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [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)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @wireapp/core
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [17.31.4](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@17.31.3...@wireapp/core@17.31.4) (2021-12-02)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @wireapp/core
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [17.31.3](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@17.31.2...@wireapp/core@17.31.3) (2021-12-02)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @wireapp/core
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
6
38
|
## [17.31.2](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@17.31.1...@wireapp/core@17.31.2) (2021-12-01)
|
|
7
39
|
|
|
8
40
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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.9.0",
|
|
9
9
|
"@wireapp/cryptobox": "12.7.1",
|
|
10
|
-
"bazinga64": "5.
|
|
10
|
+
"bazinga64": "5.10.0",
|
|
11
11
|
"hash.js": "1.1.7",
|
|
12
12
|
"http-status-codes": "2.1.4",
|
|
13
13
|
"logdown": "3.3.1",
|
|
@@ -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.31.
|
|
73
|
-
"gitHead": "
|
|
72
|
+
"version": "17.31.6",
|
|
73
|
+
"gitHead": "71b1228f9c2f578adbc9b5a4f7625cb8bfbaaa4a"
|
|
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,
|
|
@@ -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");
|
|
@@ -565,7 +546,7 @@ class ConversationService {
|
|
|
565
546
|
async getAsset({ assetId, assetToken, otrKey, sha256 }) {
|
|
566
547
|
const request = await this.apiClient.asset.api.getAssetV3(assetId, assetToken);
|
|
567
548
|
const encryptedBuffer = (await request.response).buffer;
|
|
568
|
-
return
|
|
549
|
+
return (0, AssetCryptography_1.decryptAsset)({
|
|
569
550
|
cipherText: Buffer.from(encryptedBuffer),
|
|
570
551
|
keyBytes: Buffer.from(otrKey),
|
|
571
552
|
sha256: Buffer.from(sha256),
|
|
@@ -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
|