implement change credentials flows

This commit is contained in:
Michele Balistreri 2021-10-25 09:10:43 +03:00
parent 5e24a8571d
commit 6883296620
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
3 changed files with 106 additions and 4 deletions

43
flow.go
View File

@ -353,15 +353,51 @@ func (f *KeycardFlow) signFlow(kc *keycardContext) (FlowStatus, error) {
}
func (f *KeycardFlow) changePINFlow(kc *keycardContext) (FlowStatus, error) {
return nil, errors.New("not implemented yet")
err := f.openSCAndAuthenticate(kc, false)
if err != nil {
return nil, err
}
err = f.changePIN(kc)
if err != nil {
return nil, err
}
return FlowStatus{InstanceUID: f.cardInfo.instanceUID}, nil
}
func (f *KeycardFlow) changePUKFlow(kc *keycardContext) (FlowStatus, error) {
return nil, errors.New("not implemented yet")
err := f.openSCAndAuthenticate(kc, false)
if err != nil {
return nil, err
}
err = f.changePUK(kc)
if err != nil {
return nil, err
}
return FlowStatus{InstanceUID: f.cardInfo.instanceUID}, nil
}
func (f *KeycardFlow) changePairingFlow(kc *keycardContext) (FlowStatus, error) {
return nil, errors.New("not implemented yet")
err := f.openSCAndAuthenticate(kc, false)
if err != nil {
return nil, err
}
err = f.changePairing(kc)
if err != nil {
return nil, err
}
return FlowStatus{InstanceUID: f.cardInfo.instanceUID}, nil
}
func (f *KeycardFlow) unpairThisFlow(kc *keycardContext) (FlowStatus, error) {
@ -399,7 +435,6 @@ func (f *KeycardFlow) unpairOthersFlow(kc *keycardContext) (FlowStatus, error) {
return nil, err
}
f.cardInfo.freeSlots++
}
return FlowStatus{InstanceUID: f.cardInfo.instanceUID, FreeSlots: f.cardInfo.freeSlots}, nil

View File

@ -279,3 +279,69 @@ func (f *KeycardFlow) exportKey(kc *keycardContext, path string, onlyPublic bool
return keyPair, err
}
func (f *KeycardFlow) changePIN(kc *keycardContext) error {
if newPIN, ok := f.params[NewPIN]; ok {
err := kc.changePin(newPIN.(string))
if isSCardError(err) {
return restartErr()
} else if err != nil {
return err
}
return nil
}
err := f.pauseAndWait(EnterNewPIN, ErrorChanging)
if err != nil {
return err
}
return f.changePIN(kc)
}
func (f *KeycardFlow) changePUK(kc *keycardContext) error {
if newPUK, ok := f.params[NewPUK]; ok {
err := kc.changePuk(newPUK.(string))
if isSCardError(err) {
return restartErr()
} else if err != nil {
return err
}
return nil
}
err := f.pauseAndWait(EnterNewPUK, ErrorChanging)
if err != nil {
return err
}
return f.changePUK(kc)
}
func (f *KeycardFlow) changePairing(kc *keycardContext) error {
if newPairing, ok := f.params[NewPairing]; ok {
err := kc.changePairingPassword(newPairing.(string))
if isSCardError(err) {
return restartErr()
} else if err != nil {
return err
}
return nil
}
err := f.pauseAndWait(EnterNewPair, ErrorChanging)
if err != nil {
return err
}
return f.changePairing(kc)
}

View File

@ -75,6 +75,7 @@ const (
ErrorUnblocking = "unblocking"
ErrorSigning = "signing"
ErrorExporting = "exporting"
ErrorChanging = "changing-credentials"
)
const (