pkcs15: new procedure to get application by it's symbolic name

At the moment symbolic names for the on-card applications are 'generic', 'protected'.
This distinction used by pkcs11 and minidriver module to select the
'master' application in the cases when only reduced number of slots (one)
can be exposed by module (minidriver) or particular configuration (pkcs11).
This commit is contained in:
Viktor Tarasov 2012-05-23 08:50:18 +02:00
parent 14049fb806
commit 80266ff466
3 changed files with 49 additions and 1 deletions

View File

@ -185,6 +185,7 @@ sc_pkcs15_free_prkey
sc_pkcs15_free_prkey_info
sc_pkcs15_free_pubkey
sc_pkcs15_free_pubkey_info
sc_pkcs15_get_application_by_type
sc_pkcs15_get_guid
sc_pkcs15_get_object_id
sc_pkcs15_get_objects

View File

@ -676,7 +676,7 @@ struct sc_app_info * sc_find_app(struct sc_card *card, struct sc_aid *aid)
if (!aid || !aid->len)
return card->app[0];
for (ii=0; ii < card->app_count; ii++) {
if (card->app[ii]->aid.len != aid->len)
continue;
@ -711,6 +711,50 @@ static struct sc_app_info *sc_dup_app_info(const struct sc_app_info *info)
return out;
}
struct sc_app_info *
sc_pkcs15_get_application_by_type(struct sc_card * card, char *app_type)
{
struct sc_app_info *out = NULL;
scconf_block *conf_block = NULL;
int i, rv;
if (!card)
return NULL;
if (card->app_count < 0) {
rv = sc_enum_apps(card);
if (rv < 0 && rv != SC_ERROR_FILE_NOT_FOUND)
return NULL;
}
conf_block = sc_get_conf_block(card->ctx, "framework", "pkcs15", 1);
if (!conf_block)
return NULL;
for (i = 0; i < card->app_count; i++) {
struct sc_app_info *app_info = card->app[i];
scconf_block **blocks = NULL;
char str_path[SC_MAX_AID_STRING_SIZE];
sc_bin_to_hex(app_info->aid.value, app_info->aid.len, str_path, sizeof(str_path), 0);
blocks = scconf_find_blocks(card->ctx->conf, conf_block, "application", str_path);
if (blocks) {
if (blocks[0]) {
char *type = (char *)scconf_get_str(blocks[0], "type", app_type);
if (!strcmp(type, app_type)) {
out = app_info;
break;
}
}
free(blocks);
}
}
return out;
}
static int sc_pkcs15_bind_internal(sc_pkcs15_card_t *p15card, struct sc_aid *aid)
{
sc_path_t tmppath;

View File

@ -805,6 +805,9 @@ int sc_pkcs15_get_guid(struct sc_pkcs15_card *, const struct sc_pkcs15_object *,
int sc_encode_oid (struct sc_context *, struct sc_object_id *,
unsigned char **, size_t *);
/* Get application by type: 'protected', 'generic' */
struct sc_app_info *sc_pkcs15_get_application_by_type(struct sc_card *, char *);
/* Prepend 'parent' to 'child' in case 'child' is a relative path */
int sc_pkcs15_make_absolute_path(const sc_path_t *parent, sc_path_t *child);