Skip to content

Commit

Permalink
Injimob 2310 - Handle iOS biometric negative scenarios (#1699)
Browse files Browse the repository at this point in the history
* [INJIMOB-2310]: handle biometric cancellation during app launch

Signed-off-by: adityankannan-tw <[email protected]>

* [INJIMOB-2310]: update secure keystore package and refactor

Signed-off-by: adityankannan-tw <[email protected]>

---------

Signed-off-by: adityankannan-tw <[email protected]>
Co-authored-by: adityankannan-tw <[email protected]>
  • Loading branch information
adityankannan-tw and Adityankannan authored Nov 25, 2024
1 parent 4ee227c commit e6702e9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ios/Inji.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"location" : "https://github.com/mosip/secure-keystore-ios-swift",
"state" : {
"branch" : "release-0.3.x",
"revision" : "068969c69eb56d906bf717628aa52e10cf0747ad"
"revision" : "71e155c9cecf4675933e2e6044b0a7838bc7ad58"
}
},
{
Expand Down
8 changes: 8 additions & 0 deletions machines/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const model = createModel(
STORE_RESPONSE: (response: unknown) => ({response}),
RESET_KEY_INVALIDATE_ERROR_DISMISS: () => ({}),
RESET_LINKCODE: () => ({}),
BIOMETRIC_CANCELLED: () => ({}),
},
},
);
Expand Down Expand Up @@ -101,6 +102,9 @@ export const appMachine = model.createMachine(
actions: ['resetKeyInvalidateError'],
target: 'init',
},
BIOMETRIC_CANCELLED: {
target: 'init'
}
},
states: {
init: {
Expand Down Expand Up @@ -166,6 +170,10 @@ export const appMachine = model.createMachine(
],
target: 'info',
},
BIOMETRIC_CANCELLED: {
target: 'store'
}

},
},
info: {
Expand Down
7 changes: 7 additions & 0 deletions machines/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const model = createModel(
ONBOARDING_DONE: () => ({}),
INITIAL_DOWNLOAD_DONE: () => ({}),
SET_TOUR_GUIDE: (set: boolean) => ({set}),
BIOMETRIC_CANCELLED: () => ({}),
},
},
);
Expand Down Expand Up @@ -63,6 +64,9 @@ export const authMachine = model.createMachine(
SET_TOUR_GUIDE: {
actions: 'setTourGuide',
},
BIOMETRIC_CANCELLED: {
target: 'init'
},
},
states: {
init: {
Expand All @@ -76,6 +80,9 @@ export const authMachine = model.createMachine(
},
{target: 'savingDefaults'},
],
BIOMETRIC_CANCELLED: [{
target: 'init'
}],
},
},
savingDefaults: {
Expand Down
15 changes: 14 additions & 1 deletion machines/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {assign, ContextFrom, EventFrom, send, StateFrom} from 'xstate';
import {assign, ContextFrom, EventFrom, send, StateFrom, sendUpdate} from 'xstate';
import {createModel} from 'xstate/lib/model';
import {AppServices} from '../shared/GlobalContext';
import {
Expand Down Expand Up @@ -72,6 +72,7 @@ const model = createModel(
RESET_KEY_ORDER_RESPONSE: () => ({}),
SHOWN_ACCOUNT_SELECTION_CONFIRMATION: () => ({}),
DISMISS: () => ({}),
BIOMETRIC_CANCELLED: (requester?: string) => ({requester}),
},
},
);
Expand Down Expand Up @@ -106,6 +107,18 @@ export const settingsMachine = model.createMachine(
},
{target: 'storingDefaults'},
],
BIOMETRIC_CANCELLED: {
actions: [
send(
(_, event) => model.events.BIOMETRIC_CANCELLED(event.requester),
{
to: (_, event) => event.requester,
},
),
sendUpdate(),
],
target: 'init',
},
},
},
storingDefaults: {
Expand Down
44 changes: 30 additions & 14 deletions machines/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {NativeModules} from 'react-native';
import {
AUTH_TIMEOUT,
decryptJson,
DUMMY_KEY_FOR_BIOMETRIC_ALIAS,
ENCRYPTION_ID,
encryptJson,
HMAC_ALIAS,
Expand Down Expand Up @@ -274,6 +273,19 @@ export const storeMachine =
DECRYPT_ERROR: {
actions: sendParent('DECRYPT_ERROR'),
},
BIOMETRIC_CANCELLED: {
actions: [
send(
(_, event) => model.events.BIOMETRIC_CANCELLED(event.requester),
{
to: (_, event) => event.requester,
},
),
sendUpdate(),
sendParent('BIOMETRIC_CANCELLED')
],
target: 'checkFreshInstall',
}
},
},
},
Expand All @@ -290,18 +302,11 @@ export const storeMachine =
actions: sendParent('KEY_INVALIDATE_ERROR'),
},
BIOMETRIC_CANCELLED: {
actions: [
send(
(_, event) => model.events.BIOMETRIC_CANCELLED(event.requester),
{
to: (_, event) => event.requester,
},
),
sendUpdate(),
],
},
actions: [sendParent('BIOMETRIC_CANCELLED')],
target: 'checkFreshInstall'
},
},
},
{
actions: {
notifyParent: sendParent(model.events.READY()),
Expand All @@ -328,9 +333,17 @@ export const storeMachine =
}
return;
},
checkFreshInstall: () => async _ => {
const response = await getItem('auth', null, '');
return response;
checkFreshInstall: () => async callback => {
try{
return await getItem('auth', null, '');
}
catch(e){
if(e instanceof BiometricCancellationError){
callback(model.events.BIOMETRIC_CANCELLED());
} else {
callback(model.events.STORE_ERROR(e));
}
}
},
hasEncryptionKey: () => async callback => {
let hasSetCredentials;
Expand All @@ -350,6 +363,9 @@ export const storeMachine =
base64EncodedString,
);
} catch (e) {
if(e instanceof BiometricCancellationError){
callback(model.events.BIOMETRIC_CANCELLED(event.requester));
}
sendErrorEvent(getErrorEventData('ENCRYPTION', '', e));

if (e.message.includes(keyinvalidatedString)) {
Expand Down

0 comments on commit e6702e9

Please sign in to comment.