二次发卡.txt 11.5 KB
clear string
edit Hstring $SW$
edit Hstring $RandomSESLK$;计算会话密钥的Random
edit Hstring  $INPUTData$
edit Hstring  $Random$
edit Hstring  $Key$
edit  Hstring $DESKey$
edit  Hstring $DESResult$
edit  Hstring $mw$ 
edit  Hstring $mkey$
edit  Hstring $tkey$
edit  Hstring $MACInit$
edit  Hstring $MAC$
edit  Hstring $INPUT$
edit  Hstring $Temp$
edit  Hstring $DCCK$
edit  Hstring $DIRK1$
edit  Hstring $DIRK2$
edit  Hstring $DIRK3$
edit  Hstring $DCMK1$
edit  Hstring $DCMK2$
edit  Hstring $DACK$
edit  Hstring $DEAK$
edit  Hstring $DAMK1$
edit  Hstring $DAMK2$
edit  Hstring $DACK2$
edit  Hstring $0001$
edit  Hstring $0005$
edit  Hstring $0006$
edit  Hstring $0015$
edit  Hstring $0016$
edit  Hstring $0019$

RESET 

SEND 00A4000002 3F00
ASSERT 6F148410D6C7D0C5C8DAB4B4D4B0C7F8D3A6D3C3A5009000

SEND 0084000008
edit  $Random$=g_GETSW()
watch $Random$
;3-DES           
edit  $DESKey$ = FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0

edit  $Random$ = g_GETSTR($Random$,0,8)
watch $Random$
edit  $DESResult$ = g_TDES(1 , $DESKey$ , $Random$)	
watch $DESResult$
send 0082000008  $DESResult$
assert 9000

;###################################################################################################
;###                        MF密钥替换
;###################################################################################################

edit $DCCK$ = 	FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0
edit $DACK$ = 	FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6
edit $DIRK1$ = 	11111111111111111111111111111111
edit $DIRK2$ = 	22222222222222222222222222222222
edit $DIRK3$ = 	33333333333333333333333333333333
edit $DCMK1$ = 	FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4
edit $DCMK2$ = 	22222222222222222222222222222222
edit $DEAK$ = 	FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7
edit $DAMK1$ = 	FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8

edit $0005$ = 888870000001100001FFFFFFFFFF8888FFFFFFFFFFFFFFFF721FFFFF88880003195344494C49888800031953
;edit $0005$ = 888800000003100002FFFFFFFFFF8888FFFFFFFFFFFFFFFF721FFFFF88880003195344494C49888800031953FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
;edit $0005$ = 888800000005100003FFFFFFFFFF8888FFFFFFFFFFFFFFFF721FFFFF88880003195344494C49888800031953FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF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FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
edit $0016$ = FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


;主控子密钥 $DCCK$ 
send 00 84 00 00 08
edit  $SW$ = g_GETSW()
edit  $RandomSESLK$ = g_GETSTR($SW$,0,8)	
watch $RandomSESLK$
edit  $Key$ = FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0 

edit  $mkey$=  13  000000 $DCCK$ 80000000
watch $mkey$
edit  $mw$ = g_TDES(1 , $Key$ , $mkey$)	
watch $mw$
edit  $MACInit$ = $RandomSESLK$
edit  $DESKey$= $Key$
edit  $INPUT$   = 84D401001C$mw$  
edit  $MAC$= g_TMAC($MACInit$ , $DESKey$ , $INPUT$)	
watch   $mw$  $MAC$
edit $Temp$ =  $mw$  $MAC$
watch $Temp$
;主控子密钥 $DCCK$ 
SEND 84D401001C $Temp$
ASSERT 9000

;维护子密钥 $DCMK1$ 
send 00 84 00 00 08
edit  $SW$ = g_GETSW()
edit  $RandomSESLK$ = g_GETSTR($SW$,0,8)	
watch $RandomSESLK$

edit  $mkey$=  13  010100 $DCMK1$ 80000000
watch $mkey$
edit  $mw$ = g_TDES(1 , $DCCK$ , $mkey$)	
watch $mw$
edit  $MACInit$ = $RandomSESLK$
edit  $INPUT$   = 84D401101C$mw$
edit  $MAC$= g_TMAC($MACInit$ , $DCCK$ , $INPUT$)	
watch   $mw$  $MAC$
edit $Temp$ =  $mw$  $MAC$
watch $Temp$
;维护子密钥 $DAMK$ 
SEND 84D401101C $Temp$
ASSERT 9000

;维护子密钥 $DCMK2$ 
send 00 84 00 00 08
edit  $SW$ = g_GETSW()
edit  $RandomSESLK$ = g_GETSTR($SW$,0,8)	
watch $RandomSESLK$

