curtain-web-api 1.0.39 → 1.0.41
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.
|
@@ -22,6 +22,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
25
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
35
|
exports.CurtainWebAPI = exports.reviver = exports.replacer = void 0;
|
|
27
36
|
const curtain_user_1 = require("./curtain-user");
|
|
@@ -213,46 +222,44 @@ class CurtainWebAPI {
|
|
|
213
222
|
encrypted: false,
|
|
214
223
|
e2e: false,
|
|
215
224
|
}, onUploadProgress = undefined) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
(
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return this.axiosInstance.post(this.baseURL + "curtain/", form, { headers: headers, responseType: "json" }).then((response) => {
|
|
255
|
-
return response;
|
|
225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
let form = new FormData();
|
|
227
|
+
let data = JSON.stringify(settings, exports.replacer);
|
|
228
|
+
if (enable) {
|
|
229
|
+
form.append("enable", "True");
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
form.append("enable", "False");
|
|
233
|
+
}
|
|
234
|
+
if (encryption.encrypted) {
|
|
235
|
+
form.append("encrypted", "True");
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
form.append("encrypted", "False");
|
|
239
|
+
}
|
|
240
|
+
if (encryption.e2e) {
|
|
241
|
+
form.append("e2e", "True");
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
form.append("e2e", "False");
|
|
245
|
+
}
|
|
246
|
+
if (encryption.encrypted && encryption.e2e && encryption.publicKey !== undefined) {
|
|
247
|
+
const response = yield (0, curtain_encryption_1.encryptDataRSA)(data, encryption.publicKey);
|
|
248
|
+
const base64String = (0, curtain_encryption_1.arrayBufferToBase64String)(response);
|
|
249
|
+
form.append("file", new Blob([base64String], { type: 'text/json' }), "curtain-settings.json");
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
form.append("file", new Blob([data], { type: 'text/json' }), "curtain-settings.json");
|
|
253
|
+
}
|
|
254
|
+
form.append("description", description);
|
|
255
|
+
form.append("curtain_type", sessionType);
|
|
256
|
+
let headers = new axios_1.AxiosHeaders();
|
|
257
|
+
headers["Accept"] = "application/json";
|
|
258
|
+
headers["Content-Type"] = "multipart/form-data";
|
|
259
|
+
if (onUploadProgress !== undefined) {
|
|
260
|
+
return yield this.axiosInstance.post(this.baseURL + "curtain/", form, { headers: headers, responseType: "json", onUploadProgress: onUploadProgress });
|
|
261
|
+
}
|
|
262
|
+
return yield this.axiosInstance.post(this.baseURL + "curtain/", form, { headers: headers, responseType: "json" });
|
|
256
263
|
});
|
|
257
264
|
}
|
|
258
265
|
postSettings(id, token, onDownloadProgress = undefined) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import {User} from "./curtain-user";
|
|
2
2
|
import axios, {AxiosHeaders} from "axios";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
arrayBufferToBase64String, base64ToArrayBuffer,
|
|
5
|
+
CurtainEncryption,
|
|
6
|
+
encryptAESData, encryptAESKey,
|
|
7
|
+
encryptDataRSA, exportAESKey,
|
|
8
|
+
generateAESKey
|
|
9
|
+
} from "./curtain-encryption";
|
|
4
10
|
|
|
5
11
|
const base: string = "https://celsus.muttsu.xyz/"
|
|
6
12
|
|
|
@@ -199,7 +205,7 @@ export class CurtainWebAPI {
|
|
|
199
205
|
}
|
|
200
206
|
|
|
201
207
|
|
|
202
|
-
putSettings(settings: any, enable: boolean = true, description: string = "", sessionType: string = "TP", encryption: CurtainEncryption = {
|
|
208
|
+
async putSettings(settings: any, enable: boolean = true, description: string = "", sessionType: string = "TP", encryption: CurtainEncryption = {
|
|
203
209
|
encrypted: false,
|
|
204
210
|
e2e: false,
|
|
205
211
|
}, onUploadProgress: any = undefined) {
|
|
@@ -222,9 +228,18 @@ export class CurtainWebAPI {
|
|
|
222
228
|
}
|
|
223
229
|
|
|
224
230
|
if (encryption.encrypted && encryption.e2e && encryption.publicKey !== undefined) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
231
|
+
const aesKey = await generateAESKey()
|
|
232
|
+
const encryptedData = await encryptAESData(aesKey, data)
|
|
233
|
+
const encryptedKey = await encryptAESKey(encryption.publicKey, await exportAESKey(aesKey))
|
|
234
|
+
const encryptedIV = await encryptAESKey(encryption.publicKey, base64ToArrayBuffer(encryptedData.iv))
|
|
235
|
+
const payload = {
|
|
236
|
+
encryptedData: encryptedData.encrypted,
|
|
237
|
+
encryptedKey: arrayBufferToBase64String(encryptedKey),
|
|
238
|
+
encryptedIV: arrayBufferToBase64String(encryptedIV)
|
|
239
|
+
}
|
|
240
|
+
form.append("encryptedKey", payload.encryptedKey)
|
|
241
|
+
form.append("encryptedIV", payload.encryptedIV)
|
|
242
|
+
form.append("file", new Blob([payload.encryptedData], {type: 'text/json'}), "curtain-settings.json")
|
|
228
243
|
} else {
|
|
229
244
|
form.append("file", new Blob([data], {type: 'text/json'}), "curtain-settings.json")
|
|
230
245
|
}
|
|
@@ -235,13 +250,11 @@ export class CurtainWebAPI {
|
|
|
235
250
|
headers["Accept"] = "application/json";
|
|
236
251
|
headers["Content-Type"] = "multipart/form-data";
|
|
237
252
|
if (onUploadProgress !== undefined) {
|
|
238
|
-
return this.axiosInstance.post(this.baseURL + "curtain/", form, {headers: headers, responseType:"json", onUploadProgress: onUploadProgress})
|
|
239
|
-
|
|
240
|
-
})
|
|
253
|
+
return await this.axiosInstance.post(this.baseURL + "curtain/", form, {headers: headers, responseType:"json", onUploadProgress: onUploadProgress})
|
|
254
|
+
} else {
|
|
255
|
+
return await this.axiosInstance.post(this.baseURL + "curtain/", form, {headers: headers, responseType:"json"})
|
|
241
256
|
}
|
|
242
|
-
|
|
243
|
-
return response;
|
|
244
|
-
});
|
|
257
|
+
|
|
245
258
|
}
|
|
246
259
|
|
|
247
260
|
postSettings(id: string, token: string, onDownloadProgress: any = undefined) {
|
|
@@ -471,5 +484,19 @@ export class CurtainWebAPI {
|
|
|
471
484
|
headers["Content-Type"] = "application/json";
|
|
472
485
|
return this.axiosInstance.get(this.baseURL + `stats/summary/${lastNDays}/`, {responseType:"json", headers})
|
|
473
486
|
}
|
|
487
|
+
|
|
488
|
+
postEncryptionFactors(encryptedAESKey: string, encryptedIV: string, linkId: string) {
|
|
489
|
+
let headers = new AxiosHeaders();
|
|
490
|
+
headers["Accept"] = "application/json";
|
|
491
|
+
headers["Content-Type"] = "application/json";
|
|
492
|
+
return this.axiosInstance.post(this.baseURL + "curtain/" + linkId + "/set_encryption_factors/", {encryption_key: encryptedAESKey, encryption_iv: encryptedIV}, {headers: headers, responseType: "json"}).then((response) => {return response;});
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
getEncryptionFactors(linkId: string) {
|
|
496
|
+
let headers = new AxiosHeaders();
|
|
497
|
+
headers["Accept"] = "application/json";
|
|
498
|
+
headers["Content-Type"] = "application/json";
|
|
499
|
+
return this.axiosInstance.get(this.baseURL + "curtain/" + linkId + "/get_encryption_factors/", {headers: headers, responseType: "json"}).then((response) => {return response;});
|
|
500
|
+
}
|
|
474
501
|
}
|
|
475
502
|
|
|
@@ -103,4 +103,68 @@ export function pemToArrayBuffer(pem: string) {
|
|
|
103
103
|
b64Final = b64Final.replace('-----END PUBLIC KEY-----', '');
|
|
104
104
|
|
|
105
105
|
return base64ToArrayBuffer(b64Final);
|
|
106
|
-
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// a function to generate to encrypt an aes key arraybuffer with a public key
|
|
109
|
+
export async function encryptAESKey(publicKey: CryptoKey, aesKey: ArrayBuffer) {
|
|
110
|
+
return await crypto.subtle.encrypt({name: "RSA-OAEP"}, publicKey, aesKey)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// a function to generate an aes key in GCM mode with a length of 256 bits
|
|
114
|
+
export async function generateAESKey() {
|
|
115
|
+
return await crypto.subtle.generateKey(
|
|
116
|
+
{
|
|
117
|
+
name: "AES-GCM",
|
|
118
|
+
length: 256,
|
|
119
|
+
},
|
|
120
|
+
true,
|
|
121
|
+
["encrypt", "decrypt"],
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// a function to encrypt a string with an aes key
|
|
126
|
+
export async function encryptAESData(aesKey: CryptoKey, data: string) {
|
|
127
|
+
const iv = crypto.getRandomValues(new Uint8Array(12))
|
|
128
|
+
const enc = new TextEncoder()
|
|
129
|
+
const encoded = enc.encode(data)
|
|
130
|
+
const encrypted = await crypto.subtle.encrypt({name: "AES-GCM", iv: iv}, aesKey, encoded)
|
|
131
|
+
return {encrypted: arrayBufferToBase64String(encrypted), iv: arrayBufferToBase64String(iv)}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// a function to decrypt a string with an aes key
|
|
135
|
+
export async function decryptAESData(aesKey: CryptoKey, data: string, iv: string) {
|
|
136
|
+
const dec = new TextDecoder()
|
|
137
|
+
const decrypted = await crypto.subtle.decrypt({name: "AES-GCM", iv: base64ToArrayBuffer(iv)}, aesKey, base64ToArrayBuffer(data))
|
|
138
|
+
return dec.decode(decrypted)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// a function to decrypt an aes key with a private key
|
|
142
|
+
export async function decryptAESKey(privateKey: CryptoKey, encryptedKey: ArrayBuffer) {
|
|
143
|
+
return await crypto.subtle.decrypt({name: "RSA-OAEP"}, privateKey, encryptedKey)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// a function to export an aes key to a string
|
|
147
|
+
export async function exportAESKey(key: CryptoKey) {
|
|
148
|
+
return await crypto.subtle.exportKey("raw", key)
|
|
149
|
+
}
|
|
150
|
+
// a function to import an aes key from a string
|
|
151
|
+
export async function importAESKey(key: ArrayBuffer) {
|
|
152
|
+
return await crypto.subtle.importKey("raw", key, "AES-GCM", true, ["encrypt", "decrypt"])
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// a function to encrypt aes key with a public key and also use the aes key to encrypt a large string then return the encrypted aes key and the encrypted string
|
|
156
|
+
export async function encryptDataAES(data: string, publicKey: CryptoKey) {
|
|
157
|
+
const aesKey = await generateAESKey()
|
|
158
|
+
const encryptedKey = await encryptAESKey(publicKey, await exportAESKey(aesKey))
|
|
159
|
+
const encryptedData = await encryptAESData(aesKey, data)
|
|
160
|
+
return {encryptedKey: arrayBufferToBase64String(encryptedKey), encryptedData: encryptedData}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// a function to decrypt an aes key with a private key and use the aes key to decrypt a large string
|
|
164
|
+
export async function decryptDataAES(encryptedKey: ArrayBuffer, encryptedData: string, iv: string, privateKey: CryptoKey) {
|
|
165
|
+
const aesKey = await decryptAESKey(privateKey, encryptedKey)
|
|
166
|
+
//import aes key
|
|
167
|
+
return await decryptAESData(await importAESKey(aesKey), encryptedData, iv)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|