mirror of
https://github.com/status-im/keycard-cli.git
synced 2025-03-01 04:10:33 +00:00
add get status command
This commit is contained in:
parent
b13aea9a12
commit
37c8328994
@ -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, error) {
|
||||||
logger.Info("info started")
|
logger.Info("info started")
|
||||||
cmdSet := keycard.NewCommandSet(i.c)
|
cmdSet := keycard.NewCommandSet(i.c)
|
||||||
|
|
||||||
@ -104,6 +104,41 @@ func (i *Initializer) Pair(pairingPass string) (*types.PairingInfo, error) {
|
|||||||
return cmdSet.PairingInfo, err
|
return cmdSet.PairingInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Initializer) Status(key []byte, index int) (*types.ApplicationStatus, error) {
|
||||||
|
logger.Info("pairing started")
|
||||||
|
cmdSet := keycard.NewCommandSet(i.c)
|
||||||
|
|
||||||
|
logger.Info("select keycard applet")
|
||||||
|
err := cmdSet.Select()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("select failed", "error", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !cmdSet.ApplicationInfo.Initialized {
|
||||||
|
logger.Error("pairing failed", "error", ErrNotInitialized)
|
||||||
|
return nil, ErrNotInitialized
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Info("open secure channel")
|
||||||
|
cmdSet.SetPairingInfo(key, index)
|
||||||
|
err = cmdSet.OpenSecureChannel()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("open secure channel failed", "error", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Info("get status")
|
||||||
|
cmdSet.SetPairingInfo(key, index)
|
||||||
|
appStatus, err := cmdSet.GetStatus()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("get status failed", "error", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return appStatus, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (i *Initializer) initGPSecureChannel(sdaid []byte) error {
|
func (i *Initializer) initGPSecureChannel(sdaid []byte) error {
|
||||||
// select card manager
|
// select card manager
|
||||||
err := i.selectAID(sdaid)
|
err := i.selectAID(sdaid)
|
||||||
|
36
main.go
36
main.go
@ -49,7 +49,7 @@ func init() {
|
|||||||
"delete": commandDelete,
|
"delete": commandDelete,
|
||||||
"init": commandInit,
|
"init": commandInit,
|
||||||
"pair": commandPair,
|
"pair": commandPair,
|
||||||
// "status": commandStatus,
|
"status": commandStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
@ -168,14 +168,14 @@ func askHex(description string) []byte {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func askUint8(description string) uint8 {
|
func askInt(description string) int {
|
||||||
s := ask(description)
|
s := ask(description)
|
||||||
i, err := strconv.ParseUint(s, 10, 8)
|
i, err := strconv.ParseInt(s, 10, 8)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stdlog.Fatal(err)
|
stdlog.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return uint8(i)
|
return int(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
func commandInstall(card *scard.Card) error {
|
func commandInstall(card *scard.Card) error {
|
||||||
@ -258,20 +258,20 @@ func commandPair(card *scard.Card) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// func commandStatus(card *scard.Card) error {
|
func commandStatus(card *scard.Card) error {
|
||||||
// i := NewInitializer(card)
|
i := NewInitializer(card)
|
||||||
// index := askUint8("Pairing index")
|
key := askHex("Pairing key")
|
||||||
// key := askHex("Pairing key")
|
index := askInt("Pairing index")
|
||||||
|
|
||||||
// appStatus, err := i.Status(index, key)
|
appStatus, err := i.Status(key, index)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
|
|
||||||
// fmt.Printf("Pin retry count: %d\n", appStatus.PinRetryCount)
|
fmt.Printf("Pin retry count: %d\n", appStatus.PinRetryCount)
|
||||||
// fmt.Printf("PUK retry count: %d\n", appStatus.PUKRetryCount)
|
fmt.Printf("PUK retry count: %d\n", appStatus.PUKRetryCount)
|
||||||
// fmt.Printf("Key initialized: %v\n", appStatus.KeyInitialized)
|
fmt.Printf("Key initialized: %v\n", appStatus.KeyInitialized)
|
||||||
// fmt.Printf("Public key derivation: %v\n", appStatus.PubKeyDerivation)
|
fmt.Printf("Public key derivation: %v\n", appStatus.PubKeyDerivation)
|
||||||
|
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user