1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-07-03 02:58:57 +02:00
gnupg/g10/keylist.c

756 lines
20 KiB
C
Raw Normal View History

1998-03-05 10:22:13 +01:00
/* keylist.c
2001-03-08 15:33:24 +01:00
* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
1998-03-05 10:22:13 +01:00
*
* This file is part of GnuPG.
1998-03-05 10:22:13 +01:00
*
* GnuPG is free software; you can redistribute it and/or modify
1998-03-05 10:22:13 +01:00
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GnuPG is distributed in the hope that it will be useful,
1998-03-05 10:22:13 +01:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include "options.h"
#include "packet.h"
#include "errors.h"
#include "keydb.h"
#include "memory.h"
#include "util.h"
#include "trustdb.h"
1998-03-09 22:44:06 +01:00
#include "main.h"
1998-03-05 10:22:13 +01:00
#include "i18n.h"
1998-05-29 13:53:54 +02:00
static void list_all(int);
static void list_one( STRLIST names, int secret);
1998-10-21 19:34:36 +02:00
static void list_keyblock( KBNODE keyblock, int secret );
1998-06-29 14:30:57 +02:00
static void fingerprint( PKT_public_key *pk, PKT_secret_key *sk );
1998-03-09 22:44:06 +01:00
1998-03-05 10:22:13 +01:00
/****************
1998-03-09 22:44:06 +01:00
* List the keys
* If list is NULL, all available keys are listed
1998-03-05 10:22:13 +01:00
*/
void
public_key_list( STRLIST list )
1998-03-05 10:22:13 +01:00
{
if( !list )
1998-05-29 13:53:54 +02:00
list_all(0);
else
list_one( list, 0 );
1998-05-29 13:53:54 +02:00
}
void
secret_key_list( STRLIST list )
1998-05-29 13:53:54 +02:00
{
if( !list )
1998-05-29 13:53:54 +02:00
list_all(1);
else /* List by user id */
list_one( list, 1 );
1998-03-09 22:44:06 +01:00
}
static void
1998-05-29 13:53:54 +02:00
list_all( int secret )
1998-03-09 22:44:06 +01:00
{
2001-09-06 19:10:00 +02:00
KEYDB_HANDLE hd;
1998-10-21 19:34:36 +02:00
KBNODE keyblock = NULL;
int rc=0;
2001-09-06 19:10:00 +02:00
const char *lastresname, *resname;
1998-10-21 19:34:36 +02:00
2001-09-06 19:10:00 +02:00
hd = keydb_new (secret);
if (!hd)
rc = G10ERR_GENERAL;
else
rc = keydb_search_first (hd);
1998-10-21 19:34:36 +02:00
if( rc ) {
if( rc != -1 )
2001-09-06 19:10:00 +02:00
log_error("keydb_search_first failed: %s\n", g10_errstr(rc) );
1998-10-21 19:34:36 +02:00
goto leave;
}
1998-03-09 22:44:06 +01:00
2001-09-06 19:10:00 +02:00
lastresname = NULL;
do {
rc = keydb_get_keyblock (hd, &keyblock);
if (rc) {
log_error ("keydb_get_keyblock failed: %s\n", g10_errstr(rc));
goto leave;
}
resname = keydb_get_resource_name (hd);
if (lastresname != resname ) {
1998-10-21 19:34:36 +02:00
int i;
2001-09-06 19:10:00 +02:00
printf("%s\n", resname );
for(i=strlen(resname); i; i-- )
1998-10-21 19:34:36 +02:00
putchar('-');
putchar('\n');
2001-09-06 19:10:00 +02:00
lastresname = resname;
1998-10-21 19:34:36 +02:00
}
2001-03-03 17:17:55 +01:00
merge_keys_and_selfsig( keyblock );
1998-10-21 19:34:36 +02:00
list_keyblock( keyblock, secret );
2001-09-06 19:10:00 +02:00
release_kbnode( keyblock );
keyblock = NULL;
} while (!(rc = keydb_search_next (hd)));
1998-10-21 19:34:36 +02:00
if( rc && rc != -1 )
2001-09-06 19:10:00 +02:00
log_error ("keydb_search_next failed: %s\n", g10_errstr(rc));
1998-10-21 19:34:36 +02:00
leave:
2001-09-06 19:10:00 +02:00
release_kbnode (keyblock);
keydb_release (hd);
1998-03-09 22:44:06 +01:00
}
1998-10-21 19:34:36 +02:00
1998-03-09 22:44:06 +01:00
static void
list_one( STRLIST names, int secret )
1998-03-09 22:44:06 +01:00
{
int rc = 0;
KBNODE keyblock = NULL;
GETKEY_CTX ctx;
1998-03-09 22:44:06 +01:00
1998-11-08 18:23:14 +01:00
if( secret ) {
rc = get_seckey_bynames( &ctx, NULL, names, &keyblock );
1998-11-08 18:23:14 +01:00
if( rc ) {
log_error("error reading key: %s\n", g10_errstr(rc) );
get_seckey_end( ctx );
1998-11-08 18:23:14 +01:00
return;
}
do {
list_keyblock( keyblock, 1 );
release_kbnode( keyblock );
} while( !get_seckey_next( ctx, NULL, &keyblock ) );
get_seckey_end( ctx );
1998-11-08 18:23:14 +01:00
}
else {
rc = get_pubkey_bynames( &ctx, NULL, names, &keyblock );
1998-11-08 18:23:14 +01:00
if( rc ) {
log_error("error reading key: %s\n", g10_errstr(rc) );
1998-11-08 18:23:14 +01:00
get_pubkey_end( ctx );
return;
}
do {
list_keyblock( keyblock, 0 );
release_kbnode( keyblock );
} while( !get_pubkey_next( ctx, NULL, &keyblock ) );
get_pubkey_end( ctx );
1998-03-09 22:44:06 +01:00
}
1998-10-21 19:34:36 +02:00
}
1998-03-09 22:44:06 +01:00
static void
print_key_data( PKT_public_key *pk, u32 *keyid )
{
int n = pk ? pubkey_get_npkey( pk->pubkey_algo ) : 0;
int i;
for(i=0; i < n; i++ ) {
printf("pkd:%d:%u:", i, mpi_get_nbits( pk->pkey[i] ) );
mpi_print(stdout, pk->pkey[i], 1 );
putchar(':');
putchar('\n');
}
}
2001-03-15 14:08:15 +01:00
static void
print_capabilities (PKT_public_key *pk, PKT_secret_key *sk, KBNODE keyblock)
{
unsigned int use = pk? pk->pubkey_usage : sk->pubkey_usage;
2001-03-15 14:08:15 +01:00
if ( use & PUBKEY_USAGE_ENC ) {
2001-03-15 14:08:15 +01:00
putchar ('e');
}
if ( use & PUBKEY_USAGE_SIG ) {
2001-03-15 14:08:15 +01:00
putchar ('s');
putchar ('c');
}
if ( keyblock ) { /* figure our the usable capabilities */
KBNODE k;
int enc=0, sign=0, cert=0;
for (k=keyblock; k; k = k->next ) {
if ( k->pkt->pkttype == PKT_PUBLIC_KEY
|| k->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
pk = k->pkt->pkt.public_key;
if ( pk->is_valid && !pk->is_revoked && !pk->has_expired ) {
if ( pk->pubkey_usage & PUBKEY_USAGE_ENC )
enc = 1;
if ( pk->pubkey_usage & PUBKEY_USAGE_SIG )
sign = cert = 1;
}
}
else if ( k->pkt->pkttype == PKT_SECRET_KEY
|| k->pkt->pkttype == PKT_SECRET_SUBKEY ) {
sk = k->pkt->pkt.secret_key;
if ( sk->is_valid && !sk->is_revoked && !sk->has_expired ) {
if ( sk->pubkey_usage & PUBKEY_USAGE_ENC )
enc = 1;
if ( sk->pubkey_usage & PUBKEY_USAGE_SIG )
sign = cert = 1;
}
}
}
if (enc)
putchar ('E');
if (sign)
putchar ('S');
if (cert)
putchar ('C');
}
putchar(':');
}
1998-03-19 16:27:29 +01:00
1998-10-21 19:34:36 +02:00
static void
2001-03-13 18:32:28 +01:00
list_keyblock_print ( KBNODE keyblock, int secret )
{
int rc = 0;
KBNODE kbctx;
KBNODE node;
PKT_public_key *pk;
PKT_secret_key *sk;
u32 keyid[2];
int any=0;
/* get the keyid from the keyblock */
node = find_kbnode( keyblock, secret? PKT_SECRET_KEY : PKT_PUBLIC_KEY );
if( !node ) {
log_error("Oops; key lost!\n");
dump_kbnode( keyblock );
return;
}
if( secret ) {
pk = NULL;
sk = node->pkt->pkt.secret_key;
keyid_from_sk( sk, keyid );
printf("sec %4u%c/%08lX %s ", nbits_from_sk( sk ),
pubkey_letter( sk->pubkey_algo ),
(ulong)keyid[1],
datestr_from_sk( sk ) );
}
else {
pk = node->pkt->pkt.public_key;
sk = NULL;
keyid_from_pk( pk, keyid );
printf("pub %4u%c/%08lX %s ", nbits_from_pk( pk ),
pubkey_letter( pk->pubkey_algo ),
(ulong)keyid[1],
datestr_from_pk( pk ) );
}
for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) {
if( node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode ) {
/* don't list revoked UIDS unless we are in verbose mode and
* signature listing has not been requested */
if ( !opt.verbose && !opt.list_sigs
&& node->pkt->pkt.user_id->is_revoked )
continue;
2001-03-13 18:32:28 +01:00
if( any )
printf("uid%*s", 28, "");
if ( node->pkt->pkt.user_id->is_revoked )
fputs ("[revoked] ", stdout);
print_utf8_string( stdout, node->pkt->pkt.user_id->name,
node->pkt->pkt.user_id->len );
putchar('\n');
if( !any ) {
if( opt.fingerprint )
fingerprint( pk, sk );
if( opt.with_key_data )
print_key_data( pk, keyid );
any = 1;
}
}
else if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
u32 keyid2[2];
PKT_public_key *pk2 = node->pkt->pkt.public_key;
if( !any ) {
putchar('\n');
if( opt.fingerprint )
fingerprint( pk, sk ); /* of the main key */
any = 1;
}
keyid_from_pk( pk2, keyid2 );
printf("sub %4u%c/%08lX %s", nbits_from_pk( pk2 ),
pubkey_letter( pk2->pubkey_algo ),
(ulong)keyid2[1],
datestr_from_pk( pk2 ) );
if( pk2->expiredate ) {
printf(_(" [expires: %s]"), expirestr_from_pk( pk2 ) );
}
putchar('\n');
if( opt.fingerprint > 1 )
fingerprint( pk2, NULL );
if( opt.with_key_data )
print_key_data( pk2, keyid2 );
}
else if( node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
u32 keyid2[2];
PKT_secret_key *sk2 = node->pkt->pkt.secret_key;
if( !any ) {
putchar('\n');
if( opt.fingerprint )
fingerprint( pk, sk ); /* of the main key */
any = 1;
}
keyid_from_sk( sk2, keyid2 );
printf("ssb %4u%c/%08lX %s\n", nbits_from_sk( sk2 ),
pubkey_letter( sk2->pubkey_algo ),
(ulong)keyid2[1],
datestr_from_sk( sk2 ) );
if( opt.fingerprint > 1 )
fingerprint( NULL, sk2 );
}
else if( opt.list_sigs && node->pkt->pkttype == PKT_SIGNATURE ) {
PKT_signature *sig = node->pkt->pkt.signature;
int sigrc;
char *sigstr;
if( !any ) { /* no user id, (maybe a revocation follows)*/
if( sig->sig_class == 0x20 )
puts("[revoked]");
else if( sig->sig_class == 0x18 )
puts("[key binding]");
else if( sig->sig_class == 0x28 )
puts("[subkey revoked]");
else
putchar('\n');
if( opt.fingerprint )
fingerprint( pk, sk );
any=1;
}
if( sig->sig_class == 0x20 || sig->sig_class == 0x28
|| sig->sig_class == 0x30 )
sigstr = "rev";
else if( (sig->sig_class&~3) == 0x10 )
sigstr = "sig";
else if( sig->sig_class == 0x18 )
sigstr = "sig";
else {
printf("sig "
"[unexpected signature class 0x%02x]\n",sig->sig_class );
continue;
}
if( opt.check_sigs ) {
fflush(stdout);
rc = check_key_signature( keyblock, node, NULL );
switch( rc ) {
case 0: sigrc = '!'; break;
case G10ERR_BAD_SIGN: sigrc = '-'; break;
case G10ERR_NO_PUBKEY:
case G10ERR_UNU_PUBKEY: sigrc = '?'; break;
default: sigrc = '%'; break;
}
}
else {
rc = 0;
sigrc = ' ';
}
fputs( sigstr, stdout );
printf("%c %08lX %s ",
sigrc, (ulong)sig->keyid[1], datestr_from_sig(sig));
if( sigrc == '%' )
printf("[%s] ", g10_errstr(rc) );
else if( sigrc == '?' )
;
else if ( !opt.fast_list_mode ) {
size_t n;
char *p = get_user_id( sig->keyid, &n );
print_utf8_string( stdout, p, n );
m_free(p);
}
putchar('\n');
/* fixme: check or list other sigs here */
}
}
putchar('\n');
}
static void
list_keyblock_colon( KBNODE keyblock, int secret )
1998-10-21 19:34:36 +02:00
{
int rc = 0;
KBNODE kbctx;
KBNODE node;
PKT_public_key *pk;
PKT_secret_key *sk;
u32 keyid[2];
int any=0;
int trustletter = 0;
int ulti_hack = 0;
1998-10-21 19:34:36 +02:00
1998-03-09 22:44:06 +01:00
/* get the keyid from the keyblock */
1998-06-29 14:30:57 +02:00
node = find_kbnode( keyblock, secret? PKT_SECRET_KEY : PKT_PUBLIC_KEY );
1998-03-09 22:44:06 +01:00
if( !node ) {
1998-05-29 13:53:54 +02:00
log_error("Oops; key lost!\n");
dump_kbnode( keyblock );
1998-10-21 19:34:36 +02:00
return;
1998-03-09 22:44:06 +01:00
}
1998-05-29 13:53:54 +02:00
if( secret ) {
1998-06-29 14:30:57 +02:00
pk = NULL;
sk = node->pkt->pkt.secret_key;
keyid_from_sk( sk, keyid );
2001-03-13 18:32:28 +01:00
printf("sec:u:%u:%d:%08lX%08lX:%s:%s:::",
1998-06-29 14:30:57 +02:00
nbits_from_sk( sk ),
sk->pubkey_algo,
1998-05-29 13:53:54 +02:00
(ulong)keyid[0],(ulong)keyid[1],
2001-04-19 13:40:45 +02:00
colon_datestr_from_sk( sk ),
colon_strtime (sk->expiredate)
1998-05-29 13:53:54 +02:00
/* fixme: add LID here */ );
}
else {
1998-06-29 14:30:57 +02:00
pk = node->pkt->pkt.public_key;
sk = NULL;
keyid_from_pk( pk, keyid );
2001-03-14 07:56:11 +01:00
fputs( "pub:", stdout );
trustletter = 0;
if ( !pk->is_valid )
putchar ('i');
else if ( pk->is_revoked )
putchar ('r');
else if ( pk->has_expired )
putchar ('e');
else if ( opt.fast_list_mode || opt.no_expensive_trust_checks )
;
2001-03-13 18:32:28 +01:00
else {
trustletter = query_trust_info( pk, NULL );
if( trustletter == 'u' )
ulti_hack = 1;
2001-03-14 07:56:11 +01:00
putchar(trustletter);
2001-03-13 18:32:28 +01:00
}
2001-03-14 07:56:11 +01:00
printf(":%u:%d:%08lX%08lX:%s:%s:",
1998-06-29 14:30:57 +02:00
nbits_from_pk( pk ),
pk->pubkey_algo,
1998-05-29 13:53:54 +02:00
(ulong)keyid[0],(ulong)keyid[1],
2001-04-19 13:40:45 +02:00
colon_datestr_from_pk( pk ),
colon_strtime (pk->expiredate) );
2001-03-13 18:32:28 +01:00
if( pk->local_id )
printf("%lu", pk->local_id );
putchar(':');
if( pk->local_id && !opt.fast_list_mode
&& !opt.no_expensive_trust_checks )
putchar( get_ownertrust_info( pk->local_id ) );
1998-05-29 13:53:54 +02:00
putchar(':');
}
2001-03-14 07:56:11 +01:00
if (opt.fixed_list_mode) {
/* do not merge the first uid with the primary key */
putchar(':');
2001-03-15 14:08:15 +01:00
putchar(':');
print_capabilities (pk, sk, keyblock);
2001-03-14 07:56:11 +01:00
putchar('\n');
if( opt.fingerprint )
fingerprint( pk, sk );
if( opt.with_key_data )
print_key_data( pk, keyid );
any = 1;
}
1998-03-09 22:44:06 +01:00
2001-03-15 14:08:15 +01:00
1998-03-09 22:44:06 +01:00
for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) {
if( node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode ) {
2001-03-14 07:56:11 +01:00
/*
* Fixme: We need a is_valid flag here too
*/
1998-03-09 22:44:06 +01:00
if( any ) {
2001-03-14 07:56:11 +01:00
if ( node->pkt->pkt.user_id->is_revoked )
printf("uid:r::::::::");
else if ( opt.no_expensive_trust_checks ) {
2001-01-11 14:20:02 +01:00
printf("uid:::::::::");
}
2001-03-13 18:32:28 +01:00
else {
byte namehash[20];
if( pk && !ulti_hack ) {
if( node->pkt->pkt.user_id->photo )
rmd160_hash_buffer( namehash,
2001-03-14 07:56:11 +01:00
node->pkt->pkt.user_id->photo,
node->pkt->pkt.user_id->photolen);
else
rmd160_hash_buffer( namehash,
node->pkt->pkt.user_id->name,
node->pkt->pkt.user_id->len );
trustletter = query_trust_info( pk, namehash );
}
else
trustletter = 'u';
printf("uid:%c::::::::", trustletter);
2001-03-13 18:32:28 +01:00
}
}
2001-03-13 18:32:28 +01:00
print_string( stdout, node->pkt->pkt.user_id->name,
node->pkt->pkt.user_id->len, ':' );
putchar(':');
2001-03-15 14:08:15 +01:00
if (any)
putchar('\n');
else {
putchar(':');
print_capabilities (pk, sk, keyblock);
putchar('\n');
1998-03-09 22:44:06 +01:00
if( opt.fingerprint )
1998-06-29 14:30:57 +02:00
fingerprint( pk, sk );
if( opt.with_key_data )
print_key_data( pk, keyid );
1998-03-09 22:44:06 +01:00
any = 1;
}
}
1998-06-29 14:30:57 +02:00
else if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
1998-04-02 12:30:03 +02:00
u32 keyid2[2];
1998-06-29 14:30:57 +02:00
PKT_public_key *pk2 = node->pkt->pkt.public_key;
1998-04-02 12:30:03 +02:00
if( !any ) {
2001-03-15 14:08:15 +01:00
putchar(':');
putchar(':');
print_capabilities (pk, sk, keyblock);
putchar('\n');
1998-04-02 12:30:03 +02:00
if( opt.fingerprint )
1998-06-29 14:30:57 +02:00
fingerprint( pk, sk ); /* of the main key */
1998-04-02 12:30:03 +02:00
any = 1;
}
1998-06-29 14:30:57 +02:00
keyid_from_pk( pk2, keyid2 );
2001-03-14 07:56:11 +01:00
fputs ("sub:", stdout );
if ( !pk2->is_valid )
putchar ('i');
else if ( pk2->is_revoked )
putchar ('r');
else if ( pk2->has_expired )
putchar ('e');
else if ( opt.fast_list_mode || opt.no_expensive_trust_checks )
;
2001-03-13 18:32:28 +01:00
else {
2001-03-14 07:56:11 +01:00
printf("%c", trustletter );
2001-03-13 18:32:28 +01:00
}
2001-03-14 07:56:11 +01:00
printf(":%u:%d:%08lX%08lX:%s:%s:",
1998-06-29 14:30:57 +02:00
nbits_from_pk( pk2 ),
pk2->pubkey_algo,
1998-04-02 12:30:03 +02:00
(ulong)keyid2[0],(ulong)keyid2[1],
2001-04-19 13:40:45 +02:00
colon_datestr_from_pk( pk2 ),
colon_strtime (pk2->expiredate)
1998-04-02 12:30:03 +02:00
/* fixme: add LID and ownertrust here */
);
2001-03-13 18:32:28 +01:00
if( pk->local_id ) /* use the local_id of the main key??? */
printf("%lu", pk->local_id );
putchar(':');
putchar(':');
2001-03-15 14:08:15 +01:00
putchar(':');
putchar(':');
print_capabilities (pk2, NULL, NULL);
2001-03-13 18:32:28 +01:00
putchar('\n');
1998-07-29 21:35:05 +02:00
if( opt.fingerprint > 1 )
fingerprint( pk2, NULL );
if( opt.with_key_data )
print_key_data( pk2, keyid2 );
1998-04-02 12:30:03 +02:00
}
1998-06-29 14:30:57 +02:00
else if( node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
1998-05-29 13:53:54 +02:00
u32 keyid2[2];
1998-06-29 14:30:57 +02:00
PKT_secret_key *sk2 = node->pkt->pkt.secret_key;
1998-05-29 13:53:54 +02:00
if( !any ) {
2001-03-15 14:08:15 +01:00
putchar(':');
putchar(':');
print_capabilities (pk, sk, keyblock);
1998-05-29 13:53:54 +02:00
putchar('\n');
if( opt.fingerprint )
1998-06-29 14:30:57 +02:00
fingerprint( pk, sk ); /* of the main key */
1998-05-29 13:53:54 +02:00
any = 1;
}
1998-06-29 14:30:57 +02:00
keyid_from_sk( sk2, keyid2 );
2001-03-15 14:08:15 +01:00
printf("ssb::%u:%d:%08lX%08lX:%s:%s:::::",
1998-06-29 14:30:57 +02:00
nbits_from_sk( sk2 ),
sk2->pubkey_algo,
1998-05-29 13:53:54 +02:00
(ulong)keyid2[0],(ulong)keyid2[1],
2001-04-19 13:40:45 +02:00
colon_datestr_from_sk( sk2 ),
colon_strtime (sk2->expiredate)
2001-03-15 14:08:15 +01:00
/* fixme: add LID */ );
print_capabilities (NULL, sk2, NULL);
putchar ('\n');
1998-07-29 21:35:05 +02:00
if( opt.fingerprint > 1 )
fingerprint( NULL, sk2 );
1998-05-29 13:53:54 +02:00
}
1998-03-09 22:44:06 +01:00
else if( opt.list_sigs && node->pkt->pkttype == PKT_SIGNATURE ) {
PKT_signature *sig = node->pkt->pkt.signature;
int sigrc;
2001-01-11 14:20:02 +01:00
char *sigstr;
1998-03-09 22:44:06 +01:00
if( !any ) { /* no user id, (maybe a revocation follows)*/
if( sig->sig_class == 0x20 )
2001-03-15 14:08:15 +01:00
fputs("[revoked]:", stdout);
1998-05-29 13:53:54 +02:00
else if( sig->sig_class == 0x18 )
2001-03-15 14:08:15 +01:00
fputs("[key binding]:", stdout);
else if( sig->sig_class == 0x28 )
2001-03-15 14:08:15 +01:00
fputs("[subkey revoked]:", stdout);
else
putchar (':');
putchar(':');
print_capabilities (pk, sk, keyblock);
putchar('\n');
1998-03-09 22:44:06 +01:00
if( opt.fingerprint )
1998-06-29 14:30:57 +02:00
fingerprint( pk, sk );
1998-03-09 22:44:06 +01:00
any=1;
}
if( sig->sig_class == 0x20 || sig->sig_class == 0x28
|| sig->sig_class == 0x30 )
sigstr = "rev";
1998-03-09 22:44:06 +01:00
else if( (sig->sig_class&~3) == 0x10 )
sigstr = "sig";
1998-04-02 12:30:03 +02:00
else if( sig->sig_class == 0x18 )
sigstr = "sig";
1998-03-09 22:44:06 +01:00
else {
2001-05-28 14:46:28 +02:00
printf ("sig::::::::::%02x%c:\n",
sig->sig_class, get_lsign_letter (sig) );
1998-03-09 22:44:06 +01:00
continue;
}
if( opt.check_sigs ) {
fflush(stdout);
rc = check_key_signature( keyblock, node, NULL );
switch( rc ) {
case 0: sigrc = '!'; break;
case G10ERR_BAD_SIGN: sigrc = '-'; break;
2001-03-03 17:17:55 +01:00
case G10ERR_NO_PUBKEY:
case G10ERR_UNU_PUBKEY: sigrc = '?'; break;
1998-03-09 22:44:06 +01:00
default: sigrc = '%'; break;
}
}
else {
rc = 0;
sigrc = ' ';
}
2001-01-11 14:20:02 +01:00
fputs( sigstr, stdout );
2001-03-13 18:32:28 +01:00
putchar(':');
if( sigrc != ' ' )
putchar(sigrc);
printf("::%d:%08lX%08lX:%s::::", sig->pubkey_algo,
(ulong)sig->keyid[0],
2001-04-19 13:40:45 +02:00
(ulong)sig->keyid[1], colon_datestr_from_sig(sig));
1998-03-09 22:44:06 +01:00
if( sigrc == '%' )
printf("[%s] ", g10_errstr(rc) );
else if( sigrc == '?' )
;
else if ( !opt.fast_list_mode ) {
1998-03-09 22:44:06 +01:00
size_t n;
char *p = get_user_id( sig->keyid, &n );
2001-03-13 18:32:28 +01:00
print_string( stdout, p, n, ':' );
1998-03-09 22:44:06 +01:00
m_free(p);
}
2001-05-28 14:46:28 +02:00
printf(":%02x%c:\n", sig->sig_class, get_lsign_letter (sig) );
/* fixme: check or list other sigs here */
1998-03-09 22:44:06 +01:00
}
}
if( !any ) {/* oops, no user id */
2001-03-13 18:32:28 +01:00
putchar(':');
2001-03-15 14:08:15 +01:00
putchar(':');
print_capabilities (pk, sk, keyblock);
1998-03-09 22:44:06 +01:00
putchar('\n');
}
1998-10-21 19:34:36 +02:00
}
1998-03-09 22:44:06 +01:00
2001-03-13 18:32:28 +01:00
/*
* Reorder the keyblock so that the primary user ID comes first.
* Fixme: Replace this by a generic sort function.
*/
static void
reorder_keyblock (KBNODE keyblock)
{
KBNODE primary = NULL, primary0 = NULL, primary2 = NULL;
KBNODE last, node;
for (node=keyblock; node; primary0=node, node = node->next) {
if( node->pkt->pkttype == PKT_USER_ID
&& node->pkt->pkt.user_id->is_primary ) {
primary = primary2 = node;
for (node=node->next; node; primary2=node, node = node->next ) {
if( node->pkt->pkttype == PKT_USER_ID
|| node->pkt->pkttype == PKT_PUBLIC_SUBKEY
|| node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
break;
}
}
break;
}
}
if ( !primary )
return; /* no primary key flag found (should not happen) */
1998-03-09 22:44:06 +01:00
2001-03-13 18:32:28 +01:00
for (last=NULL, node=keyblock; node; last = node, node = node->next) {
if( node->pkt->pkttype == PKT_USER_ID )
break;
}
assert (node);
assert (last); /* the user ID is never the first packet */
assert (primary0); /* ditto (this is the node before primary) */
if ( node == primary )
return; /* already the first one */
last->next = primary;
primary0->next = primary2->next;
primary2->next = node;
}
static void
list_keyblock( KBNODE keyblock, int secret )
{
reorder_keyblock (keyblock);
if (opt.with_colons)
list_keyblock_colon (keyblock, secret );
else
list_keyblock_print (keyblock, secret );
}
1998-03-09 22:44:06 +01:00
static void
1998-06-29 14:30:57 +02:00
fingerprint( PKT_public_key *pk, PKT_secret_key *sk )
1998-03-09 22:44:06 +01:00
{
byte *array, *p;
size_t i, n;
1998-07-14 19:10:28 +02:00
p = array = pk? fingerprint_from_pk( pk, NULL, &n )
: fingerprint_from_sk( sk, NULL, &n );
1998-03-09 22:44:06 +01:00
if( opt.with_colons ) {
1998-04-02 12:30:03 +02:00
printf("fpr:::::::::");
1998-03-09 22:44:06 +01:00
for(i=0; i < n ; i++, p++ )
printf("%02X", *p );
putchar(':');
}
else {
printf(" Key fingerprint =");
if( n == 20 ) {
for(i=0; i < n ; i++, i++, p += 2 ) {
if( i == 10 )
putchar(' ');
printf(" %02X%02X", *p, p[1] );
}
}
else {
for(i=0; i < n ; i++, p++ ) {
if( i && !(i%8) )
putchar(' ');
printf(" %02X", *p );
}
}
}
putchar('\n');
m_free(array);
1998-03-05 10:22:13 +01:00
}