1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-04-11 22:01:08 +02:00

scd:nks: Return USAGE information for KEYINFO command.

* scd/app-nks.c (set_usage_string): New.
(do_learn_status_core, do_readkey): Use set_usage_string.
(do_with_keygrip): Add USAGE to call send_keyinfo,
using set_usage_string.
* scd/command.c (send_keyinfo): Add arg usage.
--

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Backported-from-master: 5264d3f58e8a8362900c3518bdd683ff9a23cccc
GnuPG-bug-id: 6252

This backports only the NKS parts of the original patch

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
NIIBE Yutaka 2022-05-26 12:01:16 +09:00 committed by Werner Koch
parent 77b008d1e7
commit b199582789
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
4 changed files with 26 additions and 25 deletions

View File

@ -814,6 +814,21 @@ get_nks_tag (app_t app, int nks_app_id)
return tag; return tag;
} }
static void
set_usage_string (char usagebuf[5], int i)
{
int usageidx = 0;
if (filelist[i].issignkey)
usagebuf[usageidx++] = 's';
if (filelist[i].isauthkey)
usagebuf[usageidx++] = 'a';
if (filelist[i].isencrkey)
usagebuf[usageidx++] = 'e';
if (!usageidx)
usagebuf[usageidx++] = '-';
usagebuf[usageidx] = 0;
}
static void static void
do_learn_status_core (app_t app, ctrl_t ctrl, unsigned int flags, do_learn_status_core (app_t app, ctrl_t ctrl, unsigned int flags,
int nks_app_id) int nks_app_id)
@ -856,7 +871,6 @@ do_learn_status_core (app_t app, ctrl_t ctrl, unsigned int flags,
{ {
char gripstr[40+1]; char gripstr[40+1];
char usagebuf[5]; char usagebuf[5];
int usageidx = 0;
char *algostr = NULL; char *algostr = NULL;
err = keygripstr_from_pk_file (app, filelist[i].fid, err = keygripstr_from_pk_file (app, filelist[i].fid,
@ -869,15 +883,7 @@ do_learn_status_core (app_t app, ctrl_t ctrl, unsigned int flags,
{ {
snprintf (id_buf, sizeof id_buf, "NKS-%s.%04X", snprintf (id_buf, sizeof id_buf, "NKS-%s.%04X",
tag, filelist[i].fid); tag, filelist[i].fid);
if (filelist[i].issignkey) set_usage_string (usagebuf, i);
usagebuf[usageidx++] = 's';
if (filelist[i].isauthkey)
usagebuf[usageidx++] = 'a';
if (filelist[i].isencrkey)
usagebuf[usageidx++] = 'e';
if (!usageidx)
usagebuf[usageidx++] = '-';
usagebuf[usageidx] = 0;
send_status_info (ctrl, "KEYPAIRINFO", send_status_info (ctrl, "KEYPAIRINFO",
gripstr, 40, gripstr, 40,
id_buf, strlen (id_buf), id_buf, strlen (id_buf),
@ -1285,7 +1291,6 @@ do_readkey (app_t app, ctrl_t ctrl, const char *keyid, unsigned int flags,
{ {
char *algostr; char *algostr;
char usagebuf[5]; char usagebuf[5];
int usageidx = 0;
char id_buf[100]; char id_buf[100];
if (app_help_get_keygrip_string_pk (*pk, *pklen, NULL, NULL, NULL, if (app_help_get_keygrip_string_pk (*pk, *pklen, NULL, NULL, NULL,
@ -1295,15 +1300,7 @@ do_readkey (app_t app, ctrl_t ctrl, const char *keyid, unsigned int flags,
snprintf (id_buf, sizeof id_buf, "NKS-%s.%04X", snprintf (id_buf, sizeof id_buf, "NKS-%s.%04X",
get_nks_tag (app, filelist[i].nks_app_id), get_nks_tag (app, filelist[i].nks_app_id),
filelist[i].fid); filelist[i].fid);
if (filelist[i].issignkey) set_usage_string (usagebuf, i);
usagebuf[usageidx++] = 's';
if (filelist[i].isauthkey)
usagebuf[usageidx++] = 'a';
if (filelist[i].isencrkey)
usagebuf[usageidx++] = 'e';
if (!usageidx)
usagebuf[usageidx++] = '-';
usagebuf[usageidx] = 0;
send_status_info (ctrl, "KEYPAIRINFO", send_status_info (ctrl, "KEYPAIRINFO",
keygripstr, strlen (keygripstr), keygripstr, strlen (keygripstr),
id_buf, strlen (id_buf), id_buf, strlen (id_buf),
@ -2337,6 +2334,7 @@ do_with_keygrip (app_t app, ctrl_t ctrl, int action,
{ {
char idbuf[20]; char idbuf[20];
const char *tagstr; const char *tagstr;
char usagebuf[5];
if (app->app_local->active_nks_app == NKS_APP_ESIGN) if (app->app_local->active_nks_app == NKS_APP_ESIGN)
tagstr = "ESIGN"; tagstr = "ESIGN";
@ -2351,7 +2349,8 @@ do_with_keygrip (app_t app, ctrl_t ctrl, int action,
snprintf (idbuf, sizeof idbuf, "NKS-%s.%04X", snprintf (idbuf, sizeof idbuf, "NKS-%s.%04X",
tagstr, filelist[idx].fid); tagstr, filelist[idx].fid);
send_keyinfo (ctrl, data, keygripstr, serialno, idbuf); set_usage_string (usagebuf, idx);
send_keyinfo (ctrl, data, keygripstr, serialno, idbuf, usagebuf);
} }
} }

View File

@ -6030,7 +6030,7 @@ do_with_keygrip (app_t app, ctrl_t ctrl, int action,
goto leave; goto leave;
} }
send_keyinfo (ctrl, as_data, prkdf->keygrip, serialno, keyref); send_keyinfo (ctrl, as_data, prkdf->keygrip, serialno, keyref, NULL);
xfree (keyref); xfree (keyref);
if (want_keygripstr) if (want_keygripstr)
{ {

View File

@ -1903,14 +1903,15 @@ scd_command_handler (ctrl_t ctrl, int fd)
* data line, else as a status line. */ * data line, else as a status line. */
void void
send_keyinfo (ctrl_t ctrl, int data, const char *keygrip_str, send_keyinfo (ctrl_t ctrl, int data, const char *keygrip_str,
const char *serialno, const char *idstr) const char *serialno, const char *idstr, const char *usage)
{ {
char *string; char *string;
assuan_context_t ctx = ctrl->server_local->assuan_ctx; assuan_context_t ctx = ctrl->server_local->assuan_ctx;
string = xtryasprintf ("%s T %s %s%s", keygrip_str, string = xtryasprintf ("%s T %s %s %s%s", keygrip_str,
serialno? serialno : "-", serialno? serialno : "-",
idstr? idstr : "-", idstr? idstr : "-",
usage? usage : "-",
data? "\n" : ""); data? "\n" : "");
if (!string) if (!string)

View File

@ -126,7 +126,8 @@ const char *scd_get_socket_name (void);
gpg_error_t initialize_module_command (void); gpg_error_t initialize_module_command (void);
int scd_command_handler (ctrl_t, int); int scd_command_handler (ctrl_t, int);
void send_keyinfo (ctrl_t ctrl, int data, const char *keygrip_str, void send_keyinfo (ctrl_t ctrl, int data, const char *keygrip_str,
const char *serialno, const char *idstr); const char *serialno, const char *idstr,
const char *usage);
void send_status_info (ctrl_t ctrl, const char *keyword, ...) void send_status_info (ctrl_t ctrl, const char *keyword, ...)
GPGRT_ATTR_SENTINEL(1); GPGRT_ATTR_SENTINEL(1);
gpg_error_t send_status_direct (ctrl_t ctrl, const char *keyword, gpg_error_t send_status_direct (ctrl_t ctrl, const char *keyword,