From 36f64cf59ad517d45bd24b479114961ba11cc301 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Fri, 15 May 2015 18:25:12 +0200 Subject: [PATCH] added scritps to build package for OS X --- .../MacOSX/MacOSX_install/postinstall | 15 ++ .../MacOSX/MacOSX_uninstall/postinstall | 25 +++ virtualsmartcard/MacOSX/Makefile.am | 46 +++++ virtualsmartcard/MacOSX/debuglog.h | 1 + virtualsmartcard/MacOSX/ifdhandler.h | 186 ++++++++++++++++++ virtualsmartcard/Makefile.am | 5 +- virtualsmartcard/configure.ac | 8 +- virtualsmartcard/src/ifd-vpcd/ifd-vpcd.c | 1 + 8 files changed, 284 insertions(+), 3 deletions(-) create mode 100755 virtualsmartcard/MacOSX/MacOSX_install/postinstall create mode 100755 virtualsmartcard/MacOSX/MacOSX_uninstall/postinstall create mode 100644 virtualsmartcard/MacOSX/Makefile.am create mode 120000 virtualsmartcard/MacOSX/debuglog.h create mode 100644 virtualsmartcard/MacOSX/ifdhandler.h diff --git a/virtualsmartcard/MacOSX/MacOSX_install/postinstall b/virtualsmartcard/MacOSX/MacOSX_install/postinstall new file mode 100755 index 0000000..ba33966 --- /dev/null +++ b/virtualsmartcard/MacOSX/MacOSX_install/postinstall @@ -0,0 +1,15 @@ +#!/bin/bash + +mkdir -p /usr/libexec/SmartCardServices/drivers +ln -sf /Library/VirtualSmartCard/usr/libexec/SmartCardServices/drivers/ifd-vpcd.bundle /usr/libexec/SmartCardServices/drivers + +for f in /Library/VirtualSmartCard/bin/* +do + ln -sf $f /usr/local/bin +done + +mkdir -p /usr/local/lib/python2.7/site-packages +for f in /Library/VirtualSmartCard/lib/python2.7/site-packages/* +do + ln -sf $f /usr/local/lib/python2.7/site-packages +done diff --git a/virtualsmartcard/MacOSX/MacOSX_uninstall/postinstall b/virtualsmartcard/MacOSX/MacOSX_uninstall/postinstall new file mode 100755 index 0000000..d9e2551 --- /dev/null +++ b/virtualsmartcard/MacOSX/MacOSX_uninstall/postinstall @@ -0,0 +1,25 @@ +#!/bin/bash + +if [ -L "/usr/libexec/SmartCardServices/drivers/ifd-vpcd.bundle" ] +then + if [ "$(readlink /usr/libexec/SmartCardServices/drivers/ifd-vpcd.bundle)" == "/Library/VirtualSmartCard/usr/libexec/SmartCardServices/drivers/ifd-vpcd.bundle" ] + then + rm /usr/libexec/SmartCardServices/drivers/ifd-vpcd.bundle + fi +fi + +# Remove symlinks to commands +for file in /Library/VirtualSmartCard/bin/*; do + test -L "/usr/local/bin/$(basename $file)" && rm -f "/usr/local/bin/$(basename $file)" +done + +# Remove symlinks to files +for file in /Library/VirtualSmartCard/lib/python2.7/site-packages/* +do + test -L "/usr/local/lib/python2.7/site-packages/$(basename $file)" && rm -rf "/usr/local/lib/python2.7/site-packages/$(basename $file)" +done + +# Remove installed files +rm -rf /Library/VirtualSmartCard + +echo "Virtual Smart Card has been removed from your system. See you again!" diff --git a/virtualsmartcard/MacOSX/Makefile.am b/virtualsmartcard/MacOSX/Makefile.am new file mode 100644 index 0000000..072f11c --- /dev/null +++ b/virtualsmartcard/MacOSX/Makefile.am @@ -0,0 +1,46 @@ +EXTRA_DIST = MacOSX_install/postinstall MacOSX_uninstall/postinstall + +all-local: + @echo Use \`$(MAKE) osx\` to compile package for Mac OS X + + + +OSX_TOOLS_DIR = "$(shell xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs" +OSX_TOOL_DIR ?= "$(OSX_TOOLS_DIR)/$(shell ls -1 $(OSX_TOOLS_DIR) | sort -n -k2 -t. -r | head -1)/usr" +OSX_TARGETDIR = $(abs_top_builddir)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)_osx +osx: $(OPENPACE_MAKEFILE) + @echo Compiling OpenPACE + $(MAKE) -C $(OPENPACE) osx + rm -rf $(OSX_TARGETDIR) dmg $(top_builddir)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)_osx.dmg + @echo Configuring virtualsmartcard for IFD bundle + cd $(top_builddir) && ./configure --prefix=/Library/VirtualSmartCard \ + CFLAGS="-arch i386 -arch x86_64" --enable-infoplist + @echo Compiling virtualsmartcard + make -C $(top_builddir) clean install DESTDIR=$(OSX_TARGETDIR) + @echo Configuring virtualsmartcard for builtin libpcsclite + cd $(top_builddir) && ./configure --prefix=/Library/VirtualSmartCard \ + CFLAGS="-arch i386 -arch x86_64" --enable-libpcsclite + @echo Compiling virtualsmartcard + make -C $(top_builddir) clean install DESTDIR=$(OSX_TARGETDIR) + pkgbuild --root $(OSX_TARGETDIR) --scripts MacOSX_install --identifier com.vsmartcard.virtualsmartcard.mac --version $(PACKAGE_VERSION) --install-location / VirtualSmartCard-$(PACKAGE_VERSION)_install.pkg + pkgbuild --nopayload --identifier com.vsmartcard.virtualsmartcard.mac.uninstall --scripts MacOSX_uninstall Uninstall_VirtualSmartCard.pkg + mkdir -p dmg + cp *.pkg dmg + cp $(OPENPACE)/cross/*.pkg dmg + hdiutil create -srcfolder dmg -volname "$(PACKAGE_STRING) for Mac OS X" $(top_builddir)/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)_osx.dmg + + + +OPENPACE=$(abs_builddir)/openpace +OPENPACE_CONFIGURE_AC=$(OPENPACE)/configure.ac +OPENPACE_CONFIGURE=$(OPENPACE)/configure +OPENPACE_MAKEFILE=$(OPENPACE)/Makefile + +$(OPENPACE_CONFIGURE_AC): + git clone https://github.com/frankmorgner/openpace.git $(OPENPACE) + +$(OPENPACE_CONFIGURE): $(OPENPACE_CONFIGURE_AC) + cd $(OPENPACE) && autoreconf --verbose --install --symlink + +$(OPENPACE_MAKEFILE): $(OPENPACE_CONFIGURE) + cd $(OPENPACE) && ./configure --enable-openssl-install diff --git a/virtualsmartcard/MacOSX/debuglog.h b/virtualsmartcard/MacOSX/debuglog.h new file mode 120000 index 0000000..0006cac --- /dev/null +++ b/virtualsmartcard/MacOSX/debuglog.h @@ -0,0 +1 @@ +../src/pcsclite-vpcd/PCSC/debuglog.h \ No newline at end of file diff --git a/virtualsmartcard/MacOSX/ifdhandler.h b/virtualsmartcard/MacOSX/ifdhandler.h new file mode 100644 index 0000000..ca28a96 --- /dev/null +++ b/virtualsmartcard/MacOSX/ifdhandler.h @@ -0,0 +1,186 @@ +/* + * MUSCLE SmartCard Development ( http://www.linuxnet.com ) + * + * Copyright (C) 1999-2004 + * David Corcoran + * Damien Sauveron + * + * $Id: ifdhandler.h 3029 2008-06-26 13:58:52Z rousseau $ + */ +/** + * @file + * @brief This provides reader specific low-level calls. + */ +#ifndef _ifd_handler_h_ +#define _ifd_handler_h_ +#include +#ifdef __cplusplus +extern "C" +{ +#endif + /* + * List of data structures available to ifdhandler + */ + typedef struct _DEVICE_CAPABILITIES + { + LPSTR Vendor_Name; /**< Tag 0x0100 */ + LPSTR IFD_Type; /**< Tag 0x0101 */ + DWORD IFD_Version; /**< Tag 0x0102 */ + LPSTR IFD_Serial; /**< Tag 0x0103 */ + DWORD IFD_Channel_ID; /**< Tag 0x0110 */ + DWORD Asynch_Supported; /**< Tag 0x0120 */ + DWORD Default_Clock; /**< Tag 0x0121 */ + DWORD Max_Clock; /**< Tag 0x0122 */ + DWORD Default_Data_Rate; /**< Tag 0x0123 */ + DWORD Max_Data_Rate; /**< Tag 0x0124 */ + DWORD Max_IFSD; /**< Tag 0x0125 */ + DWORD Synch_Supported; /**< Tag 0x0126 */ + DWORD Power_Mgmt; /**< Tag 0x0131 */ + DWORD Card_Auth_Devices; /**< Tag 0x0140 */ + DWORD User_Auth_Device; /**< Tag 0x0142 */ + DWORD Mechanics_Supported; /**< Tag 0x0150 */ + DWORD Vendor_Features; /**< Tag 0x0180 - 0x01F0 User Defined. */ + } + DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES; + typedef struct _ICC_STATE + { + UCHAR ICC_Presence; /**< Tag 0x0300 */ + UCHAR ICC_Interface_Status; /**< Tag 0x0301 */ + UCHAR ATR[MAX_ATR_SIZE]; /**< Tag 0x0303 */ + UCHAR ICC_Type; /**< Tag 0x0304 */ + } + ICC_STATE, *PICC_STATE; + typedef struct _PROTOCOL_OPTIONS + { + DWORD Protocol_Type; /**< Tag 0x0201 */ + DWORD Current_Clock; /**< Tag 0x0202 */ + DWORD Current_F; /**< Tag 0x0203 */ + DWORD Current_D; /**< Tag 0x0204 */ + DWORD Current_N; /**< Tag 0x0205 */ + DWORD Current_W; /**< Tag 0x0206 */ + DWORD Current_IFSC; /**< Tag 0x0207 */ + DWORD Current_IFSD; /**< Tag 0x0208 */ + DWORD Current_BWT; /**< Tag 0x0209 */ + DWORD Current_CWT; /**< Tag 0x020A */ + DWORD Current_EBC; /**< Tag 0x020B */ + } + PROTOCOL_OPTIONS, *PPROTOCOL_OPTIONS; + typedef struct _SCARD_IO_HEADER + { + DWORD Protocol; + DWORD Length; + } + SCARD_IO_HEADER, *PSCARD_IO_HEADER; + /* + * End of structure list + */ + /* + * The list of tags should be alot more but this is all I use in the + * meantime + */ +#define TAG_IFD_ATR 0x0303 +#define TAG_IFD_SLOTNUM 0x0180 +#define TAG_IFD_SLOT_THREAD_SAFE 0x0FAC +#define TAG_IFD_THREAD_SAFE 0x0FAD +#define TAG_IFD_SLOTS_NUMBER 0x0FAE +#define TAG_IFD_SIMULTANEOUS_ACCESS 0x0FAF +#define TAG_IFD_POLLING_THREAD 0x0FB0 +#define TAG_IFD_POLLING_THREAD_KILLABLE 0x0FB1 + /* + * End of tag list + */ + /* + * IFD Handler version number enummerations + */ +#define IFD_HVERSION_1_0 0x00010000 +#define IFD_HVERSION_2_0 0x00020000 +#define IFD_HVERSION_3_0 0x00030000 + /* + * End of version number enummerations + */ + /* + * List of defines available to ifdhandler + */ +#define IFD_POWER_UP 500 +#define IFD_POWER_DOWN 501 +#define IFD_RESET 502 +#define IFD_NEGOTIATE_PTS1 1 +#define IFD_NEGOTIATE_PTS2 2 +#define IFD_NEGOTIATE_PTS3 4 +#define IFD_SUCCESS 0 +#define IFD_ERROR_TAG 600 +#define IFD_ERROR_SET_FAILURE 601 +#define IFD_ERROR_VALUE_READ_ONLY 602 +#define IFD_ERROR_PTS_FAILURE 605 +#define IFD_ERROR_NOT_SUPPORTED 606 +#define IFD_PROTOCOL_NOT_SUPPORTED 607 +#define IFD_ERROR_POWER_ACTION 608 +#define IFD_ERROR_SWALLOW 609 +#define IFD_ERROR_EJECT 610 +#define IFD_ERROR_CONFISCATE 611 +#define IFD_COMMUNICATION_ERROR 612 +#define IFD_RESPONSE_TIMEOUT 613 +#define IFD_NOT_SUPPORTED 614 +#define IFD_ICC_PRESENT 615 +#define IFD_ICC_NOT_PRESENT 616 +#define IFD_NO_SUCH_DEVICE 617 +#ifndef RESPONSECODE_DEFINED_IN_WINTYPES_H + typedef long RESPONSECODE; +#endif + /* + * If you want to compile a V2.0 IFDHandler, define IFDHANDLERv2 before you + * include this file. + * + * By default it is setup for for most recent version of the API (V3.0) + */ +#ifndef IFDHANDLERv2 + /* + * List of Defined Functions Available to IFD_Handler 3.0 + * + * All the functions of IFD_Handler 2.0 are available + * IFDHCreateChannelByName() is new + * IFDHControl() API changed + */ + RESPONSECODE IFDHCreateChannelByName(DWORD, LPSTR); + RESPONSECODE IFDHControl(DWORD, DWORD, PUCHAR, DWORD, PUCHAR, + DWORD, LPDWORD); +#else + /* + * List of Defined Functions Available to IFD_Handler 2.0 + */ + RESPONSECODE IFDHControl(DWORD, PUCHAR, DWORD, PUCHAR, PDWORD); +#endif + /* + * common functions in IFD_Handler 2.0 and 3.0 + */ + RESPONSECODE IFDHCreateChannel(DWORD, DWORD); + RESPONSECODE IFDHCloseChannel(DWORD); + RESPONSECODE IFDHGetCapabilities(DWORD, DWORD, PDWORD, PUCHAR); + RESPONSECODE IFDHSetCapabilities(DWORD, DWORD, DWORD, PUCHAR); + RESPONSECODE IFDHSetProtocolParameters(DWORD, DWORD, UCHAR, + UCHAR, UCHAR, UCHAR); + RESPONSECODE IFDHPowerICC(DWORD, DWORD, PUCHAR, PDWORD); + RESPONSECODE IFDHTransmitToICC(DWORD, SCARD_IO_HEADER, PUCHAR, + DWORD, PUCHAR, PDWORD, PSCARD_IO_HEADER); + RESPONSECODE IFDHICCPresence(DWORD); + /* + * List of Defined Functions Available to IFD_Handler 1.0 + */ + RESPONSECODE IO_Create_Channel(DWORD); + RESPONSECODE IO_Close_Channel(void); + RESPONSECODE IFD_Get_Capabilities(DWORD, PUCHAR); + RESPONSECODE IFD_Set_Capabilities(DWORD, PUCHAR); + RESPONSECODE IFD_Set_Protocol_Parameters(DWORD, UCHAR, UCHAR, + UCHAR, UCHAR); + RESPONSECODE IFD_Power_ICC(DWORD); + RESPONSECODE IFD_Swallow_ICC(void); + RESPONSECODE IFD_Eject_ICC(void); + RESPONSECODE IFD_Confiscate_ICC(void); + RESPONSECODE IFD_Transmit_to_ICC(SCARD_IO_HEADER, PUCHAR, DWORD, + PUCHAR, PDWORD, PSCARD_IO_HEADER); + RESPONSECODE IFD_Is_ICC_Present(void); + RESPONSECODE IFD_Is_ICC_Absent(void); +#ifdef __cplusplus +} +#endif +#endif diff --git a/virtualsmartcard/Makefile.am b/virtualsmartcard/Makefile.am index daf6964..3e46532 100644 --- a/virtualsmartcard/Makefile.am +++ b/virtualsmartcard/Makefile.am @@ -1,5 +1,5 @@ ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = src doc npa-example-data +SUBDIRS = src doc npa-example-data MacOSX EXTRA_DIST = test_vicc_with_npa-tool.sh test_vicc_with_handler_test.sh @@ -10,3 +10,6 @@ distcheck-hook: test -d ../.git && \ git log --pretty --numstat --summary . | git2cl > ChangeLog \ || true + +osx: + $(MAKE) -C MacOSX $@ diff --git a/virtualsmartcard/configure.ac b/virtualsmartcard/configure.ac index 7a2cbf3..744b7ba 100644 --- a/virtualsmartcard/configure.ac +++ b/virtualsmartcard/configure.ac @@ -57,7 +57,10 @@ if test "${libpcsclite}" = no ; then [AC_MSG_WARN([libpcsclite not found by pkg-config]) case "$host" in *-*-darwin*) - PCSC_CFLAGS="-DNO_LOG -I`pwd`/${top_srcdir}/src/pcsclite-vpcd/PCSC" + SDKS_PATH="$(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs" + SDK_PATH="${SDK_PATH:-$SDKS_PATH/$(ls -1 ${SDKS_PATH} | sort -n -t. -k2 -r | head -1)}" + # and set the PC/SC include path + PCSC_CFLAGS="-I$SDK_PATH/System/Library/Frameworks/PCSC.framework/Versions/Current/Headers -DNO_LOG -DRESPONSECODE_DEFINED_IN_WINTYPES_H -I`pwd`/${top_srcdir}/MacOSX" PCSC_LIBS="--framework PCSC" esac ]) @@ -65,7 +68,7 @@ if test "${libpcsclite}" = no ; then saved_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $PCSC_CFLAGS" AC_CHECK_HEADERS(ifdhandler.h,, - [ AC_MSG_ERROR([ifdhandler.h not found, install libpcsclite or use ./configure PCSC_CFLAGS=...]) ]) + [ AC_MSG_ERROR([ifdhandler.h not found, install libpcsclite or use ./configure PCSC_CFLAGS=...])], [#include ]) CPPFLAGS="$saved_CPPFLAGS" @@ -272,5 +275,6 @@ AC_CONFIG_FILES([Makefile src/vpcd/Makefile src/vpicc/Makefile src/vpcd-config/Makefile + MacOSX/Makefile ]) AC_OUTPUT diff --git a/virtualsmartcard/src/ifd-vpcd/ifd-vpcd.c b/virtualsmartcard/src/ifd-vpcd/ifd-vpcd.c index b76a52c..1305650 100644 --- a/virtualsmartcard/src/ifd-vpcd/ifd-vpcd.c +++ b/virtualsmartcard/src/ifd-vpcd/ifd-vpcd.c @@ -20,6 +20,7 @@ #include "vpcd.h" #include #include +#include #include #include #include