~ubuntu-branches/ubuntu/oneiric/gnupg2/oneiric-updates

« back to all changes in this revision

Viewing changes to g10/keylist.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* keylist.c - List all or selected keys
2
 
 * Copyright (C) 1998, 1999, 2000, 2001, 2002,
3
 
 *               2003 Free Software Foundation, Inc.
 
1
/* keylist.c - print keys
 
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003,
 
3
 *               2004, 2005 Free Software Foundation, Inc.
4
4
 *
5
5
 * This file is part of GnuPG.
6
6
 *
7
7
 * GnuPG is free software; you can redistribute it and/or modify
8
8
 * it under the terms of the GNU General Public License as published by
9
 
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * the Free Software Foundation; either version 3 of the License, or
10
10
 * (at your option) any later version.
11
11
 *
12
12
 * GnuPG is distributed in the hope that it will be useful,
15
15
 * GNU General Public License for more details.
16
16
 *
17
17
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program; if not, write to the Free Software
19
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
18
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20
19
 */
21
20
 
22
21
#include <config.h>
26
25
#include <errno.h>
27
26
#include <assert.h>
28
27
 
 
28
#include "gpg.h"
29
29
#include "options.h"
30
30
#include "packet.h"
31
 
#include "errors.h"
 
31
#include "status.h"
32
32
#include "keydb.h"
33
 
#include "memory.h"
34
33
#include "photoid.h"
35
34
#include "util.h"
36
35
#include "ttyio.h"
40
39
#include "status.h"
41
40
 
42
41
static void list_all(int);
43
 
static void list_one( STRLIST names, int secret);
 
42
static void list_one( strlist_t names, int secret);
44
43
static void print_card_serialno (PKT_secret_key *sk);
45
44
 
46
45
struct sig_stats
57
56
 * If list is NULL, all available keys are listed
58
57
 */
59
58
void
60
 
public_key_list( STRLIST list )
 
59
public_key_list( strlist_t list )
61
60
{
62
61
  if(opt.with_colons)
63
62
    {
95
94
      printf("\n");
96
95
    }
97
96
 
 
97
  /* We need to do the stale check right here because it might need to
 
98
     update the keyring while we already have the keyring open.  This
 
99
     is very bad for W32 because of a sharing violation. For real OSes
 
100
     it might lead to false results if we are later listing a keyring
 
101
     which is associated with the inode of a deleted file.  */
 
102
  check_trustdb_stale ();
 
103
 
98
104
  if( !list )
99
105
    list_all(0);
100
106
  else
102
108
}
103
109
 
104
110
void
105
 
secret_key_list( STRLIST list )
 
111
secret_key_list( strlist_t list )
106
112
{
 
113
    check_trustdb_stale ();
 
114
 
107
115
    if( !list )
108
116
        list_all(1);
109
117
    else  /* List by user id */
113
121
void
114
122
print_seckey_info (PKT_secret_key *sk)
115
123
{
116
 
    u32 sk_keyid[2];
117
 
    size_t n;
118
 
    char *p;
119
 
 
120
 
    keyid_from_sk (sk, sk_keyid);
121
 
    tty_printf ("\nsec  %4u%c/%08lX %s   ",
122
 
                nbits_from_sk (sk),
123
 
                pubkey_letter (sk->pubkey_algo),
124
 
                (ulong)sk_keyid[1], datestr_from_sk (sk));
 
124
  u32 keyid[2];
 
125
  char *p;
 
126
 
 
127
  keyid_from_sk (sk, keyid);
 
128
  p=get_user_id_native(keyid);
 
129
 
 
130
  tty_printf ("\nsec  %4u%c/%s %s %s\n",
 
131
              nbits_from_sk (sk),
 
132
              pubkey_letter (sk->pubkey_algo),
 
133
              keystr(keyid), datestr_from_sk (sk), p);
125
134
    
126
 
    p = get_user_id (sk_keyid, &n);
127
 
    tty_print_utf8_string (p, n);
128
 
    xfree (p);
129
 
 
130
 
    tty_printf ("\n");   
 
135
  xfree (p);
131
136
}
132
137
 
133
138
/* Print information about the public key.  With FP passed as NULL,
136
141
void
137
142
print_pubkey_info (FILE *fp, PKT_public_key *pk)
138
143
{
139
 
  u32 pk_keyid[2];
140
 
  size_t n;
 
144
  u32 keyid[2];
141
145
  char *p;
142
146
 
143
 
  keyid_from_pk (pk, pk_keyid);
 
147
  keyid_from_pk (pk, keyid);
 
148
 
 
149
  /* If the pk was chosen by a particular user ID, that is the one to
 
150
     print. */
 
151
  if(pk->user_id)
 
152
    p=utf8_to_native(pk->user_id->name,pk->user_id->len,0);
 
153
  else
 
154
    p=get_user_id_native(keyid);
 
155
 
144
156
  if (fp)
145
 
    fprintf (fp, "pub  %4u%c/%08lX %s   ",
 
157
    fprintf (fp, "pub  %4u%c/%s %s %s\n",
146
158
             nbits_from_pk (pk),
147
159
             pubkey_letter (pk->pubkey_algo),
148
 
             (ulong)pk_keyid[1], datestr_from_pk (pk));
 
160
             keystr(keyid), datestr_from_pk (pk), p);
149
161
  else
150
 
    tty_printf ("\npub  %4u%c/%08lX %s   ",
151
 
                nbits_from_pk (pk),
152
 
                pubkey_letter (pk->pubkey_algo),
153
 
                (ulong)pk_keyid[1], datestr_from_pk (pk));
 
162
    tty_printf ("\npub  %4u%c/%s %s %s\n",
 
163
                nbits_from_pk (pk), pubkey_letter (pk->pubkey_algo),
 
164
                keystr(keyid), datestr_from_pk (pk), p);
154
165
 
155
 
  p = get_user_id (pk_keyid, &n);
156
 
  if (fp)
157
 
    print_utf8_string2 (fp, p, n, '\n');
158
 
  else
159
 
    tty_print_utf8_string (p, n);
160
166
  xfree (p);
161
 
  
162
 
  if (fp)
163
 
    putc ('\n', fp);
164
 
  else
165
 
    tty_printf ("\n\n"); 
 
167
}
 
168
 
 
169
 
 
170
/* Print basic information of a secret key including the card serial
 
171
   number information. */
 
172
void
 
173
print_card_key_info (FILE *fp, KBNODE keyblock)
 
