pkcs15: add 'aid' parameter to the prototype of the 'bind' functions ...

prepare for the multi-application support


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5041 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
vtarasov 2011-01-05 14:21:04 +00:00
parent 103af724fe
commit f2924672d8
10 changed files with 21 additions and 13 deletions

View File

@ -584,7 +584,7 @@ void sc_pkcs15_card_clear(sc_pkcs15_card_t *p15card)
}
}
static int sc_pkcs15_bind_internal(sc_pkcs15_card_t *p15card)
static int sc_pkcs15_bind_internal(sc_pkcs15_card_t *p15card, struct sc_aid *aid)
{
unsigned char *buf = NULL;
int err, ok = 0;
@ -614,6 +614,7 @@ static int sc_pkcs15_bind_internal(sc_pkcs15_card_t *p15card)
const sc_app_info_t *info;
info = sc_find_pkcs15_app(card);
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "info '%p'", info);
if (info != NULL) {
if (info->path.len)
p15card->file_app->path = info->path;
@ -641,10 +642,12 @@ static int sc_pkcs15_bind_internal(sc_pkcs15_card_t *p15card)
/* check if an ODF is present; we don't know yet whether we have a pkcs15 card */
tmppath = p15card->file_app->path;
sc_append_path_id(&tmppath, (const u8 *) "\x50\x31", 2);
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "tmppath '%s'", sc_print_path(&tmppath));
err = sc_select_file(card, &tmppath, &p15card->file_odf);
} else {
tmppath = p15card->file_odf->path;
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "tmppath '%s'", sc_print_path(&tmppath));
sc_file_free(p15card->file_odf);
p15card->file_odf = NULL;
err = sc_select_file(card, &tmppath, &p15card->file_odf);
@ -758,7 +761,8 @@ end:
return SC_SUCCESS;
}
int sc_pkcs15_bind(sc_card_t *card, struct sc_pkcs15_card **p15card_out)
int sc_pkcs15_bind(sc_card_t *card, struct sc_aid *aid,
struct sc_pkcs15_card **p15card_out)
{
struct sc_pkcs15_card *p15card = NULL;
sc_context_t *ctx = card->ctx;
@ -801,11 +805,11 @@ int sc_pkcs15_bind(sc_card_t *card, struct sc_pkcs15_card **p15card_out)
r = sc_pkcs15_bind_synthetic(p15card);
if (r == SC_SUCCESS)
goto done;
r = sc_pkcs15_bind_internal(p15card);
r = sc_pkcs15_bind_internal(p15card, aid);
if (r < 0)
goto error;
} else {
r = sc_pkcs15_bind_internal(p15card);
r = sc_pkcs15_bind_internal(p15card, aid);
if (r == SC_SUCCESS)
goto done;
r = sc_pkcs15_bind_synthetic(p15card);
@ -813,7 +817,7 @@ int sc_pkcs15_bind(sc_card_t *card, struct sc_pkcs15_card **p15card_out)
goto error;
}
} else {
r = sc_pkcs15_bind_internal(p15card);
r = sc_pkcs15_bind_internal(p15card, aid);
if (r < 0)
goto error;
}

View File

@ -503,7 +503,7 @@ typedef struct sc_pkcs15_card {
* and initializes a new PKCS #15 card object. Will return
* SC_ERROR_PKCS15_APP_NOT_FOUND, if the card hasn't got a
* valid PKCS #15 file structure. */
int sc_pkcs15_bind(struct sc_card *card,
int sc_pkcs15_bind(struct sc_card *card, struct sc_aid *aid,
struct sc_pkcs15_card **pkcs15_card);
/* sc_pkcs15_unbind: Releases a PKCS #15 card object, and frees any
* memory allocations done on the card object. */

View File

@ -53,6 +53,10 @@ struct sc_object_id {
int value[SC_MAX_OBJECT_ID_OCTETS];
};
struct sc_aid {
unsigned char value[SC_MAX_AID_SIZE];
size_t len;
};
#define SC_PATH_TYPE_FILE_ID 0
#define SC_PATH_TYPE_DF_NAME 1

View File

@ -163,7 +163,7 @@ static CK_RV pkcs15_bind(struct sc_pkcs11_card *p11card)
return CKR_HOST_MEMORY;
p11card->fw_data = fw_data;
rc = sc_pkcs15_bind(p11card->card, &fw_data->p15_card);
rc = sc_pkcs15_bind(p11card->card, NULL, &fw_data->p15_card);
if (rc != SC_SUCCESS) {
sc_debug(context, SC_LOG_DEBUG_NORMAL, "sc_pkcs15_bind failed: %d", rc);
return sc_to_cryptoki_error(rc, NULL);

View File

@ -459,7 +459,7 @@ sc_pkcs15init_erase_card(struct sc_pkcs15_card *p15card, struct sc_profile *prof
{
/* Needs the 'SOPIN' AUTH pkcs15 object.
* So that, SOPIN can be found by it's reference. */
if (sc_pkcs15_bind(p15card->card, &p15card) >= 0)
if (sc_pkcs15_bind(p15card->card, NULL, &p15card) >= 0)
profile->p15_data = p15card;
if (profile->ops->erase_card == NULL)

View File

@ -112,7 +112,7 @@ int main(int argc, char *argv[])
printf("Looking for a PKCS#15 compatible Smart Card... ");
fflush(stdout);
sc_lock(card);
i = sc_pkcs15_bind(card, &p15card);
i = sc_pkcs15_bind(card, NULL, &p15card);
/* Keep card locked to prevent useless calls to sc_logout */
if (i) {
fprintf(stderr, "failed: %s\n", sc_strerror(i));

View File

@ -91,7 +91,7 @@ int main(int argc, char *argv[])
printf("Looking for a PKCS#15 compatible Smart Card... ");
fflush(stdout);
sc_lock(card);
i = sc_pkcs15_bind(card, &p15card);
i = sc_pkcs15_bind(card, NULL, &p15card);
sc_unlock(card);
if (i) {
fprintf(stderr, "failed: %s\n", sc_strerror(i));

View File

@ -579,7 +579,7 @@ int main(int argc, char * const argv[])
if (verbose)
fprintf(stderr, "Trying to find a PKCS #15 compatible card...\n");
r = sc_pkcs15_bind(card, &p15card);
r = sc_pkcs15_bind(card, NULL, &p15card);
if (r) {
fprintf(stderr, "PKCS #15 binding failed: %s\n", sc_strerror(r));
err = 1;

View File

@ -450,7 +450,7 @@ main(int argc, char **argv)
&& action != ACTION_ASSERT_PRISTINE
&& p15card == NULL) {
/* Read the PKCS15 structure from the card */
r = sc_pkcs15_bind(card, &p15card);
r = sc_pkcs15_bind(card, NULL, &p15card);
if (r) {
fprintf(stderr,
"PKCS#15 binding failed: %s\n",

View File

@ -1724,7 +1724,7 @@ int main(int argc, char * const argv[])
if (verbose)
fprintf(stderr, "Trying to find a PKCS#15 compatible card...\n");
r = sc_pkcs15_bind(card, &p15card);
r = sc_pkcs15_bind(card, NULL, &p15card);
if (r) {
fprintf(stderr, "PKCS#15 binding failed: %s\n", sc_strerror(r));
err = 1;