diff options
Diffstat (limited to 'scard-opensc.c')
-rw-r--r-- | scard-opensc.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/scard-opensc.c b/scard-opensc.c index 9766d46cc..e8e12dd85 100644 --- a/scard-opensc.c +++ b/scard-opensc.c | |||
@@ -474,4 +474,30 @@ sc_put_key(Key *prv, const char *id) | |||
474 | return -1; | 474 | return -1; |
475 | } | 475 | } |
476 | 476 | ||
477 | char * | ||
478 | sc_get_key_label(Key *key) | ||
479 | { | ||
480 | int r; | ||
481 | const struct sc_priv_data *priv; | ||
482 | struct sc_pkcs15_object *key_obj; | ||
483 | |||
484 | priv = (const struct sc_priv_data *) RSA_get_app_data(key->rsa); | ||
485 | if (priv == NULL || p15card == NULL) { | ||
486 | logit("SmartCard key not loaded"); | ||
487 | /* internal error => return default label */ | ||
488 | return xstrdup("smartcard key"); | ||
489 | } | ||
490 | r = sc_pkcs15_find_prkey_by_id(p15card, &priv->cert_id, &key_obj); | ||
491 | if (r) { | ||
492 | logit("Unable to find private key from SmartCard: %s", | ||
493 | sc_strerror(r)); | ||
494 | return xstrdup("smartcard key"); | ||
495 | } | ||
496 | if (key_obj == NULL || key_obj->label == NULL) | ||
497 | /* the optional PKCS#15 label does not exists | ||
498 | * => return the default label */ | ||
499 | return xstrdup("smartcard key"); | ||
500 | return xstrdup(key_obj->label); | ||
501 | } | ||
502 | |||
477 | #endif /* SMARTCARD */ | 503 | #endif /* SMARTCARD */ |