From d3b7dd4dac73fcfedaea2b7d895a5491f4d2743e Mon Sep 17 00:00:00 2001 From: frankmorgner Date: Mon, 25 Jul 2011 21:14:28 +0000 Subject: [PATCH] switched to opensc 0.12.1, where build_apdu has been accepted as sc_bytes2apdu git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@433 96b47cad-a561-4643-ad3b-153ac7d7599c --- ccid/configure.ac | 10 ++-- ccid/src/ccid.c | 6 +-- npa/configure.ac | 10 ++-- npa/src/npa-tool.c | 2 +- npa/src/scutil.c | 114 --------------------------------------------- 5 files changed, 14 insertions(+), 128 deletions(-) diff --git a/ccid/configure.ac b/ccid/configure.ac index 27ed6b8..c74c6d8 100644 --- a/ccid/configure.ac +++ b/ccid/configure.ac @@ -85,13 +85,13 @@ if test "x$enable_pace" != xno ; then 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])]) + [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" 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_MSG_CHECKING([for sc_bytes2apdu]) + AC_TRY_LINK_FUNC(sc_bytes2apdu, [ AC_MSG_RESULT([yes]) ], + [ AC_MSG_ERROR([libopensc >= 0.12.1 not found, use ./configure OPENSC_LIBS=...]) ]) fi CPPFLAGS="$saved_CPPFLAGS" LIBS="$saved_LIBS" diff --git a/ccid/src/ccid.c b/ccid/src/ccid.c index 54369c7..3c893c6 100644 --- a/ccid/src/ccid.c +++ b/ccid/src/ccid.c @@ -408,7 +408,7 @@ perform_PC_to_RDR_IccPowerOn(const __u8 *in, size_t inlen, __u8 **out, size_t *o if (sc_result >= 0) { return get_RDR_to_PC_SlotStatus(request->bSeq, - sc_result, out, outlen, card->atr, card->atr_len); + sc_result, out, outlen, card->atr.value, card->atr.len); } else { sc_debug(ctx, SC_LOG_DEBUG_VERBOSE, "Returning default status package."); return get_RDR_to_PC_SlotStatus(request->bSeq, @@ -544,7 +544,7 @@ perform_PC_to_RDR_XfrBlock(const u8 *in, size_t inlen, __u8** out, size_t *outle sc_result = perform_pseudo_apdu(abDataIn, apdulen, &abDataOut, &abDataOutLen); } else { - sc_result = build_apdu(ctx, abDataIn, apdulen, &apdu); + sc_result = sc_bytes2apdu(ctx, abDataIn, apdulen, &apdu); if (sc_result >= 0) sc_result = get_rapdu(&apdu, &abDataOut, &abDataOutLen); @@ -1217,7 +1217,7 @@ perform_PC_to_RDR_Secure(const __u8 *in, size_t inlen, __u8** out, size_t *outle sc_result = SC_ERROR_INVALID_DATA; goto err; } - sc_result = build_apdu(ctx, abPINApdu, apdulen, &apdu); + sc_result = sc_bytes2apdu(ctx, abPINApdu, apdulen, &apdu); if (sc_result < 0) { bin_log(ctx, SC_LOG_DEBUG_VERBOSE, "Invalid APDU", abPINApdu, apdulen); goto err; diff --git a/npa/configure.ac b/npa/configure.ac index 04d40ab..94f4ff1 100644 --- a/npa/configure.ac +++ b/npa/configure.ac @@ -23,8 +23,8 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) # 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])]) + [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" PKG_CHECK_EXISTS([libssl], @@ -35,9 +35,9 @@ saved_CPPFLAGS="$CPPFLAGS" saved_LIBS="$LIBS" CPPFLAGS="$CPPFLAGS $OPENSSL_CFLAGS" 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_MSG_CHECKING([for sc_bytes2apdu]) +AC_TRY_LINK_FUNC(sc_bytes2apdu, [ AC_MSG_RESULT([yes]) ], + [ AC_MSG_ERROR([libopensc >= 0.12.1 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_MSG_CHECKING([for EVP_read_pw_string_min]) diff --git a/npa/src/npa-tool.c b/npa/src/npa-tool.c index fdf6db5..e18c725 100644 --- a/npa/src/npa-tool.c +++ b/npa/src/npa-tool.c @@ -168,7 +168,7 @@ int npa_translate_apdus(struct sm_ctx *sctx, sc_card_t *card, FILE *input) if (input != stdin) bin_print(stdout, "Unencrypted C-APDU", buf, apdulen); - r = build_apdu(card->ctx, buf, apdulen, &apdu); + r = sc_bytes2apdu(card->ctx, buf, apdulen, &apdu); if (r < 0) { bin_log(ctx, SC_LOG_DEBUG_NORMAL, "Invalid C-APDU", buf, apdulen); continue; diff --git a/npa/src/scutil.c b/npa/src/scutil.c index 835e36e..de2ad9f 100644 --- a/npa/src/scutil.c +++ b/npa/src/scutil.c @@ -80,120 +80,6 @@ int initialize(int reader_id, const char *cdriver, int verbose, return SC_SUCCESS; } - -int build_apdu(sc_context_t *ctx, const u8 *buf, size_t len, sc_apdu_t *apdu) -{ - const u8 *p; - size_t len0; - - if (!buf || !apdu) - return SC_ERROR_INVALID_ARGUMENTS; - - len0 = len; - if (len < 4) { - sc_debug(ctx, SC_LOG_DEBUG_VERBOSE, "APDU too short (must be at least 4 bytes)"); - return SC_ERROR_INVALID_DATA; - } - - memset(apdu, 0, sizeof *apdu); - p = buf; - apdu->cla = *p++; - apdu->ins = *p++; - apdu->p1 = *p++; - apdu->p2 = *p++; - len -= 4; - if (!len) { - apdu->cse = SC_APDU_CASE_1; - } else { - if (*p == 0 && len >= 3) { - /* ...must be an extended APDU */ - p++; - if (len == 3) { - apdu->le = (*p++)<<8; - apdu->le += *p++; - if (apdu->le == 0) - apdu->le = 0xffff+1; - len -= 3; - apdu->cse = SC_APDU_CASE_2_EXT; - } else { - /* len > 3 */ - apdu->lc = (*p++)<<8; - apdu->lc += *p++; - len -= 3; - if (len < apdu->lc) { - sc_debug(ctx, SC_LOG_DEBUG_VERBOSE, "APDU too short (need %lu more bytes)\n", - (unsigned long) apdu->lc - len); - return SC_ERROR_INVALID_DATA; - } - apdu->data = p; - apdu->datalen = apdu->lc; - len -= apdu->lc; - p += apdu->lc; - if (!len) { - apdu->cse = SC_APDU_CASE_3_EXT; - } else { - /* at this point the apdu has a Lc, so Le is on 2 bytes */ - if (len < 2) { - sc_debug(ctx, SC_LOG_DEBUG_VERBOSE, "APDU too short (need 2 more bytes)\n"); - return SC_ERROR_INVALID_DATA; - } - apdu->le = (*p++)<<8; - apdu->le += *p++; - if (apdu->le == 0) - apdu->le = 0xffff+1; - len -= 2; - apdu->cse = SC_APDU_CASE_4_EXT; - } - } - } else { - /* ...must be a short APDU */ - if (len == 1) { - apdu->le = *p++; - if (apdu->le == 0) - apdu->le = 0xff+1; - len--; - apdu->cse = SC_APDU_CASE_2_SHORT; - } else { - apdu->lc = *p++; - len--; - if (len < apdu->lc) { - sc_debug(ctx, SC_LOG_DEBUG_VERBOSE, "APDU too short (need %lu more bytes)\n", - (unsigned long) apdu->lc - len); - return SC_ERROR_INVALID_DATA; - } - apdu->data = p; - apdu->datalen = apdu->lc; - len -= apdu->lc; - p += apdu->lc; - if (!len) { - apdu->cse = SC_APDU_CASE_3_SHORT; - } else { - apdu->le = *p++; - if (apdu->le == 0) - apdu->le = 0xff+1; - len--; - apdu->cse = SC_APDU_CASE_4_SHORT; - - } - } - } - if (len) { - sc_debug(ctx, SC_LOG_DEBUG_VERBOSE, "APDU too long (%lu bytes extra)\n", - (unsigned long) len); - return SC_ERROR_INVALID_DATA; - } - } - - apdu->flags = SC_APDU_FLAGS_NO_GET_RESP|SC_APDU_FLAGS_NO_RETRY_WL; - - sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "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); - - return SC_SUCCESS; -} - void _bin_log(sc_context_t *ctx, int type, const char *file, int line, const char *func, const char *label, const u8 *data, size_t len, FILE *f)