add install for load command

This commit is contained in:
Andrea Franz 2018-10-02 17:15:17 +02:00
parent f718e4accc
commit 48ad7291b4
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
2 changed files with 33 additions and 0 deletions

View File

@ -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...)

View File

@ -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))
}