~ubuntu-branches/ubuntu/raring/gnupg2/raring

« back to all changes in this revision

Viewing changes to kbx/keybox-openpgp.c

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2012-11-06 11:25:58 UTC
  • mfrom: (1.1.16) (7.1.8 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121106112558-lkpndvv4gqthgrn4
Tags: 2.0.19-1ubuntu1
* Resynchronize on Debian, remaining changes:
  - Add udev rules to give gpg access to some smartcard readers;
    Debian #543217.
    . debian/gnupg2.dev: udev rules to set ACLs on SCM smartcard readers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
   follwing data on success:
73
73
 
74
74
   R_DATAPKT = Pointer to the begin of the packet data.
75
 
   R_DATALEN = Length of this data.  This has already been checked to fit 
76
 
               into the buffer. 
 
75
   R_DATALEN = Length of this data.  This has already been checked to fit
 
76
               into the buffer.
77
77
   R_PKTTYPE = The packet type.
78
78
   R_NTOTAL  = The total number of bytes of this packet
79
79
 
91
91
 
92
92
  if (!len)
93
93
    return gpg_error (GPG_ERR_NO_DATA);
94
 
  
 
94
 
95
95
  ctb = *buf++; len--;
96
96
  if ( !(ctb & 0x80) )
97
97
    return gpg_error (GPG_ERR_INV_PACKET); /* Invalid CTB. */
98
 
  
 
98
 
99
99
  pktlen = 0;
100
100
  if ((ctb & 0x40))  /* New style (OpenPGP) CTB.  */
101
101
    {
108
108
      if ( c < 192 )
109
109
        pktlen = c;
110
110
      else if ( c < 224 )
111
 
        { 
 
111
        {
112
112
          pktlen = (c - 192) * 256;
113
113
          if (!len)
114
114
            return gpg_error (GPG_ERR_INV_PACKET); /* No 2nd length byte. */
150
150
  switch (pkttype)
151
151
    {
152
152
    case PKT_SIGNATURE:
153
 
    case PKT_SECRET_KEY:        
 
153
    case PKT_SECRET_KEY:
154
154
    case PKT_PUBLIC_KEY:
155
155
    case PKT_SECRET_SUBKEY:
156
156
    case PKT_MARKER:
166
166
      return gpg_error (GPG_ERR_UNEXPECTED);
167
167
    }
168
168
 
169
 
  if (pktlen == 0xffffffff) 
 
169
  if (pktlen == 0xffffffff)
170
170
      return gpg_error (GPG_ERR_INV_PACKET);
171
 
  
 
171
 
172
172
  if (pktlen > len)
173
173
    return gpg_error (GPG_ERR_INV_PACKET); /* Packet length header too long. */
174
174
 
195
195
  const unsigned char *data_start = data;
196
196
  int i, version, algorithm;
197
197
  size_t n;
198
 
  unsigned long timestamp, expiredate;
 
198
  /*unsigned long timestamp;*/
199
199
  int npkey;
200
200
  unsigned char hashbuffer[768];
201
201
  const unsigned char *mpi_n = NULL;
207
207
  version = *data++; datalen--;
208
208
  if (version < 2 || version > 4 )
209
209
    return gpg_error (GPG_ERR_INV_PACKET); /* Invalid version. */
210
 
  
211
 
  timestamp = ((data[0]<<24)|(data[1]<<16)|(data[2]<<8)|(data[3]));
 
210
 
 
211
  /*timestamp = ((data[0]<<24)|(data[1]<<16)|(data[2]<<8)|(data[3]));*/
212
212
  data +=4; datalen -=4;
213
213
 
214
214
  if (version < 4)
215
215
    {
216
 
      unsigned short ndays;
217
 
      
218
216
      if (datalen < 2)
219
217
        return gpg_error (GPG_ERR_INV_PACKET);
220
 
      ndays = ((data[0]<<8)|(data[1]));
221
 
      data +=2; datalen -= 2;
222
 
      if (ndays)
223
 
      expiredate = ndays? (timestamp + ndays * 86400L) : 0;
 
218
      data += 2; datalen -= 2;
224
219
    }
225
 
  else
226
 
    expiredate = 0; /* This is stored in the self-signature. */
227
220
 
228
221
  if (!datalen)
229
222
    return gpg_error (GPG_ERR_INV_PACKET);
234
227
    case 1:
235
228
    case 2:
236
229
    case 3: /* RSA */
237
 
      npkey = 2; 
 
230
      npkey = 2;
238
231
      break;
239
232
    case 16:
240
233
    case 20: /* Elgamal */
250
243
  for (i=0; i < npkey; i++ )
251
244
    {
252
245
      unsigned int nbits, nbytes;
253
 
      
 
246
 
254
247
      if (datalen < 2)
255
248
        return gpg_error (GPG_ERR_INV_PACKET);
256
249
      nbits = ((data[0]<<8)|(data[1]));
260
253
        return gpg_error (GPG_ERR_INV_PACKET);
261
254
      /* For use by v3 fingerprint calculation we need to know the RSA
262
255
         modulus and exponent. */
263
 
      if (i==0) 
 
256
      if (i==0)
264
257
        {
265
 
          mpi_n = data; 
 
258
          mpi_n = data;
266
259
          mpi_n_len = nbytes;
267
260
        }
268
261
      else if (i==1)
269
262
        mpi_e_len = nbytes;
270
 
        
 
263
 
271
264
      data += nbytes; datalen -= nbytes;
272
265
    }
273
266
  n = data - data_start;
287
280
      memcpy (ki->fpr, gcry_md_read (md, 0), 16);
288
281
      gcry_md_close (md);
289
282
      ki->fprlen = 16;
290
 
      
 
283
 
291
284
      if (mpi_n_len < 8)
292
285
        {
293
286
          /* Moduli less than 64 bit are out of the specs scope.  Zero
294
287
             them out becuase this is what gpg does too. */
295
 
          memset (ki->keyid, 0, 8); 
 
288
          memset (ki->keyid, 0, 8);
296
289
        }
297
290
      else
298
291
        memcpy (ki->keyid, mpi_n + mpi_n_len - 8, 8);
353
346
  int first = 1;
354
347
  struct _keybox_openpgp_key_info *k, **ktail = NULL;
355
348
  struct _keybox_openpgp_uid_info *u, **utail = NULL;
356
 
  
 
349
 
357
350
  memset (info, 0, sizeof *info);
358
351
  if (nparsed)
359
352
    *nparsed = 0;
380
373
        }
381
374
      else if (pkttype == PKT_PUBLIC_KEY || pkttype == PKT_SECRET_KEY)
382
375
        break; /* Next keyblock encountered - ready. */
383
 
      
 
376
 
384
377
      if (nparsed)
385
378
        *nparsed += n;
386
379
 
418
411
          if (err)
419
412
            break;
420
413
        }
421
 
      else if( pkttype == PKT_PUBLIC_SUBKEY && datalen && *data == '#' ) 
 
414
      else if( pkttype == PKT_PUBLIC_SUBKEY && datalen && *data == '#' )
422
415
        {
423
416
          /* Early versions of GnuPG used old PGP comment packets;
424
417
           * luckily all those comments are prefixed by a hash
482
475
 
483
476
              if (pkttype == PKT_PUBLIC_KEY || pkttype == PKT_SECRET_KEY)
484
477
                break; /* Next keyblock encountered - ready. */
485
 
              
 
478
 
486
479
              if (nparsed)
487
480
                *nparsed += n;
488
481
            }