1919# with this program; if not, see <http://www.gnu.org/licenses/>.
2020
2121from smartcard .System import readers
22- from smartcard .pcsc .PCSCPart10 import (SCARD_SHARE_DIRECT ,
23- SCARD_LEAVE_CARD , FEATURE_MCT_READER_DIRECT , getFeatureRequest , hasFeature )
22+ from smartcard .pcsc .PCSCPart10 import (
23+ SCARD_SHARE_DIRECT ,
24+ SCARD_LEAVE_CARD ,
25+ FEATURE_MCT_READER_DIRECT ,
26+ getFeatureRequest ,
27+ hasFeature ,
28+ )
2429from smartcard .util import toHexString
2530
2631
2732def parse_info (bytes ):
28- """ parse the SECODER INFO answer """
33+ """parse the SECODER INFO answer"""
2934 print ("parse the SECODER INFO answer:" , toHexString (bytes ))
3035
3136 sw = bytes [- 2 :]
@@ -34,36 +39,34 @@ def parse_info(bytes):
3439 while len (bytes ):
3540 tag = bytes [0 ]
3641 length = bytes [1 ]
37- data = bytes [2 : 2 + length ]
42+ data = bytes [2 : 2 + length ]
3843
39- print ("tag: %02X, length: %2d:" % (tag , length ), end = ' ' )
44+ print ("tag: %02X, length: %2d:" % (tag , length ), end = " " )
4045 if tag in [0x40 , 0x80 , 0x81 , 0x83 , 0x84 ]:
41- print ("'%s'" % '' .join ([chr (x ) for x in data ]))
46+ print ("'%s'" % "" .join ([chr (x ) for x in data ]))
4247 else :
4348 print (toHexString (data ))
4449
45- del bytes [:2 + length ]
50+ del bytes [: 2 + length ]
4651 print ("SW:" , toHexString (sw ))
4752
4853
4954def parse_select (bytes ):
50- """ parse the SECODER SELECT APPLICATION answer """
51- print ("parse the SECODER SELECT APPLICATION answer:" ,
52- toHexString (bytes ))
55+ """parse the SECODER SELECT APPLICATION answer"""
56+ print ("parse the SECODER SELECT APPLICATION answer:" , toHexString (bytes ))
5357
5458 print ("Activation ID:" , toHexString (bytes [0 :4 ]))
55- print ("Interface Version: '%s'" % '' .join ([chr (x ) for x in bytes [5 :11 ]]))
59+ print ("Interface Version: '%s'" % "" .join ([chr (x ) for x in bytes [5 :11 ]]))
5660 print ("Language Code:" , toHexString (bytes [11 :15 ]))
5761 print ("CSI:" , toHexString (bytes [15 :18 ]))
5862 print ("Application Identifier:" , toHexString (bytes [18 :23 ]))
5963 print ("SW:" , toHexString (bytes [23 :25 ]))
6064
6165
6266def main ():
63- """ main """
67+ """main"""
6468 card_connection = readers ()[0 ].createConnection ()
65- card_connection .connect (mode = SCARD_SHARE_DIRECT ,
66- disposition = SCARD_LEAVE_CARD )
69+ card_connection .connect (mode = SCARD_SHARE_DIRECT , disposition = SCARD_LEAVE_CARD )
6770
6871 feature_list = getFeatureRequest (card_connection )
6972 # print(getPinProperties(card_connection))
@@ -76,11 +79,40 @@ def main():
7679 res = card_connection .control (mct_reader_direct , secoder_info )
7780 parse_info (res )
7881
79- secoder_select = [0x20 , 0x71 , 0x00 , 0x00 , 0x00 , 0x00 , 0x14 , 0x00 , 0x80 ,
80- 0x05 , 0x31 , 0x2E , 0x31 , 0x2E , 0x30 , 0x84 , 0x02 , 0x64 , 0x65 ,
81- 0x90 , 0x01 , 0x01 , 0x85 , 0x03 , ord ('g' ), ord ('k' ), ord ('p' ), 0x00 , 0x00 ]
82+ secoder_select = [
83+ 0x20 ,
84+ 0x71 ,
85+ 0x00 ,
86+ 0x00 ,
87+ 0x00 ,
88+ 0x00 ,
89+ 0x14 ,
90+ 0x00 ,
91+ 0x80 ,
92+ 0x05 ,
93+ 0x31 ,
94+ 0x2E ,
95+ 0x31 ,
96+ 0x2E ,
97+ 0x30 ,
98+ 0x84 ,
99+ 0x02 ,
100+ 0x64 ,
101+ 0x65 ,
102+ 0x90 ,
103+ 0x01 ,
104+ 0x01 ,
105+ 0x85 ,
106+ 0x03 ,
107+ ord ("g" ),
108+ ord ("k" ),
109+ ord ("p" ),
110+ 0x00 ,
111+ 0x00 ,
112+ ]
82113 res = card_connection .control (mct_reader_direct , secoder_select )
83114 parse_select (res )
84115
116+
85117if __name__ == "__main__" :
86118 main ()
0 commit comments