fix set pinless path command

This commit is contained in:
Andrea Franz 2019-04-09 10:25:56 +02:00
parent 9d5e996d49
commit 6a75e43732
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
2 changed files with 33 additions and 15 deletions

View File

@ -237,7 +237,7 @@ func (cs *CommandSet) DeriveKey(path string) error {
}
func (cs *CommandSet) SetPinlessPath(path string) error {
cmd, err := NewCommandDeriveKey(path)
cmd, err := NewCommandSetPinlessPath(path)
if err != nil {
return err
}
@ -247,7 +247,21 @@ func (cs *CommandSet) SetPinlessPath(path string) error {
}
func (cs *CommandSet) Sign(data []byte) (*types.Signature, error) {
cmd, err := NewCommandSign(data)
cmd, err := NewCommandSign(data, P1SignCurrentKey)
if err != nil {
return nil, err
}
resp, err := cs.sc.Send(cmd)
if err = cs.checkOK(resp, err); err != nil {
return nil, err
}
return types.ParseSignature(data, resp.Data)
}
func (cs *CommandSet) SignPinless(data []byte) (*types.Signature, error) {
cmd, err := NewCommandSign(data, P1SignPinless)
if err != nil {
return nil, err
}

View File

@ -25,16 +25,20 @@ const (
InsSign = 0xC0
InsSetPinlessPath = 0xC1
P1PairingFirstStep = 0x00
P1PairingFinalStep = 0x01
P1GetStatusApplication = 0x00
P1GetStatusKeyPath = 0x01
P1DeriveKeyFromMaster = 0x00
P1DeriveKeyFromParent = 0x01
P1DeriveKeyFromCurrent = 0x10
P1ChangePinPIN = 0x00
P1ChangePinPUK = 0x01
P1ChangePinPairingSecret = 0x02
P1PairingFirstStep = 0x00
P1PairingFinalStep = 0x01
P1GetStatusApplication = 0x00
P1GetStatusKeyPath = 0x01
P1DeriveKeyFromMaster = 0x00
P1DeriveKeyFromParent = 0x01
P1DeriveKeyFromCurrent = 0x10
P1ChangePinPIN = 0x00
P1ChangePinPUK = 0x01
P1ChangePinPairingSecret = 0x02
P1SignCurrentKey = 0x00
P1SignDerive = 0x01
P1SignDeriveAndMakeCurrent = 0x02
P1SignPinless = 0x03
SwNoAvailablePairingSlots = 0x6A84
)
@ -209,7 +213,7 @@ func NewCommandSetPinlessPath(pathStr string) (*apdu.Command, error) {
return nil, err
}
if startingPoint != derivationpath.StartingPointMaster {
if len(path) > 0 && startingPoint != derivationpath.StartingPointMaster {
return nil, fmt.Errorf("pinless path must be set with an absolute path")
}
@ -229,7 +233,7 @@ func NewCommandSetPinlessPath(pathStr string) (*apdu.Command, error) {
), nil
}
func NewCommandSign(data []byte) (*apdu.Command, error) {
func NewCommandSign(data []byte, p1 uint8) (*apdu.Command, error) {
if len(data) != 32 {
return nil, fmt.Errorf("data length must be 32, got %d", len(data))
}
@ -237,7 +241,7 @@ func NewCommandSign(data []byte) (*apdu.Command, error) {
return apdu.NewCommand(
globalplatform.ClaGp,
InsSign,
0,
p1,
0,
data,
), nil