Skip to content

fix: safe biometry migration #607

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions src/sagas/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
firstAddressFailure,
firstAddressSuccess,
setUseSafeBiometryMode,
lockScreen,
} from '../actions';
import { fetchTokenData } from './tokens';
import {
Expand Down Expand Up @@ -437,8 +438,8 @@ export function* onPushNotificationDisabled() {
}

export function* onSafeBiometryToggleChanged() {
log.debug('Safe biometry mode feature toggle changed state, reloading wallet.');
yield put(reloadWalletRequested());
log.debug('Safe biometry mode feature toggle changed state, locking wallet.');
yield put(lockScreen());
}

/**
Expand Down
31 changes: 21 additions & 10 deletions src/screens/PinScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import baseStyle from '../styles/init';
import Spinner from '../components/Spinner';
import FeedbackModal from '../components/FeedbackModal';
import errorIcon from '../assets/images/icErrorBig.png';
import { logger } from '../logger';

const log = logger('PIN_SCREEN');

/**
* loadHistoryActive {bool} whether we still need to load history
Expand Down Expand Up @@ -147,17 +150,25 @@ class PinScreen extends React.Component {
if (this.props.isLockScreen) {
// in case it's the lock screen, we just have to execute the data migration
// method an change redux state. No need to execute callback or go back on navigation
await STORE.handleDataMigration(pin);
await biometricsMigration(pin, this.props.safeBiometryEnabled);
if (!this.props.wallet) {
// We have already made sure we have an available accessData
// The handleDataMigration method ensures we have already migrated if necessary
// This means the wallet is loaded and the access data is ready to be used.

const words = await STORE.getWalletWords(pin);
this.props.startWalletRequested({ words, pin });
try {
await STORE.handleDataMigration(pin);
const newPin = await biometricsMigration(pin, this.props.safeBiometryEnabled);
if (!this.props.wallet) {
// We have already made sure we have an available accessData
// The handleDataMigration method ensures we have already migrated if necessary
// This means the wallet is loaded and the access data is ready to be used.

const words = await STORE.getWalletWords(newPin);
this.props.startWalletRequested({ words, pin: newPin });
}
this.props.unlockScreen();
} catch (e) {
log.debug(e);
this.props.onExceptionCaptured(
new Error('Error during wallet initialization.'),
true, // Fatal since we can't start the wallet
);
}
this.props.unlockScreen();
} else {
// dismiss the pin screen first because doing it after the callback can
// end up dismissing the wrong screen
Expand Down
7 changes: 7 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const getTokenLabel = (token) => `${token.name} (${token.symbol})`;
*
* @param {string} currentPassword
* @param {bool} safeBiometryEnabled
* @return {string} The actual pin/password for the application.
*/
export async function biometricsMigration(currentPassword, safeBiometryEnabled) {
const oldBiometry = STORE.getItem(IS_OLD_BIOMETRY_ENABLED_KEY);
Expand All @@ -111,6 +112,8 @@ export async function biometricsMigration(currentPassword, safeBiometryEnabled)
await changePinOnAccessData(storage, currentPassword, password);
STORE.enableSafeBiometry(currentPassword, password);
STORE.removeItem(IS_OLD_BIOMETRY_ENABLED_KEY);

return password;
}
} else {
// Old biometry mode, need to migrate if safe biometry is enabled.
Expand All @@ -123,8 +126,12 @@ export async function biometricsMigration(currentPassword, safeBiometryEnabled)
await changePinOnAccessData(storage, currentPassword, pin);
STORE.removeItem(IS_BIOMETRY_ENABLED_KEY);
STORE.setItem(IS_OLD_BIOMETRY_ENABLED_KEY, true);

return pin;
}
}

return currentPassword;
}

/**
Expand Down