1998-03-05 10:22:13 +01:00
|
|
|
/* keylist.c
|
2003-06-15 04:54:09 +02:00
|
|
|
* Copyright (C) 1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc.
|
1998-03-05 10:22:13 +01:00
|
|
|
*
|
1998-12-23 13:41:40 +01:00
|
|
|
* This file is part of GnuPG.
|
1998-03-05 10:22:13 +01:00
|
|
|
*
|
1998-12-23 13:41:40 +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.
|
|
|
|
*
|
1998-12-23 13:41:40 +01:00
|
|
|
* 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"
|
2002-06-29 15:46:34 +02:00
|
|
|
#include "memory.h"
|
|
|
|
#include "photoid.h"
|
1998-03-05 10:22:13 +01:00
|
|
|
#include "util.h"
|
2002-06-29 15:46:34 +02:00
|
|
|
#include "ttyio.h"
|
1998-03-05 10:22:13 +01:00
|
|
|
#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"
|
2002-06-29 15:46:34 +02:00
|
|
|
#include "status.h"
|
1998-03-05 10:22:13 +01:00
|
|
|
|
1998-05-29 13:53:54 +02:00
|
|
|
static void list_all(int);
|
1999-01-24 18:16:40 +01:00
|
|
|
static void list_one( STRLIST names, int secret);
|
1998-03-09 22:44:06 +01:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
struct sig_stats
|
|
|
|
{
|
|
|
|
int inv_sigs;
|
|
|
|
int no_key;
|
|
|
|
int oth_err;
|
|
|
|
};
|
|
|
|
|
|
|
|
static FILE *attrib_fp=NULL;
|
1998-03-05 10:22:13 +01:00
|
|
|
|
|
|
|
/****************
|
1998-03-09 22:44:06 +01:00
|
|
|
* List the keys
|
2000-07-14 19:34:53 +02:00
|
|
|
* If list is NULL, all available keys are listed
|
1998-03-05 10:22:13 +01:00
|
|
|
*/
|
|
|
|
void
|
2000-07-14 19:34:53 +02:00
|
|
|
public_key_list( STRLIST list )
|
1998-03-05 10:22:13 +01:00
|
|
|
{
|
2003-07-21 18:51:59 +02:00
|
|
|
if(opt.with_colons)
|
|
|
|
{
|
|
|
|
byte trust_model;
|
|
|
|
ulong created,nextcheck;
|
|
|
|
|
|
|
|
read_trust_options(&trust_model,&created,&nextcheck);
|
|
|
|
|
|
|
|
printf("tru:");
|
|
|
|
|
|
|
|
if(nextcheck && nextcheck <= make_timestamp())
|
|
|
|
printf("o");
|
|
|
|
if(trust_model!=0)
|
|
|
|
printf("t");
|
|
|
|
|
|
|
|
/* We don't show marginals, completes, or cert_depth since
|
|
|
|
they are not accurate in 1.2.x - they are not updated when
|
|
|
|
the trustdb is rebuilt with different options. */
|
|
|
|
|
|
|
|
printf(":%d:%lu:%lu\n",trust_model,created,nextcheck);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !list )
|
|
|
|
list_all(0);
|
|
|
|
else
|
|
|
|
list_one( list, 0 );
|
1998-05-29 13:53:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-14 19:34:53 +02:00
|
|
|
secret_key_list( STRLIST list )
|
1998-05-29 13:53:54 +02:00
|
|
|
{
|
2000-07-14 19:34:53 +02:00
|
|
|
if( !list )
|
1998-05-29 13:53:54 +02:00
|
|
|
list_all(1);
|
2000-07-14 19:34:53 +02:00
|
|
|
else /* List by user id */
|
1999-02-24 11:12:32 +01:00
|
|
|
list_one( list, 1 );
|
1998-03-09 22:44:06 +01:00
|
|
|
}
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
void
|
|
|
|
show_policy_url(PKT_signature *sig,int indent)
|
|
|
|
{
|
|
|
|
const byte *p;
|
|
|
|
size_t len;
|
|
|
|
int seq=0,crit;
|
|
|
|
|
|
|
|
while((p=enum_sig_subpkt(sig->hashed,SIGSUBPKT_POLICY,&len,&seq,&crit)))
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i=0;i<indent;i++)
|
|
|
|
putchar(' ');
|
|
|
|
|
|
|
|
if(crit)
|
|
|
|
printf(_("Critical signature policy: "));
|
|
|
|
else
|
|
|
|
printf(_("Signature policy: "));
|
2003-08-31 05:37:17 +02:00
|
|
|
print_utf8_string(stdout,p,len);
|
2002-06-29 15:46:34 +02:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
show_notation(PKT_signature *sig,int indent)
|
|
|
|
{
|
|
|
|
const byte *p;
|
|
|
|
size_t len;
|
|
|
|
int seq=0,crit;
|
|
|
|
|
|
|
|
/* There may be multiple notations in the same sig. */
|
|
|
|
|
|
|
|
while((p=enum_sig_subpkt(sig->hashed,SIGSUBPKT_NOTATION,&len,&seq,&crit)))
|
|
|
|
if(len>=8)
|
|
|
|
{
|
|
|
|
int n1,n2,i;
|
|
|
|
|
|
|
|
n1=(p[4]<<8)|p[5];
|
|
|
|
n2=(p[6]<<8)|p[7];
|
|
|
|
|
|
|
|
if(8+n1+n2!=len)
|
|
|
|
{
|
|
|
|
log_info(_("WARNING: invalid notation data found\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0;i<indent;i++)
|
|
|
|
putchar(' ');
|
|
|
|
|
|
|
|
/* This is UTF8 */
|
|
|
|
if(crit)
|
|
|
|
printf(_("Critical signature notation: "));
|
|
|
|
else
|
|
|
|
printf(_("Signature notation: "));
|
|
|
|
print_utf8_string(stdout,p+8,n1);
|
|
|
|
printf("=");
|
|
|
|
|
|
|
|
if(*p&0x80)
|
|
|
|
print_utf8_string(stdout,p+8+n1,n2);
|
|
|
|
else
|
|
|
|
printf("[ %s ]",_("not human readable"));
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
log_info(_("WARNING: invalid notation data found\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_signature_stats(struct sig_stats *s)
|
|
|
|
{
|
|
|
|
if( s->inv_sigs == 1 )
|
|
|
|
tty_printf(_("1 bad signature\n") );
|
|
|
|
else if( s->inv_sigs )
|
|
|
|
tty_printf(_("%d bad signatures\n"), s->inv_sigs );
|
|
|
|
if( s->no_key == 1 )
|
|
|
|
tty_printf(_("1 signature not checked due to a missing key\n") );
|
|
|
|
else if( s->no_key )
|
|
|
|
tty_printf(_("%d signatures not checked due to missing keys\n"),s->no_key);
|
|
|
|
if( s->oth_err == 1 )
|
|
|
|
tty_printf(_("1 signature not checked due to an error\n") );
|
|
|
|
else if( s->oth_err )
|
|
|
|
tty_printf(_("%d signatures not checked due to errors\n"), s->oth_err );
|
|
|
|
}
|
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
|
|
|
{
|
2002-06-29 15:46:34 +02:00
|
|
|
KEYDB_HANDLE hd;
|
1998-10-21 19:34:36 +02:00
|
|
|
KBNODE keyblock = NULL;
|
|
|
|
int rc=0;
|
2002-06-29 15:46:34 +02:00
|
|
|
const char *lastresname, *resname;
|
|
|
|
struct sig_stats stats;
|
|
|
|
|
|
|
|
memset(&stats,0,sizeof(stats));
|
1998-10-21 19:34:36 +02:00
|
|
|
|
2002-06-29 15:46:34 +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 )
|
2002-06-29 15:46:34 +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
|
|
|
|
2002-06-29 15:46:34 +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;
|
|
|
|
}
|
2003-05-31 00:18:31 +02:00
|
|
|
if(!opt.with_colons)
|
|
|
|
{
|
|
|
|
resname = keydb_get_resource_name (hd);
|
|
|
|
if (lastresname != resname )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("%s\n", resname );
|
|
|
|
for(i=strlen(resname); i; i-- )
|
|
|
|
putchar('-');
|
|
|
|
putchar('\n');
|
|
|
|
lastresname = resname;
|
|
|
|
}
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
merge_keys_and_selfsig( keyblock );
|
|
|
|
list_keyblock( keyblock, secret, opt.fingerprint,
|
|
|
|
opt.check_sigs?&stats:NULL);
|
|
|
|
release_kbnode( keyblock );
|
|
|
|
keyblock = NULL;
|
|
|
|
} while (!(rc = keydb_search_next (hd)));
|
1998-10-21 19:34:36 +02:00
|
|
|
if( rc && rc != -1 )
|
2002-06-29 15:46:34 +02:00
|
|
|
log_error ("keydb_search_next failed: %s\n", g10_errstr(rc));
|
1998-10-21 19:34:36 +02:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
if(opt.check_sigs && !opt.with_colons)
|
|
|
|
print_signature_stats(&stats);
|
1998-03-09 22:44:06 +01:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
leave:
|
|
|
|
release_kbnode (keyblock);
|
|
|
|
keydb_release (hd);
|
2000-07-25 17:38:12 +02:00
|
|
|
}
|
|
|
|
|
1998-10-21 19:34:36 +02:00
|
|
|
|
1998-03-09 22:44:06 +01:00
|
|
|
static void
|
1999-01-24 18:16:40 +01:00
|
|
|
list_one( STRLIST names, int secret )
|
1998-03-09 22:44:06 +01:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
KBNODE keyblock = NULL;
|
1999-01-24 18:16:40 +01:00
|
|
|
GETKEY_CTX ctx;
|
2002-06-29 15:46:34 +02:00
|
|
|
const char *resname;
|
2003-05-31 00:18:31 +02:00
|
|
|
char *keyring_str = _("Keyring");
|
2002-06-29 15:46:34 +02:00
|
|
|
int i;
|
|
|
|
struct sig_stats stats;
|
1998-03-09 22:44:06 +01:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
memset(&stats,0,sizeof(stats));
|
|
|
|
|
|
|
|
/* fixme: using the bynames function has the disadvantage that we
|
|
|
|
* don't know wether one of the names given was not found. OTOH,
|
|
|
|
* this function has the advantage to list the names in the
|
|
|
|
* sequence as defined by the keyDB and does not duplicate
|
|
|
|
* outputs. A solution could be do test whether all given have
|
|
|
|
* been listed (this needs a way to use the keyDB search
|
|
|
|
* functions) or to have the search function return indicators for
|
|
|
|
* found names. Yet another way is to use the keydb search
|
|
|
|
* facilities directly. */
|
1998-11-08 18:23:14 +01:00
|
|
|
if( secret ) {
|
1999-01-24 18:16:40 +01:00
|
|
|
rc = get_seckey_bynames( &ctx, NULL, names, &keyblock );
|
1998-11-08 18:23:14 +01:00
|
|
|
if( rc ) {
|
2002-06-29 15:46:34 +02:00
|
|
|
log_error("error reading key: %s\n", g10_errstr(rc) );
|
1999-01-24 18:16:40 +01:00
|
|
|
get_seckey_end( ctx );
|
1998-11-08 18:23:14 +01:00
|
|
|
return;
|
|
|
|
}
|
1999-01-24 18:16:40 +01:00
|
|
|
do {
|
2003-05-31 00:18:31 +02:00
|
|
|
if (opt.show_keyring && !opt.with_colons) {
|
2002-06-29 15:46:34 +02:00
|
|
|
resname = keydb_get_resource_name (get_ctx_handle(ctx));
|
|
|
|
printf("%s: %s\n", keyring_str, resname);
|
|
|
|
for(i = strlen(resname) + strlen(keyring_str) + 2; i; i-- )
|
|
|
|
putchar('-');
|
|
|
|
putchar('\n');
|
|
|
|
}
|
2002-08-22 19:47:42 +02:00
|
|
|
list_keyblock( keyblock, 1, opt.fingerprint, NULL );
|
1999-01-24 18:16:40 +01:00
|
|
|
release_kbnode( keyblock );
|
|
|
|
} while( !get_seckey_next( ctx, NULL, &keyblock ) );
|
|
|
|
get_seckey_end( ctx );
|
1998-11-08 18:23:14 +01:00
|
|
|
}
|
|
|
|
else {
|
1999-01-24 18:16:40 +01:00
|
|
|
rc = get_pubkey_bynames( &ctx, NULL, names, &keyblock );
|
1998-11-08 18:23:14 +01:00
|
|
|
if( rc ) {
|
2002-06-29 15:46:34 +02:00
|
|
|
log_error("error reading key: %s\n", g10_errstr(rc) );
|
1998-11-08 18:23:14 +01:00
|
|
|
get_pubkey_end( ctx );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
do {
|
2003-05-31 00:18:31 +02:00
|
|
|
if (opt.show_keyring && !opt.with_colons) {
|
2002-06-29 15:46:34 +02:00
|
|
|
resname = keydb_get_resource_name (get_ctx_handle(ctx));
|
|
|
|
printf("%s: %s\n", keyring_str, resname);
|
|
|
|
for(i = strlen(resname) + strlen(keyring_str) + 2; i; i-- )
|
|
|
|
putchar('-');
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
list_keyblock( keyblock, 0, opt.fingerprint,
|
|
|
|
opt.check_sigs?&stats:NULL );
|
1998-11-08 18:23:14 +01:00
|
|
|
release_kbnode( keyblock );
|
|
|
|
} while( !get_pubkey_next( ctx, NULL, &keyblock ) );
|
|
|
|
get_pubkey_end( ctx );
|
1998-03-09 22:44:06 +01:00
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
if(opt.check_sigs && !opt.with_colons)
|
|
|
|
print_signature_stats(&stats);
|
1998-10-21 19:34:36 +02:00
|
|
|
}
|
1998-03-09 22:44:06 +01:00
|
|
|
|
1999-06-08 13:41:46 +02:00
|
|
|
static void
|
|
|
|
print_key_data( PKT_public_key *pk, u32 *keyid )
|
|
|
|
{
|
2000-07-14 19:34:53 +02:00
|
|
|
int n = pk ? pubkey_get_npkey( pk->pubkey_algo ) : 0;
|
1999-06-08 13:41:46 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i=0; i < n; i++ ) {
|
2002-06-29 15:46:34 +02:00
|
|
|
printf("pkd:%d:%u:", i, mpi_get_nbits( pk->pkey[i] ) );
|
1999-06-08 13:41:46 +02:00
|
|
|
mpi_print(stdout, pk->pkey[i], 1 );
|
|
|
|
putchar(':');
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
static void
|
|
|
|
print_capabilities (PKT_public_key *pk, PKT_secret_key *sk, KBNODE keyblock)
|
|
|
|
{
|
2002-10-07 20:20:28 +02:00
|
|
|
if(pk || (sk && sk->protect.s2k.mode!=1001))
|
|
|
|
{
|
|
|
|
unsigned int use = pk? pk->pubkey_usage : sk->pubkey_usage;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
2002-10-07 20:20:28 +02:00
|
|
|
if ( use & PUBKEY_USAGE_ENC )
|
2002-06-29 15:46:34 +02:00
|
|
|
putchar ('e');
|
2002-10-07 20:20:28 +02:00
|
|
|
|
|
|
|
if ( use & PUBKEY_USAGE_SIG )
|
|
|
|
{
|
|
|
|
putchar ('s');
|
|
|
|
if( pk? pk->is_primary : sk->is_primary )
|
|
|
|
putchar ('c');
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
2002-10-07 20:20:28 +02:00
|
|
|
|
2003-05-07 16:04:27 +02:00
|
|
|
if ( keyblock ) { /* figure out the usable capabilities */
|
2002-06-29 15:46:34 +02:00
|
|
|
KBNODE k;
|
2003-01-06 22:06:47 +01:00
|
|
|
int enc=0, sign=0, cert=0, disabled=0;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
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;
|
2003-01-06 22:06:47 +01:00
|
|
|
|
2003-05-07 16:04:27 +02:00
|
|
|
if(pk->is_primary)
|
2003-05-09 18:05:24 +02:00
|
|
|
disabled=pk_is_disabled(pk);
|
2003-01-06 22:06:47 +01:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
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 )
|
2002-10-03 19:40:10 +02:00
|
|
|
{
|
|
|
|
sign = 1;
|
2002-10-03 21:17:02 +02:00
|
|
|
if(pk->is_primary)
|
2002-10-03 19:40:10 +02:00
|
|
|
cert = 1;
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( k->pkt->pkttype == PKT_SECRET_KEY
|
|
|
|
|| k->pkt->pkttype == PKT_SECRET_SUBKEY ) {
|
|
|
|
sk = k->pkt->pkt.secret_key;
|
2002-10-03 21:17:02 +02:00
|
|
|
if ( sk->is_valid && !sk->is_revoked && !sk->has_expired
|
|
|
|
&& sk->protect.s2k.mode!=1001 ) {
|
2002-06-29 15:46:34 +02:00
|
|
|
if ( sk->pubkey_usage & PUBKEY_USAGE_ENC )
|
|
|
|
enc = 1;
|
|
|
|
if ( sk->pubkey_usage & PUBKEY_USAGE_SIG )
|
2002-10-03 19:40:10 +02:00
|
|
|
{
|
|
|
|
sign = 1;
|
2002-10-03 21:17:02 +02:00
|
|
|
if(sk->is_primary)
|
2002-10-03 19:40:10 +02:00
|
|
|
cert = 1;
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (enc)
|
|
|
|
putchar ('E');
|
|
|
|
if (sign)
|
|
|
|
putchar ('S');
|
|
|
|
if (cert)
|
|
|
|
putchar ('C');
|
2003-01-06 22:06:47 +01:00
|
|
|
if (disabled)
|
|
|
|
putchar ('D');
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
2003-01-06 22:06:47 +01:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
putchar(':');
|
|
|
|
}
|
|
|
|
|
2003-05-20 22:51:35 +02:00
|
|
|
void
|
|
|
|
dump_attribs(const PKT_user_id *uid,PKT_public_key *pk,PKT_secret_key *sk)
|
2002-06-29 15:46:34 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(!attrib_fp)
|
2003-05-20 22:51:35 +02:00
|
|
|
return;
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
for(i=0;i<uid->numattribs;i++)
|
|
|
|
{
|
|
|
|
if(is_status_enabled())
|
|
|
|
{
|
|
|
|
byte array[MAX_FINGERPRINT_LEN], *p;
|
|
|
|
char buf[(MAX_FINGERPRINT_LEN*2)+90];
|
|
|
|
size_t j,n;
|
|
|
|
|
|
|
|
if(pk)
|
|
|
|
fingerprint_from_pk( pk, array, &n );
|
|
|
|
else if(sk)
|
|
|
|
fingerprint_from_sk( sk, array, &n );
|
|
|
|
else
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
p = array;
|
|
|
|
for(j=0; j < n ; j++, p++ )
|
|
|
|
sprintf(buf+2*j, "%02X", *p );
|
|
|
|
|
|
|
|
sprintf(buf+strlen(buf)," %lu %u %u %u %lu %lu %u",
|
2002-07-01 18:47:22 +02:00
|
|
|
(ulong)uid->attribs[i].len,uid->attribs[i].type,i+1,
|
2002-06-29 15:46:34 +02:00
|
|
|
uid->numattribs,(ulong)uid->created,(ulong)uid->expiredate,
|
|
|
|
((uid->is_primary?0x01:0)|
|
|
|
|
(uid->is_revoked?0x02:0)|
|
|
|
|
(uid->is_expired?0x04:0)));
|
|
|
|
write_status_text(STATUS_ATTRIBUTE,buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
fwrite(uid->attribs[i].data,uid->attribs[i].len,1,attrib_fp);
|
|
|
|
}
|
|
|
|
}
|
1998-03-19 16:27:29 +01:00
|
|
|
|
1998-10-21 19:34:36 +02:00
|
|
|
static void
|
2002-06-29 15:46:34 +02:00
|
|
|
list_keyblock_print ( KBNODE keyblock, int secret, int fpr, void *opaque )
|
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;
|
2002-06-29 15:46:34 +02:00
|
|
|
struct sig_stats *stats=opaque;
|
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");
|
1999-02-10 17:22:40 +01:00
|
|
|
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 );
|
2002-10-02 23:56:03 +02:00
|
|
|
printf("sec%c %4u%c/%08lX %s ", (sk->protect.s2k.mode==1001)?'#':' ',
|
|
|
|
nbits_from_sk( sk ),
|
|
|
|
pubkey_letter( sk->pubkey_algo ),
|
|
|
|
(ulong)keyid[1],
|
|
|
|
datestr_from_sk( sk ) );
|
1998-05-29 13:53:54 +02:00
|
|
|
}
|
|
|
|
else {
|
1998-06-29 14:30:57 +02:00
|
|
|
pk = node->pkt->pkt.public_key;
|
|
|
|
sk = NULL;
|
|
|
|
keyid_from_pk( pk, keyid );
|
2002-06-29 15:46:34 +02:00
|
|
|
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 ) {
|
2002-07-26 00:59:25 +02:00
|
|
|
/* don't list revoked or expired 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 ||
|
|
|
|
node->pkt->pkt.user_id->is_expired ))
|
2002-06-29 15:46:34 +02:00
|
|
|
continue;
|
|
|
|
|
2003-05-20 22:51:35 +02:00
|
|
|
if(attrib_fp && node->pkt->pkt.user_id->attrib_data!=NULL)
|
|
|
|
dump_attribs(node->pkt->pkt.user_id,pk,sk);
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
if( any )
|
|
|
|
printf("uid%*s", 28, "");
|
|
|
|
|
|
|
|
if ( node->pkt->pkt.user_id->is_revoked )
|
|
|
|
fputs ("[revoked] ", stdout);
|
|
|
|
if ( node->pkt->pkt.user_id->is_expired )
|
|
|
|
fputs ("[expired] ", stdout);
|
|
|
|
print_utf8_string( stdout, node->pkt->pkt.user_id->name,
|
|
|
|
node->pkt->pkt.user_id->len );
|
|
|
|
putchar('\n');
|
|
|
|
if( !any ) {
|
|
|
|
if( fpr )
|
|
|
|
print_fingerprint( pk, sk, 0 );
|
|
|
|
if( opt.with_key_data )
|
|
|
|
print_key_data( pk, keyid );
|
|
|
|
any = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(opt.show_photos && node->pkt->pkt.user_id->attribs!=NULL)
|
|
|
|
show_photos(node->pkt->pkt.user_id->attribs,
|
|
|
|
node->pkt->pkt.user_id->numattribs,pk,sk);
|
|
|
|
}
|
|
|
|
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( fpr )
|
|
|
|
print_fingerprint( pk, sk, 0 ); /* 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( fpr > 1 )
|
|
|
|
print_fingerprint( pk2, NULL, 0 );
|
|
|
|
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( fpr )
|
|
|
|
print_fingerprint( pk, sk, 0 ); /* 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( fpr > 1 )
|
|
|
|
print_fingerprint( NULL, sk2, 0 );
|
|
|
|
}
|
|
|
|
else if( opt.list_sigs && node->pkt->pkttype == PKT_SIGNATURE ) {
|
|
|
|
PKT_signature *sig = node->pkt->pkt.signature;
|
|
|
|
int sigrc;
|
|
|
|
char *sigstr;
|
|
|
|
|
|
|
|
if( stats ) {
|
|
|
|
/*fflush(stdout);*/
|
|
|
|
rc = check_key_signature( keyblock, node, NULL );
|
|
|
|
switch( rc ) {
|
|
|
|
case 0: sigrc = '!'; break;
|
|
|
|
case G10ERR_BAD_SIGN: stats->inv_sigs++; sigrc = '-'; break;
|
|
|
|
case G10ERR_NO_PUBKEY:
|
|
|
|
case G10ERR_UNU_PUBKEY: stats->no_key++; continue;
|
|
|
|
default: stats->oth_err++; sigrc = '%'; break;
|
|
|
|
}
|
2002-08-20 14:45:57 +02:00
|
|
|
|
|
|
|
/* TODO: Make sure a cached sig record here still has
|
|
|
|
the pk that issued it. See also
|
|
|
|
keyedit.c:print_and_check_one_sig */
|
|
|
|
|
2000-07-14 19:34:53 +02:00
|
|
|
}
|
|
|
|
else {
|
2002-06-29 15:46:34 +02:00
|
|
|
rc = 0;
|
|
|
|
sigrc = ' ';
|
2000-07-14 19:34:53 +02:00
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
|
|
|
|
if( !any ) { /* no user id, (maybe a revocation follows)*/
|
|
|
|
/* Check if the pk is really revoked - there could be a
|
|
|
|
0x20 sig packet there even if we are not revoked
|
|
|
|
(say, if a revocation key issued the packet, but the
|
|
|
|
revocation key isn't present to verify it.) */
|
|
|
|
if( sig->sig_class == 0x20 && pk->is_revoked )
|
|
|
|
puts("[revoked]");
|
|
|
|
else if( sig->sig_class == 0x18 )
|
|
|
|
puts("[key binding]");
|
|
|
|
else if( sig->sig_class == 0x28 )
|
|
|
|
puts("[subkey revoked]");
|
|
|
|
else
|
|
|
|
putchar('\n');
|
|
|
|
if( fpr )
|
|
|
|
print_fingerprint( pk, sk, 0 );
|
|
|
|
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 if( sig->sig_class == 0x1F )
|
|
|
|
sigstr = "sig";
|
|
|
|
else {
|
|
|
|
printf("sig "
|
|
|
|
"[unexpected signature class 0x%02x]\n",sig->sig_class );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs( sigstr, stdout );
|
|
|
|
printf("%c%c %c%c%c%c%c %08lX %s ",
|
|
|
|
sigrc,(sig->sig_class-0x10>0 &&
|
|
|
|
sig->sig_class-0x10<4)?'0'+sig->sig_class-0x10:' ',
|
|
|
|
sig->flags.exportable?' ':'L',
|
|
|
|
sig->flags.revocable?' ':'R',
|
|
|
|
sig->flags.policy_url?'P':' ',
|
|
|
|
sig->flags.notation?'N':' ',
|
|
|
|
sig->flags.expired?'X':' ',
|
|
|
|
(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');
|
|
|
|
|
|
|
|
if(sig->flags.policy_url && opt.show_policy_url)
|
|
|
|
show_policy_url(sig,3);
|
|
|
|
|
|
|
|
if(sig->flags.notation && opt.show_notation)
|
|
|
|
show_notation(sig,3);
|
|
|
|
|
|
|
|
/* fixme: check or list other sigs here */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
list_keyblock_colon( KBNODE keyblock, int secret, int fpr )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* 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 );
|
2003-06-15 04:54:09 +02:00
|
|
|
printf("sec::%u:%d:%08lX%08lX:%s:%s:::",
|
2002-06-29 15:46:34 +02:00
|
|
|
nbits_from_sk( sk ),
|
|
|
|
sk->pubkey_algo,
|
|
|
|
(ulong)keyid[0],(ulong)keyid[1],
|
|
|
|
colon_datestr_from_sk( sk ),
|
|
|
|
colon_strtime (sk->expiredate)
|
|
|
|
/* fixme: add LID here */ );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pk = node->pkt->pkt.public_key;
|
|
|
|
sk = NULL;
|
|
|
|
keyid_from_pk( pk, keyid );
|
|
|
|
fputs( "pub:", stdout );
|
|
|
|
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 )
|
|
|
|
;
|
|
|
|
else {
|
|
|
|
trustletter = get_validity_info ( pk, NULL );
|
|
|
|
if( trustletter == 'u' )
|
|
|
|
ulti_hack = 1;
|
|
|
|
putchar(trustletter);
|
|
|
|
}
|
|
|
|
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],
|
2002-06-29 15:46:34 +02:00
|
|
|
colon_datestr_from_pk( pk ),
|
|
|
|
colon_strtime (pk->expiredate) );
|
|
|
|
if( pk->local_id )
|
|
|
|
printf("%lu", pk->local_id );
|
|
|
|
putchar(':');
|
|
|
|
if( !opt.fast_list_mode && !opt.no_expensive_trust_checks )
|
|
|
|
putchar( get_ownertrust_info(pk) );
|
1998-05-29 13:53:54 +02:00
|
|
|
putchar(':');
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (opt.fixed_list_mode) {
|
|
|
|
/* do not merge the first uid with the primary key */
|
|
|
|
putchar(':');
|
|
|
|
putchar(':');
|
|
|
|
print_capabilities (pk, sk, keyblock);
|
|
|
|
putchar('\n');
|
|
|
|
if( fpr )
|
|
|
|
print_fingerprint( pk, sk, 0 );
|
|
|
|
if( opt.with_key_data )
|
|
|
|
print_key_data( pk, keyid );
|
|
|
|
any = 1;
|
1998-05-29 13:53:54 +02:00
|
|
|
}
|
1998-03-09 22:44:06 +01:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
|
1998-03-09 22:44:06 +01:00
|
|
|
for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) {
|
2000-07-14 19:34:53 +02:00
|
|
|
if( node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode ) {
|
2002-06-29 15:46:34 +02:00
|
|
|
if(attrib_fp && node->pkt->pkt.user_id->attrib_data!=NULL)
|
|
|
|
dump_attribs(node->pkt->pkt.user_id,pk,sk);
|
|
|
|
/*
|
|
|
|
* Fixme: We need a is_valid flag here too
|
|
|
|
*/
|
1998-03-09 22:44:06 +01:00
|
|
|
if( any ) {
|
2002-06-29 15:46:34 +02:00
|
|
|
char *str=node->pkt->pkt.user_id->attrib_data?"uat":"uid";
|
2003-06-15 04:54:09 +02:00
|
|
|
/* If we're listing a secret key, leave out the
|
|
|
|
validity values for now. This is handled better in
|
|
|
|
1.9. */
|
|
|
|
if ( sk )
|
|
|
|
printf("%s:::::::::",str);
|
|
|
|
else if ( node->pkt->pkt.user_id->is_revoked )
|
2002-06-29 15:46:34 +02:00
|
|
|
printf("%s:r::::::::",str);
|
|
|
|
else if ( node->pkt->pkt.user_id->is_expired )
|
|
|
|
printf("%s:e::::::::",str);
|
2003-06-15 04:54:09 +02:00
|
|
|
else if ( opt.no_expensive_trust_checks )
|
2002-06-29 15:46:34 +02:00
|
|
|
printf("%s:::::::::",str);
|
|
|
|
else {
|
2002-11-13 14:14:40 +01:00
|
|
|
int uid_validity;
|
1999-03-08 20:50:18 +01:00
|
|
|
|
2003-01-09 05:04:55 +01:00
|
|
|
if( pk && !ulti_hack )
|
|
|
|
uid_validity=get_validity_info (pk,
|
|
|
|
node->pkt->pkt.user_id);
|
1999-03-10 11:27:52 +01:00
|
|
|
else
|
2002-11-13 14:14:40 +01:00
|
|
|
uid_validity = 'u';
|
|
|
|
printf("%s:%c::::::::",str,uid_validity);
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
1999-08-31 17:30:12 +02:00
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
if(node->pkt->pkt.user_id->attrib_data)
|
|
|
|
printf("%u %lu",
|
|
|
|
node->pkt->pkt.user_id->numattribs,
|
|
|
|
node->pkt->pkt.user_id->attrib_len);
|
|
|
|
else
|
|
|
|
print_string( stdout, node->pkt->pkt.user_id->name,
|
|
|
|
node->pkt->pkt.user_id->len, ':' );
|
|
|
|
putchar(':');
|
|
|
|
if (any)
|
|
|
|
putchar('\n');
|
|
|
|
else {
|
|
|
|
putchar(':');
|
|
|
|
print_capabilities (pk, sk, keyblock);
|
|
|
|
putchar('\n');
|
|
|
|
if( fpr )
|
|
|
|
print_fingerprint( pk, sk, 0 );
|
1999-06-08 13:41:46 +02:00
|
|
|
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 ) {
|
2002-06-29 15:46:34 +02:00
|
|
|
putchar(':');
|
|
|
|
putchar(':');
|
|
|
|
print_capabilities (pk, sk, keyblock);
|
|
|
|
putchar('\n');
|
|
|
|
if( fpr )
|
|
|
|
print_fingerprint( pk, sk, 0 ); /* 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 );
|
2002-06-29 15:46:34 +02: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 )
|
|
|
|
;
|
|
|
|
else {
|
2002-11-13 14:14:40 +01:00
|
|
|
/* trustletter should always be defined here */
|
|
|
|
if(trustletter)
|
|
|
|
printf("%c", trustletter );
|
2002-06-29 15:46:34 +02: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],
|
2002-06-29 15:46:34 +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 */
|
|
|
|
);
|
2002-06-29 15:46:34 +02:00
|
|
|
if( pk->local_id ) /* use the local_id of the main key??? */
|
|
|
|
printf("%lu", pk->local_id );
|
|
|
|
putchar(':');
|
|
|
|
putchar(':');
|
|
|
|
putchar(':');
|
|
|
|
putchar(':');
|
|
|
|
print_capabilities (pk2, NULL, NULL);
|
|
|
|
putchar('\n');
|
|
|
|
if( fpr > 1 )
|
|
|
|
print_fingerprint( pk2, NULL, 0 );
|
1999-06-08 13:41:46 +02:00
|
|
|
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 ) {
|
2002-06-29 15:46:34 +02:00
|
|
|
putchar(':');
|
|
|
|
putchar(':');
|
|
|
|
print_capabilities (pk, sk, keyblock);
|
1998-05-29 13:53:54 +02:00
|
|
|
putchar('\n');
|
2002-06-29 15:46:34 +02:00
|
|
|
if( fpr )
|
|
|
|
print_fingerprint( pk, sk, 0 ); /* 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 );
|
2002-06-29 15:46:34 +02: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],
|
2002-06-29 15:46:34 +02:00
|
|
|
colon_datestr_from_sk( sk2 ),
|
|
|
|
colon_strtime (sk2->expiredate)
|
|
|
|
/* fixme: add LID */ );
|
|
|
|
print_capabilities (NULL, sk2, NULL);
|
|
|
|
putchar ('\n');
|
|
|
|
if( fpr > 1 )
|
|
|
|
print_fingerprint( NULL, sk2, 0 );
|
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;
|
2002-06-29 15:46:34 +02: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 )
|
2002-06-29 15:46:34 +02:00
|
|
|
fputs("[revoked]:", stdout);
|
1998-05-29 13:53:54 +02:00
|
|
|
else if( sig->sig_class == 0x18 )
|
2002-06-29 15:46:34 +02:00
|
|
|
fputs("[key binding]:", stdout);
|
1999-04-28 13:06:52 +02:00
|
|
|
else if( sig->sig_class == 0x28 )
|
2002-06-29 15:46:34 +02:00
|
|
|
fputs("[subkey revoked]:", stdout);
|
|
|
|
else
|
|
|
|
putchar (':');
|
|
|
|
putchar(':');
|
|
|
|
print_capabilities (pk, sk, keyblock);
|
|
|
|
putchar('\n');
|
|
|
|
if( fpr )
|
|
|
|
print_fingerprint( pk, sk, 0 );
|
1998-03-09 22:44:06 +01:00
|
|
|
any=1;
|
|
|
|
}
|
|
|
|
|
1999-04-28 13:06:52 +02:00
|
|
|
if( sig->sig_class == 0x20 || sig->sig_class == 0x28
|
|
|
|
|| sig->sig_class == 0x30 )
|
2000-07-14 19:34:53 +02:00
|
|
|
sigstr = "rev";
|
1998-03-09 22:44:06 +01:00
|
|
|
else if( (sig->sig_class&~3) == 0x10 )
|
2000-07-14 19:34:53 +02:00
|
|
|
sigstr = "sig";
|
1998-04-02 12:30:03 +02:00
|
|
|
else if( sig->sig_class == 0x18 )
|
2000-07-14 19:34:53 +02:00
|
|
|
sigstr = "sig";
|
2002-09-19 18:32:44 +02:00
|
|
|
else if( sig->sig_class == 0x1F )
|
|
|
|
sigstr = "sig";
|
1998-03-09 22:44:06 +01:00
|
|
|
else {
|
2002-06-29 15:46:34 +02:00
|
|
|
printf ("sig::::::::::%02x%c:\n",
|
|
|
|
sig->sig_class, sig->flags.exportable?'x':'l');
|
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;
|
2002-06-29 15:46:34 +02:00
|
|
|
case G10ERR_BAD_SIGN: sigrc = '-'; break;
|
|
|
|
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 = ' ';
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
fputs( sigstr, stdout );
|
|
|
|
putchar(':');
|
|
|
|
if( sigrc != ' ' )
|
|
|
|
putchar(sigrc);
|
|
|
|
printf("::%d:%08lX%08lX:%s:%s:::", sig->pubkey_algo,
|
1999-11-13 17:43:23 +01:00
|
|
|
(ulong)sig->keyid[0],
|
2002-06-29 15:46:34 +02:00
|
|
|
(ulong)sig->keyid[1], colon_datestr_from_sig(sig),
|
|
|
|
colon_expirestr_from_sig(sig));
|
1998-03-09 22:44:06 +01:00
|
|
|
if( sigrc == '%' )
|
2002-06-29 15:46:34 +02:00
|
|
|
printf("[%s] ", g10_errstr(rc) );
|
1998-03-09 22:44:06 +01:00
|
|
|
else if( sigrc == '?' )
|
|
|
|
;
|
2000-07-14 19:34:53 +02:00
|
|
|
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 );
|
2002-06-29 15:46:34 +02:00
|
|
|
print_string( stdout, p, n, ':' );
|
|
|
|
m_free(p);
|
1998-03-09 22:44:06 +01:00
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
printf(":%02x%c:\n", sig->sig_class,sig->flags.exportable?'x':'l');
|
|
|
|
/* fixme: check or list other sigs here */
|
1998-03-09 22:44:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if( !any ) {/* oops, no user id */
|
2002-06-29 15:46:34 +02:00
|
|
|
putchar(':');
|
|
|
|
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
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
/*
|
|
|
|
* Reorder the keyblock so that the primary user ID (and not attribute
|
|
|
|
* packet) comes first. Fixme: Replace this by a generic sort
|
|
|
|
* function. */
|
2002-12-03 19:10:10 +01:00
|
|
|
void
|
2002-06-29 15:46:34 +02:00
|
|
|
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->attrib_data &&
|
|
|
|
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
|
|
|
|
2002-06-29 15:46:34 +02: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 */
|
1998-03-09 22:44:06 +01:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
last->next = primary;
|
|
|
|
primary0->next = primary2->next;
|
|
|
|
primary2->next = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
list_keyblock( KBNODE keyblock, int secret, int fpr, void *opaque )
|
1998-03-09 22:44:06 +01:00
|
|
|
{
|
2002-06-29 15:46:34 +02:00
|
|
|
reorder_keyblock (keyblock);
|
|
|
|
if (opt.with_colons)
|
|
|
|
list_keyblock_colon (keyblock, secret, fpr );
|
|
|
|
else
|
|
|
|
list_keyblock_print (keyblock, secret, fpr, opaque );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* standard function to print the finperprint.
|
|
|
|
* mode 0: as used in key listings, opt.with_colons is honored
|
|
|
|
* 1: print using log_info ()
|
|
|
|
* 2: direct use of tty
|
2002-08-19 10:28:00 +02:00
|
|
|
* 3: direct use of tty but only primary key.
|
2002-07-23 20:42:18 +02:00
|
|
|
* modes 1 and 2 will try and print both subkey and primary key fingerprints
|
2002-06-29 15:46:34 +02:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
print_fingerprint (PKT_public_key *pk, PKT_secret_key *sk, int mode )
|
|
|
|
{
|
|
|
|
byte array[MAX_FINGERPRINT_LEN], *p;
|
1998-03-09 22:44:06 +01:00
|
|
|
size_t i, n;
|
2002-06-29 15:46:34 +02:00
|
|
|
FILE *fp;
|
|
|
|
const char *text;
|
2002-07-23 20:42:18 +02:00
|
|
|
int primary=0;
|
|
|
|
|
|
|
|
if(sk)
|
|
|
|
{
|
|
|
|
if(sk->main_keyid[0]==sk->keyid[0] && sk->main_keyid[1]==sk->keyid[1])
|
|
|
|
primary=1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(pk->main_keyid[0]==pk->keyid[0] && pk->main_keyid[1]==pk->keyid[1])
|
|
|
|
primary=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Just to be safe */
|
|
|
|
if(mode&0x80 && !primary)
|
|
|
|
{
|
|
|
|
log_error("primary key is not really primary!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode&=~0x80;
|
|
|
|
|
|
|
|
if(!primary && (mode==1 || mode==2))
|
|
|
|
{
|
|
|
|
if(sk)
|
|
|
|
{
|
|
|
|
PKT_secret_key *primary_sk=m_alloc_clear(sizeof(*primary_sk));
|
|
|
|
get_seckey(primary_sk,sk->main_keyid);
|
|
|
|
print_fingerprint(NULL,primary_sk,mode|0x80);
|
|
|
|
free_secret_key(primary_sk);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PKT_public_key *primary_pk=m_alloc_clear(sizeof(*primary_pk));
|
|
|
|
get_pubkey(primary_pk,pk->main_keyid);
|
|
|
|
print_fingerprint(primary_pk,NULL,mode|0x80);
|
|
|
|
free_public_key(primary_pk);
|
|
|
|
}
|
|
|
|
}
|
1998-03-09 22:44:06 +01:00
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
if (mode == 1) {
|
|
|
|
fp = log_stream ();
|
2002-07-23 20:42:18 +02:00
|
|
|
if(primary)
|
|
|
|
text = _("Primary key fingerprint:");
|
|
|
|
else
|
|
|
|
text = _(" Subkey fingerprint:");
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
else if (mode == 2) {
|
|
|
|
fp = NULL; /* use tty */
|
|
|
|
/* Translators: this should fit into 24 bytes to that the fingerprint
|
|
|
|
* data is properly aligned with the user ID */
|
2002-07-23 20:42:18 +02:00
|
|
|
if(primary)
|
|
|
|
text = _(" Primary key fingerprint:");
|
|
|
|
else
|
|
|
|
text = _(" Subkey fingerprint:");
|
1998-03-09 22:44:06 +01:00
|
|
|
}
|
2002-08-19 10:28:00 +02:00
|
|
|
else if (mode == 3) {
|
|
|
|
fp = NULL; /* use tty */
|
|
|
|
text = _(" Key fingerprint =");
|
|
|
|
}
|
1998-03-09 22:44:06 +01:00
|
|
|
else {
|
2002-06-29 15:46:34 +02:00
|
|
|
fp = stdout;
|
2002-07-23 20:42:18 +02:00
|
|
|
text = _(" Key fingerprint =");
|
2002-06-29 15:46:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sk)
|
|
|
|
fingerprint_from_sk (sk, array, &n);
|
|
|
|
else
|
|
|
|
fingerprint_from_pk (pk, array, &n);
|
|
|
|
p = array;
|
|
|
|
if (opt.with_colons && !mode) {
|
|
|
|
fprintf (fp, "fpr:::::::::");
|
|
|
|
for (i=0; i < n ; i++, p++ )
|
|
|
|
fprintf (fp, "%02X", *p );
|
|
|
|
putc(':', fp);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (fp)
|
|
|
|
fputs (text, fp);
|
|
|
|
else
|
|
|
|
tty_printf ("%s", text);
|
|
|
|
if (n == 20) {
|
|
|
|
for (i=0; i < n ; i++, i++, p += 2 ) {
|
|
|
|
if (fp) {
|
|
|
|
if (i == 10 )
|
|
|
|
putc(' ', fp);
|
|
|
|
fprintf (fp, " %02X%02X", *p, p[1] );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (i == 10 )
|
|
|
|
tty_printf (" ");
|
|
|
|
tty_printf (" %02X%02X", *p, p[1]);
|
|
|
|
}
|
1998-03-09 22:44:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2002-06-29 15:46:34 +02:00
|
|
|
for (i=0; i < n ; i++, p++ ) {
|
|
|
|
if (fp) {
|
|
|
|
if (i && !(i%8) )
|
|
|
|
putc (' ', fp);
|
|
|
|
fprintf (fp, " %02X", *p );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (i && !(i%8) )
|
|
|
|
tty_printf (" ");
|
|
|
|
tty_printf (" %02X", *p );
|
|
|
|
}
|
1998-03-09 22:44:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-29 15:46:34 +02:00
|
|
|
if (fp)
|
|
|
|
putc ('\n', fp);
|
|
|
|
else
|
|
|
|
tty_printf ("\n");
|
1998-03-05 10:22:13 +01:00
|
|
|
}
|
|
|
|
|
2002-06-29 15:46:34 +02:00
|
|
|
void set_attrib_fd(int fd)
|
|
|
|
{
|
|
|
|
static int last_fd=-1;
|
|
|
|
|
|
|
|
if ( fd != -1 && last_fd == fd )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( attrib_fp && attrib_fp != stdout && attrib_fp != stderr )
|
|
|
|
fclose (attrib_fp);
|
|
|
|
attrib_fp = NULL;
|
|
|
|
if ( fd == -1 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( fd == 1 )
|
|
|
|
attrib_fp = stdout;
|
|
|
|
else if( fd == 2 )
|
|
|
|
attrib_fp = stderr;
|
|
|
|
else
|
2004-01-06 05:33:09 +01:00
|
|
|
attrib_fp = fdopen( fd, "wb" );
|
2002-06-29 15:46:34 +02:00
|
|
|
if( !attrib_fp ) {
|
|
|
|
log_fatal("can't open fd %d for attribute output: %s\n",
|
|
|
|
fd, strerror(errno));
|
|
|
|
}
|
|
|
|
last_fd = fd;
|
|
|
|
}
|