linking against opensc now as shared library

git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@394 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
frankmorgner
2011-01-31 11:51:31 +00:00
parent 8ab0ea2eb3
commit 29fdf375e9
10 changed files with 90 additions and 88 deletions

18
bitbake/npa.bb Normal file
View File

@@ -0,0 +1,18 @@
DESCRIPTION = "API and Tools for the new German identity card (neuer Personalausweis, nPA)"
LICENSE = "GPL"
DEPENDS = "openssl opensc"
RDEPENDS = "libcrypto opensc"
SRC_URI = "svn://vsmartcard.svn.sourceforge.net/svnroot;module=vsmartcard;proto=https;rev=384"
S = "${WORKDIR}/vsmartcard/npa"
inherit autotools pkgconfig
EXTRA_OECONF = ""
FILES_${PN} += "\
${bindir}/* \
${libdir}/* \
"

View File

@@ -33,26 +33,12 @@ https://docs.openmoko.org/trac/ticket/2240).
@subsection o HINTS ON OPENSC @subsection o HINTS ON OPENSC
ccid-emulator links against libopensc, which is discouraged and hindered since Without libnpa ccid-emulator links against libopensc, which is discouraged and
opensc>=0.12. We really need to get rid of this dependency. But so far we hindered since opensc>=0.12. We really need to get rid of this dependency. You
manually build it to have libopensc for linking. The good thing is that you need the opensc components to be installed (especially libopensc.so). But you
don't need any opensc components to be installed. The bad thing is, that might need to adjust the opensc library flags:
ccid-emulator configures and builds opensc on its own. So you might need to
pass some extra configure options to opensc. So if you need to pass options to
opensc, use something like the following command:
./configure \ ./configure \
OPENSC_CONFIGURE="options" OPENSC_LIBS="-L/path/to/opensc/libdir -lopensc"
@subsection l HINTS ON LIBPACE
If you have a local build of libpace and OpenPACE, that you want to link
against use something like the following command:
./configure \
OPENSSL_CFLAGS="-I/path/to/openssl-1.0.0c_with_openpace-0.4/include" \
LIBPACE_CFLAGS="-I/path/to/openssl-1.0.0c_with_openpace-0.4/include -I/path/to/libpace-0.1/src" \
OPENSSL_LIBS="-L/path/to/openssl-1.0.0c_with_openpace-0.4 -lcrypto" \
LIBPACE_LIBS="-L/path/to/openssl-1.0.0c_with_openpace-0.4 -lcrypto -L/path/to/libpace-0.1/src/.libs -lpace"
@section u USAGE @section u USAGE

View File

