Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add a legacy-hash fallback opt-in to the lock screen

Manav Rathi6e4039656c28
diff --git a/mobile/packages/lock_screen/lib/lock_screen_settings.dart b/mobile/packages/lock_screen/lib/lock_screen_settings.dart
index c0ea5976ae..6dde60b856 100644
--- a/mobile/packages/lock_screen/lib/lock_screen_settings.dart
+++ b/mobile/packages/lock_screen/lib/lock_screen_settings.dart
@@ -43,12 +43,15 @@ class LockScreenSettings {
late LockScreenHost _config;
late SharedPreferences _preferences;
late FlutterSecureStorage _secureStorage;
+ bool _useLegacyHashFallback = false;
Future<void> init(
LockScreenHost config, {
bool hasOptedForOfflineMode = false,
+ bool useLegacyHashFallback = false,
}) async {
_config = config;
+ _useLegacyHashFallback = useLegacyHashFallback;
_secureStorage = const FlutterSecureStorage();
_preferences = await SharedPreferences.getInstance();
@@ -194,6 +197,8 @@ class LockScreenSettings {
return _secureStorage.read(key: password);
}
+ bool get useLegacyHashFallback => _useLegacyHashFallback;
+
/// Verifies that the hash of [text] matches [storedHash].
Future<bool> verify({
required String text,
diff --git a/mobile/packages/lock_screen/lib/ui/lock_screen_password.dart b/mobile/packages/lock_screen/lib/ui/lock_screen_password.dart
index c07f36c4f9..0a011d5dc0 100644
--- a/mobile/packages/lock_screen/lib/ui/lock_screen_password.dart
+++ b/mobile/packages/lock_screen/lib/ui/lock_screen_password.dart
@@ -164,10 +164,16 @@ class _LockScreenPasswordState extends State<LockScreenPassword> {
}
Future<bool> _confirmPasswordAuth(String inputtedPassword) async {
- final matched = await _lockscreenSetting.verify(
- text: inputtedPassword,
- storedHash: widget.authPass,
- );
+ final matched = _lockscreenSetting.useLegacyHashFallback
+ ? await _lockscreenSetting.verifyWithLegacyFallback(
+ text: inputtedPassword,
+ storedHash: widget.authPass,
+ storageKey: LockScreenSettings.password,
+ )
+ : await _lockscreenSetting.verify(
+ text: inputtedPassword,
+ storedHash: widget.authPass,
+ );
if (matched) {
await _lockscreenSetting.setInvalidAttemptCount(0);
diff --git a/mobile/packages/lock_screen/lib/ui/lock_screen_pin.dart b/mobile/packages/lock_screen/lib/ui/lock_screen_pin.dart
index d82e857a90..fb454b8572 100644
--- a/mobile/packages/lock_screen/lib/ui/lock_screen_pin.dart
+++ b/mobile/packages/lock_screen/lib/ui/lock_screen_pin.dart
@@ -63,10 +63,16 @@ class _LockScreenPinState extends State<LockScreenPin> {
}
Future<bool> confirmPinAuth(String inputtedPin) async {
- final matched = await _lockscreenSetting.verify(
- text: inputtedPin,
- storedHash: widget.authPin,
- );
+ final matched = _lockscreenSetting.useLegacyHashFallback
+ ? await _lockscreenSetting.verifyWithLegacyFallback(
+ text: inputtedPin,
+ storedHash: widget.authPin,
+ storageKey: LockScreenSettings.pin,
+ )
+ : await _lockscreenSetting.verify(
+ text: inputtedPin,
+ storedHash: widget.authPin,
+ );
if (matched) {
invalidAttemptsCount = 0;
await _lockscreenSetting.setInvalidAttemptCount(0);