示例#1
0
def decode_file_descriptor_byte(value, verbose = True):
    result = " %s" % utils.hexdump(value, short=True)
    
    if not verbose:
        attributes = utils.parse_binary(ord(value[0]), file_descriptor_byte_descriptions, False)
        if len(value) > 1:
            attributes.append(
                "data coding byte, behavior of write functions: %s, data unit size in in nibbles: %i" % (
                    "".join( utils.parse_binary(ord(value[1]), data_coding_byte_descriptions) ),
                    2 ** (ord(value[1])&0x07)
                )
            )
        
        if len(value) > 2:
            i = 0
            for j in value[2:4]:
                i = i * 256 + ord(j)
            attributes.append(
                "maximum record length: %s" % i
            )
            if len(value) > 4:
                i = 0
                for j in value[4:6]:
                    i = i * 256 + ord(j)
                attributes.append(
                    "number of records: %s" % i
                )
        
        return result + " (%s)" % "; ".join(attributes)
    else:
        result = result + "\nFile descriptor byte:\n"
        result = result + "\t" + "\n\t".join(
            utils.parse_binary(ord(value[0]), file_descriptor_byte_descriptions, True)
        )
        if len(value) > 1:
            result = result + "\nData coding byte (0x%02X):\n" % ord(value[1])
            result = result + "\tBehavior of write functions: %s\n\tData unit size in in nibbles: %i" % (
                    "".join( utils.parse_binary(ord(value[1]), data_coding_byte_descriptions) ),
                    2 ** (ord(value[1])&0x07)
                )
        if len(value) > 2:
            i = 0
            for j in value[2:4]:
                i = i * 256 + ord(j)
            result = result + "\nMaximum record length: %s" % i
            if len(value) > 4:
                i = 0
                for j in value[4:6]:
                    i = i * 256 + ord(j)
                result = result + "\nNumber of records: %s" % i
        return result
示例#2
0
def decode_file_descriptor_byte(value, verbose=True):
    result = " %s" % utils.hexdump(value, short=True)

    if not verbose:
        attributes = utils.parse_binary(ord(value[0]),
                                        file_descriptor_byte_descriptions,
                                        False)
        if len(value) > 1:
            attributes.append(
                "data coding byte, behavior of write functions: %s, data unit size in in nibbles: %i"
                % ("".join(
                    utils.parse_binary(ord(value[1]),
                                       data_coding_byte_descriptions)), 2
                   **(ord(value[1]) & 0x07)))

        if len(value) > 2:
            i = 0
            for j in value[2:4]:
                i = i * 256 + ord(j)
            attributes.append("maximum record length: %s" % i)
            if len(value) > 4:
                i = 0
                for j in value[4:6]:
                    i = i * 256 + ord(j)
                attributes.append("number of records: %s" % i)

        return result + " (%s)" % "; ".join(attributes)
    else:
        result = result + "\nFile descriptor byte:\n"
        result = result + "\t" + "\n\t".join(
            utils.parse_binary(ord(value[0]),
                               file_descriptor_byte_descriptions, True))
        if len(value) > 1:
            result = result + "\nData coding byte (0x%02X):\n" % ord(value[1])
            result = result + "\tBehavior of write functions: %s\n\tData unit size in in nibbles: %i" % (
                "".join(
                    utils.parse_binary(ord(value[1]),
                                       data_coding_byte_descriptions)), 2**
                (ord(value[1]) & 0x07))
        if len(value) > 2:
            i = 0
            for j in value[2:4]:
                i = i * 256 + ord(j)
            result = result + "\nMaximum record length: %s" % i
            if len(value) > 4:
                i = 0
                for j in value[4:6]:
                    i = i * 256 + ord(j)
                result = result + "\nNumber of records: %s" % i
        return result
示例#3
0
 def decode_retry_counter(value):
     results = [" %s" % utils.hexdump(value, short=True)]
     results.append("Number of further allowed attempts: %i" % ord(value[0]))
     results.append("New value of the retry counter: %i\n\t%s" % (
         ord(value[1]) % 0x7F,
         "\n\t".join( utils.parse_binary( 
             ord(value[1]), MTCOS_Card.reset_retry_counter_byte_descriptions, True 
         ) )
     ) )
     return "\n".join(results)
