aboutsummaryrefslogtreecommitdiffstats
path: root/g10/keylist.c
diff options
context:
space:
mode:
Diffstat (limited to 'g10/keylist.c')
-rw-r--r--g10/keylist.c151
1 files changed, 113 insertions, 38 deletions
diff --git a/g10/keylist.c b/g10/keylist.c
index ce4d65aa4..554fb1f9c 100644
--- a/g10/keylist.c
+++ b/g10/keylist.c
@@ -35,9 +35,9 @@
#include "main.h"
#include "i18n.h"
-static void list_all(void);
-static void list_one(const char *name);
-static void fingerprint( PKT_public_cert *pkc );
+static void list_all(int);
+static void list_one(const char *name, int secret);
+static void fingerprint( PKT_public_cert *pkc, PKT_secret_cert *skc );
/****************
@@ -45,25 +45,36 @@ static void fingerprint( PKT_public_cert *pkc );
* If NNAMES is 0; all available keys are listed
*/
void
-std_key_list( int nnames, char **names )
+public_key_list( int nnames, char **names )
{
if( !nnames )
- list_all();
+ list_all(0);
else { /* List by user id */
for( ; nnames ; nnames--, names++ )
- list_one( *names );
+ list_one( *names, 0 );
+ }
+}
+
+void
+secret_key_list( int nnames, char **names )
+{
+ if( !nnames )
+ list_all(1);
+ else { /* List by user id */
+ for( ; nnames ; nnames--, names++ )
+ list_one( *names, 1 );
}
}
static void
-list_all()
+list_all( int secret )
{
int i, seq=0;
const char *s;
IOBUF a;
- while( (s=get_keyring(seq++)) ) {
+ while( (s=secret? get_secret_keyring(seq++):get_keyring(seq++)) ) {
if( !(a = iobuf_open(s)) ) {
log_error(_("can't open %s: %s\n"), s, strerror(errno));
continue;
@@ -80,9 +91,8 @@ list_all()
}
}
-
static void
-list_one( const char *name )
+list_one( const char *name, int secret )
{
int rc = 0;
KBNODE keyblock = NULL;
@@ -90,11 +100,14 @@ list_one( const char *name )
KBNODE node;
KBPOS kbpos;
PKT_public_cert *pkc;
+ PKT_secret_cert *skc;
u32 keyid[2];
int any=0;
+ int trustletter = 0;
/* search the userid */
- rc = find_keyblock_byname( &kbpos, name );
+ rc = secret? find_secret_keyblock_byname( &kbpos, name )
+ : find_keyblock_byname( &kbpos, name );
if( rc ) {
log_error("%s: user not found\n", name );
goto leave;
@@ -109,29 +122,55 @@ list_one( const char *name )
/* get the keyid from the keyblock */
- node = find_kbnode( keyblock, PKT_PUBLIC_CERT );
+ node = find_kbnode( keyblock, secret? PKT_SECRET_CERT : PKT_PUBLIC_CERT );
if( !node ) {
- log_error("Oops; public key lost!\n");
+ log_error("Oops; key lost!\n");
goto leave;
}
- pkc = node->pkt->pkt.public_cert;
- keyid_from_pkc( pkc, keyid );
- if( opt.with_colons )
- printf("pub::%u:%d:%08lX%08lX:%s:%u:::",
- /* fixme: add trust value here */
- nbits_from_pkc( pkc ),
- pkc->pubkey_algo,
- (ulong)keyid[0],(ulong)keyid[1],
- datestr_from_pkc( pkc ),
- (unsigned)pkc->valid_days
- /* fixme: add LID and ownertrust here */
- );
- else
- printf("pub %4u%c/%08lX %s ", nbits_from_pkc( pkc ),
- pubkey_letter( pkc->pubkey_algo ),
- (ulong)keyid[1],
- datestr_from_pkc( pkc ) );
+ if( secret ) {
+ pkc = NULL;
+ skc = node->pkt->pkt.secret_cert;
+ keyid_from_skc( skc, keyid );
+ if( opt.with_colons )
+ printf("sec::%u:%d:%08lX%08lX:%s:%u:::",
+ nbits_from_skc( skc ),
+ skc->pubkey_algo,
+ (ulong)keyid[0],(ulong)keyid[1],
+ datestr_from_skc( skc ),
+ (unsigned)skc->valid_days
+ /* fixme: add LID here */ );
+ else
+ printf("sec %4u%c/%08lX %s ", nbits_from_skc( skc ),
+ pubkey_letter( skc->pubkey_algo ),
+ (ulong)keyid[1],
+ datestr_from_skc( skc ) );
+ }
+ else {
+ pkc = node->pkt->pkt.public_cert;
+ skc = NULL;
+ keyid_from_pkc( pkc, keyid );
+ if( opt.with_colons ) {
+ trustletter = query_trust_info( pkc );
+ printf("pub:%c:%u:%d:%08lX%08lX:%s:%u:",
+ trustletter,
+ nbits_from_pkc( pkc ),
+ pkc->pubkey_algo,
+ (ulong)keyid[0],(ulong)keyid[1],
+ datestr_from_pkc( pkc ),
+ (unsigned)pkc->valid_days );
+ if( pkc->local_id )
+ printf("%lu", pkc->local_id );
+ putchar(':');
+ /* fixme: add ownertrust here */
+ putchar(':');
+ }
+ else
+ printf("pub %4u%c/%08lX %s ", nbits_from_pkc( pkc ),
+ pubkey_letter( pkc->pubkey_algo ),
+ (ulong)keyid[1],
+ datestr_from_pkc( pkc ) );
+ }
for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) {
if( node->pkt->pkttype == PKT_USER_ID ) {
@@ -148,7 +187,7 @@ list_one( const char *name )
putchar('\n');
if( !any ) {
if( opt.fingerprint )
- fingerprint( pkc );
+ fingerprint( pkc, skc );
any = 1;
}
}
@@ -159,14 +198,14 @@ list_one( const char *name )
if( !any ) {
putchar('\n');
if( opt.fingerprint )
- fingerprint( pkc ); /* of the main key */
+ fingerprint( pkc, skc ); /* of the main key */
any = 1;
}
keyid_from_pkc( pkc2, keyid2 );
- if( opt.with_colons )
- printf("sub::%u:%d:%08lX%08lX:%s:%u:::\n",
- /* fixme: add trust value here */
+ if( opt.with_colons ) {
+ printf("sub:%c:%u:%d:%08lX%08lX:%s:%u:",
+ trustletter,
nbits_from_pkc( pkc2 ),
pkc2->pubkey_algo,
(ulong)keyid2[0],(ulong)keyid2[1],
@@ -174,12 +213,45 @@ list_one( const char *name )
(unsigned)pkc2->valid_days
/* fixme: add LID and ownertrust here */
);
+ if( pkc->local_id ) /* use the local_id of the main key??? */
+ printf("%lu", pkc->local_id );
+ putchar(':');
+ putchar(':');
+ putchar('\n');
+ }
else
printf("sub %4u%c/%08lX %s\n", nbits_from_pkc( pkc2 ),
pubkey_letter( pkc2->pubkey_algo ),
(ulong)keyid2[1],
datestr_from_pkc( pkc2 ) );
}
+ else if( node->pkt->pkttype == PKT_SECKEY_SUBCERT ) {
+ u32 keyid2[2];
+ PKT_secret_cert *skc2 = node->pkt->pkt.secret_cert;
+
+ if( !any ) {
+ putchar('\n');
+ if( opt.fingerprint )
+ fingerprint( pkc, skc ); /* of the main key */
+ any = 1;
+ }
+
+ keyid_from_skc( skc2, keyid2 );
+ if( opt.with_colons )
+ printf("ssb::%u:%d:%08lX%08lX:%s:%u:::\n",
+ nbits_from_skc( skc2 ),
+ skc2->pubkey_algo,
+ (ulong)keyid2[0],(ulong)keyid2[1],
+ datestr_from_skc( skc2 ),
+ (unsigned)skc2->valid_days
+ /* fixme: add LID */
+ );
+ else
+ printf("ssb %4u%c/%08lX %s\n", nbits_from_skc( skc2 ),
+ pubkey_letter( skc2->pubkey_algo ),
+ (ulong)keyid2[1],
+ datestr_from_skc( skc2 ) );
+ }
else if( opt.list_sigs && node->pkt->pkttype == PKT_SIGNATURE ) {
PKT_signature *sig = node->pkt->pkt.signature;
int sigrc;
@@ -187,10 +259,12 @@ list_one( const char *name )
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
putchar('\n');
if( opt.fingerprint )
- fingerprint( pkc );
+ fingerprint( pkc, skc );
any=1;
}
@@ -259,12 +333,13 @@ list_one( const char *name )
}
static void
-fingerprint( PKT_public_cert *pkc )
+fingerprint( PKT_public_cert *pkc, PKT_secret_cert *skc )
{
byte *array, *p;
size_t i, n;
- p = array = fingerprint_from_pkc( pkc, &n );
+ p = array = pkc? fingerprint_from_pkc( pkc, &n )
+ : fingerprint_from_skc( skc, &n );
if( opt.with_colons ) {
printf("fpr:::::::::");
for(i=0; i < n ; i++, p++ )