Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major changes for all cards that needs developer review #850

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a78bc32
Set PIN-PUK association for cards that don't have it set
maciejsszmigiero Aug 13, 2016
ac2412d
Print size_t variables on properly on Windows
maciejsszmigiero Sep 28, 2016
5ce4937
Make minidriver installer custom action library optional
maciejsszmigiero Aug 25, 2016
2ae5f93
Make minidriver buildable again on mingw
maciejsszmigiero Jan 25, 2017
3f49d9b
Fix most of warnings shown when building on Linux and mingw
maciejsszmigiero Jan 25, 2017
435a4a0
Move SM test in configure.ac after LIB_PRE and DYN_LIB_EXT assignment
maciejsszmigiero Oct 22, 2016
31c63c2
Add session handle uniqueness check to PKCS#11 C_OpenSession()
maciejsszmigiero Aug 25, 2016
b83a806
Add multiple PINs support to minidriver
maciejsszmigiero Aug 25, 2016
480b442
Add reset operation to opensc-tool
maciejsszmigiero Aug 23, 2016
db5e03c
Provide notification about and handle card resets by other contexts
maciejsszmigiero Jan 28, 2017
8e4941b
Add ptrdiff_t (pointer difference) printf length modifier
maciejsszmigiero Aug 23, 2016
1b56dba
Remove logprintf() mingw hack in minidriver
maciejsszmigiero Aug 23, 2016
2a9e175
Support PIN unblocking in minidriver via PUK as response to challenge
maciejsszmigiero Aug 25, 2016
f2df771
Keep track of card resets by other contexts in minidriver
maciejsszmigiero Jan 28, 2017
4678706
Add GCC format checking attributes to log functions
maciejsszmigiero Aug 24, 2016
ee6d7f2
Fix log messages format and parameter issues flagged by GCC
maciejsszmigiero Jan 1, 2017
35efa57
Fix cases of log function format strings not being a string literal
maciejsszmigiero Aug 26, 2016
ee8f1cc
Use built-in formatted output functions on mingw
maciejsszmigiero Jan 28, 2017
6f2bbf5
Add GCC format checking attributes to minidriver logging function
maciejsszmigiero Sep 30, 2016
00478c8
Fix minidriver log messages format and parameter issues flagged by GCC
maciejsszmigiero Oct 1, 2016
5128d0d
Minidriver CardGetChallenge() parameters are output only
maciejsszmigiero Oct 1, 2016
5deedf3
Minidriver CardReadFile() parameters are optional
maciejsszmigiero Oct 1, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 41 additions & 19 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ AC_DEFINE_UNQUOTED([DEBUG_FILE], ["${DEBUG_FILE}"], [Debug file])
AC_DEFINE_UNQUOTED([PROFILE_DIR], ["${PROFILE_DIR}"], [Directory of profiles])
AC_DEFINE_UNQUOTED([PROFILE_DIR_DEFAULT], ["${PROFILE_DIR_DEFAULT}"], [Default directory of profiles])

case "${host}" in
*-mingw*)
CPPFLAGS="${CPPFLAGS} -D__USE_MINGW_ANSI_STDIO=1"
;;
esac

AC_ARG_ENABLE(
[strict],
[AS_HELP_STRING([--disable-strict],[disable strict compile mode @<:@disabled@:>@])],
Expand Down Expand Up @@ -406,8 +412,12 @@ if test "${enable_minidriver}" = "yes"; then
AC_CHECK_HEADER(
[cardmod.h],
,
[AC_MSG_ERROR([cardmod.h is not found and required for minidriver])]
)
[AC_MSG_ERROR([cardmod.h from CNG is required for minidriver])],
[#if defined(__MINGW32__)
#include "${srcdir}/src/minidriver/cardmod-mingw-compat.h"
#endif
])

AC_DEFINE([ENABLE_MINIDRIVER], [1], [Enable minidriver support])
fi

Expand Down Expand Up @@ -549,23 +559,6 @@ else
OPENSSL_LIBS=""
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_PATH="\# module_path = \"\";"
;;
*)
DEFAULT_SM_MODULE="libsmm-local.so"
DEFAULT_SM_MODULE_PATH="module_path = \$(libdir);"
;;
esac
AC_DEFINE_UNQUOTED([DEFAULT_SM_MODULE], ["${DEFAULT_SM_MODULE}"], [Default SM module])
AC_DEFINE_UNQUOTED([DEFAULT_SM_MODULE_PATH], ["${DEFAULT_SM_MODULE_PATH}"], [Default SM module path])
fi

