def testcase_ATR3(self): """Simera 3.13.""" a = ATR([0x3B, 0x16, 0x18, 0x20, 0x02, 0x01, 0x00, 0x80, 0x0D]) historicalbytes = [0x20, 0x02, 0x01, 0x00, 0x80, 0x0D] self.assertEquals(a.getHistoricalBytes(), historicalbytes) self.assertEquals(a.getChecksum(), None) self.assert_(a.isT0Supported()) self.assert_(not a.isT1Supported()) self.assert_(not a.isT15Supported())
def testcase_ATR2(self): """Palmera Protect V2.""" a = ATR([0x3B, 0x65, 0x00, 0x00, 0x9C, 0x02, 0x02, 0x01, 0x02]) historicalbytes = [0x9C, 0x02, 0x02, 0x01, 0x02] self.assertEqual(a.getHistoricalBytes(), historicalbytes) self.assertEqual(a.getChecksum(), None) self.assertTrue(a.isT0Supported()) self.assertTrue(not a.isT1Supported()) self.assertTrue(not a.isT15Supported())
def testcase_ATR2(self): """Palmera Protect V2.""" a = ATR([0x3B, 0x65, 0x00, 0x00, 0x9C, 0x02, 0x02, 0x01, 0x02]) historicalbytes = [0x9C, 0x02, 0x02, 0x01, 0x02] self.assertEquals(a.getHistoricalBytes(), historicalbytes) self.assertEquals(a.getChecksum(), None) self.assert_(a.isT0Supported()) self.assert_(not a.isT1Supported()) self.assert_(not a.isT15Supported())
def testcase_ATR5(self): """Demo Vitale online IGEA340""" a = ATR([0x3F, 0x65, 0x25, 0x00, 0x52, 0x09, 0x6A, 0x90, 0x00]) historicalbytes = [0x52, 0x09, 0x6A, 0x90, 0x00] self.assertEqual(a.getHistoricalBytes(), historicalbytes) self.assertEqual(a.getChecksum(), None) self.assertTrue(a.isT0Supported()) self.assertTrue(not a.isT1Supported()) self.assertTrue(not a.isT15Supported())
def testcase_ATR3(self): """Simera 3.13.""" a = ATR([0x3B, 0x16, 0x18, 0x20, 0x02, 0x01, 0x00, 0x80, 0x0D]) historicalbytes = [0x20, 0x02, 0x01, 0x00, 0x80, 0x0D] self.assertEqual(a.getHistoricalBytes(), historicalbytes) self.assertEqual(a.getChecksum(), None) self.assertTrue(a.isT0Supported()) self.assertTrue(not a.isT1Supported()) self.assertTrue(not a.isT15Supported())
def testcase_ATR5(self): """Demo Vitale online IGEA340""" a = ATR([0x3F, 0x65, 0x25, 0x00, 0x52, 0x09, 0x6A, 0x90, 0x00]) historicalbytes = [0x52, 0x09, 0x6A, 0x90, 0x00] self.assertEquals(a.getHistoricalBytes(), historicalbytes) self.assertEquals(a.getChecksum(), None) self.assert_(a.isT0Supported()) self.assert_(not a.isT1Supported()) self.assert_(not a.isT15Supported())
def test_ATR_get(self): atr = "3B F2 95 12 34 01 36 06" a = ATR(toBytes(atr)) self.assertEqual(a.getTA1(), 0x95) self.assertEqual(a.getTB1(), 0x12) self.assertEqual(a.getTC1(), 0x34) self.assertEqual(a.getTD1(), 0x01) self.assertEqual(a.getHistoricalBytes(), [0x36, 0x06]) self.assertFalse(a.isT15Supported()) self.assertEqual(str(a), atr)
def testcase_ATR4(self): """SIMRock'n Tree""" a = ATR([0x3B, 0x77, 0x94, 0x00, 0x00, 0x82, 0x30, 0x00, 0x13, 0x6C, 0x9F, 0x22]) historicalbytes = [0x82, 0x30, 0x00, 0x13, 0x6C, 0x9F, 0x22] self.assertEqual(a.getHistoricalBytes(), historicalbytes) self.assertEqual(a.getChecksum(), None) self.assertTrue(a.isT0Supported()) self.assertTrue(not a.isT1Supported()) self.assertTrue(not a.isT15Supported())
def translate_atr(atr): atr = ATR(atr) print atr print 'historical bytes: ', toHexString( atr.getHistoricalBytes() ) print 'checksum: ', "0x%X" % atr.getChecksum() print 'checksum OK: ', atr.checksumOK print 'T0 supported: ', atr.isT0Supported() print 'T1 supported: ', atr.isT1Supported() print 'T15 supported: ', atr.isT15Supported()
def testcase_ATR4(self): """SIMRock'n Tree""" a = ATR([0x3B, 0x77, 0x94, 0x00, 0x00, 0x82, 0x30, 0x00, 0x13, 0x6C, 0x9F, 0x22]) historicalbytes = [0x82, 0x30, 0x00, 0x13, 0x6C, 0x9F, 0x22] self.assertEquals(a.getHistoricalBytes(), historicalbytes) self.assertEquals(a.getChecksum(), None) self.assert_(a.isT0Supported()) self.assert_(not a.isT1Supported()) self.assert_(not a.isT15Supported())
def info(self): """print the type of the card on the reader""" atr = ATR(self.connection.getATR()) historical_byte = toHexString(atr.getHistoricalBytes(), 0) print(historical_byte) print(historical_byte[-17:-12]) card_name = historical_byte[-17:-12] name = option.cards.get(card_name, "") print( f"Card Name: {name}\n\tT0 {atr.isT0Supported()}\n\tT1 {atr.isT1Supported()}\n\tT1 {atr.isT15Supported()}" )
def getinfo(connection: CardConnectionDecorator) -> dict: atr = ATR(connection.getATR()) hb = toHexString(atr.getHistoricalBytes()) cardname = hb[-17:-12] name = cardnameMap.get(cardname, "Unknown " + str(cardname)) return { "Name": name, "T0": atr.isT0Supported(), "T1": atr.isT1Supported(), "T15": atr.isT15Supported() }
def testcase_ATR1(self): """Usimera Classic 2.""" a = ATR([0x3B, 0x9E, 0x95, 0x80, 0x1F, 0xC3, 0x80, 0x31, 0xA0, 0x73, 0xBE, 0x21, 0x13, 0x67, 0x29, 0x02, 0x01, 0x01, 0x81, 0xCD, 0xB9]) historicalbytes = [0x80, 0x31, 0xA0, 0x73, 0xBE, 0x21, 0x13, 0x67, 0x29, 0x02, 0x01, 0x01, 0x81, 0xCD] self.assertEquals(a.getHistoricalBytes(), historicalbytes) self.assertEquals(a.getChecksum(), 0xB9) self.assert_(a.checksumOK) self.assert_(a.isT0Supported()) self.assert_(not a.isT1Supported()) self.assert_(a.isT15Supported())
def testcase_ATR1(self): """Usimera Classic 2.""" a = ATR([0x3B, 0x9E, 0x95, 0x80, 0x1F, 0xC3, 0x80, 0x31, 0xA0, 0x73, 0xBE, 0x21, 0x13, 0x67, 0x29, 0x02, 0x01, 0x01, 0x81, 0xCD, 0xB9]) historicalbytes = [0x80, 0x31, 0xA0, 0x73, 0xBE, 0x21, 0x13, 0x67, 0x29, 0x02, 0x01, 0x01, 0x81, 0xCD] self.assertEqual(a.getHistoricalBytes(), historicalbytes) self.assertEqual(a.getChecksum(), 0xB9) self.assertTrue(a.checksumOK) self.assertTrue(a.isT0Supported()) self.assertTrue(not a.isT1Supported()) self.assertTrue(a.isT15Supported())
def getATR(): atr = ATR([ 0x3B, 0x9E, 0x95, 0x80, 0x1F, 0xC3, 0x80, 0x31, 0xA0, 0x73, 0xBE, 0x21, 0x13, 0x67, 0x29, 0x02, 0x01, 0x01, 0x81, 0xCD, 0xB9 ]) print(atr) print('historical bytes: ', toHexString(atr.getHistoricalBytes())) print('checksum: ', "0x%X" % atr.getChecksum()) print('checksum OK: ', atr.checksumOK) print('T0 supported: ', atr.isT0Supported()) print('T1 supported: ', atr.isT1Supported()) print('T15 supported: ', atr.isT15Supported())
def testcase_ATR7(self): """Protect V3 T=1""" a = ATR([0x3B, 0xE5, 0x00, 0x00, 0x81, 0x21, 0x45, 0x9C, 0x10, 0x01, 0x00, 0x80, 0x0D]) historicalbytes = [0x9C, 0x10, 0x01, 0x00, 0x80] self.assertEqual(a.getHistoricalBytes(), historicalbytes) self.assertEqual(a.getChecksum(), 0x0D) self.assertTrue(not a.isT0Supported()) self.assertTrue(a.isT1Supported()) self.assertTrue(not a.isT15Supported()) self.assertTrue(a.checksumOK) self.assertTrue(a.getTB1() == 0x00) self.assertTrue(a.getTC1() == 0x00) self.assertTrue(a.getTD1() == 0x81) self.assertTrue(a.TD[2 - 1] == 0x21) # TD2 self.assertTrue(a.TB[3 - 1] == 0x45) # TB3
def testcase_ATR7(self): """Protect V3 T=1""" a = ATR([0x3B, 0xE5, 0x00, 0x00, 0x81, 0x21, 0x45, 0x9C, 0x10, 0x01, 0x00, 0x80, 0x0D]) historicalbytes = [0x9C, 0x10, 0x01, 0x00, 0x80] self.assertEquals(a.getHistoricalBytes(), historicalbytes) self.assertEquals(a.getChecksum(), 0x0D) self.assert_(not a.isT0Supported()) self.assert_(a.isT1Supported()) self.assert_(not a.isT15Supported()) self.assert_(a.checksumOK) self.assert_(a.getTB1() == 0x00) self.assert_(a.getTC1() == 0x00) self.assert_(a.getTD1() == 0x81) self.assert_(a.TD[2 - 1] == 0x21) # TD2 self.assert_(a.TB[3 - 1] == 0x45) # TB3
def info(): global connection recognized_cards = { '00 01': 'MIFARE Classic 1K', '00 02': 'MIFARE Classic 4K', '00 03': 'MIFARE Ultralight', '00 26': 'MIFARE Mini', 'F0 04': 'Topaz and Jewel', 'F0 11': 'FeliCa 212K/424K' } if connection: print('[*] Tag Information\n') atr = ATR(connection.getATR()) hb = toHexString(atr.getHistoricalBytes()) name_key = hb[-17:-12] card_name = recognized_cards.get(name_key, 'Unknown') print('[+] Card Name: ', card_name) print('[+] T0 Support: ', atr.isT0Supported()) print('[+] T1 Support: ', atr.isT1Supported()) print('[+] T15 Support:', atr.isT15Supported())
def main(): global ATRS get_smartcards_list() cardtype = AnyCardType() while True: cardrequest = CardRequest(timeout=120, cardType=cardtype) cardservice = cardrequest.waitforcard() cardservice.connection.connect() atrBytes = cardservice.connection.getATR() atr = ATR(atrBytes) print(atr) print('historical bytes: ', toHexString(atr.getHistoricalBytes())) print('checksum: ', "0x%X" % atr.getChecksum()) print('checksum OK: ', atr.checksumOK) print('T0 supported: ', atr.isT0Supported()) print('T1 supported: ', atr.isT1Supported()) print('T15 supported: ', atr.isT15Supported()) if (ATRS[toHexString(atrBytes)]): print(ATRS[toHexString(atrBytes)]) print(cardservice.connection) send(cardservice.connection) sleep(5) return 0
for reader in readers(): try: connection = reader.createConnection() connection.connect() atr = toHexString(connection.getATR()) atr1 = atr.split(' ', 18) atr2 = toHex(atr1) atr3 = ATR(atr2) cardtype = AnyCardType() cardrequest = CardRequest(timeout=10, cardType=cardtype) cardservice = cardrequest.waitforcard() cardservice.connection.connect() READ = [0x00, 0xCA, 0x00, 0x00] apdu = READ print(reader, ': ', toHexString(connection.getATR())) print('Historical bytes: ', toHexString(atr3.getHistoricalBytes())) f.write(toHexString(connection.getATR())) f.write("\n") print("Send ACR to file") print('Sending ', toHexString(apdu), '...') response, status1, status2 = cardservice.connection.transmit(apdu) print('Response: ', response, ' | status: ', "%x %x" % (status1, status2)) uid = toHexString(response).replace(' ', '') print('UID: ', uid) if 'win32' == sys.platform: print('press Enter to continue') sys.stdin.read(1) except NoCardException:
This file is part of pyscard. pyscard is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. pyscard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ from smartcard.ATR import ATR from smartcard.util import toHexString atr = ATR([0x3B, 0x9E, 0x95, 0x80, 0x1F, 0xC3, 0x80, 0x31, 0xA0, 0x73, 0xBE, 0x21, 0x13, 0x67, 0x29, 0x02, 0x01, 0x01, 0x81, 0xCD, 0xB9]) print atr print 'historical bytes: ', toHexString(atr.getHistoricalBytes()) print 'checksum: ', "0x%X" % atr.getChecksum() print 'checksum OK: ', atr.checksumOK print 'T0 supported: ', atr.isT0Supported() print 'T1 supported: ', atr.isT1Supported() print 'T15 supported: ', atr.isT15Supported()
def testcase_ATR6(self): """Simagine 2002""" a = ATR([0x3B, 0x16, 0x94, 0x20, 0x02, 0x01, 0x00, 0x00, 0x0D]) historicalbytes = [0x20, 0x02, 0x01, 0x00, 0x00, 0x0D] self.assertEqual(a.getHistoricalBytes(), historicalbytes) self.assertEqual(a.getChecksum(), None)
data, sw1, sw2 = connection.transmit(COMMAND) if cmd == "firmver": print cmd +": "+ ''.join(chr(i) for i in data)+chr(sw1)+chr(sw2) else: print cmd + ": " + toHexString(data) print "Status words: %02X %02X" % (sw1, sw2) if (sw1, sw2) == (0x90, 0x0): print "Status: The operation completed successfully." elif (sw1, sw2) == (0x63, 0x0): print "Status: The operation failed." elif type(COMMAND) == str: if COMMAND == "info": print "###Tag Info###" atr = ATR(connection.getATR()) hb = toHexString(atr.getHistoricalBytes()) cardname = hb[-17:-12] cardnameMap = { "00 01": "MIFARE Classic 1K", "00 02": "MIFARE Classic 4K", "00 03": "MIFARE Ultralight", "00 26": "MIFARE Mini", "F0 04": "Topaz and Jewel", "F0 11": "FeliCa 212K", "F0 11": "FeliCa 424K" } name = cardnameMap.get(cardname, "unknown") print "Card Name: "+ name print "T0 supported: ", atr.isT0Supported() print "T1 supported: ", atr.isT1Supported() print "T15 suppoerted: ", atr.isT15Supported()
pyscard is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. pyscard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with pyscard; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ from smartcard.ATR import ATR from smartcard.util import toHexString atr = ATR([ 0x3B, 0x9E, 0x95, 0x80, 0x1F, 0xC3, 0x80, 0x31, 0xA0, 0x73, 0xBE, 0x21, 0x13, 0x67, 0x29, 0x02, 0x01, 0x01, 0x81, 0xCD, 0xB9 ]) print atr print 'historical bytes: ', toHexString(atr.getHistoricalBytes()) print 'checksum: ', "0x%X" % atr.getChecksum() print 'checksum OK: ', atr.checksumOK print 'T0 supported: ', atr.isT0Supported() print 'T1 supported: ', atr.isT1Supported() print 'T15 supported: ', atr.isT15Supported()
def testcase_ATR6(self): """Simagine 2002""" a = ATR([0x3B, 0x16, 0x94, 0x20, 0x02, 0x01, 0x00, 0x00, 0x0D]) historicalbytes = [0x20, 0x02, 0x01, 0x00, 0x00, 0x0D] self.assertEquals(a.getHistoricalBytes(), historicalbytes) self.assertEquals(a.getChecksum(), None)