02-权限测试.txt
9.27 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//内部认证
reset
call sendcmd(00 A4 04 00 10 D6C7D0C5C8DAB4B4D4B0C7F8D3A6D3C3)
call sendcmd(0088 0001 08 1122334455667788)
call sendcmd(0088 0002 08 1122334455667788)
call sendcmd(0088 0003 08 1122334455667788)
//MF下密钥更新测试
reset
call sendcmd(00 A4 04 00 10 D6C7D0C5C8DAB4B4D4B0C7F8D3A6D3C3)
message "密文+MAC更新维护密钥3602"
call WriteKey(0202,1536F0F03301 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF55,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0)
//MF下读写权限测试
//明文更新DIR
call sendcmd(00DC 010C 32 70 30 61164F08B5D8C0FBD4DACFDF500A11111111111111111111 61164F08B5D8C0FBC7AEB0FC500A22222222222222222222,6982)
call sendcmd(00B2 010C 00)
//明文更新0005
call sendcmd(00D6 8500 18 888870000001 313030303031FFFF 38383838FFFFFFFFFFFF,6982)
call sendcmd(00B0 8500 00)
//明文更新0006
call sendcmd(00D6 8600 18 888870000001 313030303031FFFF 38383838FFFFFFFFFFFF,6982)
call sendcmd(00B0 8600 00)
//dcmk2更新0001/0005
set cipherkey = FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF55
call WriteEF(04DC 010C,703061164F08B5D8C0FBD4DACFDF500A11111111111111111122 61164F08B5D8C0FBC7AEB0FC500A22222222222222222233,6988)
call WriteEF(04D6 8500,888870000001 313030303031FFFF 38383838FFFFFFFFFFFF,6988)
//dcmk1更新0006
set cipherkey = FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4
call WriteEF(04D6 8600,888870000001 313030303031FFFF 38383838FFFFFFFFFFFF,6988)
//dcmk1更新0001/0005
set cipherkey = FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4
call WriteEF(04DC 010C,703061164F08B5D8C0FBD4DACFDF500A11111111111111111122 61164F08B5D8C0FBC7AEB0FC500A22222222222222222233)
call WriteEF(04D6 8500,888870000001 313030303031FFFF 38383838FFFFFFFFFFFF)
//dcmk1更新0002
set cipherkey = FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF55
call WriteEF(04D6 8600,888870000001 313030303031FFFF 38383838FFFFFFFFFFFF)
//不支持单独删除DF01
//不满足权限读0015
call sendcmd(00A4 0400 08 B5D8C0FBD4DACFDF)
message "密文+MAC更新维护密钥3602"
call WriteKey(0202,1536F0F03301 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF99,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6)
call sendcmd(00B0 9500 00,6982)
call sendcmd(00B0 9600 00)
call sendcmd(00B2 01CC 00,6A83)
//明文更新15文件
call WriteEF(00D6 9500,888870000001 313030303031FFFF 38383838FFFFFFFFFFFF,6982)
//明文更新16文件
call WriteEF(00D6 9600,888870000001 313030303031FFFF 38383838FFFFFFFFFFFF,6982)
//明文更新19文件
call WriteEF(00E2 00C8,0110112233445566778899AABBCCDDEEFF00,6982)
//DAMK2更新15
set cipherkey = FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF99
call WriteEF(04D6 9500,888870000001 313030303031FFFF 38383838FFFFFFFFFFFF,6988)
//DAMK1更新16
set cipherkey = FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8
call WriteEF(04D6 9600,888870000001 313030303031FFFF 38383838FFFFFFFFFFFF,6988)
//DAMK1更新19
call WriteEF(04E2 00C8,0110112233445566778899AABBCCDDEEFF00,6988)
//DAMK1更新15
set cipherkey = FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8
call WriteEF(04D6 9500,888870000001 313030303031FFFF 38383838FFFFFFFFFFFF)
//DAMK2更新16
set cipherkey = FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF99
call WriteEF(04D6 9600,888870000001 313030303031FFFF 38383838FFFFFFFFFFFF)
//DAMK2更新19
call WriteEF(04E2 00C8,0110112233445566778899AABBCCDDEEFF00)
call sendcmd(00B2 01CC 00)
//外部认证
call ExternAuth(01,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7)
call sendcmd(00B0 9500 00)
call sendcmd(00B0 9600 00)
End
sendcmd:
prompt off
cmd = getpara()
expect = getpara()
expectlen = datalen($expect)
prompt on
sendtext $cmd
prompt off
set result[0]
prompt on
if $expectlen==0000
if sw != 9000
message"发送指令失败,预期返回:9000,实际返回:" $sw
pause
endif
else if $expectlen==0002
if sw != $expect
message"返回数据与预期不一致,预期返回:" $expect "实际返回:" $sw
pause
endif
else
prompt off
expectlen = sub($expectlen,02)
expectdata = hleft($expect,$expectlen)
expectsw = right($expect,02)
prompt on
if $result[0] != $expectdata
message"返回数据与预期不一致,预期返回:" $expectdata "实际返回:" $result[0]
pause
endif
if sw != $expectsw
message"返回数据与预期不一致,预期返回:" $expectsw "实际返回:" $sw
pause
endif
endif
return
ExternAuth:
keyid= getpara()
key = getpara()
00 84 00 00 04
set rand
res = 3des_encode_ecb($rand, $key)
0082 00 $keyid 08 $res
if sw != 9000
message"外部认证失败"
pause
endif
return
WriteKey:
P1P2 = getpara()
dat = getpara()
Key = getpara()
set cipherkey = $Key
dat = 3des_encode_ecb($dat, $Key)
0084 0000 04
set rand
des_3des_mac 84d4 $P1P2 <$dat>
if sw != 9000
message "主控密钥保护下,密文+MAC更新密钥失败"
pause
endif
return
WriteEF:
prompt off
ApduTemp = getpara()
data[0] = getpara()
expect = getpara()
expectlen = datalen($expect)
prompt on
00 84 00 00 04
set rand
des_3des_mac $ApduTemp < $data[0] >
if $expectlen==0000
if sw != 9000
message"发送指令失败,未能成功返回9000"
pause
endif
else if sw != $expect
message "写EF文件失败,未能成功返回预期值"
pause
endif
return