2019-03-11 10:05:28 +00:00
|
|
|
package keycard
|
2018-10-22 17:33:53 +00:00
|
|
|
|
|
|
|
import (
|
2019-03-01 17:44:07 +00:00
|
|
|
"github.com/status-im/keycard-go/apdu"
|
|
|
|
"github.com/status-im/keycard-go/globalplatform"
|
2018-10-22 17:33:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2018-11-06 17:38:13 +00:00
|
|
|
InsInit = uint8(0xFE)
|
|
|
|
InsOpenSecureChannel = uint8(0x10)
|
|
|
|
InsMutuallyAuthenticate = uint8(0x11)
|
|
|
|
InsPair = uint8(0x12)
|
2018-11-07 13:39:58 +00:00
|
|
|
InsGetStatus = uint8(0xF2)
|
2018-10-23 10:06:00 +00:00
|
|
|
|
2019-03-11 11:24:09 +00:00
|
|
|
//TODO: remove
|
2018-10-24 11:42:00 +00:00
|
|
|
TagSelectResponsePreInitialized = uint8(0x80)
|
2018-11-07 13:39:58 +00:00
|
|
|
TagApplicationStatusTemplate = uint8(0xA3)
|
2018-10-24 11:42:00 +00:00
|
|
|
TagApplicationInfoTemplate = uint8(0xA4)
|
2018-10-24 16:16:14 +00:00
|
|
|
|
2018-11-07 13:39:58 +00:00
|
|
|
P1PairingFirstStep = uint8(0x00)
|
|
|
|
P1PairingFinalStep = uint8(0x01)
|
|
|
|
P1GetStatusApplication = uint8(0x00)
|
|
|
|
P1GetStatusKeyPath = uint8(0x01)
|
2018-10-22 17:33:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewCommandInit(data []byte) *apdu.Command {
|
|
|
|
return apdu.NewCommand(
|
|
|
|
globalplatform.ClaGp,
|
|
|
|
InsInit,
|
|
|
|
uint8(0x00),
|
|
|
|
uint8(0x00),
|
|
|
|
data,
|
|
|
|
)
|
|
|
|
}
|
2018-10-24 16:16:14 +00:00
|
|
|
|
|
|
|
func NewCommandPairFirstStep(challenge []byte) *apdu.Command {
|
|
|
|
return apdu.NewCommand(
|
|
|
|
globalplatform.ClaGp,
|
|
|
|
InsPair,
|
|
|
|
P1PairingFirstStep,
|
|
|
|
uint8(0x00),
|
|
|
|
challenge,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCommandPairFinalStep(cryptogramHash []byte) *apdu.Command {
|
|
|
|
return apdu.NewCommand(
|
|
|
|
globalplatform.ClaGp,
|
|
|
|
InsPair,
|
|
|
|
P1PairingFinalStep,
|
|
|
|
uint8(0x00),
|
|
|
|
cryptogramHash,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCommandOpenSecureChannel(pairingIndex uint8, pubKey []byte) *apdu.Command {
|
|
|
|
return apdu.NewCommand(
|
|
|
|
globalplatform.ClaGp,
|
|
|
|
InsOpenSecureChannel,
|
|
|
|
pairingIndex,
|
|
|
|
uint8(0x00),
|
|
|
|
pubKey,
|
|
|
|
)
|
|
|
|
}
|
2018-11-06 17:38:13 +00:00
|
|
|
|
|
|
|
func NewCommandMutuallyAuthenticate(data []byte) *apdu.Command {
|
|
|
|
return apdu.NewCommand(
|
|
|
|
globalplatform.ClaGp,
|
|
|
|
InsMutuallyAuthenticate,
|
|
|
|
uint8(0x00),
|
|
|
|
uint8(0x00),
|
|
|
|
data,
|
|
|
|
)
|
|
|
|
}
|
2018-11-07 13:39:58 +00:00
|
|
|
|
|
|
|
func NewCommandGetStatus(p1 uint8) *apdu.Command {
|
|
|
|
return apdu.NewCommand(
|
|
|
|
globalplatform.ClaGp,
|
|
|
|
InsGetStatus,
|
|
|
|
p1,
|
|
|
|
uint8(0x00),
|
|
|
|
[]byte{},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCommandGetStatusApplication() *apdu.Command {
|
|
|
|
return NewCommandGetStatus(P1GetStatusApplication)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCommandGetStatusKeyPath() *apdu.Command {
|
|
|
|
return NewCommandGetStatus(P1GetStatusKeyPath)
|
|
|
|
}
|