Skip to content

Commit

Permalink
feat(INJI-436): add telemetry events to track the app generated warnings
Browse files Browse the repository at this point in the history
Signed-off-by: PuBHARGAVI <[email protected]>
  • Loading branch information
PuBHARGAVI committed Nov 2, 2023
1 parent 8b633ec commit 844c227
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 22 deletions.
8 changes: 5 additions & 3 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ fileignoreconfig:
checksum: ffe9aac2dcc590b98b0d588885c088eff189504ade653a77f74b67312bfd27ad
- filename: shared/fileStorage.ts
checksum: 07cb337dc1d5b0f0eef56270ac4f4f589260ee5e490183c024cf98a2aeafb139
- filename: shared/storage.ts
checksum: c8d874aa373bdf526bf59192139822f56915e702ef673bac4e0d7549b0fea3d0
- filename: screens/Issuers/IssuersScreen.tsx
checksum: bc12c43ccc27ac04e5763fa6a6ed3cee63e4362ba5666c160b5e53269de924ab
checksum: 9a61cd59a3718adf1f14faf3024fec66a3295ef373878a878a28e5cb1287afaa
Expand Down Expand Up @@ -61,4 +59,8 @@ fileignoreconfig:
- filename: machines/store.typegen.ts
checksum: 6d22bc5c77398316b943c512c208ce0846a9fff674c1ccac79e07f21962acd5f
- filename: machines/VCItemMachine/ExistingMosipVCItem/ExistingMosipVCItemMachine.typegen.ts
checksum: 533785a3c8096ea93afc59c65025679c24d379e824e784e745ab298a0978cd2a
checksum: 533785a3c8096ea93afc59c65025679c24d379e824e784e745ab298a0978cd2a
- filename: machines/store.ts
checksum: 30a5e44e8192aa686255aa9bcc637226bd55c4e622bee23d79f5abad1c7a6a8a
- filename: shared/storage.ts
checksum: 7ad8b7697614366eb7e372ea80c1c3bf4a4f4bb93bd4fe4b3f1e79e352cce631
20 changes: 19 additions & 1 deletion App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ import {
import {DualMessageOverlay} from './components/DualMessageOverlay';
import {useApp} from './screens/AppController';
import {Alert} from 'react-native';
import {configureTelemetry} from './shared/telemetry/TelemetryUtils';
import {
TelemetryConstants,
configureTelemetry,
getErrorEventData,
sendErrorEvent,
} from './shared/telemetry/TelemetryUtils';
import {MessageOverlay} from './components/MessageOverlay';
import SecureKeystore from 'react-native-secure-keystore';
import {isHardwareKeystoreExists} from './shared/cryptoutil/cryptoUtil';
import i18n from './i18n';
import './shared/flipperConfig';
import {__AppId} from './shared/GlobalVariables';

// kludge: this is a bad practice but has been done temporarily to surface
// an occurance of a bug with minimal residual code changes, this should
Expand Down Expand Up @@ -59,6 +65,18 @@ const AppLoadingWrapper: React.FC = () => {
);
const controller = useApp();
const {t} = useTranslation('WelcomeScreen');
useEffect(() => {
if (isKeyInvalidateError) {
configureTelemetry();
sendErrorEvent(
getErrorEventData(
TelemetryConstants.FlowType.appLogin,
TelemetryConstants.ErrorId.appWasReset,
TelemetryConstants.ErrorMessage.appWasReset,
),
);
}
}, [isKeyInvalidateError]);
return (
<>
<AppLoading />
Expand Down
14 changes: 11 additions & 3 deletions machines/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,13 @@ export const settingsMachine = model.createMachine(
}),

updateDefaults: model.assign({
appId: () => {
const appId = generateAppId();
appId: (_, event) => {
const appId =
event.response != null &&
event.response.encryptedData == null &&
event.response.appId != null
? event.response.appId
: generateAppId();
__AppId.setValue(appId);
return appId;
},
Expand Down Expand Up @@ -246,7 +251,10 @@ export const settingsMachine = model.createMachine(
},

guards: {
hasData: (_, event) => event.response != null,
hasData: (_, event) =>
event.response != null &&
event.response.encryptedData != null &&
event.response.appId != null,
hasPartialData: (_, event) =>
event.response != null && event.response.appId == null,
},
Expand Down
10 changes: 1 addition & 9 deletions machines/settings.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,12 @@ export interface Typegen0 {
resetInjiProps: 'done.invoke.settings.resetInjiProps:invocation[0]';
};
missingImplementations: {
actions: 'injiTourGuide';
actions: never;
delays: never;
guards: never;
services: never;
};
eventsCausingActions: {
injiTourGuide:
| 'ACCEPT_HARDWARE_SUPPORT_NOT_EXISTS'
| 'BACK'
| 'CANCEL'
| 'STORE_RESPONSE'
| 'done.invoke.settings.resetInjiProps:invocation[0]'
| 'error.platform.settings.resetInjiProps:invocation[0]';
requestStoredContext: 'xstate.init';
resetCredentialRegistry: 'CANCEL' | 'UPDATE_MIMOTO_HOST';
setContext: 'STORE_RESPONSE';
Expand Down Expand Up @@ -64,7 +57,6 @@ export interface Typegen0 {
matchesStates:
| 'idle'
| 'init'
| 'injiTourGuide'
| 'resetInjiProps'
| 'showInjiTourGuide'
| 'storingDefaults';
Expand Down
30 changes: 26 additions & 4 deletions machines/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import {createModel} from 'xstate/lib/model';
import {generateSecureRandom} from 'react-native-securerandom';
import {log} from 'xstate/lib/actions';
import {MY_VCS_STORE_KEY} from '../shared/constants';
import {MY_VCS_STORE_KEY, SETTINGS_STORE_KEY} from '../shared/constants';
import SecureKeystore from 'react-native-secure-keystore';
import {
AUTH_TIMEOUT,
Expand Down Expand Up @@ -485,8 +485,18 @@ export async function setItem(
encryptionKey: string,
) {
try {
const data = JSON.stringify(value);
const encryptedData = await encryptJson(encryptionKey, data);
let encryptedData;
if (key === SETTINGS_STORE_KEY) {
const appId = value.appId;
delete value.appId;
const settings = {
encryptedData: await encryptJson(encryptionKey, JSON.stringify(value)),
appId,
};
encryptedData = JSON.stringify(settings);
} else {
encryptedData = await encryptJson(encryptionKey, JSON.stringify(value));
}
await Storage.setItem(key, encryptedData, encryptionKey);
} catch (e) {
console.error('error setItem:', e);
Expand All @@ -502,7 +512,19 @@ export async function getItem(
try {
const data = await Storage.getItem(key, encryptionKey);
if (data != null) {
const decryptedData = await decryptJson(encryptionKey, data);
let decryptedData;
if (key === SETTINGS_STORE_KEY) {
let parsedData = JSON.parse(data);
if (parsedData.encryptedData) {
decryptedData = await decryptJson(
encryptionKey,
parsedData.encryptedData,
);
parsedData.encryptedData = JSON.parse(decryptedData);
}
return parsedData;
}
decryptedData = await decryptJson(encryptionKey, data);
return JSON.parse(decryptedData);
}
if (data === null && VCMetadata.isVCKey(key)) {
Expand Down
16 changes: 15 additions & 1 deletion screens/Home/MyVcsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,21 @@ export const MyVcsTab: React.FC<HomeScreenTabProps> = props => {
),
);
}
}, [controller.areAllVcsLoaded, controller.inProgressVcDownloads]);

if (controller.isTampered) {
sendErrorEvent(
getErrorEventData(
TelemetryConstants.FlowType.appLogin,
TelemetryConstants.ErrorId.vcsAreTampered,
TelemetryConstants.ErrorMessage.vcsAreTampered,
),
);
}
}, [
controller.areAllVcsLoaded,
controller.inProgressVcDownloads,
controller.isTampered,
]);

let failedVCsList = [];
controller.downloadFailedVcs.forEach(vc => {
Expand Down
12 changes: 11 additions & 1 deletion shared/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ import {
} from './cryptoutil/cryptoUtil';
import {VCMetadata} from './VCMetadata';
import {ENOENT, getItem} from '../machines/store';
import {isAndroid, MY_VCS_STORE_KEY, RECEIVED_VCS_STORE_KEY} from './constants';
import {
isAndroid,
MY_VCS_STORE_KEY,
RECEIVED_VCS_STORE_KEY,
SETTINGS_STORE_KEY,
} from './constants';
import FileStorage, {getFilePath, vcDirectoryPath} from './fileStorage';
import {__AppId} from './GlobalVariables';

export const MMKV = new MMKVLoader().initialize();

Expand Down Expand Up @@ -184,7 +190,11 @@ class Storage {
try {
(await FileStorage.exists(`${vcDirectoryPath}`)) &&
(await FileStorage.removeItem(`${vcDirectoryPath}`));
const settings = await MMKV.getItem(SETTINGS_STORE_KEY);
const appId = JSON.parse(settings).appId;
__AppId.setValue(appId);
MMKV.clearStore();
await MMKV.setItem(SETTINGS_STORE_KEY, JSON.stringify({appId: appId}));
} catch (e) {
console.log('Error Occurred while Clearing Storage.', e);
}
Expand Down
6 changes: 6 additions & 0 deletions shared/telemetry/TelemetryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ export const TelemetryConstants = {
hardwareKeyStore:
'Some security features will be unavailable as hardware key store is not available',
activationCancelled: 'Activation Cancelled',
appWasReset:
'Due to the fingerprint / facial recognition update, app security was impacted, and downloaded cards were removed. Please download again',
vcsAreTampered:
'Tampered cards detected and removed for security reasons. Please download again',
}),

ErrorId: Object.freeze({
Expand All @@ -217,6 +221,8 @@ export const TelemetryConstants = {
userCancel: 'USER_CANCEL',
resend: 'RESEND',
activationFailed: 'ACTIVATION_FAILED',
appWasReset: 'APP_WAS_RESET',
vcsAreTampered: 'VCS_ARE_TAMPERED',
}),

Screens: Object.freeze({
Expand Down

0 comments on commit 844c227

Please sign in to comment.