Skip to content
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

bio auth on mac + package updates for 3.19.3/5 #1398

Merged
merged 17 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.8.10'
repositories {
google()
jcenter()
Expand Down
5 changes: 4 additions & 1 deletion cw_bitcoin/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,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
6 changes: 5 additions & 1 deletion cw_ethereum/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.1.11
build_runner: ^2.4.7

dependency_overrides:
watcher: ^1.1.0

flutter:
# assets:
# - images/a_dot_burr.jpeg
Expand Down
5 changes: 4 additions & 1 deletion cw_evm/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ 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
flutter_lints: ^2.0.0

dependency_overrides:
watcher: ^1.1.0

flutter:
# assets:
# - images/a_dot_burr.jpeg
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
5 changes: 4 additions & 1 deletion cw_polygon/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
build_runner: ^2.1.11
build_runner: ^2.4.7

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_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