module-develop-kit 1.4.1 → 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 +5 -3
- package/dist/commonjs-virtual-dir/index3.js +5 -2
- package/dist/commonjs-virtual-dir/index4.js +2 -4
- package/dist/commonjs-virtual-dir/index5.js +2 -2
- package/dist/commonjs-virtual-dir/index7.js +4 -0
- package/dist/commonjs-virtual-dir/index8.js +4 -0
- package/dist/main.d.ts +107 -21
- package/dist/main.js +44 -40
- package/dist/src/outside-call/utils.js +1 -1
- package/dist/src/shield/crypto/index.js +53 -0
- package/dist/src/shield/crypto/sm2.js +4 -4
- package/dist/src/shield/crypto/sm4.js +15 -0
- package/dist/src/shield/crypto/util.js +23 -11
- package/dist/src/shield/gcm-crypto/axios-adapter.js +82 -0
- package/dist/src/shield/gcm-crypto/constants.js +4 -0
- package/dist/src/shield/gcm-crypto/gcm.config.js +60 -0
- package/dist/src/shield/gcm-crypto/index.js +20 -17
- package/dist/src/shield/gcm-crypto/utils.js +40 -0
- package/dist/types/axios.d.ts +10 -8
- 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/sdp-transform/lib/index.js +1 -1
- package/dist/vendor/token-types/lib/index.js +1 -1
- package/package.json +1 -1
- package/dist/src/shield/gcm-crypto/gcm.service.js +0 -29
- package/dist/src/shield/gcm-crypto/hex.js +0 -18
- package/dist/src/shield/gcm-crypto/init.js +0 -61
- package/dist/src/shield/gcm-crypto/string.js +0 -10
|
@@ -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,5 +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);
|
|
3
5
|
export {
|
|
4
|
-
|
|
6
|
+
a as default
|
|
5
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
|
*/
|
|
@@ -111,6 +126,16 @@ export declare enum ECallStatus {
|
|
|
111
126
|
RECONNECT = "reconnect"
|
|
112
127
|
}
|
|
113
128
|
|
|
129
|
+
declare enum EGcmHeaderKey {
|
|
130
|
+
publicKey = "X-Public-Key",
|
|
131
|
+
gcmPublicKey = "X-Client-SM2-Public-Key",
|
|
132
|
+
encryptIv = "X-Encrypted-Iv",
|
|
133
|
+
encryptKey = "X-Encrypted-Key",
|
|
134
|
+
encryptIvLow = "x-encrypted-iv",
|
|
135
|
+
encryptTag = "X-Encrypted-Tag",
|
|
136
|
+
encryptKeyLow = "x-encrypted-key"
|
|
137
|
+
}
|
|
138
|
+
|
|
114
139
|
declare enum EHeaderKey {
|
|
115
140
|
publicKey = "X-Public-Key",
|
|
116
141
|
gcmPublicKey = "X-Client-SM2-Public-Key",
|
|
@@ -168,7 +193,7 @@ declare type EventFnc = (...args: any) => void;
|
|
|
168
193
|
/**
|
|
169
194
|
* gcm-crypto
|
|
170
195
|
*/
|
|
171
|
-
export declare const
|
|
196
|
+
export declare const gcmCryptoPlugin: Plugin_2<IGcmCryptoOptions>;
|
|
172
197
|
|
|
173
198
|
/**
|
|
174
199
|
* 安全的解析html内容 防止xss攻击
|
|
@@ -313,30 +338,41 @@ export declare interface IFileDetectionResult {
|
|
|
313
338
|
mimeMatches?: boolean;
|
|
314
339
|
}
|
|
315
340
|
|
|
316
|
-
|
|
341
|
+
declare interface IGcmCryptoConfig {
|
|
317
342
|
/**
|
|
318
|
-
*
|
|
343
|
+
* 是否启用请求加密
|
|
344
|
+
* @default false
|
|
319
345
|
*/
|
|
320
|
-
|
|
346
|
+
enableRequestCrypto?: boolean;
|
|
321
347
|
/**
|
|
322
|
-
*
|
|
348
|
+
* 是否启用响应加密
|
|
349
|
+
* @default false
|
|
323
350
|
*/
|
|
324
|
-
|
|
351
|
+
enableResponseCrypto?: boolean;
|
|
325
352
|
}
|
|
326
353
|
|
|
327
354
|
/**
|
|
328
|
-
*
|
|
355
|
+
* GCM 加密插件配置选项
|
|
329
356
|
*/
|
|
330
|
-
|
|
357
|
+
declare interface IGcmCryptoOptions extends IGcmCryptoConfig {
|
|
358
|
+
/**
|
|
359
|
+
* 获取后端公钥的 API 函数
|
|
360
|
+
*/
|
|
361
|
+
getPublicKeyApi: () => Promise<string>;
|
|
362
|
+
/**
|
|
363
|
+
* Vue Router 实例或兼容接口
|
|
364
|
+
*/
|
|
365
|
+
router: TRouterLike;
|
|
366
|
+
}
|
|
331
367
|
|
|
332
368
|
export declare interface IResponseDataEncryptionReturn {
|
|
333
369
|
/**
|
|
334
370
|
* 响应头
|
|
335
371
|
*/
|
|
336
372
|
headers: {
|
|
337
|
-
[
|
|
338
|
-
[
|
|
339
|
-
[
|
|
373
|
+
[EGcmHeaderKey.encryptIv]: string;
|
|
374
|
+
[EGcmHeaderKey.encryptTag]: string;
|
|
375
|
+
[EGcmHeaderKey.encryptKey]: string;
|
|
340
376
|
};
|
|
341
377
|
/**
|
|
342
378
|
* 加密后的数据
|
|
@@ -422,29 +458,51 @@ export declare interface IUrlSanitizeOptions {
|
|
|
422
458
|
* 添加请求前加密回调
|
|
423
459
|
* @param callback
|
|
424
460
|
*/
|
|
425
|
-
export declare const requestDataBeforeGcmCrypto: (callback: TRequestBeforeCryptoCallBack) => void;
|
|
461
|
+
export declare const requestDataBeforeGcmCrypto: (callback: TRequestBeforeCryptoCallBack<InternalAxiosRequestConfig>) => void;
|
|
426
462
|
|
|
427
463
|
/**
|
|
428
464
|
* 请求数据加密
|
|
429
465
|
* @param publicKey 公钥
|
|
466
|
+
* @param _data 数据
|
|
467
|
+
* @deprecated 已废弃,请使用新的 gcm 方式进行加解密
|
|
468
|
+
*/
|
|
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
|
+
};
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* gcm 加密请求拦截器
|
|
481
|
+
*/
|
|
482
|
+
export declare const requestDataGcmCryptoInterceptor: <T>(config: InternalAxiosRequestConfig<T>) => Promise<InternalAxiosRequestConfig<T>>;
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* 请求数据通过gcm模式加密
|
|
486
|
+
* @param publicKey 公钥
|
|
430
487
|
* @param data 原始数据
|
|
431
488
|
* @param uri 当前请求的路径
|
|
432
489
|
*/
|
|
433
|
-
export declare const
|
|
490
|
+
export declare const requestDataGcmEncryption: <T>(publicKey: string, data: T, uri: string) => IResponseDataEncryptionReturn;
|
|
434
491
|
|
|
435
492
|
/**
|
|
436
|
-
*
|
|
493
|
+
* 添加响应前解密回调
|
|
494
|
+
* @param callback
|
|
437
495
|
*/
|
|
438
|
-
export declare const
|
|
496
|
+
export declare const responseDataBeforeGcmCrypto: <T = TAny>(callback: TRequestBeforeCryptoCallBack<AxiosResponse<T>>) => void;
|
|
439
497
|
|
|
440
498
|
/**
|
|
441
499
|
* 响应数据解密
|
|
442
|
-
* @param
|
|
443
|
-
* @
|
|
444
|
-
* @param uri
|
|
445
|
-
* @param headers
|
|
500
|
+
* @param stepCb
|
|
501
|
+
* @deprecated 已废弃,请使用新的 gcm 方式进行加解密
|
|
446
502
|
*/
|
|
447
|
-
export declare
|
|
503
|
+
export declare function responseDataEncryption<T>(stepCb: (_headers: {
|
|
504
|
+
[EHeaderKey.publicKey]: string;
|
|
505
|
+
}) => Promise<IResponseDataEncryptionStep>): Promise<T>;
|
|
448
506
|
|
|
449
507
|
/**
|
|
450
508
|
* gcm 解密响应
|
|
@@ -454,6 +512,15 @@ export declare const responseDataGcmCryptoInterceptor: <T extends {
|
|
|
454
512
|
data: unknown;
|
|
455
513
|
}>(response: AxiosResponse<T>) => AxiosResponse<T, any, {}>;
|
|
456
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
|
+
|
|
457
524
|
/**
|
|
458
525
|
* 消毒 URL,返回安全的 URL 或替代 URL
|
|
459
526
|
* @param url - 需要消毒的 URL
|
|
@@ -534,17 +601,36 @@ export { supportedExtensions }
|
|
|
534
601
|
|
|
535
602
|
export { supportedMimeTypes }
|
|
536
603
|
|
|
604
|
+
declare type TAny = any;
|
|
605
|
+
|
|
537
606
|
export declare type TData = _TData | _TData[];
|
|
538
607
|
|
|
539
608
|
declare type _TData = null | undefined | number | string | Record<string, any>;
|
|
540
609
|
|
|
541
610
|
export declare type TMaybeArray<T> = T[] | T;
|
|
542
611
|
|
|
612
|
+
/**
|
|
613
|
+
* 路由守卫函数
|
|
614
|
+
*/
|
|
615
|
+
declare type TNavigationGuard = (to: TAny, from: TAny, next: TNavigationGuardNext) => TAny | Promise<TAny>;
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* 路由守卫的 next 函数
|
|
619
|
+
*/
|
|
620
|
+
declare type TNavigationGuardNext = (to?: TAny) => void;
|
|
621
|
+
|
|
543
622
|
export declare type TNullable<T> = T | null;
|
|
544
623
|
|
|
545
624
|
export declare type TObj<K extends keyof any = string, T = any> = Record<K, T>;
|
|
546
625
|
|
|
547
|
-
declare type TRequestBeforeCryptoCallBack = (config:
|
|
626
|
+
declare type TRequestBeforeCryptoCallBack<T> = (config: T) => void;
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* 类 Router 接口,兼容 Vue Router 2/3/4
|
|
630
|
+
*/
|
|
631
|
+
declare interface TRouterLike {
|
|
632
|
+
beforeEach: (guard: TNavigationGuard) => () => void;
|
|
633
|
+
}
|
|
548
634
|
|
|
549
635
|
export declare type TUndefinable<T> = T | undefined;
|
|
550
636
|
|
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,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
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { s as
|
|
2
|
-
r.sm2.
|
|
3
|
-
const s = 1, c = (e, o) => `04${r.sm2.doEncrypt(o, e.toLowerCase(), s)}`, p = (e, o) => r.sm2.doDecrypt(o.toLowerCase().replace(/^04/, ""), e.toLowerCase(), s);
|
|
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);
|
|
4
3
|
export {
|
|
4
|
+
c as generateKeyPairHex,
|
|
5
5
|
p as sm2Decrypt,
|
|
6
|
-
|
|
6
|
+
a as sm2Encrypt
|
|
7
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
|
+
};
|
|
@@ -1,17 +1,29 @@
|
|
|
1
|
-
function o(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
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);
|
|
6
16
|
return btoa(e);
|
|
7
17
|
}
|
|
8
|
-
function
|
|
9
|
-
const
|
|
10
|
-
for (let t = 0; t <
|
|
11
|
-
e[t] =
|
|
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);
|
|
12
22
|
return Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
|
|
13
23
|
}
|
|
14
24
|
export {
|
|
15
|
-
|
|
16
|
-
o as
|
|
25
|
+
g as base64ToHex,
|
|
26
|
+
o as dataToStr,
|
|
27
|
+
i as generateRandomString,
|
|
28
|
+
a as hexToBase64
|
|
17
29
|
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { sm2 as K } from "../../../vendor/sm-crypto-v2/dist/index.js";
|
|
2
|
+
import { EGcmHeaderKey as a } from "./constants.js";
|
|
3
|
+
import { gcmConfig as r } from "./gcm.config.js";
|
|
4
|
+
import { requestDataGcmEncryption as h, responseDataGcmDecryption as E } from "./index.js";
|
|
5
|
+
import { formatUrlToGcmCryptoUri as d, sm2Decrypt as w, base64ToHex as D } from "./utils.js";
|
|
6
|
+
import { isNullOrUndefined as f } from "../../utils/is.js";
|
|
7
|
+
import "vue";
|
|
8
|
+
const g = {
|
|
9
|
+
install: (e, t) => {
|
|
10
|
+
r.init(t), t.router.beforeEach(async (o, c, n) => {
|
|
11
|
+
await r.initPublicKey(), n();
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}, x = (e) => {
|
|
15
|
+
r.addRequestBeforeCryptoCallback(e);
|
|
16
|
+
}, y = /* @__PURE__ */ new Map(), v = 10 * 60 * 1e3, l = setInterval(
|
|
17
|
+
() => {
|
|
18
|
+
const e = Date.now();
|
|
19
|
+
for (const [t, o] of y.entries())
|
|
20
|
+
e - o.timestamp > v && y.delete(t);
|
|
21
|
+
},
|
|
22
|
+
5 * 60 * 1e3
|
|
23
|
+
);
|
|
24
|
+
typeof l.unref == "function" && l.unref();
|
|
25
|
+
const i = (e, t) => e && (e[t] || e.get(t)) || "", R = async (e) => {
|
|
26
|
+
if (i(e.headers, "Content-Type") === "multipart/form-data" || !r.isEnableRequestCrypto(e) || !e.url || (r.publicKey || await r.initPublicKey(), !r.publicKey))
|
|
27
|
+
return e;
|
|
28
|
+
r.requestBeforeCryptoCallBacks.forEach((c) => {
|
|
29
|
+
c(e);
|
|
30
|
+
});
|
|
31
|
+
const { headers: t, data: o } = h(
|
|
32
|
+
r.publicKey,
|
|
33
|
+
e.data,
|
|
34
|
+
d(e.url)
|
|
35
|
+
);
|
|
36
|
+
if (e.data = f(e.data) ? e.data : o, r.isEnableResponseCrypto(e)) {
|
|
37
|
+
const { publicKey: c, privateKey: n } = K.generateKeyPairHex();
|
|
38
|
+
y.set(c, { privateKey: n, timestamp: Date.now() }), e.headers.set(a.gcmPublicKey, c);
|
|
39
|
+
}
|
|
40
|
+
return e.headers.set(t), e;
|
|
41
|
+
}, H = (e) => {
|
|
42
|
+
r.addResponseBeforeCryptoCallback(e);
|
|
43
|
+
}, _ = (e) => {
|
|
44
|
+
if (!r.isEnableResponseCrypto(e.config))
|
|
45
|
+
return e;
|
|
46
|
+
const t = i(e.headers, a.gcmPublicKey);
|
|
47
|
+
if (!t)
|
|
48
|
+
return e;
|
|
49
|
+
const o = y.get(t);
|
|
50
|
+
if (y.delete(t), !o)
|
|
51
|
+
throw new Error("[gcm-crypto] Private key not found, possible security issue or expired request");
|
|
52
|
+
const { privateKey: c } = o, { data: n, ...C } = e.data;
|
|
53
|
+
if (f(n))
|
|
54
|
+
return e;
|
|
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
|
+
throw new Error("[gcm-crypto] Missing required encryption headers");
|
|
58
|
+
try {
|
|
59
|
+
r.responseBeforeCryptoCallBacks.forEach((b) => {
|
|
60
|
+
b(e);
|
|
61
|
+
});
|
|
62
|
+
const s = w(c, D(u));
|
|
63
|
+
e.data = {
|
|
64
|
+
...C,
|
|
65
|
+
data: E(s, n, d(e.config.url), {
|
|
66
|
+
[a.encryptIv]: p,
|
|
67
|
+
[a.encryptKey]: s,
|
|
68
|
+
[a.encryptTag]: m
|
|
69
|
+
})
|
|
70
|
+
};
|
|
71
|
+
} catch (s) {
|
|
72
|
+
throw new Error(`[gcm-crypto] Decryption failed: ${s instanceof Error ? s.message : String(s)}`);
|
|
73
|
+
}
|
|
74
|
+
return e;
|
|
75
|
+
};
|
|
76
|
+
export {
|
|
77
|
+
g as gcmCryptoPlugin,
|
|
78
|
+
x as requestDataBeforeGcmCrypto,
|
|
79
|
+
R as requestDataGcmCryptoInterceptor,
|
|
80
|
+
H as responseDataBeforeGcmCrypto,
|
|
81
|
+
_ as responseDataGcmCryptoInterceptor
|
|
82
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var n = /* @__PURE__ */ ((t) => (t.publicKey = "X-Public-Key", t.gcmPublicKey = "X-Client-SM2-Public-Key", t.encryptIv = "X-Encrypted-Iv", t.encryptKey = "X-Encrypted-Key", t.encryptIvLow = "x-encrypted-iv", t.encryptTag = "X-Encrypted-Tag", t.encryptKeyLow = "x-encrypted-key", t))(n || {});
|
|
2
|
+
export {
|
|
3
|
+
n as EGcmHeaderKey
|
|
4
|
+
};
|