Skip to content

Commit

Permalink
ccid-emulator: Build libopensc from source code
Browse files Browse the repository at this point in the history
There is no longer an external (or stable) interface for libopensc.
Linking this program with an existing version of libopensc that is
pre-installed in the system library paths is not practical.

However, a specific snapshot of the OpenSC source code is embedded
here as a Git submodule (and included in the source distributions).
Build libopensc from this and statically link it into this program.
(Options such as '--enable-openpace' that are passed to ./configure
will be forwarded to control the build configuration of libopensc.)

Remove code that existed for compatibility when dynamically linking
with older versions of libopensc.
  • Loading branch information
dpward committed Apr 11, 2020
1 parent c18df66 commit bc8b237
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 456 deletions.
11 changes: 1 addition & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ before_script:
./configure --prefix=$PREFIX --enable-openssl-install --enable-python || cat config.log;
make install;
fi
# ccid requires OpenSC
- git clone https://github.com/frankmorgner/OpenSC
- cd OpenSC && autoreconf -vsi
- if [ -z "$HOST" ]; then
./configure --prefix=$PREFIX --with-completiondir=/tmp || cat config.log;
else
./configure --prefix=$PREFIX --with-completiondir=/tmp --host=$HOST || cat config.log;
fi
- make install
# Configure virtualsmartcard
- cd $TRAVIS_BUILD_DIR/virtualsmartcard && autoreconf -vsi
- if [ -z "$HOST" ]; then
Expand All @@ -85,7 +76,7 @@ before_script:
# Configure ccid
- if [ $TRAVIS_OS_NAME == linux -a -z "$HOST" ]; then
cd $TRAVIS_BUILD_DIR/ccid && autoreconf -vsi;
./configure OPENSC_LIBS="-L$PREFIX/lib -lopensc" || cat config.log;
./configure || cat config.log;
fi
# Optionally try to upload to Coverity Scan
# On error (propably quota is exhausted), just continue
Expand Down
25 changes: 24 additions & 1 deletion ccid/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
ACLOCAL_AMFLAGS = -I m4

SUBDIRS = src doc
SUBDIRS = . src doc

DIST_SUBDIRS = $(SUBDIRS) src/OpenSC

EXTRA_DIST = docs patches

all-local:
cd src/OpenSC/src/common && $(MAKE) $(AM_MAKEFLAGS) all
cd src/OpenSC/src/scconf && $(MAKE) $(AM_MAKEFLAGS) all
cd src/OpenSC/src/pkcs15init && $(MAKE) $(AM_MAKEFLAGS) all
cd src/OpenSC/src/sm && $(MAKE) $(AM_MAKEFLAGS) all
cd src/OpenSC/src/libopensc && $(MAKE) $(AM_MAKEFLAGS) all

check-local:
cd src/OpenSC/src/common && $(MAKE) $(AM_MAKEFLAGS) check
cd src/OpenSC/src/scconf && $(MAKE) $(AM_MAKEFLAGS) check
cd src/OpenSC/src/pkcs15init && $(MAKE) $(AM_MAKEFLAGS) check
cd src/OpenSC/src/sm && $(MAKE) $(AM_MAKEFLAGS) check
cd src/OpenSC/src/libopensc && $(MAKE) $(AM_MAKEFLAGS) check

