scd: Fix duplicate output of KEYPAIRINFO by readkey command.

* scd/app-help.c (app_help_get_keygrip_string_pk): Make HEXKEYGRIP
parm optional.
* scd/command.c (do_readkey): Remove duplicate output of keypairinfo
lines.
--

Note that this change needs a fix in app-p15 which does not yet handle
the APP_READKEY_FLAG_INFO.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2021-04-08 19:27:25 +02:00
parent 36355394d8
commit 22fd48e48d
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 14 additions and 12 deletions

View File

@ -58,7 +58,8 @@ app_help_count_bits (const unsigned char *a, size_t len)
* there. The caller needs to call gcry_sexp_release on that. If * there. The caller needs to call gcry_sexp_release on that. If
* R_ALGO is not NULL the public key algorithm id of Libgcrypt is * R_ALGO is not NULL the public key algorithm id of Libgcrypt is
* stored there. If R_ALGOSTR is not NULL and the function succeeds a * stored there. If R_ALGOSTR is not NULL and the function succeeds a
* newly allocated algo string (e.g. "rsa2048") is stored there. */ * newly allocated algo string (e.g. "rsa2048") is stored there.
* HEXKEYGRIP may be NULL if the caller is not interested in it. */
gpg_error_t gpg_error_t
app_help_get_keygrip_string_pk (const void *pk, size_t pklen, char *hexkeygrip, app_help_get_keygrip_string_pk (const void *pk, size_t pklen, char *hexkeygrip,
gcry_sexp_t *r_pkey, int *r_algo, gcry_sexp_t *r_pkey, int *r_algo,
@ -77,7 +78,7 @@ app_help_get_keygrip_string_pk (const void *pk, size_t pklen, char *hexkeygrip,
if (err) if (err)
return err; /* Can't parse that S-expression. */ return err; /* Can't parse that S-expression. */
if (!gcry_pk_get_keygrip (s_pkey, array)) if (hexkeygrip && !gcry_pk_get_keygrip (s_pkey, array))
{ {
gcry_sexp_release (s_pkey); gcry_sexp_release (s_pkey);
return gpg_error (GPG_ERR_GENERAL); /* Failed to calculate the keygrip.*/ return gpg_error (GPG_ERR_GENERAL); /* Failed to calculate the keygrip.*/
@ -102,7 +103,8 @@ app_help_get_keygrip_string_pk (const void *pk, size_t pklen, char *hexkeygrip,
else else
gcry_sexp_release (s_pkey); gcry_sexp_release (s_pkey);
bin2hex (array, KEYGRIP_LEN, hexkeygrip); if (hexkeygrip)
bin2hex (array, KEYGRIP_LEN, hexkeygrip);
return 0; return 0;
} }

View File

@ -471,11 +471,11 @@ static const char hlp_learn[] =
"\n" "\n"
"For certain cards, more information will be returned:\n" "For certain cards, more information will be returned:\n"
"\n" "\n"
" S KEY-FPR <no> <hexstring>\n" " S KEY-FPR <keyref> <hexstring>\n"
"\n" "\n"
"For OpenPGP cards this returns the stored fingerprints of the\n" "For some cards this returns the stored fingerprints of the\n"
"keys. This can be used check whether a key is available on the\n" "keys. This can be used check whether a key is available on the\n"
"card. NO may be 1, 2 or 3.\n" "card. KEYREF may be 1, 2 or 3 for OpenPGP or a standard keyref.\n"
"\n" "\n"
" S CA-FPR <no> <hexstring>\n" " S CA-FPR <no> <hexstring>\n"
"\n" "\n"
@ -616,19 +616,19 @@ cmd_readcert (assuan_context_t ctx, char *line)
static gpg_error_t static gpg_error_t
do_readkey (card_t card, ctrl_t ctrl, const char *line, do_readkey (card_t card, ctrl_t ctrl, const char *line,
int opt_info, int opt_nokey, int opt_info, unsigned char **pk_p, size_t *pklen_p)
unsigned char **pk_p, size_t *pklen_p)
{ {
int rc; int rc;
int direct_readkey = 0;
/* If the application supports the READKEY function we use that. /* If the application supports the READKEY function we use that.
Otherwise we use the old way by extracting it from the Otherwise we use the old way by extracting it from the
certificate. */ certificate. */
rc = app_readkey (card, ctrl, line, rc = app_readkey (card, ctrl, line,
opt_info? APP_READKEY_FLAG_INFO : 0, opt_info? APP_READKEY_FLAG_INFO : 0,
opt_nokey? NULL : pk_p, pklen_p); pk_p, pklen_p);
if (!rc) if (!rc)
; /* Got the key. */ direct_readkey = 1; /* Got the key. */
else if (gpg_err_code (rc) == GPG_ERR_UNSUPPORTED_OPERATION else if (gpg_err_code (rc) == GPG_ERR_UNSUPPORTED_OPERATION
|| gpg_err_code (rc) == GPG_ERR_NOT_FOUND) || gpg_err_code (rc) == GPG_ERR_NOT_FOUND)
{ {
@ -651,7 +651,7 @@ do_readkey (card_t card, ctrl_t ctrl, const char *line,
else else
log_error ("app_readkey failed: %s\n", gpg_strerror (rc)); log_error ("app_readkey failed: %s\n", gpg_strerror (rc));
if (!rc && opt_info) if (!rc && opt_info && !direct_readkey)
{ {
char keygripstr[KEYGRIP_LEN*2+1]; char keygripstr[KEYGRIP_LEN*2+1];
char *algostr; char *algostr;
@ -730,7 +730,7 @@ cmd_readkey (assuan_context_t ctx, char *line)
if (direct) if (direct)
card_ref (card); card_ref (card);
rc = do_readkey (card, ctrl, line, opt_info, opt_nokey, &pk, &pklen); rc = do_readkey (card, ctrl, line, opt_info, &pk, &pklen);
if (direct) if (direct)
card_unref (card); card_unref (card);