@liujitcn/kratos-taro-app-core 0.0.66 → 0.0.67
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/package.json +1 -1
- package/src/api/base/v1/login.ts +0 -13
- package/src/api/base/v1/secret_crypto.ts +36 -0
- package/src/components/KratosTabBar.tsx +14 -1
- package/src/components/PasswordVerifyDialog.tsx +5 -8
- package/src/index.ts +1 -1
- package/src/locales/README.md +1 -1
- package/src/locales/en-US.json +4 -1
- package/src/locales/ja-JP.json +4 -1
- package/src/locales/zh-CN.json +4 -1
- package/src/locales/zh-TW.json +4 -1
- package/src/rpc/base/v1/login.ts +2 -42
- package/src/rpc/base/v1/mfa.ts +3 -3
- package/src/rpc/base/v1/oauth.ts +2 -2
- package/src/rpc/base/v1/secret_crypto.ts +49 -0
- package/src/rpc/common/v1/types.ts +4 -4
- package/src/utils/http.ts +3 -3
- package/src/utils/{passwordCrypto.ts → secretCrypto.ts} +35 -30
- package/src/views/pages/login/login.tsx +3 -9
package/package.json
CHANGED
package/src/api/base/v1/login.ts
CHANGED
|
@@ -5,8 +5,6 @@ import type {
|
|
|
5
5
|
LogoutRequest,
|
|
6
6
|
LoginRequest,
|
|
7
7
|
LoginResponse,
|
|
8
|
-
PasswordPublicKeyRequest,
|
|
9
|
-
PasswordPublicKeyResponse,
|
|
10
8
|
RefreshTokenRequest,
|
|
11
9
|
RefreshTokenResponse,
|
|
12
10
|
VerifyCaptchaRequest,
|
|
@@ -17,7 +15,6 @@ import type { Empty } from '../../../rpc/google/protobuf/empty'
|
|
|
17
15
|
|
|
18
16
|
const CAPTCHA_URL = '/v1/base/captcha'
|
|
19
17
|
const CAPTCHA_VERIFY_URL = '/v1/base/captcha/verify'
|
|
20
|
-
const PASSWORD_PUBLIC_KEY_URL = '/v1/base/password-public-key'
|
|
21
18
|
const SESSION_URL = '/v1/base/session'
|
|
22
19
|
const TOKEN_URL = '/v1/base/token'
|
|
23
20
|
|
|
@@ -43,16 +40,6 @@ export class LoginServiceImpl implements LoginService {
|
|
|
43
40
|
header: { Authorization: 'no-auth' },
|
|
44
41
|
})
|
|
45
42
|
}
|
|
46
|
-
/** 获取密码临时公钥 */
|
|
47
|
-
PasswordPublicKey(request: PasswordPublicKeyRequest): Promise<PasswordPublicKeyResponse> {
|
|
48
|
-
return http<PasswordPublicKeyResponse>({
|
|
49
|
-
url: `${PASSWORD_PUBLIC_KEY_URL}`,
|
|
50
|
-
method: 'GET',
|
|
51
|
-
authMode: 'none',
|
|
52
|
-
data: request,
|
|
53
|
-
header: { Authorization: 'no-auth' },
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
43
|
/** 登出 */
|
|
57
44
|
Logout(request: LogoutRequest): Promise<Empty> {
|
|
58
45
|
return http<Empty>({
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { http } from '../../../utils/http'
|
|
2
|
+
import type {
|
|
3
|
+
GetSecretPublicKeyRequest,
|
|
4
|
+
GetSecretPublicKeyResponse,
|
|
5
|
+
RevealSecretFieldRequest,
|
|
6
|
+
RevealSecretFieldResponse,
|
|
7
|
+
SecretCryptoService,
|
|
8
|
+
} from '../../../rpc/base/v1/secret_crypto'
|
|
9
|
+
|
|
10
|
+
const SECRET_PUBLIC_KEY_URL = '/v1/base/secret-public-key'
|
|
11
|
+
const SECRET_FIELD_REVEAL_URL = '/v1/base/secret-field/reveal'
|
|
12
|
+
|
|
13
|
+
/** 敏感字段加密公共服务 */
|
|
14
|
+
export class SecretCryptoServiceImpl implements SecretCryptoService {
|
|
15
|
+
/** 获取敏感字段临时公钥 */
|
|
16
|
+
GetSecretPublicKey(request: GetSecretPublicKeyRequest): Promise<GetSecretPublicKeyResponse> {
|
|
17
|
+
return http<GetSecretPublicKeyResponse>({
|
|
18
|
+
url: `${SECRET_PUBLIC_KEY_URL}`,
|
|
19
|
+
method: 'GET',
|
|
20
|
+
authMode: 'none',
|
|
21
|
+
data: request,
|
|
22
|
+
header: { Authorization: 'no-auth' },
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 查看密钥字段明文 */
|
|
27
|
+
RevealSecretField(request: RevealSecretFieldRequest): Promise<RevealSecretFieldResponse> {
|
|
28
|
+
return http<RevealSecretFieldResponse>({
|
|
29
|
+
url: `${SECRET_FIELD_REVEAL_URL}`,
|
|
30
|
+
method: 'POST',
|
|
31
|
+
data: request,
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const defSecretCryptoService = new SecretCryptoServiceImpl()
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Image, Text, View } from '@tarojs/components'
|
|
2
2
|
import { resolveModuleIcon, resolveStaticView } from '../module'
|
|
3
3
|
import { APP_MENU_ROOT_ID, navigateAppRoute, useAppMenuBadges, useAppNavigation } from '../navigation'
|
|
4
|
+
import { useI18n } from '../locales'
|
|
4
5
|
import { resolveRootMenuId } from '../navigation-tree.mjs'
|
|
5
6
|
import './KratosTabBar.scss'
|
|
6
7
|
|
|
@@ -13,6 +14,18 @@ export interface KratosTabBarProps {
|
|
|
13
14
|
export function KratosTabBar({ route }: KratosTabBarProps) {
|
|
14
15
|
const menus = useAppNavigation((state) => state.menus)
|
|
15
16
|
const tabBar = useAppNavigation((state) => state.tabBar)
|
|
17
|
+
const { t } = useI18n()
|
|
18
|
+
|
|
19
|
+
/** 按稳定 viewKey 优先取界面语言标签,未配置的菜单回退后端标题。 */
|
|
20
|
+
const tabBarTitleKeys: Record<string, string> = {
|
|
21
|
+
HOME: 'core.navigation.home',
|
|
22
|
+
APP_ANALYTIC: 'core.navigation.analytics',
|
|
23
|
+
APP_REPORT: 'core.navigation.report',
|
|
24
|
+
MESSAGE_INBOX: 'core.navigation.message',
|
|
25
|
+
PROFILE_HOME: 'core.navigation.my',
|
|
26
|
+
}
|
|
27
|
+
const tabBarTitle = (item: { viewKey: string; title: string }): string =>
|
|
28
|
+
(tabBarTitleKeys[item.viewKey] ? t(tabBarTitleKeys[item.viewKey]) : '') || item.title
|
|
16
29
|
const messageBadge = useAppMenuBadges((state) => state.badges.MESSAGE_INBOX ?? 0)
|
|
17
30
|
const routeMenu = menus.find((menu) => resolveStaticView(menu.viewKey) === route)
|
|
18
31
|
const tabMenuId = routeMenu
|
|
@@ -41,7 +54,7 @@ export function KratosTabBar({ route }: KratosTabBarProps) {
|
|
|
41
54
|
{item.viewKey === 'MESSAGE_INBOX' && messageBadge ? (
|
|
42
55
|
<View className='kratos-tab-bar__badge' aria-hidden='true' />
|
|
43
56
|
) : null}
|
|
44
|
-
<Text className={active ? 'kratos-tab-bar__text--active' : ''}>{item
|
|
57
|
+
<Text className={active ? 'kratos-tab-bar__text--active' : ''}>{tabBarTitle(item)}</Text>
|
|
45
58
|
</View>
|
|
46
59
|
)
|
|
47
60
|
})}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Button, Input, Text, View } from '@tarojs/components'
|
|
2
2
|
import { useEffect, useState } from 'react'
|
|
3
3
|
import { useI18n } from '../locales'
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
6
|
-
import type { PasswordCrypto } from '../rpc/common/v1/types'
|
|
4
|
+
import { encryptPassword } from '../utils/secretCrypto'
|
|
5
|
+
import type { SecretCrypto } from '../rpc/common/v1/types'
|
|
7
6
|
import './PasswordVerifyDialog.scss'
|
|
8
7
|
|
|
9
8
|
/** Taro 通用密码验证弹窗属性。 */
|
|
@@ -24,12 +23,10 @@ export interface PasswordVerifyDialogProps {
|
|
|
24
23
|
cancelText?: string
|
|
25
24
|
/** 外部业务提交状态。 */
|
|
26
25
|
confirmLoading?: boolean
|
|
27
|
-
/** 密码加密场景。 */
|
|
28
|
-
scene?: PasswordCryptoScene
|
|
29
26
|
/** 是否允许点击遮罩关闭弹窗。 */
|
|
30
27
|
closeOnClickModal?: boolean
|
|
31
28
|
/** 确认并返回加密密码。 */
|
|
32
|
-
onConfirm: (password:
|
|
29
|
+
onConfirm: (password: SecretCrypto) => void | Promise<void>
|
|
33
30
|
/** 取消验证。 */
|
|
34
31
|
onCancel: () => void
|
|
35
32
|
}
|
|
@@ -44,7 +41,7 @@ export default function PasswordVerifyDialog({
|
|
|
44
41
|
confirmText,
|
|
45
42
|
cancelText,
|
|
46
43
|
confirmLoading = false,
|
|
47
|
-
|
|
44
|
+
|
|
48
45
|
closeOnClickModal = false,
|
|
49
46
|
onConfirm,
|
|
50
47
|
onCancel,
|
|
@@ -73,7 +70,7 @@ export default function PasswordVerifyDialog({
|
|
|
73
70
|
setErrorMessage('')
|
|
74
71
|
setEncrypting(true)
|
|
75
72
|
try {
|
|
76
|
-
const encryptedPassword = await encryptPassword(password
|
|
73
|
+
const encryptedPassword = await encryptPassword(password)
|
|
77
74
|
await onConfirm(encryptedPassword)
|
|
78
75
|
} catch (error) {
|
|
79
76
|
setErrorMessage(error instanceof Error ? error.message : t('common.message.request_error'))
|
package/src/index.ts
CHANGED
|
@@ -39,6 +39,6 @@ export * from './utils/auth'
|
|
|
39
39
|
export * from './utils/file'
|
|
40
40
|
export * from './utils/index'
|
|
41
41
|
export * from './utils/navigation'
|
|
42
|
-
export * from './utils/
|
|
42
|
+
export * from './utils/secretCrypto'
|
|
43
43
|
export { default as PasswordVerifyDialog } from './components/PasswordVerifyDialog'
|
|
44
44
|
export type { PasswordVerifyDialogProps } from './components/PasswordVerifyDialog'
|
package/src/locales/README.md
CHANGED
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
| `en-US.json` | 英文 Core 语言包。 | Taro 切换为英文时使用。 |
|
|
10
10
|
| `ja-JP.json` | 日文 Core 语言包。 | Taro 切换为日文时使用。 |
|
|
11
11
|
|
|
12
|
-
语言包是标准 JSON,不能在文件内直接写注释;公共键使用 `common.` 或 `core.` 命名空间。新增语言后执行仓库根目录的 `make i18n`。语言切换选项固定显示后端 `base_language.native_name`,接口不可用时使用代码内置的原生名称;`common.language.*` 仅用于普通文案和语言迁移初始数据。新增语言的完整文件清单见[
|
|
12
|
+
语言包是标准 JSON,不能在文件内直接写注释;公共键使用 `common.` 或 `core.` 命名空间。新增语言后执行仓库根目录的 `make i18n`。语言切换选项固定显示后端 `base_language.native_name`,接口不可用时使用代码内置的原生名称;`common.language.*` 仅用于普通文案和语言迁移初始数据。新增语言的完整文件清单见[国际化设计与语言扩展](../../../../../../docs/国际化最终方案.md)。
|
package/src/locales/en-US.json
CHANGED
|
@@ -125,5 +125,8 @@
|
|
|
125
125
|
"common.resource.default": "{resource}",
|
|
126
126
|
"common.action.delete_resource": "Delete {resource}",
|
|
127
127
|
"common.action.set_field_status": "Set {field}",
|
|
128
|
-
"common.action.load_more": "Load more"
|
|
128
|
+
"common.action.load_more": "Load more",
|
|
129
|
+
"common.status.loading": "Loading…",
|
|
130
|
+
"core.navigation.analytics": "Analytics",
|
|
131
|
+
"core.navigation.report": "Reports"
|
|
129
132
|
}
|
package/src/locales/ja-JP.json
CHANGED
|
@@ -125,5 +125,8 @@
|
|
|
125
125
|
"common.resource.default": "{resource}",
|
|
126
126
|
"common.action.delete_resource": "{resource}を削除",
|
|
127
127
|
"common.action.set_field_status": "{field}を設定",
|
|
128
|
-
"common.action.load_more": "さらに読み込む"
|
|
128
|
+
"common.action.load_more": "さらに読み込む",
|
|
129
|
+
"common.status.loading": "読み込み中…",
|
|
130
|
+
"core.navigation.analytics": "分析",
|
|
131
|
+
"core.navigation.report": "レポート"
|
|
129
132
|
}
|
package/src/locales/zh-CN.json
CHANGED
|
@@ -125,5 +125,8 @@
|
|
|
125
125
|
"common.resource.default": "{resource}",
|
|
126
126
|
"common.action.delete_resource": "删除{resource}",
|
|
127
127
|
"common.action.set_field_status": "设置{field}",
|
|
128
|
-
"common.action.load_more": "加载更多"
|
|
128
|
+
"common.action.load_more": "加载更多",
|
|
129
|
+
"common.status.loading": "加载中…",
|
|
130
|
+
"core.navigation.analytics": "分析",
|
|
131
|
+
"core.navigation.report": "报表"
|
|
129
132
|
}
|
package/src/locales/zh-TW.json
CHANGED
|
@@ -125,5 +125,8 @@
|
|
|
125
125
|
"common.resource.default": "{resource}",
|
|
126
126
|
"common.action.delete_resource": "刪除{resource}",
|
|
127
127
|
"common.action.set_field_status": "設定{field}",
|
|
128
|
-
"common.action.load_more": "載入更多"
|
|
128
|
+
"common.action.load_more": "載入更多",
|
|
129
|
+
"common.status.loading": "載入中…",
|
|
130
|
+
"core.navigation.analytics": "分析",
|
|
131
|
+
"core.navigation.report": "報表"
|
|
129
132
|
}
|
package/src/rpc/base/v1/login.ts
CHANGED
|
@@ -5,27 +5,9 @@
|
|
|
5
5
|
// source: base/v1/login.proto
|
|
6
6
|
|
|
7
7
|
/* eslint-disable */
|
|
8
|
-
import type {
|
|
8
|
+
import type { SecretCrypto } from "../../common/v1/types";
|
|
9
9
|
import type { Empty } from "../../google/protobuf/empty";
|
|
10
10
|
|
|
11
|
-
/** 密码加密场景枚举。 */
|
|
12
|
-
export enum PasswordCryptoScene {
|
|
13
|
-
/** PASSWORD_CRYPTO_SCENE_UNSPECIFIED - 未指定密码加密场景。 */
|
|
14
|
-
PASSWORD_CRYPTO_SCENE_UNSPECIFIED = 0,
|
|
15
|
-
/** PASSWORD_CRYPTO_SCENE_LOGIN - 登录密码加密场景。 */
|
|
16
|
-
PASSWORD_CRYPTO_SCENE_LOGIN = 1,
|
|
17
|
-
/** PASSWORD_CRYPTO_SCENE_CREATE_BASE_USER - 新增后台用户密码加密场景。 */
|
|
18
|
-
PASSWORD_CRYPTO_SCENE_CREATE_BASE_USER = 2,
|
|
19
|
-
/** PASSWORD_CRYPTO_SCENE_RESET_BASE_USER_PASSWORD - 重置后台用户密码加密场景。 */
|
|
20
|
-
PASSWORD_CRYPTO_SCENE_RESET_BASE_USER_PASSWORD = 3,
|
|
21
|
-
/** PASSWORD_CRYPTO_SCENE_UPDATE_USER_PASSWORD - 个人修改密码加密场景。 */
|
|
22
|
-
PASSWORD_CRYPTO_SCENE_UPDATE_USER_PASSWORD = 4,
|
|
23
|
-
/** PASSWORD_CRYPTO_SCENE_MFA - 多因素认证敏感操作场景。 */
|
|
24
|
-
PASSWORD_CRYPTO_SCENE_MFA = 5,
|
|
25
|
-
/** PASSWORD_CRYPTO_SCENE_CONFIGURE_PASSWORD_POLICY - 密码策略初始化密码配置场景。 */
|
|
26
|
-
PASSWORD_CRYPTO_SCENE_CONFIGURE_PASSWORD_POLICY = 6,
|
|
27
|
-
}
|
|
28
|
-
|
|
29
11
|
/**
|
|
30
12
|
* LoginStatus 表示登录请求当前所处的认证阶段。
|
|
31
13
|
* 只有 AUTHENTICATED 或 PASSWORD_CHANGE_REQUIRED 才会携带正式访问令牌,MFA 状态必须继续完成挑战。
|
|
@@ -49,12 +31,6 @@ export interface CaptchaRequest {
|
|
|
49
31
|
type: string;
|
|
50
32
|
}
|
|
51
33
|
|
|
52
|
-
/** 密码临时公钥获取条件 */
|
|
53
|
-
export interface PasswordPublicKeyRequest {
|
|
54
|
-
/** 使用场景 */
|
|
55
|
-
scene: PasswordCryptoScene;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
34
|
/** 登出请求条件 */
|
|
59
35
|
export interface LogoutRequest {
|
|
60
36
|
}
|
|
@@ -85,20 +61,6 @@ export interface VerifyCaptchaResponse {
|
|
|
85
61
|
expires_in: number;
|
|
86
62
|
}
|
|
87
63
|
|
|
88
|
-
/** 密码临时公钥响应 */
|
|
89
|
-
export interface PasswordPublicKeyResponse {
|
|
90
|
-
/** 临时密钥ID */
|
|
91
|
-
key_id: string;
|
|
92
|
-
/** 临时公钥 */
|
|
93
|
-
public_key: string;
|
|
94
|
-
/** 加密算法 */
|
|
95
|
-
algorithm: string;
|
|
96
|
-
/** 随机值 */
|
|
97
|
-
nonce: string;
|
|
98
|
-
/** 有效时间,单位秒 */
|
|
99
|
-
expires_in: number;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
64
|
/** 刷新令牌请求参数 */
|
|
103
65
|
export interface RefreshTokenRequest {
|
|
104
66
|
/** 更新令牌;未填写时由服务端从HttpOnly Cookie读取。 */
|
|
@@ -125,7 +87,7 @@ export interface LoginRequest {
|
|
|
125
87
|
user_name: string;
|
|
126
88
|
/** 用户的密码,必选项。 */
|
|
127
89
|
password:
|
|
128
|
-
|
|
|
90
|
+
| SecretCrypto
|
|
129
91
|
| undefined;
|
|
130
92
|
/** 验证码 */
|
|
131
93
|
captcha_code: string;
|
|
@@ -165,8 +127,6 @@ export interface LoginService {
|
|
|
165
127
|
Captcha(request: CaptchaRequest): Promise<CaptchaResponse>;
|
|
166
128
|
/** 验证码预校验 */
|
|
167
129
|
VerifyCaptcha(request: VerifyCaptchaRequest): Promise<VerifyCaptchaResponse>;
|
|
168
|
-
/** 获取密码临时公钥 */
|
|
169
|
-
PasswordPublicKey(request: PasswordPublicKeyRequest): Promise<PasswordPublicKeyResponse>;
|
|
170
130
|
/** 登出 */
|
|
171
131
|
Logout(request: LogoutRequest): Promise<Empty>;
|
|
172
132
|
/** 刷新认证令牌 */
|
package/src/rpc/base/v1/mfa.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// source: base/v1/mfa.proto
|
|
6
6
|
|
|
7
7
|
/* eslint-disable */
|
|
8
|
-
import type {
|
|
8
|
+
import type { SecretCrypto } from "../../common/v1/types";
|
|
9
9
|
import type { Empty } from "../../google/protobuf/empty";
|
|
10
10
|
import type { LoginResponse } from "./login";
|
|
11
11
|
|
|
@@ -79,7 +79,7 @@ export interface MfaStatusResponse {
|
|
|
79
79
|
export interface BeginMfaSetupRequest {
|
|
80
80
|
/** 当前登录密码 */
|
|
81
81
|
password:
|
|
82
|
-
|
|
|
82
|
+
| SecretCrypto
|
|
83
83
|
| undefined;
|
|
84
84
|
/** 强制绑定场景下的临时票据 */
|
|
85
85
|
setup_ticket: string;
|
|
@@ -135,7 +135,7 @@ export interface BeginMfaDisableResponse {
|
|
|
135
135
|
export interface DisableMfaRequest {
|
|
136
136
|
/** 当前登录密码 */
|
|
137
137
|
password:
|
|
138
|
-
|
|
|
138
|
+
| SecretCrypto
|
|
139
139
|
| undefined;
|
|
140
140
|
/** TOTP 动态口令 */
|
|
141
141
|
code: string;
|
package/src/rpc/base/v1/oauth.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// source: base/v1/oauth.proto
|
|
6
6
|
|
|
7
7
|
/* eslint-disable */
|
|
8
|
-
import type {
|
|
8
|
+
import type { SecretCrypto } from "../../common/v1/types";
|
|
9
9
|
import type { Empty } from "../../google/protobuf/empty";
|
|
10
10
|
import type { LoginStatus } from "./login";
|
|
11
11
|
|
|
@@ -77,7 +77,7 @@ export interface BindOauthSessionRequest {
|
|
|
77
77
|
user_name: string;
|
|
78
78
|
/** 用户密码 */
|
|
79
79
|
password:
|
|
80
|
-
|
|
|
80
|
+
| SecretCrypto
|
|
81
81
|
| undefined;
|
|
82
82
|
/** 验证码 */
|
|
83
83
|
captcha_code: string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Code generated by protoc-gen-ts_proto. DO NOT EDIT.
|
|
2
|
+
// versions:
|
|
3
|
+
// protoc-gen-ts_proto v2.11.8
|
|
4
|
+
// protoc unknown
|
|
5
|
+
// source: base/v1/secret_crypto.proto
|
|
6
|
+
|
|
7
|
+
/* eslint-disable */
|
|
8
|
+
|
|
9
|
+
/** 敏感字段临时公钥获取条件 */
|
|
10
|
+
export interface GetSecretPublicKeyRequest {
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** 敏感字段临时公钥响应 */
|
|
14
|
+
export interface GetSecretPublicKeyResponse {
|
|
15
|
+
/** 临时密钥ID */
|
|
16
|
+
key_id: string;
|
|
17
|
+
/** 临时公钥 */
|
|
18
|
+
public_key: string;
|
|
19
|
+
/** 加密算法 */
|
|
20
|
+
algorithm: string;
|
|
21
|
+
/** 随机值 */
|
|
22
|
+
nonce: string;
|
|
23
|
+
/** 有效时间,单位秒 */
|
|
24
|
+
expires_in: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 密钥字段查看条件 */
|
|
28
|
+
export interface RevealSecretFieldRequest {
|
|
29
|
+
/** 资源标识,如 ai_provider、base_oauth_provider、base_message_provider */
|
|
30
|
+
resource: string;
|
|
31
|
+
/** 记录ID */
|
|
32
|
+
id: number;
|
|
33
|
+
/** 字段名,如 api_key、client_secret */
|
|
34
|
+
field: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 密钥字段查看响应 */
|
|
38
|
+
export interface RevealSecretFieldResponse {
|
|
39
|
+
/** 密钥明文 */
|
|
40
|
+
text: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 敏感字段加密公共服务 */
|
|
44
|
+
export interface SecretCryptoService {
|
|
45
|
+
/** 获取敏感字段临时公钥,同一次提交的多个密文字段共用该公钥 */
|
|
46
|
+
GetSecretPublicKey(request: GetSecretPublicKeyRequest): Promise<GetSecretPublicKeyResponse>;
|
|
47
|
+
/** 查看密钥字段明文,仅允许查询注册过的密钥字段 */
|
|
48
|
+
RevealSecretField(request: RevealSecretFieldRequest): Promise<RevealSecretFieldResponse>;
|
|
49
|
+
}
|
|
@@ -60,8 +60,8 @@ export interface BytesValues {
|
|
|
60
60
|
value: Uint8Array[];
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
/**
|
|
64
|
-
export interface
|
|
63
|
+
/** 敏感字段密文,密码与各类密钥字段统一使用。 */
|
|
64
|
+
export interface SecretCrypto {
|
|
65
65
|
/** 临时密钥ID */
|
|
66
66
|
key_id: string;
|
|
67
67
|
/** 随机值 */
|
|
@@ -72,6 +72,6 @@ export interface PasswordCrypto {
|
|
|
72
72
|
encrypted_key: string;
|
|
73
73
|
/** 初始化向量 */
|
|
74
74
|
iv: string;
|
|
75
|
-
/**
|
|
76
|
-
|
|
75
|
+
/** 传输时为密文,服务端解密后回填明文 */
|
|
76
|
+
text: string;
|
|
77
77
|
}
|
package/src/utils/http.ts
CHANGED
|
@@ -32,21 +32,21 @@ const REFRESH_TOKEN_URL = '/v1/base/token'
|
|
|
32
32
|
const CAPTCHA_URL = '/v1/base/captcha'
|
|
33
33
|
const CONFIG_URL = '/v1/base/config'
|
|
34
34
|
const LANGUAGE_URL = '/v1/base/language'
|
|
35
|
-
const
|
|
35
|
+
const SECRET_PUBLIC_KEY_URL = '/v1/base/secret-public-key'
|
|
36
36
|
const NO_AUTH_URL_SET = new Set([
|
|
37
37
|
SESSION_URL,
|
|
38
38
|
REFRESH_TOKEN_URL,
|
|
39
39
|
CAPTCHA_URL,
|
|
40
40
|
CONFIG_URL,
|
|
41
41
|
LANGUAGE_URL,
|
|
42
|
-
|
|
42
|
+
SECRET_PUBLIC_KEY_URL,
|
|
43
43
|
])
|
|
44
44
|
const AUTH_EXPIRED_EXCLUDED_URL_SET = new Set([
|
|
45
45
|
SESSION_URL,
|
|
46
46
|
CAPTCHA_URL,
|
|
47
47
|
CONFIG_URL,
|
|
48
48
|
LANGUAGE_URL,
|
|
49
|
-
|
|
49
|
+
SECRET_PUBLIC_KEY_URL,
|
|
50
50
|
])
|
|
51
51
|
/** 认证状态被静默清理的事件名。 */
|
|
52
52
|
export const AUTH_SILENT_LOGOUT_EVENT = 'auth:silent-logout'
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import Taro from '@tarojs/taro'
|
|
2
2
|
import * as miniCrypto from 'asmcrypto.js'
|
|
3
|
-
import {
|
|
3
|
+
import { defSecretCryptoService } from '../api/base/v1/secret_crypto'
|
|
4
4
|
import { t } from '../locales'
|
|
5
|
-
import {
|
|
6
|
-
import type {
|
|
5
|
+
import type { GetSecretPublicKeyResponse } from '../rpc/base/v1/secret_crypto'
|
|
6
|
+
import type { SecretCrypto } from '../rpc/common/v1/types'
|
|
7
7
|
|
|
8
8
|
type MiniCrypto = typeof import('asmcrypto.js')
|
|
9
9
|
|
|
10
|
-
export const PASSWORD_CRYPTO_SCENE = PasswordCryptoScene
|
|
11
|
-
export type { PasswordCryptoScene }
|
|
12
|
-
|
|
13
10
|
/** 将 PEM 公钥转换为二进制 DER 数据。 */
|
|
14
11
|
function pemToArrayBuffer(pem: string) {
|
|
15
12
|
const base64 = pem
|
|
@@ -152,19 +149,14 @@ function miniBytesToBase64(value: Uint8Array) {
|
|
|
152
149
|
}
|
|
153
150
|
|
|
154
151
|
/** 使用纯 JavaScript 实现兼容缺少 WebCrypto 的运行时。 */
|
|
155
|
-
async function
|
|
152
|
+
async function encryptPortableSecret(
|
|
156
153
|
crypto: MiniCrypto,
|
|
157
|
-
|
|
158
|
-
publicKeyResponse:
|
|
159
|
-
|
|
160
|
-
public_key: string
|
|
161
|
-
algorithm: string
|
|
162
|
-
nonce: string
|
|
163
|
-
},
|
|
164
|
-
): Promise<PasswordCrypto> {
|
|
154
|
+
value: string,
|
|
155
|
+
publicKeyResponse: GetSecretPublicKeyResponse,
|
|
156
|
+
): Promise<SecretCrypto> {
|
|
165
157
|
const aesKey = new Uint8Array(await getRandomBytes(32))
|
|
166
158
|
const iv = new Uint8Array(await getRandomBytes(12))
|
|
167
|
-
const plaintext = crypto.string_to_bytes(
|
|
159
|
+
const plaintext = crypto.string_to_bytes(value, true)
|
|
168
160
|
const [modulus, exponent] = parseMiniRsaPublicKey(publicKeyResponse.public_key)
|
|
169
161
|
const hash = new crypto.Sha256()
|
|
170
162
|
const keySize = Math.ceil(new crypto.BigNumber(modulus).bitLength / 8)
|
|
@@ -206,26 +198,25 @@ async function encryptPortablePassword(
|
|
|
206
198
|
algorithm: publicKeyResponse.algorithm,
|
|
207
199
|
encrypted_key: miniBytesToBase64(encryptedKey),
|
|
208
200
|
iv: miniBytesToBase64(iv),
|
|
209
|
-
|
|
201
|
+
text: miniBytesToBase64(ciphertext),
|
|
210
202
|
}
|
|
211
203
|
}
|
|
212
204
|
|
|
213
|
-
/**
|
|
214
|
-
export async function
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
): Promise<PasswordCrypto> {
|
|
218
|
-
const plainPassword = password.trim()
|
|
219
|
-
if (!plainPassword) {
|
|
220
|
-
throw new Error(t('core.crypto.password_required'))
|
|
221
|
-
}
|
|
205
|
+
/** 获取敏感字段一次性临时公钥,同一次提交的多个密文字段共用该公钥。 */
|
|
206
|
+
export async function fetchSecretPublicKey(): Promise<GetSecretPublicKeyResponse> {
|
|
207
|
+
return defSecretCryptoService.GetSecretPublicKey({})
|
|
208
|
+
}
|
|
222
209
|
|
|
223
|
-
|
|
210
|
+
/** 使用已获取的临时公钥加密单个敏感值,供一次取钥加密多个字段的场景复用。 */
|
|
211
|
+
export async function encryptWithPublicKey(
|
|
212
|
+
publicKeyResponse: GetSecretPublicKeyResponse,
|
|
213
|
+
value: string,
|
|
214
|
+
): Promise<SecretCrypto> {
|
|
224
215
|
|
|
225
216
|
const cryptoApi = globalThis.crypto
|
|
226
217
|
const isSecureContext = typeof window === 'undefined' || window.isSecureContext
|
|
227
218
|
if (process.env.TARO_ENV === 'weapp' || !cryptoApi?.subtle || !isSecureContext) {
|
|
228
|
-
return
|
|
219
|
+
return encryptPortableSecret(miniCrypto, value, publicKeyResponse)
|
|
229
220
|
}
|
|
230
221
|
|
|
231
222
|
const publicKey = await cryptoApi.subtle.importKey(
|
|
@@ -243,7 +234,7 @@ export async function encryptPassword(
|
|
|
243
234
|
const ciphertext = await cryptoApi.subtle.encrypt(
|
|
244
235
|
{ name: 'AES-GCM', iv },
|
|
245
236
|
aesKey,
|
|
246
|
-
new TextEncoder().encode(
|
|
237
|
+
new TextEncoder().encode(value),
|
|
247
238
|
)
|
|
248
239
|
const encryptedKey = await cryptoApi.subtle.encrypt({ name: 'RSA-OAEP' }, publicKey, rawAesKey)
|
|
249
240
|
|
|
@@ -253,6 +244,20 @@ export async function encryptPassword(
|
|
|
253
244
|
algorithm: publicKeyResponse.algorithm,
|
|
254
245
|
encrypted_key: arrayBufferToBase64(encryptedKey),
|
|
255
246
|
iv: arrayBufferToBase64(iv.buffer),
|
|
256
|
-
|
|
247
|
+
text: arrayBufferToBase64(ciphertext),
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** 加密单个敏感字段值,自动获取一次性临时公钥。 */
|
|
252
|
+
export async function encryptSecret(value: string): Promise<SecretCrypto> {
|
|
253
|
+
return encryptWithPublicKey(await fetchSecretPublicKey(), value)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** 加密密码字段:去除首尾空白且不允许为空。 */
|
|
257
|
+
export async function encryptPassword(password: string): Promise<SecretCrypto> {
|
|
258
|
+
const plainPassword = password.trim()
|
|
259
|
+
if (!plainPassword) {
|
|
260
|
+
throw new Error(t('core.crypto.password_required'))
|
|
257
261
|
}
|
|
262
|
+
return encryptSecret(plainPassword)
|
|
258
263
|
}
|
|
@@ -9,7 +9,7 @@ import { LoginStatus, type LoginRequest, type LoginResponse } from '../../../rpc
|
|
|
9
9
|
import { useSettingStore, useUserStore } from '../../../stores'
|
|
10
10
|
import { formatSrc } from '../../../utils'
|
|
11
11
|
import { restoreLoginRedirect } from '../../../utils/navigation'
|
|
12
|
-
import { encryptPassword
|
|
12
|
+
import { encryptPassword } from '../../../utils/secretCrypto'
|
|
13
13
|
import { createWebAuthnCredential, getWebAuthnAssertion } from '../../../utils/webauthn'
|
|
14
14
|
import MfaRecoveryCodesDialog from '../../../components/MfaRecoveryCodesDialog'
|
|
15
15
|
import MfaSetupPanel from '../../../components/MfaSetupPanel'
|
|
@@ -421,10 +421,7 @@ export default function LoginPage() {
|
|
|
421
421
|
}
|
|
422
422
|
|
|
423
423
|
const submitLogin = async (captchaCode: string) => {
|
|
424
|
-
const encrypted = await encryptPassword(
|
|
425
|
-
password,
|
|
426
|
-
PASSWORD_CRYPTO_SCENE.PASSWORD_CRYPTO_SCENE_LOGIN,
|
|
427
|
-
)
|
|
424
|
+
const encrypted = await encryptPassword(password)
|
|
428
425
|
return userStore.login({
|
|
429
426
|
...form,
|
|
430
427
|
tenant_code: showTenantCode ? form.tenant_code : '0000',
|
|
@@ -536,10 +533,7 @@ export default function LoginPage() {
|
|
|
536
533
|
}
|
|
537
534
|
setLoading(true)
|
|
538
535
|
try {
|
|
539
|
-
const encrypted = await encryptPassword(
|
|
540
|
-
miniPassword,
|
|
541
|
-
PASSWORD_CRYPTO_SCENE.PASSWORD_CRYPTO_SCENE_LOGIN,
|
|
542
|
-
)
|
|
536
|
+
const encrypted = await encryptPassword(miniPassword)
|
|
543
537
|
const code = (await Taro.login()).code
|
|
544
538
|
const response = await userStore.bindOauthSession({
|
|
545
539
|
provider: wechatMiniProvider,
|