edit  $mkey$=  13  010200 $DCMK2$ 80000000
watch $mkey$
edit  $mw$ = g_TDES(1 , $DCCK$ , $mkey$)	
watch $mw$
edit  $MACInit$ = $RandomSESLK$
edit  $INPUT$   = 84D401101C$mw$
edit  $MAC$= g_TMAC($MACInit$ , $DCCK$ , $INPUT$)	
watch   $mw$  $MAC$
edit $Temp$ =  $mw$  $MAC$
watch $Temp$
;维护子密钥 $DAMK$ 
SEND 84D401101C $Temp$
ASSERT 9000

;DIRK1~3
send 00 84 00 00 08
edit  $SW$ = g_GETSW()
edit  $RandomSESLK$ = g_GETSTR($SW$,0,8)	
watch $RandomSESLK$

edit  $mkey$=  13  1C0101 $DIRK1$ 80000000
watch $mkey$
edit  $mw$ = g_TDES(1 , $DCCK$ , $mkey$)	
watch $mw$
edit  $MACInit$ = $RandomSESLK$
edit  $INPUT$   = 84D401101C$mw$
edit  $MAC$= g_TMAC($MACInit$ , $DCCK$ , $INPUT$)	
watch   $mw$  $MAC$
edit $Temp$ =  $mw$  $MAC$
watch $Temp$
;DIRK1~3
SEND 84D401101C $Temp$
ASSERT 9000

;DIRK1~3
send 00 84 00 00 08
edit  $SW$ = g_GETSW()
edit  $RandomSESLK$ = g_GETSTR($SW$,0,8)	
watch $RandomSESLK$

edit  $mkey$=  13  1C0201 $DIRK2$ 80000000
watch $mkey$
edit  $mw$ = g_TDES(1 , $DCCK$ , $mkey$)	
watch $mw$
edit  $MACInit$ = $RandomSESLK$
edit  $INPUT$   = 84D401101C$mw$
edit  $MAC$= g_TMAC($MACInit$ , $DCCK$ , $INPUT$)	
watch   $mw$  $MAC$
edit $Temp$ =  $mw$  $MAC$
watch $Temp$
;DIRK1~3
SEND 84D401101C $Temp$
ASSERT 9000

;DIRK1~3
send 00 84 00 00 08
edit  $SW$ = g_GETSW()
edit  $RandomSESLK$ = g_GETSTR($SW$,0,8)	
watch $RandomSESLK$

edit  $mkey$=  13  1C0301 $DIRK3$ 80000000
watch $mkey$
edit  $mw$ = g_TDES(1 , $DCCK$ , $mkey$)	
watch $mw$
edit  $MACInit$ = $RandomSESLK$
edit  $INPUT$   = 84D401101C$mw$
edit  $MAC$= g_TMAC($MACInit$ , $DCCK$ , $INPUT$)	
watch   $mw$  $MAC$
edit $Temp$ =  $mw$  $MAC$
watch $Temp$
;DIRK1~3
SEND 84D401101C $Temp$
ASSERT 9000

;更新0001 dir文件
;***************************写0001文件*********************************
SEND 0084000008
edit  $SW$ = g_GETSW()
edit  $RandomSESLK$ = g_GETSTR($SW$,0,8)	
watch $RandomSESLK$
edit  $MACInit$ = $RandomSESLK$
edit  $INPUT$   = 04E2000812 700C610A4F08B5D8C0FBD4DACFDF
edit  $MAC$= g_TMAC($MACInit$ , $DCMK1$ , $INPUT$)	
watch $MAC$
SEND $INPUT$ $MAC$
ASSERT 9000

SEND 0084000008
edit  $SW$ = g_GETSW()
edit  $RandomSESLK$ = g_GETSTR($SW$,0,8)	
watch $RandomSESLK$
edit  $MACInit$ = $RandomSESLK$
edit  $INPUT$   = 04E2000812 700C610A5008B5D8C0FBC7AEB0FC
edit  $MAC$= g_TMAC($MACInit$ , $DCMK1$ , $INPUT$)	
watch $MAC$
SEND $INPUT$ $MAC$
ASSERT 9000

;第二次更新时
;SEND 0084000008
;edit  $SW$ = g_GETSW()
;edit  $RandomSESLK$ = g_GETSTR($SW$,0,8)	
;watch $RandomSESLK$
;edit  $MACInit$ = $RandomSESLK$
;edit  $INPUT$   = 04DC010C12 700C610A4F08B5D8C0FBD4DACFDF
;edit  $MAC$= g_TMAC($MACInit$ , $DCMK1$ , $INPUT$)	
;watch $MAC$
;SEND $INPUT$ $MAC$
;ASSERT 9000

