add verification command

This commit is contained in:
Michele Balistreri 2023-10-09 20:50:55 +09:00
parent 691380d8d0
commit 9a8018e552
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
4 changed files with 37 additions and 4 deletions

View File

@ -0,0 +1,2 @@
keycard-select
keycard-identify

2
go.mod
View File

@ -6,7 +6,7 @@ require (
github.com/ebfe/scard v0.0.0-20190212122703-c3d1b1916a95
github.com/ethereum/go-ethereum v1.10.26
github.com/hsanjuan/go-ndef v0.0.1
github.com/status-im/keycard-go v0.2.0
github.com/status-im/keycard-go v0.3.1
)
require (

4
go.sum
View File

@ -306,8 +306,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.1 h1:Pbma8F07S23U1qFbsCAE3xik5oxZv0e979hAYvFDqn4=
github.com/status-im/keycard-go v0.3.1/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

@ -150,6 +150,7 @@ func NewShell(t keycardio.Transmitter) *Shell {
"keycard-set-pinless-path": s.commandKeycardSetPinlessPath,
"keycard-load-seed": s.commandKeycardLoadSeed,
"keycard-generate-mnemonic": s.commandKeycardGenerateMnemonic,
"keycard-identify": s.commandKeycardIdentify,
"cash-select": s.commandCashSelect,
"cash-sign": s.commandCashSign,
}
@ -171,7 +172,7 @@ func (s *Shell) Run() error {
for {
line, err := reader.ReadString('\n')
if err != nil {
if err != nil && err != io.EOF {
break
}
@ -886,6 +887,36 @@ func (s *Shell) commandKeycardLoadSeed(args ...string) error {
return nil
}
func (s *Shell) commandKeycardIdentify(args ...string) error {
pubkey, err := s.kCmdSet.Identify()
if err != nil {
logger.Error("failed card identification", "error", err)
return err
}
logger.Info(fmt.Sprintf("identification public key: %x", pubkey))
var compareKey []byte
if len(args) == 1 {
compareKey, err = s.parseHex(args[0])
if err != nil {
logger.Error("failed parsing public key", "error", err)
return err
}
} else {
compareKey = pubkey
}
if !bytes.Equal(compareKey, pubkey) {
logger.Error("the recovered key does not match the expected value", "error", err)
return errors.New("genuinity check failed")
}
return nil
}
func (s *Shell) commandCashSelect(args ...string) error {
if err := s.requireArgs(args, 0); err != nil {
return err