~ubuntu-branches/ubuntu/precise/gnupg2/precise-proposed

« back to all changes in this revision

Viewing changes to tools/gpgparsemail.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Urlichs
  • Date: 2006-01-24 04:31:42 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060124043142-pbg192or6qxv3yk2
Tags: 1.9.20-1
* New Upstream version. Closes:#306890,#344530
  * Closes:#320490: gpg-protect-tool fails to decrypt PKCS-12 files 
* Depend on libopensc2-dev, not -1-. Closes:#348106

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
/* This utility prints an RFC8222, possible MIME structured, message
23
23
   in an annotated format with the first column having an indicator
24
 
   for the content of the line..  Several options are available to
25
 
   scrutinize the message.  S/MIME and OpenPGP suuport is included. */
 
24
   for the content of the line.  Several options are available to
 
25
   scrutinize the message.  S/MIME and OpenPGP support is included. */
26
26
 
27
27
 
28
28
#include <stdio.h>
60
60
  int show_boundary;
61
61
  int nesting_level;
62
62
 
 
63
  int is_pkcs7;                /* Old style S/MIME message. */
 
64
 
63
65
  int gpgsm_mime;              /* gpgsm shall be used from S/MIME. */
64
66
  char *signing_protocol;
65
67
  int hashing_level;           /* The nesting level we are hashing. */
66
68
  int hashing;                 
67
69
  FILE *hash_file;
68
 
  FILE *sig_file;
69
 
  int  verify_now;             /* Falg set when all signature data is
 
70
 
 
71
  FILE *sig_file;              /* Signature part with MIME or full
 
72
                                  pkcs7 data if IS_PCKS7 is set. */
 
73
  int  verify_now;             /* Flag set when all signature data is
70
74
                                  available. */
71
75
};
72
76
 
183
187
        }
184
188
      
185
189
      /* Keep our data fd and format it for gpg/gpgsm use. */
186
 
      sprintf (data_fd_buf, "-&%d", data_fd);
 
190
      if (data_fd == -1)
 
191
        *data_fd_buf = 0;
 
192
      else
 
193
        sprintf (data_fd_buf, "-&%d", data_fd);
187
194
 
188
195
      /* Send stdout to the bit bucket. */
189
196
      fd = open ("/dev/null", O_WRONLY);
214
221
              "--assume-base64",
215
222
              "--verify",
216
223
              "--",
217
 
              "-", data_fd_buf,
 
224
              "-", data_fd == -1? NULL : data_fd_buf,
218
225
              NULL);
219
226
 
220
227
      die ("failed to exec the crypto command: %s", strerror (errno));
287
294
{
288
295
  int close_list[10];
289
296
 
290
 
  assert (info->hash_file);
291
 
  assert (info->sig_file);
292
 
  rewind (info->hash_file);
293
 
  rewind (info->sig_file);
 
297
  if (info->is_pkcs7)
 
298
    {
 
299
      assert (!info->hash_file);
 
300
      assert (info->sig_file);
 
301
      rewind (info->sig_file);
 
302
    }
 
303
  else
 
304
    {
 
305
      assert (info->hash_file);
 
306
      assert (info->sig_file);
 
307
      rewind (info->hash_file);
 
308
      rewind (info->sig_file);
 
309
    }
294
310
 
295
311
/*   printf ("# Begin hashed data\n"); */
296
312
/*   while ( (c=getc (info->hash_file)) != EOF) */
304
320
/*   rewind (info->sig_file); */
305
321
 
306
322
  close_list[0] = -1;
307
 
  run_gnupg (1, fileno (info->sig_file), fileno (info->hash_file), close_list);
 
323
  run_gnupg (1, fileno (info->sig_file),
 
324
             info->hash_file ? fileno (info->hash_file) : -1, close_list);
308
325
}
309
326
 
310
327
 
353
370
}
354
371
 
355
372
 
 
373
/* Prepare for old-style pkcs7 messages. */
 
374
static void
 
375
pkcs7_begin (struct parse_info_s *info, rfc822parse_t msg,
 
376
             rfc822parse_field_t field_ctx)
 
377
{
 
378
  const char *s;
 
379
  s = rfc822parse_query_parameter (field_ctx, "name", 0);
 
380
  if (s)
 
381
    printf ("h pkcs7.name: %s\n", s);
 
382
  if (info->is_pkcs7)
 
383
    err ("note: ignoring nested pkcs7 data");
 
384
  else
 
385
    {
 
386
      info->is_pkcs7 = 1;
 
387
      if (opt_crypto)
 
388
        {
 
389
          assert (!info->sig_file);
 
390
          info->sig_file = tmpfile ();
 
391
          if (!info->sig_file)
 
392
            die ("error creating temp file: %s", strerror (errno));
 
393
        }
 
394
    }
 
395
}
 
396
 
356
397
 
357
398
/* Print the event received by the parser for debugging as comment
358
399
   line. */
439
480
                  else if (!strcmp (s2, "encrypted"))
440
481
                    mime_encrypted_begin (info, msg, ctx);
441
482
                }
 
483
              else if (!strcmp (s1, "application")
 
484
                       && (!strcmp (s2, "pkcs7-mime")
 
485
                           || !strcmp (s2, "x-pkcs7-mime")))
 
486
                pkcs7_begin (info, msg, ctx);
442
487
            }
443
488
          else
444
489
            printf ("h media: %*s none\n", info->nesting_level*2, "");
581
626
          if (info.verify_now)
582
627
            {
583
628
              verify_signature (&info);
584
 
              fclose (info.hash_file);
 
629
              if (info.hash_file)
 
630
                fclose (info.hash_file);
585
631
              info.hash_file = NULL;
586
632
              fclose (info.sig_file);
587
633
              info.sig_file = NULL;
588
634
              info.gpgsm_mime = 0;
 
635
              info.is_pkcs7 = 0;
589
636
            }
590
637
          else
591
638
            {
621
668
 
622
669
    }
623
670
 
 
671
  if (info.sig_file && opt_crypto && info.is_pkcs7)
 
672
    {
 
673
      verify_signature (&info);
 
674
      fclose (info.sig_file);
 
675
      info.sig_file = NULL;
 
676
      info.is_pkcs7 = 0;
 
677
    }
 
678
 
624
679
  rfc822parse_close (msg);
625
680
}
626
681
 
653
708
                "  --debug     enable additional debug output\n"
654
709
                "  --help      display this help and exit\n\n"
655
710
                "With no FILE, or when FILE is -, read standard input.\n\n"
 
711
                "WARNING: This tool is under development.\n"
 
712
                "         The semantics may change without notice\n\n"
656
713
                "Report bugs to <bug-gnupg@gnu.org>.");
657
714
          exit (0);
658
715
        }