Skip to content

Commit

Permalink
reader-pcsc: use enable_boxing for UID command
Browse files Browse the repository at this point in the history
allows disabling wrapped commands with CLA=0xFF on broken readers, see
OpenSC#810
  • Loading branch information
frankmorgner committed Oct 31, 2016
1 parent d324a12 commit 4bd0e42
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
3 changes: 2 additions & 1 deletion etc/opensc.conf.in
Expand Up @@ -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;
#
Expand Down
48 changes: 25 additions & 23 deletions src/libopensc/reader-pcsc.c
Expand Up @@ -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");
}
}
}

Expand Down

0 comments on commit 4bd0e42

Please sign in to comment.