-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsm_pcsc_op.go
47 lines (42 loc) · 1.13 KB
/
gsm_pcsc_op.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package usim_go
import (
"encoding/hex"
"errors"
smartcard "github.com/sf1/go-card/smartcard"
"github.com/sirupsen/logrus"
)
func GSMAlg(ctx *smartcard.Card, simType int, rand []byte) (sres, kc []byte, err error) {
var resp []byte
var cmd []byte
var getResp []byte
cmd = SIM_CMD_RUN_GSM_ALG
// cmd = append(cmd, byte(16))
cmd = append(cmd, rand...)
getResp = append(getResp, SIM_CMD_GET_RESPONSE...)
// choose GSM_DF
_select_file(ctx, SCARD_FILE_GSM_DF, SCARD_GSM_SIM, nil)
logrus.Debug("Sending command:\n", hex.Dump(cmd))
if resp, err = ctx.Transmit(cmd); err != nil {
errStr := "GSMAlg: sending command failed"
logrus.Error(errStr)
return
}
logrus.Debug("Got response:\n", hex.Dump(resp))
if resp[0] != 0x9F {
errStr := "GSMAlg: run alg failed"
logrus.Error(errStr)
return
}
getResp = append(getResp, resp[1])
logrus.Debug("Sending command:\n", hex.Dump(getResp))
if resp, err = ctx.Transmit(getResp); err != nil {
errStr := "reading response failed"
logrus.Error(errStr, err)
err = errors.New(errStr)
return
}
logrus.Debug("Got response: \n", hex.Dump(resp))
sres = resp[0:4]
kc = resp[4:12]
return
}