-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader.py
executable file
·54 lines (49 loc) · 1.71 KB
/
reader.py
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
#!/bin/env python
from smartcard.CardType import AnyCardType
from smartcard.CardRequest import CardRequest
from smartcard.ATR import ATR
from smartcard.util import toHexString
from time import sleep
ATRS = {}
def get_smartcards_list():
global ATRS
with open('./smartcard_list.txt') as f:
lines = f.readlines()
cursor = None
for line in lines:
if line.startswith("#"):
continue
elif line.startswith("3B"):
cursor = line.replace('\n', '').replace('\t', '')
ATRS[cursor] = ""
elif cursor is not None:
ATRS[cursor] += line
def send(reader):
response, sw1, sw2 = reader.transmit([0xFF, 0xCA, 0x00, 0x00, 0x00])
print('Response :', response)
print(sw1, sw2)
def main():
global ATRS
get_smartcards_list()
cardtype = AnyCardType()
while True:
cardrequest = CardRequest( timeout=120, cardType=cardtype )
cardservice = cardrequest.waitforcard()
cardservice.connection.connect()
atrBytes = cardservice.connection.getATR()
atr = ATR(atrBytes)
print(atr)
print('historical bytes: ', toHexString(atr.getHistoricalBytes()))
print('checksum: ', "0x%X" % atr.getChecksum())
print('checksum OK: ', atr.checksumOK)
print('T0 supported: ', atr.isT0Supported())
print('T1 supported: ', atr.isT1Supported())
print('T15 supported: ', atr.isT15Supported())
if (ATRS[toHexString(atrBytes)]):
print(ATRS[toHexString(atrBytes)])
print(cardservice.connection)
send(cardservice.connection)
sleep(5)
return 0
if __name__ == '__main__':
main()