02-权限测试.txt 9.27 KB
//内部认证
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