mirror of
https://github.com/status-im/status-keycard-go.git
synced 2025-01-18 18:31:56 +00:00
implement change credentials flows
This commit is contained in:
parent
5e24a8571d
commit
6883296620
43
flow.go
43
flow.go
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -75,6 +75,7 @@ const (
|
||||
ErrorUnblocking = "unblocking"
|
||||
ErrorSigning = "signing"
|
||||
ErrorExporting = "exporting"
|
||||
ErrorChanging = "changing-credentials"
|
||||
)
|
||||
|
||||
const (
|
||||
|
Loading…
x
Reference in New Issue
Block a user