add factoryReset method

This commit is contained in:
Andrea Franz 2021-10-25 17:07:24 +02:00
parent b1e1f7f0bf
commit d45beefc14
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D

View File

@ -9,6 +9,7 @@ import (
keycard "github.com/status-im/keycard-go"
"github.com/status-im/keycard-go/apdu"
"github.com/status-im/keycard-go/globalplatform"
"github.com/status-im/keycard-go/identifiers"
"github.com/status-im/keycard-go/io"
"github.com/status-im/keycard-go/types"
"golang.org/x/crypto/pbkdf2"
@ -461,3 +462,34 @@ func (kc *keycardContext) changePairingPassword(pairingPassword string) error {
return nil
}
func (kc *keycardContext) factoryReset(pairingPassword string) error {
<-kc.connected
if kc.runErr != nil {
return kc.runErr
}
cmdSet := globalplatform.NewCommandSet(kc.c)
if err := cmdSet.OpenSecureChannel(); err != nil {
l("open secure channel failed", "error", err)
return err
}
aid, err := identifiers.KeycardInstanceAID(1)
if err != nil {
l("error getting keycard aid %+v", err)
return err
}
if err := cmdSet.DeleteObject(aid); err != nil {
l("error deleting keycard aid %+v", err)
return err
}
if err := cmdSet.InstallKeycardApplet(); err != nil {
l("error installing Keycard applet %+v", err)
return err
}
return nil
}