nPA: allow the user to specify a EF.CardAccess

This commit is contained in:
Frank Morgner
2012-09-05 09:47:02 +02:00
parent 6fb20b0549
commit c8da1f5213
2 changed files with 20 additions and 8 deletions

View File

@@ -61,17 +61,21 @@ relay.add_argument("-r", "--reader",
help="number of the reader which contains the smart card to be relayed.")
npa = parser.add_argument_group('options for nPA emulation')
npa.add_argument("-e", "--ef-cardsecurity",
npa.add_argument("-s", "--ef-cardsecurity",
action="store",
type=argparse.FileType('r'),
type=argparse.FileType('rb'),
help="EF.CardSecurity with the signed CA public key.")
npa.add_argument("-a", "--ef-cardaccess",
action="store",
type=argparse.FileType('rb'),
help="EF.CardAccess with the EAC configuration.")
npa.add_argument("-k", "--ca-key",
action="store",
type=argparse.FileType('r'),
type=argparse.FileType('rb'),
help="CA private key.")
npa.add_argument("-p", "--ca-pubkey",
action="store",
type=argparse.FileType('r'),
type=argparse.FileType('rb'),
help="CA public key.")
npa.add_argument("-c", "--ca",
action="store",
@@ -83,19 +87,24 @@ args = parser.parse_args()
from virtualsmartcard.VirtualSmartcard import VirtualICC
ef_cardsecurity_data = None
ef_cardaccess_data = None
ca_key_data = None
ca_pubkey_data = None
if (args.ef_cardsecurity):
ef_cardsecurity_data = args.ef_cardsecurity.read()
args.ef_cardsecurity.close()
if (args.ef_cardaccess):
ef_cardaccess_data = args.ef_cardaccess.read()
args.ef_cardaccess.close()
if (args.ca_key):
ca_key_data = args.ca_key.read()
args.ca_key.close()
if (args.ca_pubkey):
ca_pubkey_data = args.ca_pubkey.read()
args.ca_pubkey.close()
vicc = VirtualICC(args.file, args.type,
args.hostname, args.port, readernum=args.reader,
ef_cardsecurity=ef_cardsecurity_data, ca_pubkey=ca_pubkey_data,
ef_cardaccess=ef_cardaccess_data, ef_cardsecurity=ef_cardsecurity_data, ca_pubkey=ca_pubkey_data,
ca_key=ca_key_data, ca=args.ca)
vicc.run()

View File

@@ -499,7 +499,7 @@ class RelayOS(SmartcardOS):
class NPAOS(Iso7816OS):
def __init__(self, mf, sam, ins2handler=None, maxle=MAX_EXTENDED_LE, ef_cardsecurity=None, ca_key=None, ca_pubkey=None, ca=None):
def __init__(self, mf, sam, ins2handler=None, maxle=MAX_EXTENDED_LE, ef_cardsecurity=None, ef_cardaccess=None, ca_key=None, ca_pubkey=None, ca=None):
Iso7816OS.__init__(self, mf, sam, ins2handler, maxle)
self.ins2handler[0x86] = self.SAM.general_authenticate
self.ins2handler[0x2c] = self.SAM.reset_retry_counter
@@ -507,6 +507,9 @@ class NPAOS(Iso7816OS):
if ef_cardsecurity:
ef = self.mf.select('fid', 0x011d)
ef.setdec('data', ef_cardsecurity)
if ef_cardaccess:
ef = self.mf.select('fid', 0x011c)
ef.setdec('data', ef_cardaccess)
if ca:
self.SAM.current_SE.ca = ca
if ca_key:
@@ -553,7 +556,7 @@ class VirtualICC(object):
the vpcd, which forwards it to the application.
"""
def __init__(self, filename, card_type, host, port, lenlen=3, readernum=None, ef_cardsecurity=None, ca_key=None, ca_pubkey=None, ca=None):
def __init__(self, filename, card_type, host, port, lenlen=3, readernum=None, ef_cardsecurity=None, ef_cardaccess=None, ca_key=None, ca_pubkey=None, ca=None):
from os.path import exists
logging.basicConfig(level = logging.INFO,
@@ -578,7 +581,7 @@ class VirtualICC(object):
if card_type == "iso7816" or card_type == "ePass":
self.os = Iso7816OS(MF, SAM)
elif card_type == "nPA":
self.os = NPAOS(MF, SAM, ef_cardsecurity=ef_cardsecurity, ca_key=ca_key, ca_pubkey=ca_pubkey, ca=ca)
self.os = NPAOS(MF, SAM, ef_cardsecurity=ef_cardsecurity, ef_cardaccess=ef_cardaccess, ca_key=ca_key, ca_pubkey=ca_pubkey, ca=ca)
elif card_type == "cryptoflex":
self.os = CryptoflexOS(MF, SAM)
elif card_type == "relay":