make pairing work
This commit is contained in:
parent
101e77cc14
commit
3016fd4ec1
|
@ -24,60 +24,7 @@ proc delete*(self: KeycardController) =
|
||||||
proc reset*(self: KeycardController) =
|
proc reset*(self: KeycardController) =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc attemptOpenSecureChannel(self: KeycardController) : bool =
|
|
||||||
let pairing = self.view.pairings.getPairing(self.view.appInfo.instanceUID)
|
|
||||||
|
|
||||||
if pairing == "":
|
|
||||||
return false
|
|
||||||
|
|
||||||
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) =
|
|
||||||
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:
|
|
||||||
self.view.cardState = NotKeycard
|
|
||||||
self.view.cardNotKeycard()
|
|
||||||
elif not appInfo.initialized:
|
|
||||||
self.view.cardState = PreInit
|
|
||||||
self.view.cardPreInit()
|
|
||||||
elif self.attemptOpenSecureChannel():
|
|
||||||
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:
|
|
||||||
self.view.cardState = Unpaired
|
|
||||||
self.view.cardUnpaired()
|
|
||||||
else:
|
|
||||||
self.view.cardState = NoFreeSlots
|
|
||||||
self.view.cardNoFreeSlots()
|
|
||||||
|
|
||||||
proc init*(self: KeycardController) =
|
proc init*(self: KeycardController) =
|
||||||
self.status.events.on(SignalType.KeycardConnected.event) do(e:Args):
|
self.status.events.on(SignalType.KeycardConnected.event) do(e:Args):
|
||||||
self.getCardState()
|
self.view.getCardState()
|
||||||
self.view.cardConnected()
|
self.view.cardConnected()
|
|
@ -1,4 +1,5 @@
|
||||||
import json, os, std/wrapnils
|
import json, os
|
||||||
|
import types/keycard
|
||||||
|
|
||||||
import ../../constants
|
import ../../constants
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ proc newPairingController*(): KeycardPairingController =
|
||||||
proc save(self: KeycardPairingController) =
|
proc save(self: KeycardPairingController) =
|
||||||
writeFile(PAIRINGSTORE, $self.store)
|
writeFile(PAIRINGSTORE, $self.store)
|
||||||
|
|
||||||
proc addPairing*(self: KeycardPairingController, instanceUID: string, pairing: string) =
|
proc addPairing*(self: KeycardPairingController, instanceUID: string, pairing: KeycardPairingInfo) =
|
||||||
self.store[instanceUID] = %* pairing
|
self.store[instanceUID] = %* pairing
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
@ -25,6 +26,7 @@ proc removePairing*(self: KeycardPairingController, instanceUID: string) =
|
||||||
self.store.delete(instanceUID)
|
self.store.delete(instanceUID)
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
proc getPairing*(self: KeycardPairingController, instanceUID: string): string =
|
proc getPairing*(self: KeycardPairingController, instanceUID: string): KeycardPairingInfo =
|
||||||
let node = self.store{instanceUID}
|
let node = self.store{instanceUID}
|
||||||
return ?.node.getStr()
|
if node != nil:
|
||||||
|
result = to(node, KeycardPairingInfo)
|
||||||
|
|
|
@ -55,7 +55,6 @@ QtObject:
|
||||||
except KeycardStartException as ex:
|
except KeycardStartException as ex:
|
||||||
self.cardUnhandledError(ex.error)
|
self.cardUnhandledError(ex.error)
|
||||||
|
|
||||||
|
|
||||||
proc stopConnection*(self: KeycardView) {.slot.} =
|
proc stopConnection*(self: KeycardView) {.slot.} =
|
||||||
self.cardState = Disconnected
|
self.cardState = Disconnected
|
||||||
try:
|
try:
|
||||||
|
@ -63,17 +62,42 @@ QtObject:
|
||||||
except KeycardStopException as ex:
|
except KeycardStopException as ex:
|
||||||
self.cardUnhandledError(ex.error)
|
self.cardUnhandledError(ex.error)
|
||||||
|
|
||||||
proc pair*(self: KeycardView, password: string) {.slot.} =
|
proc attemptOpenSecureChannel(self: KeycardView): bool =
|
||||||
|
let pairing = self.pairings.getPairing(self.appInfo.instanceUID)
|
||||||
|
|
||||||
|
if pairing == nil:
|
||||||
|
return false
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.status.keycard.openSecureChannel(int(pairing.index), pairing.key)
|
||||||
|
except KeycardOpenSecureChannelException:
|
||||||
|
self.pairings.removePairing(self.appInfo.instanceUID)
|
||||||
|
return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
||||||
|
proc onSecureChannelOpened(self: KeycardView) =
|
||||||
discard """
|
discard """
|
||||||
let pairing = self.status.keycard.pair(password)
|
self.appStatus = self.status.keycard.getStatusApplication()
|
||||||
|
if self.appStatus.pukRetryCounter == 0:
|
||||||
if pairing == "":
|
self.cardState = Blocked
|
||||||
error
|
self.cardBlocked()
|
||||||
|
elif self.appStatus.pinRetryCounter == 0:
|
||||||
self.pairings.addPairing(self.appInfo.instanceUID, pairing)
|
self.cardState = Frozen
|
||||||
|
self.cardFrozen()
|
||||||
|
else:
|
||||||
|
"""
|
||||||
self.cardState = Paired
|
self.cardState = Paired
|
||||||
self.cardPaired()
|
self.cardPaired()
|
||||||
"""
|
|
||||||
|
proc pair*(self: KeycardView, password: string) {.slot.} =
|
||||||
|
try:
|
||||||
|
let pairing = self.status.keycard.pair(password)
|
||||||
|
self.pairings.addPairing(self.appInfo.instanceUID, pairing)
|
||||||
|
if self.attemptOpenSecureChannel():
|
||||||
|
self.onSecureChannelOpened()
|
||||||
|
except KeycardPairException:
|
||||||
|
discard #display wrong pairing password message
|
||||||
|
|
||||||
proc authenticate*(self: KeycardView, pin: string) {.slot.} =
|
proc authenticate*(self: KeycardView, pin: string) {.slot.} =
|
||||||
discard """
|
discard """
|
||||||
|
@ -91,3 +115,29 @@ QtObject:
|
||||||
proc recoverAccount*(self: KeycardView) {.slot.} =
|
proc recoverAccount*(self: KeycardView) {.slot.} =
|
||||||
discard """
|
discard """
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
proc getCardState*(self: KeycardView) =
|
||||||
|
var appInfo: KeycardApplicationInfo
|
||||||
|
|
||||||
|
try:
|
||||||
|
appInfo = self.status.keycard.select()
|
||||||
|
except KeycardSelectException as ex:
|
||||||
|
self.cardUnhandledError(ex.error)
|
||||||
|
return
|
||||||
|
|
||||||
|
self.appInfo = appInfo
|
||||||
|
|
||||||
|
if not appInfo.installed:
|
||||||
|
self.cardState = NotKeycard
|
||||||
|
self.cardNotKeycard()
|
||||||
|
elif not appInfo.initialized:
|
||||||
|
self.cardState = PreInit
|
||||||
|
self.cardPreInit()
|
||||||
|
elif self.attemptOpenSecureChannel():
|
||||||
|
self.onSecureChannelOpened()
|
||||||
|
elif appInfo.availableSlots > 0:
|
||||||
|
self.cardState = Unpaired
|
||||||
|
self.cardUnpaired()
|
||||||
|
else:
|
||||||
|
self.cardState = NoFreeSlots
|
||||||
|
self.cardNoFreeSlots()
|
Loading…
Reference in New Issue