@@ -67,22 +67,31 @@ LIBS="$saved_LIBS"
AC_ARG_ENABLE(pace, AC_ARG_ENABLE(pace,
AS_HELP_STRING([--enable-pace], [Enable Password Authenticated Connection Establishment (PACE)]), AS_HELP_STRING([--enable-pace], [Enable Password Authenticated Connection Establishment (PACE)]),
[enable_pace="${enableval}"], [enable_pace=no]) [enable_pace="${enableval}"], [enable_pace=no])
saved_CPPFLAGS="$CPPFLAGS"
saved_LIBS="$LIBS"
if test "x$enable_pace" != xno ; then if test "x$enable_pace" != xno ; then
PKG_CHECK_EXISTS([libpace], PKG_CHECK_EXISTS([libpace],
[PKG_CHECK_MODULES([LIBPACE], [libpace])], [PKG_CHECK_MODULES([LIBPACE], [libpace])],
[AC_MSG_WARN([libpace not found by pkg-config])]) [AC_MSG_WARN([libpace not found by pkg-config])])
saved_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $LIBPACE_CFLAGS -I$(pwd)/src/opensc/src"
saved_LIBS="$LIBS"
CPPFLAGS="$CPPFLAGS $LIBPACE_CFLAGS -I$(pwd)/src/opensc-0.12.0/src"
LIBS="$LDFLAGS $LIBPACE_LIBS" LIBS="$LDFLAGS $LIBPACE_LIBS"
AC_CHECK_HEADERS(pace/pace.h, [], [ AC_MSG_ERROR([pace/pace.h not found, install libpace or use ./configure LIBPACE_CFLAGS=...]) ]) AC_CHECK_HEADERS(pace/pace.h, [], [ AC_MSG_ERROR([pace/pace.h not found, install libpace or use ./configure LIBPACE_CFLAGS=...]) ])
AC_MSG_CHECKING([for EstablishPACEChannel]) AC_MSG_CHECKING([for EstablishPACEChannel])
AC_TRY_LINK_FUNC(EstablishPACEChannel, [ AC_MSG_RESULT([yes]) ], [ AC_MSG_ERROR([libpace not found, use ./configure LIBPACE_LIBS=...]) ]) AC_TRY_LINK_FUNC(EstablishPACEChannel, [ AC_MSG_RESULT([yes]) ], [ AC_MSG_ERROR([libpace not found, use ./configure LIBPACE_LIBS=...]) ])
CPPFLAGS="$saved_CPPFLAGS"
LIBS="$saved_LIBS"
enable_pace=yes enable_pace=yes
else
PKG_CHECK_EXISTS([libopensc],
[PKG_CHECK_MODULES([OPENSC], [libopensc >= 0.12])],
[AC_MSG_WARN([libopensc >= 0.12 not found by pkg-config])])
test -z "$OPENSC_LIBS" && OPENSC_LIBS="-lopensc"
LIBS="$LDFLAGS $OPENSC_LIBS $OPENSSL_LIBS"
AC_MSG_CHECKING([for sc_ctx_get_reader_count])
AC_TRY_LINK_FUNC(sc_ctx_get_reader_count, [ AC_MSG_RESULT([yes]) ],
[ AC_MSG_ERROR([libopensc >= 0.12 not found, use ./configure OPENSC_LIBS=...]) ])
fi fi
CPPFLAGS="$saved_CPPFLAGS"
LIBS="$saved_LIBS"
AM_CONDITIONAL(WITH_PACE, test "${enable_pace}" != "no") AM_CONDITIONAL(WITH_PACE, test "${enable_pace}" != "no")
AM_COND_IF(WITH_PACE, [AC_DEFINE(WITH_PACE, 1, [enable PACE support])]) AM_COND_IF(WITH_PACE, [AC_DEFINE(WITH_PACE, 1, [enable PACE support])])
@@ -134,9 +143,6 @@ fi
AM_CONDITIONAL(DOC_ENABLED, [test x"$enable_doc" = xyes]) AM_CONDITIONAL(DOC_ENABLED, [test x"$enable_doc" = xyes])
AC_SUBST(OPENSC_CONFIGURE)
# Checks for header files. # Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h fcntl.h memory.h stdint.h stdlib.h string.h sys/ioctl.h unistd.h]) AC_CHECK_HEADERS([arpa/inet.h fcntl.h memory.h stdint.h stdlib.h string.h sys/ioctl.h unistd.h])
@@ -172,13 +178,13 @@ Linker flags: ${LDFLAGS}
Libraries: ${LIBS} Libraries: ${LIBS}
PTHREAD_CFLAGS: ${PTHREAD_CFLAGS} PTHREAD_CFLAGS: ${PTHREAD_CFLAGS}
PTHREAD_LIBS: ${PTHREAD_LIBS} PTHREAD_LIBS: ${PTHREAD_LIBS}
OPENSC_LIBS: ${OPENSC_LIBS}
OPENSSL_CFLAGS: ${OPENSSL_CFLAGS} OPENSSL_CFLAGS: ${OPENSSL_CFLAGS}
OPENSSL_LIBS: ${OPENSSL_LIBS} OPENSSL_LIBS: ${OPENSSL_LIBS}
LIBPACE_CFLAGS: ${LIBPACE_CFLAGS} LIBPACE_CFLAGS: ${LIBPACE_CFLAGS}
LIBPACE_LIBS: ${LIBPACE_LIBS} LIBPACE_LIBS: ${LIBPACE_LIBS}
PCSC_CFLAGS: ${PCSC_CFLAGS} PCSC_CFLAGS: ${PCSC_CFLAGS}
PCSC_LIBS: ${PCSC_LIBS} PCSC_LIBS: ${PCSC_LIBS}
OPENSC_CONFIGURE: ${OPENSC_CONFIGURE}
CCID emulator: ${enable_ccid} CCID emulator: ${enable_ccid}
PACE support: ${enable_pace} PACE support: ${enable_pace}

View File

