mirror of
https://github.com/status-im/keycard-go.git
synced 2025-02-22 08:38:17 +00:00
parse key path status
This commit is contained in:
parent
9aed67c579
commit
f42cbfe8b5
@ -129,7 +129,7 @@ func (i *Initializer) Status(key []byte, index int) (*types.ApplicationStatus, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.Info("get status")
|
logger.Info("get status")
|
||||||
appStatus, err := cmdSet.GetStatus()
|
appStatus, err := cmdSet.GetStatusApplication()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("get status failed", "error", err)
|
logger.Error("get status failed", "error", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -317,16 +317,24 @@ func (s *Shell) commandKeycardGetStatus(args ...string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info("get status")
|
logger.Info("get status application")
|
||||||
appStatus, err := s.kCmdSet.GetStatus()
|
appStatus, err := s.kCmdSet.GetStatusApplication()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("get status failed", "error", err)
|
logger.Error("get status application failed", "error", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Info("get status key path")
|
||||||
|
keyStatus, err := s.kCmdSet.GetStatusKeyPath()
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("get status key path failed", "error", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.write(fmt.Sprintf("STATUS - PIN RETRY COUNT: %d\n", appStatus.PinRetryCount))
|
s.write(fmt.Sprintf("STATUS - PIN RETRY COUNT: %d\n", appStatus.PinRetryCount))
|
||||||
s.write(fmt.Sprintf("STATUS - PUK RETRY COUNT: %d\n", appStatus.PUKRetryCount))
|
s.write(fmt.Sprintf("STATUS - PUK RETRY COUNT: %d\n", appStatus.PUKRetryCount))
|
||||||
s.write(fmt.Sprintf("STATUS - KEY INITIALIZED: %v\n", appStatus.KeyInitialized))
|
s.write(fmt.Sprintf("STATUS - KEY INITIALIZED: %v\n", appStatus.KeyInitialized))
|
||||||
|
s.write(fmt.Sprintf("STATUS - KEY PATH: %v\n", keyStatus.Path))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -151,8 +151,8 @@ func (cs *CommandSet) OpenSecureChannel() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *CommandSet) GetStatus() (*types.ApplicationStatus, error) {
|
func (cs *CommandSet) GetStatus(info uint8) (*types.ApplicationStatus, error) {
|
||||||
cmd := NewCommandGetStatusApplication()
|
cmd := NewCommandGetStatus(info)
|
||||||
resp, err := cs.sc.Send(cmd)
|
resp, err := cs.sc.Send(cmd)
|
||||||
if err = cs.checkOK(resp, err); err != nil {
|
if err = cs.checkOK(resp, err); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -161,6 +161,14 @@ func (cs *CommandSet) GetStatus() (*types.ApplicationStatus, error) {
|
|||||||
return types.ParseApplicationStatus(resp.Data)
|
return types.ParseApplicationStatus(resp.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cs *CommandSet) GetStatusApplication() (*types.ApplicationStatus, error) {
|
||||||
|
return cs.GetStatus(P1GetStatusApplication)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cs *CommandSet) GetStatusKeyPath() (*types.ApplicationStatus, error) {
|
||||||
|
return cs.GetStatus(P1GetStatusKeyPath)
|
||||||
|
}
|
||||||
|
|
||||||
func (cs *CommandSet) VerifyPIN(pin string) error {
|
func (cs *CommandSet) VerifyPIN(pin string) error {
|
||||||
cmd := NewCommandVerifyPIN(pin)
|
cmd := NewCommandVerifyPIN(pin)
|
||||||
resp, err := cs.sc.Send(cmd)
|
resp, err := cs.sc.Send(cmd)
|
||||||
|
@ -90,14 +90,6 @@ func NewCommandGetStatus(p1 uint8) *apdu.Command {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCommandGetStatusApplication() *apdu.Command {
|
|
||||||
return NewCommandGetStatus(P1GetStatusApplication)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCommandGetStatusKeyPath() *apdu.Command {
|
|
||||||
return NewCommandGetStatus(P1GetStatusKeyPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewCommandGenerateKey() *apdu.Command {
|
func NewCommandGenerateKey() *apdu.Command {
|
||||||
return apdu.NewCommand(
|
return apdu.NewCommand(
|
||||||
globalplatform.ClaGp,
|
globalplatform.ClaGp,
|
||||||
|
@ -2,27 +2,33 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/status-im/keycard-go/apdu"
|
"github.com/status-im/keycard-go/apdu"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const hardenedStart = 0x80000000 // 2^31
|
||||||
|
|
||||||
var ErrApplicationStatusTemplateNotFound = errors.New("application status template not found")
|
var ErrApplicationStatusTemplateNotFound = errors.New("application status template not found")
|
||||||
|
|
||||||
type ApplicationStatus struct {
|
type ApplicationStatus struct {
|
||||||
PinRetryCount int
|
PinRetryCount int
|
||||||
PUKRetryCount int
|
PUKRetryCount int
|
||||||
KeyInitialized bool
|
KeyInitialized bool
|
||||||
|
Path string
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseApplicationStatus(data []byte) (*ApplicationStatus, error) {
|
func ParseApplicationStatus(data []byte) (*ApplicationStatus, error) {
|
||||||
appStatus := &ApplicationStatus{}
|
|
||||||
|
|
||||||
tpl, err := apdu.FindTag(data, TagApplicationStatusTemplate)
|
tpl, err := apdu.FindTag(data, TagApplicationStatusTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrApplicationStatusTemplateNotFound
|
return parseKeyPathStatus(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
appStatus := &ApplicationStatus{}
|
||||||
|
|
||||||
if pinRetryCount, err := apdu.FindTag(tpl, uint8(0x02)); err == nil && len(pinRetryCount) == 1 {
|
if pinRetryCount, err := apdu.FindTag(tpl, uint8(0x02)); err == nil && len(pinRetryCount) == 1 {
|
||||||
appStatus.PinRetryCount = int(pinRetryCount[0])
|
appStatus.PinRetryCount = int(pinRetryCount[0])
|
||||||
}
|
}
|
||||||
@ -39,3 +45,27 @@ func ParseApplicationStatus(data []byte) (*ApplicationStatus, error) {
|
|||||||
|
|
||||||
return appStatus, nil
|
return appStatus, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseKeyPathStatus(data []byte) (*ApplicationStatus, error) {
|
||||||
|
appStatus := &ApplicationStatus{}
|
||||||
|
buf := bytes.NewBuffer(data)
|
||||||
|
rawPath := make([]uint32, buf.Len()/4)
|
||||||
|
err := binary.Read(buf, binary.BigEndian, &rawPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
segments := []string{"m"}
|
||||||
|
for _, i := range rawPath {
|
||||||
|
suffix := ""
|
||||||
|
if i >= hardenedStart {
|
||||||
|
i = i - hardenedStart
|
||||||
|
suffix = "'"
|
||||||
|
}
|
||||||
|
segments = append(segments, fmt.Sprintf("%d%s", i, suffix))
|
||||||
|
}
|
||||||
|
|
||||||
|
appStatus.Path = strings.Join(segments, "/")
|
||||||
|
|
||||||
|
return appStatus, nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user