;更新0005基本信息文件
;***************************写0005文件*********************************
SEND 0084000008
edit  $SW$ = g_GETSW()
edit  $RandomSESLK$ = g_GETSTR($SW$,0,8)	
watch $RandomSESLK$
edit  $MACInit$ = $RandomSESLK$
edit  $INPUT$   = 04D6850030 $0005$
edit  $MAC$= g_TMAC($MACInit$ , $DCMK1$ , $INPUT$)	
watch $MAC$
SEND $INPUT$ $MAC$
ASSERT 9000
;更新0006预留信息文件
;***************************写0006文件*********************************
SEND 0084000008
edit  $SW$ = g_GETSW()
edit  $RandomSESLK$ = g_GETSTR($SW$,0,8)	
watch $RandomSESLK$
edit  $MACInit$ = $RandomSESLK$
edit  $INPUT$   = 04D6860030 $0006$
edit  $MAC$= g_TMAC($MACInit$ , $DCMK2$ , $INPUT$)	
watch $MAC$
SEND $INPUT$ $MAC$
ASSERT 9000


;内部认证1
SEND 0084000008
edit  $Random$=g_GETSW()
watch $Random$
;3-DES           
edit  $DESKey$ = $DIRK1$

edit  $Random$ = g_GETSTR($Random$,0,8)
watch $Random$
edit  $DESResult$ = g_TDES(1 , $DESKey$ , $Random$)	
watch $DESResult$
send 0088000108  $DESResult$
;ASSERT F643AEEE267B96BE 9000

;内部认证2
SEND 0084000008
edit  $Random$=g_GETSW()
watch $Random$
;3-DES           
edit  $DESKey$ = $DIRK2$

edit  $Random$ = g_GETSTR($Random$,0,8)
watch $Random$
edit  $DESResult$ = g_TDES(1 , $DESKey$ , $Random$)	
watch $DESResult$
send 0088000208  $DESResult$
;ASSERT 2D32365B79BAB9299000

;内部认证3
SEND 0084000008
edit  $Random$=g_GETSW()
watch $Random$
;3-DES           
edit  $DESKey$ = $DIRK3$

edit  $Random$ = g_GETSTR($Random$,0,8)
watch $Random$
edit  $DESResult$ = g_TDES(1 , $DESKey$ , $Random$)	
watch $DESResult$
send 0088000308  $DESResult$
;ASSERT 60833056F73E2A249000

;DF01:地利在线平台应用
SEND 00A40400 08 B5D8C0FBD4DACFDF
ASSERT 6F7F8410B5D8C0FBD4DACFDF0000007479617070A56B9F0801029F0C64FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9000

SEND 0084000008
edit  $Random$=g_GETSW()
watch $Random$
;3-DES           
edit  $DESKey$ = $DACK$

edit  $Random$ = g_GETSTR($Random$,0,8)
watch $Random$
edit  $DESResult$ = g_TDES(1 , $DESKey$ , $Random$)	
watch $DESResult$
send 0082000008  $DESResult$
assert 9000


;外部认证密钥 $DEAK$ 
send 00 84 00 00 08
edit  $SW$ = g_GETSW()
edit  $RandomSESLK$ = g_GETSTR($SW$,0,8)	
watch $RandomSESLK$

edit  $mkey$=  13  000100 $DEAK$ 80000000
watch $mkey$
edit  $mw$ = g_TDES(1 , $DACK$ , $mkey$)	
watch $mw$
edit  $MACInit$ = $RandomSESLK$
edit  $INPUT$   = 84D401101C$mw$
edit  $MAC$= g_TMAC($MACInit$ , $DACK$ , $INPUT$)	
watch   $mw$  $MAC$
edit $Temp$ =  $mw$  $MAC$
watch $Temp$
;维护子密钥 $DAMK$ 
SEND 84D401101C $Temp$
ASSERT 9000

;应用维护子密钥 $DCMK2$ 
send 00 84 00 00 08
edit  $SW$ = g_GETSW()
edit  $RandomSESLK$ = g_GETSTR($SW$,0,8)	
watch $RandomSESLK$

edit  $mkey$=  13  010100 $DAMK1$ 80000000
watch $mkey$
edit  $mw$ = g_TDES(1 , $DACK$ , $mkey$)	
watch $mw$
edit  $MACInit$ = $RandomSESLK$
edit  $INPUT$   = 84D401101C$mw$
edit  $MAC$= g_TMAC($MACInit$ , $DACK$ , $INPUT$)	
watch   $mw$  $MAC$
edit $Temp$ =  $mw$  $MAC$
watch $Temp$
;维护子密钥 $DAMK$ 
SEND 84D401101C $Temp$
ASSERT 9000

;外部认证
SEND 0084000008
edit  $Random$=g_GETSW()
watch $Random$
;3-DES           
edit  $DESKey$ = $DEAK$

edit  $Random$ = g_GETSTR($Random$,0,8)
watch $Random$
edit  $DESResult$ = g_TDES(1 , $DESKey$ , $Random$)	
watch $DESResult$
send 0082000108  $DESResult$
ASSERT 9000