133    """Base application""" 
  135    def __init__(self, aid):
 
  141    def selectResult(self, fci, status, body):
 
  142        return 'selectResult(fci=%s, status=0x%x) = %s\n' %(fci, status, body.hex())
 
  144    def getData(self, fileId, bytes):
 
  145        return 'getData(status=0x%x) = %s\n' %(fileId, bytes.hex())
 
  147    def getDataResult(self, status, body):
 
  148        return 'getDataResult(status=0x%x) = %s\n' %(status, body.hex())
 
  153    def mseResult(self, status, body):
 
  159    def psoResult(self, status, body):
 
  162    def getResponse(self, status, body):
 
  165    def getResponseResult(self, status, body):
 
  168    def verify(self, status, body):
 
  169        return "verify(%s)" % body.hex()
 
  171    def verifyResult(self, status, body):
 
  172        return "verify(%s)" % body.hex()
 
 
  178    """GlobalPlatform application""" 
  180    def __init__(self, aid):
 
  187    def selectResult(self, fci, status, body):
 
  188        return 'selectResult(fci=%s, status=0x%x) = %s\n' %(fci, status, body.hex())
 
  190    def getData(self, fileId, bytes):
 
  192            0x42: 
'Issuer Identification Number',
 
  193            0x45: 
'Card Image Number',
 
  195            0x67: 
'Card Capability Information'  
  198        return 'getData(%s)\n' % tags.get(fileId, 
'<unknown 0x%x>' % fileId)
 
  200    def getDataResult(self, status, body):
 
  204        return 'getDataResult(0x%x) = %s\n' %(status, body.hex())
 
  209    def mseResult(self, status, body):
 
  215    def psoResult(self, status, body):
 
  218    def getResponse(self, status, body):
 
  221    def getResponseResult(self, status, body):
 
 
  226    """PIV application""" 
  228    def __init__(self, aid):
 
  235    def selectResult(self, selectT, status, body):
 
  240        body = body[2:2+appLen]
 
  248                    ret += 
"\tpiv version: %s\n" % body[2:2 + tagLen].hex()
 
  250                    subBody = body[2:2 + tagLen]
 
  255                    content = subBody.hex()
 
  258                        if v.startswith(
'a000000308'):
 
  260                    ret += 
'\tCoexistent tag allocation authority: %s\n' % content
 
  263                    ret += 
'\tapplication label: %s\n' % body[2:2+tagLen].decode(
'utf8')
 
  265                    ret += 
'\tCryptographic algorithms supported: %s\n' % body[2:2+tagLen].hex()
 
  267                    rety += 
'\tunknown tag 0x%x\n' % tag
 
  270                ret += 
"\tTODO: selectType %s\n" % selectT
 
  272            body = body[2+tagLen:]
 
  276    def getData(self, fileId, bytes):
 
  277        ret = 
"\tfileId=%s(%0.4x)\n" % (FIDs.get(fileId, 
""), fileId)
 
  280            return ret + 
"\t/!\\ too short !!!!" 
  287            ret += 
"\tdoId=%0.4x\n"% (bytes[7] * 256 + bytes[8])
 
  296            keyStr = 
"key(tag=0x%x len=%d ref=0x%x)=" % (tag, tagLen, keyRef)
 
  301            keyStr += 
"value(tag=0x%x len=%d)" 
  303            ret += 
"\tDiscovery Object\n" 
  305            ret += 
"\tBiometric Information Templates (BIT) Group Template\n" 
  308                tagStr = bytes[7:10].hex()
 
  309                ret += 
'\ttag: %s(%s)\n' % (tagStr, PIV_OIDs.get(tagStr, 
'<unknown>'))
 
  312            ret += 
"\tunknown key access(lc=0x%x)\n" % lc
 
  316    def getDataResult(self, status, body):
 
  323        body = body[2:2+appLen]
 
  327            tagBody = body[2:2+tagLen]
 
  329            if self.
lastGet in (
'5fc102',):
 
  332                    ret += 
'\tFASC-N: %s\n' % tagBody.hex()
 
  334                    ret += 
'\tGUID: %s\n' % tagBody.hex()
 
  336                    ret += 
'\texpirationDate: %s\n' % tagBody.decode(
'utf8')
 
  338                    ret += 
'\tIssuer Asymmetric Signature: %s\n' % tagBody.hex()
 
  340                    ret += 
"\tunknown tag=0x%x len=%d content=%s\n" % (tag, tagLen, tagBody.hex())
 
  342            elif self.
