~ubuntu-branches/ubuntu/karmic/gnupg2/karmic-updates

« back to all changes in this revision

Viewing changes to g10/sig-check.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
1
/* sig-check.c -  Check a signature
2
 
 * Copyright (C) 1998, 1999, 2000, 2001, 2002,
3
 
 *               2003  Free Software Foundation, Inc.
 
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003,
 
3
 *               2004, 2006 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>
28
27
#include "gpg.h"
29
28
#include "util.h"
30
29
#include "packet.h"
31
 
#include "memory.h"
32
 
#include "mpi.h"
33
30
#include "keydb.h"
34
31
#include "cipher.h"
35
32
#include "main.h"
38
35
#include "options.h"
39
36
#include "pkglue.h"
40
37
 
41
 
struct cmp_help_context_s {
42
 
    PKT_signature *sig;
43
 
    MD_HANDLE md;
 
38
/* Context used by the compare function. */
 
39
struct cmp_help_context_s
 
40
{
 
41
  PKT_signature *sig;
 
42
  gcry_md_hd_t md;
44
43
};
45
44
 
46
45
 
47
 
static int do_check( PKT_public_key *pk, PKT_signature *sig, MD_HANDLE digest,
 
46
 
 
47
static int do_check( PKT_public_key *pk, PKT_signature *sig,
 
48
                     gcry_md_hd_t digest,
48
49
                     int *r_expired, int *r_revoked, PKT_public_key *ret_pk);
49
50
 
50
51
/****************
53
54
 * is able to append some data, before finalizing the digest.
54
55
 */
55
56
int
56
 
signature_check( PKT_signature *sig, MD_HANDLE digest )
 
57
signature_check (PKT_signature *sig, gcry_md_hd_t digest)
57
58
{
58
59
    return signature_check2( sig, digest, NULL, NULL, NULL, NULL );
59
60
}
60
61
 
61
62
int
62
 
signature_check2( PKT_signature *sig, MD_HANDLE digest, u32 *r_expiredate, 
 
63
signature_check2 (PKT_signature *sig, gcry_md_hd_t digest, u32 *r_expiredate, 
63
64
                  int *r_expired, int *r_revoked, PKT_public_key *ret_pk )
64
65
{
65
 
    PKT_public_key *pk = xcalloc (1, sizeof *pk );
 
66
    PKT_public_key *pk = xmalloc_clear( sizeof *pk );
66
67
    int rc=0;
67
68
 
68
 
    /* Sanity check that the md has a context for the hash that the
69
 
       sig is expecting.  This can happen if a onepass sig header does
70
 
       not match the actual sig, and also if the clearsign "Hash:"
71
 
       header is missing or does not match the actual sig. */
 
69
    if ( (rc=openpgp_md_test_algo(sig->digest_algo)) )
 
70
      ; /* We don't have this digest. */
 
71
    else if ((rc=openpgp_pk_test_algo(sig->pubkey_algo)))
 
72
      ; /* We don't have this pubkey algo. */
 
73
    else if (!gcry_md_is_enabled (digest,sig->digest_algo))
 
74
      {
 
75
        /* Sanity check that the md has a context for the hash that the
 
76
           sig is expecting.  This can happen if a onepass sig header does
 
77
           not match the actual sig, and also if the clearsign "Hash:"
 
78
           header is missing or does not match the actual sig. */
72
79
 
73
 
    if(!gcry_md_is_enabled (digest,sig->digest_algo)) {
74
80
        log_info(_("WARNING: signature digest conflict in message\n"));
75
 
        rc=GPG_ERR_GENERAL;
76
 
    }
 
81
        rc=G10ERR_GENERAL;
 
82
      }
77
83
    else if( get_pubkey( pk, sig->keyid ) )
78
 
        rc = GPG_ERR_NO_PUBKEY;
 
84
        rc = G10ERR_NO_PUBKEY;
79
85
    else if(!pk->is_valid && !pk->is_primary)
80
 
        rc=GPG_ERR_BAD_PUBKEY; /* you cannot have a good sig from an
 
86
        rc=G10ERR_BAD_PUBKEY; /* you cannot have a good sig from an
81
87
                                 invalid subkey */
82
 
    else {
83
 
        if (r_expiredate)
84
 
            *r_expiredate = pk->expiredate;
 
88
    else
 
89
      {
 
90
        if(r_expiredate)
 
91
          *r_expiredate = pk->expiredate;
 
92
 
85
93
        rc = do_check( pk, sig, digest, r_expired, r_revoked, ret_pk );
86
 
    }
 
94
 
 
95
        /* Check the backsig.  This is a 0x19 signature from the
 
96
           subkey on the primary key.  The idea here is that it should
 
97
           not be possible for someone to "steal" subkeys and claim
 
98
           them as their own.  The attacker couldn't actually use the
 
99
           subkey, but they could try and claim ownership of any
 
100
           signaures issued by it. */
 
101
        if(rc==0 && !pk->is_primary && pk->backsig<2)
 
102
          {
 
103
            if(pk->backsig==0)
 
104
              {
 
105
                log_info(_("WARNING: signing subkey %s is not"
 
106
                           " cross-certified\n"),keystr_from_pk(pk));
 
107
                log_info(_("please see %s for more information\n"),
 
108
                         "http://www.gnupg.org/faq/subkey-cross-certify.html");
 
109
                /* --require-cross-certification makes this warning an
 
110
                     error.  TODO: change the default to require this
 
111
                     after more keys have backsigs. */
 
112
                if(opt.flags.require_cross_cert)
 
113
                  rc=G10ERR_GENERAL;
 
114
              }
 
115
            else if(pk->backsig==1)
 
116
              {
 
117
                log_info(_("WARNING: signing subkey %s has an invalid"
 
118
                           " cross-certification\n"),keystr_from_pk(pk));
 
119
                rc=G10ERR_GENERAL;
 
120
              }
 
121
          }
 
122
      }
87
123
 
88
124
    free_public_key( pk );
89
125
 
96
132
         * one second.  Some remote batch processing applications might
97
133
         * like this feature here */
98
134
        gcry_md_hd_t md;
 
135
 
99
136
        u32 a = sig->timestamp;
100
137
        int i, nsig = pubkey_get_nsig( sig->pubkey_algo );
101
138
        byte *p, *buffer;
102
139
 
103
 
        gcry_md_open (&md, GCRY_MD_RMD160, 0);
 
140
        if (gcry_md_open (&md, GCRY_MD_RMD160, 0))
 
141
          BUG ();
 
142
 
 
143
        /* FIXME:  Why the hell are we updating DIGEST here??? */
104
144
        gcry_md_putc( digest, sig->pubkey_algo );
105
145
        gcry_md_putc( digest, sig->digest_algo );
106
146
        gcry_md_putc( digest, (a >> 24) & 0xff );
107
147
        gcry_md_putc( digest, (a >> 16) & 0xff );
108
 
        gcry_md_putc( digest, (a >>  8) & 0xff );
109
 
        gcry_md_putc( digest,  a        & 0xff );
 
148
        gcry_md_putc( digest, (a >>     8) & 0xff );
 
149
        gcry_md_putc( digest,  a           & 0xff );
110
150
        for(i=0; i < nsig; i++ ) {
111
151
            size_t n;
112
152
            unsigned char *tmp;
113
153
 
114
154
            if (gcry_mpi_aprint (GCRYMPI_FMT_USG, &tmp, &n, sig->data[i]))
115
 
                BUG();
116
 
            
 
155
              BUG();
117
156
            gcry_md_write (md, tmp, n);
118
157
            xfree (tmp);
119
158
        }
120
 
        gcry_md_final( md );
121
 
        p = make_radix64_string( gcry_md_read( md, 0 ), 20 );
122
 
        buffer = xmalloc ( strlen(p) + 60 );
 
159
        gcry_md_final (md);
 
160
        p = make_radix64_string ( gcry_md_read( md, 0 ), 20 );
 
161
        buffer = xmalloc( strlen(p) + 60 );
123
162
        sprintf( buffer, "%s %s %lu",
124
163
                 p, strtimestamp( sig->timestamp ), (ulong)sig->timestamp );
125
164
        write_status_text( STATUS_SIG_ID, buffer );
126
 
        xfree (buffer);
127
 
        xfree (p);
 
165
        xfree(buffer);
 
166
        xfree(p);
128
167
        gcry_md_close(md);
129
168
    }
130
169
 
134
173
 
135
174
static int
136
175
do_check_messages( PKT_public_key *pk, PKT_signature *sig,
137
 
                   int *r_expired, int *r_revoked )
 
176
                   int *r_expired, int *r_revoked )
138
177
{
139
178
    u32 cur_time;
140
179
 
141
 
    if (r_expired)
 
180
    if(r_expired)
142
181
      *r_expired = 0;
143
 
    if (r_revoked)
 
182
    if(r_revoked)
144
183
      *r_revoked = 0;
145
 
    if( pk->version == 4 && pk->pubkey_algo == PUBKEY_ALGO_ELGAMAL_E ) {
146
 
        log_info(_("key %08lX: this is a PGP generated "
147
 
                   "ElGamal key which is NOT secure for signatures!\n"),
148
 
                  (ulong)keyid_from_pk(pk,NULL));
149
 
        return GPG_ERR_PUBKEY_ALGO;
150
 
    }
151
184
 
152
 
    if( pk->timestamp > sig->timestamp ) {
 
185
    if( pk->timestamp > sig->timestamp )
 
186
      {
153
187
        ulong d = pk->timestamp - sig->timestamp;
154
 
        log_info( d==1
155
 
             ? _("public key %08lX is %lu second newer than the signature\n")
156
 
             : _("public key %08lX is %lu seconds newer than the signature\n"),
157
 
                (ulong)keyid_from_pk(pk,NULL),d );
 
188
        log_info(d==1
 
189
                 ?_("public key %s is %lu second newer than the signature\n")
 
190
                 :_("public key %s is %lu seconds newer than the signature\n"),
 
191
                 keystr_from_pk(pk),d );
158
192
        if( !opt.ignore_time_conflict )
159
 
            return GPG_ERR_TIME_CONFLICT; /* pubkey newer than signature */
160
 
    }
 
193
          return G10ERR_TIME_CONFLICT; /* pubkey newer than signature */
 
194
      }
161
195
 
162
196
    cur_time = make_timestamp();
163
 
    if( pk->timestamp > cur_time ) {
 
197
    if( pk->timestamp > cur_time )
 
198
      {
164
199
        ulong d = pk->timestamp - cur_time;
165
 
        log_info( d==1 ? _("key %08lX has been created %lu second "
166
 
                           "in future (time warp or clock problem)\n")
167
 
                       : _("key %08lX has been created %lu seconds "
168
 
                           "in future (time warp or clock problem)\n"),
169
 
                       (ulong)keyid_from_pk(pk,NULL),d );
 
200
        log_info( d==1
 
201
                  ? _("key %s was created %lu second"
 
202
                      " in the future (time warp or clock problem)\n")
 
203
                  : _("key %s was created %lu seconds"
 
204
                      " in the future (time warp or clock problem)\n"),
 
205
                  keystr_from_pk(pk),d );
170
206
        if( !opt.ignore_time_conflict )
171
 
            return GPG_ERR_TIME_CONFLICT;
172
 
    }
 
207
          return G10ERR_TIME_CONFLICT;
 
208
      }
173
209
 
174
210
    if( pk->expiredate && pk->expiredate < cur_time ) {
175
211
        char buf[11];
176
 
        if (opt.verbose) {
177
 
            u32 tmp_kid[2];
178
 
 
179
 
            keyid_from_pk( pk, tmp_kid );
180
 
            log_info(_("NOTE: signature key %08lX expired %s\n"),
181
 
                     (ulong)tmp_kid[1], asctimestamp( pk->expiredate ) );
182
 
        }
 
212
        if (opt.verbose)
 
213
          log_info(_("NOTE: signature key %s expired %s\n"),
 
214
                   keystr_from_pk(pk), asctimestamp( pk->expiredate ) );
183
215
        /* SIGEXPIRED is deprecated.  Use KEYEXPIRED. */
184
216
        sprintf(buf,"%lu",(ulong)pk->expiredate);
185
217
        write_status_text(STATUS_KEYEXPIRED,buf);
186
218
        write_status(STATUS_SIGEXPIRED);
187
 
        if (r_expired)
188
 
          *r_expired = 1;
 
219
        if(r_expired)
 
220
          *r_expired = 1;
189
221
    }
190
222
 
191
223
    if(pk->is_revoked && r_revoked)
196
228
 
197
229
 
198
230
static int
199
 
do_check( PKT_public_key *pk, PKT_signature *sig, MD_HANDLE digest,
 
231
do_check( PKT_public_key *pk, PKT_signature *sig, gcry_md_hd_t digest,
200
232
          int *r_expired, int *r_revoked, PKT_public_key *ret_pk )
201
233
{
202
234
    gcry_mpi_t result = NULL;
203
 
    int rc=0;
 
235
    int rc = 0;
204
236
    struct cmp_help_context_s ctx;
205
237
 
206
238
    if( (rc=do_check_messages(pk,sig,r_expired,r_revoked)) )
207
239
        return rc;
208
 
    if( (rc=gcry_md_test_algo(sig->digest_algo)) )
209
 
        return rc;
210
 
    if( (rc=gcry_pk_test_algo(sig->pubkey_algo)) )
211
 
        return rc;
212
 
 
213
 
    /* make sure the digest algo is enabled (in case of a detached
214
 
       signature)*/
215
 
    gcry_md_enable( digest, sig->digest_algo );
216
 
 
217
 
    /* complete the digest */
 
240
 
 
241
    /* Make sure the digest algo is enabled (in case of a detached
 
242
       signature).  */
 
243
    gcry_md_enable (digest, sig->digest_algo);
 
244
 
 
245
    /* Complete the digest. */
218
246
    if( sig->version >= 4 )
219
247
        gcry_md_putc( digest, sig->version );
220
248
    gcry_md_putc( digest, sig->sig_class );
253
281
        buf[5] = n;
254
282
        gcry_md_write( digest, buf, 6 );
255
283
    }
256
 
    gcry_md_final (digest);
 
284
    gcry_md_final( digest );
257
285
 
258
 
    result = encode_md_value( pk->pubkey_algo, digest, sig->digest_algo,
259
 
                              mpi_get_nbits(pk->pkey[0]), 0 );
 
286
    result = encode_md_value( pk, NULL, digest, sig->digest_algo );
260
287
    if (!result)
261
 
        return GPG_ERR_GENERAL;
 
288
        return G10ERR_GENERAL;
262
289
    ctx.sig = sig;
263
290
    ctx.md = digest;
264
 
    rc = pk_verify ( pk->pubkey_algo, result, sig->data, pk->pkey);
265
 
    gcry_mpi_release ( result );
266
 
    if( (opt.emulate_bugs & EMUBUG_MDENCODE)
267
 
        && gpg_err_code (rc) == GPG_ERR_BAD_SIGNATURE
268
 
        && is_ELGAMAL(pk->pubkey_algo) ) {
269
 
        /* In this case we try again because old GnuPG versions didn't encode
270
 
         * the hash right. There is no problem with DSA however  */
271
 
        result = encode_md_value( pk->pubkey_algo, digest, sig->digest_algo,
272
 
                              mpi_get_nbits(pk->pkey[0]), (sig->version < 5) );
273
 
        if (!result)
274
 
            rc = GPG_ERR_GENERAL;
275
 
        else {
276
 
            ctx.sig = sig;
277
 
            ctx.md = digest;
278
 
            rc = pk_verify (pk->pubkey_algo, result, sig->data, pk->pkey);
279
 
        }
280
 
    }
 
291
    rc = pk_verify( pk->pubkey_algo, result, sig->data, pk->pkey );
 
292
    gcry_mpi_release (result);
281
293
 
282
 
    if( !rc && sig->flags.unknown_critical ) {
283
 
      log_info(_("assuming bad signature from key %08lX "
284
 
                 "due to an unknown critical bit\n"),
285
 
               (ulong)keyid_from_pk(pk,NULL));
286
 
        rc = gpg_error (GPG_ERR_BAD_SIGNATURE);
287
 
    }
 
294
    if( !rc && sig->flags.unknown_critical )
 
295
      {
 
296
        log_info(_("assuming bad signature from key %s"
 
297
                   " due to an unknown critical bit\n"),keystr_from_pk(pk));
 
298
        rc = G10ERR_BAD_SIGN;
 
299
      }
288
300
 
289
301
    if(!rc && ret_pk)
290
302
      copy_public_key(ret_pk,pk);
293
305
}
294
306
 
295
307
 
 
308
 
296
309
static void
297
 
hash_uid_node( KBNODE unode, MD_HANDLE md, PKT_signature *sig )
 
310
hash_uid_node( KBNODE unode, gcry_md_hd_t md, PKT_signature *sig )
298
311
{
299
312
    PKT_user_id *uid = unode->pkt->pkt.user_id;
300
313
 
342
355
    }
343
356
}
344
357
 
345
 
 
346
358
/* Check the revocation keys to see if any of them have revoked our
347
359
   pk.  sig is the revocation sig.  pk is the key it is on.  This code
348
360
   will need to be modified if gpg ever becomes multi-threaded.  Note
349
361
   that this guarantees that a designated revocation sig will never be
350
362
   considered valid unless it is actually valid, as well as being
351
 
   issued by a revocation key in a valid direct signature.  Note that
352
 
   this is written so that a revoked revoker can still issue
 
363
   issued by a revocation key in a valid direct signature.  Note also
 
364
   that this is written so that a revoked revoker can still issue
353
365
   revocations: i.e. If A revokes B, but A is revoked, B is still
354
366
   revoked.  I'm not completely convinced this is the proper behavior,
355
367
   but it matches how PGP does it. -dms */
356
368
 
357
369
/* Returns 0 if sig is valid (i.e. pk is revoked), non-0 if not
358
 
   revoked */
 
370
   revoked.  It is important that G10ERR_NO_PUBKEY is only returned
 
371
   when a revocation signature is from a valid revocation key
 
372
   designated in a revkey subpacket, but the revocation key itself
 
373
   isn't present. */
359
374
int
360
375
check_revocation_keys(PKT_public_key *pk,PKT_signature *sig)
361
376
{
362
377
  static int busy=0;
363
 
  int i,rc=GPG_ERR_GENERAL;
 
378
  int i,rc=G10ERR_GENERAL;
364
379
 
365
380
  assert(IS_KEY_REV(sig));
366
381
  assert((sig->keyid[0]!=pk->keyid[0]) || (sig->keyid[0]!=pk->keyid[1]));
367
382
 
368
383
  if(busy)
369
384
    {
370
 
      /* return -1 (i.e. not revoked), but mark the pk as uncacheable
371
 
         as we don't really know its revocation status until it is
372
 
         checked directly. */
 
385
      /* return an error (i.e. not revoked), but mark the pk as
 
386
         uncacheable as we don't really know its revocation status
 
387
         until it is checked directly. */
373
388
 
374
389
      pk->dont_cache=1;
375
390
      return rc;
394
409
            {
395
410
              gcry_md_hd_t md;
396
411
    
397
 
              gcry_md_open (&md, sig->digest_algo,0);
 
412
              if (gcry_md_open (&md, sig->digest_algo, 0))
 
413
                BUG ();
398
414
              hash_public_key(md,pk);
399
415
              rc=signature_check(sig,md);
400
416
              cache_sig_result(sig,rc);
407
423
  return rc;
408
424
409
425
 
 
426
/* Backsigs (0x19) have the same format as binding sigs (0x18), but
 
427
   this function is simpler than check_key_signature in a few ways.
 
428
   For example, there is no support for expiring backsigs since it is
 
429
   questionable what such a thing actually means.  Note also that the
 
430
   sig cache check here, unlike other sig caches in GnuPG, is not
 
431
   persistent. */
 
432
int
 
433
check_backsig(PKT_public_key *main_pk,PKT_public_key *sub_pk,
 
434
              PKT_signature *backsig)
 
435
{
 
436
  gcry_md_hd_t md;
 
437
  int rc;
 
438
 
 
439
  /* Always check whether the algorithm is available.  Although
 
440
     gcry_md_open woyuld throw an error, some libgcrypt versions will
 
441
     print a debug message in that case too. */
 
442
  if ((rc=openpgp_md_test_algo (backsig->digest_algo)))
 
443
    return rc;
 
444
 
 
445
  if(!opt.no_sig_cache && backsig->flags.checked)
 
446
    return backsig->flags.valid? 0 : gpg_error (GPG_ERR_BAD_SIGNATURE);
 
447
 
 
448
  rc = gcry_md_open (&md, backsig->digest_algo,0);
 
449
  if (!rc)
 
450
    {
 
451
      hash_public_key(md,main_pk);
 
452
      hash_public_key(md,sub_pk);
 
453
      rc=do_check(sub_pk,backsig,md,NULL,NULL,NULL);
 
454
      cache_sig_result(backsig,rc);
 
455
      gcry_md_close(md);
 
456
    }
 
457
 
 
458
  return rc;
 
459
}
 
460
 
 
461
 
410
462
/****************
411
463
 * check the signature pointed to by NODE. This is a key signature.
412
464
 * If the function detects a self-signature, it uses the PK from
415
467
int
416
468
check_key_signature( KBNODE root, KBNODE node, int *is_selfsig )
417
469
{
418
 
    return check_key_signature2(root, node, NULL, NULL, is_selfsig, NULL, NULL);
 
470
  return check_key_signature2(root, node, NULL, NULL, is_selfsig, NULL, NULL );
419
471
}
420
472
 
421
473
/* If check_pk is set, then use it to check the signature in node
427
479
int
428
480
check_key_signature2( KBNODE root, KBNODE node, PKT_public_key *check_pk,
429
481
                      PKT_public_key *ret_pk, int *is_selfsig,
430
 
                      u32 *r_expiredate, int *r_expired )
 
482
                      u32 *r_expiredate, int *r_expired )
431
483
{
432
 
    MD_HANDLE md;
 
484
    gcry_md_hd_t md;
433
485
    PKT_public_key *pk;
434
486
    PKT_signature *sig;
435
487
    int algo;
448
500
    sig = node->pkt->pkt.signature;
449
501
    algo = sig->digest_algo;
450
502
 
451
 
    /* check whether we have cached the result of a previous signature check.*/
 
503
    /* Check whether we have cached the result of a previous signature
 
504
       check.  Note that we may no longer have the pubkey or hash
 
505
       needed to verify a sig, but can still use the cached value.  A
 
506
       cache refresh detects and clears these cases. */
452
507
    if ( !opt.no_sig_cache ) {
453
508
        if (sig->flags.checked) { /*cached status available*/
454
509
            if( is_selfsig ) {  
458
513
                if( keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1] )
459
514
                    *is_selfsig = 1;
460
515
            }
461
 
            /* BUG: This is wrong for non-self-sigs. Needs to be the
 
516
            /* BUG: This is wrong for non-self-sigs.. needs to be the
462
517
               actual pk */
463
518
            if((rc=do_check_messages(pk,sig,r_expired,NULL)))
464
519
              return rc;
466
521
        }
467
522
    }
468
523
 
469
 
    if( (rc=gcry_md_test_algo(algo)) )
470
 
      return rc;
 
524
    if( (rc=openpgp_pk_test_algo(sig->pubkey_algo)) )
 
525
        return rc;
 
526
    if( (rc=openpgp_md_test_algo(algo)) )
 
527
        return rc;
471
528
 
472
529
    if( sig->sig_class == 0x20 ) { /* key revocation */
473
530
        u32 keyid[2];   
478
535
          rc=check_revocation_keys(pk,sig);
479
536
        else
480
537
          {
481
 
            gcry_md_open (&md, algo, 0 );
 
538
            if (gcry_md_open (&md, algo, 0 ))
 
539
              BUG ();
482
540
            hash_public_key( md, pk );
483
541
            rc = do_check( pk, sig, md, r_expired, NULL, ret_pk );
484
542
            cache_sig_result ( sig, rc );
489
547
        KBNODE snode = find_prev_kbnode( root, node, PKT_PUBLIC_SUBKEY );
490
548
 
491
549
        if( snode ) {
492
 
            gcry_md_open (&md, algo, 0 );
 
550
            if (gcry_md_open (&md, algo, 0))
 
551
              BUG ();
493
552
            hash_public_key( md, pk );
494
553
            hash_public_key( md, snode->pkt->pkt.public_key );
495
554
            rc = do_check( pk, sig, md, r_expired, NULL, ret_pk );
496
555
            cache_sig_result ( sig, rc );
497
556
            gcry_md_close(md);
498
557
        }
499
 
        else {
 
558
        else
 
559
          {
500
560
            if (opt.verbose)
501
 
                log_info (_("key %08lX: no subkey for subkey "
502
 
                            "revocation signature\n"),
503
 
                          (ulong)keyid_from_pk (pk, NULL));
504
 
            rc = GPG_ERR_SIG_CLASS;
505
 
        }
 
561
              log_info (_("key %s: no subkey for subkey"
 
562
                          " revocation signature\n"),keystr_from_pk(pk));
 
563
            rc = G10ERR_SIG_CLASS;
 
564
          }
506
565
    }
507
566
    else if( sig->sig_class == 0x18 ) { /* key binding */
508
567
        KBNODE snode = find_prev_kbnode( root, node, PKT_PUBLIC_SUBKEY );
515
574
                if( keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1] )
516
575
                    *is_selfsig = 1;
517
576
            }
518
 
            gcry_md_open (&md, algo, 0 );
 
577
            if (gcry_md_open (&md, algo, 0))
 
578
              BUG ();
519
579
            hash_public_key( md, pk );
520
580
            hash_public_key( md, snode->pkt->pkt.public_key );
521
581
            rc = do_check( pk, sig, md, r_expired, NULL, ret_pk );
522
582
            cache_sig_result ( sig, rc );
523
583
            gcry_md_close(md);
524
584
        }
525
 
        else {
 
585
        else
 
586
          {
526
587
            if (opt.verbose)
527
 
                log_info(_("key %08lX: no subkey for subkey "
528
 
                           "binding signature\n"),
529
 
                         (ulong)keyid_from_pk (pk, NULL));
530
 
            rc = GPG_ERR_SIG_CLASS;
531
 
        }
 
588
              log_info(_("key %s: no subkey for subkey"
 
589
                         " binding signature\n"),keystr_from_pk(pk));
 
590
            rc = G10ERR_SIG_CLASS;
 
591
          }
532
592
    }
533
593
    else if( sig->sig_class == 0x1f ) { /* direct key signature */
534
 
        gcry_md_open (&md, algo, 0 );
 
594
        if (gcry_md_open (&md, algo, 0 ))
 
595
          BUG ();
535
596
        hash_public_key( md, pk );
536
597
        rc = do_check( pk, sig, md, r_expired, NULL, ret_pk );
537
598
        cache_sig_result ( sig, rc );
544
605
            u32 keyid[2];
545
606
 
546
607
            keyid_from_pk( pk, keyid );
547
 
            gcry_md_open (&md, algo, 0 );
 
608
            if (gcry_md_open (&md, algo, 0 ))
 
609
              BUG ();
548
610
            hash_public_key( md, pk );
549
611
            hash_uid_node( unode, md, sig );
550
612
            if( keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1] )
554
616
                rc = do_check( pk, sig, md, r_expired, NULL, ret_pk );
555
617
              }
556
618
            else if (check_pk)
557
 
              rc=do_check(check_pk,sig,md,r_expired, NULL, ret_pk);
 
619
              rc=do_check(check_pk,sig,md,r_expired,NULL,ret_pk);
558
620
            else
559
 
              rc = signature_check2( sig, md, r_expiredate, r_expired,
560
 
                                     NULL, ret_pk);
 
621
              rc=signature_check2(sig,md,r_expiredate,r_expired,NULL,ret_pk);
561
622
 
562
623
            cache_sig_result ( sig, rc );
563
624
            gcry_md_close(md);
564
625
        }
565
 
        else {
 
626
        else
 
627
          {
566
628
            if (!opt.quiet)
567
 
                log_info ("key %08lX: no user ID for key signature packet "
568
 
                          "of class %02x\n",
569
 
                          (ulong)keyid_from_pk (pk, NULL), sig->sig_class );
570
 
            rc = GPG_ERR_SIG_CLASS;
571
 
        }
 
629
              log_info ("key %s: no user ID for key signature packet"
 
630
                        " of class %02x\n",keystr_from_pk(pk),sig->sig_class);
 
631
            rc = G10ERR_SIG_CLASS;
 
632
          }
572
633
    }
573
634
 
574
635
    return rc;