@@ -1,27 +1,15 @@
OPENSCVERSION = 0.12.0 EXTRA_DIST = opensc
EXTRA_DIST = opensc-$(OPENSCVERSION) AM_CPPFLAGS = -I$(top_srcdir)/src/opensc/src
AM_CPPFLAGS = -I$(top_srcdir)/src/opensc-$(OPENSCVERSION)/src
ccid_emulator_SOURCES = ccid.c usbstring.c usb.c binutil.c ccid_emulator_SOURCES = ccid.c usbstring.c usb.c binutil.c
ccid_emulator_LDADD = $(OPENSC_LIBS) $(OPENSSL_LIBS) $(PTHREAD_LIBS) ccid_emulator_LDADD = $(OPENSSL_LIBS) $(PTHREAD_LIBS)
ccid_emulator_CFLAGS = $(OPENSC_CFLAGS) $(OPENSSL_CFLAGS) $(PTHREAD_CFLAGS) ccid_emulator_CFLAGS = $(OPENSSL_CFLAGS) $(PTHREAD_CFLAGS)
cats_test_SOURCES = cats-test.c pcscutil.c cats_test_SOURCES = cats-test.c pcscutil.c
cats_test_LDADD = $(PCSC_LIBS) cats_test_LDADD = $(PCSC_LIBS)
cats_test_CFLAGS = $(PCSC_CFLAGS) cats_test_CFLAGS = $(PCSC_CFLAGS)
opensc:
cp -r $(top_srcdir)/src/opensc-$(OPENSCVERSION) opensc
cd opensc && ./configure OPENSSL_LIBS="$(OPENSSL_LIBS)" OPENSSL_CFLAGS="$(OPENSSL_CFLAGS)" $(OPENSC_CONFIGURE)
libopensc.la: opensc
$(MAKE) -C opensc
cp opensc/src/libopensc/.libs/libopensc.* .
clean-local:
rm -rf opensc libopensc.*
bin_PROGRAMS = bin_PROGRAMS =
@@ -47,5 +35,5 @@ ccid_emulator_LDADD += $(LIBPACE_LIBS)
ccid_emulator_CFLAGS += $(LIBPACE_CFLAGS) ccid_emulator_CFLAGS += $(LIBPACE_CFLAGS)
else else
ccid_emulator_SOURCES += scutil.c ccid_emulator_SOURCES += scutil.c
ccid_emulator_LDADD += libopensc.la ccid_emulator_LDADD += $(OPENSC_LIBS)
endif endif

View File

@@ -12,6 +12,7 @@ do_subst = sed \
-e 's,[@]libdir[@],$(libdir),g' \ -e 's,[@]libdir[@],$(libdir),g' \
-e 's,[@]includedir[@],$(includedir),g' \ -e 's,[@]includedir[@],$(includedir),g' \
-e 's,[@]VERSION[@],$(VERSION),g' \ -e 's,[@]VERSION[@],$(VERSION),g' \
-e 's,[@]OPENSC_LIBS[@],$(OPENSC_LIBS),g' \
-e 's,[@]top_srcdir[@],$(top_srcdir),g' -e 's,[@]top_srcdir[@],$(top_srcdir),g'
opensc-0.11.13.tar.gz: opensc-0.11.13.tar.gz:

View File

@@ -20,19 +20,11 @@ See file INSTALL.
@subsection o HINTS ON OPENSC @subsection o HINTS ON OPENSC
libnpa links against libopensc, which is discouraged and hindered since libnpa links against libopensc, which is discouraged and hindered since
opensc>=0.12. We really need to get rid of this dependency. But so far we opensc>=0.12. We really need to get rid of this dependency. You need the opensc
manually build it to have libopensc for linking. The good thing is that you components to be installed (especially libopensc.so). But you might need to
don't need any opensc components to be installed. The bad thing is, that libnpa adjust the opensc library flags:
configures and builds opensc on its own. So you might need to pass some extra
configure options to opensc. So if you need to pass options to opensc, use
something like the following command:
./configure \ ./configure \
OPENSC_CONFIGURE="options" OPENSC_LIBS="-L/path/to/opensc/libdir -lopensc"
Worse gets the situation if you need to link against libnpa and some opensc
library at the same time. This will yield conflicts since functionality of
libopensc is linked into both libraries. This is possible (see ccid-emulator),
but not recommended. Only do this if you know what you are doing.
@subsection o HINTS ON OPENSSL @subsection o HINTS ON OPENSSL
@@ -55,6 +47,20 @@ To pass a secret to pace-tool, the command line parameters or the environment
variables PIN/CAN/MRZ/PUK/NEWPIN can be used. If none of these options is used, variables PIN/CAN/MRZ/PUK/NEWPIN can be used. If none of these options is used,
pace-tool will show a password prompt. pace-tool will show a password prompt.
@subsection l LINKING AGAINST LIBNPA
If you have a local build of libpace and OpenPACE, the preferred way to adjust
libraries and cflags for foreign code is to use pkg-config:
./configure \
PKG_CONFIG_PATH=/path/to/openssl-1.0.0c_with_openpace-0.4/lib/pkgconfig:/path/to/libpace/lib/pkgconfig"
Alternatively you can define libs and cflags by hand:
./configure \
OPENSSL_CFLAGS="-I/path/to/openssl-1.0.0c_with_openpace-0.4/include" \
LIBPACE_CFLAGS="-I/path/to/openssl-1.0.0c_with_openpace-0.4/include -I/path/to/libpace-0.1/src" \
OPENSSL_LIBS="-L/path/to/openssl-1.0.0c_with_openpace-0.4 -lcrypto" \
LIBPACE_LIBS="-L/path/to/openssl-1.0.0c_with_openpace-0.4 -lcrypto -L/path/to/libpace-0.1/src/.libs -lpace"
@section q QUESTIONS @section q QUESTIONS
For questions, please use http://sourceforge.net/projects/vsmartcard/support For questions, please use http://sourceforge.net/projects/vsmartcard/support

