diff --git a/ccid/Makefile b/ccid/Makefile index 7011d31..09a0461 100644 --- a/ccid/Makefile +++ b/ccid/Makefile @@ -9,21 +9,24 @@ bindir = $(exec_prefix)/bin # Compiler CC = gcc CFLAGS = -Wall -g -EXTRA_CFLAGS = -DNO_PACE OPENSSL_CFLAGS = `pkg-config --cflags --libs libssl` OPENSC_CFLAGS = `pkg-config --cflags --libs libopensc` PTHREAD_CFLAGS = -pthread -a_flags = $(CFLAGS) $(OPENSC_CFLAGS) $(OPENSSL_CFLAGS) \ - $(PTHREAD_CFLAGS) $(EXTRA_CFLAGS) +a_flags = $(CFLAGS) $(OPENSC_CFLAGS) $(OPENSSL_CFLAGS) $(PTHREAD_CFLAGS) INSTALL = install INSTALL_PROGRAM = $(INSTALL) TARGETS = ccid +CCID_OBJ = ccid.o sm.o usbstring.o usb.o -CCID_OBJ = ccid.o sm.o pace.o pace_lib.o usbstring.o usb.o +ifdef PACE + CCID_OBJ += pace.o pace_lib.o +else + a_flags += -DNO_PACE +endif # top-level rule all: $(TARGETS) diff --git a/ccid/ccid.c b/ccid/ccid.c index 1df5702..984f484 100644 --- a/ccid/ccid.c +++ b/ccid/ccid.c @@ -27,7 +27,9 @@ #include #include "ccid.h" +#ifndef NO_PACE #include "pace.h" +#endif static sc_context_t *ctx = NULL; static sc_card_t *card_in_slot[SC_MAX_SLOTS]; @@ -1305,6 +1307,14 @@ int ccid_state_changed(RDR_to_PC_NotifySlotChange_t **slotchange, int timeout) return 0; } +#ifdef NO_PACE +int ccid_testpace(u8 pin_id, const char *pin, size_t pinlen) +{ + sc_error(ctx, "ccid not compiled with support for PACE."); + + return SC_ERROR_NOT_SUPPORTED; +} +#else int ccid_testpace(u8 pin_id, const char *pin, size_t pinlen) { int i; @@ -1321,6 +1331,7 @@ int ccid_testpace(u8 pin_id, const char *pin, size_t pinlen) return SC_ERROR_SLOT_NOT_FOUND; } +#endif static int ccid_list_readers(sc_context_t *ctx) { diff --git a/ccid/pace.c b/ccid/pace.c index 28858ef..36baf8e 100644 --- a/ccid/pace.c +++ b/ccid/pace.c @@ -1296,6 +1296,11 @@ int pace_transmit_apdu(struct sm_ctx *ctx, sc_card_t *card, { int r; + if ((apdu->cla & 0x0C) == 0x0C) { + sc_debug(card->ctx, "Given APDU is already protected with some secure messaging."); + SC_FUNC_RETURN(card->ctx, SC_LOG_TYPE_DEBUG, sc_transmit_apdu(card, apdu)); + } + if (!ctx || !ctx->cipher_ctx) { SC_FUNC_RETURN(card->ctx, SC_LOG_TYPE_DEBUG, SC_ERROR_INVALID_ARGUMENTS); } diff --git a/ccid/sm.c b/ccid/sm.c index 1098ef0..2729671 100644 --- a/ccid/sm.c +++ b/ccid/sm.c @@ -273,6 +273,12 @@ static int sm_encrypt(const struct sm_ctx *ctx, sc_card_t *card, goto err; } + if ((apdu->cla & 0x0C) == 0x0C) { + r = SC_ERROR_INVALID_ARGUMENTS; + sc_error(card->ctx, "Given APDU is already protected with some secure messaging."); + goto err; + } + sc_copy_asn1_entry(c_sm_capdu, sm_capdu); sm_apdu->sensitive = 0; diff --git a/ccid/usb.c b/ccid/usb.c index 5d19eb8..39a66af 100644 --- a/ccid/usb.c +++ b/ccid/usb.c @@ -47,7 +47,6 @@ #include "usbstring.h" #include "ccid.h" -#include "pace.h" #define DRIVER_VENDOR_NUM 0x0D46 /* KOBIL Systems */ #define DRIVER_PRODUCT_NUM 0x3010 /* KOBIL Class 3 Reader */