#! @PYTHON@ # # Copyright (C) 2010-2012 Frank Morgner # Copyright (C) 2010 Dominik Oepen # # This file is part of virtualsmartcard. # # virtualsmartcard is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # virtualsmartcard is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. # # You should have received a copy of the GNU General Public License along with # virtualsmartcard. If not, see . # import argparse parser = argparse.ArgumentParser( description=''' The @PACKAGE_NAME@ emulates different types of smart cards. The emulator connects to the virtual smart card reader reader (vpcd). Smart card applications can access the @PACKAGE_NAME@ through the vpcd via PC/SC. ''', epilog=''' Report bugs to @PACKAGE_BUGREPORT@ ''') parser.add_argument("-t", "--type", action="store", choices=['iso7816', 'cryptoflex', 'ePass', 'nPA', 'relay'], default='iso7816', help="Type of smart card to emulate (default: %(default)s)") parser.add_argument("-f", "--file", action="store", type=argparse.FileType('r'), help="load a saved smart card image") parser.add_argument("-H", "--hostname", action="store", type=str, default='localhost', help="address of the vpcd (default: %(default)s)") parser.add_argument("-P", "--port", action="store", type=int, default=35963, help="port of the vpcd (default: %(default)s)") parser.add_argument('--version', action='version', version='%(prog)s @PACKAGE_VERSION@') relay = parser.add_argument_group('options for relaying a local smart card') relay.add_argument("-r", "--reader", action="store", type=int, 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("-s", "--ef-cardsecurity", action="store", 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('rb'), help="CA private key.") npa.add_argument("-p", "--ca-pubkey", action="store", type=argparse.FileType('rb'), help="CA public key.") npa.add_argument("-c", "--ca", action="store", type=str, help="CHR of the CVCA.") 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_cardaccess=ef_cardaccess_data, ef_cardsecurity=ef_cardsecurity_data, ca_pubkey=ca_pubkey_data, ca_key=ca_key_data, ca=args.ca) vicc.run()