module-develop-kit 1.4.2 → 1.4.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/commonjs-virtual-dir/browser.js +5 -2
- package/dist/commonjs-virtual-dir/browser2.js +2 -5
- package/dist/commonjs-virtual-dir/index.js +3 -5
- package/dist/commonjs-virtual-dir/index2.js +7 -2
- package/dist/commonjs-virtual-dir/index3.js +3 -2
- package/dist/commonjs-virtual-dir/index4.js +2 -4
- package/dist/commonjs-virtual-dir/index5.js +4 -0
- package/dist/commonjs-virtual-dir/index6.js +4 -0
- package/dist/commonjs-virtual-dir/index7.js +4 -0
- package/dist/commonjs-virtual-dir/index8.js +4 -0
- package/dist/main.d.ts +48 -8
- package/dist/main.js +44 -40
- package/dist/src/outside-call/utils.js +1 -1
- package/dist/src/shield/crypto/const.js +4 -0
- package/dist/src/shield/crypto/index.js +53 -0
- package/dist/src/shield/crypto/sm2.js +7 -0
- package/dist/src/shield/crypto/sm4.js +15 -0
- package/dist/src/shield/crypto/util.js +29 -0
- package/dist/src/shield/gcm-crypto/axios-adapter.js +20 -20
- package/dist/src/shield/gcm-crypto/index.js +11 -11
- package/dist/vendor/@tokenizer/inflate/lib/ZipHandler.js +1 -1
- package/dist/vendor/base64-js/index.js +52 -0
- package/dist/vendor/debug/src/browser.js +1 -1
- package/dist/vendor/gm-crypt/index.js +10 -0
- package/dist/vendor/gm-crypt/src/crypt.js +60 -0
- package/dist/vendor/gm-crypt/src/sm4.js +513 -0
- package/dist/vendor/ieee754/index.js +1 -1
- package/dist/vendor/jsbn/index.js +714 -0
- package/dist/vendor/sdp-transform/lib/index.js +1 -1
- package/dist/vendor/sm-crypto/src/index.js +14 -0
- package/dist/vendor/sm-crypto/src/sm2/asn1.js +86 -0
- package/dist/vendor/sm-crypto/src/sm2/ec.js +205 -0
- package/dist/vendor/sm-crypto/src/sm2/index.js +114 -0
- package/dist/vendor/sm-crypto/src/sm2/sm3.js +71 -0
- package/dist/vendor/sm-crypto/src/sm2/utils.js +95 -0
- package/dist/vendor/sm-crypto/src/sm3/index.js +50 -0
- package/dist/vendor/sm-crypto/src/sm4/index.js +408 -0
- package/dist/vendor/token-types/lib/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
var t = o();
|
|
4
|
-
const a = /* @__PURE__ */ r(t);
|
|
1
|
+
import { __require as r } from "../vendor/sm-crypto/src/index.js";
|
|
2
|
+
var s = r();
|
|
5
3
|
export {
|
|
6
|
-
|
|
4
|
+
s
|
|
7
5
|
};
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { getDefaultExportFromCjs as r } from "./_commonjsHelpers.js";
|
|
2
|
+
import { __require as o } from "../vendor/sdp-transform/lib/index.js";
|
|
3
|
+
var t = o();
|
|
4
|
+
const a = /* @__PURE__ */ r(t);
|
|
5
|
+
export {
|
|
6
|
+
a as default
|
|
7
|
+
};
|
package/dist/main.d.ts
CHANGED
|
@@ -27,6 +27,21 @@ export declare const ALLOWED_FILE_TYPES: {
|
|
|
27
27
|
readonly model: Set<string>;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* 防重放攻击策略
|
|
32
|
+
* @param uid
|
|
33
|
+
* @param salt
|
|
34
|
+
* @param ts
|
|
35
|
+
* @param data
|
|
36
|
+
* @param headers
|
|
37
|
+
* @deprecated 已废弃,请使用新的 gcm 方式进行加解密
|
|
38
|
+
*/
|
|
39
|
+
export declare function antiReplyAttackStrategy({ uid, salt, ts, data, ...headers }: IAntiReplyAttackStrategy): {
|
|
40
|
+
"X-Sign-Timestamp": string;
|
|
41
|
+
"X-Sign-Nonce": string;
|
|
42
|
+
"X-Sign-Client": string;
|
|
43
|
+
};
|
|
44
|
+
|
|
30
45
|
/**
|
|
31
46
|
* 用于格式化输出会话过程中的日志信息
|
|
32
47
|
*/
|
|
@@ -448,16 +463,32 @@ export declare const requestDataBeforeGcmCrypto: (callback: TRequestBeforeCrypto
|
|
|
448
463
|
/**
|
|
449
464
|
* 请求数据加密
|
|
450
465
|
* @param publicKey 公钥
|
|
451
|
-
* @param
|
|
452
|
-
* @
|
|
466
|
+
* @param _data 数据
|
|
467
|
+
* @deprecated 已废弃,请使用新的 gcm 方式进行加解密
|
|
453
468
|
*/
|
|
454
|
-
export declare
|
|
469
|
+
export declare function requestDataEncryption(publicKey: string, _data?: TData): {
|
|
470
|
+
headers: {
|
|
471
|
+
"X-Encrypted-Iv": string;
|
|
472
|
+
"X-Encrypted-Key": string;
|
|
473
|
+
};
|
|
474
|
+
data: {
|
|
475
|
+
body: string;
|
|
476
|
+
};
|
|
477
|
+
};
|
|
455
478
|
|
|
456
479
|
/**
|
|
457
480
|
* gcm 加密请求拦截器
|
|
458
481
|
*/
|
|
459
482
|
export declare const requestDataGcmCryptoInterceptor: <T>(config: InternalAxiosRequestConfig<T>) => Promise<InternalAxiosRequestConfig<T>>;
|
|
460
483
|
|
|
484
|
+
/**
|
|
485
|
+
* 请求数据通过gcm模式加密
|
|
486
|
+
* @param publicKey 公钥
|
|
487
|
+
* @param data 原始数据
|
|
488
|
+
* @param uri 当前请求的路径
|
|
489
|
+
*/
|
|
490
|
+
export declare const requestDataGcmEncryption: <T>(publicKey: string, data: T, uri: string) => IResponseDataEncryptionReturn;
|
|
491
|
+
|
|
461
492
|
/**
|
|
462
493
|
* 添加响应前解密回调
|
|
463
494
|
* @param callback
|
|
@@ -466,12 +497,12 @@ export declare const responseDataBeforeGcmCrypto: <T = TAny>(callback: TRequestB
|
|
|
466
497
|
|
|
467
498
|
/**
|
|
468
499
|
* 响应数据解密
|
|
469
|
-
* @param
|
|
470
|
-
* @
|
|
471
|
-
* @param uri
|
|
472
|
-
* @param headers
|
|
500
|
+
* @param stepCb
|
|
501
|
+
* @deprecated 已废弃,请使用新的 gcm 方式进行加解密
|
|
473
502
|
*/
|
|
474
|
-
export declare
|
|
503
|
+
export declare function responseDataEncryption<T>(stepCb: (_headers: {
|
|
504
|
+
[EHeaderKey.publicKey]: string;
|
|
505
|
+
}) => Promise<IResponseDataEncryptionStep>): Promise<T>;
|
|
475
506
|
|
|
476
507
|
/**
|
|
477
508
|
* gcm 解密响应
|
|
@@ -481,6 +512,15 @@ export declare const responseDataGcmCryptoInterceptor: <T extends {
|
|
|
481
512
|
data: unknown;
|
|
482
513
|
}>(response: AxiosResponse<T>) => AxiosResponse<T, any, {}>;
|
|
483
514
|
|
|
515
|
+
/**
|
|
516
|
+
* 响应数据通过gcm模式解密
|
|
517
|
+
* @param sm4Key 解密后的 SM4 密钥
|
|
518
|
+
* @param data
|
|
519
|
+
* @param uri
|
|
520
|
+
* @param headers
|
|
521
|
+
*/
|
|
522
|
+
export declare const responseDataGcmDecryption: (sm4Key: string, data: string, uri: string, headers: IResponseDataEncryptionReturn["headers"]) => any;
|
|
523
|
+
|
|
484
524
|
/**
|
|
485
525
|
* 消毒 URL,返回安全的 URL 或替代 URL
|
|
486
526
|
* @param url - 需要消毒的 URL
|
package/dist/main.js
CHANGED
|
@@ -1,46 +1,50 @@
|
|
|
1
1
|
import { useCall as r } from "./src/outside-call/index.js";
|
|
2
2
|
import { createCosFileName as i } from "./src/shield/create-cos-file-name.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
3
|
+
import { antiReplyAttackStrategy as p, requestDataEncryption as s, responseDataEncryption as n } from "./src/shield/crypto/index.js";
|
|
4
|
+
import { ALLOWED_FILE_MIMES as E, ALLOWED_FILE_TYPES as l, detectFileByExtension as c, detectFileByMime as f, detectionFilesByExtension as x, detectionFilesByMime as y, isValidDocument as D, isValidFile as u, isValidImage as S, isValidVideo as d } from "./src/shield/file-detection.js";
|
|
5
|
+
import { requestDataGcmEncryption as _, responseDataGcmDecryption as I } from "./src/shield/gcm-crypto/index.js";
|
|
6
|
+
import { htmlSanitize as F } from "./src/shield/html-sanitize.js";
|
|
7
|
+
import { startNoDebugger as B } from "./src/shield/no-debugger.js";
|
|
8
|
+
import { isUrlSafe as L, sanitizeUrl as A, sanitizeUrls as V } from "./src/shield/url-sanitize.js";
|
|
9
|
+
import { EventBus as N } from "./src/utils/eventBus.js";
|
|
10
|
+
import { CallLogger as P } from "./src/outside-call/utils.js";
|
|
11
|
+
import { ECallStatus as T, EMIT_EVENT_NAME as U, SIP_CODE_MESSAGE as z, SIP_ERROR_CAUSES as W } from "./src/outside-call/constants.js";
|
|
12
|
+
import { supportedExtensions as h, supportedMimeTypes as k } from "./vendor/file-type/source/index.js";
|
|
13
|
+
import { gcmCryptoPlugin as Y, requestDataBeforeGcmCrypto as j, requestDataGcmCryptoInterceptor as w, responseDataBeforeGcmCrypto as H, responseDataGcmCryptoInterceptor as J } from "./src/shield/gcm-crypto/axios-adapter.js";
|
|
13
14
|
export {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
E as ALLOWED_FILE_MIMES,
|
|
16
|
+
l as ALLOWED_FILE_TYPES,
|
|
17
|
+
P as CallLogger,
|
|
18
|
+
T as ECallStatus,
|
|
19
|
+
U as EMIT_EVENT_NAME,
|
|
20
|
+
N as EventBus,
|
|
21
|
+
z as SIP_CODE_MESSAGE,
|
|
22
|
+
W as SIP_ERROR_CAUSES,
|
|
23
|
+
p as antiReplyAttackStrategy,
|
|
22
24
|
i as createCosFileName,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
25
|
+
c as detectFileByExtension,
|
|
26
|
+
f as detectFileByMime,
|
|
27
|
+
x as detectionFilesByExtension,
|
|
28
|
+
y as detectionFilesByMime,
|
|
29
|
+
Y as gcmCryptoPlugin,
|
|
30
|
+
F as htmlSanitize,
|
|
31
|
+
L as isUrlSafe,
|
|
32
|
+
D as isValidDocument,
|
|
33
|
+
u as isValidFile,
|
|
34
|
+
S as isValidImage,
|
|
35
|
+
d as isValidVideo,
|
|
36
|
+
j as requestDataBeforeGcmCrypto,
|
|
37
|
+
s as requestDataEncryption,
|
|
38
|
+
w as requestDataGcmCryptoInterceptor,
|
|
39
|
+
_ as requestDataGcmEncryption,
|
|
40
|
+
H as responseDataBeforeGcmCrypto,
|
|
41
|
+
n as responseDataEncryption,
|
|
42
|
+
J as responseDataGcmCryptoInterceptor,
|
|
43
|
+
I as responseDataGcmDecryption,
|
|
44
|
+
A as sanitizeUrl,
|
|
45
|
+
V as sanitizeUrls,
|
|
46
|
+
B as startNoDebugger,
|
|
47
|
+
h as supportedExtensions,
|
|
48
|
+
k as supportedMimeTypes,
|
|
45
49
|
r as useCall
|
|
46
50
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var t = /* @__PURE__ */ ((c) => (c.publicKey = "X-Public-Key", c.gcmPublicKey = "X-Client-SM2-Public-Key", c.encryptIv = "X-Encrypted-Iv", c.encryptKey = "X-Encrypted-Key", c.encryptIvLow = "x-encrypted-iv", c.encryptTag = "X-Encrypted-Tag", c.encryptKeyLow = "x-encrypted-key", c))(t || {});
|
|
2
|
+
export {
|
|
3
|
+
t as EHeaderKey
|
|
4
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { s as m } from "../../../commonjs-virtual-dir/index.js";
|
|
2
|
+
import { EHeaderKey as a } from "./const.js";
|
|
3
|
+
import { sm2Encrypt as d, generateKeyPairHex as g, sm2Decrypt as u } from "./sm2.js";
|
|
4
|
+
import { sm4Encrypt as K, sm4Decrypt as S } from "./sm4.js";
|
|
5
|
+
import { hexToBase64 as f, generateRandomString as p, base64ToHex as E, dataToStr as v } from "./util.js";
|
|
6
|
+
function $(o, c) {
|
|
7
|
+
const e = p(), n = p(), t = {
|
|
8
|
+
body: K(
|
|
9
|
+
{
|
|
10
|
+
key: e,
|
|
11
|
+
iv: n
|
|
12
|
+
},
|
|
13
|
+
c
|
|
14
|
+
)
|
|
15
|
+
}, r = f(d(o, e));
|
|
16
|
+
return {
|
|
17
|
+
headers: {
|
|
18
|
+
"X-Encrypted-Iv": n,
|
|
19
|
+
"X-Encrypted-Key": r
|
|
20
|
+
},
|
|
21
|
+
data: t
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async function h(o) {
|
|
25
|
+
const { publicKey: c, privateKey: e } = g(), { data: n, headers: t } = await o({ "X-Public-Key": c }), r = t[a.encryptIv] || t[a.encryptIvLow], s = t[a.encryptKey] || t[a.encryptKeyLow], y = u(e, E(s)), i = S(
|
|
26
|
+
{
|
|
27
|
+
iv: r,
|
|
28
|
+
key: y
|
|
29
|
+
},
|
|
30
|
+
n
|
|
31
|
+
);
|
|
32
|
+
return JSON.parse(i);
|
|
33
|
+
}
|
|
34
|
+
function k({
|
|
35
|
+
uid: o = "",
|
|
36
|
+
salt: c = "",
|
|
37
|
+
ts: e = 0,
|
|
38
|
+
data: n = "",
|
|
39
|
+
...t
|
|
40
|
+
}) {
|
|
41
|
+
const r = Date.now() + e, s = Math.random().toString(36).substring(2, 15), y = `${r}${o}${s}${v(n)}${c}`, i = m.sm3(y);
|
|
42
|
+
return {
|
|
43
|
+
...t,
|
|
44
|
+
"X-Sign-Timestamp": String(r),
|
|
45
|
+
"X-Sign-Nonce": s,
|
|
46
|
+
"X-Sign-Client": i
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
k as antiReplyAttackStrategy,
|
|
51
|
+
$ as requestDataEncryption,
|
|
52
|
+
h as responseDataEncryption
|
|
53
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { s as o } from "../../../commonjs-virtual-dir/index.js";
|
|
2
|
+
const c = o.sm2.generateKeyPairHex, s = 1, a = (e, r) => `04${o.sm2.doEncrypt(r, e.toLowerCase(), s)}`, p = (e, r) => o.sm2.doDecrypt(r.toLowerCase().replace(/^04/, ""), e.toLowerCase(), s);
|
|
3
|
+
export {
|
|
4
|
+
c as generateKeyPairHex,
|
|
5
|
+
p as sm2Decrypt,
|
|
6
|
+
a as sm2Encrypt
|
|
7
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { g as o } from "../../../commonjs-virtual-dir/index3.js";
|
|
2
|
+
import { dataToStr as r } from "./util.js";
|
|
3
|
+
const c = "cbc", n = (t, e) => new o.sm4({
|
|
4
|
+
key: t.key,
|
|
5
|
+
iv: t.iv,
|
|
6
|
+
mode: c
|
|
7
|
+
}).decrypt(r(e)), p = (t, e) => new o.sm4({
|
|
8
|
+
key: t.key,
|
|
9
|
+
iv: t.iv,
|
|
10
|
+
mode: c
|
|
11
|
+
}).encrypt(r(e));
|
|
12
|
+
export {
|
|
13
|
+
n as sm4Decrypt,
|
|
14
|
+
p as sm4Encrypt
|
|
15
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function o(n) {
|
|
2
|
+
return typeof n == "object" ? JSON.stringify(n ?? {}) : typeof n == "number" ? String(n) : n ?? "";
|
|
3
|
+
}
|
|
4
|
+
const i = (n = 16) => {
|
|
5
|
+
const r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
6
|
+
let e = "";
|
|
7
|
+
for (let t = 0; t < n; t++)
|
|
8
|
+
e += r.charAt(Math.floor(Math.random() * r.length));
|
|
9
|
+
return e;
|
|
10
|
+
};
|
|
11
|
+
function a(n) {
|
|
12
|
+
const r = new Uint8Array(n.length / 2);
|
|
13
|
+
for (let t = 0; t < n.length; t += 2)
|
|
14
|
+
r[t / 2] = parseInt(n.slice(t, t + 2), 16);
|
|
15
|
+
const e = String.fromCharCode(...r);
|
|
16
|
+
return btoa(e);
|
|
17
|
+
}
|
|
18
|
+
function g(n) {
|
|
19
|
+
const r = atob(n), e = new Uint8Array(r.length);
|
|
20
|
+
for (let t = 0; t < r.length; t++)
|
|
21
|
+
e[t] = r.charCodeAt(t);
|
|
22
|
+
return Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
g as base64ToHex,
|
|
26
|
+
o as dataToStr,
|
|
27
|
+
i as generateRandomString,
|
|
28
|
+
a as hexToBase64
|
|
29
|
+
};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { sm2 as K } from "../../../vendor/sm-crypto-v2/dist/index.js";
|
|
2
2
|
import { EGcmHeaderKey as a } from "./constants.js";
|
|
3
3
|
import { gcmConfig as r } from "./gcm.config.js";
|
|
4
|
-
import {
|
|
4
|
+
import { requestDataGcmEncryption as h, responseDataGcmDecryption as E } from "./index.js";
|
|
5
5
|
import { formatUrlToGcmCryptoUri as d, sm2Decrypt as w, base64ToHex as D } from "./utils.js";
|
|
6
6
|
import { isNullOrUndefined as f } from "../../utils/is.js";
|
|
7
7
|
import "vue";
|
|
8
|
-
const
|
|
8
|
+
const g = {
|
|
9
9
|
install: (e, t) => {
|
|
10
|
-
r.init(t), t.router.beforeEach(async (o,
|
|
11
|
-
await r.initPublicKey(),
|
|
10
|
+
r.init(t), t.router.beforeEach(async (o, c, n) => {
|
|
11
|
+
await r.initPublicKey(), n();
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
-
},
|
|
14
|
+
}, x = (e) => {
|
|
15
15
|
r.addRequestBeforeCryptoCallback(e);
|
|
16
|
-
}, y = /* @__PURE__ */ new Map(), v = 10 * 60 * 1e3,
|
|
16
|
+
}, y = /* @__PURE__ */ new Map(), v = 10 * 60 * 1e3, l = setInterval(
|
|
17
17
|
() => {
|
|
18
18
|
const e = Date.now();
|
|
19
19
|
for (const [t, o] of y.entries())
|
|
@@ -21,12 +21,12 @@ const x = {
|
|
|
21
21
|
},
|
|
22
22
|
5 * 60 * 1e3
|
|
23
23
|
);
|
|
24
|
-
typeof
|
|
24
|
+
typeof l.unref == "function" && l.unref();
|
|
25
25
|
const i = (e, t) => e && (e[t] || e.get(t)) || "", R = async (e) => {
|
|
26
26
|
if (i(e.headers, "Content-Type") === "multipart/form-data" || !r.isEnableRequestCrypto(e) || !e.url || (r.publicKey || await r.initPublicKey(), !r.publicKey))
|
|
27
27
|
return e;
|
|
28
|
-
r.requestBeforeCryptoCallBacks.forEach((
|
|
29
|
-
|
|
28
|
+
r.requestBeforeCryptoCallBacks.forEach((c) => {
|
|
29
|
+
c(e);
|
|
30
30
|
});
|
|
31
31
|
const { headers: t, data: o } = h(
|
|
32
32
|
r.publicKey,
|
|
@@ -34,8 +34,8 @@ const i = (e, t) => e && (e[t] || e.get(t)) || "", R = async (e) => {
|
|
|
34
34
|
d(e.url)
|
|
35
35
|
);
|
|
36
36
|
if (e.data = f(e.data) ? e.data : o, r.isEnableResponseCrypto(e)) {
|
|
37
|
-
const { publicKey:
|
|
38
|
-
y.set(
|
|
37
|
+
const { publicKey: c, privateKey: n } = K.generateKeyPairHex();
|
|
38
|
+
y.set(c, { privateKey: n, timestamp: Date.now() }), e.headers.set(a.gcmPublicKey, c);
|
|
39
39
|
}
|
|
40
40
|
return e.headers.set(t), e;
|
|
41
41
|
}, H = (e) => {
|
|
@@ -49,23 +49,23 @@ const i = (e, t) => e && (e[t] || e.get(t)) || "", R = async (e) => {
|
|
|
49
49
|
const o = y.get(t);
|
|
50
50
|
if (y.delete(t), !o)
|
|
51
51
|
throw new Error("[gcm-crypto] Private key not found, possible security issue or expired request");
|
|
52
|
-
const { privateKey:
|
|
53
|
-
if (f(
|
|
52
|
+
const { privateKey: c } = o, { data: n, ...C } = e.data;
|
|
53
|
+
if (f(n))
|
|
54
54
|
return e;
|
|
55
|
-
const p = i(e.headers, a.encryptIv), u = i(e.headers, a.encryptKey),
|
|
56
|
-
if (!p || !u || !
|
|
55
|
+
const p = i(e.headers, a.encryptIv), u = i(e.headers, a.encryptKey), m = i(e.headers, a.encryptTag);
|
|
56
|
+
if (!p || !u || !m)
|
|
57
57
|
throw new Error("[gcm-crypto] Missing required encryption headers");
|
|
58
58
|
try {
|
|
59
59
|
r.responseBeforeCryptoCallBacks.forEach((b) => {
|
|
60
60
|
b(e);
|
|
61
61
|
});
|
|
62
|
-
const s = w(
|
|
62
|
+
const s = w(c, D(u));
|
|
63
63
|
e.data = {
|
|
64
64
|
...C,
|
|
65
|
-
data: E(s,
|
|
65
|
+
data: E(s, n, d(e.config.url), {
|
|
66
66
|
[a.encryptIv]: p,
|
|
67
67
|
[a.encryptKey]: s,
|
|
68
|
-
[a.encryptTag]:
|
|
68
|
+
[a.encryptTag]: m
|
|
69
69
|
})
|
|
70
70
|
};
|
|
71
71
|
} catch (s) {
|
|
@@ -74,8 +74,8 @@ const i = (e, t) => e && (e[t] || e.get(t)) || "", R = async (e) => {
|
|
|
74
74
|
return e;
|
|
75
75
|
};
|
|
76
76
|
export {
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
g as gcmCryptoPlugin,
|
|
78
|
+
x as requestDataBeforeGcmCrypto,
|
|
79
79
|
R as requestDataGcmCryptoInterceptor,
|
|
80
80
|
H as responseDataBeforeGcmCrypto,
|
|
81
81
|
_ as responseDataGcmCryptoInterceptor
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { sm4 as d } from "../../../vendor/sm-crypto-v2/dist/index.js";
|
|
2
2
|
import { EGcmHeaderKey as r } from "./constants.js";
|
|
3
|
-
import { generateHex as y, dataToStr as T, stringToUtf8Bytes as u, bytesToBase64 as
|
|
4
|
-
const v = (s,
|
|
5
|
-
const t = y(12), e = y(16), { output: o, tag: a } = d.encrypt(T(
|
|
3
|
+
import { generateHex as y, dataToStr as T, stringToUtf8Bytes as u, bytesToBase64 as m, hexToBase64 as f, sm2Encrypt as E, base64ToHex as i, utf8BytesToString as S } from "./utils.js";
|
|
4
|
+
const v = (s, c, n) => {
|
|
5
|
+
const t = y(12), e = y(16), { output: o, tag: a } = d.encrypt(T(c), e, {
|
|
6
6
|
mode: "gcm",
|
|
7
7
|
iv: t,
|
|
8
|
-
associatedData: u(`uri=${
|
|
8
|
+
associatedData: u(`uri=${n}`),
|
|
9
9
|
output: "array",
|
|
10
10
|
outputTag: !0
|
|
11
11
|
});
|
|
@@ -14,18 +14,18 @@ const v = (s, n, c) => {
|
|
|
14
14
|
return {
|
|
15
15
|
headers: {
|
|
16
16
|
[r.encryptIv]: t,
|
|
17
|
-
[r.encryptTag]:
|
|
17
|
+
[r.encryptTag]: m(a),
|
|
18
18
|
[r.encryptKey]: f(E(s, e))
|
|
19
19
|
},
|
|
20
20
|
data: {
|
|
21
|
-
body:
|
|
21
|
+
body: m(o)
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
-
}, w = (s,
|
|
25
|
-
const e = t[r.encryptIv], o =
|
|
24
|
+
}, w = (s, c, n, t) => {
|
|
25
|
+
const e = t[r.encryptIv], o = i(t[r.encryptTag]), a = d.decrypt(i(c), s, {
|
|
26
26
|
mode: "gcm",
|
|
27
27
|
iv: e,
|
|
28
|
-
associatedData: u(`uri=${
|
|
28
|
+
associatedData: u(`uri=${n}`),
|
|
29
29
|
output: "array",
|
|
30
30
|
tag: o
|
|
31
31
|
}), g = S(a);
|
|
@@ -38,6 +38,6 @@ const v = (s, n, c) => {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
export {
|
|
41
|
-
v as
|
|
42
|
-
w as
|
|
41
|
+
v as requestDataGcmEncryption,
|
|
42
|
+
w as responseDataGcmDecryption
|
|
43
43
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UINT32_LE as h, StringType as k } from "../../../token-types/lib/index.js";
|
|
2
|
-
import D from "../../../../commonjs-virtual-dir/
|
|
2
|
+
import D from "../../../../commonjs-virtual-dir/browser.js";
|
|
3
3
|
import { Signature as c, EndOfCentralDirectoryRecordToken as L, FileHeader as E, DataDescriptor as y, LocalFileHeaderToken as S } from "./ZipToken.js";
|
|
4
4
|
function m(s) {
|
|
5
5
|
const t = new Uint8Array(h.len);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { __exports as F } from "../../commonjs-virtual-dir/index8.js";
|
|
2
|
+
var A;
|
|
3
|
+
function _() {
|
|
4
|
+
if (A) return F;
|
|
5
|
+
A = 1, F.byteLength = y, F.toByteArray = C, F.fromByteArray = B;
|
|
6
|
+
for (var c = [], n = [], l = typeof Uint8Array < "u" ? Uint8Array : Array, d = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", s = 0, p = d.length; s < p; ++s)
|
|
7
|
+
c[s] = d[s], n[d.charCodeAt(s)] = s;
|
|
8
|
+
n[45] = 62, n[95] = 63;
|
|
9
|
+
function x(r) {
|
|
10
|
+
var e = r.length;
|
|
11
|
+
if (e % 4 > 0)
|
|
12
|
+
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
13
|
+
var a = r.indexOf("=");
|
|
14
|
+
a === -1 && (a = e);
|
|
15
|
+
var o = a === e ? 0 : 4 - a % 4;
|
|
16
|
+
return [a, o];
|
|
17
|
+
}
|
|
18
|
+
function y(r) {
|
|
19
|
+
var e = x(r), a = e[0], o = e[1];
|
|
20
|
+
return (a + o) * 3 / 4 - o;
|
|
21
|
+
}
|
|
22
|
+
function i(r, e, a) {
|
|
23
|
+
return (e + a) * 3 / 4 - a;
|
|
24
|
+
}
|
|
25
|
+
function C(r) {
|
|
26
|
+
var e, a = x(r), o = a[0], v = a[1], t = new l(i(r, o, v)), h = 0, u = v > 0 ? o - 4 : o, f;
|
|
27
|
+
for (f = 0; f < u; f += 4)
|
|
28
|
+
e = n[r.charCodeAt(f)] << 18 | n[r.charCodeAt(f + 1)] << 12 | n[r.charCodeAt(f + 2)] << 6 | n[r.charCodeAt(f + 3)], t[h++] = e >> 16 & 255, t[h++] = e >> 8 & 255, t[h++] = e & 255;
|
|
29
|
+
return v === 2 && (e = n[r.charCodeAt(f)] << 2 | n[r.charCodeAt(f + 1)] >> 4, t[h++] = e & 255), v === 1 && (e = n[r.charCodeAt(f)] << 10 | n[r.charCodeAt(f + 1)] << 4 | n[r.charCodeAt(f + 2)] >> 2, t[h++] = e >> 8 & 255, t[h++] = e & 255), t;
|
|
30
|
+
}
|
|
31
|
+
function L(r) {
|
|
32
|
+
return c[r >> 18 & 63] + c[r >> 12 & 63] + c[r >> 6 & 63] + c[r & 63];
|
|
33
|
+
}
|
|
34
|
+
function g(r, e, a) {
|
|
35
|
+
for (var o, v = [], t = e; t < a; t += 3)
|
|
36
|
+
o = (r[t] << 16 & 16711680) + (r[t + 1] << 8 & 65280) + (r[t + 2] & 255), v.push(L(o));
|
|
37
|
+
return v.join("");
|
|
38
|
+
}
|
|
39
|
+
function B(r) {
|
|
40
|
+
for (var e, a = r.length, o = a % 3, v = [], t = 16383, h = 0, u = a - o; h < u; h += t)
|
|
41
|
+
v.push(g(r, h, h + t > u ? u : h + t));
|
|
42
|
+
return o === 1 ? (e = r[a - 1], v.push(
|
|
43
|
+
c[e >> 2] + c[e << 4 & 63] + "=="
|
|
44
|
+
)) : o === 2 && (e = (r[a - 2] << 8) + r[a - 1], v.push(
|
|
45
|
+
c[e >> 10] + c[e >> 4 & 63] + c[e << 2 & 63] + "="
|
|
46
|
+
)), v.join("");
|
|
47
|
+
}
|
|
48
|
+
return F;
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
_ as __require
|
|
52
|
+
};
|