mirror of
https://github.com/status-im/keycard-go.git
synced 2025-01-10 03:45:48 +00:00
110 lines
2.1 KiB
Go
110 lines
2.1 KiB
Go
package keycard
|
|
|
|
import (
|
|
"github.com/status-im/keycard-go/apdu"
|
|
"github.com/status-im/keycard-go/globalplatform"
|
|
)
|
|
|
|
const (
|
|
InsInit = uint8(0xFE)
|
|
InsOpenSecureChannel = uint8(0x10)
|
|
InsMutuallyAuthenticate = uint8(0x11)
|
|
InsPair = uint8(0x12)
|
|
InsGetStatus = uint8(0xF2)
|
|
InsGenerateKey = uint8(0xD4)
|
|
InsVerifyPIN = uint8(0x20)
|
|
|
|
P1PairingFirstStep = uint8(0x00)
|
|
P1PairingFinalStep = uint8(0x01)
|
|
P1GetStatusApplication = uint8(0x00)
|
|
P1GetStatusKeyPath = uint8(0x01)
|
|
)
|
|
|
|
func NewCommandInit(data []byte) *apdu.Command {
|
|
return apdu.NewCommand(
|
|
globalplatform.ClaGp,
|
|
InsInit,
|
|
uint8(0x00),
|
|
uint8(0x00),
|
|
data,
|
|
)
|
|
}
|
|
|
|
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,
|
|
)
|
|
}
|
|
|
|
func NewCommandMutuallyAuthenticate(data []byte) *apdu.Command {
|
|
return apdu.NewCommand(
|
|
globalplatform.ClaGp,
|
|
InsMutuallyAuthenticate,
|
|
uint8(0x00),
|
|
uint8(0x00),
|
|
data,
|
|
)
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
func NewCommandGenerateKey() *apdu.Command {
|
|
return apdu.NewCommand(
|
|
globalplatform.ClaGp,
|
|
InsGenerateKey,
|
|
uint8(0),
|
|
uint8(0),
|
|
[]byte{},
|
|
)
|
|
}
|
|
|
|
func NewCommandVerifyPIN(pin string) *apdu.Command {
|
|
return apdu.NewCommand(
|
|
globalplatform.ClaGp,
|
|
InsVerifyPIN,
|
|
uint8(0),
|
|
uint8(0),
|
|
[]byte(pin),
|
|
)
|
|
}
|