Skip to content

Commit

Permalink
macOS: added support for access via CryptoTokenKit
Browse files Browse the repository at this point in the history
Binaries still need to be signed with the com.apple.security.smartcard
entitlement. The command should look something like this:

codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" target/Library/OpenSC/bin/*
codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" target/Library/OpenSC/lib/*.dylib
codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" --deep target/Library/OpenSC/lib/opensc-pkcs11.bundle
codesign --force --entitlements MacOSX/pcsc.entitlements --sign "Mac Developer" --deep target/Library/Security/tokend/OpenSC.tokend
  • Loading branch information
frankmorgner committed Apr 3, 2017
1 parent 7031351 commit 013bdcb
Show file tree
Hide file tree
Showing 6 changed files with 483 additions and 4 deletions.
35 changes: 32 additions & 3 deletions configure.ac
Expand Up @@ -58,6 +58,7 @@ AC_CANONICAL_HOST
AC_PROG_CC
# AC_PROG_CXX is needed to built the win32 custom action. Indeed dutil.h use [extern "C"] definition which fails on pure c compiler
AC_PROG_CXX
AC_PROG_OBJC
PKG_PROG_PKG_CONFIG
AC_C_BIGENDIAN

Expand Down Expand Up @@ -195,6 +196,13 @@ AC_ARG_ENABLE(
[enable_pcsc="yes"]
)

AC_ARG_ENABLE(
[cryptotokenkit],
[AS_HELP_STRING([--disable-cryptotokenkit],[disable CryptoTokenKit support @<:@enabled@:>@])],
,
[enable_cryptotokenkit="no"]
)

AC_ARG_ENABLE(
[ctapi],
[AS_HELP_STRING([--enable-ctapi],[enable CT-API support @<:@disabled@:>@])],
Expand Down Expand Up @@ -267,11 +275,11 @@ AC_ARG_WITH(

dnl ./configure check
reader_count=""
for rdriver in "${enable_pcsc}" "${enable_openct}" "${enable_ctapi}"; do
for rdriver in "${enable_pcsc}" "${enable_cryptotokenkit}" "${enable_openct}" "${enable_ctapi}"; do
test "${rdriver}" = "yes" && reader_count="${reader_count}x"
done
if test "${reader_count}" != "x"; then
AC_MSG_ERROR([Only one of --enable-pcsc, --enable-openct, --enable-ctapi can be specified!])
AC_MSG_ERROR([Only one of --enable-pcsc, --enable-cryptotokenkit, --enable-openct, --enable-ctapi can be specified!])
fi

dnl Checks for programs.
Expand Down Expand Up @@ -711,6 +719,22 @@ if test "${enable_pcsc}" = "yes"; then
AC_DEFINE([ENABLE_PCSC], [1], [Define if PC/SC is to be enabled])
fi

if test "${enable_cryptotokenkit}" = "yes"; then
if test -z "${CRYPTOTOKENKIT_CFLAGS}"; then
case "${host}" in
*-apple-*)
CRYPTOTOKENKIT_CFLAGS="-framework CryptoTokenKit -framework Foundation"
LDFLAGS="${LDFLAGS} -framework CryptoTokenKit -framework Foundation"
;;
*)
AC_MSG_ERROR([CryptoTokenKit only supported on Darwin])
;;
esac
fi
AC_DEFINE([ENABLE_CRYPTOTOKENKIT], [1], [Define if CryptoTokenKit is to be enabled])
fi


