Hello,

So this is the interesting part from the log:

On Thu, Jun 30, 2011 at 17:21, Thomas Grenman <tgren...@aalto.fi> wrote:
> 0xb779b8d0 16:59:59.149 [pkcs15-tool] dir.c:141:sc_enum_apps: called
> 0xb779b8d0 16:59:59.149 [pkcs15-tool] card.c:571:sc_select_file: called;
> type=2, path=3f002f00
> 0xb779b8d0 16:59:59.149 [pkcs15-tool] apdu.c:524:sc_transmit_apdu: called
> 0xb779b8d0 16:59:59.149 [pkcs15-tool] card.c:292:sc_lock: called
> 0xb779b8d0 16:59:59.149 [pkcs15-tool] reader-pcsc.c:241:pcsc_transmit:
> reader 'SCM SCR 331 [CCID Interface] (50400A7F) 00 00'
> 0xb779b8d0 16:59:59.149 [pkcs15-tool] apdu.c:184:sc_apdu_log: Outgoing APDU
> data [    7 bytes] =====================================
> 00 A4 08 00 02 2F 00 ...../.
> ======================================================================
> 0xb779b8d0 16:59:59.149 [pkcs15-tool]
> reader-pcsc.c:174:pcsc_internal_transmit: called
> 0xb779b8d0 16:59:59.184 [pkcs15-tool] apdu.c:184:sc_apdu_log: Incoming APDU
> data [    2 bytes] =====================================
> 6A 88 j.
> ======================================================================
> 0xb779b8d0 16:59:59.184 [pkcs15-tool] card.c:330:sc_unlock: called
> 0xb779b8d0 16:59:59.184 [pkcs15-tool] iso7816.c:103:iso7816_check_sw:
> Referenced data not found
> 0xb779b8d0 16:59:59.184 [pkcs15-tool] iso7816.c:484:iso7816_select_file:
> returning with: -1216 (Data object not found)
> 0xb779b8d0 16:59:59.184 [pkcs15-tool] card.c:597:sc_select_file: returning
> with: -1216 (Data object not found)
> 0xb779b8d0 16:59:59.184 [pkcs15-tool] dir.c:151:sc_enum_apps: Cannot select
> EF.DIR file: -1216 (Data object not found)



sc_enum_apps fails because sc_select_file returns an "unknown" SW 6A88
which gets translated to SC_ERROR_DATA_OBJECT_NOT_FOUND in iso7816.c.
Looking at ISO7816-4, it is not listed as a "relevant SW" for SELECT
command, which is failing (which also makes sense to me)
It seems to me that the card (or the relevant applet) is programmed to
return 6A88 instead of 6A82. Just to be sure: what happens if you try
opensc-explorer and try to cd to any non-existent DF with debug on,
for example:
opensc-explorer
debug 9
cd 1234

I guess it will return 6A88 again.

So for a cleaner approach, some options are available:
 - define better what sc_enum_apps is supposed to do and what it should return.
  - this could mean either returning only known error codes or
extending the "to be expected error codes" so that your original patch
would make sense. Or translating "internal" error codes to the defined
codes.
 - improve iso7816_select_file to detect the incorrect but "almost
identical" error and translate it to a semantically better one
(SC_ERROR_FILE_NOT_FOUND)
  - this does not seem like a good option, sc_select_file should be a
low level passthrough that should raise all errors without any changes

 So I guess the best option is to constrain the number of possible
error codes from sc_enum_apps and better document/define what it
should do and what happens if it fails. Does the attached patch work
for you?
From e2d2c90b67552049d1c1dc2c0e9ddf0b42bada96 Mon Sep 17 00:00:00 2001
From: Martin Paljak <mar...@martinpaljak.net>
Date: Thu, 30 Jun 2011 17:56:23 +0300
Subject: [PATCH] Fix for broken FinnishEid card which returns 6A88 isntead of 6A82 for SELECT commands with missing files.

---
 src/libopensc/dir.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/libopensc/dir.c b/src/libopensc/dir.c
index d3ce1c1..8af7384 100644
--- a/src/libopensc/dir.c
+++ b/src/libopensc/dir.c
@@ -148,6 +148,9 @@ int sc_enum_apps(sc_card_t *card)
 		card->ef_dir = NULL;
 	}
 	r = sc_select_file(card, &path, &card->ef_dir);
+	/* Workaround for cards that return 6A88 instead of 6A82 for missing files */
+	if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND)
+			r = SC_ERROR_FILE_NOT_FOUND;
 	SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot select EF.DIR file");
 
 	if (card->ef_dir->type != SC_FILE_TYPE_WORKING_EF) {
-- 
1.7.4.1

_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to