Skip to content

Commit

Permalink
include OpenSC as submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Morgner committed Dec 16, 2012
1 parent fe155bb commit d479420
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 144 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "npa/src/opensc"]
path = npa/src/opensc
url = git://github.com/OpenSC/OpenSC.git
6 changes: 3 additions & 3 deletions doc/autotools.rst.in
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.. highlight:: sh

=============
============
Installation
=============
============

The @PACKAGE_NAME@ uses the GNU Build System to compile and install. If you are
unfamiliar with it, please have a look at :file:`INSTALL`. If you have a look
around and can not find it, you are probably working bleeding edge in the
repository. Run the following command in :file:`@PACKAGE_TARNAME@` to
get the missing standard auxiliary files::

autoreconf -i
autoreconf --verbose --install

To configure (:command:`configure --help` lists possible options), build and
install the @PACKAGE_NAME@ now do the following::
Expand Down
33 changes: 22 additions & 11 deletions npa/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,25 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])


# Checks for libraries.
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"
test -z "$OPENSC_CFLAGS" && OPENSC_CFLAGS="-I${PWD}/${srcdir}/src/opensc/src -DENABLE_SM"

saved_CPPFLAGS="$CPPFLAGS"
saved_LIBS="$LIBS"
CPPFLAGS="$OPENSC_CFLAGS $CPPFLAGS"
LIBS="$LDFLAGS $OPENSC_LIBS"

