Esempio n. 1
0
 def _decode_record_hex(self, raw_hex_data):
     raw_hex_data = raw_hex_data.upper()
     atempl_base_tlv = TLV(['61'])
     atempl_base = atempl_base_tlv.parse(raw_hex_data)
     atempl_TLV_MAP = {'4F': 'aid_value', 50: 'label'}
     atempl_tlv = TLV(atempl_TLV_MAP)
     atempl = atempl_tlv.parse(atempl_base['61'])
     # FIXME: "All other Dos are according to ISO/IEC 7816-4"
     return tlv_key_replace(atempl_TLV_MAP, atempl)
Esempio n. 2
0
    def __sendGA4(self, authToken):
        header = bytearray([
            0x00, 0x86, 0, 0,
            len(authToken) + 4, 0x7c,
            len(authToken) + 2, 0x85,
            len(authToken)
        ])
        response = self.__transceiveAPDU(list(header + authToken) + [0])

        tlv = TLV(['86', '87', '88'])  # DO87 and DO88 are optional

        collection = tlv.parse(binascii.hexlify(response[2:]))

        if (collection.get('86') != None):
            DO86 = bytearray.fromhex(collection.get('86'))
        else:
            DO86 = None

        if (collection.get('87') != None):
            DO87 = bytearray.fromhex(collection.get('87'))
        else:
            DO87 = None

        if (collection.get('88') != None):
            DO88 = bytearray.fromhex(collection.get('88'))
        else:
            DO88 = None

        return DO86, DO87, DO88
Esempio n. 3
0
def decode_select_response(resp_hex):
    fixup_fcp_proprietary_tlv_map(FCP_Proprietary_TLV_MAP)
    resp_hex = resp_hex.upper()
    # outer layer
    fcp_base_tlv = TLV(['62'])
    fcp_base = fcp_base_tlv.parse(resp_hex)
    # actual FCP
    fcp_tlv = TLV(FCP_TLV_MAP)
    fcp = fcp_tlv.parse(fcp_base['62'])
    # further decode the proprietary information
    if fcp['A5']:
        prop_tlv = TLV(FCP_Proprietary_TLV_MAP)
        prop = prop_tlv.parse(fcp['A5'])
        fcp['A5'] = tlv_val_interpret(FCP_prorietary_interpreter_map, prop)
        fcp['A5'] = tlv_key_replace(FCP_Proprietary_TLV_MAP, fcp['A5'])
    # finally make sure we get human-readable keys in the output dict
    r = tlv_val_interpret(FCP_interpreter_map, fcp)
    return tlv_key_replace(FCP_TLV_MAP, r)
Esempio n. 4
0
    def __sendGA4(self, authToken):
        header = bytearray([
            0x00, 0x86, 0, 0,
            len(authToken) + 4, 0x7c,
            len(authToken) + 2, 0x85,
            len(authToken)
        ])
        response = self.__transceiveAPDU(list(header + authToken) + [0])

        tlv = TLV(['86', '87', '88'])
        collection = tlv.parse(binascii.hexlify(response[2:]).decode('ascii'))
        tpicc = collection.get('86') if collection.get('86') != None else ""
        car1 = collection.get('87') if collection.get('87') != None else ""
        car2 = collection.get('88') if collection.get('88') != None else ""

        return bytearray.fromhex(tpicc), bytearray.fromhex(
            car1), bytearray.fromhex(car2)
Esempio n. 5
0
from pytlv.TLV import *
import json

data = {"Username": "******", "age": 16}
jsondata = json.dumps(data)
print(jsondata)
tlv = TLV(['89ABCDEF', '9F04'])
test = '1234567890' + repr(jsondata)
print(len(test))
print(test)
data = tlv.build({'89ABCDEF': test})
print(data)
text = tlv.parse(data)
print(text)
'''
test1 = 'Ab0000'
print(len(test1))
data1 = tlv.build({'9f04': test1 + jsondata})
print(data1)
text1 = tlv.parse(data1)
print(text1)
'''