if test "${enable_openct}" = "yes"; then
PKG_CHECK_MODULES(
[OPENCT],
Expand Down Expand Up @@ -649,6 +642,22 @@ case "${host}" in
;;
esac

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_PATH="\# module_path = \"\";"
;;
*)
DEFAULT_SM_MODULE="libsmm-local.so"
DEFAULT_SM_MODULE_PATH="module_path = \$(libdir);"
;;
esac
AC_DEFINE_UNQUOTED([DEFAULT_SM_MODULE], ["${DEFAULT_SM_MODULE}"], [Default SM module])
AC_DEFINE_UNQUOTED([DEFAULT_SM_MODULE_PATH], ["${DEFAULT_SM_MODULE_PATH}"], [Default SM module path])
fi

if test "${with_pkcs11_provider}" = "detect"; then
DEFAULT_PKCS11_PROVIDER="opensc-pkcs11${DYN_LIB_EXT}"
Expand Down Expand Up @@ -706,6 +715,18 @@ if test "${enable_ctapi}" = "yes"; then
OPENSC_FEATURES="${OPENSC_FEATURES} ctapi"
fi

if test "${enable_minidriver}" = "yes"; then
AC_MSG_CHECKING([WiX SDK])
AC_CHECK_HEADERS([wcautil.h],[enable_minidriver_ca="yes"],[enable_minidriver_ca="no"])
if test "${enable_minidriver_ca}" = "yes"; then
AC_MSG_RESULT([found, minidriver setup custom action will be built])
else
AC_MSG_RESULT([not found, minidriver setup custom action will be skipped])
fi
else
enable_minidriver_ca="no"
fi

AC_DEFINE_UNQUOTED([OPENSC_VERSION_MAJOR], [${OPENSC_VERSION_MAJOR}], [OpenSC version major component])
AC_DEFINE_UNQUOTED([OPENSC_VERSION_MINOR], [${OPENSC_VERSION_MINOR}], [OpenSC version minor component])
AC_DEFINE_UNQUOTED([OPENSC_VERSION_FIX], [${OPENSC_VERSION_FIX}], [OpenSC version fix component])
Expand Down Expand Up @@ -770,6 +791,7 @@ AM_CONDITIONAL([ENABLE_DOC], [test "${enable_doc}" = "yes"])
AM_CONDITIONAL([WIN32], [test "${WIN32}" = "yes"])
AM_CONDITIONAL([CYGWIN], [test "${CYGWIN}" = "yes"])
AM_CONDITIONAL([ENABLE_MINIDRIVER], [test "${enable_minidriver}" = "yes"])
AM_CONDITIONAL([ENABLE_MINIDRIVER_SETUP_CUSTOMACTION], [test "${enable_minidriver_ca}" = "yes"])
AM_CONDITIONAL([ENABLE_SM], [test "${enable_sm}" = "yes"])
AM_CONDITIONAL([ENABLE_DNIE_UI], [test "${enable_dnie_ui}" = "yes"])
AM_CONDITIONAL([GIT_CHECKOUT], [test "${GIT_CHECKOUT}" = "yes"])
Expand Down
7 changes: 7 additions & 0 deletions doc/tools/opensc-tool.1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@
<listitem><para>Use the given reader number.
The default is <literal>0</literal>, the first reader in the system.</para></listitem>
</varlistentry>
<varlistentry>
<term>
<option>--reset</option>[=<replaceable>type</replaceable>],
</term>
<listitem><para>Resets the card in reader.
The default reset type is <literal>cold</literal>, but warm reset is also possible.</para></listitem>
</varlistentry>
<varlistentry>
<term>
<option>--send-apdu</option> <replaceable>apdu</replaceable>,
Expand Down
29 changes: 19 additions & 10 deletions src/libopensc/apdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,10 @@ sc_single_transmit(struct sc_card *card, struct sc_apdu *apdu)
if (card->reader->ops->transmit == NULL)
LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "cannot transmit APDU");

sc_log(ctx, "CLA:%X, INS:%X, P1:%X, P2:%X, data(%i) %p",
apdu->cla, apdu->ins, apdu->p1, apdu->p2, apdu->datalen, apdu->data);
sc_log(ctx,
"CLA:%X, INS:%X, P1:%X, P2:%X, data(%"SC_FORMAT_LEN_SIZE_T"u) %p",
apdu->cla, apdu->ins, apdu->p1, apdu->p2, apdu->datalen,
apdu->data);
#ifdef ENABLE_SM
if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT)
return sc_sm_single_transmit(card, apdu);
Expand Down Expand Up @@ -659,8 +661,9 @@ sc_bytes2apdu(sc_context_t *ctx, const u8 *buf, size_t len, sc_apdu_t *apdu)