AC_CHECK_HEADERS([libopensc/opensc.h libopensc/sm.h libopensc/pace.h],
[], [AC_MSG_ERROR([OpenSC headers not found])])
AC_MSG_CHECKING([for iasecc_sm_external_authentication])
AC_TRY_LINK_FUNC(iasecc_sm_external_authentication, [ AC_MSG_RESULT([yes]) ],
[ AC_MSG_ERROR([libopensc configured with SM (git clone git://github.com/frankmorgner/OpenSC.git) not found, use ./configure OPENSC_LIBS=...]) ])
AC_TRY_LINK_FUNC(iasecc_sm_external_authentication,
[ AC_MSG_RESULT([yes]) ],
[ AC_MSG_ERROR([Cannot link against libopensc with SM]) ])

CPPFLAGS="$saved_CPPFLAGS"
LIBS="$saved_LIBS"
AC_SUBST([OPENSC_LIBS])
AC_SUBST([OPENSC_CFLAGS])


PKG_CHECK_EXISTS([libcrypto],
Expand All @@ -71,26 +77,30 @@ saved_LIBS="$LIBS"
CPPFLAGS="$CPPFLAGS $OPENSSL_CFLAGS"
LIBS="$LDFLAGS $OPENSSL_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 headers not found]) ])
AC_MSG_CHECKING([for EVP_read_pw_string_min])
AC_TRY_LINK_FUNC(EVP_read_pw_string_min, [ AC_MSG_RESULT([yes]) ], [ AC_MSG_ERROR([OpenSSL not found, use ./configure OPENSSL_LIBS=...]) ])
AC_TRY_LINK_FUNC(EVP_read_pw_string_min,
[ AC_MSG_RESULT([yes]) ],
[ AC_MSG_ERROR([Cannot link against libcrypto]) ])

CPPFLAGS="$saved_CPPFLAGS"
LIBS="$saved_LIBS"


PKG_CHECK_EXISTS([libeac],
[PKG_CHECK_MODULES([OPENPACE], [libeac])],
PKG_CHECK_EXISTS([libeac], [PKG_CHECK_MODULES([OPENPACE], [libeac])],
[AC_MSG_WARN([libeac not found by pkg-config])])

saved_CPPFLAGS="$CPPFLAGS"
saved_LIBS="$LIBS"
CPPFLAGS="$CPPFLAGS $OPENPACE_CFLAGS"
LIBS="$LDFLAGS $OPENPACE_LIBS"

AC_CHECK_HEADERS(eac/eac.h, [], [ AC_MSG_ERROR([eac/eac.h not found, install OpenPACE or use ./configure OPENSSL_CFLAGS=...]) ])
AC_CHECK_HEADERS(eac/eac.h, [],
[ AC_MSG_ERROR([OpenPACE headers not found]) ])
AC_MSG_CHECKING([for EAC_CTX_init_pace])
AC_TRY_LINK_FUNC(EAC_CTX_init_pace, [ AC_MSG_RESULT([yes]) ], [ AC_MSG_ERROR([OpenPACE not found, use ./configure OPENPACE_LIBS=...]) ])
AC_TRY_LINK_FUNC(EAC_CTX_init_pace, [ AC_MSG_RESULT([yes]) ],
[ AC_MSG_ERROR([Cannot link against libeac]) ])

CPPFLAGS="$saved_CPPFLAGS"
LIBS="$saved_LIBS"
Expand Down Expand Up @@ -131,6 +141,7 @@ Preprocessor flags: ${CPPFLAGS}
Linker flags: ${LDFLAGS}
Libraries: ${LIBS}
OPENSC_LIBS: ${OPENSC_LIBS}
OPENSC_CFLAGS: ${OPENSC_CFLAGS}
OPENSSL_CFLAGS: ${OPENSSL_CFLAGS}
OPENSSL_LIBS: ${OPENSSL_LIBS}
OPENPACE_CFLAGS: ${OPENPACE_CFLAGS}
Expand Down
118 changes: 59 additions & 59 deletions npa/doc/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.. highlight:: sh

.. _OpenSC: http://www.opensc-project.org
.. _OpenSC with PACE: http://github.com/frankmorgner/OpenSC
.. _OpenSC: https://github.com/OpenSC/OpenSC
.. _OpenSSL: http://www.openssl.org
.. _OpenPACE: http://openpace.sourceforge.net

Expand Down Expand Up @@ -30,8 +29,10 @@ The nPA Smart Card Library offers an easy to use API for the new German identity
which could also be used for other cards. The included |npa-tool| can
be used for PIN management or to send APDUs inside a secure channel.

The nPA Smart Card Library is implemented using OpenPACE_. Some fragments of the
source code are based on the source code of the OpenSC_ tools.
The nPA Smart Card Library is implemented using OpenPACE_ and OpenSC_. nPA Smart Card Library
implements and initializes Secure Messaging wrappers of OpenSC to allow a
transparent SM usage in OpenSC. This allows nPA Smart Card Library to be fully
compatible with OpenSC.


.. _npa-install:
Expand All @@ -40,61 +41,62 @@ source code are based on the source code of the OpenSC_ tools.

The nPA Smart Card Library has the following dependencies:

- `OpenSC with PACE`_
- OpenSSL_ with OpenPACE_
- OpenSSL_
- OpenPACE_
- OpenSC_


------------------------------
Hints on OpenSSL with OpenPACE
------------------------------
------------------------------------
Installation of OpenPACE and OpenSSL
------------------------------------

The nPA Smart Card Library links against OpenSSL_, which must be patched with
OpenPACE_. Here is an example of how to get the standard installation of
OpenPACE_::
The nPA Smart Card Library links against OpenSSL_, which must be patched for OpenPACE_.
Here is an example of how to get the standard installation of OpenPACE_ (with
the required binaries for OpenSSL)::
PREFIX=/tmp/install
OPENPACE=openpace
svn co https://openpace.svn.sourceforge.net/svnroot/openpace $OPENPACE
git clone git://openpace.git.sourceforge.net/gitroot/openpace $OPENPACE
cd $OPENPACE
make patch_with_openpace
cd openpace
./config experimental-pace --prefix=$PREFIX
make depend
make
make install
autoreconf --verbose --install
# with `--enable-openssl-install` OpenSSL will be downloaded and installed along with OpenPACE
./configure --enable-openssl-install --prefix=$PREFIX
make install && cd -

Building the nPA Smart Card Library with OpenPACE_ is done best using
:command:`pkg-config`. The file :file:`libcrypto.pc` should be located in
``$INSTALL/lib/pkgconfig``. Here is how to configure the nPA Smart Card Library to use
it::
The file :file:`libcrypto.pc` should be located in ``$INSTALL/lib/pkgconfig``.

./configure PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig

----------------------
Installation of OpenSC
----------------------

---------------
Hints on OpenSC
---------------

The nPA Smart Card Library links against OpenSC, which is discouraged and hindered
since OpenSC version >= 0.12. However, I extended OpenSC to support smart card
readers with PACE capabilities. You need the OpenSC components to be installed
(especially :file:`libopensc.so`). Here is an example of how to get the
standard installation of `OpenSC with PACE`_::
The nPA Smart Card Library need the OpenSC components to be installed (especially
:file:`libopensc.so`). Here is an example of how to get a suitable installation
of OpenSC_::

PREFIX=/tmp/install
OPENSC=opensc
git clone git://github.com/frankmorgner/OpenSC.git $OPENSC
cd $OPENSC
autoreconf -i
VSMARTCARD=vsmartcard
git clone git://vsmartcard.git.sourceforge.net/gitroot/vsmartcard $VSMARTCARD
cd $VSMARTCARD/npa/src/opensc
autoreconf --verbose --install
# adding PKG_CONFIG_PATH here lets OpenSC use OpenSSL with OpenPACE
./configure --prefix=$PREFIX PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
make
make install
make install && cd -

Now :file:`libopensc.so` should be located in ``$PREFIX/lib``.


Now :file:`libopensc.so` should be located in ``$PREFIX/lib``. Here is how to
configure the nPA Smart Card Library to use it::
--------------------------------------------------------------------------------
Installation of the nPA Smart Card Library
--------------------------------------------------------------------------------

To complete this step-by-step guide, here is how to install nPA Smart Card Library::

cd $VSMARTCARD/npa
autoreconf --verbose --install
# adding PKG_CONFIG_PATH here lets OpenSC use OpenSSL with OpenPACE
./configure --prefix=$PREFIX PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig OPENSC_LIBS="-L$PREFIX/lib -lopensc"
make install && cd -

./configure OPENSC_LIBS="-L$PREFIX/lib -lopensc"


.. _npa-usage:
Expand All @@ -119,27 +121,25 @@ be found in :file:`apdus`.
Linking against libnpa
----------------------

Following the section `Installation`_ above, you have installed `OpenSC with
PACE`_, OpenPACE_ and the nPA Smart Card Library to :file:`/tmp/install`. To compile a
program using nPA Smart Card Library you need to get the header files from `OpenSC with
PACE`_ as well. Here is how to compile an external program with these
libraries::
Following the section `Installation`_ above, you have installed OpenSSL_,
OpenPACE_, OpenSC_ and the nPA Smart Card Library to `$PREFIX` which points to
:file:`/tmp/install`. To compile a program using nPA Smart Card Library you also need
the OpenSC header files, which are located in
:file:`$VSMARTCARD/npa/src/opensc` Here is how to compile an external program
with these libraries::

PREFIX=/tmp/install
OPENSC=opensc
git clone git://github.com/frankmorgner/OpenSC.git $OPENSC
cc example.c -I$OPENSC/src \
$(env PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig \
pkg-config --cflags --libs npa)
PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
cc example.c -I$VSMARTCARD/npa/src/opensc \
$(pkg-config --cflags --libs npa)

Alternatively you can specify libraries and flags by hand::

PREFIX=/tmp/install
OPENSC=opensc
git clone git://github.com/frankmorgner/OpenSC.git $OPENSC
cc example.c -I$OPENSC/src \
cc example.c -I$VSMARTCARD/npa/src/opensc \
-I$PREFIX/include \
-L$PREFIX/lib -lcrypto -lnpa -lopensc"
-L$PREFIX/lib -lnpa -lopensc -lcrypto"

The API to libnpa is documented in :ref:`npa-api`. It includes a simple
programming example.


.. include:: questions.rst
Loading

0 comments on commit d479420

Please sign in to comment.