From: <lu...@us...> - 2009-04-18 08:07:17
|
Revision: 283 http://pyscard.svn.sourceforge.net/pyscard/?rev=283&view=rev Author: ludov Date: 2009-04-18 08:07:15 +0000 (Sat, 18 Apr 2009) Log Message: ----------- set svn:executable Property Changed: ---------------- trunk/contrib/parseATR/parseATR.py Property changes on: trunk/contrib/parseATR/parseATR.py ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-06-08 15:50:01
|
Revision: 286 http://pyscard.svn.sourceforge.net/pyscard/?rev=286&view=rev Author: ludov Date: 2009-06-08 13:54:54 +0000 (Mon, 08 Jun 2009) Log Message: ----------- debug historic bytes parsing Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-06-08 13:36:32 UTC (rev 285) +++ trunk/contrib/parseATR/parseATR.py 2009-06-08 13:54:54 UTC (rev 286) @@ -238,16 +238,18 @@ tag = tlv / 16 len = tlv % 16 + text += " Tag: %d, Len: %d" % (tag, len) + if tag == 1: - text += " (country code, ISO 3166-1)" + text += " (country code, ISO 3166-1)\n" text += " Country code: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX) elif tag == 2: - text += " (issuer identification number, ISO 7812-1)"; + text += " (issuer identification number, ISO 7812-1)\n"; text += " Issuer identification number: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX) elif tag == 3: - text += " (card service data byte)" + text += " (card service data byte)\n" cs = historical_bytes.pop(0) if cs == None: text += " Error in the ATR: expecting 1 byte and got 0" @@ -256,19 +258,19 @@ text += cs(cs) elif tag == 4: - text += " (initial access data)" + text += " (initial access data)\n" text += " Initial access data: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX) elif tag == 5: - text += " (card issuer's data)" + text += " (card issuer's data)\n" text += " Card issuer data: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX) elif tag == 6: - text += " (pre-issuing data)" + text += " (pre-issuing data)\n" text += " Data: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX) elif tag == 7: - text += " (card capabilities)" + text += " (card capabilities)\n" if len == 1: sm = historical_bytes.pop(0) text += " Selection methods: %d" % sm @@ -294,7 +296,7 @@ text += " wrong ATR" elif tag == 8: - text += " (status indicator)" + text += " (status indicator)\n" if len == 1: lcs = historical_bytes.pop(0) text += " LCS (life card cycle): %d" % lcs @@ -310,13 +312,17 @@ text += " SW: %02X %02X" % (sw1, sw2) elif tag == 15: - text += " (application identifier)" + text += " (application identifier)\n" text += " Application identifier: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX) else: - text += " (unknown)" + text += " (unknown)\n" text += " Value: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX) + # consume len bytes of historic + for i in range(len): + historical_bytes.pop(0) + return text def analyse_histrorical_bytes(historical_bytes): @@ -327,6 +333,8 @@ if hb_category == None: return text + text += " Category indicator byte: %02X" % hb_category + if hb_category == 0x00: text += " (compact TLV data object)\n"; @@ -347,7 +355,7 @@ text += " SW: %02X%02X (%s)" % (sw1, sw1, "") #Chipcard::PCSC::Card::ISO7816Error("$sw1 $sw2")) elif hb_category == 0x80: - text += " (compact TLV data object)" + text += " (compact TLV data object)\n" while len(historical_bytes) > 0: text += compact_tlv(historical_bytes) @@ -388,6 +396,7 @@ print "Historical bytes: ", for b in atr["hb"]: print "0x%02X" % b, + print print analyse_histrorical_bytes(atr["hb"]) if __name__ == "__main__": This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-06-09 14:05:18
|
Revision: 287 http://pyscard.svn.sourceforge.net/pyscard/?rev=287&view=rev Author: ludov Date: 2009-06-09 13:56:33 +0000 (Tue, 09 Jun 2009) Log Message: ----------- more debug Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-06-08 13:54:54 UTC (rev 286) +++ trunk/contrib/parseATR/parseATR.py 2009-06-09 13:56:33 UTC (rev 287) @@ -47,6 +47,10 @@ def parseATR(atr_txt): atr_txt = normalize(atr_txt) atr = {} + + # the ATR itself as a list of integers + atr["atr"] = atr_txt + # store TS and T0 atr["TS"] = atr_txt[0] atr["T0"] = TDi = atr_txt[1] @@ -91,7 +95,7 @@ # Store TCK if (atr.has_key("TCK")): - atr["TCK"] = atr_txt[pointer] + atr["TCK"] = atr_txt[-1] return atr @@ -106,16 +110,16 @@ def TA2(v): F = v >> 4 D = v & 0xF - text = "Protocol to be used in spec mode: T=%s" % (D), + text = "Protocol to be used in spec mode: T=%s" % (D) if (F & 0x8): - text = text + " - Unable to change", + text += " - Unable to change" else: - text = text + " - Capable to change", + text += " - Capable to change" if (F & 0x1): - text = text + " - implicity defined" + text += " - implicity defined" else: - text = text + " - defined by interface bytes" + text += " - defined by interface bytes" return text @@ -181,9 +185,9 @@ return text def TC1(v): - text = "Extra guard time:", v, + text = "Extra guard time: %d" % v if (v == 255): - text += "(special value)" + text += " (special value)" return text def TC2(v): @@ -198,9 +202,9 @@ def TCn(i, v): text = "" if (T == 1): - text = "Error detection code: ", + text = "Error detection code: " if (v == 1): - text += "CRC"; + text += "CRC" else: if (v == 0): text += "LRC" @@ -333,7 +337,7 @@ if hb_category == None: return text - text += " Category indicator byte: %02X" % hb_category + text += " Category indicator byte: 0x%02X" % hb_category if hb_category == 0x00: text += " (compact TLV data object)\n"; @@ -372,6 +376,15 @@ return text +def compute_tck(atr): + # do not include TS byte + s = atr["atr"][0]; + for e in atr["atr"]: + s ^= e + # remove TCK + s ^= atr["atr"][-1]; + return s + def atr_display_txt(atr): TS = {0x3B: "Direct Convention", 0x3F: "Inverse Convention"} print "TS = 0x%02X --> %s" % (atr["TS"], TS[atr["TS"]]) @@ -398,8 +411,18 @@ print "0x%02X" % b, print print analyse_histrorical_bytes(atr["hb"]) - + + if (atr.has_key("TCK")): + print ("TCK = 0x%02X" % atr["TCK"]), + tck = compute_tck(atr) + if tck == atr["TCK"]: + print "(correct checksum)" + else: + print "WRONG CHECKSUM, expected 0x%02X" % tck + if __name__ == "__main__": - atr = parseATR("3B A7 00 40 18 80 65 A2 08 01 01 52") - #atr = parseATR("3F FF 95 00 FF 91 81 71 A0 47 00 44 4E 41 53 50 30 31 31 20 52 65 76 42") + #ATR = "3B A7 00 40 18 80 65 A2 08 01 01 52" + ATR = "3F FF 95 00 FF 91 81 71 A0 47 00 44 4E 41 53 50 30 31 31 20 52 65 76 42 30 36 4E" + atr = parseATR(ATR) + print "ATR:", ATR atr_display_txt(atr) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-06-09 14:23:10
|
Revision: 288 http://pyscard.svn.sourceforge.net/pyscard/?rev=288&view=rev Author: ludov Date: 2009-06-09 14:22:58 +0000 (Tue, 09 Jun 2009) Log Message: ----------- use command line arguments Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-06-09 13:56:33 UTC (rev 287) +++ trunk/contrib/parseATR/parseATR.py 2009-06-09 14:22:58 UTC (rev 288) @@ -421,8 +421,12 @@ print "WRONG CHECKSUM, expected 0x%02X" % tck if __name__ == "__main__": - #ATR = "3B A7 00 40 18 80 65 A2 08 01 01 52" - ATR = "3F FF 95 00 FF 91 81 71 A0 47 00 44 4E 41 53 50 30 31 31 20 52 65 76 42 30 36 4E" + import sys + if len(sys.argv) > 1: + ATR = " ".join(sys.argv[1:]) + else: + #ATR = "3B A7 00 40 18 80 65 A2 08 01 01 52" + ATR = "3F FF 95 00 FF 91 81 71 A0 47 00 44 4E 41 53 50 30 31 31 20 52 65 76 42 30 36 4E" atr = parseATR(ATR) print "ATR:", ATR atr_display_txt(atr) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-06-16 19:05:57
|
Revision: 293 http://pyscard.svn.sourceforge.net/pyscard/?rev=293&view=rev Author: ludov Date: 2009-06-16 12:49:49 +0000 (Tue, 16 Jun 2009) Log Message: ----------- more debug Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-06-14 12:20:19 UTC (rev 292) +++ trunk/contrib/parseATR/parseATR.py 2009-06-16 12:49:49 UTC (rev 293) @@ -54,6 +54,7 @@ # store TS and T0 atr["TS"] = atr_txt[0] atr["T0"] = TDi = atr_txt[1] + hb_length = atr["T0"] & 15 pointer = 1 # protocol number pn = 1 @@ -91,7 +92,10 @@ atr["pn"] = pn # Store historical bytes - atr["hb"] = atr_txt[pointer+1:] + atr["hb"] = atr_txt[pointer+1:pointer+1+hb_length] + + if len(atr["hb"]) < hb_length: + raise Exception("ERROR! ATR is truncated: %d byte(s) is/are missing" % (hb_length-len(atr["hb"]))) # Store TCK if (atr.has_key("TCK")): @@ -110,18 +114,18 @@ def TA2(v): F = v >> 4 D = v & 0xF - text = "Protocol to be used in spec mode: T=%s" % (D) + text = ["Protocol to be used in spec mode: T=%s" % (D)] if (F & 0x8): - text += " - Unable to change" + text.append(" - Unable to change") else: - text += " - Capable to change" + text.append(" - Capable to change") if (F & 0x1): - text += " - implicity defined" + text.append(" - implicity defined") else: - text += " - defined by interface bytes" + text.append(" - defined by interface bytes") - return text + return ''.join(text) def TA3(v): return TAn(3, v) @@ -136,20 +140,20 @@ else: F = v >> 6 D = v % 64 - Class = "(3G) " + Class = ["(3G) "] if (D & 0x1): - Class += "A 5V " + Class.append("A 5V ") if (D & 0x2): - Class += "B 3V " + Class.append("B 3V ") if (D & 0x4): - Class += "C 1.8V " + Class.append("C 1.8V ") if (D & 0x8): - Class += "D RFU " + Class.append("D RFU ") if (D & 0x10): - Class += "E RFU" + Class.append("E RFU") - text = "Clock stop: %s - Class accepted by the card: %s" % (XI[F],Class) + text = "Clock stop: %s - Class accepted by the card: %s" % (XI[F],''.join(Class)) return text def TB1(v): @@ -162,12 +166,12 @@ return text def TB2(v): - text = "Programming param PI2 (PI1 should be ignored): %d" % v, + text = ["Programming param PI2 (PI1 should be ignored): %d" % v,] if ((v>49) or (v<251)): - text += " (dV)" + text.append(" (dV)") else: - text += " is RFU" - return text + text.append(" is RFU") + return ''.join(text) def TB3(v): return TBn(3, v) @@ -185,10 +189,10 @@ return text def TC1(v): - text = "Extra guard time: %d" % v + text = ["Extra guard time: %d" % v] if (v == 255): - text += " (special value)" - return text + text.append(" (special value)") + return ''.join(text) def TC2(v): return "Work waiting time: 960 x %d x (Fi/F)" % v @@ -200,17 +204,17 @@ return TCn(4, v) def TCn(i, v): - text = "" + text = [] if (T == 1): - text = "Error detection code: " + text.append("Error detection code: ") if (v == 1): - text += "CRC" + text.append("CRC") else: if (v == 0): - text += "LRC" + text.append("LRC") else: - text += "RFU" - return text + text.append("RFU") + return ''.join(text) def TD1(v): return TDn(1, v) @@ -231,6 +235,169 @@ text = "Y(i+1) = b%s, Protocol T=%d" % (int2bin(Y,4), T) return text +def life_cycle_status(lcs): + # Table 13 - Life cycle status byte + # ISO 7816-4:2004, page 21 + if lcs > 15: + text = "Proprietary" + + if lcs == 0: + text = "No information given" + if lcs == 1: + text = "Creation state" + if lcs == 3: + text = "Initialisation state" + if lcs in [4, 6]: + text = "Operational state (deactivated)" + if lcs in [5, 7]: + text = "Operational state (activated)" + if lcs in [12, 13, 14, 15]: + text = "Termination state" + + return text + +def data_coding(dc): + # Table 87 - Second software function table (data coding byte) + # ISO 7816-4:2004, page 60 + text = [] + + if dc & 128: + text.append(" - EF of TLV structure supported\n") + + # get bits 6 and 7 + text.append(" - Behaviour of write functions: ") + v = (dc & (64+32)) >> 5 + t = ["one-time write\n", "proprietary\n", "write OR\n", "write AND\n"] + text.append(t[v]) + + text.append(" - Value 'FF' for the first byte of BER-TLV tag fields: ") + if dc & 16: + text.append("in") + text.append("valid\n") + + text.append(" - Data unit in quartets: %d" % (dc & 15)) + + return ''.join(text) + +def selection_methods(sm): + # Table 86 - First software function table (selection methods) + # ISO 7816-4:2004, page 60 + text = [] + + if sm & 1: + text.append(" - Record identifier supported\n") + + if sm & 2: + text.append(" - Record number supported\n") + + if sm & 4: + text.append(" - Short EF identifier supported\n") + + if sm & 8: + text.append(" - Implicit DF selection\n") + + if sm & 16: + text.append(" - DF selection by file identifier\n") + + if sm & 32: + text.append(" - DF selection by path\n") + + if sm & 64: + text.append(" - DF selection by partial DF name\n") + + if sm & 128: + text.append(" - DF selection by full DF name\n") + + return ''.join(text) + +def selection_mode(sm): + # Table 87 - Second software function table (data coding byte) + # ISO 7816-4:2004, page 60 + text = [] + + if sm & 1: + text.append(" - Record identifier supported\n") + + if sm & 2: + text.append(" - Record number supported\n") + + if sm & 4: + text.append(" - Short EF identifier supported\n") + + if sm & 8: + text.append(" - Implicit DF selection\n") + + if sm & 16: + text.append(" - DF selection by file identifier\n") + + if sm & 32: + text.append(" - DF selection by path\n") + + if sm & 64: + text.append(" - DF selection by partial DF name\n") + + if sm & 128: + text.append(" - DF selection by full DF name\n") + + return ''.join(text) + +def command_chaining(cc): + # Table 88 - Third software function table (command chaining, length fields and logical channels) + # ISO 7816-4:2004, page 61 + text = [] + + if cc & 128: + text.append(" - Command chaining\n") + + if cc & 64: + text.append(" - Extended Lc and Le fields\n") + + if cc & 32: + text.append(" - RFU (should not happen)\n") + + v = (cc >> 3) & 3 + t = ["No logical channel\n", "by the interface device\n", "by the card\n", "by the interface device and card\n"] + text.append(t[v]) + + text.append(" - Maximum number of logical channels: %d\n" % (cc & 7)) + + return ''.join(text) + +def card_service(cs): + # Table 85 - Card service data byte + # ISO 7816-4:2004, page 59 + text = [] + + if cs & 128: + text.append(" - Application selection: by full DF name\n") + + if cs & 64: + text.append(" - Application selection: by partial DF name\n") + + if cs & 32: + text.append(" - BER-TLV data objects available in EF.DIR\n") + + if cs & 16: + text.append(" - BER-TLV data objects available in EF.ATR\n") + + text.append(" - EF.DIR and EF.ATR access services: ") + v = (cs >> 1) & 7 + if v == 4: + text.append("by READ BINARY command\n") + elif v == 2: + text.append("by GET DATA command\n") + elif v == 0: + text.append("by GET RECORD(s) command\n") + else: + text.append("reverved for future use\n") + + if cs & 1: + text.append(" - Card without MF\n") + else: + text.append(" - Card with MF\n") + + return ''.join(text) + def compact_tlv(historical_bytes): text = "" tlv = historical_bytes.pop(0) @@ -242,137 +409,146 @@ tag = tlv / 16 len = tlv % 16 - text += " Tag: %d, Len: %d" % (tag, len) + text = [] + text.append(" Tag: %d, Len: %d" % (tag, len)) if tag == 1: - text += " (country code, ISO 3166-1)\n" - text += " Country code: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX) + text.append(" (country code, ISO 3166-1)\n") + text.append(" Country code: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX)) elif tag == 2: - text += " (issuer identification number, ISO 7812-1)\n"; - text += " Issuer identification number: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX) + text.append(" (issuer identification number, ISO 7812-1)\n") + text.append(" Issuer identification number: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX)) elif tag == 3: - text += " (card service data byte)\n" - cs = historical_bytes.pop(0) - if cs == None: - text += " Error in the ATR: expecting 1 byte and got 0" + text.append(" (card service data byte)\n") + try: + cs = historical_bytes[0] + except IndexError: + text.append("Error in the ATR: expecting 1 byte and got 0\n") else: - text += " Card service data byte: %d" % cs - text += cs(cs) + if cs == None: + text.append(" Error in the ATR: expecting 1 byte and got 0") + else: + text.append(" Card service data byte: %d" % cs) + text.append(card_service(cs)) elif tag == 4: - text += " (initial access data)\n" - text += " Initial access data: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX) + text.append(" (initial access data)\n") + text.append(" Initial access data: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX)) elif tag == 5: - text += " (card issuer's data)\n" - text += " Card issuer data: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX) + text.append(" (card issuer's data)\n") + text.append(" Card issuer data: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX)) elif tag == 6: - text += " (pre-issuing data)\n" - text += " Data: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX) + text.append(" (pre-issuing data)\n") + text.append(" Data: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX)) elif tag == 7: - text += " (card capabilities)\n" + text.append(" (card capabilities)\n") if len == 1: - sm = historical_bytes.pop(0) - text += " Selection methods: %d" % sm - text += sm(sm) + try: + sm = historical_bytes[0] + except: + text.append("Error in the ATR: expecting 1 byte and got 0\n") + else: + text.append(" Selection methods: %d" % sm) + text.append(selection_mode(sm)) elif len == 2: - sm = historical_bytes.pop(0) - dc = historical_bytes.pop(0) - text += " Selection methods: %d" % sm - text += sm(sm) - text += " Data coding byte: %d" % dc - text += dc(dc) + sm = historical_bytes[0] + dc = historical_bytes[1] + text.append(" Selection methods: %d" % sm) + text.append(selection_methods(sm)) + text.append(" Data coding byte: %d" % dc) + text.append(data_coding(dc)) elif len == 3: - sm = historical_bytes.pop(0) - dc = historical_bytes.pop(0) - cc = historical_bytes.pop(0) - text += " Selection methods: %d" % sm - text += sm(sm) - text += " Data coding byte: %d" % dc - text += dc(dc) - text += " Command chaining, length fields and logical channels: %d" % cc - text += cc(cc) + sm = historical_bytes[0] + dc = historical_bytes[1] + cc = historical_bytes[2] + text.append(" Selection methods: %d" % sm) + text.append(selection_mode(sm)) + text.append(" Data coding byte: %d" % dc) + text.append(data_coding(dc)) + text.append(" Command chaining, length fields and logical channels: %d" % cc) + text.append(command_chaining(cc)) else: - text += " wrong ATR" + text.append(" wrong ATR") elif tag == 8: - text += " (status indicator)\n" + text.append(" (status indicator)\n") if len == 1: - lcs = historical_bytes.pop(0) - text += " LCS (life card cycle): %d" % lcs + lcs = historical_bytes[0] + text.append(" LCS (life card cycle): %d" % lcs) elif len == 2: - sw1 = historical_bytes.pop(0) - sw2 = historical_bytes.pop(0) - text += " SW: %02X %02X" % (sw1, sw2) + sw1 = historical_bytes[0] + sw2 = historical_bytes[1] + text.append(" SW: %02X %02X" % (sw1, sw2)) elif len == 3: - lcs = historical_bytes.pop(0) - sw1 = historical_bytes.pop(0) - sw2 = historical_bytes.pop(0) - text += " LCS (life card cycle): %d" % lcs - text += " SW: %02X %02X" % (sw1, sw2) + lcs = historical_bytes[0] + sw1 = historical_bytes[1] + sw2 = historical_bytes[2] + text.append(" LCS (life card cycle): %d" % lcs) + text.append(" SW: %02X %02X" % (sw1, sw2)) elif tag == 15: - text += " (application identifier)\n" - text += " Application identifier: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX) + text.append(" (application identifier)\n") + text.append(" Application identifier: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX)) else: - text += " (unknown)\n" - text += " Value: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX) + text.append(" (unknown)\n") + text.append(" Value: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX)) # consume len bytes of historic - for i in range(len): - historical_bytes.pop(0) + del historical_bytes[0:len] - return text + return ''.join(text) def analyse_histrorical_bytes(historical_bytes): - text = "" - hb_category = historical_bytes.pop(0) + text = [] # return if we have NO historical bytes - if hb_category == None: - return text + if len(historical_bytes) == 0: + return "" + + hb_category = historical_bytes.pop(0) - text += " Category indicator byte: 0x%02X" % hb_category + text.append(" Category indicator byte: 0x%02X" % hb_category) if hb_category == 0x00: - text += " (compact TLV data object)\n"; + text.append(" (compact TLV data object)\n") - if historical_bytes.length() < 3: - text += " Error in the ATR: expecting 3 bytes and got %d" % historical_bytes.length() - return text + if len(historical_bytes) < 3: + text.append(" Error in the ATR: expecting 3 bytes and got %d" % len(historical_bytes)) + return ''.join(text) # get the 3 last bytes status = historical_bytes[-3:] del historical_bytes[-3:] while len(historical_bytes) > 0: - text += compact_tlv(historical_bytes) + text.append(compact_tlv(historical_bytes)) (lcs, sw1, sw2) = status[:3] - text += " Mandatory status indicator (3 last bytes)\n"; - text += " LCS (life card cycle): %d (%s)" % (lcs, lcs(lcs)) - text += " SW: %02X%02X (%s)" % (sw1, sw1, "") #Chipcard::PCSC::Card::ISO7816Error("$sw1 $sw2")) + text.append(" Mandatory status indicator (3 last bytes)\n") + text.append(" LCS (life card cycle): %d (%s)" % (lcs, life_cycle_status(lcs))) + text.append( " SW: %02X%02X (%s)" % (sw1, sw1, "")) #Chipcard::PCSC::Card::ISO7816Error("$sw1 $sw2")) elif hb_category == 0x80: - text += " (compact TLV data object)\n" + text.append(" (compact TLV data object)\n") while len(historical_bytes) > 0: - text += compact_tlv(historical_bytes) + text.append(compact_tlv(historical_bytes)) elif hb_category == 0x10: - text += " (next byte is the DIR data reference)" + text.append(" (next byte is the DIR data reference)") data_ref = historical_bytes.pop(0) - text += " DIR data reference: %d", data_ref + text.append(" DIR data reference: %d" % data_ref) elif hb_category in (0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F): - text += " (Reserved for future use)"; + text.append(" (Reserved for future use)") else: - text += " (proprietary format)"; + text.append(" (proprietary format)") return text This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-07-05 19:14:41
|
Revision: 295 http://pyscard.svn.sourceforge.net/pyscard/?rev=295&view=rev Author: ludov Date: 2009-07-05 19:14:31 +0000 (Sun, 05 Jul 2009) Log Message: ----------- add color for text output Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-06-26 14:54:32 UTC (rev 294) +++ trunk/contrib/parseATR/parseATR.py 2009-07-05 19:14:31 UTC (rev 295) @@ -550,7 +550,7 @@ else: text.append(" (proprietary format)") - return text + return ''.join(text) def compute_tck(atr): # do not include TS byte @@ -561,13 +561,25 @@ s ^= atr["atr"][-1]; return s +def colorize_txt(l): + magenta = "\033[35m" + normal = "\033[0m" + text = l[0] + if len(l) > 1: + text += magenta + "".join(l[1:]) + normal + return text + def atr_display_txt(atr): + return atr_display(atr, colorize_txt) + +def atr_display(atr, colorize): + text = [] TS = {0x3B: "Direct Convention", 0x3F: "Inverse Convention"} - print "TS = 0x%02X --> %s" % (atr["TS"], TS[atr["TS"]]) + text.append(["TS = 0x%02X --> " % atr["TS"], TS[atr["TS"]]]) Y1 = atr["T0"] >> 4 K = atr["T0"] & 0xF - print "T0 = 0x%02X, Y(1): b%s, K: %d (historical bytes)" % (atr["T0"], int2bin(Y1, padding = 4), K) + text.append(["T0 = 0x%02X --> " % atr["T0"], "Y(1): b%s, K: %d (historical bytes)" % (int2bin(Y1, padding = 4), K)]) for i in (1, 2, 3, 4): separator = False @@ -575,27 +587,31 @@ key = "T%s%d" % (p, i) if (atr.has_key(key)): v = atr[key] - print " T%s(%d) = 0x%02X -->" % (p, i, v), - print eval("%s(%d)" % (key, v)) + t = [" T%s(%d) = 0x%02X --> " % (p, i, v)] + t.append(eval("%s(%d)" % (key, v))) + text.append(t) separator = True if separator: - print "----" + text.append("----") if (atr.has_key("hb")): - print "Historical bytes: ", - for b in atr["hb"]: - print "0x%02X" % b, - print - print analyse_histrorical_bytes(atr["hb"]) + t = ["Historical bytes: "] + t.append(smartcard.util.toHexString(atr["hb"], smartcard.util.HEX)) + text.append(t) + text.append(analyse_histrorical_bytes(atr["hb"])) + if (atr.has_key("TCK")): - print ("TCK = 0x%02X" % atr["TCK"]), + t = ["TCK = 0x%02X " % atr["TCK"]] tck = compute_tck(atr) if tck == atr["TCK"]: - print "(correct checksum)" + t.append("(correct checksum)") else: - print "WRONG CHECKSUM, expected 0x%02X" % tck + t.append("WRONG CHECKSUM, expected 0x%02X" % tck) + text.append(t) + return "\n".join([colorize(t) for t in text]) + if __name__ == "__main__": import sys if len(sys.argv) > 1: @@ -605,4 +621,5 @@ ATR = "3F FF 95 00 FF 91 81 71 A0 47 00 44 4E 41 53 50 30 31 31 20 52 65 76 42 30 36 4E" atr = parseATR(ATR) print "ATR:", ATR - atr_display_txt(atr) + text = atr_display_txt(atr) + print text This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-07-29 21:21:58
|
Revision: 311 http://pyscard.svn.sourceforge.net/pyscard/?rev=311&view=rev Author: ludov Date: 2009-07-29 21:21:49 +0000 (Wed, 29 Jul 2009) Log Message: ----------- improve robustness add html support Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-07-27 14:08:29 UTC (rev 310) +++ trunk/contrib/parseATR/parseATR.py 2009-07-29 21:21:49 UTC (rev 311) @@ -24,6 +24,10 @@ ATR_MAX_PROTOCOLS = 7 T = -1 +class ParseAtrException(Exception): + """Base class for exceptions in this module.""" + pass + def normalize(atr): """ transform an ATR in list of integers valid input formats are @@ -95,7 +99,12 @@ atr["hb"] = atr_txt[pointer+1:pointer+1+hb_length] if len(atr["hb"]) < hb_length: - raise Exception("ERROR! ATR is truncated: %d byte(s) is/are missing" % (hb_length-len(atr["hb"]))) + missing = hb_length-len(atr["hb"]) + if missing > 1: + (t1, t2) = ("s", "are") + else: + (t1, t2) = ("", "is") + raise ParseAtrException("ERROR! ATR is truncated: %d byte%s %s missing" % (missing, t1, t2)) # Store TCK if (atr.has_key("TCK")): @@ -106,10 +115,11 @@ def TA1(v): Fi = (372, 372, 558, 744, 1116, 1488, 1860, "RFU", "RFU", 512, 768, 1024, 1536, 2048, "RFU", "RFU") Di = ("RFU", 1, 2, 4, 8, 16, 32, "RFU", 12, 20, "RFU", "RFU", "RFU", "RFU", "RFU", "RFU") + FMax = (4, 5, 6, 8, 12, 16, 20, "RFU", "RFU", 5, 7.5, 10, 15, 20, "RFU", "RFU") F = v >> 4 D = v & 0xF value = Fi[F]/Di[D] - return "Fi=%s, Di=%s, %g cycles/ETU (%d bits/s at 3.57 MHz)" % (Fi[F], Di[D], value, 3571200/value) + return "Fi=%s, Di=%s, %g cycles/ETU (%d bits/s at 4.00 MHz, %d bits/s for fMax=%d MHz)" % (Fi[F], Di[D], value, 4000000/value, FMax[F]*1000000/value, FMax[F]) def TA2(v): F = v >> 4 @@ -572,6 +582,32 @@ def atr_display_txt(atr): return atr_display(atr, colorize_txt) +html_escape_table = { + "&": "&", + '"': """, + "'": "'", + ">": ">", + "<": "<", + } + +def html_escape(text): + """Produce entities within text.""" + L=[] + for c in text: + L.append(html_escape_table.get(c,c)) + return "".join(L) + +def colorize_html(l): + text = '<span class="left">' + html_escape(l[0]) + '</span>' + if len(l) > 1: + text += '<span class="right">' + html_escape("".join(l[1:])) + '</span>' + else: + text = l[0] + return text + +def atr_display_html(atr): + return atr_display(atr, colorize_html) + def atr_display(atr, colorize): text = [] TS = {0x3B: "Direct Convention", 0x3F: "Inverse Convention"} @@ -599,7 +635,9 @@ t.append(smartcard.util.toHexString(atr["hb"], smartcard.util.HEX)) text.append(t) - text.append(analyse_histrorical_bytes(atr["hb"])) + t = analyse_histrorical_bytes(atr["hb"]) + if t: + text.append(t) if (atr.has_key("TCK")): t = ["TCK = 0x%02X " % atr["TCK"]] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-10-04 10:55:05
|
Revision: 314 http://pyscard.svn.sourceforge.net/pyscard/?rev=314&view=rev Author: ludov Date: 2009-10-04 10:54:44 +0000 (Sun, 04 Oct 2009) Log Message: ----------- move the " --> " in colorize_txt() since it is for text output only Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-10-04 09:07:37 UTC (rev 313) +++ trunk/contrib/parseATR/parseATR.py 2009-10-04 10:54:44 UTC (rev 314) @@ -576,7 +576,7 @@ normal = "\033[0m" text = l[0] if len(l) > 1: - text += magenta + "".join(l[1:]) + normal + text += " --> " + magenta + "".join(l[1:]) + normal return text def atr_display_txt(atr): @@ -611,11 +611,11 @@ def atr_display(atr, colorize): text = [] TS = {0x3B: "Direct Convention", 0x3F: "Inverse Convention"} - text.append(["TS = 0x%02X --> " % atr["TS"], TS[atr["TS"]]]) + text.append(["TS = 0x%02X" % atr["TS"], TS[atr["TS"]]]) Y1 = atr["T0"] >> 4 K = atr["T0"] & 0xF - text.append(["T0 = 0x%02X --> " % atr["T0"], "Y(1): b%s, K: %d (historical bytes)" % (int2bin(Y1, padding = 4), K)]) + text.append(["T0 = 0x%02X" % atr["T0"], "Y(1): b%s, K: %d (historical bytes)" % (int2bin(Y1, padding = 4), K)]) for i in (1, 2, 3, 4): separator = False @@ -623,12 +623,12 @@ key = "T%s%d" % (p, i) if (atr.has_key(key)): v = atr[key] - t = [" T%s(%d) = 0x%02X --> " % (p, i, v)] + t = [" T%s(%d) = 0x%02X" % (p, i, v)] t.append(eval("%s(%d)" % (key, v))) text.append(t) separator = True if separator: - text.append("----") + text.append(["----"]) if (atr.has_key("hb")): t = ["Historical bytes: "] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-10-04 11:17:13
|
Revision: 316 http://pyscard.svn.sourceforge.net/pyscard/?rev=316&view=rev Author: ludov Date: 2009-10-04 11:17:03 +0000 (Sun, 04 Oct 2009) Log Message: ----------- use a locally defined toHexString() Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-10-04 10:56:32 UTC (rev 315) +++ trunk/contrib/parseATR/parseATR.py 2009-10-04 11:17:03 UTC (rev 316) @@ -18,8 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """ -import smartcard.util - ATR_PROTOCOL_TYPE_T0 = 0 ATR_MAX_PROTOCOLS = 7 T = -1 @@ -28,6 +26,10 @@ """Base class for exceptions in this module.""" pass +def toHexString(bytes=[]): + """ return a hex list """ + return " ".join(["%02X" % b for b in bytes]) + def normalize(atr): """ transform an ATR in list of integers valid input formats are @@ -424,11 +426,11 @@ if tag == 1: text.append(" (country code, ISO 3166-1)\n") - text.append(" Country code: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX)) + text.append(" Country code: " + toHexString(historical_bytes[:len])) elif tag == 2: text.append(" (issuer identification number, ISO 7812-1)\n") - text.append(" Issuer identification number: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX)) + text.append(" Issuer identification number: " + toHexString(historical_bytes[:len])) elif tag == 3: text.append(" (card service data byte)\n") @@ -445,15 +447,15 @@ elif tag == 4: text.append(" (initial access data)\n") - text.append(" Initial access data: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX)) + text.append(" Initial access data: " + toHexString(historical_bytes[:len])) elif tag == 5: text.append(" (card issuer's data)\n") - text.append(" Card issuer data: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX)) + text.append(" Card issuer data: " + toHexString(historical_bytes[:len])) elif tag == 6: text.append(" (pre-issuing data)\n") - text.append(" Data: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX)) + text.append(" Data: " + toHexString(historical_bytes[:len])) elif tag == 7: text.append(" (card capabilities)\n") @@ -503,11 +505,11 @@ elif tag == 15: text.append(" (application identifier)\n") - text.append(" Application identifier: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX)) + text.append(" Application identifier: " + toHexString(historical_bytes[:len])) else: text.append(" (unknown)\n") - text.append(" Value: " + smartcard.util.toHexString(historical_bytes[:len], smartcard.util.HEX)) + text.append(" Value: " + toHexString(historical_bytes[:len])) # consume len bytes of historic del historical_bytes[0:len] @@ -632,7 +634,7 @@ if (atr.has_key("hb")): t = ["Historical bytes: "] - t.append(smartcard.util.toHexString(atr["hb"], smartcard.util.HEX)) + t.append(toHexString(atr["hb"])) text.append(t) t = analyse_histrorical_bytes(atr["hb"]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-10-04 13:26:39
|
Revision: 317 http://pyscard.svn.sourceforge.net/pyscard/?rev=317&view=rev Author: ludov Date: 2009-10-04 13:26:23 +0000 (Sun, 04 Oct 2009) Log Message: ----------- try to find card description for a given ATR Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-10-04 11:17:03 UTC (rev 316) +++ trunk/contrib/parseATR/parseATR.py 2009-10-04 13:26:23 UTC (rev 317) @@ -652,6 +652,25 @@ return "\n".join([colorize(t) for t in text]) +def match_atr(atr): + """ try to find card description for a given ATR """ + card = [] + file = open("smartcard_list.txt") + for line in file: + if line.startswith("#"): + continue + line = line.rstrip("\n") + + if line == atr: + # found the ATR + for desc in file: + if desc == "\n": + break; + # get all the possible card descriptions + card.append(desc.strip()) + file.close() + return card + if __name__ == "__main__": import sys if len(sys.argv) > 1: @@ -663,3 +682,9 @@ print "ATR:", ATR text = atr_display_txt(atr) print text + + card = match_atr(ATR) + if card: + print "\nPossibly identified card:", " ".join(card) + else: + print "\nUnknown card" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-10-04 14:19:31
|
Revision: 318 http://pyscard.svn.sourceforge.net/pyscard/?rev=318&view=rev Author: ludov Date: 2009-10-04 14:19:19 +0000 (Sun, 04 Oct 2009) Log Message: ----------- normalize ATR before matching Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-10-04 13:26:23 UTC (rev 317) +++ trunk/contrib/parseATR/parseATR.py 2009-10-04 14:19:19 UTC (rev 318) @@ -655,6 +655,7 @@ def match_atr(atr): """ try to find card description for a given ATR """ card = [] + atr = toHexString(normalize(atr)) file = open("smartcard_list.txt") for line in file: if line.startswith("#"): @@ -679,7 +680,7 @@ #ATR = "3B A7 00 40 18 80 65 A2 08 01 01 52" ATR = "3F FF 95 00 FF 91 81 71 A0 47 00 44 4E 41 53 50 30 31 31 20 52 65 76 42 30 36 4E" atr = parseATR(ATR) - print "ATR:", ATR + print "ATR:", toHexString(normalize(ATR)) text = atr_display_txt(atr) print text This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-10-04 14:59:12
|
Revision: 319 http://pyscard.svn.sourceforge.net/pyscard/?rev=319&view=rev Author: ludov Date: 2009-10-04 14:59:00 +0000 (Sun, 04 Oct 2009) Log Message: ----------- ParseAtrException is a subclass of exceptions.Exception Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-10-04 14:19:19 UTC (rev 318) +++ trunk/contrib/parseATR/parseATR.py 2009-10-04 14:59:00 UTC (rev 319) @@ -22,10 +22,15 @@ ATR_MAX_PROTOCOLS = 7 T = -1 -class ParseAtrException(Exception): +import exceptions +class ParseAtrException(exceptions.Exception): """Base class for exceptions in this module.""" - pass + def __init__(self, text): + self.text = text + def __str__(self): + return self.text + def toHexString(bytes=[]): """ return a hex list """ return " ".join(["%02X" % b for b in bytes]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-10-21 15:39:47
|
Revision: 320 http://pyscard.svn.sourceforge.net/pyscard/?rev=320&view=rev Author: ludov Date: 2009-10-21 15:39:38 +0000 (Wed, 21 Oct 2009) Log Message: ----------- improve formating Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-10-04 14:59:00 UTC (rev 319) +++ trunk/contrib/parseATR/parseATR.py 2009-10-21 15:39:38 UTC (rev 320) @@ -460,7 +460,7 @@ elif tag == 6: text.append(" (pre-issuing data)\n") - text.append(" Data: " + toHexString(historical_bytes[:len])) + text.append(" Data: " + toHexString(historical_bytes[:len]) + "\n") elif tag == 7: text.append(" (card capabilities)\n") @@ -470,24 +470,24 @@ except: text.append("Error in the ATR: expecting 1 byte and got 0\n") else: - text.append(" Selection methods: %d" % sm) + text.append(" Selection methods: %d\n" % sm) text.append(selection_mode(sm)) elif len == 2: sm = historical_bytes[0] dc = historical_bytes[1] - text.append(" Selection methods: %d" % sm) + text.append(" Selection methods: %d\n" % sm) text.append(selection_methods(sm)) - text.append(" Data coding byte: %d" % dc) + text.append(" Data coding byte: %d\n" % dc) text.append(data_coding(dc)) elif len == 3: sm = historical_bytes[0] dc = historical_bytes[1] cc = historical_bytes[2] - text.append(" Selection methods: %d" % sm) + text.append(" Selection methods: %d\n" % sm) text.append(selection_mode(sm)) - text.append(" Data coding byte: %d" % dc) + text.append(" Data coding byte: %d\n" % dc) text.append(data_coding(dc)) - text.append(" Command chaining, length fields and logical channels: %d" % cc) + text.append(" Command chaining, length fields and logical channels: %d\n" % cc) text.append(command_chaining(cc)) else: text.append(" wrong ATR") @@ -567,7 +567,7 @@ else: text.append(" (proprietary format)") - return ''.join(text) + return text def compute_tck(atr): # do not include TS byte This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-10-21 15:53:19
|
Revision: 322 http://pyscard.svn.sourceforge.net/pyscard/?rev=322&view=rev Author: ludov Date: 2009-10-21 15:53:13 +0000 (Wed, 21 Oct 2009) Log Message: ----------- remove extra ": " Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-10-21 15:50:17 UTC (rev 321) +++ trunk/contrib/parseATR/parseATR.py 2009-10-21 15:53:13 UTC (rev 322) @@ -638,7 +638,7 @@ text.append(["----"]) if (atr.has_key("hb")): - t = ["Historical bytes: "] + t = ["Historical bytes"] t.append(toHexString(atr["hb"])) text.append(t) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-11-12 12:32:44
|
Revision: 323 http://pyscard.svn.sourceforge.net/pyscard/?rev=323&view=rev Author: ludov Date: 2009-11-12 12:32:36 +0000 (Thu, 12 Nov 2009) Log Message: ----------- use sw2 instead of sw1 when needed (typo) Thanks to Alexei Bouznik for the bug report Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-10-21 15:53:13 UTC (rev 322) +++ trunk/contrib/parseATR/parseATR.py 2009-11-12 12:32:36 UTC (rev 323) @@ -549,7 +549,7 @@ (lcs, sw1, sw2) = status[:3] text.append(" Mandatory status indicator (3 last bytes)\n") text.append(" LCS (life card cycle): %d (%s)" % (lcs, life_cycle_status(lcs))) - text.append( " SW: %02X%02X (%s)" % (sw1, sw1, "")) #Chipcard::PCSC::Card::ISO7816Error("$sw1 $sw2")) + text.append( " SW: %02X%02X (%s)" % (sw1, sw2, "")) #Chipcard::PCSC::Card::ISO7816Error("$sw1 $sw2")) elif hb_category == 0x80: text.append(" (compact TLV data object)\n") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-11-12 12:34:50
|
Revision: 324 http://pyscard.svn.sourceforge.net/pyscard/?rev=324&view=rev Author: ludov Date: 2009-11-12 12:34:38 +0000 (Thu, 12 Nov 2009) Log Message: ----------- output reformat Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-11-12 12:32:36 UTC (rev 323) +++ trunk/contrib/parseATR/parseATR.py 2009-11-12 12:34:38 UTC (rev 324) @@ -691,6 +691,6 @@ card = match_atr(ATR) if card: - print "\nPossibly identified card:", " ".join(card) + print "Possibly identified card:", " ".join(card) else: - print "\nUnknown card" + print "Unknown card" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-11-13 19:54:06
|
Revision: 325 http://pyscard.svn.sourceforge.net/pyscard/?rev=325&view=rev Author: ludov Date: 2009-11-13 19:53:58 +0000 (Fri, 13 Nov 2009) Log Message: ----------- normalize'): allow more than one space character between hex digits Thanks to Alexei Bouznik for the patch Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-11-12 12:34:38 UTC (rev 324) +++ trunk/contrib/parseATR/parseATR.py 2009-11-13 19:53:58 UTC (rev 325) @@ -41,9 +41,17 @@ "3B A7 00 40 18 80 65 A2 08 01 01 52" "3B:A7:00:40:18:80:65:A2:08:01:01:52" """ - atr = atr.replace(":", " ") - atr = atr.split(" ") - atr = map(lambda x: int(x,16), atr) + atr = atr.replace(":", "") + atr = atr.replace(" ", "") + + res = [] + while len(atr) >= 2: + byte, atr = atr[:2], atr[2:] + res.append(byte) + if len(atr) > 0: + raise ParseAtrException('warning: odd string, remainder: %r' % atr) + + atr = map(lambda x: int(x,16), res) return atr def int2bin(i, padding = 8): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-11-13 19:56:22
|
Revision: 326 http://pyscard.svn.sourceforge.net/pyscard/?rev=326&view=rev Author: ludov Date: 2009-11-13 19:56:15 +0000 (Fri, 13 Nov 2009) Log Message: ----------- add missing formatting \n Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-11-13 19:53:58 UTC (rev 325) +++ trunk/contrib/parseATR/parseATR.py 2009-11-13 19:56:15 UTC (rev 326) @@ -455,16 +455,16 @@ if cs == None: text.append(" Error in the ATR: expecting 1 byte and got 0") else: - text.append(" Card service data byte: %d" % cs) + text.append(" Card service data byte: %d\n" % cs) text.append(card_service(cs)) elif tag == 4: text.append(" (initial access data)\n") - text.append(" Initial access data: " + toHexString(historical_bytes[:len])) + text.append(" Initial access data: " + toHexString(historical_bytes[:len]) + "\n") elif tag == 5: text.append(" (card issuer's data)\n") - text.append(" Card issuer data: " + toHexString(historical_bytes[:len])) + text.append(" Card issuer data: " + toHexString(historical_bytes[:len]) + "\n") elif tag == 6: text.append(" (pre-issuing data)\n") @@ -513,7 +513,7 @@ lcs = historical_bytes[0] sw1 = historical_bytes[1] sw2 = historical_bytes[2] - text.append(" LCS (life card cycle): %d" % lcs) + text.append(" LCS (life card cycle): %d\n" % lcs) text.append(" SW: %02X %02X" % (sw1, sw2)) elif tag == 15: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-11-22 14:15:22
|
Revision: 330 http://pyscard.svn.sourceforge.net/pyscard/?rev=330&view=rev Author: ludov Date: 2009-11-22 14:15:15 +0000 (Sun, 22 Nov 2009) Log Message: ----------- match_atr(): accept an atr_file argument. Default value is "smartcard_list.txt" Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-11-16 10:51:53 UTC (rev 329) +++ trunk/contrib/parseATR/parseATR.py 2009-11-22 14:15:15 UTC (rev 330) @@ -669,11 +669,11 @@ return "\n".join([colorize(t) for t in text]) -def match_atr(atr): +def match_atr(atr, atr_file = "smartcard_list.txt"): """ try to find card description for a given ATR """ card = [] atr = toHexString(normalize(atr)) - file = open("smartcard_list.txt") + file = open(atr_file) for line in file: if line.startswith("#"): continue This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-11-22 14:16:48
|
Revision: 331 http://pyscard.svn.sourceforge.net/pyscard/?rev=331&view=rev Author: ludov Date: 2009-11-22 14:16:37 +0000 (Sun, 22 Nov 2009) Log Message: ----------- catch an explicite IndexError exception instead of all Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-11-22 14:15:15 UTC (rev 330) +++ trunk/contrib/parseATR/parseATR.py 2009-11-22 14:16:37 UTC (rev 331) @@ -479,7 +479,7 @@ if len == 1: try: sm = historical_bytes[0] - except: + except IndexError: text.append("Error in the ATR: expecting 1 byte and got 0\n") else: text.append(" Selection methods: %d\n" % sm) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-11-22 14:25:30
|
Revision: 332 http://pyscard.svn.sourceforge.net/pyscard/?rev=332&view=rev Author: ludov Date: 2009-11-22 14:25:23 +0000 (Sun, 22 Nov 2009) Log Message: ----------- parseATR.py:672:30: E251 no spaces around keyword / parameter equals Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-11-22 14:16:37 UTC (rev 331) +++ trunk/contrib/parseATR/parseATR.py 2009-11-22 14:25:23 UTC (rev 332) @@ -669,7 +669,7 @@ return "\n".join([colorize(t) for t in text]) -def match_atr(atr, atr_file = "smartcard_list.txt"): +def match_atr(atr, atr_file="smartcard_list.txt"): """ try to find card description for a given ATR """ card = [] atr = toHexString(normalize(atr)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-11-28 15:26:29
|
Revision: 360 http://pyscard.svn.sourceforge.net/pyscard/?rev=360&view=rev Author: ludov Date: 2009-11-28 15:26:22 +0000 (Sat, 28 Nov 2009) Log Message: ----------- correctly handle invalid TS byte Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-11-24 08:32:59 UTC (rev 359) +++ trunk/contrib/parseATR/parseATR.py 2009-11-28 15:26:22 UTC (rev 360) @@ -630,7 +630,7 @@ def atr_display(atr, colorize): text = [] TS = {0x3B: "Direct Convention", 0x3F: "Inverse Convention"} - text.append(["TS = 0x%02X" % atr["TS"], TS[atr["TS"]]]) + text.append(["TS = 0x%02X" % atr["TS"], TS.get(atr["TS"], "Invalid")]) Y1 = atr["T0"] >> 4 K = atr["T0"] & 0xF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-11-28 15:38:25
|
Revision: 361 http://pyscard.svn.sourceforge.net/pyscard/?rev=361&view=rev Author: ludov Date: 2009-11-28 15:38:19 +0000 (Sat, 28 Nov 2009) Log Message: ----------- reformat comment Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-11-28 15:26:22 UTC (rev 360) +++ trunk/contrib/parseATR/parseATR.py 2009-11-28 15:38:19 UTC (rev 361) @@ -26,7 +26,7 @@ class ParseAtrException(exceptions.Exception): - """Base class for exceptions in this module.""" + """ Base class for exceptions in this module """ def __init__(self, text): self.text = text This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-11-28 16:08:09
|
Revision: 362 http://pyscard.svn.sourceforge.net/pyscard/?rev=362&view=rev Author: ludov Date: 2009-11-28 16:08:02 +0000 (Sat, 28 Nov 2009) Log Message: ----------- correctly handle invalid TA1 byte Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-11-28 15:38:19 UTC (rev 361) +++ trunk/contrib/parseATR/parseATR.py 2009-11-28 16:08:02 UTC (rev 362) @@ -137,9 +137,16 @@ FMax = (4, 5, 6, 8, 12, 16, 20, "RFU", "RFU", 5, 7.5, 10, 15, 20, "RFU", "RFU") F = v >> 4 D = v & 0xF - value = Fi[F] / Di[D] - return "Fi=%s, Di=%s, %g cycles/ETU (%d bits/s at 4.00 MHz, %d bits/s for fMax=%d MHz)" % (Fi[F], Di[D], value, 4000000 / value, FMax[F] * 1000000 / value, FMax[F]) + text = "Fi=%s, Di=%s" % (Fi[F], Di[D]) + if "RFU" in [Fi[F], Di[D]]: + text += ", INVALID VALUE" + else: + value = Fi[F] / Di[D] + text += ", %g cycles/ETU (%d bits/s at 4.00 MHz, %d bits/s for fMax=%d MHz)" % (value, 4000000 / value, FMax[F] * 1000000 / value, FMax[F]) + + return text + def TA2(v): F = v >> 4 D = v & 0xF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lu...@us...> - 2009-12-06 11:14:23
|
Revision: 363 http://pyscard.svn.sourceforge.net/pyscard/?rev=363&view=rev Author: ludov Date: 2009-12-06 11:14:15 +0000 (Sun, 06 Dec 2009) Log Message: ----------- add a default return value for life_cycle_status() Modified Paths: -------------- trunk/contrib/parseATR/parseATR.py Modified: trunk/contrib/parseATR/parseATR.py =================================================================== --- trunk/contrib/parseATR/parseATR.py 2009-11-28 16:08:02 UTC (rev 362) +++ trunk/contrib/parseATR/parseATR.py 2009-12-06 11:14:15 UTC (rev 363) @@ -274,6 +274,8 @@ def life_cycle_status(lcs): # Table 13 - Life cycle status byte # ISO 7816-4:2004, page 21 + text = "Unknown" + if lcs > 15: text = "Proprietary" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |