From d45beefc1434a112499f6a8be20c3e5dfe5249d0 Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Mon, 25 Oct 2021 17:07:24 +0200 Subject: [PATCH] add factoryReset method --- keycard_context.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/keycard_context.go b/keycard_context.go index 5a37623..89156aa 100644 --- a/keycard_context.go +++ b/keycard_context.go @@ -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 +}