Merge pull request #706 from frankmorgner/npa-generic

generic changes from #611
This commit is contained in:
viktorTarasov 2016-03-10 11:04:12 +01:00
commit a5550f980b
17 changed files with 168 additions and 66 deletions

View File

@ -12,6 +12,7 @@ configuration:
environment:
matrix:
- VSVER: 14
- VSVER: 12
- VSVER: 10
@ -20,6 +21,12 @@ matrix:
# not included in AppVeyor right now
- platform: x64
VSVER: 10
# does currently not build zlib out of the box
- configuration: Release
VSVER: 14
# does currently not build zlib out of the box
- configuration: Debug
VSVER: 14
install:
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
@ -91,8 +98,11 @@ build_script:
- cd win32 && nmake /f Makefile.mak %NMAKE_ARCH% %NMAKE_EXTRA% VSVER=%VSVER% OpenSC.msi
- move OpenSC.msi %ARTIFACT%
- appveyor PushArtifact %ARTIFACT%
# optionaly put all pdb files for dump analysis, but this consume approx 100 MB per build
# - ps: Get-ChildItem -recurse c:\projects\OpenSC -exclude vc*.pdb *.pdb | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
# put all pdb files for dump analysis, but this consume approx 100 MB per build
- ps: >-
If ($env:Configuration -Like "*Debug*") {
Get-ChildItem -recurse c:\projects\OpenSC -exclude vc*.pdb *.pdb | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
}
cache:
- C:\OpenSSL-Win32 -> appveyor.yml

View File

