add v2 factory reset

This commit is contained in:
Michele Balistreri 2023-09-08 09:09:43 +09:00
parent 0f6eab0141
commit c6b7095a85
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
3 changed files with 21 additions and 4 deletions

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.16
require (
github.com/ebfe/scard v0.0.0-20190212122703-c3d1b1916a95
github.com/ethereum/go-ethereum v1.10.26
github.com/status-im/keycard-go v0.2.0
github.com/status-im/keycard-go v0.3.0
golang.org/x/crypto v0.1.0
golang.org/x/text v0.4.0
)

4
go.sum
View File

@ -304,8 +304,8 @@ github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA=
github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg=
github.com/status-im/keycard-go v0.3.0 h1:i+JcpGVCR75W8ZGtWQfQgnrepBJQ2+V36BDqh1nF8bo=
github.com/status-im/keycard-go v0.3.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=

View File

@ -212,6 +212,7 @@ func (kc *keycardContext) selectApplet() (*types.ApplicationInfo, error) {
if err != nil {
if e, ok := err.(*apdu.ErrBadResponse); ok && e.Sw == globalplatform.SwFileNotFound {
err = nil
kc.cmdSet.ApplicationInfo = &types.ApplicationInfo{}
} else {
l("select failed %+v", err)
return nil, err
@ -425,7 +426,7 @@ func (kc *keycardContext) changePairingPassword(pairingPassword string) error {
return nil
}
func (kc *keycardContext) factoryReset(retry bool) error {
func (kc *keycardContext) factoryResetFallback(retry bool) error {
cmdSet := globalplatform.NewCommandSet(kc.c)
if err := cmdSet.Select(); err != nil {
@ -462,6 +463,22 @@ func (kc *keycardContext) factoryReset(retry bool) error {
return nil
}
func (kc *keycardContext) factoryReset(retry bool) error {
appInfo, err := kc.selectApplet()
if err != nil || !appInfo.HasFactoryResetCapability() {
return kc.factoryResetFallback(retry)
}
err = kc.cmdSet.FactoryReset()
if err != nil {
return kc.factoryResetFallback(retry)
}
return nil
}
func (kc *keycardContext) storeMetadata(metadata *types.Metadata) error {
err := kc.cmdSet.StoreData(keycard.P1StoreDataPublic, metadata.Serialize())