Skip to content
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

Log firmware revision check to Sentry on mobile #16386

Merged
merged 2 commits into from
Jan 17, 2025
Merged
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
7 changes: 6 additions & 1 deletion suite-native/app/src/hooks/useGlobalHooks.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { useDetectDeviceError, useHandleDeviceConnection } from '@suite-native/device';
import {
useDetectDeviceError,
useHandleDeviceConnection,
useReportDeviceCompromised,
} from '@suite-native/device';
import { useConnectPopupNavigation } from '@suite-native/module-connect-popup';

import { useCoinEnablingInitialCheck } from './useCoinEnablingInitialCheck';
Expand All @@ -14,4 +18,5 @@ export const useGlobalHooks = () => {

useHandleDeviceConnection();
useDetectDeviceError();
useReportDeviceCompromised();
};
2 changes: 2 additions & 0 deletions suite-native/device/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@reduxjs/toolkit": "1.9.5",
"@sentry/react-native": "6.5.0",
"@suite-common/redux-utils": "workspace:*",
"@suite-common/suite-utils": "workspace:*",
"@suite-common/wallet-core": "workspace:*",
"@suite-common/wallet-utils": "workspace:*",
"@suite-native/alerts": "workspace:*",
Expand All @@ -29,6 +30,7 @@
"@suite-native/navigation": "workspace:*",
"@suite-native/settings": "workspace:*",
"@trezor/connect": "workspace:*",
"@trezor/device-utils": "workspace:*",
"@trezor/styles": "workspace:*",
"lottie-react-native": "^7.1.0",
"react": "18.2.0",
Expand Down
38 changes: 38 additions & 0 deletions suite-native/device/src/hooks/useReportDeviceCompromised.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useSelector } from 'react-redux';
import { useEffect, useMemo } from 'react';

import * as Sentry from '@sentry/react-native';

import { getFirmwareVersion } from '@trezor/device-utils';
import { selectSelectedDevice } from '@suite-common/wallet-core';

import { selectFirmwareRevisionCheckError } from '../selectors';

const reportCheckFail = (checkType: 'Firmware revision', contextData: any) => {
Sentry.captureException(`${checkType} check failed! ${JSON.stringify(contextData)}`);
};

const useCommonData = () => {
const device = useSelector(selectSelectedDevice);
const model = device?.features?.internal_model;
const revision = device?.features?.revision;
const version = getFirmwareVersion(device);
const vendor = device?.features?.fw_vendor;

return useMemo(
() => ({ model, revision, version, vendor }),
[model, revision, version, vendor],
);
};

export const useReportDeviceCompromised = () => {
const commonData = useCommonData();

const revisionCheckError = useSelector(selectFirmwareRevisionCheckError);

useEffect(() => {
if (revisionCheckError !== null) {
reportCheckFail('Firmware revision', { ...commonData, revisionCheckError });
}
}, [commonData, revisionCheckError]);
};
1 change: 1 addition & 0 deletions suite-native/device/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './middlewares/buttonRequestMiddleware';
export * from './hooks/useHandleDeviceConnection';
export * from './hooks/useDetectDeviceError';
export * from './hooks/useReportDeviceConnectToAnalytics';
export * from './hooks/useReportDeviceCompromised';
export * from './components/ConnectDeviceAnimation';
export * from './components/ConfirmOnTrezorImage';
export * from './components/ConnectorImage';
Expand Down
15 changes: 15 additions & 0 deletions suite-native/device/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
selectIsDiscoveredDeviceAccountless,
selectIsUnacquiredDevice,
} from '@suite-common/wallet-core';
import { isDeviceAcquired } from '@suite-common/suite-utils';
import { getTotalFiatBalance } from '@suite-common/wallet-utils';
import { selectFiatCurrencyCode, SettingsSliceRootState } from '@suite-native/settings';

Expand Down Expand Up @@ -106,3 +107,17 @@ export const selectHasNoDeviceWithEmptyPassphrase = createMemoizedSelector(
[selectDeviceInstances],
deviceInstances => A.isEmpty(deviceInstances.filter(d => d.useEmptyPassphrase)),
);

/**
* Get firmware revision check error, or null if check was successful / skipped.
*/
export const selectFirmwareRevisionCheckError = (state: DeviceRootState) => {
const device = selectSelectedDevice(state);
if (!isDeviceAcquired(device) || !device.authenticityChecks) return null;
const checkResult = device.authenticityChecks.firmwareRevision;

// null means not performed, then don't consider it failed
if (!checkResult || checkResult.success) return null;

return checkResult.error;
};
4 changes: 4 additions & 0 deletions suite-native/device/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
{
"path": "../../suite-common/redux-utils"
},
{
"path": "../../suite-common/suite-utils"
},
{
"path": "../../suite-common/wallet-core"
},
Expand All @@ -23,6 +26,7 @@
{ "path": "../navigation" },
{ "path": "../settings" },
{ "path": "../../packages/connect" },
{ "path": "../../packages/device-utils" },
{ "path": "../../packages/styles" }
],
"include": [".", "**/*.json"]
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10274,6 +10274,7 @@ __metadata:
"@reduxjs/toolkit": "npm:1.9.5"
"@sentry/react-native": "npm:6.5.0"
"@suite-common/redux-utils": "workspace:*"
"@suite-common/suite-utils": "workspace:*"
"@suite-common/wallet-core": "workspace:*"
"@suite-common/wallet-utils": "workspace:*"
"@suite-native/alerts": "workspace:*"
Expand All @@ -10288,6 +10289,7 @@ __metadata:
"@suite-native/navigation": "workspace:*"
"@suite-native/settings": "workspace:*"
"@trezor/connect": "workspace:*"
"@trezor/device-utils": "workspace:*"
"@trezor/styles": "workspace:*"
lottie-react-native: "npm:^7.1.0"
react: "npm:18.2.0"
Expand Down
Loading