@wireapp/core 45.2.14 → 45.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/conversation/AssetService/AssetService.d.ts +21 -8
- package/lib/conversation/AssetService/AssetService.d.ts.map +1 -1
- package/lib/conversation/AssetService/AssetService.js +24 -2
- package/lib/conversation/ConversationService/ConversationService.d.ts +0 -3
- package/lib/conversation/ConversationService/ConversationService.d.ts.map +1 -1
- package/lib/conversation/ConversationService/ConversationService.js +0 -14
- package/lib/cryptography/AssetCryptography/AssetCryptography.d.ts +9 -0
- package/lib/cryptography/AssetCryptography/AssetCryptography.d.ts.map +1 -0
- package/lib/cryptography/AssetCryptography/AssetCryptography.js +52 -0
- package/lib/cryptography/AssetCryptography/AssetCryptography.test.d.ts +2 -0
- package/lib/cryptography/AssetCryptography/AssetCryptography.test.d.ts.map +1 -0
- package/lib/cryptography/AssetCryptography/AssetCryptography.test.js +45 -0
- package/lib/cryptography/AssetCryptography/index.d.ts +1 -8
- package/lib/cryptography/AssetCryptography/index.d.ts.map +1 -1
- package/lib/cryptography/AssetCryptography/index.js +15 -32
- package/package.json +3 -3
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { AssetOptions } from '@wireapp/api-client/lib/asset';
|
|
2
|
+
import { AssetOptions, AssetResponse } from '@wireapp/api-client/lib/asset';
|
|
3
3
|
import { ProgressCallback, RequestCancelable } from '@wireapp/api-client/lib/http';
|
|
4
4
|
import { APIClient } from '@wireapp/api-client';
|
|
5
|
-
import { EncryptedAssetUploaded } from '../../cryptography';
|
|
6
|
-
|
|
5
|
+
import { EncryptedAsset, EncryptedAssetUploaded } from '../../cryptography';
|
|
6
|
+
interface AssetDataV4 {
|
|
7
7
|
assetKey: string;
|
|
8
8
|
assetToken: string;
|
|
9
9
|
assetDomain: string;
|
|
10
10
|
forceCaching: boolean;
|
|
11
11
|
version: 4;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
interface AssetDataV3 {
|
|
14
14
|
assetKey: string;
|
|
15
15
|
assetToken: string;
|
|
16
16
|
forceCaching: boolean;
|
|
17
17
|
version: 3;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
interface AssetDataV2 {
|
|
20
20
|
assetId: string;
|
|
21
21
|
conversationId: string;
|
|
22
22
|
forceCaching: boolean;
|
|
23
23
|
version: 2;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
interface AssetDataV1 {
|
|
26
26
|
assetId: string;
|
|
27
27
|
conversationId: string;
|
|
28
28
|
forceCaching: boolean;
|
|
29
29
|
version: 1;
|
|
30
30
|
}
|
|
31
|
+
export { ProgressCallback };
|
|
31
32
|
export type AssetUrlData = AssetDataV1 | AssetDataV2 | AssetDataV3 | AssetDataV4;
|
|
32
33
|
export declare class AssetService {
|
|
33
34
|
private readonly apiClient;
|
|
@@ -40,9 +41,9 @@ export declare class AssetService {
|
|
|
40
41
|
* @param progressCallback?
|
|
41
42
|
* @return Resolves when the asset has been uploaded
|
|
42
43
|
*/
|
|
43
|
-
|
|
44
|
+
downloadRawAsset(assetData: AssetUrlData, progressCallback?: ProgressCallback): {
|
|
44
45
|
cancel: () => void;
|
|
45
|
-
response: Promise<
|
|
46
|
+
response: Promise<AssetResponse>;
|
|
46
47
|
};
|
|
47
48
|
/**
|
|
48
49
|
* Uploads a raw asset to the backend without encrypting it
|
|
@@ -62,5 +63,17 @@ export declare class AssetService {
|
|
|
62
63
|
* @return cancellable request that resolves with the uploaded image and decryption keys
|
|
63
64
|
*/
|
|
64
65
|
uploadAsset(plainText: Buffer | Uint8Array, options?: AssetOptions, progressCallback?: ProgressCallback): Promise<RequestCancelable<EncryptedAssetUploaded>>;
|
|
66
|
+
decryptAsset(asset: EncryptedAsset): Promise<Uint8Array>;
|
|
67
|
+
/**
|
|
68
|
+
* Will download and decrypt an asset stored on the server
|
|
69
|
+
* @param assetData - the data of the asset to download
|
|
70
|
+
* @param otrKey the encryption key used to encrypt the asset
|
|
71
|
+
* @param sha256 the sha256 hash of the asset
|
|
72
|
+
* @param progressCallback a progress callback to inform about the download progress
|
|
73
|
+
*/
|
|
74
|
+
downloadAsset(assetData: AssetUrlData, otrKey: Uint8Array, sha256: Uint8Array, progressCallback?: ProgressCallback): {
|
|
75
|
+
response: Promise<AssetResponse>;
|
|
76
|
+
cancel: () => void;
|
|
77
|
+
};
|
|
65
78
|
}
|
|
66
79
|
//# sourceMappingURL=AssetService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetService.d.ts","sourceRoot":"","sources":["../../../src/conversation/AssetService/AssetService.ts"],"names":[],"mappings":";AAmBA,OAAO,EAAC,YAAY,EAAC,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"AssetService.d.ts","sourceRoot":"","sources":["../../../src/conversation/AssetService/AssetService.ts"],"names":[],"mappings":";AAmBA,OAAO,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAC,gBAAgB,EAAE,iBAAiB,EAAC,MAAM,8BAA8B,CAAC;AAEjF,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,cAAc,EAAE,sBAAsB,EAAC,MAAM,oBAAoB,CAAC;AAG1E,UAAU,WAAW;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,CAAC,CAAC;CACZ;AACD,UAAU,WAAW;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,E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require("../../cryptography/AssetCryptography");
|
|
22
|
+
const AssetCryptography_1 = require("../../cryptography/AssetCryptography/AssetCryptography");
|
|
23
23
|
class AssetService {
|
|
24
24
|
constructor(apiClient) {
|
|
25
25
|
this.apiClient = apiClient;
|
|
@@ -32,7 +32,7 @@ class AssetService {
|
|
|
32
32
|
* @param progressCallback?
|
|
33
33
|
* @return Resolves when the asset has been uploaded
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
downloadRawAsset(assetData, progressCallback) {
|
|
36
36
|
const { forceCaching } = assetData;
|
|
37
37
|
switch (assetData.version) {
|
|
38
38
|
case 1:
|
|
@@ -83,5 +83,27 @@ class AssetService {
|
|
|
83
83
|
};
|
|
84
84
|
}) });
|
|
85
85
|
}
|
|
86
|
+
decryptAsset(asset) {
|
|
87
|
+
return (0, AssetCryptography_1.decryptAsset)(asset);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Will download and decrypt an asset stored on the server
|
|
91
|
+
* @param assetData - the data of the asset to download
|
|
92
|
+
* @param otrKey the encryption key used to encrypt the asset
|
|
93
|
+
* @param sha256 the sha256 hash of the asset
|
|
94
|
+
* @param progressCallback a progress callback to inform about the download progress
|
|
95
|
+
*/
|
|
96
|
+
downloadAsset(assetData, otrKey, sha256, progressCallback) {
|
|
97
|
+
const request = this.downloadRawAsset(assetData, progressCallback);
|
|
98
|
+
const { response } = request;
|
|
99
|
+
return {
|
|
100
|
+
response: response.then(async (response) => (Object.assign(Object.assign({}, response), { buffer: await (0, AssetCryptography_1.decryptAsset)({
|
|
101
|
+
cipherText: new Uint8Array(response.buffer),
|
|
102
|
+
keyBytes: otrKey,
|
|
103
|
+
sha256: sha256,
|
|
104
|
+
}) }))),
|
|
105
|
+
cancel: request.cancel,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
86
108
|
}
|
|
87
109
|
exports.AssetService = AssetService;
|
|
@@ -11,7 +11,6 @@ import { ProteusService } from '../../messagingProtocols/proteus';
|
|
|
11
11
|
import { AddUsersToProteusConversationParams, SendProteusMessageParams } from '../../messagingProtocols/proteus/ProteusService/ProteusService.types';
|
|
12
12
|
import { HandledEventResult } from '../../notification';
|
|
13
13
|
import { CoreDatabase } from '../../storage/CoreDB';
|
|
14
|
-
import { RemoteData } from '../content';
|
|
15
14
|
import { SubconversationService } from '../SubconversationService/SubconversationService';
|
|
16
15
|
type Events = {
|
|
17
16
|
MLSConversationRecovered: {
|
|
@@ -51,8 +50,6 @@ export declare class ConversationService extends TypedEventEmitter<Events> {
|
|
|
51
50
|
getConversation(conversationId: QualifiedId): Promise<Conversation>;
|
|
52
51
|
getMLSSelfConversation(): Promise<MLSConversation>;
|
|
53
52
|
getConversations(conversationIds?: QualifiedId[]): Promise<RemoteConversations>;
|
|
54
|
-
getAsset({ assetId, assetToken, otrKey, sha256 }: RemoteData): Promise<Uint8Array>;
|
|
55
|
-
getUnencryptedAsset(assetId: string, assetToken?: string): Promise<ArrayBuffer>;
|
|
56
53
|
addUsersToProteusConversation(params: AddUsersToProteusConversationParams): Promise<import("./ConversationService.types").ProteusAddUsersResponse>;
|
|
57
54
|
removeUserFromConversation(conversationId: QualifiedId, userId: QualifiedId): Promise<ConversationMemberLeaveEvent>;
|
|
58
55
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConversationService.d.ts","sourceRoot":"","sources":["../../../src/conversation/ConversationService/ConversationService.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,YAAY,EACZ,2BAA2B,EAC3B,WAAW,EACX,eAAe,EACf,oBAAoB,EAEpB,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAEnB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACL,YAAY,EAIZ,4BAA4B,EAE7B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAIvD,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAC,iBAAiB,EAAC,MAAM,kBAAkB,CAAC;AAGnD,OAAO,EAEL,cAAc,EAEd,6BAA6B,EAC7B,oBAAoB,EACpB,UAAU,EACX,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAC,YAAY,EAAuB,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"ConversationService.d.ts","sourceRoot":"","sources":["../../../src/conversation/ConversationService/ConversationService.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,YAAY,EACZ,2BAA2B,EAC3B,WAAW,EACX,eAAe,EACf,oBAAoB,EAEpB,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAEnB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACL,YAAY,EAIZ,4BAA4B,EAE7B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAIvD,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAC,iBAAiB,EAAC,MAAM,kBAAkB,CAAC;AAGnD,OAAO,EAEL,cAAc,EAEd,6BAA6B,EAC7B,oBAAoB,EACpB,UAAU,EACX,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAC,YAAY,EAAuB,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAC,UAAU,EAAC,MAAM,8BAA8B,CAAC;AAMxD,OAAO,EAAkC,cAAc,EAAC,MAAM,kCAAkC,CAAC;AACjG,OAAO,EACL,mCAAmC,EACnC,wBAAwB,EACzB,MAAM,sEAAsE,CAAC;AAC9E,OAAO,EAAsB,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAIlD,OAAO,EAAC,s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vD,8BAA8B,CAAC,EAC1C,OAAO,EACP,cAAc,EACd,gBAAgB,GACjB,EAAE,iBAAiB,GAAG,OAAO,CAAC,6BAA6B,CAAC;IAoBhD,oBAAoB,CAAC,cAAc,EAAE,WAAW;IAI7D;;;OAGG;IACU,qBAAqB,CAAC,OAAO,EAAE,MAAM;IAIlD;;;;OAIG;IACU,4BAA4B,CAAC,OAAO,EAAE,MAAM;IAI5C,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAIlD,YAAY;IAYb,gCAAgC;IAe7C;;;OAGG;YACW,kCAAkC;IA2BhD;;;OAGG;YACW,+BAA+B;IAqB7C;;;;;;;OAOG;YACW,gBAAgB;IAQ9B;;;OAGG;IACG,sBAAsB,CAAC,MAAM,EAAE,WAAW;IAIhD;;;;;;;OAOG;IACH,SAAgB,4BAA4B,YACjC,MAAM,YACL;QAAC,IAAI,EAAE,WAAW,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,eAChC,WAAW,4BAEvB,QAAQ,eAAe,CAAC,CAoDzB;IAEF;;;;;;;;OAQG;IACU,uBAAuB,CAAC,EACnC,OAAO,EACP,cAAc,EACd,UAAU,EACV,cAAc,GACf,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,cAAc,EAAE,WAAW,CAAC;QAC5B,UAAU,EAAE,WAAW,CAAC;QACxB,cAAc,EAAE,WAAW,EAAE,CAAC;KAC/B,GAAG,OAAO,CAAC,IAAI,CAAC;YA4BH,wBAAwB;YAsBxB,gCAAgC;YAyBhC,4BAA4B;YA0B5B,wBAAwB;YAIxB,yBAAyB;IAKvC;;;;OAIG;IACU,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAoB3E"}
|
|
@@ -31,7 +31,6 @@ const logdown_1 = __importDefault(require("logdown"));
|
|
|
31
31
|
const commons_1 = require("@wireapp/commons");
|
|
32
32
|
const protocol_messaging_1 = require("@wireapp/protocol-messaging");
|
|
33
33
|
const conversation_2 = require("../../conversation/");
|
|
34
|
-
const AssetCryptography_1 = require("../../cryptography/AssetCryptography");
|
|
35
34
|
const conversationRejoinQueue_1 = require("../../messagingProtocols/mls/conversationRejoinQueue");
|
|
36
35
|
const CoreCryptoMLSError_1 = require("../../messagingProtocols/mls/MLSService/CoreCryptoMLSError");
|
|
37
36
|
const proteus_1 = require("../../messagingProtocols/proteus");
|
|
@@ -162,19 +161,6 @@ class ConversationService extends commons_1.TypedEventEmitter {
|
|
|
162
161
|
}
|
|
163
162
|
return this.apiClient.api.conversation.getConversationsByQualifiedIds(conversationIds);
|
|
164
163
|
}
|
|
165
|
-
async getAsset({ assetId, assetToken, otrKey, sha256 }) {
|
|
166
|
-
const request = this.apiClient.api.asset.getAssetV3(assetId, assetToken);
|
|
167
|
-
const encryptedBuffer = (await request.response).buffer;
|
|
168
|
-
return (0, AssetCryptography_1.decryptAsset)({
|
|
169
|
-
cipherText: new Uint8Array(encryptedBuffer),
|
|
170
|
-
keyBytes: otrKey,
|
|
171
|
-
sha256: sha256,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
async getUnencryptedAsset(assetId, assetToken) {
|
|
175
|
-
const request = await this.apiClient.api.asset.getAssetV3(assetId, assetToken);
|
|
176
|
-
return (await request.response).buffer;
|
|
177
|
-
}
|
|
178
164
|
async addUsersToProteusConversation(params) {
|
|
179
165
|
return this.proteusService.addUsersToConversation(params);
|
|
180
166
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CipherOptions } from '@wireapp/api-client/lib/asset';
|
|
2
|
+
import { EncryptedAsset } from './EncryptedAsset';
|
|
3
|
+
interface EncryptOptions extends CipherOptions {
|
|
4
|
+
plainText: Uint8Array;
|
|
5
|
+
}
|
|
6
|
+
export declare const decryptAsset: ({ cipherText, keyBytes, sha256: referenceSha256, }: EncryptedAsset) => Promise<Uint8Array>;
|
|
7
|
+
export declare const encryptAsset: ({ plainText, algorithm }: EncryptOptions) => Promise<EncryptedAsset>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=AssetCryptography.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssetCryptography.d.ts","sourceRoot":"","sources":["../../../src/cryptography/AssetCryptography/AssetCryptography.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,aAAa,EAAC,MAAM,+BAA+B,CAAC;AAG5D,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAYhD,UAAU,cAAe,SAAQ,aAAa;IAC5C,SAAS,EAAE,UAAU,CAAC;CACvB;AAED,eAAO,MAAM,YAAY,uDAItB,cAAc,KAAG,QAAQ,UAAU,CAQrC,CAAC;AAEF,eAAO,MAAM,YAAY,6BAAkD,cAAc,KAAG,QAAQ,cAAc,CAiBjH,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
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.encryptAsset = exports.decryptAsset = void 0;
|
|
22
|
+
const crypto_node_1 = require("./crypto.node");
|
|
23
|
+
const isEqual = (a, b) => {
|
|
24
|
+
const arrayA = new Uint32Array(a);
|
|
25
|
+
const arrayB = new Uint32Array(b);
|
|
26
|
+
const hasSameLength = arrayA.length === arrayB.length;
|
|
27
|
+
const hasSameValues = arrayA.every((value, index) => value === arrayB[index]);
|
|
28
|
+
return hasSameLength && hasSameValues;
|
|
29
|
+
};
|
|
30
|
+
const decryptAsset = async ({ cipherText, keyBytes, sha256: referenceSha256, }) => {
|
|
31
|
+
const computedSha256 = await crypto_node_1.crypto.digest(cipherText);
|
|
32
|
+
if (!isEqual(computedSha256, referenceSha256)) {
|
|
33
|
+
throw new Error('Encrypted asset does not match its SHA-256 hash');
|
|
34
|
+
}
|
|
35
|
+
return crypto_node_1.crypto.decrypt(cipherText, keyBytes);
|
|
36
|
+
};
|
|
37
|
+
exports.decryptAsset = decryptAsset;
|
|
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);
|
|
43
|
+
ivCipherText.set(initializationVector, 0);
|
|
44
|
+
ivCipherText.set(new Uint8Array(cipher), initializationVector.byteLength);
|
|
45
|
+
const sha256 = await crypto_node_1.crypto.digest(ivCipherText);
|
|
46
|
+
return {
|
|
47
|
+
cipherText: ivCipherText,
|
|
48
|
+
keyBytes: key,
|
|
49
|
+
sha256,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
exports.encryptAsset = encryptAsset;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AssetCryptography.test.d.ts","sourceRoot":"","sources":["../../../src/cryptography/AssetCryptography/AssetCryptography.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Wire
|
|
4
|
+
* Copyright (C) 2024 Wire Swiss GmbH
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU General Public License as published by
|
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* This program is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU General Public License
|
|
17
|
+
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
const AssetCryptography_1 = require("./AssetCryptography");
|
|
22
|
+
describe('AssetCrypto', () => {
|
|
23
|
+
it('should encrypt and decrypt ArrayBuffer', async () => {
|
|
24
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
25
|
+
const { cipherText, keyBytes, sha256 } = await (0, AssetCryptography_1.encryptAsset)({ plainText: bytes });
|
|
26
|
+
const buffer = await (0, AssetCryptography_1.decryptAsset)({ cipherText, keyBytes, sha256 });
|
|
27
|
+
expect(new Uint8Array(buffer)).toEqual(bytes);
|
|
28
|
+
});
|
|
29
|
+
// This test conforms to the following testing standards:
|
|
30
|
+
// @SF.Messages @TSFI.RESTfulAPI @S0.2 @S0.3
|
|
31
|
+
it('should not decrypt when hash is missing', async () => {
|
|
32
|
+
const bytes = new Uint8Array(16);
|
|
33
|
+
global.crypto.getRandomValues(bytes);
|
|
34
|
+
const { cipherText, keyBytes } = await (0, AssetCryptography_1.encryptAsset)({ plainText: bytes });
|
|
35
|
+
await expect((0, AssetCryptography_1.decryptAsset)({ cipherText, keyBytes, sha256: null })).rejects.toThrow();
|
|
36
|
+
});
|
|
37
|
+
// This test conforms to the following testing standards:
|
|
38
|
+
// @SF.Messages @TSFI.RESTfulAPI @S0.2 @S0.3
|
|
39
|
+
it('should not decrypt when hash is an empty array', async () => {
|
|
40
|
+
const bytes = new Uint8Array(16);
|
|
41
|
+
global.crypto.getRandomValues(bytes);
|
|
42
|
+
const { cipherText, keyBytes } = await (0, AssetCryptography_1.encryptAsset)({ plainText: bytes });
|
|
43
|
+
await expect((0, AssetCryptography_1.decryptAsset)({ cipherText, keyBytes, sha256: new Uint8Array([]) })).rejects.toThrow();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { EncryptedAsset } from './EncryptedAsset';
|
|
3
|
-
interface EncryptOptions extends CipherOptions {
|
|
4
|
-
plainText: Uint8Array;
|
|
5
|
-
}
|
|
6
|
-
export declare const decryptAsset: ({ cipherText, keyBytes, sha256: referenceSha256, }: EncryptedAsset) => Promise<Uint8Array>;
|
|
7
|
-
export declare const encryptAsset: ({ plainText, algorithm }: EncryptOptions) => Promise<EncryptedAsset>;
|
|
8
|
-
export {};
|
|
1
|
+
export * from './AssetCryptography';
|
|
9
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cryptography/AssetCryptography/index.ts"],"names":[],"mappings":"AAmBA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cryptography/AssetCryptography/index.ts"],"names":[],"mappings":"AAmBA,cAAc,qBAAqB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
3
|
* Wire
|
|
4
|
-
* Copyright (C)
|
|
4
|
+
* Copyright (C) 2024 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
|
|
@@ -17,36 +17,19 @@
|
|
|
17
17
|
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
-
Object.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const arrayB = new Uint32Array(b);
|
|
26
|
-
const hasSameLength = arrayA.length === arrayB.length;
|
|
27
|
-
const hasSameValues = arrayA.every((value, index) => value === arrayB[index]);
|
|
28
|
-
return hasSameLength && hasSameValues;
|
|
29
|
-
};
|
|
30
|
-
const decryptAsset = async ({ cipherText, keyBytes, sha256: referenceSha256, }) => {
|
|
31
|
-
const computedSha256 = await crypto_node_1.crypto.digest(cipherText);
|
|
32
|
-
if (!isEqual(computedSha256, referenceSha256)) {
|
|
33
|
-
throw new Error('Encrypted asset does not match its SHA-256 hash');
|
|
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]; } };
|
|
34
25
|
}
|
|
35
|
-
|
|
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);
|
|
36
33
|
};
|
|
37
|
-
exports
|
|
38
|
-
|
|
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);
|
|
43
|
-
ivCipherText.set(initializationVector, 0);
|
|
44
|
-
ivCipherText.set(new Uint8Array(cipher), initializationVector.byteLength);
|
|
45
|
-
const sha256 = await crypto_node_1.crypto.digest(ivCipherText);
|
|
46
|
-
return {
|
|
47
|
-
cipherText: ivCipherText,
|
|
48
|
-
keyBytes: key,
|
|
49
|
-
sha256,
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
exports.encryptAsset = encryptAsset;
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
__exportStar(require("./AssetCryptography"), exports);
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"./lib/cryptography/AssetCryptography/crypto.node": "./lib/cryptography/AssetCryptography/crypto.browser.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@wireapp/api-client": "^26.
|
|
14
|
+
"@wireapp/api-client": "^26.12.0",
|
|
15
15
|
"@wireapp/commons": "^5.2.7",
|
|
16
16
|
"@wireapp/core-crypto": "1.0.0-rc.52",
|
|
17
17
|
"@wireapp/cryptobox": "12.8.0",
|
|
@@ -61,6 +61,6 @@
|
|
|
61
61
|
"test:coverage": "jest --coverage",
|
|
62
62
|
"watch": "tsc --watch"
|
|
63
63
|
},
|
|
64
|
-
"version": "45.
|
|
65
|
-
"gitHead": "
|
|
64
|
+
"version": "45.3.1",
|
|
65
|
+
"gitHead": "f9424b7e31a5dbe86e87df714f9cb6e534ca4193"
|
|
66
66
|
}
|