2010/11/16 Ludovic Rousseau <ludovic.rouss...@gmail.com>: > 2010/11/4 Camille Moncelier <moncel...@devlife.org>: >> On Thu, 4 Nov 2010 09:37:30 +0100 >> Ludovic Rousseau <ludovic.rouss...@gmail.com> wrote: >> >>> 2010/11/3 Camille Moncelier <moncel...@devlife.org>: >>> > In some case readers can be wired to always return >>> > CKF_TOKEN_PRESENT even when there's no card (Because there's no >>> > mechanical contacts for card insertion, like some SIMcard readers). >>> >>> So why connect the SIM card reader without any smart card inside? >>> The smart card reader is wired to the host and can't be unplugged? >>> >>> What is your use case exactly? >>> >>> Bye >>> >> >> I'm using embedded computers with two smartcard readers soldered like >> this one: >> http://www.globalconnectortechnology.com/sim-connectors/pdf/SIM5051.pdf >> >> These connectors doesn't have sim inserted contacts so the controller >> is wired so it always reports there's a smartcard because it has no way >> to tell if there not. >> >> libp11 fails to access any token if one of the reader fails to read a >> token. > > I see the problem. > > I am not sure your patch is complete. With your change > pkcs11_init_slot() will never return with an error. So > PKCS11_enumerate_slots() (the only user of pkcs11_init_slot()) should > also be changed to reflect that. > > Other comments?
New patch proposed attached. Since I am not the maintainer of libp11 I do not want to commit a patch with possible bad side effects. Bye -- Dr. Ludovic Rousseau
Index: src/p11_slot.c =================================================================== --- src/p11_slot.c (révision 196) +++ src/p11_slot.c (copie de travail) @@ -21,7 +21,7 @@ #include <openssl/buffer.h> #include "libp11-int.h" -static int pkcs11_init_slot(PKCS11_CTX *, PKCS11_SLOT *, CK_SLOT_ID); +static void pkcs11_init_slot(PKCS11_CTX *, PKCS11_SLOT *, CK_SLOT_ID); static int pkcs11_check_token(PKCS11_CTX *, PKCS11_SLOT *); static void pkcs11_destroy_token(PKCS11_TOKEN *); @@ -60,13 +60,7 @@ PKCS11_enumerate_slots(PKCS11_CTX * ctx, slots = (PKCS11_SLOT *) pkcs11_malloc(nslots * sizeof(PKCS11_SLOT)); for (n = 0; n < nslots; n++) { - if (pkcs11_init_slot(ctx, &slots[n], slotid[n])) { - while (n--) - pkcs11_release_slot(ctx, slots + n); - OPENSSL_free(slotid); - OPENSSL_free(slots); - return -1; - } + pkcs11_init_slot(ctx, &slots[n], slotid[n]); } *slotp = slots; @@ -302,28 +296,34 @@ int PKCS11_generate_random(PKCS11_SLOT * /* * Helper functions */ -static int pkcs11_init_slot(PKCS11_CTX * ctx, PKCS11_SLOT * slot, CK_SLOT_ID id) +static void pkcs11_init_slot(PKCS11_CTX * ctx, PKCS11_SLOT * slot, CK_SLOT_ID id) { PKCS11_SLOT_private *priv; CK_SLOT_INFO info; int rv; rv = CRYPTOKI_call(ctx, C_GetSlotInfo(id, &info)); - CRYPTOKI_checkerr(PKCS11_F_PKCS11_ENUM_SLOTS, rv); priv = PKCS11_NEW(PKCS11_SLOT_private); priv->parent = ctx; priv->id = id; - slot->description = PKCS11_DUP(info.slotDescription); - slot->manufacturer = PKCS11_DUP(info.manufacturerID); - slot->removable = (info.flags & CKF_REMOVABLE_DEVICE) ? 1 : 0; slot->_private = priv; - - if ((info.flags & CKF_TOKEN_PRESENT) && pkcs11_check_token(ctx, slot)) - return -1; - - return 0; + if (CKR_OK == rv) { + slot->description = PKCS11_DUP(info.slotDescription); + slot->manufacturer = PKCS11_DUP(info.manufacturerID); + slot->removable = (info.flags & CKF_REMOVABLE_DEVICE) ? 1 : 0; + if ((info.flags & CKF_TOKEN_PRESENT) && pkcs11_check_token(ctx, slot)) + slot->token = NULL; + } + else { + char desc[64]; + snprintf(desc, sizeof(desc), "(GetSlotInfo failed, error 0x%X)", rv); + slot->description = PKCS11_DUP(desc); + slot->manufacturer = PKCS11_DUP("Unknown"); + slot->removable = 0; + slot->token = NULL; + } } void PKCS11_release_all_slots(PKCS11_CTX * ctx, PKCS11_SLOT *slots, unsigned int nslots)
_______________________________________________ opensc-devel mailing list opensc-devel@lists.opensc-project.org http://www.opensc-project.org/mailman/listinfo/opensc-devel