keycard-go/globalplatform/scp02_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"
2019-03-01 17:44:07 +00:00
"github.com/status-im/keycard-go/apdu"
"github.com/status-im/keycard-go/globalplatform/crypto"
"github.com/status-im/keycard-go/hexutils"
2018-09-27 16:01:09 +00:00
"github.com/stretchr/testify/assert"
)
2019-03-05 11:00:23 +00:00
func TestSCP02Wrapper_Wrap(t *testing.T) {
2018-09-27 16:01:09 +00:00
macKey := hexutils.HexToBytes("2983BA77D709C2DAA1E6000ABCCAC951")
2019-03-05 11:00:23 +00:00
w := NewSCP02Wrapper(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
}