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

View File

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