View File

@@ -19,15 +19,22 @@ AM_PROG_CC_C_O
PKG_PROG_PKG_CONFIG PKG_PROG_PKG_CONFIG
# Checks for libraries. # Checks for libraries.
PKG_CHECK_EXISTS([libopensc],
[PKG_CHECK_MODULES([OPENSC], [libopensc >= 0.12 ])],
[AC_MSG_WARN([libopensc >= 0.12 not found by pkg-config])])
test -z "$OPENSC_LIBS" && OPENSC_LIBS="-lopensc"
PKG_CHECK_EXISTS([libssl], PKG_CHECK_EXISTS([libssl],
[PKG_CHECK_MODULES([OPENSSL], [libssl])], [PKG_CHECK_MODULES([OPENSSL], [libssl])],
[AC_MSG_WARN([libssl not found by pkg-config])]) [AC_MSG_WARN([libssl not found by pkg-config])])
saved_CPPFLAGS="$CPPFLAGS" saved_CPPFLAGS="$CPPFLAGS"
saved_LIBS="$LIBS" saved_LIBS="$LIBS"
CPPFLAGS="$CPPFLAGS $OPENSSL_CFLAGS" CPPFLAGS="$CPPFLAGS $OPENSSL_CFLAGS"
LIBS="$LDFLAGS $OPENSSL_LIBS" LIBS="$LDFLAGS $OPENSC_LIBS $OPENSSL_LIBS"
AC_MSG_CHECKING([for sc_ctx_get_reader_count])
AC_TRY_LINK_FUNC(sc_ctx_get_reader_count, [ AC_MSG_RESULT([yes]) ],
[ AC_MSG_ERROR([libopensc >= 0.12 not found, use ./configure OPENSC_LIBS=...]) ])
AC_CHECK_HEADERS(openssl/evp.h, [], [ AC_MSG_ERROR([openssl/evp.h not found, install OpenSSL or use ./configure OPENSSL_CFLAGS=...]) ]) AC_CHECK_HEADERS(openssl/evp.h, [], [ AC_MSG_ERROR([openssl/evp.h not found, install OpenSSL or use ./configure OPENSSL_CFLAGS=...]) ])
AC_MSG_CHECKING([for EVP_read_pw_string_min]) AC_MSG_CHECKING([for EVP_read_pw_string_min])
@@ -56,9 +63,6 @@ fi
AM_CONDITIONAL(DOC_ENABLED, [test x"$enable_doc" = xyes]) AM_CONDITIONAL(DOC_ENABLED, [test x"$enable_doc" = xyes])
AC_SUBST(OPENSC_CONFIGURE)
# Checks for header files. # Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h fcntl.h memory.h stdint.h stdlib.h string.h sys/ioctl.h unistd.h]) AC_CHECK_HEADERS([arpa/inet.h fcntl.h memory.h stdint.h stdlib.h string.h sys/ioctl.h unistd.h])
@@ -92,9 +96,9 @@ Compiler flags: ${CFLAGS}
Preprocessor flags: ${CPPFLAGS} Preprocessor flags: ${CPPFLAGS}
Linker flags: ${LDFLAGS} Linker flags: ${LDFLAGS}
Libraries: ${LIBS} Libraries: ${LIBS}
OPENSC_LIBS: ${OPENSC_LIBS}
OPENSSL_CFLAGS: ${OPENSSL_CFLAGS} OPENSSL_CFLAGS: ${OPENSSL_CFLAGS}
OPENSSL_LIBS: ${OPENSSL_LIBS} OPENSSL_LIBS: ${OPENSSL_LIBS}
OPENSC_CONFIGURE: ${OPENSC_CONFIGURE}
Documentation: ${enable_doc} Documentation: ${enable_doc}

View File

