mirror of
https://github.com/status-im/keycard-go.git
synced 2025-01-22 17:59:35 +00:00
add docs to commands
This commit is contained in:
parent
7538feac95
commit
d5c83615d6
@ -8,11 +8,13 @@ import (
|
|||||||
"github.com/status-im/status-go/smartcard/globalplatform/crypto"
|
"github.com/status-im/status-go/smartcard/globalplatform/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// APDUWrapper is a wrapper for apdu commands inside a global platform secure channel.
|
||||||
type APDUWrapper struct {
|
type APDUWrapper struct {
|
||||||
macKey []byte
|
macKey []byte
|
||||||
icv []byte
|
icv []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewAPDUWrapper returns a new APDUWrapper using the specified key for MAC generation.
|
||||||
func NewAPDUWrapper(macKey []byte) *APDUWrapper {
|
func NewAPDUWrapper(macKey []byte) *APDUWrapper {
|
||||||
return &APDUWrapper{
|
return &APDUWrapper{
|
||||||
macKey: macKey,
|
macKey: macKey,
|
||||||
@ -20,6 +22,8 @@ func NewAPDUWrapper(macKey []byte) *APDUWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wrap wraps the apdu command adding the MAC to the end of the command.
|
||||||
|
// Future implementations will encrypt the message when needed.
|
||||||
func (w *APDUWrapper) Wrap(cmd *apdu.Command) (*apdu.Command, error) {
|
func (w *APDUWrapper) Wrap(cmd *apdu.Command) (*apdu.Command, error) {
|
||||||
macData := new(bytes.Buffer)
|
macData := new(bytes.Buffer)
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/status-im/status-go/smartcard/globalplatform/crypto"
|
"github.com/status-im/status-go/smartcard/globalplatform/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Constants used in apdu commands and responses as defined by iso7816 and globalplatform.
|
||||||
const (
|
const (
|
||||||
ClaISO7816 = uint8(0x00)
|
ClaISO7816 = uint8(0x00)
|
||||||
ClaGp = uint8(0x80)
|
ClaGp = uint8(0x80)
|
||||||
@ -44,6 +45,7 @@ const (
|
|||||||
tagGetStatusAID = byte(0x4F)
|
tagGetStatusAID = byte(0x4F)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewCommandSelect returns a Select command as defined in the globalplatform specifications.
|
||||||
func NewCommandSelect(aid []byte) *apdu.Command {
|
func NewCommandSelect(aid []byte) *apdu.Command {
|
||||||
c := apdu.NewCommand(
|
c := apdu.NewCommand(
|
||||||
ClaISO7816,
|
ClaISO7816,
|
||||||
@ -60,6 +62,7 @@ func NewCommandSelect(aid []byte) *apdu.Command {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCommandSelect returns an Initialize Update command as defined in the globalplatform specifications.
|
||||||
func NewCommandInitializeUpdate(challenge []byte) *apdu.Command {
|
func NewCommandInitializeUpdate(challenge []byte) *apdu.Command {
|
||||||
c := apdu.NewCommand(
|
c := apdu.NewCommand(
|
||||||
ClaGp,
|
ClaGp,
|
||||||
@ -76,6 +79,7 @@ func NewCommandInitializeUpdate(challenge []byte) *apdu.Command {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCommandSelect returns an External Authenticate command as defined in the globalplatform specifications.
|
||||||
func NewCommandExternalAuthenticate(encKey, cardChallenge, hostChallenge []byte) (*apdu.Command, error) {
|
func NewCommandExternalAuthenticate(encKey, cardChallenge, hostChallenge []byte) (*apdu.Command, error) {
|
||||||
hostCryptogram, err := calculateHostCryptogram(encKey, cardChallenge, hostChallenge)
|
hostCryptogram, err := calculateHostCryptogram(encKey, cardChallenge, hostChallenge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -91,6 +95,7 @@ func NewCommandExternalAuthenticate(encKey, cardChallenge, hostChallenge []byte)
|
|||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCommandSelect returns a Get Response command as defined in the globalplatform specifications.
|
||||||
func NewCommandGetResponse(length uint8) *apdu.Command {
|
func NewCommandGetResponse(length uint8) *apdu.Command {
|
||||||
c := apdu.NewCommand(
|
c := apdu.NewCommand(
|
||||||
ClaISO7816,
|
ClaISO7816,
|
||||||
@ -105,6 +110,7 @@ func NewCommandGetResponse(length uint8) *apdu.Command {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCommandSelect returns a Delete command as defined in the globalplatform specifications.
|
||||||
func NewCommandDelete(aid []byte) *apdu.Command {
|
func NewCommandDelete(aid []byte) *apdu.Command {
|
||||||
data := []byte{tagDeleteAID, byte(len(aid))}
|
data := []byte{tagDeleteAID, byte(len(aid))}
|
||||||
data = append(data, aid...)
|
data = append(data, aid...)
|
||||||
@ -118,6 +124,7 @@ func NewCommandDelete(aid []byte) *apdu.Command {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCommandSelect returns an Install command with the install-for-load parameter as defined in the globalplatform specifications.
|
||||||
func NewCommandInstallForLoad(aid, sdaid []byte) *apdu.Command {
|
func NewCommandInstallForLoad(aid, sdaid []byte) *apdu.Command {
|
||||||
data := []byte{byte(len(aid))}
|
data := []byte{byte(len(aid))}
|
||||||
data = append(data, aid...)
|
data = append(data, aid...)
|
||||||
@ -135,6 +142,7 @@ func NewCommandInstallForLoad(aid, sdaid []byte) *apdu.Command {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCommandSelect returns an Install command with the install-for-instalp parameter as defined in the globalplatform specifications.
|
||||||
func NewCommandInstallForInstall(pkgAID, appletAID, instanceAID, params []byte) *apdu.Command {
|
func NewCommandInstallForInstall(pkgAID, appletAID, instanceAID, params []byte) *apdu.Command {
|
||||||
data := []byte{byte(len(pkgAID))}
|
data := []byte{byte(len(pkgAID))}
|
||||||
data = append(data, pkgAID...)
|
data = append(data, pkgAID...)
|
||||||
@ -167,6 +175,7 @@ func NewCommandInstallForInstall(pkgAID, appletAID, instanceAID, params []byte)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCommandSelect returns a Get Status command as defined in the globalplatform specifications.
|
||||||
func NewCommandGetStatus(aid []byte, p1 uint8) *apdu.Command {
|
func NewCommandGetStatus(aid []byte, p1 uint8) *apdu.Command {
|
||||||
data := []byte{tagGetStatusAID}
|
data := []byte{tagGetStatusAID}
|
||||||
data = append(data, byte(len(aid)))
|
data = append(data, byte(len(aid)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user