174
{
 
175
  KBNODE node;
 
176
  int i;
 
177
 
 
178
  for (node = keyblock; node; node = node->next ) 
 
179
    {
 
180
      if (node->pkt->pkttype == PKT_SECRET_KEY
 
181
          || (node->pkt->pkttype == PKT_SECRET_SUBKEY) )
 
182
        {
 
183
          PKT_secret_key *sk = node->pkt->pkt.secret_key;
 
184
          
 
185
          tty_fprintf (fp, "%s%c  %4u%c/%s  ",
 
186
                       node->pkt->pkttype == PKT_SECRET_KEY? "sec":"ssb",
 
187
                       (sk->protect.s2k.mode==1001)?'#':
 
188
                       (sk->protect.s2k.mode==1002)?'>':' ',
 
189
                       nbits_from_sk (sk),
 
190
                       pubkey_letter (sk->pubkey_algo),
 
191
                       keystr_from_sk(sk));
 
192
          tty_fprintf (fp, _("created: %s"), datestr_from_sk (sk));
 
193
          tty_fprintf (fp, "  ");
 
194
          tty_fprintf (fp, _("expires: %s"), expirestr_from_sk (sk));
 
195
          if (sk->is_protected && sk->protect.s2k.mode == 1002)
 
196
            {
 
197
              tty_fprintf (fp, "\n                      ");
 
198
              tty_fprintf (fp, _("card-no: ")); 
 
199
              if (sk->protect.ivlen == 16
 
200
                  && !memcmp (sk->protect.iv, "\xD2\x76\x00\x01\x24\x01", 6))
 
201
                { 
 
202
                  /* This is an OpenPGP card. */
 
203
                  for (i=8; i < 14; i++)
 
204
                    {
 
205
                      if (i == 10)
 
206
                        tty_fprintf (fp, " ");
 
207
                      tty_fprintf (fp, "%02X", sk->protect.iv[i]);
 
208
                    }
 
209
                }
 
210
              else
 
211
                { /* Something is wrong: Print all. */
 
212
                  for (i=0; i < sk->protect.ivlen; i++)
 
213
                    tty_fprintf (fp, "%02X", sk->protect.iv[i]);
 
214
                }
 
215
            }
 
216
          tty_fprintf (fp, "\n");
 
217
        }
 
218
    }
 
219
}
 
220
 
 
221
 
 
222
 
 
223
/* Flags = 0x01 hashed 0x02 critical */
 
224
static void
 
225
status_one_subpacket(sigsubpkttype_t type,size_t len,int flags,const byte *buf)
 
226
{
 
227
  char status[40];
 
228
 
 
229
  /* Don't print these. */
 
230
  if(len>256)
 
231
    return;
 
232
 
 
233
  sprintf(status,"%d %u %u ",type,flags,(unsigned int)len);
 
234
 
 
235
  write_status_text_and_buffer(STATUS_SIG_SUBPACKET,status,buf,len,0);
166
236
}
167
237
 
168
238
/*
184
254
      if(mode!=2)
185
255
        {
186
256
          int i;
187
 
          char *str;
 
257
          const char *str;
188
258
 
189
259
          for(i=0;i<indent;i++)
190
260
            putchar(' ');
206
276
    }
207
277
}
208
278
 
209
 
 
210
279
/*
211
280
  mode=0 for stdout.
212
281
  mode=1 for log_info + status messages
226
295
      if(mode!=2)
227
296
        {
228
297
          int i;
229
 
          char *str;
 
298
          const char *str;
230
299
 
231
300
          for(i=0;i<indent;i++)
232
301
            putchar(' ');
243
312
          fprintf(fp,"\n");
244
313
        }
245
314
 
246
 
      /* TODO: put in a status-fd tag for preferred keyservers */
 
315
      if(mode)
 
316
        status_one_subpacket(SIGSUBPKT_PREF_KS,len,(crit?0x02:0)|0x01,p);
247
317
    }
248
318
}
249
319
 
250
 
 
251
320
/*
252
321
  mode=0 for stdout.
253
322
  mode=1 for log_info + status messages
254
323
  mode=2 for status messages only
 
324
 
 
325
  which bits:
 
326
  1 == standard notations
 
327
  2 == user notations
255
328
*/
256
329
 
257
330
void
258
 
show_notation(PKT_signature *sig,int indent,int mode)
 
331
show_notation(PKT_signature *sig,int indent,int mode,int which)
259
332
{
260
 
  const byte *p;
261
 
  size_t len;
262
 
  int seq=0,crit;
263
333
  FILE *fp=mode?log_get_stream():stdout;
 
334
  struct notation *nd,*notations;
 
335
 
 
336
  if(which==0)
 
337
    which=3;
 
338
 
 
339
  notations=sig_to_notation(sig);
264
340
 
265
341
  /* There may be multiple notations in the same sig. */
266
 
 
267
 
  while((p=enum_sig_subpkt(sig->hashed,SIGSUBPKT_NOTATION,&len,&seq,&crit)))
268
 
    if(len>=8)
269
 
      {
270
 
        int n1,n2;
271
 
 
272
 
        n1=(p[4]<<8)|p[5];
273
 
        n2=(p[6]<<8)|p[7];
274
 
 
275
 
        if(8+n1+n2!=len)
276
 
          {
277
 
            log_info(_("WARNING: invalid notation data found\n"));
278
 
            return;
279
 
          }
280
 
 
281
 
        if(mode!=2)
282
 
          {
283
 
            int i;
284
 
            char *str;
285
 
 
286
 
            for(i=0;i<indent;i++)
287
 
              putchar(' ');
288
 
 
289
 
            /* This is UTF8 */
290
 
            if(crit)
291
 
              str=_("Critical signature notation: ");
292
 
            else
293
 
              str=_("Signature notation: ");
294
 
            if(mode)
295
 
              log_info("%s",str);
296
 
            else
297
 
              printf("%s",str);
298
 
            print_utf8_string(fp,p+8,n1);
299
 
            fprintf(fp,"=");
300
 
 
301
 
            if(*p&0x80)
302
 
              print_utf8_string(fp,p+8+n1,n2);
303
 
            else
304
 
              fprintf(fp,"[ %s ]",_("not human readable"));
305
 
 
306
 
            fprintf(fp,"\n");
307
 
          }
308
 
 
309
 
        if(mode)
310
 
          {
311
 
            write_status_buffer ( STATUS_NOTATION_NAME, p+8   , n1, 0 );
312
 
            write_status_buffer ( STATUS_NOTATION_DATA, p+8+n1, n2, 50 );
313
 
          }
314
 
      }
315
 
  else
316
 
    log_info(_("WARNING: invalid notation data found\n"));
 
342
  for(nd=notations;nd;nd=nd->next)
 
343
    {
 
344
      if(mode!=2)
 
345
        {
 
346
          int has_at=!!strchr(nd->name,'@');
 
347
 
 
348
          if((which&1 && !has_at) || (which&2 && has_at))
 
349
            {
 
350
              int i;
 
351
              const char *str;
 
352
 
 
353
              for(i=0;i<indent;i++)
 
354
                putchar(' ');
 
355
 
 
356
              if(nd->flags.critical)
 
357
                str=_("Critical signature notation: ");
 
358
              else
 
359
                str=_("Signature notation: ");
 
360
              if(mode)
 
361
                log_info("%s",str);
 
362
              else
 
363
                printf("%s",str);
 
364
              /* This is all UTF8 */
 
365
              print_utf8_string(fp,nd->name,strlen(nd->name));
 
366
              fprintf(fp,"=");
 
367
              print_utf8_string(fp,nd->value,strlen(nd->value));
 
368
              fprintf(fp,"\n");
 
369
            }
 
370
        }
 
371
 
 
372
      if(mode)
 
373
        {
 
374
          write_status_buffer(STATUS_NOTATION_NAME,
 
375
                              nd->name,strlen(nd->name),0);
 
376
          write_status_buffer(STATUS_NOTATION_DATA,
 
377
                              nd->value,strlen(nd->value),50);
 
378
        }
 
379
    }
 
380
 
 
381
  free_notation(notations);
317
382
}
318
383
 
