mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-04 12:34:14 +01:00
Cw 540 encrypt shared (#1269)
* start writing migration * save * finishing up migration * more fixes * fixes * migration fixes * remove commented code and ensure widget initialization in root.dart * use securekey static functions everywhere applicable
This commit is contained in:
@@ -185,6 +185,9 @@ Future<void> defaultSettingsMigration(
|
||||
case 25:
|
||||
await rewriteSecureStoragePin(secureStorage: secureStorage);
|
||||
break;
|
||||
case 26:
|
||||
await insecureStorageMigration(secureStorage: secureStorage, sharedPreferences: sharedPreferences);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -378,6 +381,82 @@ Node getMoneroDefaultNode({required Box<Node> nodes}) {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> insecureStorageMigration({
|
||||
required SharedPreferences sharedPreferences,
|
||||
required FlutterSecureStorage secureStorage,
|
||||
}) async {
|
||||
bool? allowBiometricalAuthentication =
|
||||
sharedPreferences.getBool(SecureKey.allowBiometricalAuthenticationKey);
|
||||
bool? useTOTP2FA = sharedPreferences.getBool(SecureKey.useTOTP2FA);
|
||||
bool? shouldRequireTOTP2FAForAccessingWallet =
|
||||
sharedPreferences.getBool(SecureKey.shouldRequireTOTP2FAForAccessingWallet);
|
||||
bool? shouldRequireTOTP2FAForSendsToContact =
|
||||
sharedPreferences.getBool(SecureKey.shouldRequireTOTP2FAForSendsToContact);
|
||||
bool? shouldRequireTOTP2FAForSendsToNonContact =
|
||||
sharedPreferences.getBool(SecureKey.shouldRequireTOTP2FAForSendsToNonContact);
|
||||
bool? shouldRequireTOTP2FAForSendsToInternalWallets =
|
||||
sharedPreferences.getBool(SecureKey.shouldRequireTOTP2FAForSendsToInternalWallets);
|
||||
bool? shouldRequireTOTP2FAForExchangesToInternalWallets =
|
||||
sharedPreferences.getBool(SecureKey.shouldRequireTOTP2FAForExchangesToInternalWallets);
|
||||
bool? shouldRequireTOTP2FAForExchangesToExternalWallets =
|
||||
sharedPreferences.getBool(SecureKey.shouldRequireTOTP2FAForExchangesToExternalWallets);
|
||||
bool? shouldRequireTOTP2FAForAddingContacts =
|
||||
sharedPreferences.getBool(SecureKey.shouldRequireTOTP2FAForAddingContacts);
|
||||
bool? shouldRequireTOTP2FAForCreatingNewWallets =
|
||||
sharedPreferences.getBool(SecureKey.shouldRequireTOTP2FAForCreatingNewWallets);
|
||||
bool? shouldRequireTOTP2FAForAllSecurityAndBackupSettings =
|
||||
sharedPreferences.getBool(SecureKey.shouldRequireTOTP2FAForAllSecurityAndBackupSettings);
|
||||
int? selectedCake2FAPreset = sharedPreferences.getInt(SecureKey.selectedCake2FAPreset);
|
||||
String? totpSecretKey = sharedPreferences.getString(SecureKey.totpSecretKey);
|
||||
int? pinTimeOutDuration = sharedPreferences.getInt(SecureKey.pinTimeOutDuration);
|
||||
int? lastAuthTimeMilliseconds = sharedPreferences.getInt(SecureKey.lastAuthTimeMilliseconds);
|
||||
|
||||
try {
|
||||
await secureStorage.write(
|
||||
key: SecureKey.allowBiometricalAuthenticationKey,
|
||||
value: allowBiometricalAuthentication.toString());
|
||||
await secureStorage.write(key: SecureKey.useTOTP2FA, value: useTOTP2FA.toString());
|
||||
await secureStorage.write(
|
||||
key: SecureKey.shouldRequireTOTP2FAForAccessingWallet,
|
||||
value: shouldRequireTOTP2FAForAccessingWallet.toString());
|
||||
await secureStorage.write(
|
||||
key: SecureKey.shouldRequireTOTP2FAForSendsToContact,
|
||||
value: shouldRequireTOTP2FAForSendsToContact.toString());
|
||||
await secureStorage.write(
|
||||
key: SecureKey.shouldRequireTOTP2FAForSendsToNonContact,
|
||||
value: shouldRequireTOTP2FAForSendsToNonContact.toString());
|
||||
await secureStorage.write(
|
||||
key: SecureKey.shouldRequireTOTP2FAForSendsToInternalWallets,
|
||||
value: shouldRequireTOTP2FAForSendsToInternalWallets.toString());
|
||||
await secureStorage.write(
|
||||
key: SecureKey.shouldRequireTOTP2FAForExchangesToInternalWallets,
|
||||
value: shouldRequireTOTP2FAForExchangesToInternalWallets.toString());
|
||||
await secureStorage.write(
|
||||
key: SecureKey.shouldRequireTOTP2FAForExchangesToExternalWallets,
|
||||
value: shouldRequireTOTP2FAForExchangesToExternalWallets.toString());
|
||||
await secureStorage.write(
|
||||
key: SecureKey.shouldRequireTOTP2FAForAddingContacts,
|
||||
value: shouldRequireTOTP2FAForAddingContacts.toString());
|
||||
await secureStorage.write(
|
||||
key: SecureKey.shouldRequireTOTP2FAForCreatingNewWallets,
|
||||
value: shouldRequireTOTP2FAForCreatingNewWallets.toString());
|
||||
await secureStorage.write(
|
||||
key: SecureKey.shouldRequireTOTP2FAForAllSecurityAndBackupSettings,
|
||||
value: shouldRequireTOTP2FAForAllSecurityAndBackupSettings.toString());
|
||||
await secureStorage.write(
|
||||
key: SecureKey.selectedCake2FAPreset, value: selectedCake2FAPreset.toString());
|
||||
await secureStorage.write(key: SecureKey.totpSecretKey, value: totpSecretKey.toString());
|
||||
await secureStorage.write(
|
||||
key: SecureKey.pinTimeOutDuration, value: pinTimeOutDuration.toString());
|
||||
await secureStorage.write(
|
||||
key: SecureKey.lastAuthTimeMilliseconds, value: lastAuthTimeMilliseconds.toString());
|
||||
} catch (e) {
|
||||
print("Error migrating shared preferences to secure storage!: $e");
|
||||
// this actually shouldn't be that big of a problem since we don't delete the old keys in this update
|
||||
// and we read and write to the new locations when loading storage, the migration is just for extra safety
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> rewriteSecureStoragePin({required FlutterSecureStorage secureStorage}) async {
|
||||
// the bug only affects ios/mac:
|
||||
if (!Platform.isIOS && !Platform.isMacOS) {
|
||||
|
||||
@@ -23,8 +23,6 @@ class PreferencesKey {
|
||||
static const walletListOrder = 'wallet_list_order';
|
||||
static const walletListAscending = 'wallet_list_ascending';
|
||||
static const currentFiatApiModeKey = 'current_fiat_api_mode';
|
||||
static const allowBiometricalAuthenticationKey = 'allow_biometrical_authentication';
|
||||
static const useTOTP2FA = 'use_totp_2fa';
|
||||
static const failedTotpTokenTrials = 'failed_token_trials';
|
||||
static const disableExchangeKey = 'disable_exchange';
|
||||
static const exchangeStatusKey = 'exchange_status';
|
||||
@@ -33,6 +31,7 @@ class PreferencesKey {
|
||||
static const displayActionListModeKey = 'display_list_mode';
|
||||
static const currentPinLength = 'current_pin_length';
|
||||
static const currentLanguageCode = 'language_code';
|
||||
static const currentSeedPhraseLength = 'current_seed_phrase_length';
|
||||
static const currentDefaultSettingsMigrationVersion =
|
||||
'current_default_settings_migration_version';
|
||||
static const moneroTransactionPriority = 'current_fee_priority_monero';
|
||||
@@ -47,8 +46,6 @@ class PreferencesKey {
|
||||
static const moneroWalletPasswordUpdateV1Base = 'monero_wallet_update_v1';
|
||||
static const syncModeKey = 'sync_mode';
|
||||
static const syncAllKey = 'sync_all';
|
||||
static const pinTimeOutDuration = 'pin_timeout_duration';
|
||||
static const lastAuthTimeMilliseconds = 'last_auth_time_milliseconds';
|
||||
static const lastPopupDate = 'last_popup_date';
|
||||
static const lastAppReviewDate = 'last_app_review_date';
|
||||
static const sortBalanceBy = 'sort_balance_by';
|
||||
@@ -75,25 +72,4 @@ class PreferencesKey {
|
||||
static const lastSeenAppVersion = 'last_seen_app_version';
|
||||
static const shouldShowMarketPlaceInDashboard = 'should_show_marketplace_in_dashboard';
|
||||
static const isNewInstall = 'is_new_install';
|
||||
static const shouldRequireTOTP2FAForAccessingWallet =
|
||||
'should_require_totp_2fa_for_accessing_wallets';
|
||||
static const shouldRequireTOTP2FAForSendsToContact =
|
||||
'should_require_totp_2fa_for_sends_to_contact';
|
||||
static const shouldRequireTOTP2FAForSendsToNonContact =
|
||||
'should_require_totp_2fa_for_sends_to_non_contact';
|
||||
static const shouldRequireTOTP2FAForSendsToInternalWallets =
|
||||
'should_require_totp_2fa_for_sends_to_internal_wallets';
|
||||
static const shouldRequireTOTP2FAForExchangesToInternalWallets =
|
||||
'should_require_totp_2fa_for_exchanges_to_internal_wallets';
|
||||
static const shouldRequireTOTP2FAForExchangesToExternalWallets =
|
||||
'should_require_totp_2fa_for_exchanges_to_external_wallets';
|
||||
static const shouldRequireTOTP2FAForAddingContacts =
|
||||
'should_require_totp_2fa_for_adding_contacts';
|
||||
static const shouldRequireTOTP2FAForCreatingNewWallets =
|
||||
'should_require_totp_2fa_for_creating_new_wallets';
|
||||
static const shouldRequireTOTP2FAForAllSecurityAndBackupSettings =
|
||||
'should_require_totp_2fa_for_all_security_and_backup_settings';
|
||||
static const selectedCake2FAPreset = 'selected_cake_2fa_preset';
|
||||
static const totpSecretKey = 'totp_secret_key';
|
||||
static const currentSeedPhraseLength = 'current_seed_phrase_length';
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
enum SecretStoreKey { moneroWalletPassword, pinCodePassword, backupPassword }
|
||||
|
||||
const moneroWalletPassword = "MONERO_WALLET_PASSWORD";
|
||||
@@ -35,3 +38,65 @@ String generateStoreKeyFor({
|
||||
|
||||
return _key;
|
||||
}
|
||||
|
||||
class SecureKey {
|
||||
static const allowBiometricalAuthenticationKey = 'allow_biometrical_authentication';
|
||||
static const useTOTP2FA = 'use_totp_2fa';
|
||||
static const shouldRequireTOTP2FAForAccessingWallet =
|
||||
'should_require_totp_2fa_for_accessing_wallets';
|
||||
static const shouldRequireTOTP2FAForSendsToContact =
|
||||
'should_require_totp_2fa_for_sends_to_contact';
|
||||
static const shouldRequireTOTP2FAForSendsToNonContact =
|
||||
'should_require_totp_2fa_for_sends_to_non_contact';
|
||||
static const shouldRequireTOTP2FAForSendsToInternalWallets =
|
||||
'should_require_totp_2fa_for_sends_to_internal_wallets';
|
||||
static const shouldRequireTOTP2FAForExchangesToInternalWallets =
|
||||
'should_require_totp_2fa_for_exchanges_to_internal_wallets';
|
||||
static const shouldRequireTOTP2FAForExchangesToExternalWallets =
|
||||
'should_require_totp_2fa_for_exchanges_to_external_wallets';
|
||||
static const shouldRequireTOTP2FAForAddingContacts =
|
||||
'should_require_totp_2fa_for_adding_contacts';
|
||||
static const shouldRequireTOTP2FAForCreatingNewWallets =
|
||||
'should_require_totp_2fa_for_creating_new_wallets';
|
||||
static const shouldRequireTOTP2FAForAllSecurityAndBackupSettings =
|
||||
'should_require_totp_2fa_for_all_security_and_backup_settings';
|
||||
static const selectedCake2FAPreset = 'selected_cake_2fa_preset';
|
||||
static const totpSecretKey = 'totp_secret_key';
|
||||
static const pinTimeOutDuration = 'pin_timeout_duration';
|
||||
static const lastAuthTimeMilliseconds = 'last_auth_time_milliseconds';
|
||||
|
||||
static Future<int?> getInt({
|
||||
required FlutterSecureStorage secureStorage,
|
||||
required SharedPreferences sharedPreferences,
|
||||
required String key,
|
||||
}) async {
|
||||
int? value = int.tryParse((await secureStorage.read(key: key) ?? ''));
|
||||
value ??= sharedPreferences.getInt(key);
|
||||
return value;
|
||||
}
|
||||
|
||||
static Future<bool?> getBool({
|
||||
required FlutterSecureStorage secureStorage,
|
||||
required SharedPreferences sharedPreferences,
|
||||
required String key,
|
||||
}) async {
|
||||
String? value = (await secureStorage.read(key: key) ?? '');
|
||||
if (value.toLowerCase() == "true") {
|
||||
return true;
|
||||
} else if (value.toLowerCase() == "false") {
|
||||
return false;
|
||||
} else {
|
||||
return sharedPreferences.getBool(key);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<String?> getString({
|
||||
required FlutterSecureStorage secureStorage,
|
||||
required SharedPreferences sharedPreferences,
|
||||
required String key,
|
||||
}) async {
|
||||
String? value = await secureStorage.read(key: key);
|
||||
value ??= sharedPreferences.getString(key);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user