### Install libnfc with Custom Prefix Source: https://frankmorgner.github.io/vsmartcard/pcsc-relay/README.html Example of cloning, building, and installing libnfc to a specified prefix, useful for custom configurations. ```bash PREFIX=/tmp/install LIBNFC=libnfc git clone https://github.com/nfc-tools/libnfc $LIBNFC cd $LIBNFC autoreconf -i # See `./configure --help` for enabling support of additional hardware ./configure --prefix=$PREFIX make make install ``` -------------------------------- ### Configure, Build, and Install Source: https://frankmorgner.github.io/vsmartcard/ccid/README.html Configure, build, and install the USB CCID Emulator using the standard GNU Build System commands. ```bash ./configure make make install ``` -------------------------------- ### Configure, Build, and Install Virtual Smart Card Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html Configure the build with specified system configuration directory, compile the project, and install it. ```bash ./configure --sysconfdir=/etc make make install ``` -------------------------------- ### Configure, Build, and Install PC/SC Relay Source: https://frankmorgner.github.io/vsmartcard/pcsc-relay/README.html Standard commands to configure, build, and install PC/SC Relay using the GNU Build System. ```bash ./configure make make install ``` -------------------------------- ### Build and Install vpcd on Mac OS X Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html Clone the repository, navigate to the virtualsmartcard directory, generate build files, configure with Info.plist support, build, and install. ```bash git clone https://github.com/frankmorgner/vsmartcard.git cd vsmartcard/virtualsmartcard autoreconf -vis ./configure --enable-infoplist make make install ``` -------------------------------- ### Install Linux Kernel Headers and Source Source: https://frankmorgner.github.io/vsmartcard/ccid/README.html Install necessary Linux kernel headers and source files required for building GadgetFS modules on Debian systems. ```bash sudo apt-get install linux-source linux-headers-`uname -r` sudo tar xjf /usr/src/linux-source-*.tar.bz2 ``` -------------------------------- ### Start vpicc Virtual Smart Card Tool Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html Launches the vpicc virtual smart card tool in test mode for the ePass. This command should be run after starting the virtual card and configuring it with the correct MRZ. ```bash vicc -t ePass ``` -------------------------------- ### Verify Smart Card Installation on macOS Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html Command to verify that the smart card reader is correctly installed and recognized by the system. ```bash system_profiler SPSmartCardsDataType ``` -------------------------------- ### Install Python 2.7 Dependencies for vpicc Testing Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html Installs necessary packages for Python 2.7 on Ubuntu to run the vpicc testing tools. Ensure you have Python 2.7 development headers and pip installed. ```bash sudo apt-get install python2.7-dev curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py python2.7 get-pip.py python2.7 -m pip install pycryptodomex pyscard python2.7 readpass.py --no-gui git clone https://github.com/henryk/cyberflex-shell cd cyberflex-shell ``` -------------------------------- ### Start PC/SC Relay with VPCD Emulator Source: https://frankmorgner.github.io/vsmartcard/pcsc-relay/README.html Launch pcsc-relay specifying the 'vpcd' emulator, typically used with Android Smart Card Emulator. ```bash pcsc-relay --emulator vpcd ``` -------------------------------- ### Show CryptoTokenKit Logs on macOS Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html Command to display logs for the CryptoTokenKit subsystem, useful for debugging installation or configuration issues. ```bash log show --predicate '(subsystem == "com.apple.CryptoTokenKit")' --info --debug ``` -------------------------------- ### Get USB Device Product and Vendor ID on macOS Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html Use this command to retrieve the product and vendor IDs of a USB device, which are needed for configuring vpcd. ```bash system_profiler SPUSBDataType \ | awk \ '(/Product ID:/{p=$3}) (/Vendor ID:/{v=$3}) (/Manufacturer:/{sub(/.*: /,"",$0); m=$0}) (/Location ID:/{sub(/.*: /,"",$0); printf("%s:%s %s (%s)\n", v, p, $0, m);} '\ ``` -------------------------------- ### Clone Virtual Smart Card Repository Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html Clone the Virtual Smart Card git repository and update submodules to get the latest source code. ```bash git clone https://github.com/frankmorgner/vsmartcard.git cd vsmartcard git submodule update --init --recursive ``` -------------------------------- ### Clone and Initialize Submodules Source: https://frankmorgner.github.io/vsmartcard/ACardEmulator/README.html Clone the repository and initialize its submodules to set up the project for manual compilation. ```bash git clone https://github.com/frankmorgner/vsmartcard.git cd vsmartcard git submodule update --init --recursive ``` -------------------------------- ### vpicc Command Line Usage Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html Overview of available command-line switches for the vpicc tool. Use this to understand how to configure the virtual smart card emulator for different scenarios. ```bash usage: vicc [-h] [-t {iso7816,cryptoflex,ePass,nPA,relay,handler_test}] [-v] [-f FILE] [-H HOSTNAME] [-P PORT] [-R] [--version] [--reader READER] [--mitm MITM] [--ef-cardaccess EF_CARDACCESS] [--ef-cardsecurity EF_CARDSECURITY] [--cvca CVCA] [--disable-ta-checks] [--ca-key CA_KEY] [-d DATASETFILE] [--esign-cert ESIGN_CERT] [--esign-ca-cert ESIGN_CA_CERT] Virtual Smart Card 0.10: Smart card emulator written in Python. The emulator connects to the virtual smart card reader reader (vpcd). Smart card applications can access the Virtual Smart Card through the vpcd via PC/SC. options: -h, --help show this help message and exit -t {iso7816,cryptoflex,ePass,nPA,relay,handler_test}, --type {iso7816,cryptoflex,ePass,nPA,relay,handler_test} type of smart card to emulate (default: iso7816) -v, --verbose Use (several times) to be more verbose -f FILE, --file FILE load a saved smart card image -H HOSTNAME, --hostname HOSTNAME specifiy vpcd's host name if vicc shall connect to it. (default: localhost) -P PORT, --port PORT port of connection establishment (default: 35963) -R, --reversed use reversed connection mode. vicc will wait for an incoming connection from vpcd. (default: False) --version show program's version number and exit Relaying a local smart card (`--type=relay`): --reader READER number of the reader containing the card to be relayed (default: 0) --mitm MITM relative path to a file containing a Man-in-the-Middle class that is supposed to be used with the relay Emulation of German identity card (`--type=nPA`): --ef-cardaccess EF_CARDACCESS the card's EF.CardAccess (default: use file from first generation nPA) --ef-cardsecurity EF_CARDSECURITY the card's EF.CardSecurity (default: use file from first generation nPA) --cvca CVCA trust anchor for verifying certificates in TA (default: use libeac's trusted certificates) --disable-ta-checks disable checking the validity period of CV certifcates (default: False) --ca-key CA_KEY the chip's private key for CA (default: randomly generated, invalidates signature of EF.CardSecurity) -d DATASETFILE, --datasetfile DATASETFILE Load the smartcard's data groups (DGs) from the specified dataset file. For DGs not in dataset file default values are used. The data groups in the data set file must have the following syntax: --------------------------------------------------- Datagroupname=Datagroupvalue --------------------------------------------------- For Example: GivenNames=GERTRUD. The following Dataset Elements may be used in the dataset file: DocumentType, IssuingState, DateOfExpiry, GivenNames, FamilyNames, ReligiousArtisticName, AcademicTitle, DateOfBirth, PlaceOfBirth, Nationality, Sex, BirthName, Country, City, ZIP, Street, CommunityID, ResidencePermit1, ResidencePermit2, dg12, dg14, dg15, dg16, dg21. --esign-cert ESIGN_CERT the card holder's certificate for QES --esign-ca-cert ESIGN_CA_CERT the CA's certificate for QES Report bugs to https://github.com/frankmorgner/vsmartcard/issues ``` -------------------------------- ### CCID Emulator Command Line Options Source: https://frankmorgner.github.io/vsmartcard/ccid/README.html Use these options to configure the CCID emulator, including reader selection, USB product/vendor IDs, and verbosity. GadgetFS must be mounted at the specified directory. ```bash Usage: ccid-emulator [OPTION]... Emulate a USB CCID compliant smart card reader -h, --help Print help and exit -V, --version Print version and exit -i, --info Print available readers and drivers. (default=off) -r, --reader=INT Number of the PC/SC reader to use (-1 for autodetect) (default=`-1') --gadgetfs=FILENAME Directory where GadgetFS is mounted (default=`/dev/gadget') -v, --verbose Use (several times) to be more verbose Changing the appearance on the Universal Serial Bus: -p, --product=INT USB product ID (default=`0x3010') -e, --vendor=INT USB vendor ID (default=`0x0D46') --serial=STRING USB serial number (default=`random') --interface=STRING USB serial number (default=`notification status') --interrupt Add interrupt pipe for CCID (default=off) Report bugs to https://github.com/frankmorgner/vsmartcard/issues Written by Frank Morgner ``` -------------------------------- ### Import Test Signing Certificate on Windows Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html Import the BixVReader.cer certificate into the 'Trusted Root Certification Authority' and 'Trusted Publishers' stores for the Local Computer. This can be done via the command line. ```bash CertMgr /add BixVReader.cer /s /r localMachine root /all CertMgr /add BixVReader.cer /s /r localMachine trustedpublisher ``` -------------------------------- ### Build GadgetFS and dummy_hcd Modules Source: https://frankmorgner.github.io/vsmartcard/ccid/README.html Build the dummy_hcd and gadgetfs kernel modules from the Linux kernel source code. ```bash cd linux-source-*/drivers/usb/gadget # build dummy_hcd and gadgetfs echo "KDIR := /lib/modules/`uname -r`/build" >> Makefile echo "PWD := `pwd`" >> Makefile echo "obj-m := dummy_hcd.o gadgetfs.o" >> Makefile echo "default: " >> Makefile echo -e "\t\t "make # load GadgetFS with its dependencies sudo modprobe udc-core sudo insmod ./dummy_hcd.ko sudo insmod ./gadgetfs.ko default_uid=`id -u` # mount GadgetFS sudo mkdir /dev/gadget sudo mount -t gadgetfs gadgetfs /dev/gadget ``` -------------------------------- ### Configure PC/SC Relay with Custom libnfc Path Source: https://frankmorgner.github.io/vsmartcard/pcsc-relay/README.html Configure PC/SC Relay to use a custom-installed libnfc by specifying the PKG_CONFIG_PATH. ```bash ./configure PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig ``` -------------------------------- ### Generate Build Files for PC/SC Relay Source: https://frankmorgner.github.io/vsmartcard/pcsc-relay/README.html Run autoreconf to generate necessary build files if working with a bleeding-edge version from the repository. ```bash autoreconf --verbose --install ``` -------------------------------- ### Initialize VirtualICC with Card Configuration Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/api.html Initializes the `VirtualICC` class, which manages the virtual smart card reader. It configures the card type, connects to the VPCD, and handles different card OS implementations based on the `card_type` parameter. Supports various card types like 'iso7816', 'nPA', 'cryptoflex', 'relay', and 'handler_test'. ```python def __init__(self, datasetfile, card_type, host, port, readernum=None, mitmPath=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): from os.path import exists logging.basicConfig(level=logginglevel, format="%(asctime)s [%(levelname)s] %(message)s", datefmt="%d.%m.%Y %H:%M:%S") self.cardGenerator = CardGenerator(card_type) # If a dataset file is specified, read the card's data groups from disk if datasetfile is not None: if exists(datasetfile): logging.info("Reading Data Groups from file %s.", datasetfile) self.cardGenerator.readDatagroups(datasetfile) MF, SAM = self.cardGenerator.getCard() # Generate an OS object of the correct card_type if card_type == "iso7816" or card_type == "ePass": self.os = Iso7816OS(MF, SAM) elif card_type == "nPA": from virtualsmartcard.cards.nPA import NPAOS self.os = NPAOS(MF, SAM, ef_cardsecurity=ef_cardsecurity, ef_cardaccess=ef_cardaccess, ca_key=ca_key, cvca=cvca, disable_checks=disable_checks, esign_key=esign_key, esign_ca_cert=esign_ca_cert, esign_cert=esign_cert) elif card_type == "cryptoflex": from virtualsmartcard.cards.cryptoflex import CryptoflexOS self.os = CryptoflexOS(MF, SAM) elif card_type == "relay": from virtualsmartcard.cards.Relay import RelayOS from virtualsmartcard.cards.RelayMiddleman import RelayMiddleman mitm = loadMitMFromPath(mitmPath) if mitmPath else RelayMiddleman() self.os = RelayOS(readernum,mitm=mitm) elif card_type == "handler_test": from virtualsmartcard.cards.HandlerTest import HandlerTestOS self.os = HandlerTestOS() else: logging.warning("Unknown cardtype %s. Will use standard card_type \n (ISO 7816)", card_type) card_type = "iso7816" self.os = Iso7816OS(MF, SAM) self.type = card_type # Connect to the VPCD self.host = host self.port = port if host: # use normal connection mode try: self.sock = self.connectToPort(host, port) self.sock.settimeout(None) self.server_sock = None except socket.error as e: logging.critical("Failed to open socket: %s", str(e)) logging.critical("Is pcscd running at %s? Is vpcd loaded? Is a \n firewall blocking port %u?", host, port) sys.exit() else: # use reversed connection mode try: local_ip = [(s.connect(('9.9.9.9', 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1] custom_url = 'vicc://%s:%d' % (local_ip, port) print('VICC hostname: %s' % local_ip) print('VICC port: %d' % port) print('On your NFC phone with the Android Smart Card Emulator app scan this code:') try: import qrcode qr = qrcode.QRCode() qr.add_data(custom_url) qr.print_ascii() except ImportError: print('https://api.qrserver.com/v1/create-qr-code/?data=%s' % custom_url) (self.sock, self.server_sock, host) = self.openPort(port) self.sock.settimeout(None) except socket.error as e: logging.critical("Failed to open socket: %s", str(e)) ``` -------------------------------- ### Clone vsmartcard Repository Source: https://frankmorgner.github.io/vsmartcard/TCardEmulator/README.html Clone the vsmartcard repository to access the source code. This is the initial step for manual compilation. ```bash git clone https://github.com/frankmorgner/vsmartcard.git ``` -------------------------------- ### Configure vpcd on Unix Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html Configure vpcd by specifying the friendly name, device name, library path, and channel ID in the reader configuration file. Ensure the PC/SC daemon reads this configuration. ```ini FRIENDLYNAME "Virtual PCD" DEVICENAME /dev/null:0x8C7B LIBPATH /usr/lib/pcsc/drivers/serial/libifdvpcd.so CHANNELID 0x8C7B ``` -------------------------------- ### Generate Build Files with Autoreconf Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html Generate the necessary auxiliary files for the GNU Build System using autoreconf. This is required if working with a bleeding-edge version from the repository. ```bash autoreconf --verbose --install ``` -------------------------------- ### Create BAC Script for cyberflex-shell Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html Creates a script file to be executed by cyberflex-shell for performing Basic Access Control (BAC). This involves selecting the application and performing the BAC operation with a given key. ```bash echo "select_application a0000002471001" > script.txt echo "perform_bac L898902C<3UTO6908061F9406236ZE184226B<<<<<14" >> script.txt python2.7 cyberflex-shell.py script.txt ``` -------------------------------- ### Windows vpcd Configuration File (BixVReader.ini) Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html This INI file configures vpcd on Windows. The 'TCP_PORT' setting specifies the port for vpicc connections. ```ini [Driver] NumReaders=3 [Reader0] RPC_TYPE=0 VENDOR_NAME=Fabio Ottavi VENDOR_IFD_TYPE=Pipe Reader DECIVE_UNIT=0 [Reader1] RPC_TYPE=1 VENDOR_NAME=Fabio Ottavi VENDOR_IFD_TYPE=TCP/IP Reader DECIVE_UNIT=1 [Reader2] RPC_TYPE=2 VENDOR_NAME=Virtual Smart Card Architecture VENDOR_IFD_TYPE=Virtual PCD TCP_PORT=35963 DECIVE_UNIT=2 ``` -------------------------------- ### Clone vsmartcard Git Repository Source: https://frankmorgner.github.io/vsmartcard/index.html Clone the vsmartcard project from its GitHub repository to access the source code and contribute. ```bash git clone https://github.com/frankmorgner/vsmartcard.git ``` -------------------------------- ### PC/SC Relay Command Line Usage Source: https://frankmorgner.github.io/vsmartcard/pcsc-relay/README.html This displays the available command-line options for the pcsc-relay executable. Use these options to configure the emulator, connector, and verbosity. ```bash Usage: pcsc-relay [OPTION]... Relay a smart card to a contactless interface Using an contact-less interface (currently OpenPICC or libnfc) pcsc-relay receives command APDUs which are forwared to an existing smart card via PC/SC. pcsc-relay sends the response APDU back to the contact-less interface. -h, --help Print help and exit -V, --version Print version and exit -e, --emulator=ENUM Contact-less emulator backend (possible values="libnfc", "vpcd", "openpicc" default=`libnfc') -c, --connector=ENUM Smart card connector backend (possible values="pcsc", "vicc" default=`pcsc') -f, --foreground Stay in foreground (default=on) -v, --verbose Use (several times) to be more verbose PC/SC connector: -r, --reader=INT Number of the PC/SC reader to use (-1 for autodetect) (default=`-1') Virtual Smart Card connector: -p, --vpcd-port=INT Port for communicating virtual smart card (default=`35963') -n, --vpcd-hostname=STRING Hostname for connecting to virtual smart card (default=`wait for an incoming connection') Virtual Smart Card Reader emulator: -P, --vicc-port=INT Port to listen for virtual smart card reader (default=`35963') -N, --vicc-hostname=STRING Hostname for connecting to virtual smart card reader (default=`wait for an incoming connection') -A, --vicc-atr=STRING ATR (default=`3B80800101') Report bugs to https://github.com/frankmorgner/vsmartcard/issues Written by Frank Morgner and Dominik Oepen ``` -------------------------------- ### Create Cryptoflex File Structures Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/api.html Customizes file creation for Cryptoflex cards, modifying the interpretation of APDU data for different file structures (transparent, record-based). Use when defining new files or directories on the card. ```python if data[0:2] != b"\xff\xff": raise SwError(SW["ERR_INCORRECTPARAMETERS"]) args = { "parent": None, "filedescriptor": 0, "fid": stringtoint(data[4:6]), } if data[6] == b"\x01": args["data"] = bytes(0)*stringtoint(data[2:4]) args["filedescriptor"] = FDB["EFSTRUCTURE_TRANSPARENT"] new_file = TransparentStructureEF(**args) elif data[6] == b"\x02": if len(data) > 16: args["maxrecordsize"] = stringtoint(data[16]) elif p2: # if given a number of records args["maxrecordsize"] = (stringtoint(data[2:4]) / p2) args["filedescriptor"] = FDB["EFSTRUCTURE_LINEAR_FIXED_" "NOFURTHERINFO"] new_file = RecordStructureEF(**args) elif data[6] == b"\x03": args["filedescriptor"] = FDB["EFSTRUCTURE_LINEAR_VARIABLE_" "NOFURTHERINFO"] new_file = RecordStructureEF(**args) elif data[6] == b"\x04": args["filedescriptor"] = FDB["EFSTRUCTURE_CYCLIC_NOFURTHERINFO"] new_file = RecordStructureEF(**args) elif data[6] == b"\x38": if data[12] != b"\x03": raise SwError(SW["ERR_INCORRECTPARAMETERS"]) new_file = DF(**args) else: logging.error("unknown type: 0x%x" % ord(data[6])) raise SwError(SW["ERR_INCORRECTPARAMETERS"]) return [new_file] def recordHandlingDecode(self, p1, p2): ``` -------------------------------- ### Restart PC/SC Service on macOS Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html Command to restart the PC/SC service on macOS after modifying the Info.plist file. This ensures the new configuration is loaded. ```bash sudo killall -SIGKILL -m '.*com.apple.ifdreader' ``` -------------------------------- ### Implement Custom Smart Card Relay Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/api.html This class relays commands to a physical smart card via a reader, useful for implementing relay or MitM attacks. It requires a reader number and optionally a middleman object. ```python class RelayOS(SmartcardOS): """ This class implements relaying of a (physical) smartcard. The RelayOS forwards the command APDUs received from the vpcd to the real smartcard via an actual smart card reader and sends the responses back to the vpcd. This class can be used to implement relay or MitM attacks. """ def __init__(self, readernum, mitm=RelayMiddleman()): """ Initialize the connection to the (physical) smart card via a given reader """ # See which readers are available readers = smartcard.System.listReaders() if len(readers) <= readernum: logging.critical("Invalid number of reader '%u' (only %u available)", readernum, len(readers)) sys.exit() # Connect to the reader and its card # XXX this is a workaround, see on sourceforge bug #3083254 # should better use # self.reader = smartcard.System.readers()[readernum] self.reader = readers[readernum] try: self.session = smartcard.Session(self.reader) except smartcard.Exceptions.CardConnectionException as e: logging.critical("Error connecting to card: %s", str(e)) sys.exit() logging.info("Connected to card in '%s'", self.reader) self.mitm = mitm atexit.register(self.cleanup) def cleanup(self): """ Close the connection to the physical card """ try: self.session.close() except smartcard.Exceptions.CardConnectionException as e: logging.warning("Error disconnecting from card: %s", str(e)) def getATR(self): # when powerDown has been called, fetching the ATR will throw an error. # In this case we must try to reconnect (and then get the ATR). try: atr = self.session.getATR() except smartcard.Exceptions.CardConnectionException as e: try: # Try to reconnect to the card self.session.close() self.session = smartcard.Session(self.reader) atr = self.session.getATR() except smartcard.Exceptions.CardConnectionException as e: logging.critical("Error getting ATR: %s", str(e)) sys.exit() return "".join([chr(b) for b in atr]) def powerUp(self): # When powerUp is called multiple times the session is valid (and the # card is implicitly powered) we can check for an ATR. But when # powerDown has been called, the session gets lost. In this case we # must try to reconnect (and power the card). try: self.session.getATR() except smartcard.Exceptions.CardConnectionException as e: try: self.session = smartcard.Session(self.reader) except smartcard.Exceptions.CardConnectionException as e: logging.critical("Error connecting to card: %s", str(e)) sys.exit() def powerDown(self): # There is no power down in the session context so we simply # disconnect, which should implicitly power down the card. try: self.session.close() except smartcard.Exceptions.CardConnectionException as e: logging.critical("Error disconnecting from card: %s", str(e)) sys.exit() def reset(self): self.powerDown() self.powerUp() def execute(self, msg): # sendCommandAPDU() expects a list of APDU bytes if isinstance(msg,str): apdu = map(ord, msg) else: apdu = list(msg) apdu = self.mitm.handleInPDU(apdu) try: rapdu, sw1, sw2 = self.session.sendCommandAPDU(apdu) except smartcard.Exceptions.CardConnectionException as e: logging.critical("Error transmitting APDU: %s", str(e)) sys.exit() # XXX this is a workaround, see on sourceforge bug #3083586 # should better use # rapdu = rapdu + [sw1, sw2] if rapdu[-2:] == [sw1, sw2]: pass else: rapdu = rapdu + [sw1, sw2] rapdu = self.mitm.handleOutPDU(rapdu) # return the response APDU as string return "".join(map(chr, rapdu)) ``` -------------------------------- ### macOS Info.plist Configuration for vpcd Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/README.html This XML configuration file is used to register vpcd as a USB device on macOS. Modify the 'ifdVendorID' and 'ifdProductID' to match your device. ```xml CFBundleDevelopmentRegion English CFBundleExecutable libifdvpcd.dylib CFBundleInfoDictionaryVersion 6.0 CFBundleName ifd-vpcd CFBundlePackageType BNDL CFBundleSignature ???? CFBundleVersion 0.8 ifdManufacturerString Virtual Smart Card Architecture ifdProductString Virtual PCD ifdCapabilities 0x00000000 ifdProtocolSupport 0x00000001 ifdVersionNumber 0x00000001 ifdVendorID 0x18d1 ifdProductID 0x4ee1 ifdFriendlyName /dev/null:0x8C7B Copyright This driver is protected by terms of the GNU General Public License version 3, or (at your option) any later version. ``` -------------------------------- ### Format Cryptoflex Card Responses Source: https://frankmorgner.github.io/vsmartcard/virtualsmartcard/api.html Overrides the default response formatting for Cryptoflex cards to handle specific behaviors regarding length and data encoding. Use when interacting with Cryptoflex-specific commands. ```python def formatResult(self, ins, le, data, sw): if le == 0 and len(data): # cryptoflex does not inpterpret le==0 as maxle self.lastCommandSW = sw self.lastCommandOffcut = data r = R_APDU(inttostring(SW["ERR_WRONGLENGTH"] + min(0xff, len(data)))).render() else: if ins == 0xa4 and len(data): # get response should be followed by select file self.lastCommandSW = sw self.lastCommandOffcut = data r = R_APDU(inttostring(SW["NORMAL_REST"] + min(0xff, len(data)))).render() else: r = Iso7816OS.formatResult(self, Iso7816OS.seekable(ins), le, data, sw, False) return r ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.