@secure-exec/core 0.1.1-rc.2 → 0.1.1-rc.3
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/dist/bridge/child-process.js +22 -8
- package/dist/bridge/fs.js +29 -25
- package/dist/bridge/module.js +12 -3
- package/dist/bridge/network.d.ts +101 -1
- package/dist/bridge/network.js +629 -12
- package/dist/bridge/process.js +46 -25
- package/dist/bridge.js +795 -65
- package/dist/generated/isolate-runtime.d.ts +5 -5
- package/dist/generated/isolate-runtime.js +5 -5
- package/dist/index.d.ts +1 -1
- package/dist/isolate-runtime/apply-timing-mitigation-freeze.js +8 -6
- package/dist/isolate-runtime/bridge-initial-globals.js +4 -143
- package/dist/isolate-runtime/require-setup.js +960 -5
- package/dist/isolate-runtime/setup-dynamic-import.js +5 -1
- package/dist/isolate-runtime/setup-fs-facade.js +21 -60
- package/dist/shared/bridge-contract.d.ts +220 -94
- package/dist/shared/bridge-contract.js +31 -3
- package/dist/shared/console-formatter.js +4 -4
- package/dist/shared/global-exposure.js +95 -0
- package/dist/shared/permissions.js +16 -0
- package/dist/types.d.ts +42 -1
- package/package.json +1 -1
|
@@ -96,6 +96,34 @@
|
|
|
96
96
|
if (lastSlash === 0) return "/";
|
|
97
97
|
return p.slice(0, lastSlash);
|
|
98
98
|
}
|
|
99
|
+
if (typeof globalThis.TextDecoder === "function") {
|
|
100
|
+
_OrigTextDecoder = globalThis.TextDecoder;
|
|
101
|
+
_utf8Aliases = {
|
|
102
|
+
"utf-8": true,
|
|
103
|
+
"utf8": true,
|
|
104
|
+
"unicode-1-1-utf-8": true,
|
|
105
|
+
"ascii": true,
|
|
106
|
+
"us-ascii": true,
|
|
107
|
+
"iso-8859-1": true,
|
|
108
|
+
"latin1": true,
|
|
109
|
+
"binary": true,
|
|
110
|
+
"windows-1252": true,
|
|
111
|
+
"utf-16le": true,
|
|
112
|
+
"utf-16": true,
|
|
113
|
+
"ucs-2": true,
|
|
114
|
+
"ucs2": true
|
|
115
|
+
};
|
|
116
|
+
globalThis.TextDecoder = function TextDecoder(encoding, options) {
|
|
117
|
+
var label = encoding !== void 0 ? String(encoding).toLowerCase().replace(/\s/g, "") : "utf-8";
|
|
118
|
+
if (_utf8Aliases[label]) {
|
|
119
|
+
return new _OrigTextDecoder("utf-8", options);
|
|
120
|
+
}
|
|
121
|
+
return new _OrigTextDecoder(encoding, options);
|
|
122
|
+
};
|
|
123
|
+
globalThis.TextDecoder.prototype = _OrigTextDecoder.prototype;
|
|
124
|
+
}
|
|
125
|
+
var _OrigTextDecoder;
|
|
126
|
+
var _utf8Aliases;
|
|
99
127
|
function _patchPolyfill(name2, result2) {
|
|
100
128
|
if (typeof result2 !== "object" && typeof result2 !== "function" || result2 === null) {
|
|
101
129
|
return result2;
|
|
@@ -129,6 +157,24 @@
|
|
|
129
157
|
if (typeof BufferCtor.constants !== "object" || BufferCtor.constants === null) {
|
|
130
158
|
BufferCtor.constants = result2.constants;
|
|
131
159
|
}
|
|
160
|
+
var bProto = BufferCtor.prototype;
|
|
161
|
+
if (bProto) {
|
|
162
|
+
var encs = ["utf8", "ascii", "latin1", "binary", "hex", "base64", "ucs2", "utf16le"];
|
|
163
|
+
for (var ei = 0; ei < encs.length; ei++) {
|
|
164
|
+
(function(e) {
|
|
165
|
+
if (typeof bProto[e + "Slice"] !== "function") {
|
|
166
|
+
bProto[e + "Slice"] = function(start, end) {
|
|
167
|
+
return this.toString(e, start, end);
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
if (typeof bProto[e + "Write"] !== "function") {
|
|
171
|
+
bProto[e + "Write"] = function(str, offset, length) {
|
|
172
|
+
return this.write(str, offset, length, e);
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
})(encs[ei]);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
132
178
|
}
|
|
133
179
|
return result2;
|
|
134
180
|
}
|
|
@@ -185,6 +231,854 @@
|
|
|
185
231
|
}
|
|
186
232
|
return result2;
|
|
187
233
|
}
|
|
234
|
+
if (name2 === "zlib") {
|
|
235
|
+
if (typeof result2.constants !== "object" || result2.constants === null) {
|
|
236
|
+
var zlibConstants = {};
|
|
237
|
+
var constKeys = Object.keys(result2);
|
|
238
|
+
for (var ci = 0; ci < constKeys.length; ci++) {
|
|
239
|
+
var ck = constKeys[ci];
|
|
240
|
+
if (ck.indexOf("Z_") === 0 && typeof result2[ck] === "number") {
|
|
241
|
+
zlibConstants[ck] = result2[ck];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (typeof zlibConstants.DEFLATE !== "number") zlibConstants.DEFLATE = 1;
|
|
245
|
+
if (typeof zlibConstants.INFLATE !== "number") zlibConstants.INFLATE = 2;
|
|
246
|
+
if (typeof zlibConstants.GZIP !== "number") zlibConstants.GZIP = 3;
|
|
247
|
+
if (typeof zlibConstants.DEFLATERAW !== "number") zlibConstants.DEFLATERAW = 4;
|
|
248
|
+
if (typeof zlibConstants.INFLATERAW !== "number") zlibConstants.INFLATERAW = 5;
|
|
249
|
+
if (typeof zlibConstants.UNZIP !== "number") zlibConstants.UNZIP = 6;
|
|
250
|
+
if (typeof zlibConstants.GUNZIP !== "number") zlibConstants.GUNZIP = 7;
|
|
251
|
+
result2.constants = zlibConstants;
|
|
252
|
+
}
|
|
253
|
+
return result2;
|
|
254
|
+
}
|
|
255
|
+
if (name2 === "crypto") {
|
|
256
|
+
if (typeof _cryptoHashDigest !== "undefined") {
|
|
257
|
+
let SandboxHash2 = function(algorithm) {
|
|
258
|
+
this._algorithm = algorithm;
|
|
259
|
+
this._chunks = [];
|
|
260
|
+
};
|
|
261
|
+
var SandboxHash = SandboxHash2;
|
|
262
|
+
SandboxHash2.prototype.update = function update(data, inputEncoding) {
|
|
263
|
+
if (typeof data === "string") {
|
|
264
|
+
this._chunks.push(Buffer.from(data, inputEncoding || "utf8"));
|
|
265
|
+
} else {
|
|
266
|
+
this._chunks.push(Buffer.from(data));
|
|
267
|
+
}
|
|
268
|
+
return this;
|
|
269
|
+
};
|
|
270
|
+
SandboxHash2.prototype.digest = function digest(encoding) {
|
|
271
|
+
var combined = Buffer.concat(this._chunks);
|
|
272
|
+
var resultBase64 = _cryptoHashDigest.applySync(void 0, [
|
|
273
|
+
this._algorithm,
|
|
274
|
+
combined.toString("base64")
|
|
275
|
+
]);
|
|
276
|
+
var resultBuffer = Buffer.from(resultBase64, "base64");
|
|
277
|
+
if (!encoding || encoding === "buffer") return resultBuffer;
|
|
278
|
+
return resultBuffer.toString(encoding);
|
|
279
|
+
};
|
|
280
|
+
SandboxHash2.prototype.copy = function copy() {
|
|
281
|
+
var c = new SandboxHash2(this._algorithm);
|
|
282
|
+
c._chunks = this._chunks.slice();
|
|
283
|
+
return c;
|
|
284
|
+
};
|
|
285
|
+
SandboxHash2.prototype.write = function write(data, encoding) {
|
|
286
|
+
this.update(data, encoding);
|
|
287
|
+
return true;
|
|
288
|
+
};
|
|
289
|
+
SandboxHash2.prototype.end = function end(data, encoding) {
|
|
290
|
+
if (data) this.update(data, encoding);
|
|
291
|
+
};
|
|
292
|
+
result2.createHash = function createHash(algorithm) {
|
|
293
|
+
return new SandboxHash2(algorithm);
|
|
294
|
+
};
|
|
295
|
+
result2.Hash = SandboxHash2;
|
|
296
|
+
}
|
|
297
|
+
if (typeof _cryptoHmacDigest !== "undefined") {
|
|
298
|
+
let SandboxHmac2 = function(algorithm, key) {
|
|
299
|
+
this._algorithm = algorithm;
|
|
300
|
+
if (typeof key === "string") {
|
|
301
|
+
this._key = Buffer.from(key, "utf8");
|
|
302
|
+
} else if (key && typeof key === "object" && key._pem !== void 0) {
|
|
303
|
+
this._key = Buffer.from(key._pem, "utf8");
|
|
304
|
+
} else {
|
|
305
|
+
this._key = Buffer.from(key);
|
|
306
|
+
}
|
|
307
|
+
this._chunks = [];
|
|
308
|
+
};
|
|
309
|
+
var SandboxHmac = SandboxHmac2;
|
|
310
|
+
SandboxHmac2.prototype.update = function update(data, inputEncoding) {
|
|
311
|
+
if (typeof data === "string") {
|
|
312
|
+
this._chunks.push(Buffer.from(data, inputEncoding || "utf8"));
|
|
313
|
+
} else {
|
|
314
|
+
this._chunks.push(Buffer.from(data));
|
|
315
|
+
}
|
|
316
|
+
return this;
|
|
317
|
+
};
|
|
318
|
+
SandboxHmac2.prototype.digest = function digest(encoding) {
|
|
319
|
+
var combined = Buffer.concat(this._chunks);
|
|
320
|
+
var resultBase64 = _cryptoHmacDigest.applySync(void 0, [
|
|
321
|
+
this._algorithm,
|
|
322
|
+
this._key.toString("base64"),
|
|
323
|
+
combined.toString("base64")
|
|
324
|
+
]);
|
|
325
|
+
var resultBuffer = Buffer.from(resultBase64, "base64");
|
|
326
|
+
if (!encoding || encoding === "buffer") return resultBuffer;
|
|
327
|
+
return resultBuffer.toString(encoding);
|
|
328
|
+
};
|
|
329
|
+
SandboxHmac2.prototype.copy = function copy() {
|
|
330
|
+
var c = new SandboxHmac2(this._algorithm, this._key);
|
|
331
|
+
c._chunks = this._chunks.slice();
|
|
332
|
+
return c;
|
|
333
|
+
};
|
|
334
|
+
SandboxHmac2.prototype.write = function write(data, encoding) {
|
|
335
|
+
this.update(data, encoding);
|
|
336
|
+
return true;
|
|
337
|
+
};
|
|
338
|
+
SandboxHmac2.prototype.end = function end(data, encoding) {
|
|
339
|
+
if (data) this.update(data, encoding);
|
|
340
|
+
};
|
|
341
|
+
result2.createHmac = function createHmac(algorithm, key) {
|
|
342
|
+
return new SandboxHmac2(algorithm, key);
|
|
343
|
+
};
|
|
344
|
+
result2.Hmac = SandboxHmac2;
|
|
345
|
+
}
|
|
346
|
+
if (typeof _cryptoRandomFill !== "undefined") {
|
|
347
|
+
result2.randomBytes = function randomBytes(size, callback) {
|
|
348
|
+
if (typeof size !== "number" || size < 0 || size !== (size | 0)) {
|
|
349
|
+
var err = new TypeError('The "size" argument must be of type number. Received type ' + typeof size);
|
|
350
|
+
if (typeof callback === "function") {
|
|
351
|
+
callback(err);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
throw err;
|
|
355
|
+
}
|
|
356
|
+
if (size > 2147483647) {
|
|
357
|
+
var rangeErr = new RangeError('The value of "size" is out of range. It must be >= 0 && <= 2147483647. Received ' + size);
|
|
358
|
+
if (typeof callback === "function") {
|
|
359
|
+
callback(rangeErr);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
throw rangeErr;
|
|
363
|
+
}
|
|
364
|
+
var buf = Buffer.alloc(size);
|
|
365
|
+
var offset = 0;
|
|
366
|
+
while (offset < size) {
|
|
367
|
+
var chunk = Math.min(size - offset, 65536);
|
|
368
|
+
var base64 = _cryptoRandomFill.applySync(void 0, [chunk]);
|
|
369
|
+
var hostBytes = Buffer.from(base64, "base64");
|
|
370
|
+
hostBytes.copy(buf, offset);
|
|
371
|
+
offset += chunk;
|
|
372
|
+
}
|
|
373
|
+
if (typeof callback === "function") {
|
|
374
|
+
callback(null, buf);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
return buf;
|
|
378
|
+
};
|
|
379
|
+
result2.randomFillSync = function randomFillSync(buffer, offset, size) {
|
|
380
|
+
if (offset === void 0) offset = 0;
|
|
381
|
+
var byteLength = buffer.byteLength !== void 0 ? buffer.byteLength : buffer.length;
|
|
382
|
+
if (size === void 0) size = byteLength - offset;
|
|
383
|
+
if (offset < 0 || size < 0 || offset + size > byteLength) {
|
|
384
|
+
throw new RangeError('The value of "offset + size" is out of range.');
|
|
385
|
+
}
|
|
386
|
+
var bytes = new Uint8Array(buffer.buffer || buffer, buffer.byteOffset ? buffer.byteOffset + offset : offset, size);
|
|
387
|
+
var filled = 0;
|
|
388
|
+
while (filled < size) {
|
|
389
|
+
var chunk = Math.min(size - filled, 65536);
|
|
390
|
+
var base64 = _cryptoRandomFill.applySync(void 0, [chunk]);
|
|
391
|
+
var hostBytes = Buffer.from(base64, "base64");
|
|
392
|
+
bytes.set(hostBytes, filled);
|
|
393
|
+
filled += chunk;
|
|
394
|
+
}
|
|
395
|
+
return buffer;
|
|
396
|
+
};
|
|
397
|
+
result2.randomFill = function randomFill(buffer, offsetOrCb, sizeOrCb, callback) {
|
|
398
|
+
var offset = 0;
|
|
399
|
+
var size;
|
|
400
|
+
var cb;
|
|
401
|
+
if (typeof offsetOrCb === "function") {
|
|
402
|
+
cb = offsetOrCb;
|
|
403
|
+
} else if (typeof sizeOrCb === "function") {
|
|
404
|
+
offset = offsetOrCb || 0;
|
|
405
|
+
cb = sizeOrCb;
|
|
406
|
+
} else {
|
|
407
|
+
offset = offsetOrCb || 0;
|
|
408
|
+
size = sizeOrCb;
|
|
409
|
+
cb = callback;
|
|
410
|
+
}
|
|
411
|
+
if (typeof cb !== "function") {
|
|
412
|
+
throw new TypeError("Callback must be a function");
|
|
413
|
+
}
|
|
414
|
+
try {
|
|
415
|
+
result2.randomFillSync(buffer, offset, size);
|
|
416
|
+
cb(null, buffer);
|
|
417
|
+
} catch (e) {
|
|
418
|
+
cb(e);
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
result2.randomInt = function randomInt(minOrMax, maxOrCb, callback) {
|
|
422
|
+
var min, max, cb;
|
|
423
|
+
if (typeof maxOrCb === "function" || maxOrCb === void 0) {
|
|
424
|
+
min = 0;
|
|
425
|
+
max = minOrMax;
|
|
426
|
+
cb = maxOrCb;
|
|
427
|
+
} else {
|
|
428
|
+
min = minOrMax;
|
|
429
|
+
max = maxOrCb;
|
|
430
|
+
cb = callback;
|
|
431
|
+
}
|
|
432
|
+
if (!Number.isSafeInteger(min)) {
|
|
433
|
+
var minErr = new TypeError('The "min" argument must be a safe integer');
|
|
434
|
+
if (typeof cb === "function") {
|
|
435
|
+
cb(minErr);
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
throw minErr;
|
|
439
|
+
}
|
|
440
|
+
if (!Number.isSafeInteger(max)) {
|
|
441
|
+
var maxErr = new TypeError('The "max" argument must be a safe integer');
|
|
442
|
+
if (typeof cb === "function") {
|
|
443
|
+
cb(maxErr);
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
throw maxErr;
|
|
447
|
+
}
|
|
448
|
+
if (max <= min) {
|
|
449
|
+
var rangeErr2 = new RangeError('The value of "max" is out of range. It must be greater than the value of "min" (' + min + ")");
|
|
450
|
+
if (typeof cb === "function") {
|
|
451
|
+
cb(rangeErr2);
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
throw rangeErr2;
|
|
455
|
+
}
|
|
456
|
+
var range = max - min;
|
|
457
|
+
var bytes = 6;
|
|
458
|
+
var maxValid = Math.pow(2, 48) - Math.pow(2, 48) % range;
|
|
459
|
+
var val;
|
|
460
|
+
do {
|
|
461
|
+
var base64 = _cryptoRandomFill.applySync(void 0, [bytes]);
|
|
462
|
+
var buf = Buffer.from(base64, "base64");
|
|
463
|
+
val = buf.readUIntBE(0, bytes);
|
|
464
|
+
} while (val >= maxValid);
|
|
465
|
+
var result22 = min + val % range;
|
|
466
|
+
if (typeof cb === "function") {
|
|
467
|
+
cb(null, result22);
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
return result22;
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
if (typeof _cryptoPbkdf2 !== "undefined") {
|
|
474
|
+
result2.pbkdf2Sync = function pbkdf2Sync(password, salt, iterations, keylen, digest) {
|
|
475
|
+
var pwBuf = typeof password === "string" ? Buffer.from(password, "utf8") : Buffer.from(password);
|
|
476
|
+
var saltBuf = typeof salt === "string" ? Buffer.from(salt, "utf8") : Buffer.from(salt);
|
|
477
|
+
var resultBase64 = _cryptoPbkdf2.applySync(void 0, [
|
|
478
|
+
pwBuf.toString("base64"),
|
|
479
|
+
saltBuf.toString("base64"),
|
|
480
|
+
iterations,
|
|
481
|
+
keylen,
|
|
482
|
+
digest
|
|
483
|
+
]);
|
|
484
|
+
return Buffer.from(resultBase64, "base64");
|
|
485
|
+
};
|
|
486
|
+
result2.pbkdf2 = function pbkdf2(password, salt, iterations, keylen, digest, callback) {
|
|
487
|
+
try {
|
|
488
|
+
var derived = result2.pbkdf2Sync(password, salt, iterations, keylen, digest);
|
|
489
|
+
callback(null, derived);
|
|
490
|
+
} catch (e) {
|
|
491
|
+
callback(e);
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
if (typeof _cryptoScrypt !== "undefined") {
|
|
496
|
+
result2.scryptSync = function scryptSync(password, salt, keylen, options) {
|
|
497
|
+
var pwBuf = typeof password === "string" ? Buffer.from(password, "utf8") : Buffer.from(password);
|
|
498
|
+
var saltBuf = typeof salt === "string" ? Buffer.from(salt, "utf8") : Buffer.from(salt);
|
|
499
|
+
var opts = {};
|
|
500
|
+
if (options) {
|
|
501
|
+
if (options.N !== void 0) opts.N = options.N;
|
|
502
|
+
if (options.r !== void 0) opts.r = options.r;
|
|
503
|
+
if (options.p !== void 0) opts.p = options.p;
|
|
504
|
+
if (options.maxmem !== void 0) opts.maxmem = options.maxmem;
|
|
505
|
+
if (options.cost !== void 0) opts.N = options.cost;
|
|
506
|
+
if (options.blockSize !== void 0) opts.r = options.blockSize;
|
|
507
|
+
if (options.parallelization !== void 0) opts.p = options.parallelization;
|
|
508
|
+
}
|
|
509
|
+
var resultBase64 = _cryptoScrypt.applySync(void 0, [
|
|
510
|
+
pwBuf.toString("base64"),
|
|
511
|
+
saltBuf.toString("base64"),
|
|
512
|
+
keylen,
|
|
513
|
+
JSON.stringify(opts)
|
|
514
|
+
]);
|
|
515
|
+
return Buffer.from(resultBase64, "base64");
|
|
516
|
+
};
|
|
517
|
+
result2.scrypt = function scrypt(password, salt, keylen, optionsOrCb, callback) {
|
|
518
|
+
var opts = optionsOrCb;
|
|
519
|
+
var cb = callback;
|
|
520
|
+
if (typeof optionsOrCb === "function") {
|
|
521
|
+
opts = void 0;
|
|
522
|
+
cb = optionsOrCb;
|
|
523
|
+
}
|
|
524
|
+
try {
|
|
525
|
+
var derived = result2.scryptSync(password, salt, keylen, opts);
|
|
526
|
+
cb(null, derived);
|
|
527
|
+
} catch (e) {
|
|
528
|
+
cb(e);
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
var _useStatefulCipher = typeof _cryptoCipherivCreate !== "undefined";
|
|
533
|
+
if (typeof _cryptoCipheriv !== "undefined" || _useStatefulCipher) {
|
|
534
|
+
let SandboxCipher2 = function(algorithm, key, iv) {
|
|
535
|
+
this._algorithm = algorithm;
|
|
536
|
+
this._key = typeof key === "string" ? Buffer.from(key, "utf8") : Buffer.from(key);
|
|
537
|
+
this._iv = typeof iv === "string" ? Buffer.from(iv, "utf8") : Buffer.from(iv);
|
|
538
|
+
this._authTag = null;
|
|
539
|
+
this._finalized = false;
|
|
540
|
+
if (_useStatefulCipher) {
|
|
541
|
+
this._sessionId = _cryptoCipherivCreate.applySync(void 0, [
|
|
542
|
+
"cipher",
|
|
543
|
+
algorithm,
|
|
544
|
+
this._key.toString("base64"),
|
|
545
|
+
this._iv.toString("base64")
|
|
546
|
+
]);
|
|
547
|
+
} else {
|
|
548
|
+
this._sessionId = -1;
|
|
549
|
+
this._chunks = [];
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
var SandboxCipher = SandboxCipher2;
|
|
553
|
+
SandboxCipher2.prototype.update = function update(data, inputEncoding, outputEncoding) {
|
|
554
|
+
var buf;
|
|
555
|
+
if (typeof data === "string") {
|
|
556
|
+
buf = Buffer.from(data, inputEncoding || "utf8");
|
|
557
|
+
} else {
|
|
558
|
+
buf = Buffer.from(data);
|
|
559
|
+
}
|
|
560
|
+
if (this._sessionId >= 0) {
|
|
561
|
+
var resultBase64 = _cryptoCipherivUpdate.applySync(void 0, [this._sessionId, buf.toString("base64")]);
|
|
562
|
+
var resultBuffer = Buffer.from(resultBase64, "base64");
|
|
563
|
+
if (outputEncoding && outputEncoding !== "buffer") return resultBuffer.toString(outputEncoding);
|
|
564
|
+
return resultBuffer;
|
|
565
|
+
}
|
|
566
|
+
this._chunks.push(buf);
|
|
567
|
+
if (outputEncoding && outputEncoding !== "buffer") return "";
|
|
568
|
+
return Buffer.alloc(0);
|
|
569
|
+
};
|
|
570
|
+
SandboxCipher2.prototype.final = function final(outputEncoding) {
|
|
571
|
+
if (this._finalized) throw new Error("Attempting to call final() after already finalized");
|
|
572
|
+
this._finalized = true;
|
|
573
|
+
if (this._sessionId >= 0) {
|
|
574
|
+
var resultJson = _cryptoCipherivFinal.applySync(void 0, [this._sessionId]);
|
|
575
|
+
var parsed = JSON.parse(resultJson);
|
|
576
|
+
if (parsed.authTag) this._authTag = Buffer.from(parsed.authTag, "base64");
|
|
577
|
+
var resultBuffer = Buffer.from(parsed.data, "base64");
|
|
578
|
+
if (outputEncoding && outputEncoding !== "buffer") return resultBuffer.toString(outputEncoding);
|
|
579
|
+
return resultBuffer;
|
|
580
|
+
}
|
|
581
|
+
var combined = Buffer.concat(this._chunks);
|
|
582
|
+
var resultJson2 = _cryptoCipheriv.applySync(void 0, [
|
|
583
|
+
this._algorithm,
|
|
584
|
+
this._key.toString("base64"),
|
|
585
|
+
this._iv.toString("base64"),
|
|
586
|
+
combined.toString("base64")
|
|
587
|
+
]);
|
|
588
|
+
var parsed2 = JSON.parse(resultJson2);
|
|
589
|
+
if (parsed2.authTag) this._authTag = Buffer.from(parsed2.authTag, "base64");
|
|
590
|
+
var resultBuffer2 = Buffer.from(parsed2.data, "base64");
|
|
591
|
+
if (outputEncoding && outputEncoding !== "buffer") return resultBuffer2.toString(outputEncoding);
|
|
592
|
+
return resultBuffer2;
|
|
593
|
+
};
|
|
594
|
+
SandboxCipher2.prototype.getAuthTag = function getAuthTag() {
|
|
595
|
+
if (!this._finalized) throw new Error("Cannot call getAuthTag before final()");
|
|
596
|
+
if (!this._authTag) throw new Error("Auth tag is only available for GCM ciphers");
|
|
597
|
+
return this._authTag;
|
|
598
|
+
};
|
|
599
|
+
SandboxCipher2.prototype.setAAD = function setAAD(data) {
|
|
600
|
+
if (this._sessionId >= 0) {
|
|
601
|
+
var buf = typeof data === "string" ? Buffer.from(data, "utf8") : Buffer.from(data);
|
|
602
|
+
_cryptoCipherivUpdate.applySync(void 0, [this._sessionId, "", JSON.stringify({ setAAD: buf.toString("base64") })]);
|
|
603
|
+
}
|
|
604
|
+
return this;
|
|
605
|
+
};
|
|
606
|
+
SandboxCipher2.prototype.setAutoPadding = function setAutoPadding(autoPadding) {
|
|
607
|
+
if (this._sessionId >= 0) {
|
|
608
|
+
_cryptoCipherivUpdate.applySync(void 0, [this._sessionId, "", JSON.stringify({ setAutoPadding: autoPadding !== false })]);
|
|
609
|
+
}
|
|
610
|
+
return this;
|
|
611
|
+
};
|
|
612
|
+
result2.createCipheriv = function createCipheriv(algorithm, key, iv) {
|
|
613
|
+
return new SandboxCipher2(algorithm, key, iv);
|
|
614
|
+
};
|
|
615
|
+
result2.Cipheriv = SandboxCipher2;
|
|
616
|
+
}
|
|
617
|
+
if (typeof _cryptoDecipheriv !== "undefined" || _useStatefulCipher) {
|
|
618
|
+
let SandboxDecipher2 = function(algorithm, key, iv) {
|
|
619
|
+
this._algorithm = algorithm;
|
|
620
|
+
this._key = typeof key === "string" ? Buffer.from(key, "utf8") : Buffer.from(key);
|
|
621
|
+
this._iv = typeof iv === "string" ? Buffer.from(iv, "utf8") : Buffer.from(iv);
|
|
622
|
+
this._authTag = null;
|
|
623
|
+
this._finalized = false;
|
|
624
|
+
if (_useStatefulCipher) {
|
|
625
|
+
this._sessionId = _cryptoCipherivCreate.applySync(void 0, [
|
|
626
|
+
"decipher",
|
|
627
|
+
algorithm,
|
|
628
|
+
this._key.toString("base64"),
|
|
629
|
+
this._iv.toString("base64")
|
|
630
|
+
]);
|
|
631
|
+
} else {
|
|
632
|
+
this._sessionId = -1;
|
|
633
|
+
this._chunks = [];
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
var SandboxDecipher = SandboxDecipher2;
|
|
637
|
+
SandboxDecipher2.prototype.update = function update(data, inputEncoding, outputEncoding) {
|
|
638
|
+
var buf;
|
|
639
|
+
if (typeof data === "string") {
|
|
640
|
+
buf = Buffer.from(data, inputEncoding || "utf8");
|
|
641
|
+
} else {
|
|
642
|
+
buf = Buffer.from(data);
|
|
643
|
+
}
|
|
644
|
+
if (this._sessionId >= 0) {
|
|
645
|
+
var resultBase64 = _cryptoCipherivUpdate.applySync(void 0, [this._sessionId, buf.toString("base64")]);
|
|
646
|
+
var resultBuffer = Buffer.from(resultBase64, "base64");
|
|
647
|
+
if (outputEncoding && outputEncoding !== "buffer") return resultBuffer.toString(outputEncoding);
|
|
648
|
+
return resultBuffer;
|
|
649
|
+
}
|
|
650
|
+
this._chunks.push(buf);
|
|
651
|
+
if (outputEncoding && outputEncoding !== "buffer") return "";
|
|
652
|
+
return Buffer.alloc(0);
|
|
653
|
+
};
|
|
654
|
+
SandboxDecipher2.prototype.final = function final(outputEncoding) {
|
|
655
|
+
if (this._finalized) throw new Error("Attempting to call final() after already finalized");
|
|
656
|
+
this._finalized = true;
|
|
657
|
+
if (this._sessionId >= 0) {
|
|
658
|
+
if (this._authTag) {
|
|
659
|
+
_cryptoCipherivUpdate.applySync(void 0, [this._sessionId, "", JSON.stringify({ setAuthTag: this._authTag.toString("base64") })]);
|
|
660
|
+
}
|
|
661
|
+
var resultJson = _cryptoCipherivFinal.applySync(void 0, [this._sessionId]);
|
|
662
|
+
var parsed = JSON.parse(resultJson);
|
|
663
|
+
var resultBuffer = Buffer.from(parsed.data, "base64");
|
|
664
|
+
if (outputEncoding && outputEncoding !== "buffer") return resultBuffer.toString(outputEncoding);
|
|
665
|
+
return resultBuffer;
|
|
666
|
+
}
|
|
667
|
+
var combined = Buffer.concat(this._chunks);
|
|
668
|
+
var options = {};
|
|
669
|
+
if (this._authTag) options.authTag = this._authTag.toString("base64");
|
|
670
|
+
var resultBase64 = _cryptoDecipheriv.applySync(void 0, [
|
|
671
|
+
this._algorithm,
|
|
672
|
+
this._key.toString("base64"),
|
|
673
|
+
this._iv.toString("base64"),
|
|
674
|
+
combined.toString("base64"),
|
|
675
|
+
JSON.stringify(options)
|
|
676
|
+
]);
|
|
677
|
+
var resultBuffer2 = Buffer.from(resultBase64, "base64");
|
|
678
|
+
if (outputEncoding && outputEncoding !== "buffer") return resultBuffer2.toString(outputEncoding);
|
|
679
|
+
return resultBuffer2;
|
|
680
|
+
};
|
|
681
|
+
SandboxDecipher2.prototype.setAuthTag = function setAuthTag(tag) {
|
|
682
|
+
this._authTag = typeof tag === "string" ? Buffer.from(tag, "base64") : Buffer.from(tag);
|
|
683
|
+
return this;
|
|
684
|
+
};
|
|
685
|
+
SandboxDecipher2.prototype.setAAD = function setAAD(data) {
|
|
686
|
+
if (this._sessionId >= 0) {
|
|
687
|
+
var buf = typeof data === "string" ? Buffer.from(data, "utf8") : Buffer.from(data);
|
|
688
|
+
_cryptoCipherivUpdate.applySync(void 0, [this._sessionId, "", JSON.stringify({ setAAD: buf.toString("base64") })]);
|
|
689
|
+
}
|
|
690
|
+
return this;
|
|
691
|
+
};
|
|
692
|
+
SandboxDecipher2.prototype.setAutoPadding = function setAutoPadding(autoPadding) {
|
|
693
|
+
if (this._sessionId >= 0) {
|
|
694
|
+
_cryptoCipherivUpdate.applySync(void 0, [this._sessionId, "", JSON.stringify({ setAutoPadding: autoPadding !== false })]);
|
|
695
|
+
}
|
|
696
|
+
return this;
|
|
697
|
+
};
|
|
698
|
+
result2.createDecipheriv = function createDecipheriv(algorithm, key, iv) {
|
|
699
|
+
return new SandboxDecipher2(algorithm, key, iv);
|
|
700
|
+
};
|
|
701
|
+
result2.Decipheriv = SandboxDecipher2;
|
|
702
|
+
}
|
|
703
|
+
if (typeof _cryptoSign !== "undefined") {
|
|
704
|
+
result2.sign = function sign(algorithm, data, key) {
|
|
705
|
+
var dataBuf = typeof data === "string" ? Buffer.from(data, "utf8") : Buffer.from(data);
|
|
706
|
+
var keyPem;
|
|
707
|
+
if (typeof key === "string") {
|
|
708
|
+
keyPem = key;
|
|
709
|
+
} else if (key && typeof key === "object" && key._pem) {
|
|
710
|
+
keyPem = key._pem;
|
|
711
|
+
} else if (Buffer.isBuffer(key)) {
|
|
712
|
+
keyPem = key.toString("utf8");
|
|
713
|
+
} else {
|
|
714
|
+
keyPem = String(key);
|
|
715
|
+
}
|
|
716
|
+
var sigBase64 = _cryptoSign.applySync(void 0, [
|
|
717
|
+
algorithm,
|
|
718
|
+
dataBuf.toString("base64"),
|
|
719
|
+
keyPem
|
|
720
|
+
]);
|
|
721
|
+
return Buffer.from(sigBase64, "base64");
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
if (typeof _cryptoVerify !== "undefined") {
|
|
725
|
+
result2.verify = function verify(algorithm, data, key, signature) {
|
|
726
|
+
var dataBuf = typeof data === "string" ? Buffer.from(data, "utf8") : Buffer.from(data);
|
|
727
|
+
var keyPem;
|
|
728
|
+
if (typeof key === "string") {
|
|
729
|
+
keyPem = key;
|
|
730
|
+
} else if (key && typeof key === "object" && key._pem) {
|
|
731
|
+
keyPem = key._pem;
|
|
732
|
+
} else if (Buffer.isBuffer(key)) {
|
|
733
|
+
keyPem = key.toString("utf8");
|
|
734
|
+
} else {
|
|
735
|
+
keyPem = String(key);
|
|
736
|
+
}
|
|
737
|
+
var sigBuf = typeof signature === "string" ? Buffer.from(signature, "base64") : Buffer.from(signature);
|
|
738
|
+
return _cryptoVerify.applySync(void 0, [
|
|
739
|
+
algorithm,
|
|
740
|
+
dataBuf.toString("base64"),
|
|
741
|
+
keyPem,
|
|
742
|
+
sigBuf.toString("base64")
|
|
743
|
+
]);
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
if (typeof _cryptoGenerateKeyPairSync !== "undefined") {
|
|
747
|
+
let SandboxKeyObject2 = function(type, pem) {
|
|
748
|
+
this.type = type;
|
|
749
|
+
this._pem = pem;
|
|
750
|
+
};
|
|
751
|
+
var SandboxKeyObject = SandboxKeyObject2;
|
|
752
|
+
SandboxKeyObject2.prototype.export = function exportKey(options) {
|
|
753
|
+
if (!options || options.format === "pem") {
|
|
754
|
+
return this._pem;
|
|
755
|
+
}
|
|
756
|
+
if (options.format === "der") {
|
|
757
|
+
var lines = this._pem.split("\n").filter(function(l) {
|
|
758
|
+
return l && l.indexOf("-----") !== 0;
|
|
759
|
+
});
|
|
760
|
+
return Buffer.from(lines.join(""), "base64");
|
|
761
|
+
}
|
|
762
|
+
return this._pem;
|
|
763
|
+
};
|
|
764
|
+
SandboxKeyObject2.prototype.toString = function() {
|
|
765
|
+
return this._pem;
|
|
766
|
+
};
|
|
767
|
+
result2.generateKeyPairSync = function generateKeyPairSync(type, options) {
|
|
768
|
+
var opts = {};
|
|
769
|
+
if (options) {
|
|
770
|
+
if (options.modulusLength !== void 0) opts.modulusLength = options.modulusLength;
|
|
771
|
+
if (options.publicExponent !== void 0) opts.publicExponent = options.publicExponent;
|
|
772
|
+
if (options.namedCurve !== void 0) opts.namedCurve = options.namedCurve;
|
|
773
|
+
if (options.divisorLength !== void 0) opts.divisorLength = options.divisorLength;
|
|
774
|
+
if (options.primeLength !== void 0) opts.primeLength = options.primeLength;
|
|
775
|
+
}
|
|
776
|
+
var resultJson = _cryptoGenerateKeyPairSync.applySync(void 0, [
|
|
777
|
+
type,
|
|
778
|
+
JSON.stringify(opts)
|
|
779
|
+
]);
|
|
780
|
+
var parsed = JSON.parse(resultJson);
|
|
781
|
+
if (options && options.publicKeyEncoding && options.privateKeyEncoding) {
|
|
782
|
+
return { publicKey: parsed.publicKey, privateKey: parsed.privateKey };
|
|
783
|
+
}
|
|
784
|
+
return {
|
|
785
|
+
publicKey: new SandboxKeyObject2("public", parsed.publicKey),
|
|
786
|
+
privateKey: new SandboxKeyObject2("private", parsed.privateKey)
|
|
787
|
+
};
|
|
788
|
+
};
|
|
789
|
+
result2.generateKeyPair = function generateKeyPair(type, options, callback) {
|
|
790
|
+
try {
|
|
791
|
+
var pair = result2.generateKeyPairSync(type, options);
|
|
792
|
+
callback(null, pair.publicKey, pair.privateKey);
|
|
793
|
+
} catch (e) {
|
|
794
|
+
callback(e);
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
result2.createPublicKey = function createPublicKey(key) {
|
|
798
|
+
if (typeof key === "string") {
|
|
799
|
+
if (key.indexOf("-----BEGIN") === -1) {
|
|
800
|
+
throw new TypeError("error:0900006e:PEM routines:OPENSSL_internal:NO_START_LINE");
|
|
801
|
+
}
|
|
802
|
+
return new SandboxKeyObject2("public", key);
|
|
803
|
+
}
|
|
804
|
+
if (key && typeof key === "object" && key._pem) {
|
|
805
|
+
return new SandboxKeyObject2("public", key._pem);
|
|
806
|
+
}
|
|
807
|
+
if (key && typeof key === "object" && key.type === "private") {
|
|
808
|
+
return new SandboxKeyObject2("public", key._pem);
|
|
809
|
+
}
|
|
810
|
+
if (key && typeof key === "object" && key.key) {
|
|
811
|
+
var keyData = typeof key.key === "string" ? key.key : key.key.toString("utf8");
|
|
812
|
+
return new SandboxKeyObject2("public", keyData);
|
|
813
|
+
}
|
|
814
|
+
if (Buffer.isBuffer(key)) {
|
|
815
|
+
var keyStr = key.toString("utf8");
|
|
816
|
+
if (keyStr.indexOf("-----BEGIN") === -1) {
|
|
817
|
+
throw new TypeError("error:0900006e:PEM routines:OPENSSL_internal:NO_START_LINE");
|
|
818
|
+
}
|
|
819
|
+
return new SandboxKeyObject2("public", keyStr);
|
|
820
|
+
}
|
|
821
|
+
return new SandboxKeyObject2("public", String(key));
|
|
822
|
+
};
|
|
823
|
+
result2.createPrivateKey = function createPrivateKey(key) {
|
|
824
|
+
if (typeof key === "string") {
|
|
825
|
+
if (key.indexOf("-----BEGIN") === -1) {
|
|
826
|
+
throw new TypeError("error:0900006e:PEM routines:OPENSSL_internal:NO_START_LINE");
|
|
827
|
+
}
|
|
828
|
+
return new SandboxKeyObject2("private", key);
|
|
829
|
+
}
|
|
830
|
+
if (key && typeof key === "object" && key._pem) {
|
|
831
|
+
return new SandboxKeyObject2("private", key._pem);
|
|
832
|
+
}
|
|
833
|
+
if (key && typeof key === "object" && key.key) {
|
|
834
|
+
var keyData = typeof key.key === "string" ? key.key : key.key.toString("utf8");
|
|
835
|
+
return new SandboxKeyObject2("private", keyData);
|
|
836
|
+
}
|
|
837
|
+
if (Buffer.isBuffer(key)) {
|
|
838
|
+
var keyStr = key.toString("utf8");
|
|
839
|
+
if (keyStr.indexOf("-----BEGIN") === -1) {
|
|
840
|
+
throw new TypeError("error:0900006e:PEM routines:OPENSSL_internal:NO_START_LINE");
|
|
841
|
+
}
|
|
842
|
+
return new SandboxKeyObject2("private", keyStr);
|
|
843
|
+
}
|
|
844
|
+
return new SandboxKeyObject2("private", String(key));
|
|
845
|
+
};
|
|
846
|
+
result2.createSecretKey = function createSecretKey(key) {
|
|
847
|
+
if (typeof key === "string") {
|
|
848
|
+
return new SandboxKeyObject2("secret", key);
|
|
849
|
+
}
|
|
850
|
+
if (Buffer.isBuffer(key) || key instanceof Uint8Array) {
|
|
851
|
+
return new SandboxKeyObject2("secret", Buffer.from(key).toString("utf8"));
|
|
852
|
+
}
|
|
853
|
+
return new SandboxKeyObject2("secret", String(key));
|
|
854
|
+
};
|
|
855
|
+
result2.KeyObject = SandboxKeyObject2;
|
|
856
|
+
}
|
|
857
|
+
if (typeof _cryptoSubtle !== "undefined") {
|
|
858
|
+
let SandboxCryptoKey2 = function(keyData) {
|
|
859
|
+
this.type = keyData.type;
|
|
860
|
+
this.extractable = keyData.extractable;
|
|
861
|
+
this.algorithm = keyData.algorithm;
|
|
862
|
+
this.usages = keyData.usages;
|
|
863
|
+
this._keyData = keyData;
|
|
864
|
+
}, toBase642 = function(data) {
|
|
865
|
+
if (typeof data === "string") return Buffer.from(data).toString("base64");
|
|
866
|
+
if (data instanceof ArrayBuffer) return Buffer.from(new Uint8Array(data)).toString("base64");
|
|
867
|
+
if (ArrayBuffer.isView(data)) return Buffer.from(new Uint8Array(data.buffer, data.byteOffset, data.byteLength)).toString("base64");
|
|
868
|
+
return Buffer.from(data).toString("base64");
|
|
869
|
+
}, subtleCall2 = function(reqObj) {
|
|
870
|
+
return _cryptoSubtle.applySync(void 0, [JSON.stringify(reqObj)]);
|
|
871
|
+
}, normalizeAlgo2 = function(algorithm) {
|
|
872
|
+
if (typeof algorithm === "string") return { name: algorithm };
|
|
873
|
+
return algorithm;
|
|
874
|
+
};
|
|
875
|
+
var SandboxCryptoKey = SandboxCryptoKey2, toBase64 = toBase642, subtleCall = subtleCall2, normalizeAlgo = normalizeAlgo2;
|
|
876
|
+
var SandboxSubtle = {};
|
|
877
|
+
SandboxSubtle.digest = function digest(algorithm, data) {
|
|
878
|
+
return Promise.resolve().then(function() {
|
|
879
|
+
var algo = normalizeAlgo2(algorithm);
|
|
880
|
+
var result22 = JSON.parse(subtleCall2({
|
|
881
|
+
op: "digest",
|
|
882
|
+
algorithm: algo.name,
|
|
883
|
+
data: toBase642(data)
|
|
884
|
+
}));
|
|
885
|
+
var buf = Buffer.from(result22.data, "base64");
|
|
886
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
887
|
+
});
|
|
888
|
+
};
|
|
889
|
+
SandboxSubtle.generateKey = function generateKey(algorithm, extractable, keyUsages) {
|
|
890
|
+
return Promise.resolve().then(function() {
|
|
891
|
+
var algo = normalizeAlgo2(algorithm);
|
|
892
|
+
var reqAlgo = Object.assign({}, algo);
|
|
893
|
+
if (reqAlgo.hash) reqAlgo.hash = normalizeAlgo2(reqAlgo.hash);
|
|
894
|
+
if (reqAlgo.publicExponent) {
|
|
895
|
+
reqAlgo.publicExponent = Buffer.from(new Uint8Array(reqAlgo.publicExponent.buffer || reqAlgo.publicExponent)).toString("base64");
|
|
896
|
+
}
|
|
897
|
+
var result22 = JSON.parse(subtleCall2({
|
|
898
|
+
op: "generateKey",
|
|
899
|
+
algorithm: reqAlgo,
|
|
900
|
+
extractable,
|
|
901
|
+
usages: Array.from(keyUsages)
|
|
902
|
+
}));
|
|
903
|
+
if (result22.publicKey && result22.privateKey) {
|
|
904
|
+
return {
|
|
905
|
+
publicKey: new SandboxCryptoKey2(result22.publicKey),
|
|
906
|
+
privateKey: new SandboxCryptoKey2(result22.privateKey)
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
return new SandboxCryptoKey2(result22.key);
|
|
910
|
+
});
|
|
911
|
+
};
|
|
912
|
+
SandboxSubtle.importKey = function importKey(format, keyData, algorithm, extractable, keyUsages) {
|
|
913
|
+
return Promise.resolve().then(function() {
|
|
914
|
+
var algo = normalizeAlgo2(algorithm);
|
|
915
|
+
var reqAlgo = Object.assign({}, algo);
|
|
916
|
+
if (reqAlgo.hash) reqAlgo.hash = normalizeAlgo2(reqAlgo.hash);
|
|
917
|
+
var serializedKeyData;
|
|
918
|
+
if (format === "jwk") {
|
|
919
|
+
serializedKeyData = keyData;
|
|
920
|
+
} else if (format === "raw") {
|
|
921
|
+
serializedKeyData = toBase642(keyData);
|
|
922
|
+
} else {
|
|
923
|
+
serializedKeyData = toBase642(keyData);
|
|
924
|
+
}
|
|
925
|
+
var result22 = JSON.parse(subtleCall2({
|
|
926
|
+
op: "importKey",
|
|
927
|
+
format,
|
|
928
|
+
keyData: serializedKeyData,
|
|
929
|
+
algorithm: reqAlgo,
|
|
930
|
+
extractable,
|
|
931
|
+
usages: Array.from(keyUsages)
|
|
932
|
+
}));
|
|
933
|
+
return new SandboxCryptoKey2(result22.key);
|
|
934
|
+
});
|
|
935
|
+
};
|
|
936
|
+
SandboxSubtle.exportKey = function exportKey(format, key) {
|
|
937
|
+
return Promise.resolve().then(function() {
|
|
938
|
+
var result22 = JSON.parse(subtleCall2({
|
|
939
|
+
op: "exportKey",
|
|
940
|
+
format,
|
|
941
|
+
key: key._keyData
|
|
942
|
+
}));
|
|
943
|
+
if (format === "jwk") return result22.jwk;
|
|
944
|
+
var buf = Buffer.from(result22.data, "base64");
|
|
945
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
946
|
+
});
|
|
947
|
+
};
|
|
948
|
+
SandboxSubtle.encrypt = function encrypt(algorithm, key, data) {
|
|
949
|
+
return Promise.resolve().then(function() {
|
|
950
|
+
var algo = normalizeAlgo2(algorithm);
|
|
951
|
+
var reqAlgo = Object.assign({}, algo);
|
|
952
|
+
if (reqAlgo.iv) reqAlgo.iv = toBase642(reqAlgo.iv);
|
|
953
|
+
if (reqAlgo.additionalData) reqAlgo.additionalData = toBase642(reqAlgo.additionalData);
|
|
954
|
+
var result22 = JSON.parse(subtleCall2({
|
|
955
|
+
op: "encrypt",
|
|
956
|
+
algorithm: reqAlgo,
|
|
957
|
+
key: key._keyData,
|
|
958
|
+
data: toBase642(data)
|
|
959
|
+
}));
|
|
960
|
+
var buf = Buffer.from(result22.data, "base64");
|
|
961
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
962
|
+
});
|
|
963
|
+
};
|
|
964
|
+
SandboxSubtle.decrypt = function decrypt(algorithm, key, data) {
|
|
965
|
+
return Promise.resolve().then(function() {
|
|
966
|
+
var algo = normalizeAlgo2(algorithm);
|
|
967
|
+
var reqAlgo = Object.assign({}, algo);
|
|
968
|
+
if (reqAlgo.iv) reqAlgo.iv = toBase642(reqAlgo.iv);
|
|
969
|
+
if (reqAlgo.additionalData) reqAlgo.additionalData = toBase642(reqAlgo.additionalData);
|
|
970
|
+
var result22 = JSON.parse(subtleCall2({
|
|
971
|
+
op: "decrypt",
|
|
972
|
+
algorithm: reqAlgo,
|
|
973
|
+
key: key._keyData,
|
|
974
|
+
data: toBase642(data)
|
|
975
|
+
}));
|
|
976
|
+
var buf = Buffer.from(result22.data, "base64");
|
|
977
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
978
|
+
});
|
|
979
|
+
};
|
|
980
|
+
SandboxSubtle.deriveBits = function deriveBits(algorithm, baseKey, length) {
|
|
981
|
+
return Promise.resolve().then(function() {
|
|
982
|
+
var algo = normalizeAlgo2(algorithm);
|
|
983
|
+
var reqAlgo = Object.assign({}, algo);
|
|
984
|
+
if (reqAlgo.hash) reqAlgo.hash = normalizeAlgo2(reqAlgo.hash);
|
|
985
|
+
if (reqAlgo.salt) reqAlgo.salt = toBase642(reqAlgo.salt);
|
|
986
|
+
var result22 = JSON.parse(subtleCall2({
|
|
987
|
+
op: "deriveBits",
|
|
988
|
+
algorithm: reqAlgo,
|
|
989
|
+
key: baseKey._keyData,
|
|
990
|
+
length
|
|
991
|
+
}));
|
|
992
|
+
var buf = Buffer.from(result22.data, "base64");
|
|
993
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
994
|
+
});
|
|
995
|
+
};
|
|
996
|
+
SandboxSubtle.sign = function sign(algorithm, key, data) {
|
|
997
|
+
return Promise.resolve().then(function() {
|
|
998
|
+
var result22 = JSON.parse(subtleCall2({
|
|
999
|
+
op: "sign",
|
|
1000
|
+
algorithm: normalizeAlgo2(algorithm),
|
|
1001
|
+
key: key._keyData,
|
|
1002
|
+
data: toBase642(data)
|
|
1003
|
+
}));
|
|
1004
|
+
var buf = Buffer.from(result22.data, "base64");
|
|
1005
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
1006
|
+
});
|
|
1007
|
+
};
|
|
1008
|
+
SandboxSubtle.verify = function verify(algorithm, key, signature, data) {
|
|
1009
|
+
return Promise.resolve().then(function() {
|
|
1010
|
+
var result22 = JSON.parse(subtleCall2({
|
|
1011
|
+
op: "verify",
|
|
1012
|
+
algorithm: normalizeAlgo2(algorithm),
|
|
1013
|
+
key: key._keyData,
|
|
1014
|
+
signature: toBase642(signature),
|
|
1015
|
+
data: toBase642(data)
|
|
1016
|
+
}));
|
|
1017
|
+
return result22.result;
|
|
1018
|
+
});
|
|
1019
|
+
};
|
|
1020
|
+
result2.subtle = SandboxSubtle;
|
|
1021
|
+
result2.webcrypto = { subtle: SandboxSubtle, getRandomValues: result2.randomFillSync };
|
|
1022
|
+
}
|
|
1023
|
+
if (typeof result2.getCurves !== "function") {
|
|
1024
|
+
result2.getCurves = function getCurves() {
|
|
1025
|
+
return [
|
|
1026
|
+
"prime256v1",
|
|
1027
|
+
"secp256r1",
|
|
1028
|
+
"secp384r1",
|
|
1029
|
+
"secp521r1",
|
|
1030
|
+
"secp256k1",
|
|
1031
|
+
"secp224r1",
|
|
1032
|
+
"secp192k1"
|
|
1033
|
+
];
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
if (typeof result2.getCiphers !== "function") {
|
|
1037
|
+
result2.getCiphers = function getCiphers() {
|
|
1038
|
+
return [
|
|
1039
|
+
"aes-128-cbc",
|
|
1040
|
+
"aes-128-gcm",
|
|
1041
|
+
"aes-192-cbc",
|
|
1042
|
+
"aes-192-gcm",
|
|
1043
|
+
"aes-256-cbc",
|
|
1044
|
+
"aes-256-gcm",
|
|
1045
|
+
"aes-128-ctr",
|
|
1046
|
+
"aes-192-ctr",
|
|
1047
|
+
"aes-256-ctr"
|
|
1048
|
+
];
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
if (typeof result2.getHashes !== "function") {
|
|
1052
|
+
result2.getHashes = function getHashes() {
|
|
1053
|
+
return ["md5", "sha1", "sha256", "sha384", "sha512"];
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
if (typeof result2.timingSafeEqual !== "function") {
|
|
1057
|
+
result2.timingSafeEqual = function timingSafeEqual(a, b) {
|
|
1058
|
+
if (a.length !== b.length) {
|
|
1059
|
+
throw new RangeError("Input buffers must have the same byte length");
|
|
1060
|
+
}
|
|
1061
|
+
var out = 0;
|
|
1062
|
+
for (var i = 0; i < a.length; i++) {
|
|
1063
|
+
out |= a[i] ^ b[i];
|
|
1064
|
+
}
|
|
1065
|
+
return out === 0;
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
return result2;
|
|
1069
|
+
}
|
|
1070
|
+
if (name2 === "stream") {
|
|
1071
|
+
if (typeof result2 === "function" && result2.prototype && typeof result2.Readable === "function") {
|
|
1072
|
+
var readableProto = result2.Readable.prototype;
|
|
1073
|
+
var streamProto = result2.prototype;
|
|
1074
|
+
if (readableProto && streamProto && !(readableProto instanceof result2)) {
|
|
1075
|
+
var currentParent = Object.getPrototypeOf(readableProto);
|
|
1076
|
+
Object.setPrototypeOf(streamProto, currentParent);
|
|
1077
|
+
Object.setPrototypeOf(readableProto, streamProto);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
return result2;
|
|
1081
|
+
}
|
|
188
1082
|
if (name2 === "path") {
|
|
189
1083
|
if (result2.win32 === null || result2.win32 === void 0) {
|
|
190
1084
|
result2.win32 = result2.posix || result2;
|
|
@@ -230,7 +1124,6 @@
|
|
|
230
1124
|
return result2;
|
|
231
1125
|
}
|
|
232
1126
|
var _deferredCoreModules = /* @__PURE__ */ new Set([
|
|
233
|
-
"net",
|
|
234
1127
|
"tls",
|
|
235
1128
|
"readline",
|
|
236
1129
|
"perf_hooks",
|
|
@@ -275,8 +1168,25 @@
|
|
|
275
1168
|
return _requireFrom(moduleName2, _currentModule.dirname);
|
|
276
1169
|
};
|
|
277
1170
|
__requireExposeCustomGlobal("require", __require);
|
|
1171
|
+
var _resolveCache = /* @__PURE__ */ Object.create(null);
|
|
278
1172
|
function _resolveFrom(moduleName2, fromDir2) {
|
|
279
|
-
const
|
|
1173
|
+
const cacheKey2 = fromDir2 + "\0" + moduleName2;
|
|
1174
|
+
if (cacheKey2 in _resolveCache) {
|
|
1175
|
+
const cached = _resolveCache[cacheKey2];
|
|
1176
|
+
if (cached === null) {
|
|
1177
|
+
const err = new Error("Cannot find module '" + moduleName2 + "'");
|
|
1178
|
+
err.code = "MODULE_NOT_FOUND";
|
|
1179
|
+
throw err;
|
|
1180
|
+
}
|
|
1181
|
+
return cached;
|
|
1182
|
+
}
|
|
1183
|
+
let resolved2;
|
|
1184
|
+
if (typeof _resolveModuleSync !== "undefined") {
|
|
1185
|
+
resolved2 = _resolveModuleSync.applySync(void 0, [moduleName2, fromDir2]);
|
|
1186
|
+
} else {
|
|
1187
|
+
resolved2 = _resolveModule.applySyncPromise(void 0, [moduleName2, fromDir2]);
|
|
1188
|
+
}
|
|
1189
|
+
_resolveCache[cacheKey2] = resolved2;
|
|
280
1190
|
if (resolved2 === null) {
|
|
281
1191
|
const err = new Error("Cannot find module '" + moduleName2 + "'");
|
|
282
1192
|
err.code = "MODULE_NOT_FOUND";
|
|
@@ -405,6 +1315,18 @@
|
|
|
405
1315
|
_debugRequire("loaded", name, "dns-special");
|
|
406
1316
|
return _dnsModule;
|
|
407
1317
|
}
|
|
1318
|
+
if (name === "net") {
|
|
1319
|
+
if (__internalModuleCache["net"]) return __internalModuleCache["net"];
|
|
1320
|
+
__internalModuleCache["net"] = _netModule;
|
|
1321
|
+
_debugRequire("loaded", name, "net-special");
|
|
1322
|
+
return _netModule;
|
|
1323
|
+
}
|
|
1324
|
+
if (name === "tls") {
|
|
1325
|
+
if (__internalModuleCache["tls"]) return __internalModuleCache["tls"];
|
|
1326
|
+
__internalModuleCache["tls"] = _tlsModule;
|
|
1327
|
+
_debugRequire("loaded", name, "tls-special");
|
|
1328
|
+
return _tlsModule;
|
|
1329
|
+
}
|
|
408
1330
|
if (name === "os") {
|
|
409
1331
|
if (__internalModuleCache["os"]) return __internalModuleCache["os"];
|
|
410
1332
|
__internalModuleCache["os"] = _osModule;
|
|
@@ -522,7 +1444,19 @@
|
|
|
522
1444
|
end: _createChannel2(),
|
|
523
1445
|
asyncStart: _createChannel2(),
|
|
524
1446
|
asyncEnd: _createChannel2(),
|
|
525
|
-
error: _createChannel2()
|
|
1447
|
+
error: _createChannel2(),
|
|
1448
|
+
traceSync: function(fn, context, thisArg) {
|
|
1449
|
+
var args = Array.prototype.slice.call(arguments, 3);
|
|
1450
|
+
return fn.apply(thisArg, args);
|
|
1451
|
+
},
|
|
1452
|
+
tracePromise: function(fn, context, thisArg) {
|
|
1453
|
+
var args = Array.prototype.slice.call(arguments, 3);
|
|
1454
|
+
return fn.apply(thisArg, args);
|
|
1455
|
+
},
|
|
1456
|
+
traceCallback: function(fn, context, thisArg) {
|
|
1457
|
+
var args = Array.prototype.slice.call(arguments, 3);
|
|
1458
|
+
return fn.apply(thisArg, args);
|
|
1459
|
+
}
|
|
526
1460
|
};
|
|
527
1461
|
},
|
|
528
1462
|
Channel: function Channel(name2) {
|
|
@@ -549,7 +1483,12 @@
|
|
|
549
1483
|
if (_unsupportedCoreModules.has(name)) {
|
|
550
1484
|
throw new Error(name + " is not supported in sandbox");
|
|
551
1485
|
}
|
|
552
|
-
|
|
1486
|
+
if (__internalModuleCache[name]) {
|
|
1487
|
+
_debugRequire("name-cache-hit", name, name);
|
|
1488
|
+
return __internalModuleCache[name];
|
|
1489
|
+
}
|
|
1490
|
+
const isPath = name[0] === "." || name[0] === "/";
|
|
1491
|
+
const polyfillCode = isPath ? null : _loadPolyfill.applySyncPromise(void 0, [name]);
|
|
553
1492
|
if (polyfillCode !== null) {
|
|
554
1493
|
if (__internalModuleCache[name]) return __internalModuleCache[name];
|
|
555
1494
|
const moduleObj = { exports: {} };
|
|
@@ -566,6 +1505,14 @@
|
|
|
566
1505
|
_debugRequire("loaded", name, "polyfill");
|
|
567
1506
|
return __internalModuleCache[name];
|
|
568
1507
|
}
|
|
1508
|
+
const resolveCacheKey = fromDir + "\0" + name;
|
|
1509
|
+
if (resolveCacheKey in _resolveCache) {
|
|
1510
|
+
const cachedPath = _resolveCache[resolveCacheKey];
|
|
1511
|
+
if (cachedPath !== null && __internalModuleCache[cachedPath]) {
|
|
1512
|
+
_debugRequire("resolve-cache-hit", name, cachedPath);
|
|
1513
|
+
return __internalModuleCache[cachedPath];
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
569
1516
|
resolved = _resolveFrom(name, fromDir);
|
|
570
1517
|
cacheKey = resolved;
|
|
571
1518
|
if (__internalModuleCache[cacheKey]) {
|
|
@@ -576,7 +1523,12 @@
|
|
|
576
1523
|
_debugRequire("pending-hit", name, cacheKey);
|
|
577
1524
|
return _pendingModules[cacheKey].exports;
|
|
578
1525
|
}
|
|
579
|
-
|
|
1526
|
+
let source;
|
|
1527
|
+
if (typeof _loadFileSync !== "undefined") {
|
|
1528
|
+
source = _loadFileSync.applySync(void 0, [resolved]);
|
|
1529
|
+
} else {
|
|
1530
|
+
source = _loadFile.applySyncPromise(void 0, [resolved]);
|
|
1531
|
+
}
|
|
580
1532
|
if (source === null) {
|
|
581
1533
|
const err = new Error("Cannot find module '" + resolved + "'");
|
|
582
1534
|
err.code = "MODULE_NOT_FOUND";
|
|
@@ -642,6 +1594,9 @@
|
|
|
642
1594
|
_currentModule = prevModule;
|
|
643
1595
|
}
|
|
644
1596
|
__internalModuleCache[cacheKey] = module.exports;
|
|
1597
|
+
if (!isPath && name !== cacheKey) {
|
|
1598
|
+
__internalModuleCache[name] = module.exports;
|
|
1599
|
+
}
|
|
645
1600
|
delete _pendingModules[cacheKey];
|
|
646
1601
|
_debugRequire("loaded", name, cacheKey);
|
|
647
1602
|
return module.exports;
|