Skip to content

Commit 939cac4

Browse files
committed
info command shows cash applet info
1 parent 6024104 commit 939cac4

File tree

5 files changed

+57
-25
lines changed

5 files changed

+57
-25
lines changed

Gopkg.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

initializer.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (i *Initializer) Init() (*keycard.Secrets, error) {
6868
}
6969

7070
// Info returns a types.ApplicationInfo struct with info about the card.
71-
func (i *Initializer) Info() (*types.ApplicationInfo, error) {
71+
func (i *Initializer) Info() (*types.ApplicationInfo, *types.CashApplicationInfo, error) {
7272
logger.Info("info started")
7373
cmdSet := keycard.NewCommandSet(i.c)
7474

@@ -82,7 +82,18 @@ func (i *Initializer) Info() (*types.ApplicationInfo, error) {
8282
}
8383
}
8484

85-
return cmdSet.ApplicationInfo, err
85+
logger.Info("select cash applet")
86+
cashCmdSet := keycard.NewCashCommandSet(i.c)
87+
err = cashCmdSet.Select()
88+
if err != nil {
89+
if e, ok := err.(*apdu.ErrBadResponse); ok && e.Sw == globalplatform.SwFileNotFound {
90+
err = nil
91+
} else {
92+
logger.Error("select failed", "error", err)
93+
}
94+
}
95+
96+
return cmdSet.ApplicationInfo, cashCmdSet.CashApplicationInfo, err
8697
}
8798

8899
func (i *Initializer) Pair(pairingPass string) (*types.PairingInfo, error) {

main.go

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313

1414
"github.com/ebfe/scard"
15+
"github.com/ethereum/go-ethereum/crypto"
1516
"github.com/ethereum/go-ethereum/log"
1617
)
1718

@@ -241,7 +242,7 @@ func commandInstall(card *scard.Card) error {
241242

242243
func commandInfo(card *scard.Card) error {
243244
i := NewInitializer(card)
244-
info, err := i.Info()
245+
info, cashInfo, err := i.Info()
245246
if err != nil {
246247
return err
247248
}
@@ -251,19 +252,39 @@ func commandInfo(card *scard.Card) error {
251252
keyInitialized = true
252253
}
253254

254-
fmt.Printf("Installed: %+v\n", info.Installed)
255-
fmt.Printf("Initialized: %+v\n", info.Initialized)
256-
fmt.Printf("Key Initialized: %+v\n", keyInitialized)
257-
fmt.Printf("InstanceUID: 0x%x\n", info.InstanceUID)
258-
fmt.Printf("SecureChannelPublicKey: 0x%x\n", info.SecureChannelPublicKey)
259-
fmt.Printf("Version: 0x%x\n", info.Version)
260-
fmt.Printf("AvailableSlots: 0x%x\n", info.AvailableSlots)
261-
fmt.Printf("KeyUID: 0x%x\n", info.KeyUID)
262-
fmt.Printf("Capabilities:\n")
263-
fmt.Printf(" Secure channel:%v\n", info.HasSecureChannelCapability())
264-
fmt.Printf(" Key management:%v\n", info.HasKeyManagementCapability())
265-
fmt.Printf(" Credentials Management:%v\n", info.HasCredentialsManagementCapability())
266-
fmt.Printf(" NDEF:%v\n", info.HasNDEFCapability())
255+
fmt.Printf("Keycard Applet:\n")
256+
fmt.Printf(" Installed: %+v\n", info.Installed)
257+
fmt.Printf(" Initialized: %+v\n", info.Initialized)
258+
fmt.Printf(" Key Initialized: %+v\n", keyInitialized)
259+
fmt.Printf(" InstanceUID: 0x%x\n", info.InstanceUID)
260+
fmt.Printf(" SecureChannelPublicKey: 0x%x\n", info.SecureChannelPublicKey)
261+
fmt.Printf(" Version: 0x%x\n", info.Version)
262+
fmt.Printf(" AvailableSlots: 0x%x\n", info.AvailableSlots)
263+
fmt.Printf(" KeyUID: 0x%x\n", info.KeyUID)
264+
fmt.Printf(" Capabilities:\n")
265+
fmt.Printf(" Secure channel:%v\n", info.HasSecureChannelCapability())
266+
fmt.Printf(" Key management:%v\n", info.HasKeyManagementCapability())
267+
fmt.Printf(" Credentials Management:%v\n", info.HasCredentialsManagementCapability())
268+
fmt.Printf(" NDEF:%v\n", info.HasNDEFCapability())
269+
fmt.Printf("Cash applet \n\n")
270+
271+
if cashInfo == nil {
272+
fmt.Printf(" Installed: %+v\n", false)
273+
return nil
274+
}
275+
276+
ecdsaPubKey, err := crypto.UnmarshalPubkey(cashInfo.PublicKey)
277+
if err != nil {
278+
return err
279+
}
280+
281+
cashAddress := crypto.PubkeyToAddress(*ecdsaPubKey)
282+
283+
fmt.Printf(" Installed: %+v\n", cashInfo.Installed)
284+
fmt.Printf(" PublicKey: 0x%x\n", cashInfo.PublicKey)
285+
fmt.Printf(" Address: 0x%x\n", cashAddress)
286+
fmt.Printf(" Public Data: 0x%x\n", cashInfo.PublicData)
287+
fmt.Printf(" Version: 0x%x\n", cashInfo.Version)
267288

268289
return nil
269290
}

shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ func (s *Shell) commandCashSelect(args ...string) error {
820820

821821
s.write(fmt.Sprintf("Installed: %v\n", info.Installed))
822822
s.write(fmt.Sprintf("PublicKey: %x\n", info.PublicKey))
823-
s.write(fmt.Sprintf("PublicKeyData: %x\n", info.PublicKeyData))
823+
s.write(fmt.Sprintf("PublicData: %x\n", info.PublicData))
824824
s.write(fmt.Sprintf("Version: %x\n\n", info.Version))
825825

826826
if e, ok := err.(*apdu.ErrBadResponse); ok && e.Sw == globalplatform.SwFileNotFound {

vendor/github.com/status-im/keycard-go/types/cash_application_info.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)