Add RFID_Card class. (I just discovered that section 3.2.2 of PC/SC 2.01 specifies handling of contactless storage cards such as mifare through an emulated APDU interface.)
git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@204 f711b948-2313-0410-aaa9-d29f33439f0b
This commit is contained in:
parent
a1b12fe941
commit
a810933abc
|
@ -1,5 +1,6 @@
|
|||
import utils, TLV_utils
|
||||
from iso_7816_4_card import *
|
||||
from rfid_card import RFID_Card
|
||||
import building_blocks
|
||||
|
||||
class MTCOS_Card(ISO_7816_4_Card,building_blocks.Card_with_80_aa):
|
||||
|
@ -12,6 +13,11 @@ class MTCOS_Card(ISO_7816_4_Card,building_blocks.Card_with_80_aa):
|
|||
("3BFE9100FF918171FE40004120001177B1024D54434F537301CF", None),
|
||||
]
|
||||
|
||||
STOP_ATRS = [
|
||||
# Don't use this class for the contactless interface, but instead MTCOS_Card_RFID below
|
||||
("3b8980014d54434f53730102013f", None),
|
||||
]
|
||||
|
||||
COMMANDS = {
|
||||
"list_dirs": building_blocks.Card_with_80_aa.cmd_listdirs,
|
||||
"list_files": building_blocks.Card_with_80_aa.cmd_listfiles,
|
||||
|
@ -56,6 +62,8 @@ class MTCOS_Card(ISO_7816_4_Card,building_blocks.Card_with_80_aa):
|
|||
(0x8E, 0x0C, None, "3DES-Key (Triple DES with 2 or 3 keys)"),
|
||||
(0x81, 0x00, None, " - ECB"),
|
||||
(0x81, 0x01, None, " - CBC"),
|
||||
)
|
||||
cryptographic_algorithm_byte_descriptions_old = (
|
||||
(0x80, 0x80, None, "Asymmetric Algorithm"),
|
||||
(0xC0, 0x80, None, "Private Key"),
|
||||
(0xB0, 0x80, None, "RSA"),
|
||||
|
@ -63,6 +71,11 @@ class MTCOS_Card(ISO_7816_4_Card,building_blocks.Card_with_80_aa):
|
|||
(0xB2, 0x82, None, " - PKCS#1 type 2 and 2"),
|
||||
(0xB4, 0x84, None, " - ISO/IEC 9796-2"),
|
||||
)
|
||||
cryptographic_algorithm_byte_descriptions_new = (
|
||||
(0x80, 0x00, None, "Last Byte"),
|
||||
(0x80, 0x80, None, "At least one byte following"),
|
||||
)
|
||||
## FIXME: This is broken, the MTCOS guys changed their bitflags, no way to distinguish old from new
|
||||
def decode_83(value):
|
||||
## 0x83 in 0xA5 is either "Cryptographic algorithm and allowed applications" or
|
||||
## "Default key reference for authentication commands in this environment"
|
||||
|
@ -199,3 +212,14 @@ class MTCOS_Card(ISO_7816_4_Card,building_blocks.Card_with_80_aa):
|
|||
}
|
||||
TLV_OBJECTS[TLV_utils.context_FCI] = TLV_OBJECTS[TLV_utils.context_FCP]
|
||||
|
||||
class MTCOS_Card_RFID(MTCOS_Card,RFID_Card):
|
||||
DRIVER_NAME = ["MTCOS RFID"]
|
||||
ATRS = [
|
||||
("3b8980014d54434f53730102013f", None),
|
||||
]
|
||||
|
||||
STOP_ATRS = []
|
||||
|
||||
COMMANDS = {}
|
||||
COMMANDS.update(MTCOS_Card.COMMANDS)
|
||||
COMMANDS.update(RFID_Card.COMMANDS)
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
import utils
|
||||
from generic_card import *
|
||||
|
||||
class RFID_Card(Card):
|
||||
DRIVER_NAME = ["RFID"]
|
||||
APDU_GET_UID = utils.C_APDU(CLA=0xff, INS=0xCA, p1=0, p2=0, Le=0)
|
||||
|
||||
ATRS = [
|
||||
# Contactless storage cards
|
||||
("3b8f8001804f0ca000000306......00000000..", None),
|
||||
# All other cards that follow the general ATR format
|
||||
("3b8.8001.*", None),
|
||||
]
|
||||
|
||||
STOP_ATRS = [
|
||||
# Mifare, handled below
|
||||
("3b8f8001804f0ca000000306..000[1-3]00000000..", None),
|
||||
]
|
||||
|
||||
def get_uid(self):
|
||||
result = self.send_apdu(utils.C_APDU(self.APDU_GET_UID))
|
||||
return result.data
|
||||
|
||||
def cmd_get_uid(self):
|
||||
uid = self.get_uid()
|
||||
print utils.hexdump(uid, short=True)
|
||||
|
||||
COMMANDS = {
|
||||
"get_uid": cmd_get_uid,
|
||||
}
|
||||
|
||||
class RFID_Storage_Card(RFID_Card):
|
||||
STOP_ATRS = []
|
||||
ATRS = []
|
||||
|
||||
class Mifare_Card(RFID_Storage_Card):
|
||||
pass
|
||||
|
||||
class Mifare_Classic_Card(Mifare_Card):
|
||||
DRIVER_NAME = ["Mifare Classic"]
|
||||
|
||||
ATRS = [
|
||||
# Classic 1k
|
||||
("3b8f8001804f0ca000000306..000100000000..", None),
|
||||
# Classic 4k
|
||||
("3b8f8001804f0ca000000306..000200000000..", None),
|
||||
]
|
||||
|
||||
class Mifare_Ultralight_Card(Mifare_Card):
|
||||
DRIVER_NAME = ["Mifare Ultralight"]
|
||||
|
||||
ATRS = [
|
||||
# Ultralight
|
||||
("3b8f8001804f0ca000000306..000300000000..", None),
|
||||
]
|
Loading…
Reference in New Issue