~ubuntu-branches/ubuntu/hardy/gnupg2/hardy-proposed

« back to all changes in this revision

Viewing changes to sm/export.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Bienia
  • Date: 2007-05-15 13:54:55 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070515135455-89qfyalmgjy6gcqw
Tags: 2.0.4-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Remove libpcsclite-dev, libopensc2-dev build dependencies (they are in
    universe).
  - Build-depend on libcurl3-gnutls-dev
  - g10/call-agent.c: set DBG_ASSUAN to 0 to suppress a debug message
  - Include /doc files as done with gnupg
  - debian/rules: add doc/com-certs.pem to the docs for gpgsm
  - debian/copyright: update download url
  - debian/README.Debian: remove note the gnupg2 isn't released yet.
  - debian/control: Change Maintainer/XSBC-Original-Maintainer field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
#define DUPTABLE_SIZE (1 << DUPTABLE_BITS)
58
58
 
59
59
 
60
 
static void print_short_info (ksba_cert_t cert, FILE *fp);
 
60
static void print_short_info (ksba_cert_t cert, FILE *fp, estream_t stream);
61
61
static gpg_error_t export_p12 (ctrl_t ctrl,
62
62
                               const unsigned char *certimg, size_t certimglen,
63
63
                               const char *prompt, const char *keygrip,
127
127
 
128
128
 
129
129
 
130
 
/* Export all certificates or just those given in NAMES. */
 
130
/* Export all certificates or just those given in NAMES. If STREAM is
 
131
   not NULL the output is send to this extended stream. */
131
132
void
132
 
gpgsm_export (ctrl_t ctrl, strlist_t names, FILE *fp)
 
133
gpgsm_export (ctrl_t ctrl, strlist_t names, FILE *fp, estream_t stream)
133
134
{
134
135
  KEYDB_HANDLE hd = NULL;
135
136
  KEYDB_SEARCH_DESC *desc = NULL;
257
258
          if (ctrl->create_pem)
258
259
            {
259
260
              if (count)
 
261
                {
 
262
                  if (stream)
 
263
                    es_putc ('\n', stream);
 
264
                  else
 
265
                    putc ('\n', fp);
 
266
                }
 
267
              print_short_info (cert, fp, stream);
 
268
              if (stream)
 
269
                es_putc ('\n', stream);
 
270
              else
260
271
                putc ('\n', fp);
261
 
              print_short_info (cert, fp);
262
 
              putc ('\n', fp);
263
272
            }
264
273
          count++;
265
274
 
266
275
          if (!b64writer)
267
276
            {
268
277
              ctrl->pem_name = "CERTIFICATE";
269
 
              rc = gpgsm_create_writer (&b64writer, ctrl, fp, &writer);
 
278
              rc = gpgsm_create_writer (&b64writer, ctrl, fp, stream, &writer);
270
279
              if (rc)
271
280
                {
272
281
                  log_error ("can't create writer: %s\n", gpg_strerror (rc));
403
412
 
404
413
  if (ctrl->create_pem)
405
414
    {
406
 
      print_short_info (cert, fp);
 
415
      print_short_info (cert, fp, NULL);
407
416
      putc ('\n', fp);
408
417
    }
409
418
 
 
419
  if (opt.p12_charset)
 
420
    {
 
421
      fprintf (fp, "The passphrase is %s encoded.\n\n",
 
422
               opt.p12_charset);
 
423
    }
 
424
 
410
425
  ctrl->pem_name = "PKCS12";
411
 
  rc = gpgsm_create_writer (&b64writer, ctrl, fp, &writer);
 
426
  rc = gpgsm_create_writer (&b64writer, ctrl, fp, NULL, &writer);
412
427
  if (rc)
413
428
    {
414
429
      log_error ("can't create writer: %s\n", gpg_strerror (rc));
461
476
}
462
477
 
463
478
 
464
 
/* Print some info about the certifciate CERT to FP */
465
 
static void
466
 
print_short_info (ksba_cert_t cert, FILE *fp)
 
479
/* Call either es_putc or the plain putc.  */
 
480
static void
 
481
do_putc (int value, FILE *fp, estream_t stream)
 
482
{
 
483
  if (stream)
 
484
    es_putc (value, stream);
 
485
  else
 
486
    putc (value, fp);
 
487
}
 
488
 
 
489
/* Call either es_fputs or the plain fputs.  */
 
490
static void
 
491
do_fputs (const char *string, FILE *fp, estream_t stream)
 
492
{
 
493
  if (stream)
 
494
    es_fputs (string, stream);
 
495
  else
 
496
    fputs (string, fp);
 
497
}
 
498
 
 
499
 
 
500
/* Print some info about the certifciate CERT to FP or STREAM */
 
501
static void
 
502
print_short_info (ksba_cert_t cert, FILE *fp, estream_t stream)
467
503
{
468
504
  char *p;
469
505
  ksba_sexp_t sexp;
471
507
 
472
508
  for (idx=0; (p = ksba_cert_get_issuer (cert, idx)); idx++)
473
509
    {
474
 
      fputs (!idx?   "Issuer ...: "
475
 
                 : "\n   aka ...: ", fp); 
476
 
      gpgsm_print_name (fp, p);
 
510
      do_fputs ((!idx
 
511
                 ?   "Issuer ...: "
 
512
                 : "\n   aka ...: "), fp, stream); 
 
513
      if (stream)
 
514
        gpgsm_es_print_name (stream, p);
 
515
      else
 
516
        gpgsm_print_name (fp, p);
477
517
      xfree (p);
478
518
    }
479
 
  putc ('\n', fp);
 
519
  do_putc ('\n', fp, stream);
480
520
 
481
 
  fputs ("Serial ...: ", fp); 
 
521
  do_fputs ("Serial ...: ", fp, stream); 
482
522
  sexp = ksba_cert_get_serial (cert);
483
523
  if (sexp)
484
524
    {
491
531
          for (len=0; *s && *s != ':' && digitp (s); s++)
492
532
            len = len*10 + atoi_1 (s);
493
533
          if (*s == ':')
494
 
            for (s++; len; len--, s++)
495
 
              fprintf (fp, "%02X", *s);
 
534
            {
 
535
              if (stream)
 
536
                es_write_hexstring (stream, s+1, len, 0, NULL);
 
537
              else
 
538
                print_hexstring (fp, s+1, len, 0);
 
539
            }
496
540
        }
497
541
      xfree (sexp);
498
542
    }
499
 
  putc ('\n', fp);
 
543
  do_putc ('\n', fp, stream);
500
544
 
501
545
  for (idx=0; (p = ksba_cert_get_subject (cert, idx)); idx++)
502
546
    {
503
 
      fputs (!idx?   "Subject ..: "
504
 
                 : "\n    aka ..: ", fp); 
505
 
      gpgsm_print_name (fp, p);
 
547
      do_fputs ((!idx
 
548
                 ?   "Subject ..: "
 
549
                 : "\n    aka ..: "), fp, stream); 
 
550
      if (stream)
 
551
        gpgsm_es_print_name (stream, p);
 
552
      else
 
553
        gpgsm_print_name (fp, p);
506
554
      xfree (p);
507
555
    }
508
 
  putc ('\n', fp);
 
556
  do_putc ('\n', fp, stream);
509
557
}
510
558
 
511
559
 
525
573
  argv[i++] = "--prompt";
526
574
  argv[i++] = prompt?prompt:"";
527
575
  argv[i++] = "--enable-status-msg";
 
576
  if (opt.p12_charset)
 
577
    {
 
578
      argv[i++] = "--p12-charset";
 
579
      argv[i++] = opt.p12_charset;
 
580
    }
528
581
  argv[i++] = "--",
529
582
  argv[i++] = keygrip,
530
583
  argv[i] = NULL;