From 4bd0e4261b85885ed80e56a9dd933b7d2f7360b8 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Mon, 31 Oct 2016 16:52:40 +0100 Subject: [PATCH] reader-pcsc: use enable_boxing for UID command allows disabling wrapped commands with CLA=0xFF on broken readers, see https://github.com/OpenSC/OpenSC/issues/810 --- etc/opensc.conf.in | 3 ++- src/libopensc/reader-pcsc.c | 48 +++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/etc/opensc.conf.in b/etc/opensc.conf.in index 754f75a2af2..970dcd99147 100644 --- a/etc/opensc.conf.in +++ b/etc/opensc.conf.in @@ -95,7 +95,8 @@ app default { # Default: true # enable_pinpad = false; # - # Detect boxing commands for PIN operations (BSI TR-03119) + # Detect reader capabilities with boxing commands (wrapped APDUs with + # CLA=0xFF as defined by PC/SC pt. 3 and BSI TR-03119) # Default: false # enable_boxing = true; # diff --git a/src/libopensc/reader-pcsc.c b/src/libopensc/reader-pcsc.c index 2abaffee7ed..27ea4299fbb 100644 --- a/src/libopensc/reader-pcsc.c +++ b/src/libopensc/reader-pcsc.c @@ -472,29 +472,31 @@ static int pcsc_reconnect(sc_reader_t * reader, DWORD action) static void initialize_uid(sc_reader_t *reader) { - sc_apdu_t apdu; - /* though we only expect 10 bytes max, we want to set the Le to 0x00 to not - * get 0x6282 as SW in case of a UID variant shorter than 10 bytes */ - u8 rbuf[256]; - - memset(&apdu, 0, sizeof(apdu)); - apdu.cse = SC_APDU_CASE_2_SHORT; - apdu.cla = 0xFF; - apdu.ins = 0xCA; - apdu.p1 = 0x00; - apdu.p2 = 0x00; - apdu.le = 0x00; - apdu.resp = rbuf; - apdu.resplen = sizeof rbuf; - - if (SC_SUCCESS == pcsc_transmit(reader, &apdu) - && apdu.sw1 == 0x90 && apdu.sw2 == 0x00) { - reader->uid.len = apdu.resplen; - memcpy(reader->uid.value, apdu.resp, reader->uid.len); - sc_debug_hex(reader->ctx, SC_LOG_DEBUG_NORMAL, "UID", - reader->uid.value, reader->uid.len); - } else { - sc_debug(reader->ctx, SC_LOG_DEBUG_NORMAL, "unable to get UID"); + if (reader->flags & SC_READER_TEST_BOXING) { + sc_apdu_t apdu; + /* though we only expect 10 bytes max, we want to set the Le to 0x00 to not + * get 0x6282 as SW in case of a UID variant shorter than 10 bytes */ + u8 rbuf[256]; + + memset(&apdu, 0, sizeof(apdu)); + apdu.cse = SC_APDU_CASE_2_SHORT; + apdu.cla = 0xFF; + apdu.ins = 0xCA; + apdu.p1 = 0x00; + apdu.p2 = 0x00; + apdu.le = 0x00; + apdu.resp = rbuf; + apdu.resplen = sizeof rbuf; + + if (SC_SUCCESS == pcsc_transmit(reader, &apdu) + && apdu.sw1 == 0x90 && apdu.sw2 == 0x00) { + reader->uid.len = apdu.resplen; + memcpy(reader->uid.value, apdu.resp, reader->uid.len); + sc_debug_hex(reader->ctx, SC_LOG_DEBUG_NORMAL, "UID", + reader->uid.value, reader->uid.len); + } else { + sc_debug(reader->ctx, SC_LOG_DEBUG_NORMAL, "unable to get UID"); + } } }