lastGet in (
'5fc107',):
 
  345                    0xf0: 
"Card Identifier",
 
  346                    0xf1: 
"Capability Container version number",
 
  347                    0xf2: 
"Capability Grammar version number",
 
  348                    0xf3: 
"Applications CardURL",
 
  350                    0xf5: 
"Registered Data Model number",
 
  351                    0xf6: 
"Access Control Rule Table",
 
  353                    0xfa: 
"Redirection Tag",
 
  354                    0xfb: 
"Capability Tuples (CTs)",
 
  355                    0xfc: 
"Status Tuples (STs)",
 
  357                    0xe3: 
"Extended Application CardURL",
 
  358                    0xb4: 
"Security Object Buffer",
 
  359                    0xfe: 
"Error Detection Code" 
  362                if tag 
in capas.keys():
 
  364                        ret += 
"\t%s: len=%d %s\n" % (capas[tag], tagLen, tagBody.hex())
 
  366                    ret += 
"\tunknown capa tag 0x%x: %s\n" % (tag, tagBody.hex())
 
  373                ret += 
"\t%s: unimplemented tag=0x%x len=%d content=%s\n" % (self.
lastGet, tag, tagLen, tagBody.hex())
 
  375            body = body[2+tagLen:]
 
  379    def getResponse(self, status, body):
 
  382    def getResponseResult(self, status, body):
 
  388    def mseResult(self, status, body):
 
  394    def psoResult(self, status, body):
 
  397    def verify(self, status, body):
 
  398        return "verify(%s)" % body.hex()
 
  400    def verifyResult(self, status, body):
 
  401        return "verify(%s)" % body.hex()
 
 
  407    """GIDS application""" 
  409    def __init__(self, aid):
 
  416    def parseFcp(self, bytes):
 
  421        body = bytes[2:2+tagLen]
 
  429                tag2Body = body[2:2+tag2Len] 
 
  432                    ret += 
'\t\tFileDescriptor: %s\n' % tag2Body.hex() 
 
  434                    ret += 
'\t\tLifeCycleByte: %s\n' % tag2Body.hex()
 
  436                    ret += 
'\t\tDF name: %s\n' % tag2Body.encode(
'utf8')
 
  438                    ret += 
'\t\tSecurityAttributes: %s\n' % tag2Body.hex()
 
  440                    ret += 
'\t\tunhandled tag=0x%x body=%s\n' % (tag2, tag2Body.hex())
 
  442                body = body[2+tag2Len:]
 
  446    def parseFci(self, bytes):
 
  451        body = bytes[2:2+tagLen]
 
  459                tag2Body = body[2:2+tag2Len]
 
  462                    ret += 
'\t\tApplication AID: %s\n' % tag2Body.hex()
 
  465                    ret += 
'\t\tApplication label: %s\n' % tag2Body.encode(
'utf8')
 
  470                    while len(body2) > 2:
 
  477                                tokens.append(
'mutualAuthSymAlgo')
 
  479                                tokens.append(
'extAuthSymAlgo')
 
  481                                tokens.append(
'keyEstabIntAuthECC')
 
  484                        body2 = body2[2+tag3Len:]
 
  486                    ret += 
'\t\tDiscretionary data objects: %s\n' % 
",".join(tokens)
 
  488                    ret += 
'\t\tunhandled tag=0x%x body=%s\n' % (tag2, tag2Body.hex())
 
  490                body = body[2+tag2Len:]
 
  495    def selectResult(self, selectT, status, body):
 
  501        elif selectT == 
'FCI':
 
  504            return '\tselectResult(fci=%s, status=0x%x) = %s\n' % (selectT, status, body.hex())
 
  506    def getData(self, fileId, bytes):
 
  512            doStr = bytes[7:7+tagLen].hex()
 
  513            ret = 
'\tDO=%s\n' % DOs.get(doStr, 
"<%s>" % doStr)
 
  516            ret = 
'\tunknown tag=0%x len=%d v=%s' % (tag, tagLen, bytes[7:7+tagLen].hex())
 
  520    def getDataResult(self, status, body):
 
  527            ret += '\ttag=0x%x len=%d content=%s\n' % (tag, tagLen, body[2:2+tagLen].hex()) 
  529            body = body[2+tagLen:] 
  536    def mseResult(self, status, body):
 
  539    def getResponse(self, status, body):
 
  542    def getResponseResult(self, status, body):
 
  548    def psoResult(self, status, body):
 
 
  626            (cla, ins, p1, p2) = bytes[0:4]