~ubuntu-branches/ubuntu/precise/gnupg2/precise-updates

« back to all changes in this revision

Viewing changes to g10/verify.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Bienia
  • Date: 2007-02-02 14:29:54 UTC
  • mto: (5.1.9 feisty) (7.1.1 squeeze) (1.1.13 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20070202142954-8dmrb4d9l2imbtdm
Tags: upstream-2.0.2
ImportĀ upstreamĀ versionĀ 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
verify_signatures( int nfiles, char **files )
56
56
{
57
57
    IOBUF fp;
58
 
    armor_filter_context_t afx;
59
 
    progress_filter_context_t pfx;
 
58
    armor_filter_context_t *afx = NULL;
 
59
    progress_filter_context_t *pfx = new_progress_context ();
60
60
    const char *sigfile;
61
61
    int i, rc;
62
62
    strlist_t sl;
63
63
 
64
 
    memset( &afx, 0, sizeof afx);
65
 
    /* decide whether we should handle a detached or a normal signature,
 
64
    /* Decide whether we should handle a detached or a normal signature,
66
65
     * which is needed so that the code later can hash the correct data and
67
66
     * not have a normal signature act as detached signature and ignoring the
68
67
     * indended signed material from the 2nd file or stdin.
71
70
     * 3. gpg file <file2  - detached
72
71
     * 4. gpg file file2   - detached
73
72
     * The question is how decide between case 2 and 3?  The only way
74
 
     * we can do it is by reading one byte from stdin and the unget
 
73
     * we can do it is by reading one byte from stdin and then unget
75
74
     * it; the problem here is that we may be reading from the
76
75
     * terminal (which could be detected using isatty() but won't work
77
76
     * when under contol of a pty using program (e.g. expect)) and
86
85
     * that all quite easily in mainproc.c 
87
86
     */
88
87
     
89
 
 
90
88
    sigfile = nfiles? *files : NULL;
91
89
 
92
90
    /* open the signature file */
101
99
        rc = gpg_error_from_syserror ();
102
100
        log_error(_("can't open `%s': %s\n"),
103
101
                  print_fname_stdin(sigfile), strerror (errno));
104
 
        return rc;
 
102
        goto leave;
105
103
    }
106
 
    handle_progress (&pfx, fp, sigfile);
 
104
    handle_progress (pfx, fp, sigfile);
107
105
 
108
 
    if( !opt.no_armor && use_armor_filter( fp ) )
109
 
        iobuf_push_filter( fp, armor_filter, &afx );
 
106
    if ( !opt.no_armor && use_armor_filter( fp ) )
 
107
      {
 
108
        afx = new_armor_context ();
 
109
        push_armor_filter (afx, fp);
 
110
      }
110
111
 
111
112
    sl = NULL;
112
113
    for(i=nfiles-1 ; i > 0 ; i-- )
114
115
    rc = proc_signature_packets( NULL, fp, sl, sigfile );
115
116
    free_strlist(sl);
116
117
    iobuf_close(fp);
117
 
    if( (afx.no_openpgp_data && rc == -1) || rc == G10ERR_NO_DATA ) {
 
118
    if( (afx && afx->no_openpgp_data && rc == -1) || rc == G10ERR_NO_DATA ) {
118
119
        log_error(_("the signature could not be verified.\n"
119
120
                   "Please remember that the signature file (.sig or .asc)\n"
120
121
                   "should be the first file given on the command line.\n") );
121
122
        rc = 0;
122
123
    }
123
124
 
 
125
 leave:
 
126
    release_armor_context (afx);
 
127
    release_progress_context (pfx);
124
128
    return rc;
125
129
}
126
130
 
127
131
 
 
132
 
128
133
void
129
134
print_file_status( int status, const char *name, int what )
130
135
{
139
144
verify_one_file( const char *name )
140
145
{
141
146
    IOBUF fp;
142
 
    armor_filter_context_t afx;
143
 
    progress_filter_context_t pfx;
 
147
    armor_filter_context_t *afx = NULL;
 
148
    progress_filter_context_t *pfx = new_progress_context ();
144
149
    int rc;
145
150
 
146
151
    print_file_status( STATUS_FILE_START, name, 1 );
158
163
        log_error(_("can't open `%s': %s\n"),
159
164
                  print_fname_stdin(name), strerror (errno));
160
165
        print_file_status( STATUS_FILE_ERROR, name, 1 );
161
 
        return rc;
 
166
        goto leave;
162
167
    }
163
 
    handle_progress (&pfx, fp, name);
 
168
    handle_progress (pfx, fp, name);
164
169
 
165
170
    if( !opt.no_armor ) {
166
171
        if( use_armor_filter( fp ) ) {
167
 
            memset( &afx, 0, sizeof afx);
168
 
            iobuf_push_filter( fp, armor_filter, &afx );
 
172
            afx = new_armor_context ();
 
173
            push_armor_filter (afx, fp);
169
174
        }
170
175
    }
171
176
 
172
177
    rc = proc_signature_packets( NULL, fp, NULL, name );
173
178
    iobuf_close(fp);
174
179
    write_status( STATUS_FILE_DONE );
 
180
 
 
181
 leave:
 
182
    release_armor_context (afx);
 
183
    release_progress_context (pfx);
175
184
    return rc;
176
185
}
177
186
 
209
218
    }
210
219
    return 0;
211
220
}
 
221
 
 
222
 
 
223
 
 
224
 
 
225
/* Perform a verify operation.  To verify detached signatures, DATA_FD
 
226
   shall be the descriptor of the signed data; for regular signatures
 
227
   it needs to be -1.  If OUT_FP is not NULL and DATA_FD is not -1 the
 
228
   the signed material gets written that stream. 
 
229
 
 
230
   FIXME: OUTFP is not yet implemented.
 
231
*/
 
232
int
 
233
gpg_verify (ctrl_t ctrl, int sig_fd, int data_fd, FILE *out_fp)
 
234
{
 
235
  int rc;
 
236
  iobuf_t fp;
 
237
  armor_filter_context_t *afx = NULL;
 
238
  progress_filter_context_t *pfx = new_progress_context ();
 
239
 
 
240
  fp = iobuf_fdopen (sig_fd, "rb");
 
241
  if (fp && is_secured_file (sig_fd))
 
242
    {
 
243
      fp = NULL;
 
244
      errno = EPERM;
 
245
    }
 
246
  if ( !fp )
 
247
    {
 
248
      rc = gpg_error_from_syserror ();
 
249
      log_error (_("can't open fd %d: %s\n"), sig_fd, strerror (errno));
 
250
      goto leave;
 
251
    }
 
252
 
 
253
  handle_progress (pfx, fp, NULL);
 
254
 
 
255
  if ( !opt.no_armor && use_armor_filter (fp) )
 
256
    {
 
257
      afx = new_armor_context ();
 
258
      push_armor_filter (afx, fp);
 
259
    }
 
260
 
 
261
  rc = proc_signature_packets_by_fd ( NULL, fp, data_fd );
 
262
 
 
263
  if ( afx && afx->no_openpgp_data
 
264
       && (rc == -1 || gpg_err_code (rc) == GPG_ERR_EOF) )
 
265
    rc = gpg_error (GPG_ERR_NO_DATA);
 
266
 
 
267
 leave:  
 
268
  if (fp)
 
269
    iobuf_close (fp);
 
270
  release_progress_context (pfx);
 
271
  release_armor_context (afx);
 
272
  return rc;
 
273
}
 
274