319
384
static void
346
411
 
347
412
    hd = keydb_new (secret);
348
413
    if (!hd)
349
 
        rc = GPG_ERR_GENERAL;
 
414
        rc = G10ERR_GENERAL;
350
415
    else
351
416
        rc = keydb_search_first (hd);
352
417
    if( rc ) {
353
418
        if( rc != -1 )
354
 
            log_error("keydb_search_first failed: %s\n", gpg_strerror (rc) );
 
419
            log_error("keydb_search_first failed: %s\n", g10_errstr(rc) );
355
420
        goto leave;
356
421
    }
357
422
 
359
424
    do {
360
425
        rc = keydb_get_keyblock (hd, &keyblock);
361
426
        if (rc) {
362
 
            log_error ("keydb_get_keyblock failed: %s\n", gpg_strerror (rc));
 
427
            log_error ("keydb_get_keyblock failed: %s\n", g10_errstr(rc));
363
428
            goto leave;
364
429
        }
365
430
        if(!opt.with_colons)
383
448
        keyblock = NULL;
384
449
    } while (!(rc = keydb_search_next (hd)));
385
450
    if( rc && rc != -1 )
386
 
        log_error ("keydb_search_next failed: %s\n", gpg_strerror (rc));
 
451
        log_error ("keydb_search_next failed: %s\n", g10_errstr(rc));
387
452
 
388
453
    if(opt.check_sigs && !opt.with_colons)
389
454
      print_signature_stats(&stats);
395
460
 
396
461
 
397
462
static void
398
 
list_one( STRLIST names, int secret )
 
