mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
gpg: Improve 'General key info' line of --card-status.
* g10/keylist.c (print_pubkey_info): Print either "pub" or "sub". * g10/getkey.c (get_pubkey_byfprint): Add optional arg R_KEYBLOCK. * g10/keyid.c (keyid_from_fingerprint): Adjust for change. * g10/revoke.c (gen_desig_revoke): Adjust for change. * g10/card-util.c (card_status): Simplify by using new arg. Align card-no string. * g10/card-util.c (card_status): Remove not used GnuPG-1 code. -- This now prints "sub" if the first used card key is actually a subkey. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
173b26c8f8
commit
874ef16e70
@ -366,6 +366,7 @@ card_status (estream_t fp, char *serialno, size_t serialnobuflen)
|
|||||||
{
|
{
|
||||||
struct agent_card_info_s info;
|
struct agent_card_info_s info;
|
||||||
PKT_public_key *pk = xcalloc (1, sizeof *pk);
|
PKT_public_key *pk = xcalloc (1, sizeof *pk);
|
||||||
|
kbnode_t keyblock = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
unsigned int uval;
|
unsigned int uval;
|
||||||
const unsigned char *thefpr;
|
const unsigned char *thefpr;
|
||||||
@ -587,41 +588,17 @@ card_status (estream_t fp, char *serialno, size_t serialnobuflen)
|
|||||||
/* If the fingerprint is all 0xff, the key has no asssociated
|
/* If the fingerprint is all 0xff, the key has no asssociated
|
||||||
OpenPGP certificate. */
|
OpenPGP certificate. */
|
||||||
if ( thefpr && !fpr_is_ff (thefpr)
|
if ( thefpr && !fpr_is_ff (thefpr)
|
||||||
&& !get_pubkey_byfprint (pk, thefpr, 20))
|
&& !get_pubkey_byfprint (pk, &keyblock, thefpr, 20))
|
||||||
{
|
{
|
||||||
kbnode_t keyblock = NULL;
|
|
||||||
|
|
||||||
print_pubkey_info (fp, pk);
|
print_pubkey_info (fp, pk);
|
||||||
|
if (keyblock)
|
||||||
#if GNUPG_MAJOR_VERSION == 1
|
|
||||||
if ( !get_seckeyblock_byfprint (&keyblock, thefpr, 20) )
|
|
||||||
print_card_key_info (fp, keyblock);
|
print_card_key_info (fp, keyblock);
|
||||||
else if ( !get_keyblock_byfprint (&keyblock, thefpr, 20) )
|
|
||||||
{
|
|
||||||
release_kbnode (keyblock);
|
|
||||||
keyblock = NULL;
|
|
||||||
|
|
||||||
if (!auto_create_card_key_stub (info.serialno,
|
|
||||||
info.fpr1valid? info.fpr1:NULL,
|
|
||||||
info.fpr2valid? info.fpr2:NULL,
|
|
||||||
info.fpr3valid? info.fpr3:NULL))
|
|
||||||
{
|
|
||||||
if ( !get_seckeyblock_byfprint (&keyblock, thefpr, 20) )
|
|
||||||
print_card_key_info (fp, keyblock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#else /* GNUPG_MAJOR_VERSION != 1 */
|
|
||||||
if (!get_keyblock_byfprint (&keyblock, thefpr, 20))
|
|
||||||
print_card_key_info (fp, keyblock);
|
|
||||||
#endif /* GNUPG_MAJOR_VERSION != 1 */
|
|
||||||
|
|
||||||
release_kbnode (keyblock);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
tty_fprintf (fp, "[none]\n");
|
tty_fprintf (fp, "[none]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
release_kbnode (keyblock);
|
||||||
free_public_key (pk);
|
free_public_key (pk);
|
||||||
agent_release_card_info (&info);
|
agent_release_card_info (&info);
|
||||||
}
|
}
|
||||||
|
22
g10/getkey.c
22
g10/getkey.c
@ -968,17 +968,26 @@ get_pubkey_byfpr (PKT_public_key *pk, const byte *fpr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Search for a key with the given fingerprint.
|
/* Search for a key with the given fingerprint. The caller need to
|
||||||
|
* prove an allocated public key object at PK. If R_KEYBLOCK is not
|
||||||
|
* NULL the entire keyblock is stored there and the caller needs to
|
||||||
|
* call release_kbnode() on it. Note that this function does an exact
|
||||||
|
* search and thus the public key stored at PK may be a copy of a
|
||||||
|
* subkey.
|
||||||
|
*
|
||||||
* FIXME:
|
* FIXME:
|
||||||
* We should replace this with the _byname function. This can be done
|
* We should replace this with the _byname function. This can be done
|
||||||
* by creating a userID conforming to the unified fingerprint style.
|
* by creating a userID conforming to the unified fingerprint style.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
get_pubkey_byfprint (PKT_public_key * pk,
|
get_pubkey_byfprint (PKT_public_key *pk, kbnode_t *r_keyblock,
|
||||||
const byte * fprint, size_t fprint_len)
|
const byte * fprint, size_t fprint_len)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
if (r_keyblock)
|
||||||
|
*r_keyblock = NULL;
|
||||||
|
|
||||||
if (fprint_len == 20 || fprint_len == 16)
|
if (fprint_len == 20 || fprint_len == 16)
|
||||||
{
|
{
|
||||||
struct getkey_ctx_s ctx;
|
struct getkey_ctx_s ctx;
|
||||||
@ -994,7 +1003,14 @@ get_pubkey_byfprint (PKT_public_key * pk,
|
|||||||
memcpy (ctx.items[0].u.fpr, fprint, fprint_len);
|
memcpy (ctx.items[0].u.fpr, fprint, fprint_len);
|
||||||
rc = lookup (&ctx, &kb, 0);
|
rc = lookup (&ctx, &kb, 0);
|
||||||
if (!rc && pk)
|
if (!rc && pk)
|
||||||
pk_from_block (&ctx, pk, kb);
|
{
|
||||||
|
pk_from_block (&ctx, pk, kb);
|
||||||
|
if (r_keyblock)
|
||||||
|
{
|
||||||
|
*r_keyblock = kb;
|
||||||
|
kb = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
release_kbnode (kb);
|
release_kbnode (kb);
|
||||||
get_pubkey_end (&ctx);
|
get_pubkey_end (&ctx);
|
||||||
}
|
}
|
||||||
|
@ -223,8 +223,8 @@ int get_pubkey_next( GETKEY_CTX ctx, PKT_public_key *pk, KBNODE *ret_keyblock );
|
|||||||
void get_pubkey_end( GETKEY_CTX ctx );
|
void get_pubkey_end( GETKEY_CTX ctx );
|
||||||
gpg_error_t get_seckey (PKT_public_key *pk, u32 *keyid);
|
gpg_error_t get_seckey (PKT_public_key *pk, u32 *keyid);
|
||||||
gpg_error_t get_pubkey_byfpr (PKT_public_key *pk, const byte *fpr);
|
gpg_error_t get_pubkey_byfpr (PKT_public_key *pk, const byte *fpr);
|
||||||
int get_pubkey_byfprint( PKT_public_key *pk, const byte *fprint,
|
int get_pubkey_byfprint (PKT_public_key *pk, kbnode_t *r_keyblock,
|
||||||
size_t fprint_len );
|
const byte *fprint, size_t fprint_len);
|
||||||
int get_pubkey_byfprint_fast (PKT_public_key *pk,
|
int get_pubkey_byfprint_fast (PKT_public_key *pk,
|
||||||
const byte *fprint, size_t fprint_len);
|
const byte *fprint, size_t fprint_len);
|
||||||
int get_keyblock_byfprint( KBNODE *ret_keyblock, const byte *fprint,
|
int get_keyblock_byfprint( KBNODE *ret_keyblock, const byte *fprint,
|
||||||
|
@ -463,7 +463,7 @@ keyid_from_fingerprint( const byte *fprint, size_t fprint_len, u32 *keyid )
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
memset (&pk, 0, sizeof pk);
|
memset (&pk, 0, sizeof pk);
|
||||||
rc = get_pubkey_byfprint (&pk, fprint, fprint_len);
|
rc = get_pubkey_byfprint (&pk, NULL, fprint, fprint_len);
|
||||||
if( rc )
|
if( rc )
|
||||||
{
|
{
|
||||||
log_error("Oops: keyid_from_fingerprint: no pubkey\n");
|
log_error("Oops: keyid_from_fingerprint: no pubkey\n");
|
||||||
|
@ -170,7 +170,7 @@ print_seckey_info (PKT_public_key *pk)
|
|||||||
the tty output interface is used, otherwise output is directted to
|
the tty output interface is used, otherwise output is directted to
|
||||||
the given stream. */
|
the given stream. */
|
||||||
void
|
void
|
||||||
print_pubkey_info (estream_t fp, PKT_public_key * pk)
|
print_pubkey_info (estream_t fp, PKT_public_key *pk)
|
||||||
{
|
{
|
||||||
u32 keyid[2];
|
u32 keyid[2];
|
||||||
char *p;
|
char *p;
|
||||||
@ -187,7 +187,8 @@ print_pubkey_info (estream_t fp, PKT_public_key * pk)
|
|||||||
|
|
||||||
if (fp)
|
if (fp)
|
||||||
tty_printf ("\n");
|
tty_printf ("\n");
|
||||||
tty_fprintf (fp, "pub %s/%s %s %s\n",
|
tty_fprintf (fp, "%s %s/%s %s %s\n",
|
||||||
|
pk->flags.primary? "pub":"sub",
|
||||||
pubkey_string (pk, pkstrbuf, sizeof pkstrbuf),
|
pubkey_string (pk, pkstrbuf, sizeof pkstrbuf),
|
||||||
keystr (keyid), datestr_from_pk (pk), p);
|
keystr (keyid), datestr_from_pk (pk), p);
|
||||||
xfree (p);
|
xfree (p);
|
||||||
@ -205,6 +206,7 @@ print_card_key_info (estream_t fp, kbnode_t keyblock)
|
|||||||
char *serialno;
|
char *serialno;
|
||||||
int s2k_char;
|
int s2k_char;
|
||||||
char pkstrbuf[PUBKEY_STRING_SIZE];
|
char pkstrbuf[PUBKEY_STRING_SIZE];
|
||||||
|
int indent;
|
||||||
|
|
||||||
for (node = keyblock; node; node = node->next)
|
for (node = keyblock; node; node = node->next)
|
||||||
{
|
{
|
||||||
@ -226,18 +228,18 @@ print_card_key_info (estream_t fp, kbnode_t keyblock)
|
|||||||
else
|
else
|
||||||
s2k_char = '#'; /* Key not found. */
|
s2k_char = '#'; /* Key not found. */
|
||||||
|
|
||||||
tty_fprintf (fp, "%s%c %s/%s ",
|
tty_fprintf (fp, "%s%c %s/%s %n",
|
||||||
node->pkt->pkttype == PKT_PUBLIC_KEY ? "sec" : "ssb",
|
node->pkt->pkttype == PKT_PUBLIC_KEY ? "sec" : "ssb",
|
||||||
s2k_char,
|
s2k_char,
|
||||||
pubkey_string (pk, pkstrbuf, sizeof pkstrbuf),
|
pubkey_string (pk, pkstrbuf, sizeof pkstrbuf),
|
||||||
keystr_from_pk (pk));
|
keystr_from_pk (pk),
|
||||||
|
&indent);
|
||||||
tty_fprintf (fp, _("created: %s"), datestr_from_pk (pk));
|
tty_fprintf (fp, _("created: %s"), datestr_from_pk (pk));
|
||||||
tty_fprintf (fp, " ");
|
tty_fprintf (fp, " ");
|
||||||
tty_fprintf (fp, _("expires: %s"), expirestr_from_pk (pk));
|
tty_fprintf (fp, _("expires: %s"), expirestr_from_pk (pk));
|
||||||
if (serialno)
|
if (serialno)
|
||||||
{
|
{
|
||||||
tty_fprintf (fp, "\n ");
|
tty_fprintf (fp, "\n%*s%s", indent, "", _("card-no: "));
|
||||||
tty_fprintf (fp, _("card-no: "));
|
|
||||||
if (strlen (serialno) == 32
|
if (strlen (serialno) == 32
|
||||||
&& !strncmp (serialno, "D27600012401", 12))
|
&& !strncmp (serialno, "D27600012401", 12))
|
||||||
{
|
{
|
||||||
|
@ -291,7 +291,7 @@ gen_desig_revoke( const char *uname, strlist_t locusr )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
pk2 = xmalloc_clear (sizeof *pk2);
|
pk2 = xmalloc_clear (sizeof *pk2);
|
||||||
rc = get_pubkey_byfprint (pk2,
|
rc = get_pubkey_byfprint (pk2, NULL,
|
||||||
pk->revkey[i].fpr, MAX_FINGERPRINT_LEN);
|
pk->revkey[i].fpr, MAX_FINGERPRINT_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user