agent: New field "Prompt" to prevent asking card key insertion.

* agent/findkey.c (prompt_for_card): Add "Prompt" field handling.

--

GnuPG-bug-id: 5987
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2022-05-27 09:59:54 +09:00
parent d86b6c28fc
commit 9f1dcfc7a7
1 changed files with 21 additions and 4 deletions

View File

@ -976,14 +976,25 @@ prompt_for_card (ctrl_t ctrl, const unsigned char *grip,
char hexgrip[41];
char *comment_buffer = NULL;
const char *comment = NULL;
int refuse_prompt = 0;
bin2hex (grip, 20, hexgrip);
if (keymeta && (comment = nvc_get_string (keymeta, "Label:")))
if (keymeta)
{
if (strchr (comment, '\n')
&& (comment_buffer = linefeed_to_percent0A (comment)))
comment = comment_buffer;
const char *p;
if ((p = nvc_get_string (keymeta, "Prompt:")) && !strcmp (p, "no"))
refuse_prompt = 1;
if ((p = nvc_get_string (keymeta, "Label:")))
{
if (strchr (p, '\n')
&& (comment_buffer = linefeed_to_percent0A (p)))
comment = comment_buffer;
else
comment = p;
}
}
err = parse_shadow_info (shadow_info, &want_sn, NULL, NULL);
@ -1042,6 +1053,12 @@ prompt_for_card (ctrl_t ctrl, const unsigned char *grip,
}
/* Card is not available. Prompt the insertion. */
if (refuse_prompt)
{
err = gpg_error (GPG_ERR_UNUSABLE_SECKEY);
break;
}
if (asprintf (&desc,
"%s:%%0A%%0A"
" %s%%0A"