@ -544,9 +544,9 @@ fi
if test "${enable_sm}" = "yes"; then
AC_DEFINE([ENABLE_SM], [1], [Enable secure messaging support])
DEFAULT_SM_MODULE="${LIB_PRE}smm-local${DYN_LIB_EXT}"
case "${host}" in
*-mingw*|*-winnt*|*-cygwin*)
DEFAULT_SM_MODULE="smm-local.dll"
DEFAULT_SM_MODULE_PATH="\# module_path = \"\";"
;;
*-apple-*)
@ -626,19 +626,30 @@ if test "${enable_pcsc}" = "yes"; then
AC_DEFINE([ENABLE_PCSC], [1], [Define if PC/SC is to be enabled])
fi
AC_SUBST(DYN_LIB_EXT)
AC_SUBST(LIBDIR)
AC_SUBST(LIB_PRE)
case "${host}" in
*-mingw*|*-winnt*|*-cygwin*)
DYN_LIB_EXT=".dll"
LIBDIR=""
LIB_PRE=""
;;
*-apple-*)
DYN_LIB_EXT=".dylib"
LIBDIR="\$(libdir)/"
LIB_PRE="lib"
;;
*)
DYN_LIB_EXT=".so"
LIBDIR="\$(libdir)/"
LIB_PRE="lib"
;;
esac
if test "${with_pkcs11_provider}" = "detect"; then
case "${host}" in
*-*-darwin*)
DEFAULT_PKCS11_PROVIDER="opensc-pkcs11.so"
;;
*-mingw*|*-winnt*|*-cygwin*)
DEFAULT_PKCS11_PROVIDER="opensc-pkcs11.dll"
;;
*)
DEFAULT_PKCS11_PROVIDER="opensc-pkcs11.so"
;;
esac
DEFAULT_PKCS11_PROVIDER="opensc-pkcs11${DYN_LIB_EXT}"
else
DEFAULT_PKCS11_PROVIDER="${with_pkcs11_provider}"
fi
@ -700,13 +711,13 @@ AC_DEFINE_UNQUOTED([OPENSC_VERSION_REVISION], [${OPENSC_VERSION_REVISION}], [Ope
AC_DEFINE_UNQUOTED([OPENSC_SCM_REVISION], ["${OPENSC_SCM_REVISION}"], [OpenSC version Git describe revision])
AC_DEFINE_UNQUOTED([OPENSC_FEATURES], ["${OPENSC_FEATURES}"], [Enabled OpenSC features])
AC_DEFINE_UNQUOTED([OPENSC_VS_FF_LEGAL_COPYRIGHT], [${OPENSC_VS_FF_LEGAL_COPYRIGHT}], [OpenSC version-info LegalCopyright value])
AC_DEFINE_UNQUOTED([OPENSC_VS_FF_COMPANY_NAME], [${OPENSC_VS_FF_COMPANY_NAME}], [OpenSC version-info CompanyName value])
AC_DEFINE_UNQUOTED([OPENSC_VS_FF_COMMENTS], [${OPENSC_VS_FF_COMMENTS}], [OpenSC version-info Comments])
AC_DEFINE_UNQUOTED([OPENSC_VS_FF_PRODUCT_NAME], [${OPENSC_VS_FF_PRODUCT_NAME}], [OpenSC version-info ProductName])
AC_DEFINE_UNQUOTED([OPENSC_VS_FF_PRODUCT_UPDATES], [${OPENSC_VS_FF_PRODUCT_UPDATES}], [OpenSC version-info UpdateURL])
AC_DEFINE_UNQUOTED([OPENSC_VS_FF_PRODUCT_URL], [${OPENSC_VS_FF_PRODUCT_URL}], [OpenSC version-info ProductURL])
AC_DEFINE_UNQUOTED([OPENSC_VS_FF_COMPANY_URL], [${OPENSC_VS_FF_COMPANY_URL}], [OpenSC version-info UpdateURL])
AC_DEFINE_UNQUOTED([OPENSC_VS_FF_LEGAL_COPYRIGHT], ["${OPENSC_VS_FF_LEGAL_COPYRIGHT}"], [OpenSC version-info LegalCopyright value])
AC_DEFINE_UNQUOTED([OPENSC_VS_FF_COMPANY_NAME], ["${OPENSC_VS_FF_COMPANY_NAME}"], [OpenSC version-info CompanyName value])
AC_DEFINE_UNQUOTED([OPENSC_VS_FF_COMMENTS], ["${OPENSC_VS_FF_COMMENTS}"], [OpenSC version-info Comments])
AC_DEFINE_UNQUOTED([OPENSC_VS_FF_PRODUCT_NAME], ["${OPENSC_VS_FF_PRODUCT_NAME}"], [OpenSC version-info ProductName])
AC_DEFINE_UNQUOTED([OPENSC_VS_FF_PRODUCT_UPDATES], ["${OPENSC_VS_FF_PRODUCT_UPDATES}"], [OpenSC version-info UpdateURL])
AC_DEFINE_UNQUOTED([OPENSC_VS_FF_PRODUCT_URL], ["${OPENSC_VS_FF_PRODUCT_URL}"], [OpenSC version-info ProductURL])
AC_DEFINE_UNQUOTED([OPENSC_VS_FF_COMPANY_URL], ["${OPENSC_VS_FF_COMPANY_URL}"], [OpenSC version-info UpdateURL])
pkcs11dir="\$(libdir)/pkcs11"

View File

@ -17,11 +17,13 @@ opensc.conf: opensc.conf.in force
.in:
@sed \
-e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \
-e 's|@libdir[@]|$(libdir)|g' \
-e 's|@DEBUG_FILE[@]|$(DEBUG_FILE)|g' \
-e 's|@DEFAULT_PCSC_PROVIDER[@]|$(DEFAULT_PCSC_PROVIDER)|g' \
-e 's|@DEFAULT_SM_MODULE[@]|$(DEFAULT_SM_MODULE)|g' \
-e 's|@DEFAULT_SM_MODULE_PATH[@]|$(DEFAULT_SM_MODULE_PATH)|g' \
-e 's|@DYN_LIB_EXT[@]|$(DYN_LIB_EXT)|g' \
-e 's|@LIBDIR[@]|$(LIBDIR)|g' \
-e 's|@LIB_PRE[@]|$(LIB_PRE)|g' \
-e 's|@PROFILE_DIR[@]|$(PROFILE_DIR)|g' \
-e 's|@PROFILE_DIR_DEFAULT[@]|$(PROFILE_DIR_DEFAULT)|g' \
< $< > $@

View File

@ -12,7 +12,7 @@ app default {
# A greater value means more debug info.
# Default: 0
#
debug = 0;
#debug = 3;
# The file to which debug output will be written
#
@ -53,7 +53,7 @@ app default {
# CT-API module configuration.
reader_driver ctapi {
# module @libdir@/libtowitoko.so {
# module @LIBDIR@@LIB_PRE@towitoko@DYN_LIB_EXT@ {
# CT-API ports:
# 0..3 COM1..4
# 4 Printer
@ -134,7 +134,7 @@ app default {
#
# card_driver customcos {
# The location of the driver library
# module = @libdir@/card_customcos.so;
# module = @LIBDIR@@LIB_PRE@card_customcos@DYN_LIB_EXT@;
# }
# Force using specific card driver
@ -531,7 +531,7 @@ app default {
#
# emulate custom {
# The location of the driver library
# module = @libdir@/p15emu_custom.so;
# module = @LIBDIR@@LIB_PRE@p15emu_custom@DYN_LIB_EXT@;
# }
# some additional application parameters:

View File

@ -171,23 +171,6 @@ static int sc_apdu2bytes(sc_context_t *ctx, const sc_apdu_t *apdu,
return SC_SUCCESS;
}
void sc_apdu_log(sc_context_t *ctx, int level, const u8 *data, size_t len, int is_out)
{
size_t blen = len * 5 + 128;
char *buf = malloc(blen);
if (buf == NULL)
return;
sc_hex_dump(ctx, level, data, len, buf, blen);
sc_debug(ctx, level, "\n%s APDU data [%5u bytes] =====================================\n"
"%s"
"======================================================================\n",
is_out != 0 ? "Outgoing" : "Incoming", len,
buf);
free(buf);
}
int sc_apdu_get_octets(sc_context_t *ctx, const sc_apdu_t *apdu, u8 **buf,
size_t *len, unsigned int proto)
{

View File

@ -515,7 +515,8 @@ static int select_file_id(sc_card_t *card, const u8 *buf, size_t buflen,
u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
sc_file_t *file;
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called, p1=%u, path=%s\n", p1, sc_dump_hex(buf, buflen));
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called, p1=%u\n", p1);
sc_debug_hex(card->ctx, SC_LOG_DEBUG_NORMAL, "path", buf, buflen);
sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, p1, 0);
apdu.resp = rbuf;

View File

@ -239,8 +239,8 @@ int sc_apdu_set_resp(sc_context_t *ctx, sc_apdu_t *apdu, const u8 *buf,
* @param len length of the APDU
* @param is_outgoing != 0 if the data is send to the card
*/
void sc_apdu_log(sc_context_t *ctx, int level, const u8 *data, size_t len,
int is_outgoing);
#define sc_apdu_log(ctx, level, data, len, is_outgoing) \
sc_debug_hex(ctx, level, is_outgoing != 0 ? "Outgoing APDU" : "Incoming APDU", data, len)
extern struct sc_reader_driver *sc_get_pcsc_driver(void);
extern struct sc_reader_driver *sc_get_ctapi_driver(void);

View File

@ -87,6 +87,7 @@ sc_disconnect_card
sc_do_log
sc_do_log_noframe
_sc_debug
_sc_debug_hex
sc_enum_apps
sc_encode_oid
sc_parse_ef_atr

View File

@ -161,6 +161,28 @@ void _sc_log(struct sc_context *ctx, const char *format, ...)
va_end(ap);
}
void _sc_debug_hex(sc_context_t *ctx, int type, const char *file, int line,
const char *func, const char *label, const u8 *data, size_t len)
{
size_t blen = len * 5 + 128;
char *buf = malloc(blen);
if (buf == NULL)
return;
sc_hex_dump(ctx, type, data, len, buf, blen);
if (label)
sc_do_log(ctx, type, file, line, func,
"\n%s (%u byte%s):\n%s",
label, (unsigned int) len, len==1?"":"s", buf);
else
sc_do_log(ctx, type, file, line, func,
"%u byte%s:\n%s",
(unsigned int) len, len==1?"":"s", buf);
free(buf);
}
/* Although not used, we need this for consistent exports */
void sc_hex_dump(struct sc_context *ctx, int level, const u8 * in, size_t count, char *buf, size_t len)
{

View File

@ -57,6 +57,31 @@ void sc_do_log(struct sc_context *ctx, int level, const char *file, int line, co
void sc_do_log_noframe(sc_context_t *ctx, int level, const char *format, va_list args);
void _sc_debug(struct sc_context *ctx, int level, const char *format, ...);
void _sc_log(struct sc_context *ctx, const char *format, ...);
/**
* @brief Log binary data to a sc context
*
* @param[in] ctx Context for logging
* @param[in] level
* @param[in] label Label to prepend to the buffer
* @param[in] data Binary data
* @param[in] len Length of \a data
*/
#define sc_debug_hex(ctx, level, label, data, len) \
_sc_debug_hex(ctx, level, __FILE__, __LINE__, __FUNCTION__, label, data, len)
/**
* @brief Log binary data
*
* @param[in] ctx Context for logging
* @param[in] type Debug level
* @param[in] file File name to be prepended
* @param[in] line Line to be prepended
* @param[in] func Function to be prepended
* @param[in] label label to prepend to the buffer
* @param[in] data binary data
* @param[in] len length of \a data
*/
void _sc_debug_hex(struct sc_context *ctx, int level, const char *file, int line,
const char *func, const char *label, const u8 *data, size_t len);
void sc_hex_dump(struct sc_context *ctx, int level, const u8 * buf, size_t len, char *out, size_t outlen);
char * sc_dump_hex(const u8 * in, size_t count);

View File

@ -300,6 +300,9 @@ typedef struct sc_reader {
const struct sc_reader_operations *ops;
void *drv_data;
char *name;
char *vendor;
unsigned char version_major;
unsigned char version_minor;
unsigned long flags, capabilities;
unsigned int supported_protocols, active_protocol;

View File

@ -47,6 +47,15 @@
#endif
#endif
#define SCARD_CLASS_SYSTEM 0x7fff
#define SCARD_ATTR_VALUE(Class, Tag) ((((ULONG)(Class)) << 16) | ((ULONG)(Tag)))
#define SCARD_ATTR_DEVICE_FRIENDLY_NAME_A SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0003)
#define SCARD_ATTR_DEVICE_SYSTEM_NAME_A SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0004)
#define SCARD_CLASS_VENDOR_INFO 1
#define SCARD_ATTR_VENDOR_NAME SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0100) /**< Vendor name. */
#define SCARD_ATTR_VENDOR_IFD_TYPE SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0101) /**< Vendor-supplied interface device type (model designation of reader). */
#define SCARD_ATTR_VENDOR_IFD_VERSION SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0102) /**< Vendor-supplied interface device version (DWORD in the form 0xMMmmbbbb where MM = major version, mm = minor version, and bbbb = build number). */
/* Logging */
#define PCSC_TRACE(reader, desc, rv) do { sc_log(reader->ctx, "%s:" desc ": 0x%08lx\n", reader->name, rv); } while (0)
#define PCSC_LOG(ctx, desc, rv) do { sc_log(ctx, desc ": 0x%08lx\n", rv); } while (0)
@ -727,7 +736,8 @@ static int pcsc_init(sc_context_t *ctx)
gpriv->SCardListReaders = (SCardListReaders_t)sc_dlsym(gpriv->dlhandle, "SCardListReadersA");
/* If we have SCardGetAttrib it is correct API */
if (sc_dlsym(gpriv->dlhandle, "SCardGetAttrib") != NULL) {
gpriv->SCardGetAttrib = (SCardGetAttrib_t)sc_dlsym(gpriv->dlhandle, "SCardGetAttrib");
if (gpriv->SCardGetAttrib != NULL) {
#ifdef __APPLE__
gpriv->SCardControl = (SCardControl_t)sc_dlsym(gpriv->dlhandle, "SCardControl132");
#endif
@ -1057,6 +1067,25 @@ static void detect_reader_features(sc_reader_t *reader, SCARDHANDLE card_handle)
/* debug the product and vendor ID of the reader */
part10_get_vendor_product(reader, card_handle, NULL, NULL);
}
if(gpriv->SCardGetAttrib != NULL) {
if (gpriv->SCardGetAttrib(card_handle, SCARD_ATTR_VENDOR_NAME,
rbuf, &rcount) == SCARD_S_SUCCESS
&& rcount > 0) {
/* add NUL termination, just in case... */
rbuf[(sizeof rbuf)-1] = '\0';
reader->vendor = strdup((char *) rbuf);
}
rcount = sizeof rbuf;
if(gpriv->SCardGetAttrib(card_handle, SCARD_ATTR_VENDOR_IFD_VERSION,
rbuf, &rcount) == SCARD_S_SUCCESS
&& rcount == 4) {
i = *(DWORD *) rbuf;
reader->version_major = (i >> 24) & 0xFF;
reader->version_minor = (i >> 16) & 0xFF;
}
}
}
static int pcsc_detect_readers(sc_context_t *ctx)
@ -1804,7 +1833,7 @@ pcsc_pin_cmd(sc_reader_t *reader, struct sc_pin_cmd_data *data)
/* If PIN block building failed, we fail too */
SC_TEST_RET(reader->ctx, SC_LOG_DEBUG_NORMAL, r, "PC/SC v2 pinpad block building failed!");
/* If not, debug it, just for fun */
sc_debug(reader->ctx, SC_LOG_DEBUG_NORMAL, "PC/SC v2 pinpad block: %s", sc_dump_hex(sbuf, scount));
sc_debug_hex(reader->ctx, SC_LOG_DEBUG_NORMAL, "PC/SC v2 pinpad block", sbuf, scount);
r = pcsc_internal_transmit(reader, sbuf, scount, rbuf, &rcount, ioctl);
@ -2108,11 +2137,6 @@ struct sc_reader_driver * sc_get_pcsc_driver(void)
#ifdef ENABLE_MINIDRIVER
#define SCARD_CLASS_SYSTEM 0x7fff
#define SCARD_ATTR_VALUE(Class, Tag) ((((ULONG)(Class)) << 16) | ((ULONG)(Tag)))
#define SCARD_ATTR_DEVICE_FRIENDLY_NAME_A SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0003)
#define SCARD_ATTR_DEVICE_SYSTEM_NAME_A SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0004)
static int cardmod_connect(sc_reader_t *reader)
{
int r;

View File

@ -55,14 +55,9 @@ install-exec-hook:
done
else
# see http://wiki.cacert.org/wiki/Pkcs11TaskForce
if CYGWIN
PKCS11_SUFFIX=.dll
else
PKCS11_SUFFIX=.so
endif
install-exec-hook:
$(MKDIR_P) "$(DESTDIR)$(pkcs11dir)"
for l in opensc-pkcs11$(PKCS11_SUFFIX) onepin-opensc-pkcs11$(PKCS11_SUFFIX) pkcs11-spy$(PKCS11_SUFFIX); do \
for l in opensc-pkcs11$(DYN_LIB_EXT) onepin-opensc-pkcs11$(DYN_LIB_EXT) pkcs11-spy$(DYN_LIB_EXT); do \
rm -f "$(DESTDIR)$(pkcs11dir)/$$l"; \
$(LN_S) ../$$l "$(DESTDIR)$(pkcs11dir)/$$l"; \
done

View File

@ -348,13 +348,13 @@ CK_RV C_GetInfo(CK_INFO_PTR pInfo)
pInfo->cryptokiVersion.major = 2;
pInfo->cryptokiVersion.minor = 20;
strcpy_bp(pInfo->manufacturerID,
"OpenSC (www.opensc-project.org)",
OPENSC_VS_FF_COMPANY_NAME,
sizeof(pInfo->manufacturerID));
strcpy_bp(pInfo->libraryDescription,
"Smart card PKCS#11 API",
OPENSC_VS_FF_PRODUCT_NAME,
sizeof(pInfo->libraryDescription));
pInfo->libraryVersion.major = 0;
pInfo->libraryVersion.minor = 0; /* FIXME: use 0.116 for 0.11.6 from autoconf */
pInfo->libraryVersion.major = OPENSC_VERSION_MAJOR;
pInfo->libraryVersion.minor = OPENSC_VERSION_MINOR;
sc_pkcs11_unlock();
return rv;

View File

@ -53,10 +53,10 @@ static struct sc_pkcs11_slot * reader_get_slot(sc_reader_t *reader)
static void init_slot_info(CK_SLOT_INFO_PTR pInfo)
{
strcpy_bp(pInfo->slotDescription, "Virtual hotplug slot", 64);
strcpy_bp(pInfo->manufacturerID, "OpenSC (www.opensc-project.org)", 32);
strcpy_bp(pInfo->manufacturerID, OPENSC_VS_FF_COMPANY_NAME, 32);
pInfo->flags = CKF_REMOVABLE_DEVICE | CKF_HW_SLOT;
pInfo->hardwareVersion.major = 0;
pInfo->hardwareVersion.minor = 0;
pInfo->hardwareVersion.major = OPENSC_VERSION_MAJOR;
pInfo->hardwareVersion.minor = OPENSC_VERSION_MINOR;
pInfo->firmwareVersion.major = 0;
pInfo->firmwareVersion.minor = 0;
}
@ -97,7 +97,10 @@ CK_RV create_slot(sc_reader_t *reader)
init_slot_info(&slot->slot_info);
if (reader != NULL) {
slot->reader = reader;
strcpy_bp(slot->slot_info.manufacturerID, reader->vendor, 32);
strcpy_bp(slot->slot_info.slotDescription, reader->name, 64);
slot->slot_info.hardwareVersion.major = reader->version_major;
slot->slot_info.hardwareVersion.minor = reader->version_minor;
}
return CKR_OK;

View File

@ -41,6 +41,12 @@
// WiX Header Files:
#include <wcautil.h>
#if defined(_MSC_VER) && (_MSC_VER >= 1900)
// only for VS 2015 or later
// WiX 3.10 was built for older versions of VS and needs this for compatibility
#pragma comment(lib, "legacy_stdio_definitions.lib")
#endif
#define X86onX64_SC_DATABASE TEXT("SOFTWARE\\Wow6432Node\\Microsoft\\Cryptography\\Calais\\SmartCards")
#define SC_DATABASE TEXT("SOFTWARE\\Microsoft\\Cryptography\\Calais\\SmartCards")
#define BASE_CSP TEXT("OpenSC CSP")

View File

@ -96,6 +96,22 @@
#define OPENSC_FEATURES "N/A"
#endif
#ifndef OPENSC_VERSION_MAJOR
#define OPENSC_VERSION_MAJOR 0
#endif
#ifndef OPENSC_VERSION_MINOR
#define OPENSC_VERSION_MINOR 15
#endif
#ifndef OPENSC_VS_FF_COMPANY_NAME
#define OPENSC_VS_FF_COMPANY_NAME "OpenSC Project"
#endif
#ifndef OPENSC_VS_FF_PRODUCT_NAME
#define OPENSC_VS_FF_PRODUCT_NAME "OpenSC smartcard framework"
#endif
#ifndef DEFAULT_PKCS11_PROVIDER
#define DEFAULT_PKCS11_PROVIDER "opensc-pkcs11.dll"
#endif