if (!len) {
apdu->cse = SC_APDU_CASE_1;
sc_log(ctx, "CASE_1 APDU: %lu bytes:\tins=%02x p1=%02x p2=%02x lc=%04x le=%04x",
(unsigned long) len0, apdu->ins, apdu->p1, apdu->p2, apdu->lc, apdu->le);
sc_log(ctx,
"CASE_1 APDU: %"SC_FORMAT_LEN_SIZE_T"u bytes:\tins=%02x p1=%02x p2=%02x lc=%04"SC_FORMAT_LEN_SIZE_T"x le=%04"SC_FORMAT_LEN_SIZE_T"x",
len0, apdu->ins, apdu->p1, apdu->p2, apdu->lc, apdu->le);
return SC_SUCCESS;
}

Expand All @@ -681,7 +684,9 @@ sc_bytes2apdu(sc_context_t *ctx, const u8 *buf, size_t len, sc_apdu_t *apdu)
apdu->lc += *p++;
len -= 3;
if (len < apdu->lc) {
sc_log(ctx, "APDU too short (need %lu more bytes)", (unsigned long) apdu->lc - len);
sc_log(ctx,
"APDU too short (need %"SC_FORMAT_LEN_SIZE_T"u more bytes)",
apdu->lc - len);
return SC_ERROR_INVALID_DATA;
}
apdu->data = p;
Expand Down Expand Up @@ -719,7 +724,9 @@ sc_bytes2apdu(sc_context_t *ctx, const u8 *buf, size_t len, sc_apdu_t *apdu)
apdu->lc = *p++;
len--;
if (len < apdu->lc) {
sc_log(ctx, "APDU too short (need %lu more bytes)", (unsigned long) apdu->lc - len);
sc_log(ctx,
"APDU too short (need %"SC_FORMAT_LEN_SIZE_T"u more bytes)",
apdu->lc - len);
return SC_ERROR_INVALID_DATA;
}
apdu->data = p;
Expand All @@ -743,10 +750,12 @@ sc_bytes2apdu(sc_context_t *ctx, const u8 *buf, size_t len, sc_apdu_t *apdu)
return SC_ERROR_INVALID_DATA;
}