463
list_one( strlist_t names, int secret )
399
464
{
400
465
    int rc = 0;
401
466
    KBNODE keyblock = NULL;
402
467
    GETKEY_CTX ctx;
403
468
    const char *resname;
404
 
    char *keyring_str = _("Keyring");
 
469
    const char *keyring_str = _("Keyring");
405
470
    int i;
406
471
    struct sig_stats stats;
407
472
 
419
484
    if( secret ) {
420
485
        rc = get_seckey_bynames( &ctx, NULL, names, &keyblock );
421
486
        if( rc ) {
422
 
            log_error("error reading key: %s\n",  gpg_strerror (rc) );
 
487
            log_error("error reading key: %s\n",  g10_errstr(rc) );
423
488
            get_seckey_end( ctx );
424
489
            return;
425
490
        }
439
504
    else {
440
505
        rc = get_pubkey_bynames( &ctx, NULL, names, &keyblock );
441
506
        if( rc ) {
442
 
            log_error("error reading key: %s\n", gpg_strerror (rc) );
 
507
            log_error("error reading key: %s\n", g10_errstr(rc) );
443
508
            get_pubkey_end( ctx );
444
509
            return;
445
510
        }
463
528
}
464
529
 
465
530
static void
466
 
print_key_data( PKT_public_key *pk, u32 *keyid )
 
531
print_key_data( PKT_public_key *pk )
467
532
{
468
533
    int n = pk ? pubkey_get_npkey( pk->pubkey_algo ) : 0;
469
534
    int i;
483
548
    {
484
549
      unsigned int use = pk? pk->pubkey_usage : sk->pubkey_usage;
485
550
    
486
 
      if ( (use & PUBKEY_USAGE_ENC) )
 
551
      if ( use & PUBKEY_USAGE_ENC )
487
552
        putchar ('e');
488
553
 
489
 
      if ( (use & PUBKEY_USAGE_SIG) )
 
554
      if ( use & PUBKEY_USAGE_SIG )
490
555
        {
491
556
          putchar ('s');
492
557
          if( pk? pk->is_primary : sk->is_primary )
510
575
                  disabled=pk_is_disabled(pk);
511
576
 
512
577
                if ( pk->is_valid && !pk->is_revoked && !pk->has_expired ) {
513
 
                    if ( (pk->pubkey_usage & PUBKEY_USAGE_ENC) )
 
578
                    if ( pk->pubkey_usage & PUBKEY_USAGE_ENC )
514
579
                        enc = 1;
515
 
                    if ( (pk->pubkey_usage & PUBKEY_USAGE_SIG) )
 
580
                    if ( pk->pubkey_usage & PUBKEY_USAGE_SIG )
516
581
                      {
517
582
                        sign = 1;
518
583
                        if(pk->is_primary)
527
592
                sk = k->pkt->pkt.secret_key;
528
593
                if ( sk->is_valid && !sk->is_revoked && !sk->has_expired
529
594
                     && sk->protect.s2k.mode!=1001 ) {
530
 
                    if ( (sk->pubkey_usage & PUBKEY_USAGE_ENC) )
 
595
                    if ( sk->pubkey_usage & PUBKEY_USAGE_ENC )
531
596
                        enc = 1;
532
 
                    if ( (sk->pubkey_usage & PUBKEY_USAGE_SIG) )
 
597
                    if ( sk->pubkey_usage & PUBKEY_USAGE_SIG )
533
598
                      {
534
599
                        sign = 1;
535
600
                        if(sk->is_primary)
555
620
    putchar(':');
556
621
}
557
622
 
 
623
/* Flags = 0x01 hashed 0x02 critical */
 
624
static void
 
625
print_one_subpacket(sigsubpkttype_t type,size_t len,int flags,const byte *buf)
 
626
{
 
627
  size_t i;
 
628
 
 
629
  printf("spk:%d:%u:%u:",type,flags,(unsigned int)len);
 
630
 
 
631
  for(i=0;i<len;i++)
 
632
    {
 
633
      /* printable ascii other than : and % */
 
634
      if(buf[i]>=32 && buf[i]<=126 && buf[i]!=':' && buf[i]!='%')
 
635
        printf("%c",buf[i]);
 
636
      else
 
637
        printf("%%%02X",buf[i]);
 
638
    }
 
639
 
 
640
  printf("\n");
 
641
}
 
642
 
 
643
void
 
644
print_subpackets_colon(PKT_signature *sig)
 
645
{
 
646
  byte *i;
 
647
 
 
648
  assert(opt.show_subpackets);
 
649
 
 
650
  for(i=opt.show_subpackets;*i;i++)
 
651
    {
 
652
      const byte *p;
 
653
      size_t len;
 
654
      int seq,crit;
 
655
 
 
656
      seq=0;
 
657
 
 
658
      while((p=enum_sig_subpkt(sig->hashed,*i,&len,&seq,&crit)))
 
659
        print_one_subpacket(*i,len,0x01|(crit?0x02:0),p);
 
660
 
 
661
      seq=0;
 
662
 
 
663
      while((p=enum_sig_subpkt(sig->unhashed,*i,&len,&seq,&crit)))
 
664
        print_one_subpacket(*i,len,0x00|(crit?0x02:0),p);
 
665
    }
 
666
}
 
667
 
558
668
void
559
669
dump_attribs(const PKT_user_id *uid,PKT_public_key *pk,PKT_secret_key *sk)
560
670
{
603
713
    KBNODE node;
604
714
    PKT_public_key *pk;
605
715
    PKT_secret_key *sk;
606
 
    u32 keyid[2];
607
 
    int any=0;
608
716
    struct sig_stats *stats=opaque;
609
 
    int newformat=((opt.list_options&LIST_SHOW_VALIDITY) && !secret)
610
 
      || (opt.list_options&LIST_SHOW_LONG_KEYID);
 
717
    int skip_sigs=0;
611
718
 
612
719
    /* get the keyid from the keyblock */
613
720
    node = find_kbnode( keyblock, secret? PKT_SECRET_KEY : PKT_PUBLIC_KEY );
621
728
      {
622
729
        pk = NULL;
623
730
        sk = node->pkt->pkt.secret_key;
624
 
        keyid_from_sk( sk, keyid );
625
 
 
626
 
        printf("sec%c  %4u%c/",(sk->protect.s2k.mode==1001)?'#':' ',
627
 
               nbits_from_sk( sk ),pubkey_letter( sk->pubkey_algo ));
628
 
 
629
 
        if(opt.list_options&LIST_SHOW_LONG_KEYID)
630
 
          printf("%08lX%08lX",(ulong)keyid[0],(ulong)keyid[1]);
631
 
        else
632
 
          printf("%08lX",(ulong)keyid[1]);
633
 
 
634
 
        printf(" %s%s",datestr_from_sk( sk ),newformat?"":" " );
635
 
 
636
 
        if(newformat && sk->expiredate )
637
 
          printf(_(" [expires: %s]"), expirestr_from_sk( sk ) );
 
731
 
 
732
        printf("sec%c  %4u%c/%s %s",(sk->protect.s2k.mode==1001)?'#':
 
733
               (sk->protect.s2k.mode==1002)?'>':' ',
 
734
               nbits_from_sk( sk ),pubkey_letter( sk->pubkey_algo ),
 
735
               keystr_from_sk(sk),datestr_from_sk( sk ));
 
736
 
 
737
        if(sk->has_expired)
 
738
          {
 
739
            printf(" [");
 
740
            printf(_("expired: %s"),expirestr_from_sk(sk));
 
741
            printf("]");
 
742
          }
 
743
        else if(sk->expiredate )
 
744
          {
 
745
            printf(" [");
 
746
            printf(_("expires: %s"),expirestr_from_sk(sk));
 
747
            printf("]");
 
748
          }
 
749
 
 
750
        printf("\n");
638
751
      }
639
752
    else
640
753
      {
641
 
        int validity;
642
754
        pk = node->pkt->pkt.public_key;
643
755
        sk = NULL;
644
 
        keyid_from_pk( pk, keyid );
645
 
 
646
 
        validity=get_validity(pk,NULL);
647
 
 
648
 
        printf("pub   %4u%c/",
649
 
               nbits_from_pk(pk),pubkey_letter(pk->pubkey_algo));
650
 
 
651
 
        if(opt.list_options&LIST_SHOW_LONG_KEYID)
652
 
          printf("%08lX%08lX",(ulong)keyid[0],(ulong)keyid[1]);
653
 
        else
654
 
          printf("%08lX",(ulong)keyid[1]);
655
 
 
656
 
        printf(" %s%s",datestr_from_pk( pk ),newformat?"":" " );
 
756
 
 
757
        check_trustdb_stale();
 
758
 
 
759
        printf("pub   %4u%c/%s %s",
 
760
               nbits_from_pk(pk),pubkey_letter(pk->pubkey_algo),
 
761
               keystr_from_pk(pk),datestr_from_pk( pk ));
657
762
 
658
763
        /* We didn't include this before in the key listing, but there
659
764
           is room in the new format, so why not? */
660
 
        if(newformat && pk->expiredate)
661
 
          printf(_(" [expires: %s]"), expirestr_from_pk( pk ) );
662
 
 
 
765
 
 
766
        if(pk->is_revoked)
 
767
          {
 
768
            printf(" [");
 
769
            printf(_("revoked: %s"),revokestr_from_pk(pk));
 
770
            printf("]");
 
771
          }
 
772
        else if(pk->has_expired)
 
773
          {
 
774
            printf(" [");
 
775
            printf(_("expired: %s"),expirestr_from_pk(pk));
 
776
            printf("]");
 
777
          }
 
778
        else if(pk->expiredate)
 
779
          {
 
780
            printf(" [");
 
781
            printf(_("expires: %s"),expirestr_from_pk(pk));
 
782
            printf("]");
 
783
          }
 
784
 
 
785
#if 0
 
786
        /* I need to think about this some more.  It's easy enough to
 
787
           include, but it looks sort of confusing in the
 
788
           listing... */
663
789
        if(opt.list_options&LIST_SHOW_VALIDITY)
664
 
          printf(" [%s]",trust_value_to_string(validity));
 
790
          {
 
791
            int validity=get_validity(pk,NULL);
 
792
            printf(" [%s]",trust_value_to_string(validity));
 
793
          }
 
794
#endif
 
795
 
 
796
        printf("\n");
665
797
      }
666
798
 
 
799
    if( fpr )
 
800
      print_fingerprint( pk, sk, 0 );
 
801
    print_card_serialno (sk);
 
802
    if( opt.with_key_data )
 
803
      print_key_data( pk );
 
804
 
667
805
    for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) {
668
806
        if( node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode ) {
669
 
            int indent;
670
 
            /* don't list revoked or expired UIDS unless we are in
671
 
             * verbose mode and signature listing has not been
672
 
             * requested */
673
 
            if ( !opt.verbose && !opt.list_sigs &&
674
 
                 (node->pkt->pkt.user_id->is_revoked ||
675
 
                  node->pkt->pkt.user_id->is_expired ))
676
 
                continue; 
677
 
 
678
 
            if(attrib_fp && node->pkt->pkt.user_id->attrib_data!=NULL)
679
 
              dump_attribs(node->pkt->pkt.user_id,pk,sk);
680
 
 
681
 
            if(!any && newformat)
682
 
              printf("\n");
683
 
 
684
 
            if((opt.list_options&LIST_SHOW_VALIDITY) && pk)
685
 
              {
686
 
                const char *validity=
687
 
                trust_value_to_string(get_validity(pk,node->pkt->pkt.user_id));
688
 
 
689
 
                /* Includes the 3 spaces for [, ], and " ". */
690
 
                indent=((opt.list_options&LIST_SHOW_LONG_KEYID)?23:15)
691
 
                  -strlen(validity);
692
 
 
693
 
                if(indent<0)
 
807
            PKT_user_id *uid=node->pkt->pkt.user_id;
 
808
 
 
809
            if(pk && (uid->is_expired || uid->is_revoked)
 
810
               && !(opt.list_options&LIST_SHOW_UNUSABLE_UIDS))
 
811
              {
 
812
                skip_sigs=1;
 
813
                continue;
 
814
              }
 
815
            else
 
816
              skip_sigs=0;
 
817
 
 
818
            if(attrib_fp && uid->attrib_data!=NULL)
 
819
              dump_attribs(uid,pk,sk);
 
820
 
 
821
            if((uid->is_revoked || uid->is_expired)
 
822
               || ((opt.list_options&LIST_SHOW_UID_VALIDITY) && pk))
 
823
              {
 
824
                const char *validity;
 
825
                int indent;
 
826
 
 
827
                validity=uid_trust_string_fixed(pk,uid);
 
828
                indent=(keystrlen()+9)-atoi(uid_trust_string_fixed(NULL,NULL));
 
829
 
 
830
                if(indent<0 || indent>40)
694
831
                  indent=0;
695
832
 
696
 
                printf("uid%*s[%s] ",indent,"",validity);
 
833
                printf("uid%*s%s ",indent,"",validity);
697
834
              }
698
 
            else if(newformat)
699
 
              printf("uid%*s",26,"");
700
 
            else if(any)
701
 
              printf("uid%*s",29,"");
702
 
 
703
 
            if ( node->pkt->pkt.user_id->is_revoked )
704
 
                fputs ("[revoked] ", stdout);
705
 
            if ( node->pkt->pkt.user_id->is_expired )
706
 
                fputs ("[expired] ", stdout);
707
 
 
708
 
            print_utf8_string( stdout,  node->pkt->pkt.user_id->name,
709
 
                               node->pkt->pkt.user_id->len );
 
835
            else
 
836
              printf("uid%*s", (int)keystrlen()+10,"");
 
837
 
 
838
            print_utf8_string( stdout, uid->name, uid->len );
710
839
            putchar('\n');
711
 
            if( !any ) {
712
 
                if( fpr )
713
 
                    print_fingerprint( pk, sk, 0 );
714
 
                print_card_serialno (sk);
715
 
                if( opt.with_key_data )
716
 
                    print_key_data( pk, keyid );
717
 
                any = 1;
718
 
            }
719
840
 
720
 
            if((opt.list_options&LIST_SHOW_PHOTOS)
721
 
               && node->pkt->pkt.user_id->attribs!=NULL)
722
 
              show_photos(node->pkt->pkt.user_id->attribs,
723
 
                          node->pkt->pkt.user_id->numattribs,pk,sk);
 
841
            if((opt.list_options&LIST_SHOW_PHOTOS) && uid->attribs!=NULL)
 
842
              show_photos(uid->attribs,uid->numattribs,pk,sk);
724
843
        }
725
 
        else if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) {
726
 
            u32 keyid2[2];
 
844
        else if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY )
 
845
          {
727
846
            PKT_public_key *pk2 = node->pkt->pkt.public_key;
728
847
 
729
 
            if( !any ) {
730
 
                putchar('\n');
731
 
                if( fpr )
732
 
                    print_fingerprint( pk, sk, 0 ); /* of the main key */
733
 
                any = 1;
734
 
            }
735
 
 
736
 
            keyid_from_pk( pk2, keyid2 );
737
 
            printf("sub   %4u%c/",
738
 
                   nbits_from_pk( pk2 ),pubkey_letter( pk2->pubkey_algo ));
739
 
            if(opt.list_options&LIST_SHOW_LONG_KEYID)
740
 
              printf("%08lX%08lX",(ulong)keyid2[0],(ulong)keyid2[1]);
 
848
            if((pk2->is_revoked || pk2->has_expired)
 
849
               && !(opt.list_options&LIST_SHOW_UNUSABLE_SUBKEYS))
 
850
              {
 
851
                skip_sigs=1;
 
852
                continue;
 
853
              }
741
854
            else
742
 
              printf("%08lX",(ulong)keyid2[1]);
743
 
            printf(" %s",datestr_from_pk(pk2));
744
 
            if( pk2->expiredate )
745
 
              printf(_(" [expires: %s]"), expirestr_from_pk( pk2 ) );
 
855
              skip_sigs=0;
 
856
 
 
857
            printf("sub   %4u%c/%s %s",
 
858
                   nbits_from_pk( pk2 ),pubkey_letter( pk2->pubkey_algo ),
 
859
                   keystr_from_pk(pk2),datestr_from_pk(pk2));
 
860
            if( pk2->is_revoked )
 
861
              {
 
862
                printf(" [");
 
863
                printf(_("revoked: %s"),revokestr_from_pk(pk2));
 
864
                printf("]");
 
865
              }
 
866
            else if( pk2->has_expired )
 
867
              {
 
868
                printf(" [");
 
869
                printf(_("expired: %s"),expirestr_from_pk(pk2));
 
870
                printf("]");
 
871
              }
 
872
            else if( pk2->expiredate )
 
873
              {
 
874
                printf(" [");
 
875
                printf(_("expires: %s"),expirestr_from_pk(pk2));
 
876
                printf("]");
 
877
              }
746
878
            putchar('\n');
747
879
            if( fpr > 1 )
748
 
                print_fingerprint( pk2, NULL, 0 );
 
880
              print_fingerprint( pk2, NULL, 0 );
749
881
            if( opt.with_key_data )
750
 
                print_key_data( pk2, keyid2 );
751
 
        }
752
 
        else if( node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
753
 
            u32 keyid2[2];
 
882
              print_key_data( pk2 );
 
883
          }
 
884
        else if( node->pkt->pkttype == PKT_SECRET_SUBKEY )
 
885
          {
754
886
            PKT_secret_key *sk2 = node->pkt->pkt.secret_key;
755
887
 
756
 
            if( !any ) {
757
 
                putchar('\n');
758
 
                if( fpr )
759
 
                    print_fingerprint( pk, sk, 0 ); /* of the main key */
760
 
                print_card_serialno (sk);
761
 
                any = 1;
762
 
            }
763
 
 
764
 
            keyid_from_sk( sk2, keyid2 );
765
 
            printf("ssb   %4u%c/",
766
 
                   nbits_from_sk( sk2 ),pubkey_letter( sk2->pubkey_algo ));
767
 
            if(opt.list_options&LIST_SHOW_LONG_KEYID)
768
 
              printf("%08lX%08lX",(ulong)keyid2[0],(ulong)keyid2[1]);
769
 
            else
770
 
              printf("%08lX",(ulong)keyid2[1]);
771
 
            printf(" %s",datestr_from_sk( sk2 ) );
 
888
            printf("ssb%c  %4u%c/%s %s",
 
889
                   (sk2->protect.s2k.mode==1001)?'#':
 
890
                   (sk2->protect.s2k.mode==1002)?'>':' ',
 
891
                   nbits_from_sk( sk2 ),pubkey_letter( sk2->pubkey_algo ),
 
892
                   keystr_from_sk(sk2),datestr_from_sk( sk2 ) );
772
893
            if( sk2->expiredate )
773
 
              printf(_(" [expires: %s]"), expirestr_from_sk( sk2 ) );
 
894
              {
 
895
                printf(" [");
 
896
                printf(_("expires: %s"),expirestr_from_sk(sk2));
 
897
                printf("]");
 
898
              }
774
899
            putchar('\n');
775
900
            if( fpr > 1 )
776
901
              {
777
 
                print_fingerprint( NULL, sk2, 0 );
778
 
                print_card_serialno (sk);
 
902
                print_fingerprint( NULL, sk2, 0 );
 
903
                print_card_serialno (sk2);
779
904
              }
780
 
        }
781
 
        else if( opt.list_sigs && node->pkt->pkttype == PKT_SIGNATURE ) {
 
905
          }
 
906
        else if( opt.list_sigs
 
907
                 && node->pkt->pkttype == PKT_SIGNATURE
 
908
                 && !skip_sigs ) {
782
909
            PKT_signature *sig = node->pkt->pkt.signature;
783
910
            int sigrc;
784
911
            char *sigstr;
787
914
                /*fflush(stdout);*/
788
915
                rc = check_key_signature( keyblock, node, NULL );
789
916
                switch( gpg_err_code (rc) ) {
790
 
                 case 0:                 sigrc = '!'; break;
791
 
                 case GPG_ERR_BAD_SIGNATURE:   stats->inv_sigs++; sigrc = '-'; break;
 
917
                 case 0:                sigrc = '!'; break;
 
918
                 case GPG_ERR_BAD_SIGNATURE:
 
919
                   stats->inv_sigs++; sigrc = '-'; break;
792
920
                 case GPG_ERR_NO_PUBKEY: 
793
921
                 case GPG_ERR_UNUSABLE_PUBKEY: stats->no_key++; continue;
794
 
                 default:                stats->oth_err++; sigrc = '%'; break;
 
922
                 default:               stats->oth_err++; sigrc = '%'; break;
795
923
                }
796
924
 
797
925
                /* TODO: Make sure a cached sig record here still has
798
926
                   the pk that issued it.  See also
799
927
                   keyedit.c:print_and_check_one_sig */
800
 
 
801
928
            }
802
929
            else {
803
930
                rc = 0;
804
931
                sigrc = ' ';
805
932
            }
806
933
 
807
 
            if( !any ) { /* no user id, (maybe a revocation follows)*/
808
 
              /* Check if the pk is really revoked - there could be a
809
 
                 0x20 sig packet there even if we are not revoked
810
 
                 (say, if a revocation key issued the packet, but the
811
 
                 revocation key isn't present to verify it.) */
812
 
                if( sig->sig_class == 0x20 && pk->is_revoked )
813
 
                    puts("[revoked]");
814
 
                else if( sig->sig_class == 0x18 )
815
 
                    puts("[key binding]");
816
 
                else if( sig->sig_class == 0x28 )
817
 
                    puts("[subkey revoked]");
818
 
                else
819
 
                    putchar('\n');
820
 
                if( fpr )
821
 
                    print_fingerprint( pk, sk, 0 );
822
 
                print_card_serialno (sk);
823
 
                any=1;
824
 
            }
825
 
 
826
934
            if( sig->sig_class == 0x20 || sig->sig_class == 0x28
827
935
                                       || sig->sig_class == 0x30 )
828
936
               sigstr = "rev";
839
947
            }
840
948
 
841
949
            fputs( sigstr, stdout );
842
 
            printf("%c%c %c%c%c%c%c%c ",
 
950
            printf("%c%c %c%c%c%c%c%c %s %s",
843
951
                   sigrc,(sig->sig_class-0x10>0 &&
844
952
                          sig->sig_class-0x10<4)?'0'+sig->sig_class-0x10:' ',
845
953
                   sig->flags.exportable?' ':'L',
848
956
                   sig->flags.notation?'N':' ',
849
957
                   sig->flags.expired?'X':' ',
850
958
                   (sig->trust_depth>9)?'T':
851
 
                   (sig->trust_depth>0)?'0'+sig->trust_depth:' ');
852
 
            if(opt.list_options&LIST_SHOW_LONG_KEYID)
853
 
              printf("%08lX%08lX",(ulong)sig->keyid[0],(ulong)sig->keyid[1]);
854
 
            else
855
 
              printf("%08lX",(ulong)sig->keyid[1]);
856
 
            printf(" %s   ", datestr_from_sig(sig));
 
959
                   (sig->trust_depth>0)?'0'+sig->trust_depth:' ',
 
960
                   keystr(sig->keyid),datestr_from_sig(sig));
 
961
            if(opt.list_options&LIST_SHOW_SIG_EXPIRE)
 
962
              printf(" %s", expirestr_from_sig(sig));
 
963
            printf("  ");
857
964
            if( sigrc == '%' )
858
 
                printf("[%s] ", gpg_strerror (rc) );
 
965
                printf("[%s] ", g10_errstr(rc) );
859
966
            else if( sigrc == '?' )
860
967
                ;
861
968
            else if ( !opt.fast_list_mode ) {
862
969
                size_t n;
863
970
                char *p = get_user_id( sig->keyid, &n );
864
971
                print_utf8_string( stdout, p, n );
865
 
                xfree (p);
 
972
                xfree(p);
866
973
            }
867
974
            putchar('\n');
868
975
 
869
 
            if(sig->flags.policy_url && (opt.list_options&LIST_SHOW_POLICY))
 
976
            if(sig->flags.policy_url
 
977
               && (opt.list_options&LIST_SHOW_POLICY_URLS))
870
978
              show_policy_url(sig,3,0);
871
979
 
872
 
            if(sig->flags.notation && (opt.list_options&LIST_SHOW_NOTATION))
873
 
              show_notation(sig,3,0);
 
980
            if(sig->flags.notation && (opt.list_options&LIST_SHOW_NOTATIONS))
 
981
              show_notation(sig,3,0,
 
982
                            ((opt.list_options&LIST_SHOW_STD_NOTATIONS)?1:0)+
 
983
                            ((opt.list_options&LIST_SHOW_USER_NOTATIONS)?2:0));
874
984
 
875
 
            if(sig->flags.pref_ks && (opt.list_options&LIST_SHOW_KEYSERVER))
 
985
            if(sig->flags.pref_ks
 
986
               && (opt.list_options&LIST_SHOW_KEYSERVER_URLS))
876
987
              show_keyserver_url(sig,3,0);
877
988
 
878
989
            /* fixme: check or list other sigs here */
881
992
    putchar('\n');
882
993
}
883
994
 
 
995
void
 
996
print_revokers(PKT_public_key *pk)
 
997
{
 
998
  /* print the revoker record */
 
999
  if( !pk->revkey && pk->numrevkeys )
 
1000
    BUG();
 
1001
  else
 
1002
    {
 
1003
      int i,j;
 
1004
 
 
1005
      for (i=0; i < pk->numrevkeys; i++)
 
1006
        {
 
1007
          byte *p;
 
1008
 
 
1009
          printf ("rvk:::%d::::::", pk->revkey[i].algid);
 
1010
          p = pk->revkey[i].fpr;
 
1011
          for (j=0; j < 20; j++, p++ )
 
1012
            printf ("%02X", *p);
 
1013
          printf (":%02x%s:\n", pk->revkey[i].class,
 
1014
                  (pk->revkey[i].class&0x40)?"s":"");
 
1015
        }
 
1016
    }
 
1017
}
884
1018
 
885
1019
static void
886
1020
list_keyblock_colon( KBNODE keyblock, int secret, int fpr )
894
1028
    int any=0;
895
1029
    int trustletter = 0;
896
1030
    int ulti_hack = 0;
 
1031
    int i;
897
1032
 
898
1033
    /* get the keyid from the keyblock */
899
1034
    node = find_kbnode( keyblock, secret? PKT_SECRET_KEY : PKT_PUBLIC_KEY );
934
1069
                ulti_hack = 1;
935
1070
            putchar(trustletter);
936
1071
        }
937
 
        printf(":%u:%d:%08lX%08lX:%s:%s:",
 
1072
        printf(":%u:%d:%08lX%08lX:%s:%s::",
938
1073
                    nbits_from_pk( pk ),
939
1074
                    pk->pubkey_algo,
940
1075
                    (ulong)keyid[0],(ulong)keyid[1],
941
1076
                    colon_datestr_from_pk( pk ),
942
1077
                    colon_strtime (pk->expiredate) );
943
 
        if( pk->local_id )
944
 
            printf("%lu", pk->local_id );
945
 
        putchar(':');
946
1078
        if( !opt.fast_list_mode && !opt.no_expensive_trust_checks  )
947
1079
            putchar( get_ownertrust_info(pk) );
948
1080
            putchar(':');
949
1081
    }
950
 
    
 
1082
 
951
1083
    if (opt.fixed_list_mode) {
952
1084
        /* do not merge the first uid with the primary key */
953
1085
        putchar(':');
954
1086
        putchar(':');
955
1087
        print_capabilities (pk, sk, keyblock);
 
1088
        if (secret) {
 
1089
          putchar(':'); /* End of field 13. */
 
1090
          putchar(':'); /* End of field 14. */
 
1091
          if (sk->protect.s2k.mode == 1001)
 
1092
            putchar('#'); /* Key is just a stub. */
 
1093
          else if (sk->protect.s2k.mode == 1002) {
 
1094
            /* Key is stored on an external token (card) or handled by
 
1095
               the gpg-agent.  Print the serial number of that token
 
1096
               here. */
 
1097
            for (i=0; i < sk->protect.ivlen; i++)
 
1098
              printf ("%02X", sk->protect.iv[i]);
 
1099
          }
 
1100
          putchar(':'); /* End of field 15. */
 
1101
        }
956
1102
        putchar('\n');
 
1103
        if(pk)
 
1104
          print_revokers(pk);
957
1105
        if( fpr )
958
1106
            print_fingerprint( pk, sk, 0 );
959
1107
        if( opt.with_key_data )
960
 
            print_key_data( pk, keyid );
 
1108
            print_key_data( pk );
961
1109
        any = 1;
962
1110
    }
963
1111
 
964
 
 
965
1112
    for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) {
966
1113
        if( node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode ) {
967
1114
            PKT_user_id *uid=node->pkt->pkt.user_id;
971
1118
             * Fixme: We need a is_valid flag here too 
972
1119
             */
973
1120
            if( any ) {
974
 
                int i;
975
1121
                char *str=uid->attrib_data?"uat":"uid";
976
1122
                /* If we're listing a secret key, leave out the
977
 
                   validity values for now.  FIXME: This should be
978
 
                   handled better in 1.9. */
 
1123
                   validity values for now.  This is handled better in
 
1124
                   1.9. */
979
1125
                if ( sk )
980
1126
                    printf("%s:::::",str);
981
1127
                else if ( uid->is_revoked )
1018
1164
                if( fpr )
1019
1165
                    print_fingerprint( pk, sk, 0 );
1020
1166
                if( opt.with_key_data )
1021
 
                    print_key_data( pk, keyid );
 
1167
                    print_key_data( pk );
1022
1168
                any = 1;
1023
1169
            }
1024
1170
        }
1051
1197
                if(trustletter)
1052
1198
                  printf("%c", trustletter );
1053
1199
            }
1054
 
            printf(":%u:%d:%08lX%08lX:%s:%s:",
 
1200
            printf(":%u:%d:%08lX%08lX:%s:%s:::::",
1055
1201
                        nbits_from_pk( pk2 ),
1056
1202
                        pk2->pubkey_algo,
1057
1203
                        (ulong)keyid2[0],(ulong)keyid2[1],
1059
1205
                        colon_strtime (pk2->expiredate)
1060
1206
                        /* fixme: add LID and ownertrust here */
1061
1207
                                                );
1062
 
            if( pk->local_id ) /* use the local_id of the main key??? */
1063
 
                printf("%lu", pk->local_id );
1064
 
            putchar(':');
1065
 
            putchar(':');
1066
 
            putchar(':');
1067
 
            putchar(':');
1068
1208
            print_capabilities (pk2, NULL, NULL);
1069
1209
            putchar('\n');
1070
1210
            if( fpr > 1 )
1071
1211
                print_fingerprint( pk2, NULL, 0 );
1072
1212
            if( opt.with_key_data )
1073
 
                print_key_data( pk2, keyid2 );
 
1213
                print_key_data( pk2 );
1074
1214
        }
1075
1215
        else if( node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
1076
1216
            u32 keyid2[2];
1095
1235
                        colon_strtime (sk2->expiredate)
1096
1236
                   /* fixme: add LID */ );
1097
1237
            print_capabilities (NULL, sk2, NULL);
 
1238
            if (opt.fixed_list_mode) {
 
1239
              /* We print the serial number only in fixed list mode
 
1240
                 for the primary key so, so avoid questions we print
 
1241
                 it for subkeys also only in this mode.  There is no
 
1242
                 technical reason, though. */
 
1243
              putchar(':'); /* End of field 13. */
 
1244
              putchar(':'); /* End of field 14. */
 
1245
              if (sk2->protect.s2k.mode == 1001)
 
1246
                putchar('#'); /* Key is just a stub. */
 
1247
              else if (sk2->protect.s2k.mode == 1002) {
 
1248
                /* Key is stored on an external token (card) or handled by
 
1249
                   the gpg-agent.  Print the serial number of that token
 
1250
                   here. */
 
1251
                for (i=0; i < sk2->protect.ivlen; i++)
 
1252
                  printf ("%02X", sk2->protect.iv[i]);
 
1253
              }
 
1254
              putchar(':'); /* End of field 15. */
 
1255
            }
1098
1256
            putchar ('\n');
1099
1257
            if( fpr > 1 )
1100
 
                print_fingerprint( NULL, sk2, 0 );
 
1258
              print_fingerprint( NULL, sk2, 0 );
1101
1259
        }
1102
1260
        else if( opt.list_sigs && node->pkt->pkttype == PKT_SIGNATURE ) {
1103
1261
            PKT_signature *sig = node->pkt->pkt.signature;
1104
 
            int sigrc, fprokay=0;
 
1262
            int sigrc,fprokay=0;
1105
1263
            char *sigstr;
1106
1264
            size_t fplen;
1107
1265
            byte fparray[MAX_FINGERPRINT_LEN];
1142
1300
 
1143
1301
                fflush(stdout);
1144
1302
                if(opt.no_sig_cache)
1145
 
                  signer_pk = xcalloc (1, sizeof(PKT_public_key));
 
1303
                  signer_pk=xmalloc_clear(sizeof(PKT_public_key));
1146
1304
 
1147
1305
                rc = check_key_signature2( keyblock, node, NULL, signer_pk,
1148
1306
                                           NULL, NULL, NULL );
1149
 
                switch( gpg_err_code (rc) ) {
1150
 
                  case 0:                  sigrc = '!'; break;
1151
 
                  case GPG_ERR_BAD_SIGNATURE:    sigrc = '-'; break;
 
1307
                switch ( gpg_err_code (rc) ) {
 
1308
                  case 0:                       sigrc = '!'; break;
 
1309
                  case GPG_ERR_BAD_SIGNATURE:   sigrc = '-'; break;
1152
1310
                  case GPG_ERR_NO_PUBKEY: 
1153
 
                  case GPG_ERR_UNUSABLE_PUBKEY:  sigrc = '?'; break;
1154
 
                  default:                 sigrc = '%'; break;
 
1311
                  case GPG_ERR_UNUSABLE_PUBKEY: sigrc = '?'; break;
 
1312
                  default:                      sigrc = '%'; break;
1155
1313
                }
1156
1314
 
1157
1315
                if(opt.no_sig_cache)
1158
1316
                  {
1159
 
                    if(!rc)
 
1317
                    if(rc==0)
1160
1318
                      {
1161
1319
                        fingerprint_from_pk (signer_pk, fparray, &fplen);
1162
1320
                        fprokay=1;
1187
1345
            printf(":");
1188
1346
 
1189
1347
            if( sigrc == '%' )
1190
 
                printf("[%s] ", gpg_strerror (rc) );
 
1348
                printf("[%s] ", g10_errstr(rc) );
1191
1349
            else if( sigrc == '?' )
1192
1350
                ;
1193
1351
            else if ( !opt.fast_list_mode ) {
1194
1352
                size_t n;
1195
1353
                char *p = get_user_id( sig->keyid, &n );
1196
1354
                print_string( stdout, p, n, ':' );
1197
 
                xfree (p);
 
1355
                xfree(p);
1198
1356
            }
1199
1357
            printf(":%02x%c:", sig->sig_class,sig->flags.exportable?'x':'l');
 
1358
 
1200
1359
            if(opt.no_sig_cache && opt.check_sigs && fprokay)
1201
1360
              {
1202
 
                size_t i;
1203
 
 
1204
1361
                printf(":");
1205
1362
 
1206
1363
                for (i=0; i < fplen ; i++ )
1210
1367
              }
1211
1368
 
1212
1369
            printf("\n");
 
1370
 
 
1371
            if(opt.show_subpackets)
 
1372
              print_subpackets_colon(sig);
 
1373
 
1213
1374
            /* fixme: check or list other sigs here */
1214
1375
        }
1215
1376
    }
1225
1386
 * Reorder the keyblock so that the primary user ID (and not attribute
1226
1387
 * packet) comes first.  Fixme: Replace this by a generic sort
1227
1388
 * function.  */
1228
 
void
1229
 
reorder_keyblock (KBNODE keyblock)
 
1389
static void
 
1390
do_reorder_keyblock (KBNODE keyblock,int attr)
1230
1391
{
1231
1392
    KBNODE primary = NULL, primary0 = NULL, primary2 = NULL;
1232
1393
    KBNODE last, node;
1233
1394
 
1234
1395
    for (node=keyblock; node; primary0=node, node = node->next) {
1235
1396
        if( node->pkt->pkttype == PKT_USER_ID &&
1236
 
            !node->pkt->pkt.user_id->attrib_data &&
 
1397
            ((attr && node->pkt->pkt.user_id->attrib_data) ||
 
1398
             (!attr && !node->pkt->pkt.user_id->attrib_data)) &&
1237
1399
            node->pkt->pkt.user_id->is_primary ) {
1238
1400
            primary = primary2 = node;
1239
1401
            for (node=node->next; node; primary2=node, node = node->next ) {
1265
1427
}
1266
1428
 
1267
1429
void
 
1430
reorder_keyblock (KBNODE keyblock)
 
1431
{
 
1432
  do_reorder_keyblock(keyblock,1);
 
1433
  do_reorder_keyblock(keyblock,0);
 
1434
}
 
1435
 
 
1436
void
1268
1437
list_keyblock( KBNODE keyblock, int secret, int fpr, void *opaque )
1269
1438
{
1270
1439
    reorder_keyblock (keyblock);
1315
1484
      {
1316
1485
        if(sk)
1317
1486
          {
1318
 
            PKT_secret_key *primary_sk=xcalloc (1,sizeof(*primary_sk));
 
1487
            PKT_secret_key *primary_sk=xmalloc_clear(sizeof(*primary_sk));
1319
1488
            get_seckey(primary_sk,sk->main_keyid);
1320
1489
            print_fingerprint(NULL,primary_sk,mode|0x80);
1321
1490
            free_secret_key(primary_sk);
1322
1491
          }
1323
1492
        else
1324
1493
          {
1325
 
            PKT_public_key *primary_pk=xcalloc (1,sizeof(*primary_pk));
 
1494
            PKT_public_key *primary_pk=xmalloc_clear(sizeof(*primary_pk));
1326
1495
            get_pubkey(primary_pk,pk->main_keyid);
1327
1496
            print_fingerprint(primary_pk,NULL,mode|0x80);
1328
1497
            free_public_key(primary_pk);
1338
1507
    }
1339
1508
    else if (mode == 2) {
1340
1509
        fp = NULL; /* use tty */
1341
 
        /* Translators: this should fit into 24 bytes to that the fingerprint
1342
 
         * data is properly aligned with the user ID */
1343
1510
        if(primary)
 
1511
          /* TRANSLATORS: this should fit into 24 bytes to that the
 
1512
           * fingerprint data is properly aligned with the user ID */
1344
1513
          text = _(" Primary key fingerprint:");
1345
1514
        else
1346
1515
          text = _("      Subkey fingerprint:");
1405
1574
        tty_printf ("\n");
1406
1575
}
1407
1576
 
1408
 
 
1409
1577
/* Print the serial number of an OpenPGP card if available. */
1410
1578
static void
1411
1579
print_card_serialno (PKT_secret_key *sk)
1417
1585
  if (!sk->is_protected || sk->protect.s2k.mode != 1002) 
1418
1586
    return; /* Not a card. */
1419
1587
  if (opt.with_colons)
1420
 
    return; /* Format not yet defined. */
 
1588
    return; /* Handled elsewhere. */
1421
1589
 
1422
1590
  fputs (_("      Card serial no. ="), stdout);
1423
1591
  putchar (' ');
1439
1607
  putchar ('\n');
1440
1608
}
1441
1609
 
 
1610
 
 
1611
 
1442
1612
void set_attrib_fd(int fd)
1443
1613
{
1444
1614
  static int last_fd=-1;
1457
1627
  else if( fd == 2 )
1458
1628
    attrib_fp = stderr;
1459
1629
  else
1460
 
    attrib_fp = fdopen( fd, "w" );
 
1630
    attrib_fp = fdopen( fd, "wb" );
1461
1631
  if( !attrib_fp ) {
1462
1632
    log_fatal("can't open fd %d for attribute output: %s\n",
1463
1633
              fd, strerror(errno));
1464
1634
  }
 
1635
 
1465
1636
  last_fd = fd;
1466
1637
}