gpg: During secret key import print "sec" instead of "pub".

* g10/keyedit.c (show_basic_key_info): New arg 'print_sec'.  Remove
useless code for "sub" and "ssb".
* g10/import.c (import_one): Pass FROM_SK to show_basic_key_info.  Do
not print the first  keyinfo in FROM_SK mode.
printing.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2019-03-15 19:11:32 +01:00
parent f06b6fe47f
commit f64477db86
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
4 changed files with 25 additions and 16 deletions

View File

@ -3075,10 +3075,11 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
} }
void void
show_basic_key_info (ctrl_t ctrl, KBNODE keyblock) show_basic_key_info (ctrl_t ctrl, KBNODE keyblock, int made_from_sec)
{ {
(void)ctrl; (void)ctrl;
(void) keyblock; (void)keyblock;
(void)made_from_sec;
} }
int int

View File

@ -1666,7 +1666,8 @@ update_key_origin (kbnode_t keyblock, u32 curtime, int origin, const char *url)
* the internal errorcount, so that invalid input can be detected by * the internal errorcount, so that invalid input can be detected by
* programs which called gpg. If SILENT is no messages are printed - * programs which called gpg. If SILENT is no messages are printed -
* even most error messages are suppressed. ORIGIN is the origin of * even most error messages are suppressed. ORIGIN is the origin of
* the key (0 for unknown) and URL the corresponding URL. * the key (0 for unknown) and URL the corresponding URL. FROM_SK
* indicates that the key has been made from a secret key.
*/ */
static gpg_error_t static gpg_error_t
import_one (ctrl_t ctrl, import_one (ctrl_t ctrl,
@ -1710,9 +1711,11 @@ import_one (ctrl_t ctrl,
keyid_from_pk( pk, keyid ); keyid_from_pk( pk, keyid );
uidnode = find_next_kbnode( keyblock, PKT_USER_ID ); uidnode = find_next_kbnode( keyblock, PKT_USER_ID );
if (opt.verbose && !opt.interactive && !silent) if (opt.verbose && !opt.interactive && !silent && !from_sk)
{ {
log_info( "pub %s/%s %s ", /* Note that we do not print this info in FROM_SK mode
* because import_one already printed that. */
log_info ("pub %s/%s %s ",
pubkey_string (pk, pkstrbuf, sizeof pkstrbuf), pubkey_string (pk, pkstrbuf, sizeof pkstrbuf),
keystr_from_pk(pk), datestr_from_pk(pk) ); keystr_from_pk(pk), datestr_from_pk(pk) );
if (uidnode) if (uidnode)
@ -1745,7 +1748,7 @@ import_one (ctrl_t ctrl,
print_import_check (pk, uidnode->pkt->pkt.user_id); print_import_check (pk, uidnode->pkt->pkt.user_id);
merge_keys_and_selfsig (ctrl, keyblock); merge_keys_and_selfsig (ctrl, keyblock);
tty_printf ("\n"); tty_printf ("\n");
show_basic_key_info (ctrl, keyblock); show_basic_key_info (ctrl, keyblock, from_sk);
tty_printf ("\n"); tty_printf ("\n");
if (!cpr_get_answer_is_yes ("import.okay", if (!cpr_get_answer_is_yes ("import.okay",
"Do you want to import this key? (y/N) ")) "Do you want to import this key? (y/N) "))

View File

@ -3677,13 +3677,14 @@ show_key_with_all_names (ctrl_t ctrl, estream_t fp,
/* Display basic key information. This function is suitable to show /* Display basic key information. This function is suitable to show
information on the key without any dependencies on the trustdb or * information on the key without any dependencies on the trustdb or
any other internal GnuPG stuff. KEYBLOCK may either be a public or * any other internal GnuPG stuff. KEYBLOCK may either be a public or
a secret key. This function may be called with KEYBLOCK containing * a secret key. This function may be called with KEYBLOCK containing
secret keys and thus the printing of "pub" vs. "sec" does only * secret keys and thus the printing of "pub" vs. "sec" does only
depend on the packet type and not by checking with gpg-agent. */ * depend on the packet type and not by checking with gpg-agent. If
* PRINT_SEC ist set "sec" is printed instead of "pub". */
void void
show_basic_key_info (ctrl_t ctrl, kbnode_t keyblock) show_basic_key_info (ctrl_t ctrl, kbnode_t keyblock, int print_sec)
{ {
KBNODE node; KBNODE node;
int i; int i;
@ -3696,13 +3697,17 @@ show_basic_key_info (ctrl_t ctrl, kbnode_t keyblock)
|| node->pkt->pkttype == PKT_SECRET_KEY) || node->pkt->pkttype == PKT_SECRET_KEY)
{ {
PKT_public_key *pk = node->pkt->pkt.public_key; PKT_public_key *pk = node->pkt->pkt.public_key;
const char *tag;
if (node->pkt->pkttype == PKT_SECRET_KEY || print_sec)
tag = "sec";
else
tag = "pub";
/* Note, we use the same format string as in other show /* Note, we use the same format string as in other show
functions to make the translation job easier. */ functions to make the translation job easier. */
tty_printf ("%s %s/%s ", tty_printf ("%s %s/%s ",
node->pkt->pkttype == PKT_PUBLIC_KEY ? "pub" : tag,
node->pkt->pkttype == PKT_PUBLIC_SUBKEY ? "sub" :
node->pkt->pkttype == PKT_SECRET_KEY ? "sec" :"ssb",
pubkey_string (pk, pkstrbuf, sizeof pkstrbuf), pubkey_string (pk, pkstrbuf, sizeof pkstrbuf),
keystr_from_pk (pk)); keystr_from_pk (pk));
tty_printf (_("created: %s"), datestr_from_pk (pk)); tty_printf (_("created: %s"), datestr_from_pk (pk));

View File

@ -50,7 +50,7 @@ void keyedit_quick_set_expire (ctrl_t ctrl,
char **subkeyfprs); char **subkeyfprs);
void keyedit_quick_set_primary (ctrl_t ctrl, const char *username, void keyedit_quick_set_primary (ctrl_t ctrl, const char *username,
const char *primaryuid); const char *primaryuid);
void show_basic_key_info (ctrl_t ctrl, kbnode_t keyblock); void show_basic_key_info (ctrl_t ctrl, kbnode_t keyblock, int print_sec);
int keyedit_print_one_sig (ctrl_t ctrl, estream_t fp, int keyedit_print_one_sig (ctrl_t ctrl, estream_t fp,
int rc, kbnode_t keyblock, int rc, kbnode_t keyblock,
kbnode_t node, int *inv_sigs, int *no_key, kbnode_t node, int *inv_sigs, int *no_key,