Skip to content

Commit

Permalink
bio auth on mac + package updates for 3.19.3/5 (#1398)
Browse files Browse the repository at this point in the history
* bio auth mac fix

* remove comment and change duration from 2 to 0

* cherry pick previous changes

* workaround for secure storage bug on mac

* bump version to 3.19.5 (because breez will need this version anyways)

* some code cleanup

* some changess didn't get saved

* just documenting the issue [skip ci]

* undo accidental removal + minor code cleanup

* merge conflicts

* Minor UI change [skip ci]

---------

Co-authored-by: Omar Hatem <[email protected]>
  • Loading branch information
fossephate and OmarHatem28 authored May 6, 2024
1 parent 3f3cd10 commit e5be737
Show file tree
Hide file tree
Showing 32 changed files with 655 additions and 480 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr_test_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Flutter action
uses: subosito/flutter-action@v1
with:
flutter-version: "3.10.x"
flutter-version: "3.19.5"
channel: stable

- name: Install package dependencies
Expand Down
5 changes: 4 additions & 1 deletion cw_bitcoin/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.1.11
build_runner: ^2.4.7
build_resolvers: ^2.0.9
mobx_codegen: ^2.0.7
hive_generator: ^1.1.3

dependency_overrides:
watcher: ^1.1.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

Expand Down
5 changes: 4 additions & 1 deletion cw_bitcoin_cash/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.1.11
build_runner: ^2.4.7
mobx_codegen: ^2.0.7
hive_generator: ^1.1.3

dependency_overrides:
watcher: ^1.1.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

Expand Down
4 changes: 3 additions & 1 deletion cw_core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.1.11
build_runner: ^2.4.7
build_resolvers: ^2.0.9
mobx_codegen: ^2.0.7
hive_generator: ^2.0.1

dependency_overrides:
watcher: ^1.1.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
4 changes: 3 additions & 1 deletion cw_ethereum/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ dependency_overrides:
git:
url: https://github.com/cake-tech/web3dart.git
ref: cake
watcher: ^1.1.0

dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.1.11
build_runner: ^2.4.7

flutter:
# assets:
# - images/a_dot_burr.jpeg
Expand Down
3 changes: 2 additions & 1 deletion cw_evm/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ dependency_overrides:
git:
url: https://github.com/cake-tech/ledger-flutter.git
ref: cake
watcher: ^1.1.0

dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.1.11
build_runner: ^2.4.7
mobx_codegen: ^2.0.7
hive_generator: ^1.1.3
flutter_lints: ^2.0.0
Expand Down
5 changes: 4 additions & 1 deletion cw_haven/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.1.11
build_runner: ^2.4.7
mobx_codegen: ^2.0.7
build_resolvers: ^2.0.9
hive_generator: ^1.1.3

dependency_overrides:
watcher: ^1.1.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

Expand Down
5 changes: 4 additions & 1 deletion cw_monero/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.1.11
build_runner: ^2.4.7
build_resolvers: ^2.0.9
mobx_codegen: ^2.0.7
hive_generator: ^1.1.3

dependency_overrides:
watcher: ^1.1.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

Expand Down
5 changes: 4 additions & 1 deletion cw_nano/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.1.11
build_runner: ^2.4.7
mobx_codegen: ^2.0.7
hive_generator: ^1.1.3

dependency_overrides:
watcher: ^1.1.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

Expand Down
4 changes: 3 additions & 1 deletion cw_polygon/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ dependency_overrides:
git:
url: https://github.com/cake-tech/web3dart.git
ref: cake
watcher: ^1.1.0

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
build_runner: ^2.1.11
build_runner: ^2.4.7


# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
5 changes: 4 additions & 1 deletion cw_solana/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
build_runner: ^2.1.11
build_runner: ^2.4.7
mobx_codegen: ^2.0.7
hive_generator: ^1.1.3

dependency_overrides:
watcher: ^1.1.0

flutter:
# assets:
# - images/a_dot_burr.jpeg
Expand Down
13 changes: 6 additions & 7 deletions lib/core/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ class AuthService with Store {
Future<void> setPassword(String password) async {
final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
final encodedPassword = encodedPinCode(pin: password);
// secure storage has a weird bug on macOS, where overwriting a key doesn't work, unless
// we delete what's there first:
if (Platform.isMacOS) {
await secureStorage.delete(key: key);
}
await secureStorage.write(key: key, value: encodedPassword);
await writeSecureStorage(secureStorage, key: key, value: encodedPassword);
}

Future<bool> canAuthenticate() async {
Expand All @@ -74,7 +69,11 @@ class AuthService with Store {

void saveLastAuthTime() {
int timestamp = DateTime.now().millisecondsSinceEpoch;
secureStorage.write(key: SecureKey.lastAuthTimeMilliseconds, value: timestamp.toString());
writeSecureStorage(
secureStorage,
key: SecureKey.lastAuthTimeMilliseconds,
value: timestamp.toString(),
);
}

Future<bool> requireAuth() async {
Expand Down
17 changes: 8 additions & 9 deletions lib/core/backup_service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:cake_wallet/core/secure_storage.dart';
import 'package:cake_wallet/themes/theme_list.dart';
import 'package:cake_wallet/utils/device_info.dart';
import 'package:cw_core/wallet_type.dart';
Expand Down Expand Up @@ -275,7 +276,7 @@ class BackupService {
if (currentTransactionPriorityKeyLegacy != null)
await _sharedPreferences.setInt(
PreferencesKey.currentTransactionPriorityKeyLegacy, currentTransactionPriorityKeyLegacy);

if (currentBitcoinElectrumSererId != null)
await _sharedPreferences.setInt(
PreferencesKey.currentBitcoinElectrumSererIdKey, currentBitcoinElectrumSererId);
Expand Down Expand Up @@ -373,16 +374,15 @@ class BackupService {
final backupPasswordKey = generateStoreKeyFor(key: SecretStoreKey.backupPassword);
final backupPassword = keychainJSON[backupPasswordKey] as String;

await _flutterSecureStorage.delete(key: backupPasswordKey);
await _flutterSecureStorage.write(key: backupPasswordKey, value: backupPassword);
await writeSecureStorage(_flutterSecureStorage, key: backupPasswordKey, value: backupPassword);

keychainWalletsInfo.forEach((dynamic rawInfo) async {
final info = rawInfo as Map<String, dynamic>;
await importWalletKeychainInfo(info);
});

await _flutterSecureStorage.delete(key: pinCodeKey);
await _flutterSecureStorage.write(key: pinCodeKey, value: encodedPinCode(pin: decodedPin));
await writeSecureStorage(_flutterSecureStorage,
key: pinCodeKey, value: encodedPinCode(pin: decodedPin));

keychainDumpFile.deleteSync();
}
Expand All @@ -401,16 +401,15 @@ class BackupService {
final backupPasswordKey = generateStoreKeyFor(key: SecretStoreKey.backupPassword);
final backupPassword = keychainJSON[backupPasswordKey] as String;

await _flutterSecureStorage.delete(key: backupPasswordKey);
await _flutterSecureStorage.write(key: backupPasswordKey, value: backupPassword);
await writeSecureStorage(_flutterSecureStorage, key: backupPasswordKey, value: backupPassword);

keychainWalletsInfo.forEach((dynamic rawInfo) async {
final info = rawInfo as Map<String, dynamic>;
await importWalletKeychainInfo(info);
});

await _flutterSecureStorage.delete(key: pinCodeKey);
await _flutterSecureStorage.write(key: pinCodeKey, value: encodedPinCode(pin: decodedPin));
await writeSecureStorage(_flutterSecureStorage,
key: pinCodeKey, value: encodedPinCode(pin: decodedPin));

keychainDumpFile.deleteSync();
}
Expand Down
3 changes: 1 addition & 2 deletions lib/core/key_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class KeyService {
key: SecretStoreKey.moneroWalletPassword, walletName: walletName);
final encodedPassword = encodeWalletPassword(password: password);

await _secureStorage.delete(key: key);
await _secureStorage.write(key: key, value: encodedPassword);
await writeSecureStorage(_secureStorage, key: key, value: encodedPassword);
}

Future<void> deleteWalletPassword({required String walletName}) async {
Expand Down
11 changes: 11 additions & 0 deletions lib/core/secure_storage.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
// For now, we can create a utility function to handle this.
//
Expand All @@ -25,3 +26,13 @@ Future<String?> readSecureStorage(FlutterSecureStorage secureStorage, String key

return result;
}

Future<void> writeSecureStorage(FlutterSecureStorage secureStorage,
{required String key, required String value}) async {
// delete the value before writing on macOS because of a weird bug
// https://github.com/mogol/flutter_secure_storage/issues/581
if (Platform.isMacOS) {
await secureStorage.delete(key: key);
}
await secureStorage.write(key: key, value: value);
}
27 changes: 12 additions & 15 deletions lib/entities/biometric_auth.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
import 'package:local_auth/local_auth.dart';
import 'package:flutter/services.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:flutter_local_authentication/flutter_local_authentication.dart';

class BiometricAuth {
final _localAuth = LocalAuthentication();
final _flutterLocalAuthenticationPlugin = FlutterLocalAuthentication();

Future<bool> isAuthenticated() async {
try {
return await _localAuth.authenticate(
localizedReason: S.current.biometric_auth_reason,
options: AuthenticationOptions(
biometricOnly: true,
useErrorDialogs: true,
stickyAuth: false));
} on PlatformException catch (e) {
final authenticated = await _flutterLocalAuthenticationPlugin.authenticate();
return authenticated;
} catch (e) {
print(e);
}

return false;
}

Future<bool> canCheckBiometrics() async {
bool canAuthenticate;
try {
return await _localAuth.canCheckBiometrics;
} on PlatformException catch (e) {
print(e);
canAuthenticate = await _flutterLocalAuthenticationPlugin.canAuthenticate();
await _flutterLocalAuthenticationPlugin.setTouchIDAuthenticationAllowableReuseDuration(0);
} catch (error) {
print("Exception checking support. $error");
canAuthenticate = false;
}

return false;
return canAuthenticate;
}
}
5 changes: 3 additions & 2 deletions lib/entities/fs_migration.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';
import 'dart:convert';
import 'package:cake_wallet/core/secure_storage.dart';
import 'package:collection/collection.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand Down Expand Up @@ -147,8 +148,8 @@ Future<void> ios_migrate_pin() async {

final key = generateStoreKeyFor(key: SecretStoreKey.pinCodePassword);
final encodedPassword = encodedPinCode(pin: pinPassword);
await flutterSecureStorage.delete(key: key);
await flutterSecureStorage.write(key: key, value: encodedPassword);
await writeSecureStorage(flutterSecureStorage, key: key, value: encodedPassword);

await prefs.setBool('ios_migration_pin_completed', true);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/entities/get_encryption_key.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cake_wallet/core/secure_storage.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:cw_core/cake_hive.dart';

Expand All @@ -10,8 +11,7 @@ Future<List<int>> getEncryptionKey(
key = CakeHive.generateSecureKey();
final keyStringified = key.join(',');
String storageKey = 'transactionDescriptionsBoxKey';
await secureStorage.delete(key: storageKey);
await secureStorage.write(key: storageKey, value: keyStringified);
await writeSecureStorage(secureStorage, key: storageKey, value: keyStringified);
} else {
key = stringifiedKey.split(',').map((i) => int.parse(i)).toList();
}
Expand Down
Loading

0 comments on commit e5be737

Please sign in to comment.