1998-03-05 09:22:13 +00:00
|
|
|
/* keylist.c
|
2000-05-30 15:31:45 +00:00
|
|
|
* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
|
1998-03-05 09:22:13 +00:00
|
|
|
*
|
1998-12-23 12:41:40 +00:00
|
|
|
* This file is part of GnuPG.
|
1998-03-05 09:22:13 +00:00
|
|
|
*
|
1998-12-23 12:41:40 +00:00
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
1998-03-05 09:22:13 +00: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.
|
|
|
|
*
|
1998-12-23 12:41:40 +00:00
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
1998-03-05 09:22:13 +00: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 21:44:06 +00:00
|
|
|
#include "main.h"
|
1998-03-05 09:22:13 +00:00
|
|
|
#include "i18n.h"
|
|
|
|
|
1998-05-29 11:53:54 +00:00
|
|
|
static void list_all(int);
|
1999-01-24 17:16:40 +00:00
|
|
|
static void list_one( STRLIST names, int secret);
|
1998-10-21 17:34:36 +00:00
|
|
|
static void list_keyblock( KBNODE keyblock, int secret );
|
1998-06-29 12:30:57 +00:00
|
|
|
static void fingerprint( PKT_public_key *pk, PKT_secret_key *sk );
|
1998-03-09 21:44:06 +00:00
|
|
|
|
1998-03-05 09:22:13 +00:00
|
|
|
|
|
|
|
/****************
|
1998-03-09 21:44:06 +00:00
|
|
|
* List the keys
|
2000-05-30 15:31:45 +00:00
|
|
|
* If list is NULL, all available keys are listed
|
1998-03-05 09:22:13 +00:00
|
|
|
*/
|
|
|
|
void
|
2000-05-30 15:31:45 +00:00
|
|
|
public_key_list( STRLIST list )
|
1998-03-05 09:22:13 +00:00
|
|
|
{
|
2000-05-30 15:31:45 +00:00
|
|
|
if( !list )
|
1998-05-29 11:53:54 +00:00
|
|
|
list_all(0);
|
2000-05-30 15:31:45 +00:00
|
|
|
else
|
1999-01-24 17:16:40 +00:00
|
|
|
list_one( list, 0 );
|
1998-05-29 11:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-05-30 15:31:45 +00:00
|
|
|
secret_key_list( STRLIST list )
|
1998-05-29 11:53:54 +00:00
|
|
|
{
|
2000-05-30 15:31:45 +00:00
|
|
|
if( !list )
|
1998-05-29 11:53:54 +00:00
|
|
|
list_all(1);
|
2000-05-30 15:31:45 +00:00
|
|
|
else /* List by user id */
|
1999-02-24 10:12:32 +00:00
|
|
|
list_one( list, 1 );
|
1998-03-09 21:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
1998-05-29 11:53:54 +00:00
|
|
|
list_all( int secret )
|
1998-03-09 21:44:06 +00:00
|
|
|
{
|
1998-10-21 17:34:36 +00:00
|
|
|
KBPOS kbpos;
|
|
|
|
KBNODE keyblock = NULL;
|
|
|
|
int rc=0;
|
|
|
|
int lastresno;
|
|
|
|
|
|
|
|
rc = enum_keyblocks( secret? 5:0, &kbpos, &keyblock );
|
|
|
|
if( rc ) {
|
|
|
|
if( rc != -1 )
|
|
|
|
log_error("enum_keyblocks(open) failed: %s\n", g10_errstr(rc) );
|
|
|
|
goto leave;
|
|
|
|
}
|
1998-03-09 21:44:06 +00:00
|
|
|
|
1998-10-21 17:34:36 +00:00
|
|
|
lastresno = -1;
|
|
|
|
while( !(rc = enum_keyblocks( 1, &kbpos, &keyblock )) ) {
|
|
|
|
if( lastresno != kbpos.resno ) {
|
|
|
|
const char *s = keyblock_resource_name( &kbpos );
|
|
|
|
int i;
|
|
|
|
|
|
|
|
lastresno = kbpos.resno;
|
|
|
|
printf("%s\n", s );
|
|
|
|
for(i=strlen(s); i; i-- )
|
|
|
|
putchar('-');
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
merge_keys_and_selfsig( keyblock );
|
|
|
|
list_keyblock( keyblock, secret );
|
|
|
|
release_kbnode( keyblock ); keyblock = NULL;
|
1998-03-09 21:44:06 +00:00
|
|
|
}
|
1998-10-21 17:34:36 +00:00
|
|
|
|
|
|
|
if( rc && rc != -1 )
|
|
|
|
log_error("enum_keyblocks(read) failed: %s\n", g10_errstr(rc));
|
|
|
|
|
|
|
|
leave:
|
|
|
|
enum_keyblocks( 2, &kbpos, &keyblock ); /* close */
|
|
|
|
release_kbnode( keyblock );
|
1998-03-09 21:44:06 +00:00
|
|
|
}
|
|
|
|
|
1998-10-21 17:34:36 +00:00
|
|
|
|
|
|
|
|
1998-03-09 21:44:06 +00:00
|
|
|
static void
|
1999-01-24 17:16:40 +00:00
|
|
|
list_one( STRLIST names, int secret )
|
1998-03-09 21:44:06 +00:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
KBNODE keyblock = NULL;
|
1999-01-24 17:16:40 +00:00
|
|
|
GETKEY_CTX ctx;
|
1998-03-09 21:44:06 +00:00
|
|
|
|
1998-11-08 17:23:14 +00:00
|
|
|
if( secret ) {
|
1999-01-24 17:16:40 +00:00
|
|
|
rc = get_seckey_bynames( &ctx, NULL, names, &keyblock );
|
1998-11-08 17:23:14 +00:00
|
|
|
if( rc ) {
|
1999-01-24 17:16:40 +00:00
|
|
|
log_error("error reading key: %s\n", g10_errstr(rc) );
|
|
|
|
get_seckey_end( ctx );
|
1998-11-08 17:23:14 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-01-24 17:16:40 +00:00
|
|
|
do {
|
|
|
|
merge_keys_and_selfsig( keyblock );
|
1999-02-28 18:14:18 +00:00
|
|
|
list_keyblock( keyblock, 1 );
|
1999-01-24 17:16:40 +00:00
|
|
|
release_kbnode( keyblock );
|
|
|
|
} while( !get_seckey_next( ctx, NULL, &keyblock ) );
|
|
|
|
get_seckey_end( ctx );
|
1998-11-08 17:23:14 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-01-24 17:16:40 +00:00
|
|
|
rc = get_pubkey_bynames( &ctx, NULL, names, &keyblock );
|
1998-11-08 17:23:14 +00:00
|
|
|
if( rc ) {
|
1999-01-24 17:16:40 +00:00
|
|
|
log_error("error reading key: %s\n", g10_errstr(rc) );
|
1998-11-08 17:23:14 +00:00
|
|
|
get_pubkey_end( ctx );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
do {
|
2000-05-30 15:31:45 +00:00
|
|
|
merge_keys_and_selfsig( keyblock );
|
1998-11-08 17:23:14 +00:00
|
|
|
list_keyblock( keyblock, 0 );
|
|
|
|
release_kbnode( keyblock );
|
|
|
|
} while( !get_pubkey_next( ctx, NULL, &keyblock ) );
|
|
|
|
get_pubkey_end( ctx );
|
1998-03-09 21:44:06 +00:00
|
|
|
}
|
1998-10-21 17:34:36 +00:00
|
|
|
}
|
1998-03-09 21:44:06 +00:00
|
|
|
|
1999-06-08 11:41:46 +00:00
|
|
|
static void
|
|
|
|
print_key_data( PKT_public_key *pk, u32 *keyid )
|
|
|
|
{
|
2000-05-30 15:31:45 +00:00
|
|
|
int n = pk ? pubkey_get_npkey( pk->pubkey_algo ) : 0;
|
1999-06-08 11:41:46 +00:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-03-19 15:27:29 +00:00
|
|
|
|
1998-10-21 17:34:36 +00:00
|
|
|
static void
|
|
|
|
list_keyblock( 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;
|
|
|
|
int trustletter = 0;
|
1999-04-18 18:53:34 +00:00
|
|
|
int ulti_hack = 0;
|
1998-10-21 17:34:36 +00:00
|
|
|
|
1998-03-09 21:44:06 +00:00
|
|
|
/* get the keyid from the keyblock */
|
1998-06-29 12:30:57 +00:00
|
|
|
node = find_kbnode( keyblock, secret? PKT_SECRET_KEY : PKT_PUBLIC_KEY );
|
1998-03-09 21:44:06 +00:00
|
|
|
if( !node ) {
|
1998-05-29 11:53:54 +00:00
|
|
|
log_error("Oops; key lost!\n");
|
1999-02-10 16:22:40 +00:00
|
|
|
dump_kbnode( keyblock );
|
1998-10-21 17:34:36 +00:00
|
|
|
return;
|
1998-03-09 21:44:06 +00:00
|
|
|
}
|
|
|
|
|
1998-05-29 11:53:54 +00:00
|
|
|
if( secret ) {
|
1998-06-29 12:30:57 +00:00
|
|
|
pk = NULL;
|
|
|
|
sk = node->pkt->pkt.secret_key;
|
|
|
|
keyid_from_sk( sk, keyid );
|
1998-05-29 11:53:54 +00:00
|
|
|
if( opt.with_colons )
|
1999-03-10 10:27:52 +00:00
|
|
|
printf("sec:u:%u:%d:%08lX%08lX:%s:%s:::",
|
1998-06-29 12:30:57 +00:00
|
|
|
nbits_from_sk( sk ),
|
|
|
|
sk->pubkey_algo,
|
1998-05-29 11:53:54 +00:00
|
|
|
(ulong)keyid[0],(ulong)keyid[1],
|
1998-06-29 12:30:57 +00:00
|
|
|
datestr_from_sk( sk ),
|
1998-10-16 16:00:17 +00:00
|
|
|
sk->expiredate? strtimestamp(sk->expiredate):""
|
1998-05-29 11:53:54 +00:00
|
|
|
/* fixme: add LID here */ );
|
|
|
|
else
|
1998-06-29 12:30:57 +00:00
|
|
|
printf("sec %4u%c/%08lX %s ", nbits_from_sk( sk ),
|
|
|
|
pubkey_letter( sk->pubkey_algo ),
|
1998-05-29 11:53:54 +00:00
|
|
|
(ulong)keyid[1],
|
1998-06-29 12:30:57 +00:00
|
|
|
datestr_from_sk( sk ) );
|
1998-05-29 11:53:54 +00:00
|
|
|
}
|
|
|
|
else {
|
1998-06-29 12:30:57 +00:00
|
|
|
pk = node->pkt->pkt.public_key;
|
|
|
|
sk = NULL;
|
|
|
|
keyid_from_pk( pk, keyid );
|
1998-05-29 11:53:54 +00:00
|
|
|
if( opt.with_colons ) {
|
2000-05-30 15:31:45 +00:00
|
|
|
if ( opt.fast_list_mode ) {
|
|
|
|
fputs( "pub::", stdout );
|
|
|
|
trustletter = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
trustletter = query_trust_info( pk, NULL );
|
|
|
|
if( trustletter == 'u' )
|
|
|
|
ulti_hack = 1;
|
|
|
|
printf("pub:%c:", trustletter );
|
|
|
|
}
|
|
|
|
printf("%u:%d:%08lX%08lX:%s:%s:",
|
1998-06-29 12:30:57 +00:00
|
|
|
nbits_from_pk( pk ),
|
|
|
|
pk->pubkey_algo,
|
1998-05-29 11:53:54 +00:00
|
|
|
(ulong)keyid[0],(ulong)keyid[1],
|
1998-06-29 12:30:57 +00:00
|
|
|
datestr_from_pk( pk ),
|
2000-05-30 15:31:45 +00:00
|
|
|
pk->expiredate? strtimestamp(pk->expiredate):"" );
|
1998-06-29 12:30:57 +00:00
|
|
|
if( pk->local_id )
|
|
|
|
printf("%lu", pk->local_id );
|
1998-05-29 11:53:54 +00:00
|
|
|
putchar(':');
|
2000-05-30 15:31:45 +00:00
|
|
|
if( pk->local_id && !opt.fast_list_mode )
|
1998-11-13 19:41:41 +00:00
|
|
|
putchar( get_ownertrust_info( pk->local_id ) );
|
1998-05-29 11:53:54 +00:00
|
|
|
putchar(':');
|
|
|
|
}
|
|
|
|
else
|
1998-06-29 12:30:57 +00:00
|
|
|
printf("pub %4u%c/%08lX %s ", nbits_from_pk( pk ),
|
|
|
|
pubkey_letter( pk->pubkey_algo ),
|
1998-05-29 11:53:54 +00:00
|
|
|
(ulong)keyid[1],
|
1998-06-29 12:30:57 +00:00
|
|
|
datestr_from_pk( pk ) );
|
1998-05-29 11:53:54 +00:00
|
|
|
}
|
1998-03-09 21:44:06 +00:00
|
|
|
|
|
|
|
for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) {
|
2000-05-30 15:31:45 +00:00
|
|
|
if( node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode ) {
|
1998-03-09 21:44:06 +00:00
|
|
|
if( any ) {
|
2000-05-30 15:31:45 +00:00
|
|
|
if ( opt.with_colons ) {
|
1999-03-08 19:50:18 +00:00
|
|
|
byte namehash[20];
|
|
|
|
|
1999-04-18 18:53:34 +00:00
|
|
|
if( pk && !ulti_hack ) {
|
2000-05-30 15:31:45 +00:00
|
|
|
if( node->pkt->pkt.user_id->photo )
|
|
|
|
rmd160_hash_buffer( namehash,
|
|
|
|
node->pkt->pkt.user_id->name,
|
|
|
|
node->pkt->pkt.user_id->len );
|
|
|
|
else
|
|
|
|
rmd160_hash_buffer( namehash,
|
|
|
|
node->pkt->pkt.user_id->name,
|
|
|
|
node->pkt->pkt.user_id->len );
|
1999-03-10 10:27:52 +00:00
|
|
|
trustletter = query_trust_info( pk, namehash );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
trustletter = 'u';
|
1999-03-08 19:50:18 +00:00
|
|
|
printf("uid:%c::::::::", trustletter);
|
|
|
|
}
|
1998-03-09 21:44:06 +00:00
|
|
|
else
|
|
|
|
printf("uid%*s", 28, "");
|
|
|
|
}
|
1999-08-31 15:30:12 +00:00
|
|
|
if( opt.with_colons ) {
|
|
|
|
print_string( stdout, node->pkt->pkt.user_id->name,
|
|
|
|
node->pkt->pkt.user_id->len, ':' );
|
1998-03-09 21:44:06 +00:00
|
|
|
putchar(':');
|
1999-08-31 15:30:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
print_utf8_string( stdout, node->pkt->pkt.user_id->name,
|
|
|
|
node->pkt->pkt.user_id->len );
|
|
|
|
|
1998-03-09 21:44:06 +00:00
|
|
|
putchar('\n');
|
|
|
|
if( !any ) {
|
|
|
|
if( opt.fingerprint )
|
1998-06-29 12:30:57 +00:00
|
|
|
fingerprint( pk, sk );
|
1999-06-08 11:41:46 +00:00
|
|
|
if( opt.with_key_data )
|
|
|
|
print_key_data( pk, keyid );
|
1998-03-09 21:44:06 +00:00
|
|
|
any = 1;
|
|
|
|
}
|
|
|
|
}
|
1998-06-29 12:30:57 +00:00
|
|
|
else if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
|
1998-04-02 10:30:03 +00:00
|
|
|
u32 keyid2[2];
|
1998-06-29 12:30:57 +00:00
|
|
|
PKT_public_key *pk2 = node->pkt->pkt.public_key;
|
1998-04-02 10:30:03 +00:00
|
|
|
|
|
|
|
if( !any ) {
|
|
|
|
putchar('\n');
|
|
|
|
if( opt.fingerprint )
|
1998-06-29 12:30:57 +00:00
|
|
|
fingerprint( pk, sk ); /* of the main key */
|
1998-04-02 10:30:03 +00:00
|
|
|
any = 1;
|
|
|
|
}
|
|
|
|
|
1998-07-29 19:35:05 +00:00
|
|
|
|
|
|
|
|
1998-06-29 12:30:57 +00:00
|
|
|
keyid_from_pk( pk2, keyid2 );
|
1998-05-29 11:53:54 +00:00
|
|
|
if( opt.with_colons ) {
|
2000-05-30 15:31:45 +00:00
|
|
|
if ( opt.fast_list_mode ) {
|
|
|
|
fputs( "sub::", stdout );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("sub:%c:", trustletter );
|
|
|
|
}
|
|
|
|
printf("%u:%d:%08lX%08lX:%s:%s:",
|
1998-06-29 12:30:57 +00:00
|
|
|
nbits_from_pk( pk2 ),
|
|
|
|
pk2->pubkey_algo,
|
1998-04-02 10:30:03 +00:00
|
|
|
(ulong)keyid2[0],(ulong)keyid2[1],
|
1998-06-29 12:30:57 +00:00
|
|
|
datestr_from_pk( pk2 ),
|
1998-10-16 16:00:17 +00:00
|
|
|
pk2->expiredate? strtimestamp(pk2->expiredate):""
|
1998-04-02 10:30:03 +00:00
|
|
|
/* fixme: add LID and ownertrust here */
|
|
|
|
);
|
1998-06-29 12:30:57 +00:00
|
|
|
if( pk->local_id ) /* use the local_id of the main key??? */
|
|
|
|
printf("%lu", pk->local_id );
|
1998-05-29 11:53:54 +00:00
|
|
|
putchar(':');
|
|
|
|
putchar(':');
|
|
|
|
putchar('\n');
|
|
|
|
}
|
2000-05-30 15:31:45 +00:00
|
|
|
else {
|
|
|
|
printf("sub %4u%c/%08lX %s", nbits_from_pk( pk2 ),
|
1998-06-29 12:30:57 +00:00
|
|
|
pubkey_letter( pk2->pubkey_algo ),
|
1998-04-02 10:30:03 +00:00
|
|
|
(ulong)keyid2[1],
|
1998-06-29 12:30:57 +00:00
|
|
|
datestr_from_pk( pk2 ) );
|
2000-05-30 15:31:45 +00:00
|
|
|
if( pk2->expiredate ) {
|
|
|
|
printf(_(" [expires: %s]"), expirestr_from_pk( pk2 ) );
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
}
|
1998-07-29 19:35:05 +00:00
|
|
|
if( opt.fingerprint > 1 )
|
|
|
|
fingerprint( pk2, NULL );
|
1999-06-08 11:41:46 +00:00
|
|
|
if( opt.with_key_data )
|
|
|
|
print_key_data( pk2, keyid2 );
|
1998-04-02 10:30:03 +00:00
|
|
|
}
|
1998-06-29 12:30:57 +00:00
|
|
|
else if( node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
|
1998-05-29 11:53:54 +00:00
|
|
|
u32 keyid2[2];
|
1998-06-29 12:30:57 +00:00
|
|
|
PKT_secret_key *sk2 = node->pkt->pkt.secret_key;
|
1998-05-29 11:53:54 +00:00
|
|
|
|
|
|
|
if( !any ) {
|
|
|
|
putchar('\n');
|
|
|
|
if( opt.fingerprint )
|
1998-06-29 12:30:57 +00:00
|
|
|
fingerprint( pk, sk ); /* of the main key */
|
1998-05-29 11:53:54 +00:00
|
|
|
any = 1;
|
|
|
|
}
|
|
|
|
|
1998-06-29 12:30:57 +00:00
|
|
|
keyid_from_sk( sk2, keyid2 );
|
1998-05-29 11:53:54 +00:00
|
|
|
if( opt.with_colons )
|
1998-10-16 16:00:17 +00:00
|
|
|
printf("ssb::%u:%d:%08lX%08lX:%s:%s:::\n",
|
1998-06-29 12:30:57 +00:00
|
|
|
nbits_from_sk( sk2 ),
|
|
|
|
sk2->pubkey_algo,
|
1998-05-29 11:53:54 +00:00
|
|
|
(ulong)keyid2[0],(ulong)keyid2[1],
|
1998-06-29 12:30:57 +00:00
|
|
|
datestr_from_sk( sk2 ),
|
1998-10-16 16:00:17 +00:00
|
|
|
sk2->expiredate? strtimestamp(sk2->expiredate):""
|
1998-05-29 11:53:54 +00:00
|
|
|
/* fixme: add LID */
|
|
|
|
);
|
|
|
|
else
|
1998-06-29 12:30:57 +00:00
|
|
|
printf("ssb %4u%c/%08lX %s\n", nbits_from_sk( sk2 ),
|
|
|
|
pubkey_letter( sk2->pubkey_algo ),
|
1998-05-29 11:53:54 +00:00
|
|
|
(ulong)keyid2[1],
|
1998-06-29 12:30:57 +00:00
|
|
|
datestr_from_sk( sk2 ) );
|
1998-07-29 19:35:05 +00:00
|
|
|
if( opt.fingerprint > 1 )
|
|
|
|
fingerprint( NULL, sk2 );
|
|
|
|
|
1998-05-29 11:53:54 +00:00
|
|
|
}
|
1998-03-09 21:44:06 +00:00
|
|
|
else if( opt.list_sigs && node->pkt->pkttype == PKT_SIGNATURE ) {
|
|
|
|
PKT_signature *sig = node->pkt->pkt.signature;
|
|
|
|
int sigrc;
|
2000-05-30 15:31:45 +00:00
|
|
|
char *sigstr;
|
1998-03-09 21:44:06 +00:00
|
|
|
|
|
|
|
if( !any ) { /* no user id, (maybe a revocation follows)*/
|
|
|
|
if( sig->sig_class == 0x20 )
|
|
|
|
puts("[revoked]");
|
1998-05-29 11:53:54 +00:00
|
|
|
else if( sig->sig_class == 0x18 )
|
|
|
|
puts("[key binding]");
|
1999-04-28 11:06:52 +00:00
|
|
|
else if( sig->sig_class == 0x28 )
|
|
|
|
puts("[subkey revoked]");
|
1998-03-09 21:44:06 +00:00
|
|
|
else
|
|
|
|
putchar('\n');
|
|
|
|
if( opt.fingerprint )
|
1998-06-29 12:30:57 +00:00
|
|
|
fingerprint( pk, sk );
|
1998-03-09 21:44:06 +00:00
|
|
|
any=1;
|
|
|
|
}
|
|
|
|
|
1999-04-28 11:06:52 +00:00
|
|
|
if( sig->sig_class == 0x20 || sig->sig_class == 0x28
|
|
|
|
|| sig->sig_class == 0x30 )
|
2000-05-30 15:31:45 +00:00
|
|
|
sigstr = "rev";
|
1998-03-09 21:44:06 +00:00
|
|
|
else if( (sig->sig_class&~3) == 0x10 )
|
2000-05-30 15:31:45 +00:00
|
|
|
sigstr = "sig";
|
1998-04-02 10:30:03 +00:00
|
|
|
else if( sig->sig_class == 0x18 )
|
2000-05-30 15:31:45 +00:00
|
|
|
sigstr = "sig";
|
1998-03-09 21:44:06 +00:00
|
|
|
else {
|
|
|
|
if( opt.with_colons )
|
1998-04-02 10:30:03 +00:00
|
|
|
printf("sig::::::::::%02x:\n",sig->sig_class );
|
1998-03-09 21:44:06 +00:00
|
|
|
else
|
1998-04-02 10:30:03 +00:00
|
|
|
printf("sig "
|
1998-03-09 21:44:06 +00:00
|
|
|
"[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: sigrc = '?'; break;
|
|
|
|
default: sigrc = '%'; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rc = 0;
|
|
|
|
sigrc = ' ';
|
|
|
|
}
|
2000-05-30 15:31:45 +00:00
|
|
|
fputs( sigstr, stdout );
|
1998-03-09 21:44:06 +00:00
|
|
|
if( opt.with_colons ) {
|
|
|
|
putchar(':');
|
|
|
|
if( sigrc != ' ' )
|
|
|
|
putchar(sigrc);
|
2000-05-30 15:31:45 +00:00
|
|
|
printf("::%d:%08lX%08lX:%s::::", sig->pubkey_algo,
|
|
|
|
(ulong)sig->keyid[0],
|
1998-03-09 21:44:06 +00:00
|
|
|
(ulong)sig->keyid[1], datestr_from_sig(sig));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("%c %08lX %s ",
|
|
|
|
sigrc, (ulong)sig->keyid[1], datestr_from_sig(sig));
|
|
|
|
if( sigrc == '%' )
|
|
|
|
printf("[%s] ", g10_errstr(rc) );
|
|
|
|
else if( sigrc == '?' )
|
|
|
|
;
|
2000-05-30 15:31:45 +00:00
|
|
|
else if ( !opt.fast_list_mode ) {
|
1998-03-09 21:44:06 +00:00
|
|
|
size_t n;
|
|
|
|
char *p = get_user_id( sig->keyid, &n );
|
1999-08-31 15:30:12 +00:00
|
|
|
if( opt.with_colons )
|
|
|
|
print_string( stdout, p, n, ':' );
|
|
|
|
else
|
|
|
|
print_utf8_string( stdout, p, n );
|
1998-03-09 21:44:06 +00:00
|
|
|
m_free(p);
|
|
|
|
}
|
|
|
|
if( opt.with_colons )
|
|
|
|
printf(":%02x:", sig->sig_class );
|
|
|
|
putchar('\n');
|
1998-06-09 15:14:06 +00:00
|
|
|
/* FIXME: check or list other sigs here (subpkt PRIV_ADD_SIG)*/
|
1998-03-09 21:44:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if( !any ) {/* oops, no user id */
|
|
|
|
if( opt.with_colons )
|
|
|
|
putchar(':');
|
|
|
|
putchar('\n');
|
|
|
|
}
|
1999-01-24 17:16:40 +00:00
|
|
|
else if( !opt.with_colons )
|
|
|
|
putchar('\n'); /* separator line */
|
1998-10-21 17:34:36 +00:00
|
|
|
}
|
1998-03-09 21:44:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
1998-06-29 12:30:57 +00:00
|
|
|
fingerprint( PKT_public_key *pk, PKT_secret_key *sk )
|
1998-03-09 21:44:06 +00:00
|
|
|
{
|
|
|
|
byte *array, *p;
|
|
|
|
size_t i, n;
|
|
|
|
|
1998-07-14 17:10:28 +00:00
|
|
|
p = array = pk? fingerprint_from_pk( pk, NULL, &n )
|
|
|
|
: fingerprint_from_sk( sk, NULL, &n );
|
1998-03-09 21:44:06 +00:00
|
|
|
if( opt.with_colons ) {
|
1998-04-02 10:30:03 +00:00
|
|
|
printf("fpr:::::::::");
|
1998-03-09 21:44:06 +00: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 09:22:13 +00:00
|
|
|
}
|
|
|
|
|