-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d069f33
commit a52ae6a
Showing
17 changed files
with
398 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import lockScreenService from '@/service/lock-screen-service'; | ||
import { userStorage } from '@/store/main-store'; | ||
|
||
export default new class { | ||
lastActionTime = 0; | ||
|
||
listen(maxIdleMinutes = 5, intervalSecs = 60) { | ||
setInterval(() => { | ||
this.checkIdleTimeAndHandle(maxIdleMinutes); | ||
}, intervalSecs * 1000); | ||
|
||
this.logLastActionTime(); | ||
|
||
document.body.addEventListener('click', () => { | ||
this.logLastActionTime(); | ||
}); | ||
} | ||
|
||
logLastActionTime() { | ||
this.lastActionTime = Math.round(new Date().getTime() / 1000); | ||
} | ||
|
||
async checkIdleTimeAndHandle(maxIdleMinutes: number) { | ||
const now = Math.round(new Date().getTime() / 1000); | ||
const maxIdleSeconds = maxIdleMinutes * 60; | ||
const idleTime = now - this.lastActionTime; | ||
|
||
// console.log('idle time', idleTime, '>', maxIdleSeconds, '=', idleTime > maxIdleSeconds); | ||
|
||
if (!userStorage.value) { | ||
return; | ||
} | ||
|
||
if (idleTime > maxIdleSeconds) { | ||
lockScreenService.lock(); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import router from '@/router'; | ||
import encryptionService from '@/service/encryption-service'; | ||
import { isLock, isManuallyLock, kekStorage, saltStorage } from '@/store/main-store'; | ||
import { enableBiometricsOption } from '@/store/options-store'; | ||
import { simpleAlert } from '@/utilities/alert'; | ||
import secretToolkit, { Encoder } from '@/utilities/secret-toolkit'; | ||
import { | ||
AndroidBiometryStrength, | ||
BiometricAuth, | ||
BiometryType, | ||
} from '@aparajita/capacitor-biometric-auth'; | ||
import { Capacitor } from '@capacitor/core'; | ||
import { timingSafeEquals } from '@windwalker-io/srp'; | ||
|
||
export default new class { | ||
async lock() { | ||
isLock.value = true; | ||
|
||
router.replace({ name: 'lock' }); | ||
} | ||
|
||
async unlock() { | ||
isLock.value = false; | ||
isManuallyLock.value = false; | ||
} | ||
|
||
async passwordAuthenticate(password: string) { | ||
const kek = secretToolkit.encode( | ||
await encryptionService.deriveKek(password, saltStorage.value), | ||
Encoder.HEX | ||
); | ||
|
||
if (!timingSafeEquals(kekStorage.value, kek)) { | ||
throw new Error('Invalid password'); | ||
} | ||
} | ||
|
||
async testBiometrics() { | ||
try { | ||
await this.biometricsAuthenticate(); | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
simpleAlert(e.message); | ||
} | ||
} | ||
} | ||
|
||
async biometricsAuthenticate() { | ||
if (!Capacitor.isNativePlatform()) { | ||
// web simulate | ||
await BiometricAuth.setBiometryType(BiometryType.touchId); | ||
await BiometricAuth.setBiometryIsEnrolled(true); | ||
await BiometricAuth.setDeviceIsSecure(true); | ||
} | ||
|
||
const info = await BiometricAuth.checkBiometry(); | ||
|
||
if (!info.isAvailable) { | ||
throw new Error('Touch ID or Face ID not available.'); | ||
} | ||
|
||
await BiometricAuth.authenticate({ | ||
reason: 'Please authenticate', | ||
cancelTitle: 'Cancel', | ||
allowDeviceCredential: true, | ||
iosFallbackTitle: 'Use password', | ||
androidTitle: 'Biometric login', | ||
androidSubtitle: 'Log in using biometric authentication', | ||
androidConfirmationRequired: true, | ||
androidBiometryStrength: AndroidBiometryStrength.weak, | ||
}); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { StorageSerializers, useLocalStorage } from '@vueuse/core'; | ||
|
||
export const enableBiometricsOption = useLocalStorage( | ||
'@authman:config:enable.biometrics', | ||
true, | ||
{ | ||
serializer: StorageSerializers.boolean | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.