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

« back to all changes in this revision

Viewing changes to scd/app-dinsig.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Urlichs
  • Date: 2006-01-24 04:31:42 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060124043142-pbg192or6qxv3yk2
Tags: 1.9.20-1
* New Upstream version. Closes:#306890,#344530
  * Closes:#320490: gpg-protect-tool fails to decrypt PKCS-12 files 
* Depend on libopensc2-dev, not -1-. Closes:#348106

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* app-dinsig.c - The DINSIG (DIN V 66291-1) card application.
2
 
 *      Copyright (C) 2002, 2004 Free Software Foundation, Inc.
 
2
 *      Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
3
3
 *
4
4
 * This file is part of GnuPG.
5
5
 *
280
280
{
281
281
  if (!app->did_chv1 || app->force_chv1 ) 
282
282
    {
 
283
      const char *s;
283
284
      char *pinvalue;
284
285
      int rc;
285
286
 
286
 
      rc = pincb (pincb_arg, "PIN", &pinvalue); 
 
287
      rc = pincb (pincb_arg, "PIN", &pinvalue);
287
288
      if (rc)
288
289
        {
289
290
          log_info ("PIN callback returned error: %s\n", gpg_strerror (rc));
291
292
        }
292
293
 
293
294
      /* We require the PIN to be at least 6 and at max 8 bytes.
294
 
         According to the specs, this should all be ASCII but we don't
295
 
         check this. */
 
295
         According to the specs, this should all be ASCII.  */
 
296
      for (s=pinvalue; digitp (s); s++)
 
297
        ;
 
298
      if (*s)
 
299
        {
 
300
          log_error ("Non-numeric digits found in PIN\n");
 
301
          xfree (pinvalue);
 
302
          return gpg_error (GPG_ERR_BAD_PIN);
 
303
        }
 
304
 
296
305
      if (strlen (pinvalue) < 6)
297
306
        {
298
307
          log_error ("PIN is too short; minimum length is 6\n");
307
316
        }
308
317
 
309
318
      rc = iso7816_verify (app->slot, 0x81, pinvalue, strlen (pinvalue));
 
319
      if (gpg_err_code (rc) == GPG_ERR_INV_VALUE)
 
320
        {
 
321
          /* We assume that ISO 9564-1 encoding is used and we failed
 
322
             because the first nibble we passed was 3 and not 2.  DIN
 
323
             says something about looking up such an encoding in the
 
324
             SSD but I was not able to find any tag relevant to
 
325
             this. */
 
326
          char paddedpin[8];
 
327
          int i, ndigits;
 
328
 
 
329
          for (ndigits=0, s=pinvalue; *s; ndigits++, s++)
 
330
            ;
 
331
          i = 0;
 
332
          paddedpin[i++] = 0x20 | (ndigits & 0x0f);
 
333
          for (s=pinvalue; i < sizeof paddedpin && *s && s[1]; s = s+2 )
 
334
            paddedpin[i++] = (((*s - '0') << 4) | ((s[1] - '0') & 0x0f));
 
335
          if (i < sizeof paddedpin && *s)
 
336
            paddedpin[i++] = (((*s - '0') << 4) | 0x0f);
 
337
          while (i < sizeof paddedpin)
 
338
              paddedpin[i++] = 0xff;
 
339
          rc = iso7816_verify (app->slot, 0x81, paddedpin, sizeof paddedpin);
 
340
        }
310
341
      if (rc)
311
342
        {
312
343
          log_error ("verify PIN failed\n");
404
435
  int slot = app->slot;
405
436
  int rc;
406
437
  
407
 
  rc = iso7816_select_application (slot, aid, sizeof aid);
 
438
  rc = iso7816_select_application (slot, aid, sizeof aid, 0);
408
439
  if (!rc)
409
440
    {
410
441
      app->apptype = "DINSIG";