clean-local:
cd src/OpenSC/src/common && $(MAKE) $(AM_MAKEFLAGS) clean
cd src/OpenSC/src/scconf && $(MAKE) $(AM_MAKEFLAGS) clean
cd src/OpenSC/src/pkcs15init && $(MAKE) $(AM_MAKEFLAGS) clean
cd src/OpenSC/src/sm && $(MAKE) $(AM_MAKEFLAGS) clean
cd src/OpenSC/src/libopensc && $(MAKE) $(AM_MAKEFLAGS) clean
18 changes: 2 additions & 16 deletions ccid/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,6 @@ AC_TRY_LINK_FUNC(EVP_read_pw_string_min, [ AC_MSG_RESULT([yes]) ], [ AC_MSG_ERRO
CPPFLAGS="$saved_CPPFLAGS"
LIBS="$saved_LIBS"

saved_CPPFLAGS="$CPPFLAGS"
saved_LIBS="$LIBS"
PKG_CHECK_EXISTS([libopensc],
[PKG_CHECK_MODULES([OPENSC], [libopensc >= 0.12.1])],
[AC_MSG_WARN([libopensc >= 0.12.1 not found by pkg-config])])
test -z "$OPENSC_LIBS" && OPENSC_LIBS="-lopensc $OPENSSL_LIBS"
LIBS="$LDFLAGS $OPENSC_LIBS"
AC_MSG_CHECKING([for sc_bytes2apdu])
AC_TRY_LINK_FUNC(sc_bytes2apdu, [ AC_MSG_RESULT([yes]) ],
[ AC_MSG_ERROR([libopensc >= 0.12.1 not found, use ./configure OPENSC_LIBS=...]) ])
AC_CHECK_FUNCS([sc_apdu_set_resp sc_apdu_get_octets _sc_match_atr boxing_buf_to_pace_input])
CPPFLAGS="$saved_CPPFLAGS"
LIBS="$saved_LIBS"


PACKAGE_SUMMARY="Emulate a USB CCID compliant smart card reader"
AC_SUBST(PACKAGE_SUMMARY)

Expand Down Expand Up @@ -102,6 +87,8 @@ AC_CONFIG_FILES([
doc/Makefile
])

AC_CONFIG_SUBDIRS([src/OpenSC])

AC_OUTPUT

cat << EOF
Expand All @@ -122,7 +109,6 @@ Libraries: ${LIBS}

PTHREAD_CFLAGS: ${PTHREAD_CFLAGS}
PTHREAD_LIBS: ${PTHREAD_LIBS}
OPENSC_LIBS: ${OPENSC_LIBS}
OPENSSL_CFLAGS: ${OPENSSL_CFLAGS}
OPENSSL_LIBS: ${OPENSSL_LIBS}

Expand Down
1 change: 0 additions & 1 deletion ccid/doc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ do_subst = $(SED) \
-e 's,[@]libdir[@],$(libdir),g' \
-e 's,[@]includedir[@],$(includedir),g' \
-e 's,[@]VERSION[@],$(VERSION),g' \
-e 's,[@]OPENSC_LIBS[@],$(OPENSC_LIBS),g' \
-e 's,[@]abs_top_srcdir[@],$(abs_top_srcdir),g' \
-e 's,[@]top_srcdir[@],$(top_srcdir),g'

Expand Down
30 changes: 3 additions & 27 deletions ccid/doc/README.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ modern Windows and Unix-like systems by default.

.. include:: autotools.txt

The @PACKAGE_NAME@ depends on :program:`libopensc`, which is automatically
built from a snapshot of the OpenSC source code and then statically linked.


=================
Hints on GadgetFS
Expand Down Expand Up @@ -302,33 +305,6 @@ loading the module, you maybe want to check out `this patch
<https://comments.gmane.org/gmane.linux.usb.general/47440>`_.


===============
Hints on OpenSC
===============

@PACKAGE_NAME@ needs the OpenSC components to be
installed (especially :file:`libopensc.so`). Here is an example of how to get
the standard installation of OpenSC without |PACE|::

PREFIX=/tmp/install
VSMARTCARD=$PWD/vsmartcard
git clone https://github.com/frankmorgner/vsmartcard.git $VSMARTCARD
cd $VSMARTCARD
git submodule init
git submodule update
cd $VSMARTCARD/ccid/src/opensc
autoreconf --verbose --install
./configure --prefix=$PREFIX
make install && cd -

Now :file:`libopensc.so` should be located in ``$PREFIX/lib``. Here is how to
configure the @PACKAGE_NAME@ to use it::

cd $VSMARTCARD/ccid
./configure --prefix=$PREFIX OPENSC_LIBS="-L$PREFIX/lib -lopensc"
make install && cd -


*****
Usage
*****
Expand Down
5 changes: 2 additions & 3 deletions ccid/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ do_subst = $(SED) \
BUILT_SOURCES = cmdline.h cmdline.c

EXTRA_DIST = ccid-emulator.ggo ccid-emulator.ggo.in
EXTRA_DIST += $(shell find $(top_srcdir)/src/OpenSC/src -path '*/.git' -prune -o -type f -a \( -name '*.h' -o -name 'apdu.c' -o -name 'card.c' \) -print)
MAINTAINERCLEANFILES = $(BUILT_SOURCES) ccid-emulator.ggo $(dist_man1_MANS)

dist_man1_MANS = ccid-emulator.1

ccid_emulator_SOURCES = cmdline.c ccid.c usbstring.c usb.c scutil.c
ccid_emulator_LDADD = $(OPENSC_LIBS) $(OPENSSL_LIBS) $(PTHREAD_LIBS)
ccid_emulator_LDADD = OpenSC/src/libopensc/libopensc.la
ccid_emulator_LDFLAGS = $(OPENSSL_LIBS) $(PTHREAD_LIBS) -static
ccid_emulator_CFLAGS = $(OPENSSL_CFLAGS) $(PTHREAD_CFLAGS) -I$(top_srcdir)/src/OpenSC/src


Expand All @@ -42,7 +42,6 @@ bin_PROGRAMS = ccid-emulator

noinst_HEADERS = \
ccid.h \
ccid-types.h \
cmdline.h \
scutil.h \
usbstring.h
Loading

0 comments on commit bc8b237

Please sign in to comment.