mirror of
https://github.com/status-im/status-keycard-go.git
synced 2025-02-12 06:16:48 +00:00
* ci: simple build and lint jobs, upgrade to Go 1.22 * ci: install pcsc-lite * fix: linter issues * fix: bump golangci-lint version * fix: go mod tidy * fix: rebase issues * feat: make lint command * ci: add pcsc lib
116 lines
3.8 KiB
Go
116 lines
3.8 KiB
Go
package mocked
|
|
|
|
import (
|
|
"github.com/status-im/status-keycard-go/internal"
|
|
"github.com/status-im/status-keycard-go/pkg/flow"
|
|
"github.com/status-im/status-keycard-go/signal"
|
|
)
|
|
|
|
func (mkf *MockedKeycardFlow) handleRecoverAccountFlow() {
|
|
flowStatus := flow.FlowStatus{}
|
|
|
|
if mkf.insertedKeycard.NotStatusKeycard {
|
|
flowStatus[internal.ErrorKey] = internal.ErrorNotAKeycard
|
|
flowStatus[flow.InstanceUID] = ""
|
|
flowStatus[flow.KeyUID] = ""
|
|
flowStatus[flow.FreeSlots] = 0
|
|
mkf.state = flow.Paused
|
|
signal.Send(flow.SwapCard, flowStatus)
|
|
return
|
|
}
|
|
|
|
flowStatus = flow.FlowStatus{
|
|
flow.InstanceUID: mkf.insertedKeycard.InstanceUID,
|
|
flow.KeyUID: mkf.insertedKeycard.KeyUID,
|
|
}
|
|
|
|
if mkf.insertedKeycard.InstanceUID == "" || mkf.insertedKeycard.KeyUID == "" {
|
|
finalType := flow.SwapCard
|
|
flowStatus[internal.ErrorKey] = internal.ErrorNoKeys
|
|
flowStatus[flow.FreeSlots] = 0
|
|
mkf.state = flow.Paused
|
|
signal.Send(finalType, flowStatus)
|
|
return
|
|
}
|
|
|
|
var (
|
|
enteredPIN string
|
|
enteredNewPIN string
|
|
enteredPUK string
|
|
)
|
|
|
|
if v, ok := mkf.params[flow.PIN]; ok {
|
|
enteredPIN = v.(string)
|
|
}
|
|
if v, ok := mkf.params[flow.NewPIN]; ok {
|
|
enteredNewPIN = v.(string)
|
|
}
|
|
if v, ok := mkf.params[flow.PUK]; ok {
|
|
enteredPUK = v.(string)
|
|
}
|
|
|
|
finalType := flow.EnterPIN
|
|
if mkf.insertedKeycard.PukRetries == 0 {
|
|
flowStatus[internal.ErrorKey] = flow.PUKRetries
|
|
finalType = flow.SwapCard
|
|
} else {
|
|
if mkf.insertedKeycard.PinRetries == 0 {
|
|
if len(enteredPUK) == flow.DefPUKLen {
|
|
if len(enteredPIN) == flow.DefPINLen && enteredPIN == enteredNewPIN {
|
|
if enteredPUK != mkf.insertedKeycard.Puk {
|
|
mkf.insertedKeycard.PukRetries--
|
|
if mkf.insertedKeycard.PukRetries == 0 {
|
|
flowStatus[internal.ErrorKey] = flow.PUKRetries
|
|
finalType = flow.SwapCard
|
|
} else {
|
|
flowStatus[internal.ErrorKey] = flow.PUK
|
|
finalType = flow.EnterPUK
|
|
}
|
|
}
|
|
} else {
|
|
flowStatus[internal.ErrorKey] = internal.ErrorUnblocking
|
|
finalType = flow.EnterNewPIN
|
|
}
|
|
} else {
|
|
flowStatus[internal.ErrorKey] = ""
|
|
finalType = flow.EnterPUK
|
|
}
|
|
} else {
|
|
if len(enteredNewPIN) == 0 && len(enteredPIN) == flow.DefPINLen && enteredPIN != mkf.insertedKeycard.Pin {
|
|
mkf.insertedKeycard.PinRetries--
|
|
flowStatus[internal.ErrorKey] = flow.PIN
|
|
finalType = flow.EnterPIN
|
|
if mkf.insertedKeycard.PinRetries == 0 {
|
|
flowStatus[internal.ErrorKey] = ""
|
|
finalType = flow.EnterPUK
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if mkf.insertedKeycard.PinRetries > 0 && len(enteredPIN) == flow.DefPINLen && enteredPIN == mkf.insertedKeycard.Pin ||
|
|
mkf.insertedKeycard.PinRetries == 0 && mkf.insertedKeycard.PukRetries > 0 && len(enteredPUK) == flow.DefPUKLen &&
|
|
enteredPUK == mkf.insertedKeycard.Puk && len(enteredPIN) == flow.DefPINLen && enteredPIN == enteredNewPIN {
|
|
|
|
mkf.insertedKeycard.PinRetries = flow.MaxPINRetries
|
|
mkf.insertedKeycard.PukRetries = flow.MaxPUKRetries
|
|
mkf.insertedKeycard.Pin = enteredPIN
|
|
flowStatus[internal.ErrorKey] = ""
|
|
flowStatus[flow.MasterKey] = mkf.insertedKeycardHelper.ExportedKey[flow.MasterPath]
|
|
flowStatus[flow.WalleRootKey] = mkf.insertedKeycardHelper.ExportedKey[flow.WalletRoothPath]
|
|
flowStatus[flow.WalletKey] = mkf.insertedKeycardHelper.ExportedKey[flow.WalletPath]
|
|
flowStatus[flow.EIP1581Key] = mkf.insertedKeycardHelper.ExportedKey[flow.Eip1581Path]
|
|
flowStatus[flow.WhisperKey] = mkf.insertedKeycardHelper.ExportedKey[flow.WhisperPath]
|
|
flowStatus[flow.EncKey] = mkf.insertedKeycardHelper.ExportedKey[flow.EncryptionPath]
|
|
mkf.state = flow.Idle
|
|
signal.Send(flow.FlowResult, flowStatus)
|
|
return
|
|
}
|
|
|
|
flowStatus[flow.FreeSlots] = mkf.insertedKeycard.FreePairingSlots
|
|
flowStatus[flow.PINRetries] = mkf.insertedKeycard.PinRetries
|
|
flowStatus[flow.PUKRetries] = mkf.insertedKeycard.PukRetries
|
|
mkf.state = flow.Paused
|
|
signal.Send(finalType, flowStatus)
|
|
}
|