2005-09-29 19:05:55 +00:00
|
|
|
import utils, binascii
|
2005-09-29 03:39:14 +00:00
|
|
|
from generic_card import *
|
2006-05-18 15:45:07 +00:00
|
|
|
from utils import C_APDU
|
2005-09-29 03:39:14 +00:00
|
|
|
|
|
|
|
class Java_Card(Card):
|
2006-11-19 04:44:45 +00:00
|
|
|
APDU_SELECT_APPLICATION = C_APDU(ins=0xa4,p1=0x04)
|
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(
|
2006-05-18 15:45:07 +00:00
|
|
|
C_APDU(self.APDU_SELECT_APPLICATION,
|
|
|
|
data = aid) )
|
2005-09-29 03:39:14 +00:00
|
|
|
return result
|
2005-09-29 19:05:55 +00:00
|
|
|
|
2005-10-09 02:06:32 +00:00
|
|
|
def cmd_selectapplication(self, application):
|
|
|
|
"""Select an application on the card.
|
|
|
|
application can be given either as hexadezimal aid or by symbolic name (if known)."""
|
|
|
|
|
|
|
|
if self.APPLICATIONS.has_key(application):
|
|
|
|
aid = self.APPLICATIONS[application]
|
2005-09-29 19:05:55 +00:00
|
|
|
else:
|
2005-10-09 02:06:32 +00:00
|
|
|
aid = binascii.a2b_hex("".join(application.split()))
|
2005-09-29 19:05:55 +00:00
|
|
|
result = self.select_application(aid)
|
2006-05-18 15:45:07 +00:00
|
|
|
if len(result.data) > 0:
|
|
|
|
print utils.hexdump(result.data)
|
2005-09-29 19:05:55 +00:00
|
|
|
|
|
|
|
COMMANDS = dict(Card.COMMANDS)
|
|
|
|
COMMANDS.update( {
|
2005-10-09 02:06:32 +00:00
|
|
|
"select_application": cmd_selectapplication
|
2005-09-29 19:05:55 +00:00
|
|
|
} )
|