-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapduprocessor.py
More file actions
executable file
·48 lines (39 loc) · 1.85 KB
/
Copy pathapduprocessor.py
File metadata and controls
executable file
·48 lines (39 loc) · 1.85 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
from bitmask import BitMask
class ProcessorApdu:
def parseCLA3210(self, data, offset):
log = []
if ((data[offset] & (BitMask.B3|BitMask.B2)) == (BitMask.B3|BitMask.B2)):
log.append('Bits 3..2 ISO secure messaging; header authentic')
elif ((data[offset] & (BitMask.B3|BitMask.B2)) == BitMask.B3):
log.append('Bits 3..2 ISO secure messaging; header not authentic')
elif ((data[offset] & (BitMask.B3|BitMask.B2)) == BitMask.B2):
log.append('Bits 3..2 Non-ISO secure messaging using a private method')
else:
log.append('Bits 3..2 Secure messaging not used')
log.append('Bits 1..0 Logical Channel %d' % (data[offset] & (BitMask.B1|BitMask.B0)))
return log
def parseApduDataPCD(self, data, offset):
log = []
#log.append("APDU DATA: %s" % str(" ".join(["{0:02x}".format(x) for x in data[offset:]])))
try:
# case where neither Lc nor Data not Le given - don't bother
# TODO Lc and Le extensions (3 bytes 00 xx xx)
data[offset]
if (len(data)-offset == 1):
# we have offset set to the last byte - this is Le
log.append('Byte %d length of response data Le (0=Maximum) %d' % (offset, data[offset]))
else:
Lc = data[offset]
log.append('Byte %d length of command data Lc %d' % (offset, data[offset]))
log.append("Command Data: %s" % str(" ".join(["{0:02x}".format(x) for x in data[offset+1:Lc+offset+1]])))
if (len(data)-(Lc+offset+1) == 1):
log.append('Byte %d length of response data Le (0=Maximum) %d' % (Lc+offset+1, data[Lc+offset+1]))
except IndexError:
# case where neither Lc nor Data not Le given - don't bother
pass
return log
def parseApduDataPICC(self, data, offset):
log = []
if (data[offset:-2] != []):
log.append("TLV content: %s" % str(" ".join(["{0:02x}".format(x) for x in data[offset:-2]])))
return log