diff --git a/src/app/keycard/core.nim b/src/app/keycard/core.nim index af02b1c4ab..ffb92058c1 100644 --- a/src/app/keycard/core.nim +++ b/src/app/keycard/core.nim @@ -1,5 +1,6 @@ import NimQml, chronicles, std/wrapnils import status/[signals, status, keycard] +import types/keycard as keycardtypes import view, pairing logScope: @@ -29,11 +30,25 @@ proc attemptOpenSecureChannel(self: KeycardController) : bool = if pairing == "": return false - # actually open secure channel + discard """let err = self.status.keycard.openSecureChannel(pairing) + + if err == Ok: + return true + + self.view.pairings.removePairing(self.view.appInfo.instanceUID) + + """" return false proc getCardState(self: KeycardController) = - let appInfo = self.status.keycard.select() + var appInfo: KeycardApplicationInfo + + try: + appInfo = self.status.keycard.select() + except KeycardSelectException as ex: + self.view.cardUnhandledError(ex.error) + return + self.view.appInfo = appInfo if not appInfo.installed: @@ -43,7 +58,16 @@ proc getCardState(self: KeycardController) = self.view.cardState = PreInit self.view.cardPreInit() elif self.attemptOpenSecureChannel(): - # here we will also be able to check if the card is Frozen/Blocked + discard """ + self.view.appStatus = self.status.keycard.getStatusApplication() + if self.view.appStatus.pukRetryCounter == 0: + self.view.cardState = Blocked + self.view.cardBlocked() + elif self.view.appStatus.pinRetryCounter == 0: + self.view.cardState = Frozen + self.view.cardFrozen() + else: + """ self.view.cardState = Paired self.view.cardPaired() elif appInfo.availableSlots > 0: diff --git a/src/app/keycard/view.nim b/src/app/keycard/view.nim index 38df5aee56..6ed805eab3 100644 --- a/src/app/keycard/view.nim +++ b/src/app/keycard/view.nim @@ -1,6 +1,6 @@ import NimQml, chronicles import status/[status, keycard] -import status/types/keycard as keycardtypes +import types/keycard as keycardtypes import pairing logScope: @@ -47,18 +47,47 @@ QtObject: proc cardFrozen*(self: KeycardView) {.signal.} proc cardBlocked*(self: KeycardView) {.signal.} proc cardAuthenticated*(self: KeycardView) {.signal.} + proc cardUnhandledError*(self: KeycardView, error: string) {.signal.} proc startConnection*(self: KeycardView) {.slot.} = - discard self.status.keycard.start() + try: + self.status.keycard.start() + except KeycardStartException as ex: + self.cardUnhandledError(ex.error) + proc stopConnection*(self: KeycardView) {.slot.} = self.cardState = Disconnected - discard self.status.keycard.stop() + try: + self.status.keycard.stop() + except KeycardStopException as ex: + self.cardUnhandledError(ex.error) proc pair*(self: KeycardView, password: string) {.slot.} = discard """ - on succesful pairing, save and change card state - otherwise throw error + let pairing = self.status.keycard.pair(password) - self.status.keycard.pair(password) + if pairing == "": + error + + self.pairings.addPairing(self.appInfo.instanceUID, pairing) + self.cardState = Paired + self.cardPaired() + """ + + proc authenticate*(self: KeycardView, pin: string) {.slot.} = + discard """ + let resp = self.status.keycard.verifyPIN(pin) + if resp is error: + handle error + + self.cardAuthenticated() + """ + + proc init*(self: KeycardView, pin: string) {.slot.} = + discard """ + """ + + proc recoverAccount*(self: KeycardView) {.slot.} = + discard """ """ \ No newline at end of file diff --git a/ui/onboarding/Keycard.qml b/ui/onboarding/Keycard.qml index e8b90fdabc..b69dd85059 100644 --- a/ui/onboarding/Keycard.qml +++ b/ui/onboarding/Keycard.qml @@ -2,10 +2,16 @@ import QtQuick 2.13 import "./Keycard" import "../shared/keycard" -// this will be the entry point. for now it opens all keycard-related dialogs in sequence for test Item { + enum OnboardingFlow { + Recover, + Generate, + ImportMnemonic + } + property var onClosed: function () {} property bool connected: false + property int flow: OnboardingFlow.Recover id: keycardView anchors.fill: parent @@ -17,7 +23,9 @@ Item { CreatePINModal { id: createPinModal onClosed: function () { - keycardView.onClosed() + if (!createPinModal.submitted) { + keycardView.onClosed() + } } } @@ -33,7 +41,9 @@ Item { PINModal { id: pinModal onClosed: function () { - keycardView.onClosed() + if (!pinModal.submitted) { + keycardView.onClosed() + } } } @@ -54,13 +64,28 @@ Item { } onCardPaired: { + pinModal.open() + } + onCardAuthenticated: { + switch (flow) { + case OnboardingFlow.Recover: { + keycardModel.recoverAccount(); + break; + } + case OnboardingFlow.Generate: { + break; + } + case OnboardingFlow.ImportMnemonic: { + break; + } + } } //TODO: support the states below onCardPreInit: { - keycardView.onClosed() + createPinModal.open() } onCardFrozen: { @@ -76,14 +101,11 @@ Item { // later add factory reset option for the NoFreeSlots case onCardNoFreeSlots: { - //status-lib currently always returns availableSlots = 0 so we end up here - //keycardView.onClosed() - pairingModal.open() + keycardView.onClosed() } onCardNotKeycard: { keycardView.onClosed() - } } diff --git a/ui/onboarding/Keycard/CreatePINModal.qml b/ui/onboarding/Keycard/CreatePINModal.qml index 993c9a22ed..64c4077565 100644 --- a/ui/onboarding/Keycard/CreatePINModal.qml +++ b/ui/onboarding/Keycard/CreatePINModal.qml @@ -11,12 +11,14 @@ ModalPopup { property bool repeatPINFieldValid: false property string pinValidationError: "" property string repeatPINValidationError: "" + property bool submitted: false id: popup title: qsTr("Create PIN") height: 500 onOpened: { + submitted = false firstPINField.text = ""; firstPINField.forceActiveFocus(Qt.MouseFocusReason) } @@ -102,6 +104,9 @@ ModalPopup { enabled: firstPINFieldValid && repeatPINFieldValid onClicked: { + submitted = true + keycardModel.init(firstPINField.text) + popup.close() } } } diff --git a/ui/shared/keycard/PINModal.qml b/ui/shared/keycard/PINModal.qml index 3d80eb8fef..1ce9c11cbf 100644 --- a/ui/shared/keycard/PINModal.qml +++ b/ui/shared/keycard/PINModal.qml @@ -7,12 +7,14 @@ import "../../shared" ModalPopup { property bool pinFieldValid: false + property bool submitted: false id: popup title: qsTr("Authenticate PIN") height: 400 onOpened: { + submitted = false pinField.text = ""; pinField.forceActiveFocus(Qt.MouseFocusReason) } @@ -58,7 +60,9 @@ ModalPopup { enabled: pinFieldValid onClicked: { - + submitted = true + keycardModel.authenticate(pinField.text) + popup.close() } } } diff --git a/ui/shared/keycard/PairingModal.qml b/ui/shared/keycard/PairingModal.qml index ddfacb74e6..aa877569ad 100644 --- a/ui/shared/keycard/PairingModal.qml +++ b/ui/shared/keycard/PairingModal.qml @@ -14,6 +14,7 @@ ModalPopup { height: 400 onOpened: { + submitted = false pairingPasswordField.text = ""; pairingPasswordField.forceActiveFocus(Qt.MouseFocusReason) }