-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/passcode #6335
base: x
Are you sure you want to change the base?
Fix/passcode #6335
Changes from all commits
93f1357
3e4d68b
cc33bfc
faba1b2
958fb3e
1ffa60b
bb4359f
0bc1025
deea105
afa8d8d
3421bae
fc4c6a9
d313725
d392aea
35dfd33
fa6f0fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -775,4 +775,7 @@ module.exports = [ | |
'cacheable', | ||
'benfen', | ||
'bfc', | ||
'biometric', | ||
'biometrics', | ||
'Biometric', | ||
]; |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -50,7 +50,13 @@ import ServiceBase from '../ServiceBase'; | |||||||
import { checkExtUIOpen } from '../utils'; | ||||||||
|
||||||||
import { biologyAuthUtils } from './biologyAuthUtils'; | ||||||||
import { EPasswordPromptType } from './types'; | ||||||||
import { | ||||||||
EPasswordMode, | ||||||||
EPasswordPromptType, | ||||||||
PASSCODE_LENGTH, | ||||||||
PASSWORD_MAX_LENGTH, | ||||||||
PASSWORD_MIN_LENGTH, | ||||||||
} from './types'; | ||||||||
|
||||||||
import type { IPasswordRes } from './types'; | ||||||||
|
||||||||
|
@@ -273,20 +279,33 @@ export default class ServicePassword extends ServiceBase { | |||||||
} | ||||||||
|
||||||||
// validatePassword -------------------------------- | ||||||||
validatePasswordValidRules(password: string): void { | ||||||||
validatePasswordValidRules( | ||||||||
password: string, | ||||||||
passwordMode: EPasswordMode, | ||||||||
): void { | ||||||||
ensureSensitiveTextEncoded(password); | ||||||||
const realPassword = decodePassword({ password }); | ||||||||
// **** length matched | ||||||||
if (realPassword.length < 8 || realPassword.length > 128) { | ||||||||
if ( | ||||||||
passwordMode === EPasswordMode.PASSWORD && | ||||||||
(realPassword.length < PASSWORD_MIN_LENGTH || | ||||||||
realPassword.length > PASSWORD_MAX_LENGTH) | ||||||||
) { | ||||||||
throw new OneKeyErrors.PasswordStrengthValidationFailed(); | ||||||||
} | ||||||||
if (passwordMode === EPasswordMode.PASSCODE) { | ||||||||
if (realPassword.length !== PASSCODE_LENGTH) { | ||||||||
throw new OneKeyErrors.PasswordStrengthValidationFailed(); | ||||||||
} | ||||||||
} | ||||||||
// **** other rules .... | ||||||||
} | ||||||||
|
||||||||
validatePasswordSame(password: string, newPassword: string) { | ||||||||
ensureSensitiveTextEncoded(password); | ||||||||
ensureSensitiveTextEncoded(newPassword); | ||||||||
|
||||||||
console.log('same__password', password); | ||||||||
console.log('same__newPassword', newPassword); | ||||||||
Comment on lines
+307
to
+308
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 打印原密码和新密码可能带来风险,建议删除或隐藏敏感输出。 -console.log('same__password', password);
-console.log('same__newPassword', newPassword);
+// 建议删除或通过安全日志替代,避免潜在敏感数据泄露 📝 Committable suggestion
Suggested change
Comment on lines
+307
to
+308
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) 查看相同密码日志 |
||||||||
const realPassword = decodePassword({ password }); | ||||||||
const realNewPassword = decodePassword({ password: newPassword }); | ||||||||
if (realPassword === realNewPassword) { | ||||||||
|
@@ -296,20 +315,23 @@ export default class ServicePassword extends ServiceBase { | |||||||
|
||||||||
async validatePassword({ | ||||||||
password, | ||||||||
passwordMode, | ||||||||
newPassword, | ||||||||
skipDBVerify, | ||||||||
}: { | ||||||||
password: string; | ||||||||
passwordMode: EPasswordMode; | ||||||||
newPassword?: string; | ||||||||
skipDBVerify?: boolean; | ||||||||
}): Promise<void> { | ||||||||
ensureSensitiveTextEncoded(password); | ||||||||
if (newPassword) { | ||||||||
ensureSensitiveTextEncoded(newPassword); | ||||||||
} | ||||||||
this.validatePasswordValidRules(password); | ||||||||
if (newPassword) { | ||||||||
this.validatePasswordValidRules(newPassword); | ||||||||
if (!newPassword) { | ||||||||
this.validatePasswordValidRules(password, passwordMode); | ||||||||
} else { | ||||||||
this.validatePasswordValidRules(newPassword, passwordMode); | ||||||||
this.validatePasswordSame(password, newPassword); | ||||||||
} | ||||||||
if (!skipDBVerify) { | ||||||||
|
@@ -336,20 +358,30 @@ export default class ServicePassword extends ServiceBase { | |||||||
return checkPasswordSet; | ||||||||
} | ||||||||
|
||||||||
async setPasswordSetStatus(isSet: boolean): Promise<void> { | ||||||||
await passwordPersistAtom.set((v) => ({ ...v, isPasswordSet: isSet })); | ||||||||
async setPasswordSetStatus( | ||||||||
isSet: boolean, | ||||||||
passMode?: EPasswordMode, | ||||||||
): Promise<void> { | ||||||||
await passwordPersistAtom.set((v) => ({ | ||||||||
...v, | ||||||||
isPasswordSet: isSet, | ||||||||
...(passMode ? { passwordMode: passMode } : {}), | ||||||||
})); | ||||||||
} | ||||||||
|
||||||||
// password actions -------------- | ||||||||
@backgroundMethod() | ||||||||
async setPassword(password: string): Promise<string> { | ||||||||
async setPassword( | ||||||||
password: string, | ||||||||
passwordMode: EPasswordMode, | ||||||||
): Promise<string> { | ||||||||
ensureSensitiveTextEncoded(password); | ||||||||
await this.validatePassword({ password, skipDBVerify: true }); | ||||||||
await this.validatePassword({ password, passwordMode, skipDBVerify: true }); | ||||||||
try { | ||||||||
await this.unLockApp(); | ||||||||
await this.saveBiologyAuthPassword(password); | ||||||||
await this.setCachedPassword(password); | ||||||||
await this.setPasswordSetStatus(true); | ||||||||
await this.setPasswordSetStatus(true, passwordMode); | ||||||||
await localDb.setPassword({ password }); | ||||||||
return password; | ||||||||
} catch (e) { | ||||||||
|
@@ -362,16 +394,21 @@ export default class ServicePassword extends ServiceBase { | |||||||
async updatePassword( | ||||||||
oldPassword: string, | ||||||||
newPassword: string, | ||||||||
passwordMode: EPasswordMode, | ||||||||
): Promise<string> { | ||||||||
ensureSensitiveTextEncoded(oldPassword); | ||||||||
ensureSensitiveTextEncoded(newPassword); | ||||||||
|
||||||||
await this.validatePassword({ password: oldPassword, newPassword }); | ||||||||
await this.validatePassword({ | ||||||||
password: oldPassword, | ||||||||
newPassword, | ||||||||
passwordMode, | ||||||||
}); | ||||||||
try { | ||||||||
await this.backgroundApi.serviceAddressBook.updateHash(newPassword); | ||||||||
await this.saveBiologyAuthPassword(newPassword); | ||||||||
await this.setCachedPassword(newPassword); | ||||||||
await this.setPasswordSetStatus(true); | ||||||||
await this.setPasswordSetStatus(true, passwordMode); | ||||||||
// update v5 db password | ||||||||
await localDb.updatePassword({ oldPassword, newPassword }); | ||||||||
// update v4 db password | ||||||||
|
@@ -391,17 +428,19 @@ export default class ServicePassword extends ServiceBase { | |||||||
@backgroundMethod() | ||||||||
async verifyPassword({ | ||||||||
password, | ||||||||
passwordMode, | ||||||||
isBiologyAuth, | ||||||||
}: { | ||||||||
password: string; | ||||||||
passwordMode: EPasswordMode; | ||||||||
isBiologyAuth?: boolean; | ||||||||
}): Promise<string> { | ||||||||
let verifyingPassword = password; | ||||||||
if (isBiologyAuth) { | ||||||||
verifyingPassword = await this.getBiologyAuthPassword(); | ||||||||
} | ||||||||
ensureSensitiveTextEncoded(verifyingPassword); | ||||||||
await this.validatePassword({ password: verifyingPassword }); | ||||||||
await this.validatePassword({ password: verifyingPassword, passwordMode }); | ||||||||
await this.setCachedPassword(verifyingPassword); | ||||||||
return verifyingPassword; | ||||||||
} | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { isSupportWebAuth } from '@onekeyhq/shared/src/webAuth'; | |
import { EPasswordVerifyStatus } from '@onekeyhq/shared/types/password'; | ||
|
||
import { biologyAuthUtils } from '../../../services/ServicePassword/biologyAuthUtils'; | ||
import { EPasswordMode } from '../../../services/ServicePassword/types'; | ||
import { EAtomNames } from '../atomNames'; | ||
import { globalAtom, globalAtomComputed } from '../utils'; | ||
|
||
|
@@ -60,12 +61,20 @@ export type IPasswordPersistAtom = { | |
webAuthCredentialId: string; | ||
appLockDuration: number; | ||
enableSystemIdleLock: boolean; | ||
passwordMode: EPasswordMode; | ||
enablePasswordErrorProtection: boolean; | ||
passwordErrorAttempts: number; | ||
passwordErrorProtectionTime: number; | ||
Comment on lines
+64
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) 新增字段强化错误保护功能。 |
||
}; | ||
export const passwordAtomInitialValue: IPasswordPersistAtom = { | ||
isPasswordSet: false, | ||
webAuthCredentialId: '', | ||
appLockDuration: 240, | ||
enableSystemIdleLock: true, | ||
passwordMode: EPasswordMode.PASSWORD, | ||
enablePasswordErrorProtection: false, | ||
passwordErrorAttempts: 0, | ||
passwordErrorProtectionTime: 0, | ||
}; | ||
export const { target: passwordPersistAtom, use: usePasswordPersistAtom } = | ||
globalAtom<IPasswordPersistAtom>({ | ||
|
@@ -74,6 +83,15 @@ export const { target: passwordPersistAtom, use: usePasswordPersistAtom } = | |
initialValue: passwordAtomInitialValue, | ||
}); | ||
|
||
export const { target: passwordModeAtom, use: usePasswordModeAtom } = | ||
globalAtomComputed<EPasswordMode>((get) => { | ||
const { passwordMode, isPasswordSet } = get(passwordPersistAtom.atom()); | ||
if (platformEnv.isNative && !isPasswordSet) { | ||
return EPasswordMode.PASSCODE; | ||
} | ||
return passwordMode; | ||
}); | ||
|
||
export const { target: systemIdleLockSupport, use: useSystemIdleLockSupport } = | ||
globalAtomComputed<Promise<boolean | undefined>>(async (get) => { | ||
const platformSupport = platformEnv.isExtension || platformEnv.isDesktop; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
添加的生物识别相关词汇看起来不错!
这些新增的拼写检查跳过词很合理,与密码设置功能的更新相符。
建议考虑是否还需要添加其他相关术语,比如: