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

« back to all changes in this revision

Viewing changes to g10/sig-check.c

  • Committer: Bazaar Package Importer
  • Author(s): Eric Dorland
  • Date: 2009-03-08 22:46:47 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090308224647-gq17gatcl71lrc2k
Tags: 2.0.11-1
* New upstream release. (Closes: #496663)
* debian/control: Make the description a little more distinctive than
  gnupg v1's. Thanks Jari Aalto. (Closes: #496323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
130
130
         * and the timestamp, but the drawback of this is, that it is
131
131
         * not possible to sign more than one identical document within
132
132
         * one second.  Some remote batch processing applications might
133
 
         * like this feature here */
134
 
        gcry_md_hd_t md;
135
 
 
 
133
         * like this feature here.  
 
134
         * 
 
135
         * Note that before 2.0.10, we used RIPE-MD160 for the hash
 
136
         * and accidently didn't include the timestamp and algorithm
 
137
         * information in the hash.  Given that this feature is not
 
138
         * commonly used and that a replay attacks detection should
 
139
         * not solely be based on this feature (because it does not
 
140
         * work with RSA), we take the freedom and switch to SHA-1
 
141
         * with 2.0.10 to take advantage of hardware supported SHA-1
 
142
         * implementations.  We also include the missing information
 
143
         * in the hash.  Note also the SIG_ID as computed by gpg 1.x
 
144
         * and gpg 2.x didn't matched either because 2.x used to print
 
145
         * MPIs not in PGP format.  */
136
146
        u32 a = sig->timestamp;
137
 
        int i, nsig = pubkey_get_nsig( sig->pubkey_algo );
138
 
        byte *p, *buffer;
139
 
 
140
 
        if (gcry_md_open (&md, GCRY_MD_RMD160, 0))
141
 
          BUG ();
142
 
 
143
 
        /* FIXME:  Why the hell are we updating DIGEST here??? */
144
 
        gcry_md_putc( digest, sig->pubkey_algo );
145
 
        gcry_md_putc( digest, sig->digest_algo );
146
 
        gcry_md_putc( digest, (a >> 24) & 0xff );
147
 
        gcry_md_putc( digest, (a >> 16) & 0xff );
148
 
        gcry_md_putc( digest, (a >>     8) & 0xff );
149
 
        gcry_md_putc( digest,  a           & 0xff );
150
 
        for(i=0; i < nsig; i++ ) {
151
 
            size_t n;
152
 
            unsigned char *tmp;
153
 
 
154
 
            if (gcry_mpi_aprint (GCRYMPI_FMT_USG, &tmp, &n, sig->data[i]))
155
 
              BUG();
156
 
            gcry_md_write (md, tmp, n);
157
 
            xfree (tmp);
158
 
        }
159
 
        gcry_md_final (md);
160
 
        p = make_radix64_string ( gcry_md_read( md, 0 ), 20 );
161
 
        buffer = xmalloc( strlen(p) + 60 );
162
 
        sprintf( buffer, "%s %s %lu",
163
 
                 p, strtimestamp( sig->timestamp ), (ulong)sig->timestamp );
164
 
        write_status_text( STATUS_SIG_ID, buffer );
165
 
        xfree(buffer);
166
 
        xfree(p);
167
 
        gcry_md_close(md);
 
147
        int nsig = pubkey_get_nsig( sig->pubkey_algo );
 
148
        unsigned char *p, *buffer;
 
149
        size_t n, nbytes;
 
150
        int i;
 
151
        char hashbuf[20];
 
152
 
 
153
        nbytes = 6;
 
154
        for (i=0; i < nsig; i++ )
 
155
          {
 
156
            if (gcry_mpi_print (GCRYMPI_FMT_USG, NULL, 0, &n, sig->data[i]))
 
157
              BUG();
 
158
            nbytes += n;
 
159
          }
 
160
 
 
161
        /* Make buffer large enough to be later used as output buffer.  */
 
162
        if (nbytes < 100)
 
163
          nbytes = 100;
 
164
        nbytes += 10;  /* Safety margin.  */
 
165
 
 
166
        /* Fill and hash buffer.  */
 
167
        buffer = p = xmalloc (nbytes);
 
168
        *p++ = sig->pubkey_algo;
 
169
        *p++ = sig->digest_algo;
 
170
        *p++ = (a >> 24) & 0xff;
 
171
        *p++ = (a >> 16) & 0xff;
 
172
        *p++ = (a >>  8) & 0xff;
 
173
        *p++ =  a & 0xff;
 
174
        nbytes -= 6;
 
175
        for (i=0; i < nsig; i++ )
 
176
          {
 
177
            if (gcry_mpi_print (GCRYMPI_FMT_PGP, p, nbytes, &n, sig->data[i]))
 
178
              BUG();
 
179
            p += n;
 
180
            nbytes -= n;
 
181
          }
 
182
        gcry_md_hash_buffer (GCRY_MD_SHA1, hashbuf, buffer, p-buffer);
 
183
 
 
184
        p = make_radix64_string (hashbuf, 20);
 
185
        sprintf (buffer, "%s %s %lu",
 
186
                 p, strtimestamp (sig->timestamp), (ulong)sig->timestamp);
 
187
        xfree (p);
 
188
        write_status_text (STATUS_SIG_ID, buffer);
 
189
        xfree (buffer);
168
190
    }
169
191
 
170
192
    return rc;
220
242
          *r_expired = 1;
221
243
    }
222
244
 
223
 
    if(pk->is_revoked && r_revoked)
224
 
      *r_revoked=1;
 
245
    if (pk->is_revoked)
 
246
      {
 
247
        if (opt.verbose)
 
248
          log_info (_("NOTE: signature key %s has been revoked\n"),
 
249
                    keystr_from_pk(pk));
 
250
        if (r_revoked)
 
251
          *r_revoked=1;
 
252
      }
225
253
 
226
254
    return 0;
227
255
}
414
442
              hash_public_key(md,pk);
415
443
              rc=signature_check(sig,md);
416
444
              cache_sig_result(sig,rc);
 
445
              gcry_md_close (md);
417
446
              break;
418
447
            }
419
448
        }