diff options
author | Werner Koch <wk@gnupg.org> | 2021-03-30 17:25:24 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2021-03-30 17:25:24 +0200 |
commit | 7f9126363265a6b6fe4223d68fc4e87678c4ddfc (patch) | |
tree | e2c2fa8cebe759c8d180075d10a001ca7122c9d4 /scd/app-p15.c | |
parent | scd:p15: For CardOS make use of ISO7816_VERIFY_NOT_NEEDED. (diff) | |
download | gnupg2-7f9126363265a6b6fe4223d68fc4e87678c4ddfc.tar.xz gnupg2-7f9126363265a6b6fe4223d68fc4e87678c4ddfc.zip |
scd:p15: Return labels for keys and certificates.
* scd/app-p15.c (send_certinfo): Extend certinfo.
(do_getattr): Support KEY-LABEL.
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'scd/app-p15.c')
-rw-r--r-- | scd/app-p15.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/scd/app-p15.c b/scd/app-p15.c index c243d6afa..47a79d7ee 100644 --- a/scd/app-p15.c +++ b/scd/app-p15.c @@ -3709,6 +3709,8 @@ send_certinfo (app_t app, ctrl_t ctrl, const char *certtype, for (; certinfo; certinfo = certinfo->next) { char *buf, *p; + const char *label; + char *labelbuf; buf = xtrymalloc (9 + certinfo->objidlen*2 + 1); if (!buf) @@ -3723,9 +3725,18 @@ send_certinfo (app_t app, ctrl_t ctrl, const char *certtype, p = stpcpy (p, "."); bin2hex (certinfo->objid, certinfo->objidlen, p); + label = (certinfo->label && *certinfo->label)? certinfo->label : "-"; + labelbuf = percent_data_escape (0, NULL, label, strlen (label)); + if (!labelbuf) + { + xfree (buf); + return gpg_error_from_syserror (); + } + send_status_info (ctrl, "CERTINFO", certtype, strlen (certtype), buf, strlen (buf), + labelbuf, strlen (labelbuf), NULL, (size_t)0); xfree (buf); } @@ -4414,6 +4425,37 @@ do_getattr (app_t app, ctrl_t ctrl, const char *name) xfree (p); return err; } + else if (!strcmp (name, "KEY-LABEL")) + { + /* Send KEY-LABEL lines for all private key objects. */ + const char *label; + char *idbuf, *labelbuf; + + for (prkdf = app->app_local->private_key_info; prkdf; + prkdf = prkdf->next) + { + idbuf = keyref_from_prkdf (app, prkdf); + if (!idbuf) + return gpg_error_from_syserror (); + + label = (prkdf->label && *prkdf->label)? prkdf->label : "-"; + labelbuf = percent_data_escape (0, NULL, label, strlen (label)); + if (!labelbuf) + { + xfree (idbuf); + return gpg_error_from_syserror (); + } + + send_status_info (ctrl, name, + idbuf, strlen (idbuf), + labelbuf, strlen(labelbuf), + NULL, 0); + xfree (idbuf); + xfree (labelbuf); + } + return 0; + } + return gpg_error (GPG_ERR_INV_NAME); } |