AC_SUBST(DYN_LIB_EXT)
AC_SUBST(LIBDIR)
AC_SUBST(LIB_PRE)
Expand Down Expand Up @@ -803,6 +827,9 @@ if test "${enable_pcsc}" = "yes"; then
OPENSC_FEATURES="${OPENSC_FEATURES} pcsc(${DEFAULT_PCSC_PROVIDER})"
OPTIONAL_PCSC_CFLAGS="${PCSC_CFLAGS}"
fi
if test "${enable_cryptotokenkit}" = "yes"; then
OPTIONAL_CRYPTOTOKENKIT_CFLAGS="${CRYPTOTOKENKIT_CFLAGS}"
fi
if test "${enable_ctapi}" = "yes"; then
OPENSC_FEATURES="${OPENSC_FEATURES} ctapi"
fi
Expand Down Expand Up @@ -878,7 +905,7 @@ AM_CONDITIONAL([ENABLE_THREAD_LOCKING], [test "${enable_thread_locking}" = "yes"
AM_CONDITIONAL([ENABLE_ZLIB], [test "${enable_zlib}" = "yes"])
AM_CONDITIONAL([ENABLE_READLINE], [test "${enable_readline}" = "yes"])
AM_CONDITIONAL([ENABLE_OPENSSL], [test "${enable_openssl}" = "yes"])
AM_CONDITIONAL([ENABLE_OPENCT], [test "${enable_openct}" = "yes"])
AM_CONDITIONAL([ENABLE_CRYPTOTOKENKIT], [test "${enable_cryptotokenkit}" = "yes"])
AM_CONDITIONAL([ENABLE_DOC], [test "${enable_doc}" = "yes"])
AM_CONDITIONAL([WIN32], [test "${WIN32}" = "yes"])
AM_CONDITIONAL([CYGWIN], [test "${CYGWIN}" = "yes"])
Expand Down Expand Up @@ -970,6 +997,7 @@ zlib support: ${enable_zlib}
readline support: ${enable_readline}
OpenSSL support: ${enable_openssl}
PC/SC support: ${enable_pcsc}
CryptoTokenKit support: ${enable_cryptotokenkit}
OpenCT support: ${enable_openct}
CT-API support: ${enable_ctapi}
minidriver support: ${enable_minidriver}
Expand Down Expand Up @@ -999,6 +1027,7 @@ OPENPACE_LIBS: ${OPENPACE_LIBS}
OPENCT_CFLAGS: ${OPENCT_CFLAGS}
OPENCT_LIBS: ${OPENCT_LIBS}
PCSC_CFLAGS: ${PCSC_CFLAGS}
CRYPTOTOKENKIT_CFLAGS: ${CRYPTOTOKENKIT_CFLAGS}

EOF

13 changes: 12 additions & 1 deletion etc/opensc.conf.in
Expand Up @@ -124,7 +124,18 @@ app default {
# Default: n/a
# max_send_size = 255;
# max_recv_size = 256;
};
}

# Options for CryptoTokenKit support
reader_driver cryptotokenkit {
# Limit command and response sizes. Some Readers don't propagate their
# transceive capabilities correctly. max_send_size and max_recv_size
# allow setting the limits manually, for example to enable extended
# length capabilities.
# Default: autodetect
# max_send_size = 65535;
# max_recv_size = 65536;
}

# Whitelist of card drivers to load at start-up
#
Expand Down
12 changes: 12 additions & 0 deletions src/libopensc/Makefile.am
Expand Up @@ -18,6 +18,7 @@ AM_CPPFLAGS = -DOPENSC_CONF_PATH=\"$(sysconfdir)/opensc.conf\" \
-I$(top_srcdir)/src
AM_CFLAGS = $(OPENPACE_CFLAGS) $(OPTIONAL_OPENSSL_CFLAGS) $(OPTIONAL_OPENCT_CFLAGS) \
$(OPTIONAL_PCSC_CFLAGS) $(OPTIONAL_ZLIB_CFLAGS)
AM_OBJCFLAGS = $(AM_CFLAGS)

libopensc_la_SOURCES_BASE = \
sc.c ctx.c log.c errors.c \
Expand Down Expand Up @@ -55,9 +56,20 @@ libopensc_la_SOURCES_BASE = \
pkcs15-dnie.c pkcs15-gids.c pkcs15-iasecc.c pkcs15-jpki.c \
compression.c p15card-helper.c sm.c \
aux-data.c

if ENABLE_CRYPTOTOKENKIT
# most platforms don't support objective C the way we needed.
# Only include it if needed
libopensc_la_SOURCES_BASE += reader-cryptotokenkit.m
else
libopensc_la_LIBTOOLFLAGS = --tag CC
libopensc_static_la_LIBTOOLFLAGS = --tag CC
endif

libopensc_la_SOURCES = $(libopensc_la_SOURCES_BASE) \
libopensc.exports
libopensc_static_la_SOURCES = $(libopensc_la_SOURCES_BASE)

if WIN32
libopensc_la_SOURCES += $(top_builddir)/win32/versioninfo.rc
endif
Expand Down
2 changes: 2 additions & 0 deletions src/libopensc/ctx.c
Expand Up @@ -797,6 +797,8 @@ int sc_context_create(sc_context_t **ctx_out, const sc_context_param_t *parm)
if(strcmp(ctx->app_name, "cardmod") == 0)
ctx->reader_driver = sc_get_cardmod_driver();
#endif
#elif defined(ENABLE_CRYPTOTOKENKIT)
ctx->reader_driver = sc_get_cryptotokenkit_driver();
#elif defined(ENABLE_CTAPI)
ctx->reader_driver = sc_get_ctapi_driver();
#elif defined(ENABLE_OPENCT)
Expand Down
1 change: 1 addition & 0 deletions src/libopensc/internal.h
Expand Up @@ -257,6 +257,7 @@ extern struct sc_reader_driver *sc_get_pcsc_driver(void);
extern struct sc_reader_driver *sc_get_ctapi_driver(void);
extern struct sc_reader_driver *sc_get_openct_driver(void);
extern struct sc_reader_driver *sc_get_cardmod_driver(void);
extern struct sc_reader_driver *sc_get_cryptotokenkit_driver(void);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 013bdcb

Please sign in to comment.