@@ -7,5 +7,5 @@ Name: libpace
Description: Password Authenticated Connection Establishment (PACE) library Description: Password Authenticated Connection Establishment (PACE) library
Version: @VERSION@ Version: @VERSION@
Requires: libssl Requires: libssl
Libs: -L${libdir} -lpace Libs: -L${libdir} -lpace @OPENSC_LIBS@
Cflags: -I${includedir} Cflags: -I${includedir}

View File

@@ -1,28 +1,15 @@
OPENSCVERSION = 0.12.0 EXTRA_DIST = opensc
EXTRA_DIST = opensc-$(OPENSCVERSION) AM_CPPFLAGS = -I$(top_srcdir)/src/pace -I$(top_srcdir)/src/opensc/src
AM_CPPFLAGS = -I$(top_srcdir)/src/pace -I$(top_srcdir)/src/opensc-$(OPENSCVERSION)/src
libpace_la_SOURCES = sm.c scutil.c pace.c pace_lib.c libpace_la_SOURCES = sm.c scutil.c pace.c pace_lib.c
libpace_la_LIBADD = $(OPENSSL_LIBS) libopensc.la libpace_la_LIBADD = $(OPENSSL_LIBS) $(OPENSC_LIBS)
libpace_la_CFLAGS = $(OPENSSL_CFLAGS) libpace_la_CFLAGS = $(OPENSSL_CFLAGS)
pace_tool_SOURCES = pace-tool.c binutil.c pace_tool_SOURCES = pace-tool.c binutil.c
pace_tool_LDADD = $(OPENSSL_LIBS) libpace.la libopensc.la pace_tool_LDADD = $(OPENSSL_LIBS) $(OPENSC_LIBS) libpace.la
pace_tool_CFLAGS = $(OPENSSL_CFLAGS) pace_tool_CFLAGS = $(OPENSSL_CFLAGS)
opensc:
cp -r $(top_srcdir)/src/opensc-$(OPENSCVERSION) opensc
cd opensc && ./configure OPENSSL_LIBS="$(OPENSSL_LIBS)" OPENSSL_CFLAGS="$(OPENSSL_CFLAGS)" $(OPENSC_CONFIGURE)
.PHONY:libopensc.la
libopensc.la: opensc
$(MAKE) -C opensc
cp opensc/src/libopensc/.libs/libopensc.* .
clean-local:
rm -rf opensc libopensc.*
bin_PROGRAMS = pace-tool bin_PROGRAMS = pace-tool

View File

@@ -185,6 +185,7 @@ main (int argc, char **argv)
struct establish_pace_channel_input pace_input; struct establish_pace_channel_input pace_input;
struct establish_pace_channel_output pace_output; struct establish_pace_channel_output pace_output;
time_t t_start, t_end; time_t t_start, t_end;
struct timeval tv;
size_t outlen; size_t outlen;
memset(&sctx, 0, sizeof sctx); memset(&sctx, 0, sizeof sctx);
@@ -367,23 +368,28 @@ main (int argc, char **argv)
if (strlen(can_ch) > pace_input.pin_length) if (strlen(can_ch) > pace_input.pin_length)
break; break;
printf("Trying %s=%s\n", gettimeofday(&tv, NULL);
printf("%d,%06d: Trying %s=%s\n",
tv.tv_sec, tv.tv_usec,
pace_secret_name(pace_input.pin_id), pace_input.pin); pace_secret_name(pace_input.pin_id), pace_input.pin);
i = EstablishPACEChannel(NULL, card, pace_input, &pace_output, i = EstablishPACEChannel(NULL, card, pace_input, &pace_output,
&sctx); &sctx);
can_nb++; can_nb--;
} while (0 > i); } while (0 > i && can_nb > 0);
t_end = time(NULL); t_end = time(NULL);
gettimeofday(&tv, NULL);
if (0 > i) { if (0 > i) {
printf("Tried breaking %s for %.0fs without success.\n", printf("%d,%06d: Tried breaking %s for %.0fs without success.\n",
tv.tv_sec, tv.tv_usec,
pace_secret_name(pace_input.pin_id), difftime(t_end, t_start)); pace_secret_name(pace_input.pin_id), difftime(t_end, t_start));
goto err; goto err;
} else { } else {
printf("Tried breaking %s for %.0fs with success.\n", printf("%d,%06d: Tried breaking %s for %.0fs with success (%s=%s).\n",
pace_secret_name(pace_input.pin_id), difftime(t_end, t_start)); tv.tv_sec, tv.tv_usec,
printf("%s=%s\n", pace_secret_name(pace_input.pin_id), pace_input.pin); pace_secret_name(pace_input.pin_id), difftime(t_end, t_start),
pace_secret_name(pace_input.pin_id), pace_input.pin);
} }
} }