sc_log(ctx, "Case %d %s APDU, %lu bytes:\tins=%02x p1=%02x p2=%02x lc=%04x le=%04x",
apdu->cse & SC_APDU_SHORT_MASK,
(apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
(unsigned long) len0, apdu->ins, apdu->p1, apdu->p2, apdu->lc, apdu->le);
sc_log(ctx,
"Case %d %s APDU, %"SC_FORMAT_LEN_SIZE_T"u bytes:\tins=%02x p1=%02x p2=%02x lc=%04"SC_FORMAT_LEN_SIZE_T"x le=%04"SC_FORMAT_LEN_SIZE_T"x",
apdu->cse & SC_APDU_SHORT_MASK,
(apdu->cse & SC_APDU_EXT) != 0 ? "extended" : "short",
len0, apdu->ins, apdu->p1, apdu->p2, apdu->lc,
apdu->le);

return SC_SUCCESS;
}
33 changes: 20 additions & 13 deletions src/libopensc/asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,9 @@ const u8 *sc_asn1_skip_tag(sc_context_t *ctx, const u8 ** buf, size_t *buflen,
return NULL;
len -= (p - *buf); /* header size */
if (taglen > len) {
sc_debug(ctx, SC_LOG_DEBUG_ASN1, "too long ASN.1 object (size %d while only %d available)\n",
taglen, len);
sc_debug(ctx, SC_LOG_DEBUG_ASN1,
"too long ASN.1 object (size %"SC_FORMAT_LEN_SIZE_T"u while only %"SC_FORMAT_LEN_SIZE_T"u available)\n",
taglen, len);
return NULL;
}
*buflen -= (p - *buf) + taglen;
Expand Down Expand Up @@ -1276,7 +1277,9 @@ static int asn1_decode_entry(sc_context_t *ctx,struct sc_asn1_entry *entry,
case SC_ASN1_BOOLEAN:
if (parm != NULL) {
if (objlen != 1) {
sc_debug(ctx, SC_LOG_DEBUG_ASN1, "invalid ASN.1 object length: %d\n", objlen);
sc_debug(ctx, SC_LOG_DEBUG_ASN1,
"invalid ASN.1 object length: %"SC_FORMAT_LEN_SIZE_T"u\n",
objlen);
r = SC_ERROR_INVALID_ASN1_OBJECT;
} else
*((int *) parm) = obj[0] ? 1 : 0;
Expand Down Expand Up @@ -1444,10 +1447,9 @@ static int asn1_decode(sc_context_t *ctx, struct sc_asn1_entry *asn1,
struct sc_asn1_entry *entry = asn1;
size_t left = len, objlen;

sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*scalled, left=%u, depth %d%s\n",
depth, depth, "",
left, depth,
choice ? ", choice" : "");
sc_debug(ctx, SC_LOG_DEBUG_ASN1,
"%*.*scalled, left=%"SC_FORMAT_LEN_SIZE_T"u, depth %d%s\n",
depth, depth, "", left, depth, choice ? ", choice" : "");

if (!p)
return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
Expand Down Expand Up @@ -1553,9 +1555,10 @@ static int asn1_encode_entry(sc_context_t *ctx, const struct sc_asn1_entry *entr
(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
if (!(entry->flags & SC_ASN1_PRESENT))
goto no_object;
sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*stype=%d, tag=0x%02x, parm=%p, len=%u\n",
depth, depth, "",
entry->type, entry->tag, parm, len? *len : 0);
sc_debug(ctx, SC_LOG_DEBUG_ASN1,
"%*.*stype=%d, tag=0x%02x, parm=%p, len=%"SC_FORMAT_LEN_SIZE_T"u\n",
depth, depth, "", entry->type, entry->tag, parm,
len ? *len : 0);

if (entry->type == SC_ASN1_CHOICE) {
const struct sc_asn1_entry *list, *choice = NULL;
Expand Down Expand Up @@ -1733,7 +1736,9 @@ static int asn1_encode_entry(sc_context_t *ctx, const struct sc_asn1_entry *entr
if (buf)
free(buf);
if (r >= 0)
sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*slength of encoded item=%u\n", depth, depth, "", *objlen);
sc_debug(ctx, SC_LOG_DEBUG_ASN1,
"%*.*slength of encoded item=%"SC_FORMAT_LEN_SIZE_T"u\n",
depth, depth, "", *objlen);
return r;
}

Expand Down Expand Up @@ -1916,8 +1921,10 @@ sc_asn1_sig_value_sequence_to_rs(struct sc_context *ctx, unsigned char *in, size
memcpy(buf + (halflen - r_len), r, r_len);
memcpy(buf + (buflen - s_len), s, s_len);

sc_log(ctx, "r(%i): %s", halflen, sc_dump_hex(buf, halflen));
sc_log(ctx, "s(%i): %s", halflen, sc_dump_hex(buf + halflen, halflen));
sc_log(ctx, "r(%"SC_FORMAT_LEN_SIZE_T"u): %s", halflen,
sc_dump_hex(buf, halflen));
sc_log(ctx, "s(%"SC_FORMAT_LEN_SIZE_T"u): %s", halflen,
sc_dump_hex(buf + halflen, halflen));

rv = SC_SUCCESS;
done:
Expand Down
4 changes: 3 additions & 1 deletion src/libopensc/aux-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ sc_aux_data_get_md_guid(struct sc_context *ctx, struct sc_auxiliary_data *aux_da
strlcat(guid, "}", sizeof(guid));

if (*out_size < strlen(guid)) {
sc_log(ctx, "aux-data: buffer too small: out_size:%i < guid-length:%i", *out_size, strlen(guid));
sc_log(ctx,
"aux-data: buffer too small: out_size:%"SC_FORMAT_LEN_SIZE_T"u < guid-length:%"SC_FORMAT_LEN_SIZE_T"u",
*out_size, strlen(guid));
LOG_FUNC_RETURN(ctx, SC_ERROR_BUFFER_TOO_SMALL);
}

Expand Down
11 changes: 6 additions & 5 deletions src/libopensc/card-atrust-acos.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,12 @@ static int atrust_acos_select_file(struct sc_card *card,
pbuf[0] = '\0';

sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
"current path (%s, %s): %s (len: %u)\n",
(card->cache.current_path.type==SC_PATH_TYPE_DF_NAME?"aid":"path"),
(card->cache.valid?"valid":"invalid"), pbuf,
card->cache.current_path.len);

"current path (%s, %s): %s (len: %"SC_FORMAT_LEN_SIZE_T"u)\n",
card->cache.current_path.type == SC_PATH_TYPE_DF_NAME ?
"aid" : "path",
card->cache.valid ? "valid" : "invalid", pbuf,
card->cache.current_path.len);

memcpy(path, in_path->value, in_path->len);
pathlen = in_path->len;

Expand Down
Loading