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