diff options
author | Werner Koch <[email protected]> | 2015-08-06 16:00:12 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2015-08-06 16:00:12 +0000 |
commit | fbb6c25ab5dbb5f2b1f1eb342ca7caa3f955d8c9 (patch) | |
tree | cb9f74fa31f3d265d1d6318e098e4a4c43aa1bf4 | |
parent | gpg: Adjust UID line indentation for common key algos. (diff) | |
download | gnupg-fbb6c25ab5dbb5f2b1f1eb342ca7caa3f955d8c9.tar.gz gnupg-fbb6c25ab5dbb5f2b1f1eb342ca7caa3f955d8c9.zip |
gpg: Add commands "fpr *" and "grip" to --edit-key.
* g10/keyedit.c (cmdGRIP): New.
(cmds): Add command "grip".
(keyedit_menu) <cmdFPR>: Print subkeys with argument "*".
(keyedit_menu) <cmdGRIP>: Print keygrip.
(show_key_and_fingerprint): Add arg "with_subkeys".
(show_key_and_grip): New.
* g10/keylist.c (print_fingerprint): Add mode 4.
--
Signed-off-by: Werner Koch <[email protected]>
-rw-r--r-- | g10/keyedit.c | 69 | ||||
-rw-r--r-- | g10/keylist.c | 8 |
2 files changed, 71 insertions, 6 deletions
diff --git a/g10/keyedit.c b/g10/keyedit.c index 6238b3085..d8dba2d73 100644 --- a/g10/keyedit.c +++ b/g10/keyedit.c @@ -56,7 +56,8 @@ static void show_key_with_all_names (ctrl_t ctrl, estream_t fp, int with_revoker, int with_fpr, int with_subkeys, int with_prefs, int nowarn); -static void show_key_and_fingerprint (KBNODE keyblock); +static void show_key_and_fingerprint (kbnode_t keyblock, int with_subkeys); +static void show_key_and_grip (kbnode_t keyblock); static void subkey_expire_warning (kbnode_t keyblock); static int menu_adduid (KBNODE keyblock, int photo, const char *photo_name, const char *uidstr); @@ -1305,7 +1306,7 @@ enum cmdids cmdSHOWPREF, cmdSETPREF, cmdPREFKS, cmdNOTATION, cmdINVCMD, cmdSHOWPHOTO, cmdUPDTRUST, cmdCHKTRUST, cmdADDCARDKEY, cmdKEYTOCARD, cmdBKUPTOCARD, cmdCHECKBKUPKEY, - cmdCLEAN, cmdMINIMIZE, cmdNOP + cmdCLEAN, cmdMINIMIZE, cmdGRIP, cmdNOP }; static struct @@ -1322,6 +1323,7 @@ static struct { "help", cmdHELP, 0, N_("show this help")}, { "?", cmdHELP, 0, NULL}, { "fpr", cmdFPR, 0, N_("show key fingerprint")}, + { "grip", cmdGRIP, 0, N_("show the keygrip")}, { "list", cmdLIST, 0, N_("list key and user IDs")}, { "l", cmdLIST, 0, NULL}, { "uid", cmdSELUID, 0, N_("select user ID N")}, @@ -1644,7 +1646,13 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr, break; case cmdFPR: - show_key_and_fingerprint (keyblock); + show_key_and_fingerprint + (keyblock, (*arg_string == '*' + && (!arg_string[1] || spacep (arg_string + 1)))); + break; + + case cmdGRIP: + show_key_and_grip (keyblock); break; case cmdSELUID: @@ -3235,10 +3243,11 @@ show_basic_key_info (KBNODE keyblock) } } + static void -show_key_and_fingerprint (KBNODE keyblock) +show_key_and_fingerprint (kbnode_t keyblock, int with_subkeys) { - KBNODE node; + kbnode_t node; PKT_public_key *pk = NULL; char pkstrbuf[PUBKEY_STRING_SIZE]; @@ -3262,6 +3271,56 @@ show_key_and_fingerprint (KBNODE keyblock) tty_printf ("\n"); if (pk) print_fingerprint (NULL, pk, 2); + if (with_subkeys) + { + for (node = keyblock; node; node = node->next) + { + if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY) + { + pk = node->pkt->pkt.public_key; + tty_printf ("sub %s/%s %s [%s]\n", + pubkey_string (pk, pkstrbuf, sizeof pkstrbuf), + keystr_from_pk(pk), + datestr_from_pk (pk), + usagestr_from_pk (pk, 0)); + + print_fingerprint (NULL, pk, 4); + } + } + } +} + + +/* Show a listing of the primary and its subkeys along with their + keygrips. */ +static void +show_key_and_grip (kbnode_t keyblock) +{ + kbnode_t node; + PKT_public_key *pk = NULL; + char pkstrbuf[PUBKEY_STRING_SIZE]; + char *hexgrip; + + for (node = keyblock; node; node = node->next) + { + if (node->pkt->pkttype == PKT_PUBLIC_KEY + || node->pkt->pkttype == PKT_PUBLIC_SUBKEY) + { + pk = node->pkt->pkt.public_key; + tty_printf ("%s %s/%s %s [%s]\n", + node->pkt->pkttype == PKT_PUBLIC_KEY? "pub":"sub", + pubkey_string (pk, pkstrbuf, sizeof pkstrbuf), + keystr_from_pk(pk), + datestr_from_pk (pk), + usagestr_from_pk (pk, 0)); + + if (!hexkeygrip_from_pk (pk, &hexgrip)) + { + tty_printf (" Keygrip: %s\n", hexgrip); + xfree (hexgrip); + } + } + } } diff --git a/g10/keylist.c b/g10/keylist.c index 0f4c85ae0..4ea4bf5c5 100644 --- a/g10/keylist.c +++ b/g10/keylist.c @@ -1726,6 +1726,7 @@ print_icao_hexdigit (estream_t fp, int c) * 1: print using log_info () * 2: direct use of tty * 3: direct use of tty but only primary key. + * 4: direct use of tty but only subkey. * 10: Same as 0 but with_colons etc is ignored. * * Modes 1 and 2 will try and print both subkey and primary key @@ -1784,7 +1785,7 @@ print_fingerprint (estream_t override_fp, PKT_public_key *pk, int mode) { fp = override_fp; /* Use tty or given stream. */ if (primary) - /* TRANSLATORS: this should fit into 24 bytes to that the + /* TRANSLATORS: this should fit into 24 bytes so that the * fingerprint data is properly aligned with the user ID */ text = _(" Primary key fingerprint:"); else @@ -1795,6 +1796,11 @@ print_fingerprint (estream_t override_fp, PKT_public_key *pk, int mode) fp = override_fp; /* Use tty or given stream. */ text = _(" Key fingerprint ="); } + else if (mode == 4) + { + fp = override_fp; /* Use tty or given stream. */ + text = _(" Subkey fingerprint:"); + } else { fp = override_fp? override_fp : es_stdout; |