From fa2789237b33971b4c891d514ec6cfba8e12e302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Cort=C3=A9s=20Ross?= Date: Fri, 25 Feb 2022 11:55:52 +0100 Subject: [PATCH] LIVE-1469 Handle onboarded devices in device actions (#1738) --- src/errors.ts | 1 + src/hw/connectManager.ts | 6 ++++++ src/hw/getDeviceInfo.ts | 19 ++++++++++++++++++- src/types/manager.ts | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/errors.ts b/src/errors.ts index d7d6f81708..b51e92f367 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -23,6 +23,7 @@ export const LowerThanMinimumRelayFee = createCustomErrorClass( export const TransactionRefusedOnDevice = createCustomErrorClass( "TransactionRefusedOnDevice" ); +export const DeviceNotOnboarded = createCustomErrorClass("DeviceNotOnboarded"); export const InvalidAddressBecauseAlreadyDelegated = createCustomErrorClass( "InvalidAddressBecauseAlreadyDelegated" ); diff --git a/src/hw/connectManager.ts b/src/hw/connectManager.ts index 3238af2f52..57f2f75bc9 100644 --- a/src/hw/connectManager.ts +++ b/src/hw/connectManager.ts @@ -12,6 +12,7 @@ import getDeviceInfo from "./getDeviceInfo"; import getAppAndVersion from "./getAppAndVersion"; import appSupportsQuitApp from "../appSupportsQuitApp"; import { isDashboardName } from "./isDashboardName"; +import { DeviceNotOnboarded } from "../errors"; import type { AppAndVersion } from "./connectApp"; import quitApp from "./quitApp"; export type Input = { @@ -77,6 +78,11 @@ const cmd = ({ concatMap((deviceInfo) => { timeoutSub.unsubscribe(); + // FIXME Until we have proper flagging of the onboarded status. + if (!deviceInfo.onboarded) { + throw new DeviceNotOnboarded(); + } + if (deviceInfo.isBootloader) { return of({ type: "bootloader", diff --git a/src/hw/getDeviceInfo.ts b/src/hw/getDeviceInfo.ts index 112d0f4288..bec08e2371 100644 --- a/src/hw/getDeviceInfo.ts +++ b/src/hw/getDeviceInfo.ts @@ -10,6 +10,7 @@ import getAppAndVersion from "./getAppAndVersion"; import type { DeviceInfo } from "../types/manager"; import { PROVIDERS } from "../manager/provider"; import { isDashboardName } from "./isDashboardName"; +import { DeviceNotOnboarded } from "../errors"; const ManagerAllowedFlag = 0x08; const PinValidatedFlag = 0x80; export default async function getDeviceInfo( @@ -37,7 +38,16 @@ export default async function getDeviceInfo( throw new DeviceOnDashboardExpected(); } - const res = await getVersion(transport); + const res = await getVersion(transport).catch((e) => { + if (e instanceof TransportStatusError) { + // @ts-expect-error typescript not checking agains the instanceof + if (e.statusCode === 0x6d06) { + throw new DeviceNotOnboarded(); + } + } + throw e; + }); + const { isBootloader, rawVersion, @@ -57,6 +67,12 @@ export default async function getDeviceInfo( const flag = flags.length > 0 ? flags[0] : 0; const managerAllowed = !!(flag & ManagerAllowedFlag); const pinValidated = !!(flag & PinValidatedFlag); + + // FIXME Until we have proper flagging of the onboarded status. + let onboarded = true; + if (flags.length === 4) { + onboarded = !!(flags[0] & 0x04); + } log( "hw", "deviceInfo: se@" + @@ -79,5 +95,6 @@ export default async function getDeviceInfo( isBootloader, managerAllowed, pinValidated, + onboarded, }; } diff --git a/src/types/manager.ts b/src/types/manager.ts index a206e72aa0..804ed19c8e 100644 --- a/src/types/manager.ts +++ b/src/types/manager.ts @@ -30,6 +30,7 @@ export type DeviceInfo = { mcuBlVersion?: string; mcuTargetId?: number; seTargetId?: number; + onboarded?: boolean; }; export type DeviceModelInfo = { modelId: DeviceModelId;