DEL: Reset keychain after uninstall

This commit is contained in:
marcosrdz 2021-01-14 10:30:29 -05:00
parent 1fcf8b2e8a
commit 7d9f81b543
4 changed files with 2 additions and 98 deletions

View File

@ -133,8 +133,6 @@ export const BlueStorageProvider = ({ children }) => {
const getHodlHodlApiKey = BlueApp.getHodlHodlApiKey; const getHodlHodlApiKey = BlueApp.getHodlHodlApiKey;
const createFakeStorage = BlueApp.createFakeStorage; const createFakeStorage = BlueApp.createFakeStorage;
const decryptStorage = BlueApp.decryptStorage; const decryptStorage = BlueApp.decryptStorage;
const isDeleteWalletAfterUninstallEnabled = BlueApp.isDeleteWalletAfterUninstallEnabled;
const setResetOnAppUninstallTo = BlueApp.setResetOnAppUninstallTo;
const isPasswordInUse = BlueApp.isPasswordInUse; const isPasswordInUse = BlueApp.isPasswordInUse;
const cachedPassword = BlueApp.cachedPassword; const cachedPassword = BlueApp.cachedPassword;
const setIsAdancedModeEnabled = BlueApp.setIsAdancedModeEnabled; const setIsAdancedModeEnabled = BlueApp.setIsAdancedModeEnabled;
@ -182,9 +180,7 @@ export const BlueStorageProvider = ({ children }) => {
setNewWalletAdded, setNewWalletAdded,
resetWallets, resetWallets,
getHodlHodlApiKey, getHodlHodlApiKey,
isDeleteWalletAfterUninstallEnabled,
decryptStorage, decryptStorage,
setResetOnAppUninstallTo,
isPasswordInUse, isPasswordInUse,
setIsAdancedModeEnabled, setIsAdancedModeEnabled,
setPreferredFiatCurrency, setPreferredFiatCurrency,

View File

@ -16,7 +16,6 @@ import {
HDSegwitElectrumSeedP2WPKHWallet, HDSegwitElectrumSeedP2WPKHWallet,
MultisigHDWallet, MultisigHDWallet,
} from './'; } from './';
import { Platform } from 'react-native';
const encryption = require('../blue_modules/encryption'); const encryption = require('../blue_modules/encryption');
const Realm = require('realm'); const Realm = require('realm');
const createHash = require('create-hash'); const createHash = require('create-hash');
@ -33,7 +32,6 @@ export class AppStorage {
static ELECTRUM_SERVER_HISTORY = 'electrum_server_history'; static ELECTRUM_SERVER_HISTORY = 'electrum_server_history';
static PREFERRED_CURRENCY = 'preferredCurrency'; static PREFERRED_CURRENCY = 'preferredCurrency';
static ADVANCED_MODE_ENABLED = 'advancedmodeenabled'; static ADVANCED_MODE_ENABLED = 'advancedmodeenabled';
static DELETE_WALLET_AFTER_UNINSTALL = 'deleteWalletAfterUninstall';
static HODL_HODL_API_KEY = 'HODL_HODL_API_KEY'; static HODL_HODL_API_KEY = 'HODL_HODL_API_KEY';
static HODL_HODL_SIGNATURE_KEY = 'HODL_HODL_SIGNATURE_KEY'; static HODL_HODL_SIGNATURE_KEY = 'HODL_HODL_SIGNATURE_KEY';
static HODL_HODL_CONTRACTS = 'HODL_HODL_CONTRACTS'; static HODL_HODL_CONTRACTS = 'HODL_HODL_CONTRACTS';
@ -76,16 +74,6 @@ export class AppStorage {
} }
}; };
setResetOnAppUninstallTo = async value => {
if (Platform.OS === 'ios') {
await this.setItem(AppStorage.DELETE_WALLET_AFTER_UNINSTALL, value ? '1' : '');
try {
RNSecureKeyStore.setResetOnAppUninstallTo(value);
} catch (Error) {
console.warn(Error);
}
}
};
storageIsEncrypted = async () => { storageIsEncrypted = async () => {
let data; let data;
@ -140,7 +128,6 @@ export class AppStorage {
decryptStorage = async password => { decryptStorage = async password => {
if (password === this.cachedPassword) { if (password === this.cachedPassword) {
this.cachedPassword = undefined; this.cachedPassword = undefined;
await this.setResetOnAppUninstallTo(true);
await this.saveToDisk(); await this.saveToDisk();
this.wallets = []; this.wallets = [];
this.tx_metadata = []; this.tx_metadata = [];
@ -150,16 +137,6 @@ export class AppStorage {
} }
}; };
isDeleteWalletAfterUninstallEnabled = async () => {
let deleteWalletsAfterUninstall;
try {
deleteWalletsAfterUninstall = await this.getItem(AppStorage.DELETE_WALLET_AFTER_UNINSTALL);
} catch (_e) {
deleteWalletsAfterUninstall = true;
}
return !!deleteWalletsAfterUninstall;
};
encryptStorage = async password => { encryptStorage = async password => {
// assuming the storage is not yet encrypted // assuming the storage is not yet encrypted
await this.saveToDisk(); await this.saveToDisk();

View File

@ -1,6 +1,6 @@
/* global alert */ /* global alert */
import React, { useEffect, useState, useCallback, useContext } from 'react'; import React, { useEffect, useState, useCallback, useContext } from 'react';
import { ScrollView, Alert, Platform, TouchableOpacity, TouchableWithoutFeedback, StyleSheet } from 'react-native'; import { ScrollView, Alert, TouchableOpacity, TouchableWithoutFeedback, StyleSheet } from 'react-native';
import { useNavigation } from '@react-navigation/native'; import { useNavigation } from '@react-navigation/native';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback'; import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import { colors } from 'react-native-elements'; import { colors } from 'react-native-elements';
@ -10,20 +10,11 @@ import { BlueLoading, SafeBlueArea, BlueSpacing20, BlueCard, BlueListItem, BlueH
import Biometric from '../../class/biometrics'; import Biometric from '../../class/biometrics';
import loc from '../../loc'; import loc from '../../loc';
import { BlueStorageContext } from '../../blue_modules/storage-context'; import { BlueStorageContext } from '../../blue_modules/storage-context';
import { isCatalyst } from '../../blue_modules/environment';
const prompt = require('../../blue_modules/prompt'); const prompt = require('../../blue_modules/prompt');
const EncryptStorage = () => { const EncryptStorage = () => {
const { const { isStorageEncrypted, encryptStorage, decryptStorage, saveToDisk } = useContext(BlueStorageContext);
isStorageEncrypted,
setResetOnAppUninstallTo,
encryptStorage,
isDeleteWalletAfterUninstallEnabled,
decryptStorage,
saveToDisk,
} = useContext(BlueStorageContext);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [deleteWalletsAfterUninstall, setDeleteWalletsAfterUninstall] = useState(false);
const [biometrics, setBiometrics] = useState({ isDeviceBiometricCapable: false, isBiometricsEnabled: false, biometricsType: '' }); const [biometrics, setBiometrics] = useState({ isDeviceBiometricCapable: false, isBiometricsEnabled: false, biometricsType: '' });
const [storageIsEncryptedSwitchEnabled, setStorageIsEncryptedSwitchEnabled] = useState(false); const [storageIsEncryptedSwitchEnabled, setStorageIsEncryptedSwitchEnabled] = useState(false);
const { navigate, popToTop } = useNavigation(); const { navigate, popToTop } = useNavigation();
@ -38,10 +29,8 @@ const EncryptStorage = () => {
const isBiometricsEnabled = await Biometric.isBiometricUseEnabled(); const isBiometricsEnabled = await Biometric.isBiometricUseEnabled();
const isDeviceBiometricCapable = await Biometric.isDeviceBiometricCapable(); const isDeviceBiometricCapable = await Biometric.isDeviceBiometricCapable();
const biometricsType = (await Biometric.biometricType()) || loc.settings.biometrics; const biometricsType = (await Biometric.biometricType()) || loc.settings.biometrics;
const deleteWalletsAfterUninstall = await isDeleteWalletAfterUninstallEnabled();
const isStorageEncryptedSwitchEnabled = await isStorageEncrypted(); const isStorageEncryptedSwitchEnabled = await isStorageEncrypted();
setStorageIsEncryptedSwitchEnabled(isStorageEncryptedSwitchEnabled); setStorageIsEncryptedSwitchEnabled(isStorageEncryptedSwitchEnabled);
setDeleteWalletsAfterUninstall(deleteWalletsAfterUninstall);
setBiometrics({ isBiometricsEnabled, isDeviceBiometricCapable, biometricsType }); setBiometrics({ isBiometricsEnabled, isDeviceBiometricCapable, biometricsType });
setIsLoading(false); setIsLoading(false);
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
@ -67,17 +56,10 @@ const EncryptStorage = () => {
setIsLoading(false); setIsLoading(false);
setStorageIsEncryptedSwitchEnabled(await isStorageEncrypted()); setStorageIsEncryptedSwitchEnabled(await isStorageEncrypted());
setDeleteWalletsAfterUninstall(await isDeleteWalletAfterUninstallEnabled());
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}; };
const onDeleteWalletsAfterUninstallSwitch = async value => {
await setResetOnAppUninstallTo(value);
setDeleteWalletsAfterUninstall(value);
// eslint-disable-next-line react-hooks/exhaustive-deps
};
const onEncryptStorageSwitch = async value => { const onEncryptStorageSwitch = async value => {
setIsLoading(true); setIsLoading(true);
if (value === true) { if (value === true) {
@ -170,17 +152,6 @@ const EncryptStorage = () => {
Component={TouchableWithoutFeedback} Component={TouchableWithoutFeedback}
switch={{ onValueChange: onEncryptStorageSwitch, value: storageIsEncryptedSwitchEnabled }} switch={{ onValueChange: onEncryptStorageSwitch, value: storageIsEncryptedSwitchEnabled }}
/> />
{Platform.OS === 'ios' && !isCatalyst && (
<BlueListItem
hideChevron
title={loc.settings.encrypt_del_uninstall}
Component={TouchableWithoutFeedback}
switch={{
onValueChange: onDeleteWalletsAfterUninstallSwitch,
value: deleteWalletsAfterUninstall,
}}
/>
)}
{storageIsEncryptedSwitchEnabled && ( {storageIsEncryptedSwitchEnabled && (
<BlueListItem <BlueListItem
onPress={navigateToPlausibleDeniability} onPress={navigateToPlausibleDeniability}

View File

@ -1,11 +1,6 @@
import { AppStorage } from '../../class';
import AsyncStorage from '@react-native-async-storage/async-storage'; import AsyncStorage from '@react-native-async-storage/async-storage';
import RNFS from 'react-native-fs'; import RNFS from 'react-native-fs';
import RNSecureKeyStore, { ACCESSIBLE } from 'react-native-secure-key-store'; import RNSecureKeyStore, { ACCESSIBLE } from 'react-native-secure-key-store';
import DefaultPreference from 'react-native-default-preference';
import { Platform } from 'react-native';
import { isCatalyst } from '../../blue_modules/environment';
export default class WalletMigrate { export default class WalletMigrate {
static expoDataDirectory = RNFS.DocumentDirectoryPath + '/ExponentExperienceData/%40overtorment%2Fbluewallet/RCTAsyncLocalStorage'; static expoDataDirectory = RNFS.DocumentDirectoryPath + '/ExponentExperienceData/%40overtorment%2Fbluewallet/RCTAsyncLocalStorage';
@ -15,41 +10,6 @@ export default class WalletMigrate {
// 0: Let's start! // 0: Let's start!
async start() { async start() {
if (Platform.OS === 'ios' && !isCatalyst) {
const defaultPreferenceGroupName = await DefaultPreference.getName();
console.log('----- defaultPreferenceGroupName');
console.log(defaultPreferenceGroupName);
console.log('----- ');
const isNotFirstLaunch = await DefaultPreference.get('RnSksIsAppInstalled');
console.log('----- isNotFirstLaunch');
console.log(isNotFirstLaunch);
console.log('----- ');
if (isNotFirstLaunch === undefined) {
try {
console.warn('It is the first launch...');
await RNSecureKeyStore.setResetOnAppUninstallTo(false);
let deleteWalletsFromKeychain = '1';
try {
deleteWalletsFromKeychain = await RNSecureKeyStore.get(AppStorage.DELETE_WALLET_AFTER_UNINSTALL);
await RNSecureKeyStore.setResetOnAppUninstallTo(deleteWalletsFromKeychain === '1');
await RNSecureKeyStore.get(AppStorage.DELETE_WALLET_AFTER_UNINSTALL);
} catch (e) {
console.log('----- deleteWalletsFromKeychain catch');
console.log(e.message);
await RNSecureKeyStore.setResetOnAppUninstallTo(deleteWalletsFromKeychain === '1');
await RNSecureKeyStore.get(AppStorage.DELETE_WALLET_AFTER_UNINSTALL);
}
console.log('----- deleteWalletsFromKeychain');
console.log(deleteWalletsFromKeychain);
console.log('----- ');
} catch (e) {
console.log(e);
}
} else {
console.warn('It is NOT the first launch...');
}
await DefaultPreference.set('RnSksIsAppInstalled', '1');
}
return this.migrateDataFromExpo(); return this.migrateDataFromExpo();
} }