diff options
Diffstat (limited to 'g10/keylist.c')
-rw-r--r-- | g10/keylist.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/g10/keylist.c b/g10/keylist.c index ce66a1359..cb38026e6 100644 --- a/g10/keylist.c +++ b/g10/keylist.c @@ -41,6 +41,7 @@ static void list_all(int); static void list_one( STRLIST names, int secret); +static void print_card_serialno (PKT_secret_key *sk); struct sig_stats { @@ -752,6 +753,7 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque ) if( !any ) { if( fpr ) print_fingerprint( pk, sk, 0 ); + print_card_serialno (sk); if( opt.with_key_data ) print_key_data( pk ); any = 1; @@ -805,6 +807,7 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque ) putchar('\n'); if( fpr ) print_fingerprint( pk, sk, 0 ); /* of the main key */ + print_card_serialno (sk); any = 1; } @@ -817,7 +820,10 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque ) printf(_(" [expires: %s]"), expirestr_from_sk( sk2 ) ); putchar('\n'); if( fpr > 1 ) - print_fingerprint( NULL, sk2, 0 ); + { + print_fingerprint( NULL, sk2, 0 ); + print_card_serialno (sk2); + } } else if( opt.list_sigs && node->pkt->pkttype == PKT_SIGNATURE @@ -861,6 +867,7 @@ list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque ) putchar('\n'); if( fpr ) print_fingerprint( pk, sk, 0 ); + print_card_serialno (sk); any=1; } @@ -1475,6 +1482,41 @@ print_fingerprint (PKT_public_key *pk, PKT_secret_key *sk, int mode ) tty_printf ("\n"); } +/* Print the serial number of an OpenPGP card if available. */ +static void +print_card_serialno (PKT_secret_key *sk) +{ + int i; + + if (!sk) + return; + if (!sk->is_protected || sk->protect.s2k.mode != 1002) + return; /* Not a card. */ + if (opt.with_colons) + return; /* Handled elesewhere. */ + + fputs (_(" Card serial no. ="), stdout); + putchar (' '); + if (sk->protect.ivlen == 16 + && !memcmp (sk->protect.iv, "\xD2\x76\x00\x01\x24\x01", 6) ) + { /* This is an OpenPGP card. Just print the relevant part. */ + for (i=8; i < 14; i++) + { + if (i == 10) + putchar (' '); + printf ("%02X", sk->protect.iv[i]); + } + } + else + { /* Something is wrong: Print all. */ + for (i=0; i < sk->protect.ivlen; i++) + printf ("%02X", sk->protect.iv[i]); + } + putchar ('\n'); +} + + + void set_attrib_fd(int fd) { static int last_fd=-1; |