mirror of
https://github.com/status-im/keycard-cli.git
synced 2025-02-28 20:00:38 +00:00
info command shows cash applet info
This commit is contained in:
parent
60241043d8
commit
939cac4b3e
4
Gopkg.lock
generated
4
Gopkg.lock
generated
@ -58,7 +58,7 @@
|
||||
|
||||
[[projects]]
|
||||
branch = "develop"
|
||||
digest = "1:44f5b58c27b45056a4d88fe7ce11b00fd0a10a590ef0de9a4a32f50a4de91cce"
|
||||
digest = "1:c1e848dfcb099a3a582671d67bf2aa58ad51b330cf2d808bf8123075da972fc9"
|
||||
name = "github.com/status-im/keycard-go"
|
||||
packages = [
|
||||
".",
|
||||
@ -73,7 +73,7 @@
|
||||
"types",
|
||||
]
|
||||
pruneopts = "NUT"
|
||||
revision = "f38e9a19958eb492359ace5d068a7ce42e7824f8"
|
||||
revision = "957c095369694cc23ce9f2bca4acd325764860eb"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
@ -68,7 +68,7 @@ func (i *Initializer) Init() (*keycard.Secrets, error) {
|
||||
}
|
||||
|
||||
// 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")
|
||||
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) {
|
||||
|
49
main.go
49
main.go
@ -12,6 +12,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/ebfe/scard"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
)
|
||||
|
||||
@ -241,7 +242,7 @@ func commandInstall(card *scard.Card) error {
|
||||
|
||||
func commandInfo(card *scard.Card) error {
|
||||
i := NewInitializer(card)
|
||||
info, err := i.Info()
|
||||
info, cashInfo, err := i.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -251,19 +252,39 @@ func commandInfo(card *scard.Card) error {
|
||||
keyInitialized = true
|
||||
}
|
||||
|
||||
fmt.Printf("Installed: %+v\n", info.Installed)
|
||||
fmt.Printf("Initialized: %+v\n", info.Initialized)
|
||||
fmt.Printf("Key Initialized: %+v\n", keyInitialized)
|
||||
fmt.Printf("InstanceUID: 0x%x\n", info.InstanceUID)
|
||||
fmt.Printf("SecureChannelPublicKey: 0x%x\n", info.SecureChannelPublicKey)
|
||||
fmt.Printf("Version: 0x%x\n", info.Version)
|
||||
fmt.Printf("AvailableSlots: 0x%x\n", info.AvailableSlots)
|
||||
fmt.Printf("KeyUID: 0x%x\n", info.KeyUID)
|
||||
fmt.Printf("Capabilities:\n")
|
||||
fmt.Printf(" Secure channel:%v\n", info.HasSecureChannelCapability())
|
||||
fmt.Printf(" Key management:%v\n", info.HasKeyManagementCapability())
|
||||
fmt.Printf(" Credentials Management:%v\n", info.HasCredentialsManagementCapability())
|
||||
fmt.Printf(" NDEF:%v\n", info.HasNDEFCapability())
|
||||
fmt.Printf("Keycard Applet:\n")
|
||||
fmt.Printf(" Installed: %+v\n", info.Installed)
|
||||
fmt.Printf(" Initialized: %+v\n", info.Initialized)
|
||||
fmt.Printf(" Key Initialized: %+v\n", keyInitialized)
|
||||
fmt.Printf(" InstanceUID: 0x%x\n", info.InstanceUID)
|
||||
fmt.Printf(" SecureChannelPublicKey: 0x%x\n", info.SecureChannelPublicKey)
|
||||
fmt.Printf(" Version: 0x%x\n", info.Version)
|
||||
fmt.Printf(" AvailableSlots: 0x%x\n", info.AvailableSlots)
|
||||
fmt.Printf(" KeyUID: 0x%x\n", info.KeyUID)
|
||||
fmt.Printf(" Capabilities:\n")
|
||||
fmt.Printf(" Secure channel:%v\n", info.HasSecureChannelCapability())
|
||||
fmt.Printf(" Key management:%v\n", info.HasKeyManagementCapability())
|
||||
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
|
||||
}
|
||||
|
2
shell.go
2
shell.go
@ -820,7 +820,7 @@ func (s *Shell) commandCashSelect(args ...string) error {
|
||||
|
||||
s.write(fmt.Sprintf("Installed: %v\n", info.Installed))
|
||||
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))
|
||||
|
||||
if e, ok := err.(*apdu.ErrBadResponse); ok && e.Sw == globalplatform.SwFileNotFound {
|
||||
|
12
vendor/github.com/status-im/keycard-go/types/cash_application_info.go
generated
vendored
12
vendor/github.com/status-im/keycard-go/types/cash_application_info.go
generated
vendored
@ -3,10 +3,10 @@ package types
|
||||
import "github.com/status-im/keycard-go/apdu"
|
||||
|
||||
type CashApplicationInfo struct {
|
||||
Installed bool
|
||||
PublicKey []byte
|
||||
PublicKeyData []byte
|
||||
Version []byte
|
||||
Installed bool
|
||||
PublicKey []byte
|
||||
PublicData []byte
|
||||
Version []byte
|
||||
}
|
||||
|
||||
func ParseCashApplicationInfo(data []byte) (*CashApplicationInfo, error) {
|
||||
@ -23,7 +23,7 @@ func ParseCashApplicationInfo(data []byte) (*CashApplicationInfo, error) {
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
@ -34,7 +34,7 @@ func ParseCashApplicationInfo(data []byte) (*CashApplicationInfo, error) {
|
||||
}
|
||||
|
||||
info.PublicKey = pubKey
|
||||
info.PublicKeyData = pubKeyData
|
||||
info.PublicData = pubData
|
||||
info.Version = appVersion
|
||||
|
||||
return info, nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user