keycard-go/globalplatform/apdu_wrapper_test.go

44 lines
1.3 KiB
Go
Raw Normal View History

2018-09-27 16:01:09 +00:00
package globalplatform
import (
"testing"
"github.com/status-im/status-go/smartcard/apdu"
"github.com/status-im/status-go/smartcard/globalplatform/crypto"
"github.com/status-im/status-go/smartcard/hexutils"
"github.com/stretchr/testify/assert"
)
func TestAPDUWrapper_Wrap(t *testing.T) {
macKey := hexutils.HexToBytes("2983BA77D709C2DAA1E6000ABCCAC951")
2018-09-28 09:25:08 +00:00
w := NewAPDUWrapper(macKey)
2018-09-27 16:01:09 +00:00
2018-09-28 09:25:08 +00:00
data := hexutils.HexToBytes("1d4de92eaf7a2c9f")
2018-09-27 16:01:09 +00:00
cmd := apdu.NewCommand(uint8(0x80), uint8(0x82), uint8(0x01), uint8(0x00), data)
2018-09-28 09:25:08 +00:00
// check initial icv
2018-09-27 16:01:09 +00:00
assert.Equal(t, crypto.NullBytes8, w.icv)
wrappedCmd, err := w.Wrap(cmd)
assert.NoError(t, err)
raw, err := wrappedCmd.Serialize()
assert.NoError(t, err)
expected := "84 82 01 00 10 1D 4D E9 2E AF 7A 2C 9F 8F 9B 0D F6 81 C1 D3 EC"
assert.Equal(t, expected, hexutils.BytesToHexWithSpaces(raw))
2018-09-28 09:25:08 +00:00
// check icv generated from previous mac
assert.Equal(t, "8F9B0DF681C1D3EC", hexutils.BytesToHex(w.icv))
data = hexutils.HexToBytes("4F00")
cmd = apdu.NewCommand(uint8(0x80), uint8(0xF2), uint8(0x80), uint8(0x02), data)
cmd.SetLe(0x00)
wrappedCmd, err = w.Wrap(cmd)
assert.NoError(t, err)
raw, err = wrappedCmd.Serialize()
assert.NoError(t, err)
expected = "84 F2 80 02 0A 4F 00 30 F1 49 20 9E 17 B3 97 00"
assert.Equal(t, expected, hexutils.BytesToHexWithSpaces(raw))
2018-09-27 16:01:09 +00:00
}