fix(@desktop/onboarding): reading keycards regardless of the way of providing keycards

This commit is contained in:
Sale Djenic 2023-09-24 17:50:12 +02:00 committed by saledjenic
parent d107a9f90b
commit 2af8e49ee3
5 changed files with 34 additions and 28 deletions

View File

@ -32,7 +32,7 @@ method executeCancelCommand*(self: InsertKeycardState, controller: Controller) =
method resolveKeycardNextState*(self: InsertKeycardState, keycardFlowType: string, keycardEvent: KeycardEvent,
controller: Controller): State =
let state = ensureReaderAndCardPresenceAndResolveNextState(self, keycardFlowType, keycardEvent, controller)
let state = readingKeycard(self, keycardFlowType, keycardEvent, controller)
if not state.isNil:
return state
if keycardFlowType == ResponseTypeValueInsertCard and

View File

@ -32,4 +32,4 @@ method executeCancelCommand*(self: PluginReaderState, controller: Controller) =
method resolveKeycardNextState*(self: PluginReaderState, keycardFlowType: string, keycardEvent: KeycardEvent,
controller: Controller): State =
return ensureReaderAndCardPresenceAndResolveNextState(self, keycardFlowType, keycardEvent, controller)
return readingKeycard(self, keycardFlowType, keycardEvent, controller)

View File

@ -23,29 +23,4 @@ method getNextSecondaryState*(self: ReadingKeycardState, controller: Controller)
method resolveKeycardNextState*(self: ReadingKeycardState, keycardFlowType: string, keycardEvent: KeycardEvent,
controller: Controller): State =
if self.flowType == FlowType.UnlockKeycard or
self.flowType == FlowType.RenameKeycard or
self.flowType == FlowType.ChangeKeycardPin or
self.flowType == FlowType.ChangeKeycardPuk or
self.flowType == FlowType.ChangePairingCode or
self.flowType == FlowType.MigrateFromAppToKeycard or
(self.flowType == FlowType.CreateCopyOfAKeycard and
not isPredefinedKeycardDataFlagSet(controller.getKeycardData(), PredefinedKeycardData.CopyFromAKeycardPartDone)) or
self.flowType == FlowType.FactoryReset and
not controller.getKeyPairForProcessing().isNil:
# this part is only for the flows which are card specific (the card we're running a flow for is known in advance)
let ensureKeycardPresenceState = ensureReaderAndCardPresence(self, keycardFlowType, keycardEvent, controller)
if ensureKeycardPresenceState.isNil: # means the keycard is inserted
let nextState = ensureReaderAndCardPresenceAndResolveNextState(self, keycardFlowType, keycardEvent, controller)
if not nextState.isNil and
(nextState.stateType == StateType.KeycardEmpty or
nextState.stateType == StateType.NotKeycard or
nextState.stateType == StateType.KeycardEmptyMetadata):
return nextState
let keyUid = controller.getKeyPairForProcessing().getKeyUid()
if keyUid.len > 0:
if keyUid != keycardEvent.keyUid:
return createState(StateType.WrongKeycard, self.flowType, nil)
controller.setKeycardUid(keycardEvent.instanceUID)
# this is used in case a keycard is inserted and we jump to the first meaningful screen
return ensureReaderAndCardPresenceAndResolveNextState(self, keycardFlowType, keycardEvent, controller)
return readingKeycard(self, keycardFlowType, keycardEvent, controller)

View File

@ -39,6 +39,7 @@ proc findBackStateWithTargetedStateType*(currentState: State, targetedStateType:
# Resolve state section
proc ensureReaderAndCardPresence*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State
proc ensureReaderAndCardPresenceAndResolveNextState*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State
proc readingKeycard*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State
include biometrics_state
include biometrics_password_failed_state

View File

@ -576,3 +576,33 @@ proc ensureReaderAndCardPresenceAndResolveNextState*(state: State, keycardFlowTy
if keycardEvent.pinRetries == 0 and keycardEvent.pukRetries > 0:
controller.setKeycardData(updatePredefinedKeycardData(controller.getKeycardData(), PredefinedKeycardData.UseGeneralMessageForLockedState, add = true))
return createState(StateType.MaxPinRetriesReached, state.flowType, nil)
proc readingKeycard*(state: State, keycardFlowType: string, keycardEvent: KeycardEvent, controller: Controller): State =
controller.setKeycardUid("")
if state.flowType == FlowType.UnlockKeycard or
state.flowType == FlowType.RenameKeycard or
state.flowType == FlowType.ChangeKeycardPin or
state.flowType == FlowType.ChangeKeycardPuk or
state.flowType == FlowType.ChangePairingCode or
state.flowType == FlowType.MigrateFromAppToKeycard or
(state.flowType == FlowType.CreateCopyOfAKeycard and
not isPredefinedKeycardDataFlagSet(controller.getKeycardData(), PredefinedKeycardData.CopyFromAKeycardPartDone)) or
state.flowType == FlowType.FactoryReset and
not controller.getKeyPairForProcessing().isNil:
# this part is only for the flows which are card specific (the card we're running a flow for is known in advance)
let ensureKeycardPresenceState = ensureReaderAndCardPresence(state, keycardFlowType, keycardEvent, controller)
if ensureKeycardPresenceState.isNil: # means the keycard is inserted
let nextState = ensureReaderAndCardPresenceAndResolveNextState(state, keycardFlowType, keycardEvent, controller)
if not nextState.isNil and
(nextState.stateType == StateType.KeycardEmpty or
nextState.stateType == StateType.NotKeycard or
nextState.stateType == StateType.KeycardEmptyMetadata):
return nextState
let keyUid = controller.getKeyPairForProcessing().getKeyUid()
if keyUid.len > 0 and keycardEvent.keyUid.len > 0:
if keyUid != keycardEvent.keyUid:
return createState(StateType.WrongKeycard, state.flowType, nil)
controller.setKeycardUid(keycardEvent.instanceUID)
# this is used in case a keycard is inserted and we jump to the first meaningful screen
return ensureReaderAndCardPresenceAndResolveNextState(state, keycardFlowType, keycardEvent, controller)