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

« back to all changes in this revision

Viewing changes to g10/mainproc.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Bienia
  • Date: 2007-02-02 14:29:54 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070202142954-f5h55skq432ona6m
Tags: 2.0.2-0ubuntu1
* New upstream release
  - includes the patch for CVE-2006-6235
  - a PIN pad can now also be used for signing keys
* Remaining changes:
  - Remove libpcsclite-dev, libopensc2-dev build dependencies (they are in
    universe).
  - Build-depend on libcurl3-gnutls-dev
  - Include /doc files as done with gnupg
* g10/call-agent.c: set DBG_ASSUAN to 0 to suppress a debug message
* debian/rules: add doc/com-certs.pem to the docs for gpgsm
* debian/README.Debian: remove note the gnupg2 isn't released yet.
* Modified Maintainer values to match Debian-Maintainer-Field spec.

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
  md_filter_context_t mfx;
66
66
  int sigs_only;    /* Process only signatures and reject all other stuff. */
67
67
  int encrypt_only; /* Process only encryption messages. */
68
 
  strlist_t signed_data;
 
68
    
 
69
  /* Name of the file with the complete signature or the file with the
 
70
     detached signature.  This is currently only used to deduce the
 
71
     file name of the data file if that has not been given. */
69
72
  const char *sigfilename;
 
73
  
 
74
  /* A structure to describe the signed data in case of a detached
 
75
     signature. */
 
76
  struct 
 
77
  {
 
78
    /* A file descriptor of the the signed data.  Only used if not -1. */
 
79
    int data_fd;
 
80
    /* A list of filenames with the data files or NULL. This is only
 
81
       used if DATA_FD is -1. */
 
82
    strlist_t data_names;
 
83
    /* Flag to indicated that either one of the next previous fieldss
 
84
       is used.  This is only needed for better readability. */
 
85
    int used;
 
86
  } signed_data;
 
87
  
70
88
  DEK *dek;
71
89
  int last_was_session_key;
72
90
  KBNODE list;      /* The current list of packets. */
290
308
          }
291
309
        else
292
310
          {
293
 
            int canceled;
294
 
 
295
311
            c->dek = passphrase_to_dek (NULL, 0, algo, &enc->s2k, 0,
296
 
                                        NULL, &canceled);
297
 
            if (canceled)
298
 
              {
299
 
                /* For unknown reasons passphrase_to_dek does only
300
 
                   return NULL if a new passphrase has been requested
301
 
                   and has not been repeated correctly.  Thus even
302
 
                   with a cancel requested (by means of the gpg-agent)
303
 
                   it won't return NULL but an empty passphrase.  We
304
 
                   take the most conservative approach for now and
305
 
                   work around it right here. */
306
 
                xfree (c->dek);
307
 
                c->dek = NULL;
308
 
              }
309
 
 
 
312
                                        NULL, NULL);
310
313
            if(c->dek)
311
314
              {
312
315
                c->dek->symmetric=1;
707
710
static int
708
711
proc_compressed_cb( IOBUF a, void *info )
709
712
{
710
 
    return proc_signature_packets( info, a, ((CTX)info)->signed_data,
711
 
                                            ((CTX)info)->sigfilename );
 
713
  if ( ((CTX)info)->signed_data.used
 
714
       && ((CTX)info)->signed_data.data_fd != -1)
 
715
    return proc_signature_packets_by_fd (info, a,
 
716
                                         ((CTX)info)->signed_data.data_fd);
 
717
  else
 
718
    return proc_signature_packets (info, a,
 
719
                                   ((CTX)info)->signed_data.data_names,
 
720
                                   ((CTX)info)->sigfilename );
712
721
}
713
722
 
714
723
static int
1139
1148
 
1140
1149
    c->anchor = anchor;
1141
1150
    c->sigs_only = 1;
1142
 
    c->signed_data = signedfiles;
 
1151
 
 
1152
    c->signed_data.data_fd = -1;
 
1153
    c->signed_data.data_names = signedfiles;
 
1154
    c->signed_data.used = !!signedfiles;
 
1155
 
1143
1156
    c->sigfilename = sigfilename;
1144
1157
    rc = do_proc_packets( c, a );
1145
1158
 
1166
1179
}
1167
1180
 
1168
1181
int
 
1182
proc_signature_packets_by_fd (void *anchor, IOBUF a, int signed_data_fd )
 
1183
{
 
1184
  int rc;
 
1185
  CTX c = xcalloc (1, sizeof *c);
 
1186
 
 
1187
  c->anchor = anchor;
 
1188
  c->sigs_only = 1;
 
1189
 
 
1190
  c->signed_data.data_fd = signed_data_fd;
 
1191
  c->signed_data.data_names = NULL;
 
1192
  c->signed_data.used = (signed_data_fd != -1);
 
1193
 
 
1194
  rc = do_proc_packets ( c, a );
 
1195
 
 
1196
  /* If we have not encountered any signature we print an error
 
1197
     messages, send a NODATA status back and return an error code.
 
1198
     Using log_error is required because verify_files does not check
 
1199
     error codes for each file but we want to terminate the process
 
1200
     with an error. */ 
 
1201
  if (!rc && !c->any_sig_seen)
 
1202
    {
 
1203
      write_status_text (STATUS_NODATA, "4");
 
1204
      log_error (_("no signature found\n"));
 
1205
      rc = gpg_error (GPG_ERR_NO_DATA);
 
1206
    }
 
1207
  
 
1208
  /* Propagate the signature seen flag upward. Do this only on success
 
1209
     so that we won't issue the nodata status several times. */
 
1210
  if (!rc && c->anchor && c->any_sig_seen)
 
1211
    c->anchor->any_sig_seen = 1;
 
1212
  
 
1213
  xfree ( c );
 
1214
  return rc;
 
1215
}
 
