info command shows cash applet info

This commit is contained in:
Andrea Franz 2020-04-02 12:28:32 +02:00
parent 60241043d8
commit 939cac4b3e
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
5 changed files with 57 additions and 25 deletions

4
Gopkg.lock generated
View File

@ -58,7 +58,7 @@
[[projects]] [[projects]]
branch = "develop" branch = "develop"
digest = "1:44f5b58c27b45056a4d88fe7ce11b00fd0a10a590ef0de9a4a32f50a4de91cce" digest = "1:c1e848dfcb099a3a582671d67bf2aa58ad51b330cf2d808bf8123075da972fc9"
name = "github.com/status-im/keycard-go" name = "github.com/status-im/keycard-go"
packages = [ packages = [
".", ".",
@ -73,7 +73,7 @@
"types", "types",
] ]
pruneopts = "NUT" pruneopts = "NUT"
revision = "f38e9a19958eb492359ace5d068a7ce42e7824f8" revision = "957c095369694cc23ce9f2bca4acd325764860eb"
[[projects]] [[projects]]
branch = "master" branch = "master"

View File

@ -68,7 +68,7 @@ func (i *Initializer) Init() (*keycard.Secrets, error) {
} }
// Info returns a types.ApplicationInfo struct with info about the card. // Info returns a types.ApplicationInfo struct with info about the card.
func (i *Initializer) Info() (*types.ApplicationInfo, error) { func (i *Initializer) Info() (*types.ApplicationInfo, *types.CashApplicationInfo, error) {
logger.Info("info started") logger.Info("info started")
cmdSet := keycard.NewCommandSet(i.c) cmdSet := keycard.NewCommandSet(i.c)
@ -82,7 +82,18 @@ func (i *Initializer) Info() (*types.ApplicationInfo, error) {
} }
} }
return cmdSet.ApplicationInfo, err logger.Info("select cash applet")
cashCmdSet := keycard.NewCashCommandSet(i.c)
err = cashCmdSet.Select()
if err != nil {
if e, ok := err.(*apdu.ErrBadResponse); ok && e.Sw == globalplatform.SwFileNotFound {
err = nil
} else {
logger.Error("select failed", "error", err)
}
}
return cmdSet.ApplicationInfo, cashCmdSet.CashApplicationInfo, err
} }
func (i *Initializer) Pair(pairingPass string) (*types.PairingInfo, error) { func (i *Initializer) Pair(pairingPass string) (*types.PairingInfo, error) {

49
main.go
View File

@ -12,6 +12,7 @@ import (
"strings" "strings"
"github.com/ebfe/scard" "github.com/ebfe/scard"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
@ -241,7 +242,7 @@ func commandInstall(card *scard.Card) error {
func commandInfo(card *scard.Card) error { func commandInfo(card *scard.Card) error {
i := NewInitializer(card) i := NewInitializer(card)
info, err := i.Info() info, cashInfo, err := i.Info()
if err != nil { if err != nil {
return err return err
} }
@ -251,19 +252,39 @@ func commandInfo(card *scard.Card) error {
keyInitialized = true keyInitialized = true
} }
fmt.Printf("Installed: %+v\n", info.Installed) fmt.Printf("Keycard Applet:\n")
fmt.Printf("Initialized: %+v\n", info.Initialized) fmt.Printf(" Installed: %+v\n", info.Installed)
fmt.Printf("Key Initialized: %+v\n", keyInitialized) fmt.Printf(" Initialized: %+v\n", info.Initialized)
fmt.Printf("InstanceUID: 0x%x\n", info.InstanceUID) fmt.Printf(" Key Initialized: %+v\n", keyInitialized)
fmt.Printf("SecureChannelPublicKey: 0x%x\n", info.SecureChannelPublicKey) fmt.Printf(" InstanceUID: 0x%x\n", info.InstanceUID)
fmt.Printf("Version: 0x%x\n", info.Version) fmt.Printf(" SecureChannelPublicKey: 0x%x\n", info.SecureChannelPublicKey)
fmt.Printf("AvailableSlots: 0x%x\n", info.AvailableSlots) fmt.Printf(" Version: 0x%x\n", info.Version)
fmt.Printf("KeyUID: 0x%x\n", info.KeyUID) fmt.Printf(" AvailableSlots: 0x%x\n", info.AvailableSlots)
fmt.Printf("Capabilities:\n") fmt.Printf(" KeyUID: 0x%x\n", info.KeyUID)
fmt.Printf(" Secure channel:%v\n", info.HasSecureChannelCapability()) fmt.Printf(" Capabilities:\n")
fmt.Printf(" Key management:%v\n", info.HasKeyManagementCapability()) fmt.Printf(" Secure channel:%v\n", info.HasSecureChannelCapability())
fmt.Printf(" Credentials Management:%v\n", info.HasCredentialsManagementCapability()) fmt.Printf(" Key management:%v\n", info.HasKeyManagementCapability())
fmt.Printf(" NDEF:%v\n", info.HasNDEFCapability()) fmt.Printf(" Credentials Management:%v\n", info.HasCredentialsManagementCapability())
fmt.Printf(" NDEF:%v\n", info.HasNDEFCapability())
fmt.Printf("Cash applet \n\n")
if cashInfo == nil {
fmt.Printf(" Installed: %+v\n", false)
return nil
}
ecdsaPubKey, err := crypto.UnmarshalPubkey(cashInfo.PublicKey)
if err != nil {
return err
}
cashAddress := crypto.PubkeyToAddress(*ecdsaPubKey)
fmt.Printf(" Installed: %+v\n", cashInfo.Installed)
fmt.Printf(" PublicKey: 0x%x\n", cashInfo.PublicKey)
fmt.Printf(" Address: 0x%x\n", cashAddress)
fmt.Printf(" Public Data: 0x%x\n", cashInfo.PublicData)
fmt.Printf(" Version: 0x%x\n", cashInfo.Version)
return nil return nil
} }

View File

@ -820,7 +820,7 @@ func (s *Shell) commandCashSelect(args ...string) error {
s.write(fmt.Sprintf("Installed: %v\n", info.Installed)) s.write(fmt.Sprintf("Installed: %v\n", info.Installed))
s.write(fmt.Sprintf("PublicKey: %x\n", info.PublicKey)) s.write(fmt.Sprintf("PublicKey: %x\n", info.PublicKey))
s.write(fmt.Sprintf("PublicKeyData: %x\n", info.PublicKeyData)) s.write(fmt.Sprintf("PublicData: %x\n", info.PublicData))
s.write(fmt.Sprintf("Version: %x\n\n", info.Version)) s.write(fmt.Sprintf("Version: %x\n\n", info.Version))
if e, ok := err.(*apdu.ErrBadResponse); ok && e.Sw == globalplatform.SwFileNotFound { if e, ok := err.(*apdu.ErrBadResponse); ok && e.Sw == globalplatform.SwFileNotFound {

View File

@ -3,10 +3,10 @@ package types
import "github.com/status-im/keycard-go/apdu" import "github.com/status-im/keycard-go/apdu"
type CashApplicationInfo struct { type CashApplicationInfo struct {
Installed bool Installed bool
PublicKey []byte PublicKey []byte
PublicKeyData []byte PublicData []byte
Version []byte Version []byte
} }
func ParseCashApplicationInfo(data []byte) (*CashApplicationInfo, error) { func ParseCashApplicationInfo(data []byte) (*CashApplicationInfo, error) {
@ -23,7 +23,7 @@ func ParseCashApplicationInfo(data []byte) (*CashApplicationInfo, error) {
return nil, err return nil, err
} }
pubKeyData, err := apdu.FindTag(data, apdu.Tag{TagApplicationInfoTemplate}, apdu.Tag{0x82}) pubData, err := apdu.FindTag(data, apdu.Tag{TagApplicationInfoTemplate}, apdu.Tag{0x82})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -34,7 +34,7 @@ func ParseCashApplicationInfo(data []byte) (*CashApplicationInfo, error) {
} }
info.PublicKey = pubKey info.PublicKey = pubKey
info.PublicKeyData = pubKeyData info.PublicData = pubData
info.Version = appVersion info.Version = appVersion
return info, nil return info, nil