2005-09-29 19:05:55 +00:00
|
|
|
import utils, binascii
|
2005-09-29 03:39:14 +00:00
|
|
|
from generic_card import *
|
2005-09-30 04:13:34 +00:00
|
|
|
from utils import APDU
|
2005-09-29 03:39:14 +00:00
|
|
|
|
|
|
|
class Java_Card(Card):
|
2005-09-30 04:13:34 +00:00
|
|
|
APDU_SELECT_APPLICATION = APDU("\x00\xa4\x04\x00")
|
2005-09-29 03:39:14 +00:00
|
|
|
DRIVER_NAME = "Generic Java"
|
2005-09-29 19:05:55 +00:00
|
|
|
APPLICATIONS = {
|
|
|
|
"muscle": "\xa0\x00\x00\x00\x01\x01"
|
|
|
|
}
|
2005-09-29 03:39:14 +00:00
|
|
|
|
|
|
|
def __init__(self, card = None):
|
|
|
|
Card.__init__(self, card = card)
|
|
|
|
|
|
|
|
def select_application(self, aid):
|
2005-09-30 04:13:34 +00:00
|
|
|
result = self.send_apdu(
|
2005-10-07 01:50:34 +00:00
|
|
|
APDU(self.APDU_SELECT_APPLICATION,
|
2005-09-30 04:13:34 +00:00
|
|
|
content = aid) )
|
2005-09-29 03:39:14 +00:00
|
|
|
return result
|
2005-09-29 19:05:55 +00:00
|
|
|
|
|
|
|
def cmd_selectapplication(self, *args):
|
|
|
|
if len(args) != 1:
|
|
|
|
raise TypeError, "Must give exactly one argument: the application to select."
|
|
|
|
if self.APPLICATIONS.has_key(args[0]):
|
|
|
|
aid = self.APPLICATIONS[args[0]]
|
|
|
|
else:
|
|
|
|
aid = binascii.a2b_hex("".join(args[0].split()))
|
|
|
|
result = self.select_application(aid)
|
|
|
|
if len(result) > 2:
|
|
|
|
print utils.hexdump(result[:-2])
|
|
|
|
|
|
|
|
COMMANDS = dict(Card.COMMANDS)
|
|
|
|
COMMANDS.update( {
|
|
|
|
"select_application": (cmd_selectapplication, "select_application application",
|
|
|
|
"""Select an application on the card. application can be given either as hexadezimal aid or by symbolic name (if known).""")
|
|
|
|
} )
|