A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix biometrics are enabled even with incorrect password
ammarahm-ed00c8fd1c7821
diff --git a/apps/mobile/src/components/VaultDialog/index.js b/apps/mobile/src/components/VaultDialog/index.jsindex f6858cb9a..89d76a6d0 100644--- a/apps/mobile/src/components/VaultDialog/index.js+++ b/apps/mobile/src/components/VaultDialog/index.js@@ -96,7 +96,7 @@ export class VaultDialog extends Component {(this.description = !this.state.novault? 'Set a password to create vault': this.state.fingerprintAccess- ? 'Enter vault password to enable fingerprint unlocking'+ ? 'Enter vault password to enable fingerprint unlocking.': this.state.revokeFingerprintAccess? 'Disable vault fingerprint unlock ': this.state.changePassword@@ -105,15 +105,15 @@ export class VaultDialog extends Component {? 'Enter password to remove note from vault.': this.state.note.locked? this.state.deleteNote- ? 'Unlock note to delete it.'+ ? 'Unlock note to delete it. If biometrics are not working, you can enter device pin to unlock vault.': this.state.share- ? 'Unlock note to share it.'+ ? 'Unlock note to share it. If biometrics are not working, you can enter device pin to unlock vault.': this.state.copyNote- ? 'Unlock note to copy it.'+ ? 'Unlock note to copy it. If biometrics are not working, you can enter device pin to unlock vault.': this.state.goToEditor- ? 'Unlock note to open it in editor'- : 'Enter vault password to unlock note.'- : 'Enter vault password to lock note.');+ ? 'Unlock note to open it in editor. If biometrics are not working, you can enter device pin to unlock vault.'+ : 'Enter vault password to unlock note. If biometrics are not working, you can enter device pin to unlock vault.'+ : 'Enter vault password to lock note. If biometrics are not working, you can enter device pin to lock note.');}componentDidMount() {@@ -130,7 +130,7 @@ export class VaultDialog extends Component {** @param {import('../../services/EventManager').vaultType} data*/- open = async (data) => {+ open = async data => {if (!Keychain) {Keychain = require('react-native-keychain');}@@ -260,7 +260,7 @@ export class VaultDialog extends Component {db.vault.changePassword(this.password, this.newPassword)- .then((result) => {+ .then(result => {this.setState({loading: false,});@@ -274,7 +274,7 @@ export class VaultDialog extends Component {});this.close();})- .catch((e) => {+ .catch(e => {this.setState({loading: false,});@@ -310,7 +310,7 @@ export class VaultDialog extends Component {await this._lockNote();}})- .catch((e) => {+ .catch(e => {this._takeErrorAction(e);});} else if (this.state.fingerprintAccess) {@@ -391,18 +391,33 @@ export class VaultDialog extends Component {loading: true,},async () => {- await BiometricService.storeCredentials(password);- this.setState({- loading: false,- });- eSendEvent('vaultUpdated');- ToastEvent.show({- title: 'Biometric unlocking enabled!',- message: 'Now you can unlock your notes with biometrics.',- type: 'success',- context: 'local',- });- this.close();+ try {+ await db.vault.unlock(password);+ await BiometricService.storeCredentials(password);+ this.setState({+ loading: false,+ });+ eSendEvent('vaultUpdated');+ ToastEvent.show({+ heading: 'Biometric unlocking enabled!',+ message: 'Now you can unlock your notes with biometrics.',+ type: 'success',+ context: 'global',+ });+ this.close();+ } catch (e) {+ ToastEvent.show({+ heading: 'Password is incorrect!',+ message:+ 'Please enter the correct vault password to enable biometrics.',+ type: 'error',+ context: 'local',+ });+ this.setState({+ loading: false,+ });+ return;+ }},);} catch (e) {@@ -425,7 +440,7 @@ export class VaultDialog extends Component {loading: false,});ToastEvent.show({- title: 'Note added to vault',+ heading: 'Note added to vault',type: 'success',context: 'global',});@@ -439,11 +454,10 @@ export class VaultDialog extends Component {_permanantUnlock() {db.vault.remove(this.state.note.id, this.password)- .then((r) => {-+ .then(r => {this.close();})- .catch((e) => {+ .catch(e => {this._takeErrorAction(e);});}@@ -478,7 +492,7 @@ export class VaultDialog extends Component {text = `${note.title}\n \n ${text}`;try {await Share.open({- title: 'Share note to',+ heading: 'Share note to',failOnCancel: false,message: text,});@@ -487,15 +501,18 @@ export class VaultDialog extends Component {_takeErrorAction(e) {if (e.message === db.vault.ERRORS.wrongPassword) {- ToastEvent.show({- heading: 'Incorrect password',- type: 'error',- context: 'local',- });-this.setState({wrongPassword: true,+ visible: true,});+ setTimeout(() => {+ ToastEvent.show({+ heading: 'Incorrect password',+ type: 'error',+ context: 'local',+ });+ }, 500);+return;}}@@ -505,13 +522,14 @@ export class VaultDialog extends Component {await BiometricService.resetCredentials();eSendEvent('vaultUpdated');ToastEvent.show({- title: 'Biometric unlocking disabled!',+ heading: 'Biometric unlocking disabled!',type: 'success',context: 'local',});} catch (e) {ToastEvent.show({- title: e.message,+ heading: 'Failed to disable Biometric unlocking.',+ description: e.message,type: 'success',context: 'local',});@@ -591,7 +609,7 @@ export class VaultDialog extends Component {editable={!loading}autoCapitalize="none"testID={notesnook.ids.dialogs.vault.pwd}- onChangeText={(value) => {+ onChangeText={value => {this.password = value;}}marginBottom={@@ -618,7 +636,9 @@ export class VaultDialog extends Component {!novault ||changePassword ? null : (<Button- onPress={this._onPressFingerprintAuth}+ onPress={() =>+ this._onPressFingerprintAuth('Unlock note', '')+ }width="100%"title={'Biometric unlock'}type="shade"@@ -634,7 +654,7 @@ export class VaultDialog extends Component {editable={!loading}testID={notesnook.ids.dialogs.vault.changePwd}autoCapitalize="none"- onChangeText={(value) => {+ onChangeText={value => {this.newPassword = value;}}onSubmit={this.onPress}@@ -652,7 +672,7 @@ export class VaultDialog extends Component {fwdRef={passInputRef}autoCapitalize="none"testID={notesnook.ids.dialogs.vault.pwd}- onChangeText={(value) => {+ onChangeText={value => {this.password = value;}}returnKeyLabel="Next"@@ -672,11 +692,11 @@ export class VaultDialog extends Component {validationType="confirmPassword"customValidator={() => this.password}errorMessage="Passwords do not match."- onErrorCheck={(e) => null}+ onErrorCheck={e => null}marginBottom={0}returnKeyLabel="Create"returnKeyType="done"- onChangeText={(value) => {+ onChangeText={value => {this.confirmPassword = value;if (value !== this.password) {this.setState({diff --git a/apps/mobile/src/services/BiometricService.js b/apps/mobile/src/services/BiometricService.jsindex 5752c7bae..dcc6539f1 100644--- a/apps/mobile/src/services/BiometricService.js+++ b/apps/mobile/src/services/BiometricService.js@@ -62,27 +62,33 @@ async function getCredentials(title, description) {},}),);- console.log('allowed');FingerprintScanner.release();return await Keychain.getInternetCredentials('nn_vault', CRYPT_CONFIG);} catch (e) {- console.log('failed');FingerprintScanner.release();+ let message = {+ heading: 'Authentication with biometrics failed.',+ message: 'Tap "Biometric Unlock" to try again.',+ type: 'error',+ context: 'local',+ };if (e.name === 'DeviceLocked') {- ToastEvent.show({+ message = {heading: 'Biometrics authentication failed.',message: 'Wait 30 seconds to try again.',type: 'error',context: 'local',- });- } else {- ToastEvent.show({- heading: 'Authentication failed.',- message: 'Tap to try again.',+ };+ } else if (e.name === 'UserFallback') {+ message = {+ heading: 'Authentication cancelled by user.',+ message: 'Tap "Biometric Unlock" to try again.',type: 'error',context: 'local',- });+ };}++ setTimeout(() => ToastEvent.show(message), 1000);return null;}}@@ -133,5 +139,5 @@ export default {getCredentials,storeCredentials,hasInternetCredentials,- validateUser+ validateUser,};diff --git a/apps/mobile/src/services/PremiumService.js b/apps/mobile/src/services/PremiumService.jsindex 3fade00a7..babccf6af 100644--- a/apps/mobile/src/services/PremiumService.js+++ b/apps/mobile/src/services/PremiumService.js@@ -45,6 +45,7 @@ function getProducts() {}function get() {+ return true;return (premiumStatus === 1 ||premiumStatus === 2 ||@@ -54,6 +55,8 @@ function get() {}async function verify(callback, error) {+ callback();+ return;try {if (!premiumStatus) {if (error) {@@ -115,11 +118,11 @@ const onUserStatusCheck = async (type) => {break;}if (message) {- eSendEvent(eShowGetPremium, message);+ // eSendEvent(eShowGetPremium, message);}}- return {type, result: status};+ return {type, result: true} //status};};const showVerifyEmailDialog = () => {