Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: support for Belgian eID cards #104

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow for unparsed logging
Some unknown cards, which the Relay card may need to deal with, may not
use the APDU format. Trying to parse commands sent to those cards as
though they were in the APDU format is obviously wrong. However, most
cards do support APDU, so default to logging parsed APDUs, still.
  • Loading branch information
yoe committed Jun 15, 2017
commit e3a1aacce7c9758482420f8515beb49dc2abd41f
3 changes: 2 additions & 1 deletion virtualsmartcard/src/vpicc/vicc.in
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ parser.add_argument("-P", "--port",
parser.add_argument("-R", "--reversed",
action="store_true",
help="use reversed connection mode. vicc will wait for an incoming connection from vpcd. (default: %(default)s)")
parser.add_argument('--log-unparsed', action="store_true", help="Log unparsed command APDUs, rather than trying to parse them")
parser.add_argument('--version', action='version', version='%(prog)s @PACKAGE_VERSION@')

relay = parser.add_argument_group('Relaying a local smart card (`--type=relay`)')
Expand Down Expand Up @@ -156,7 +157,7 @@ vicc = VirtualICC(args.datasetfile, args.type, hostname, args.port,
readernum=args.reader, ef_cardaccess=ef_cardaccess_data,
ef_cardsecurity=ef_cardsecurity_data, ca_key=ca_key_data, cvca=cvca,
disable_checks=args.disable_ta_checks, esign_ca_cert=esign_ca_cert,
esign_cert=esign_cert, logginglevel=logginglevel)
esign_cert=esign_cert, logginglevel=logginglevel, logunparsed=args.log_unparsed)
try:
vicc.run()
except KeyboardInterrupt:
Expand Down
10 changes: 8 additions & 2 deletions virtualsmartcard/src/vpicc/virtualsmartcard/VirtualSmartcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def execute(self, msg):
"""
return ""

def logAPDU(self, parsed, unparsed):
if(self.logunparsed):
logging.info("Unparsed APDU:\n%s", hexdump(unparsed));
else:
logging.info("Parsed APDU:\n%s", str(parsed))

class Iso7816OS(SmartcardOS):

Expand Down Expand Up @@ -286,7 +291,7 @@ def notImplemented(*argz, **args):
return self.formatResult(False, 0, "",
SW["ERR_INCORRECTPARAMETERS"], False)

logging.info("Parsed APDU:\n%s", str(c))
self.logAPDU(parsed=c, unparsed=msg)

# Handle Class Byte
# {{{
Expand Down Expand Up @@ -391,7 +396,7 @@ def __init__(self, datasetfile, card_type, host, port,
readernum=None, ef_cardsecurity=None, ef_cardaccess=None,
ca_key=None, cvca=None, disable_checks=False, esign_key=None,
esign_ca_cert=None, esign_cert=None,
logginglevel=logging.INFO):
logginglevel=logging.INFO, logunparsed=False):
from os.path import exists

logging.basicConfig(level=logginglevel,
Expand Down Expand Up @@ -437,6 +442,7 @@ def __init__(self, datasetfile, card_type, host, port,
card_type = "iso7816"
self.os = Iso7816OS(MF, SAM)
self.type = card_type
self.os.logunparsed = logunparsed

# Connect to the VPCD
self.host = host
Expand Down
2 changes: 1 addition & 1 deletion virtualsmartcard/src/vpicc/virtualsmartcard/cards/Relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def reset(self):
def execute(self, msg):
try:
c = C_APDU(msg)
logging.info("Parsed APDU:\n%s", str(c))
self.logAPDU(parsed=c, unparsed=msg)
except ValueError as e:
# ignore the parse failure, just don't log the parsed APDU
logging.warning("Could not parse APDU:%s", str(e))
Expand Down