implement init

This commit is contained in:
Michele Balistreri 2021-10-22 09:55:00 +03:00
parent e299c38600
commit a59b341980
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
3 changed files with 39 additions and 10 deletions

10
flow.go
View File

@ -107,9 +107,7 @@ func (f *KeycardFlow) runFlow() {
func (f *KeycardFlow) pause(action string, errMsg string) {
status := FlowParams{}
if errMsg != "" {
status[ErrorKey] = errMsg
}
status[ErrorKey] = errMsg
if f.cardInfo.freeSlots != -1 {
status[InstanceUID] = f.cardInfo.instanceUID
@ -128,7 +126,7 @@ func (f *KeycardFlow) pause(action string, errMsg string) {
func (f *KeycardFlow) pauseAndWait(action string, errMsg string) error {
if f.state == Cancelling {
return errors.New("cancel")
return giveupErr()
}
f.pause(action, errMsg)
@ -138,7 +136,7 @@ func (f *KeycardFlow) pauseAndWait(action string, errMsg string) error {
f.state = Running
return nil
} else {
return errors.New("cancel")
return giveupErr()
}
}
@ -173,7 +171,7 @@ func (f *KeycardFlow) connect() *keycardContext {
return nil
}
f.pause(InsertCard, "")
f.pause(InsertCard, ErrorConnection)
select {
case <-f.wakeUp:
if f.state != Cancelling {

View File

@ -56,7 +56,7 @@ func (f *KeycardFlow) pair(kc *keycardContext) error {
delete(f.params, PairingPass)
}
err := f.pauseAndWait(EnterPairing, "")
err := f.pauseAndWait(EnterPairing, ErrorPairing)
if err != nil {
return err
@ -66,8 +66,36 @@ func (f *KeycardFlow) pair(kc *keycardContext) error {
}
func (f *KeycardFlow) initCard(kc *keycardContext) error {
//NOTE: after init a restart of the flow is always needed
return errors.New("not implemented")
newPIN, pinOK := f.params[NewPIN]
if !pinOK {
f.pauseAndWait(EnterNewPIN, ErrorRequireInit)
return f.initCard(kc)
}
newPUK, pukOK := f.params[NewPUK]
if !pukOK {
f.pauseAndWait(EnterNewPUK, ErrorRequireInit)
return f.initCard(kc)
}
newPairing, pairingOK := f.params[NewPairing]
if !pairingOK {
f.pauseAndWait(EnterNewPair, ErrorRequireInit)
return f.initCard(kc)
}
err := kc.init(newPIN.(string), newPUK.(string), newPairing.(string))
if err == nil {
f.params[PIN] = newPIN
f.params[PairingPass] = newPairing
delete(f.params, NewPIN)
delete(f.params, NewPUK)
delete(f.params, NewPairing)
}
return err
}
func (f *KeycardFlow) openSC(kc *keycardContext, giveup bool) error {
@ -145,7 +173,7 @@ func (f *KeycardFlow) unblockPIN(kc *keycardContext) error {
if !pukOK {
err = f.pauseAndWait(EnterPUK, pukError)
} else if !pinOK {
err = f.pauseAndWait(EnterNewPIN, "")
err = f.pauseAndWait(EnterNewPIN, ErrorUnblocking)
}
if err != nil {

View File

@ -65,6 +65,9 @@ const (
ErrorUnknownFlow = "unknown-flow"
ErrorNotAKeycard = "not-a-keycard"
ErrorNoKeys = "no-keys"
ErrorRequireInit = "require-init"
ErrorPairing = "pairing"
ErrorUnblocking = "unblocking"
)
const (