From 48ad7291b4abfff0ed24cd82b3bf0b3983f782cf Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Tue, 2 Oct 2018 17:15:17 +0200 Subject: [PATCH] add install for load command --- globalplatform/commands.go | 20 ++++++++++++++++++++ globalplatform/commands_test.go | 13 +++++++++++++ 2 files changed, 33 insertions(+) diff --git a/globalplatform/commands.go b/globalplatform/commands.go index 7236074..d50ea80 100644 --- a/globalplatform/commands.go +++ b/globalplatform/commands.go @@ -15,6 +15,9 @@ const ( InsExternalAuthenticate = uint8(0x82) InsGetResponse = uint8(0xC0) InsDelete = uint8(0xE4) + InsInstall = uint8(0xE6) + + P1InstallForLoad = uint8(0x02) Sw1ResponseDataIncomplete = uint8(0x61) @@ -92,6 +95,23 @@ func NewCommandDelete(aid []byte) *apdu.Command { ) } +func NewCommandInstallForLoad(aid, sdaid []byte) *apdu.Command { + data := []byte{byte(len(aid))} + data = append(data, aid...) + data = append(data, byte(len(sdaid))) + data = append(data, sdaid...) + // empty hash length and hash + data = append(data, []byte{0x00, 0x00, 0x00}...) + + return apdu.NewCommand( + ClaGp, + InsInstall, + P1InstallForLoad, + uint8(0x00), + data, + ) +} + func calculateHostCryptogram(encKey, cardChallenge, hostChallenge []byte) ([]byte, error) { var data []byte data = append(data, cardChallenge...) diff --git a/globalplatform/commands_test.go b/globalplatform/commands_test.go index 97803f6..1952278 100644 --- a/globalplatform/commands_test.go +++ b/globalplatform/commands_test.go @@ -65,3 +65,16 @@ func TestNewCommandDelete(t *testing.T) { expected := "4F050102030405" assert.Equal(t, expected, hexutils.BytesToHex(cmd.Data)) } + +func TestNewCommandInstallForLoad(t *testing.T) { + aid := hexutils.HexToBytes("53746174757357616C6C6574") + sdaid := hexutils.HexToBytes("A000000151000000") + cmd := NewCommandInstallForLoad(aid, sdaid) + assert.Equal(t, uint8(0x80), cmd.Cla) + assert.Equal(t, uint8(0xE6), cmd.Ins) + assert.Equal(t, uint8(0x02), cmd.P1) + assert.Equal(t, uint8(0x00), cmd.P2) + + expected := "0C53746174757357616C6C657408A000000151000000000000" + assert.Equal(t, expected, hexutils.BytesToHex(cmd.Data)) +}