Skip to content

Commit

Permalink
feat(suite, suite-common): report firmware version check fail to Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
komret committed Feb 4, 2025
1 parent 4e2db5f commit 69b9677
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 13 deletions.
12 changes: 4 additions & 8 deletions packages/suite/src/actions/settings/deviceSettingsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,11 @@ export const resetDevice =
if (!result.success) {
dispatch(notificationsActions.addToast({ type: 'error', error: result.payload.error }));
if (result.payload.code === 'Failure_EntropyCheck') {
const model = device?.features?.internal_model;
const revision = device?.features?.revision;
const version = getFirmwareVersion(device);
const vendor = device?.features?.fw_vendor;
reportCheckFail('Entropy', {
model,
revision,
version,
vendor,
model: device?.features?.internal_model,
revision: device?.features?.revision,
version: getFirmwareVersion(device),
vendor: device?.features?.fw_vendor,
error: result.payload.error,
});
const hardErrors: string[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { selectFirmwareRevisionCheckError } from 'src/reducers/suite/suiteReduce
import { captureSentryMessage, withSentryScope } from 'src/utils/suite/sentry';

export const reportCheckFail = (
checkType: 'Firmware revision' | 'Firmware hash' | 'Entropy',
checkType: 'Entropy' | 'Firmware hash' | 'Firmware revision' | 'Firmware version',
contextData: Record<string, any>,
errorPayload?: unknown,
) => {
Expand Down
12 changes: 11 additions & 1 deletion packages/suite/src/middlewares/suite/eventsMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { DEVICE } from '@trezor/connect';

import { SUITE } from 'src/actions/suite/constants';
import { reportCheckFail } from 'src/components/suite/SecurityCheck/useReportDeviceCompromised';
import { Action, AppState, Dispatch } from 'src/types/suite';

/*
Expand Down Expand Up @@ -68,7 +69,16 @@ const eventsMiddleware =
}

if (action.type === DEVICE.FIRMWARE_VERSION_CHANGED) {
// TODO: show warning? move this to different middleware?
// TODO: Add UI.
const { device, oldVersion, newVersion } = action.payload;
reportCheckFail('Firmware version', {
model: device?.features?.internal_model,
revision: device?.features?.revision,
oldVersion,
newVersion,
vendor: device?.features?.fw_vendor,
error: 'Firmware version changed unexpectedly.',
});
}

if (deviceActions.selectDevice.match(action)) {
Expand Down
2 changes: 2 additions & 0 deletions packages/suite/src/support/extraDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
findLabelsToBeMovedOrDeleted,
moveLabelsForRbfAction,
} from 'src/actions/wallet/moveLabelsForRbfActions';
import { reportCheckFail } from 'src/components/suite/SecurityCheck/useReportDeviceCompromised';
import { selectIsWindowVisible } from 'src/reducers/suite/windowReducer';
import { fixLoadedCoinjoinAccount } from 'src/utils/wallet/coinjoinUtils';

Expand Down Expand Up @@ -216,5 +217,6 @@ export const extraDependencies: ExtraDependencies = {
utils: {
saveAs: (data, fileName) => saveAs(data, fileName),
connectInitSettings,
reportCheckFail,
},
};
26 changes: 23 additions & 3 deletions suite-common/firmware/src/firmwareThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const firmwareUpdate = createThunk<

const {
selectors: { selectLanguage },
utils: { reportCheckFail },
} = extra;

const device = selectSelectedDevice(getState());
Expand Down Expand Up @@ -154,7 +155,14 @@ export const firmwareUpdate = createThunk<
connectResponse: firmwareUpdateResponse,
});
} else {
const { check, versionCheck } = firmwareUpdateResponse.payload;
const {
check,
versionCheck,
bootloaderVersion,
binaryVersion,
installedVersion,
releaseVersion,
} = firmwareUpdateResponse.payload;
if (check === 'mismatch') {
// hash check was performed, and it does not match, so consider firmware counterfeit
dispatch(handleFwHashMismatch(device));
Expand All @@ -165,12 +173,24 @@ export const firmwareUpdate = createThunk<
errorMessage: firmwareUpdateResponse.payload.checkError,
}),
);
} else if (!binary && !versionCheck) {
// TODO: log to sentry
} else {
dispatch(handleFwHashValid(device));
}

// TODO: Add to the if-else block above and add handle in UI.
if (!binary && !versionCheck) {
reportCheckFail('Firmware version', {
model: device.features?.internal_model,
revision: device.features?.revision,
vendor: device.features?.fw_vendor,
bootloaderVersion,
binaryVersion,
installedVersion,
releaseVersion,
error: 'Unexpected firmware version change during firmware update.',
});
}

return fulfillWithValue({
device,
...targetProperties,
Expand Down
5 changes: 5 additions & 0 deletions suite-common/redux-utils/src/extraDependenciesType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ export type ExtraDependencies = {
utils: {
saveAs: (data: Blob, fileName: string) => void;
connectInitSettings: ConnectInitSettings;
reportCheckFail: (
checkType: 'Entropy' | 'Firmware hash' | 'Firmware revision' | 'Firmware version',
contextData: Record<string, any>,
errorPayload?: unknown,
) => void;
};
};

Expand Down
2 changes: 2 additions & 0 deletions suite-common/test-utils/src/extraDependenciesMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,7 @@ export const extraDependenciesMock: ExtraDependencies = {
appUrl: '@suite-native/app',
},
},
reportCheckFail: (checkType, _contextData) =>
console.warn(`Reporting ${checkType} check fail. Implementation on phone not ready.`),
},
};

0 comments on commit 69b9677

Please sign in to comment.