1216
 
 
1217
 
 
1218
int
1169
1219
proc_encryption_packets( void *anchor, IOBUF a )
1170
1220
{
1171
1221
    CTX c = xmalloc_clear( sizeof *c );
1914
1964
    else if( node->pkt->pkttype == PKT_ONEPASS_SIG ) {
1915
1965
        /* check all signatures */
1916
1966
        if( !c->have_data ) {
 
1967
            int use_textmode = 0;
 
1968
 
1917
1969
            free_md_filter_context( &c->mfx );
1918
1970
            /* prepare to create all requested message digests */
1919
1971
            if (gcry_md_open (&c->mfx.md, 0, 0))
1926
1978
                gcry_md_enable (c->mfx.md,
1927
1979
                                n1->pkt->pkt.signature->digest_algo);
1928
1980
              }
1929
 
            /* ask for file and hash it */
 
1981
 
 
1982
            if (n1 && n1->pkt->pkt.onepass_sig->sig_class == 0x01)
 
1983
                use_textmode = 1;
 
1984
 
 
1985
            /* Ask for file and hash it. */
1930
1986
            if( c->sigs_only ) {
1931
 
                rc = hash_datafiles( c->mfx.md, NULL,
1932
 
                                     c->signed_data, c->sigfilename,
1933
 
                        n1? (n1->pkt->pkt.onepass_sig->sig_class == 0x01):0 );
 
1987
                if (c->signed_data.used && c->signed_data.data_fd != -1)
 
1988
                    rc = hash_datafile_by_fd (c->mfx.md, NULL,
 
1989
                                              c->signed_data.data_fd,
 
1990
                                              use_textmode);
 
1991
                else
 
1992
                    rc = hash_datafiles (c->mfx.md, NULL,
 
1993
                                         c->signed_data.data_names,
 
1994
                                         c->sigfilename,
 
1995
                                         use_textmode );
1934
1996
            }
1935
1997
            else {
1936
 
                rc = ask_for_detached_datafile( c->mfx.md, c->mfx.md2,
 
1998
                rc = ask_for_detached_datafile (c->mfx.md, c->mfx.md2,
1937
1999
                                                iobuf_get_real_fname(c->iobuf),
1938
 
                        n1? (n1->pkt->pkt.onepass_sig->sig_class == 0x01):0 );
 
2000
                                                use_textmode );
1939
2001
            }
1940
2002
            if( rc ) {
1941
2003
                log_error("can't hash datafile: %s\n", g10_errstr(rc));
1942
2004
                return;
1943
2005
            }
1944
2006
        }
1945
 
        else if ( c->signed_data ) {
 
2007
        else if ( c->signed_data.used ) {
1946
2008
            log_error (_("not a detached signature\n") );
1947
2009
            return;
1948
2010
        }
1958
2020
            log_error("cleartext signature without data\n" );
1959
2021
            return;
1960
2022
        }
1961
 
        else if ( c->signed_data ) {
 
2023
        else if ( c->signed_data.used ) {
1962
2024
            log_error (_("not a detached signature\n") );
1963
2025
            return;
1964
2026
        }
2034
2096
                    gcry_md_start_debug( c->mfx.md2, "verify2" );
2035
2097
            }
2036
2098
            if( c->sigs_only ) {
2037
 
                rc = hash_datafiles( c->mfx.md, c->mfx.md2,
2038
 
                                     c->signed_data, c->sigfilename,
2039
 
                                     (sig->sig_class == 0x01) );
 
2099
                if (c->signed_data.used && c->signed_data.data_fd != -1)
 
2100
                    rc = hash_datafile_by_fd (c->mfx.md, c->mfx.md2,
 
2101
                                              c->signed_data.data_fd, 
 
2102
                                              (sig->sig_class == 0x01));
 
2103
                else
 
2104
                    rc = hash_datafiles (c->mfx.md, c->mfx.md2,
 
2105
                                         c->signed_data.data_names,
 
2106
                                         c->sigfilename,
 
2107
                                         (sig->sig_class == 0x01));
2040
2108
            }
2041
2109
            else {
2042
2110
                rc = ask_for_detached_datafile( c->mfx.md, c->mfx.md2,
2048
2116
                return;
2049
2117
            }
2050
2118
        }
2051
 
        else if ( c->signed_data ) {
 
2119
        else if ( c->signed_data.used ) {
2052
2120
            log_error (_("not a detached signature\n") );
2053
2121
            return;
2054
2122
        }