示例#4
0
 def decode_83(value):
     ## 0x83 in 0xA5 is either "Cryptographic algorithm and allowed applications" or
     ##  "Default key reference for authentication commands in this environment"
     
     if len(value) >= 2:
         results = [" %s" % utils.hexdump(value, short=True)]
         results.append("Application class: 0x%02x\n\t%s" % (
             ord(value[0]),
             "\n\t".join( utils.parse_binary( 
                 ord(value[0]), MTCOS_Card.application_class_byte_descriptions, True 
             ) )
         ) )
         results.append("Cryptographic algorithm: 0x%02x\n\t%s" % (
             ord(value[1]),
             "\n\t".join( utils.parse_binary( 
                 ord(value[1]), MTCOS_Card.cryptographic_algorithm_byte_descriptions, True 
             ) )
         ) )
         return "\n".join(results)
     elif len(value) == 1:
         return "\nDefault key reference for authentication commands in this environment: 0x%02x" % ord(value[0])
示例#5
0
def decode_compact_access_bitmap(value):
    return (" %s \n" % utils.hexdump(value, short=True)) + "\n".join(utils.parse_binary(ord(value[0]), compact_access_descriptions, True))
示例#6
0
 def decode_file_descriptor_extension(cls, value):
     result = [" "+utils.hexdump(value, short=True)]
     if len(value) >= 1:
         result.append("File status: %s" % utils.hexdump(value[0], short=True))
         result.append("\t" + "\n\t".join(
             utils.parse_binary( 
                 ord(value[0]), cls.file_status_descriptions, True 
             ) )
         )
     
     if len(value) >= 2:
         is_secret = (ord(value[1]) & 0x80 == 0x80)
         is_key = (ord(value[1]) & 0xC0 == 0xC0)
         
         if is_key:
             iftd = value[1:4]
         elif is_secret:
             iftd = value[1:3]
         else:
             iftd = value[1:2]
         
         result.append("Internal File Type Descriptor: %s" % utils.hexdump(iftd, short=True))
         if len(iftd) >= 1:
             result.append("\tFile Type: %s" % utils.hexdump(iftd[0], short=True))
             result.append("\t\t" + "\n\t\t".join(
                 utils.parse_binary( 
                     ord(iftd[0]), cls.iftd_byte_1_descriptions, True 
                 ) )
             )
         
         if len(iftd) >= 2:
             result.append("\tNumber of secret: %i (0x%x)" % ((ord(iftd[1])&0x1F,)*2) )
         
         if len(iftd) >= 3:
             result.append("\tCryptographic algorithm: %s" % utils.hexdump(iftd[2], short=True))
             result.append("\t\t" + "\n\t\t".join(
                 utils.parse_binary( 
                     ord(iftd[2]), cls.iftd_byte_3_descriptions, True 
                 ) )
             )
         
         fbz = value[1+len(iftd):]
         if len(fbz) == 2:
             result.append("\tVerification failure counter (FBZ): %s" % utils.hexdump(fbz, short=True))
             if fbz == "\x00\x00":
                 result.append("\t\tFBZ unused")
             else:
                 result.append("\t\tCurrent value: %i (0x%x)%s" % (
                     ord(fbz[0]), ord(fbz[0]),
                     ord(fbz[0]) == 0 and (ord(fbz[1]) != 0 and " (Secret locked)" or " (FBZ unused)") or "")
                 )
                 resetmode = ord(fbz[1])
                 result.append("\t\tReset value: %i (0x%x)%s" % (
                     resetmode & 0x7F, resetmode & 0x7F,
                     resetmode == 0 and " (FBZ unused)" or (
                         resetmode & 0x80 == 0x00 and " (reset with unblock password and successful verification)"
                         or " (reset only with unblock password)")
                     )
                 )
             
     
     return "\n".join(result)
示例#7
0
 def decode_physical_access(value):
     return "\n"+"\n".join( 
         utils.parse_binary( 
             ord(value[0]), MTCOS_Card.physical_access_byte_descriptions, True 
         ) 
     )
示例#8
0
def decode_lcs(value):
    value = ord(value[0])
    return " 0x%02x\n%s" % (value, "\n".join(
            utils.parse_binary(value, life_cycle_status_byte_descriptions, True)
        )
    )
示例#9
0
def decode_lcs(value):
    value = ord(value[0])
    return " 0x%02x\n%s" % (value, "\n".join(
        utils.parse_binary(value, life_cycle_status_byte_descriptions, True)))