diff --git a/src/libopensc/card-multiflex.c b/src/libopensc/card-multiflex.c index 0c873a85..fc0399bb 100644 --- a/src/libopensc/card-multiflex.c +++ b/src/libopensc/card-multiflex.c @@ -144,8 +144,6 @@ static int mflex_select_file(struct sc_card *card, const struct sc_path *path, sc_format_path("I3F00", &tmppath); r = mflex_select_file(card, &tmppath, NULL); SC_TEST_RET(card->ctx, r, "Unable to select Master File (MF)"); - pathptr += 2; - pathlen -= 2; } while (pathlen > 2) { memcpy(tmppath.value, pathptr, 2); diff --git a/src/libopensc/opensc.h b/src/libopensc/opensc.h index ae4e56d7..d09b23bf 100644 --- a/src/libopensc/opensc.h +++ b/src/libopensc/opensc.h @@ -245,7 +245,7 @@ struct sc_card_operations { /* select_file: Does the equivalent of SELECT FILE command specified * in ISO7816-4. Stores information about the selected file to - * , if not NULL. */ + * , if not NULL. */ int (*select_file)(struct sc_card *card, const struct sc_path *path, struct sc_file *file_out); int (*get_response)(struct sc_card *card, u8 * buf, size_t count); @@ -340,6 +340,7 @@ int sc_lock(struct sc_card *card); int sc_unlock(struct sc_card *card); /* ISO 7816-4 related functions */ + int sc_select_file(struct sc_card *card, const struct sc_path *path, struct sc_file *file); int sc_read_binary(struct sc_card *card, unsigned int idx, u8 * buf, diff --git a/src/libopensc/pkcs15.c b/src/libopensc/pkcs15.c index 60a3a68e..95b9081a 100644 --- a/src/libopensc/pkcs15.c +++ b/src/libopensc/pkcs15.c @@ -272,6 +272,7 @@ int sc_pkcs15_bind(struct sc_card *card, err = sc_select_file(card, &tmppath, &p15card->file_dir); if (err) { error(ctx, "Error selecting EF(DIR): %s\n", sc_strerror(err)); + err = SC_ERROR_PKCS15_CARD_NOT_FOUND; goto error; } err = sc_read_binary(card, 0, buf, p15card->file_dir.size, 0); diff --git a/src/libopensc/sc.c b/src/libopensc/sc.c index 3389b6c3..71631d52 100644 --- a/src/libopensc/sc.c +++ b/src/libopensc/sc.c @@ -213,11 +213,11 @@ void sc_format_path(const char *str, struct sc_path *path) int type = SC_PATH_TYPE_PATH; u8 *p = path->value; - if (*p == 'i' || *p == 'I') { + if (*str == 'i' || *str == 'I') { type = SC_PATH_TYPE_FILE_ID; - p++; + str++; } - while (str) { + while (*str) { int byte; if (sscanf(str, "%02X", &byte) != 1) diff --git a/src/pkcs11/generic.c b/src/pkcs11/generic.c index 4f674169..0827aaa2 100644 --- a/src/pkcs11/generic.c +++ b/src/pkcs11/generic.c @@ -165,7 +165,7 @@ CK_RV C_GetSlotInfo(CK_SLOT_ID slotID, CK_SLOT_INFO_PTR pInfo) CK_RV C_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo) { int r; - + LOG("C_GetTokenInfo(%d, 0x%x)\n", slotID, pInfo); if (slotID < 0 || slotID >= ctx->reader_count) return CKR_SLOT_ID_INVALID; @@ -181,7 +181,7 @@ CK_RV C_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo) pInfo->label[31] = 0; strncpy((char *) pInfo->manufacturerID, slot[slotID].p15card->manufacturer_id, 32); pInfo->manufacturerID[31] = 0; - strcpy((char *) pInfo->model, "PKCS#15 SC"); + strcpy((char *) pInfo->model, "PKCS #15 SC"); strncpy((char *) pInfo->serialNumber, slot[slotID].p15card->serial_number, 16); pInfo->serialNumber[15] = 0; @@ -210,7 +210,7 @@ CK_RV C_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo) pInfo->hardwareVersion.minor = 0; pInfo->firmwareVersion.major = 1; pInfo->firmwareVersion.minor = 0; - + return CKR_OK; } @@ -248,7 +248,7 @@ CK_RV C_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_INFO_PTR pInfo) { LOG("C_GetMechanismInfo(%d, %d, 0x%x)\n", slotID, type, pInfo); - return CKR_FUNCTION_NOT_SUPPORTED; + return CKR_FUNCTION_NOT_SUPPORTED; } CK_RV C_InitToken(CK_SLOT_ID slotID, @@ -256,6 +256,6 @@ CK_RV C_InitToken(CK_SLOT_ID slotID, CK_ULONG ulPinLen, CK_CHAR_PTR pLabel) { - LOG("C_InitToken(%d, '%s', %d, '%s')\n", slotID, pPin, ulPinLen, pLabel); - return CKR_FUNCTION_NOT_SUPPORTED; + LOG("C_InitToken(%d, '%s', %d, '%s')\n", slotID, pPin, ulPinLen, pLabel); + return CKR_FUNCTION_NOT_SUPPORTED; } diff --git a/src/pkcs11/slot.c b/src/pkcs11/slot.c index 34492344..b818f157 100644 --- a/src/pkcs11/slot.c +++ b/src/pkcs11/slot.c @@ -133,10 +133,6 @@ int slot_connect(int id) struct sc_pkcs15_cert *cert; struct sc_pkcs15_cert_info *cinfo = &p15card->cert_info[c]; -#if 0 - if (cinfo->authority) - continue; -#endif LOG("Reading '%s' certificate.\n", cinfo->com_attr.label); r = sc_pkcs15_read_certificate(p15card, cinfo, &cert); if (r) @@ -144,12 +140,14 @@ int slot_connect(int id) LOG("Adding '%s' certificate object (id %X).\n", cinfo->com_attr.label, cinfo->id); slot_add_certificate_object(id, c, cinfo, cert); + for (i = 0; i < p15card->prkey_count; i++) { struct sc_pkcs15_prkey_info *pinfo = &p15card->prkey_info[i]; if (sc_pkcs15_compare_id(&cinfo->id, &pinfo->id)) { LOG("Adding '%s' private key object (id %X).\n", - pinfo->com_attr.label, pinfo->id); - slot_add_private_key_object(id, i, pinfo, cert); + pinfo->com_attr.label, pinfo->id.value[0]); + if (slot_add_private_key_object(id, i, pinfo, cert)) + LOG("Private key addition failed.\n"); } } sc_pkcs15_free_certificate(cert); @@ -163,8 +161,10 @@ int slot_disconnect(int id) LOG("Disconnecting from slot %d\n", id); slot[id].flags = 0; if (slot[id].p15card != NULL) { + struct sc_card *card = slot[id].p15card->card; + sc_pkcs15_unbind(slot[id].p15card); - sc_disconnect_card(slot[id].p15card->card); + sc_disconnect_card(card); slot[id].p15card = NULL; }