~ubuntu-branches/ubuntu/hardy/gnupg2/hardy-security

« back to all changes in this revision

Viewing changes to scd/ccid-driver.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Bienia
  • Date: 2007-03-09 12:32:03 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20070309123203-64xnl30ctoyv4pcv
Tags: 2.0.3-1ubuntu1
* Merge from Debian unstable. Remaining changes:
  - Remove libpcsclite-dev, libopensc2-dev build dependencies (they are in
    universe).
  - Build-depend on libcurl3-gnutls-dev
  - Include /doc files as done with gnupg
  - debian/rules: add doc/com-certs.pem to the docs for gpgsm
  - g10/call-agent.c: set DBG_ASSUAN to 0 to suppress a debug message
  - debian/README.Debian: remove note the gnupg2 isn't released yet.
  - debian/control: Change Maintainer/XSBC-Original-Maintainer field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* ccid-driver.c - USB ChipCardInterfaceDevices driver
2
 
 *      Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
3
 
 *      Written by Werner Koch.
 
2
 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
3
 * Written by Werner Koch.
4
4
 *
5
5
 * This file is part of GnuPG.
6
6
 *
53
53
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
54
54
 * OF THE POSSIBILITY OF SUCH DAMAGE.
55
55
 *
56
 
 * $Date: 2007-01-31 15:24:41 +0100 (Wed, 31 Jan 2007) $
 
56
 * $Date: 2007-03-07 21:55:14 +0100 (Wed, 07 Mar 2007) $
57
57
 */
58
58
 
59
59
 
1458
1458
      DEBUGOUT_1 ("bulk-in msg too short (%u)\n", (unsigned int)msglen);
1459
1459
      return CCID_DRIVER_ERR_INV_VALUE;
1460
1460
    }
1461
 
  if (buffer[0] != expected_type)
1462
 
    {
1463
 
      DEBUGOUT_1 ("unexpected bulk-in msg type (%02x)\n", buffer[0]);
1464
 
      return CCID_DRIVER_ERR_INV_VALUE;
1465
 
    }
1466
1461
  if (buffer[5] != 0)    
1467
1462
    {
1468
1463
      DEBUGOUT_1 ("unexpected bulk-in slot (%d)\n", buffer[5]);
1475
1470
      return CCID_DRIVER_ERR_INV_VALUE;
1476
1471
    }
1477
1472
 
 
1473
  /* We need to handle the time extension request before we check that
 
1474
     we go the expected message type.  This is in particular required
 
1475
     for the Cherry keyboard which sends a time extension request for
 
1476
     each key hit.  */
1478
1477
  if ( !(buffer[7] & 0x03) && (buffer[7] & 0xC0) == 0x80)
1479
1478
    { 
1480
1479
      /* Card present and active, time extension requested. */
1483
1482
      goto retry;
1484
1483
    }
1485
1484
 
 
1485
  if (buffer[0] != expected_type)
 
1486
    {
 
1487
      DEBUGOUT_1 ("unexpected bulk-in msg type (%02x)\n", buffer[0]);
 
1488
      return CCID_DRIVER_ERR_INV_VALUE;
 
1489
    }
 
1490
 
 
1491
 
1486
1492
  if (!no_debug)
1487
1493
    {
1488
1494
      DEBUGOUT_3 ("status: %02X  error: %02X  octet[9]: %02X\n"
2330
2336
  int i;
2331
2337
  size_t dummy_nresp;
2332
2338
  int testmode;
 
2339
  int cherry_mode = 0;
2333
2340
 
2334
2341
  testmode = !resp && !nresp;
2335
2342
 
2368
2375
    case VENDOR_SCM:  /* Tested with SPR 532. */
2369
2376
    case VENDOR_KAAN: /* Tested with KAAN Advanced (1.02). */
2370
2377
      break;
2371
 
      /* The CHERRY XX44 does not yet work. I have not investigated it
2372
 
         closer because there is another problem: It echos a "*" for
2373
 
         each entered character and we somehow need to arrange that it
2374
 
         doesn't get to the tty at all.  Given that we are running
2375
 
         without a control terminal there is not much we can do about.
2376
 
         A weird hack using pinentry comes in mind but I doubt that
2377
 
         this is a clean solution.  Need to contact Cherry.
2378
 
       */
 
2378
    case VENDOR_CHERRY:
 
2379
      /* The CHERRY XX44 keyboard echos an asterisk for each entered
 
2380
         character on the keyboard channel.  We use a special variant
 
2381
         of PC_to_RDR_Secure which directs these characters to the
 
2382
         smart card's bulk-in channel.  We also need to append a zero
 
2383
         Lc byte to the APDU.  It seems that it will be replaced with
 
2384
         the actual length instead of being appended before the APDU
 
2385
         is send to the card. */
 
2386
      cherry_mode = 1;
 
2387
      break;
2379
2388
    default:
2380
2389
     return CCID_DRIVER_ERR_NOT_SUPPORTED;
2381
2390
    }
2393
2402
        return rc;
2394
2403
    }
2395
2404
 
2396
 
  msg[0] = PC_to_RDR_Secure;
 
2405
  msg[0] = cherry_mode? 0x89 : PC_to_RDR_Secure;
2397
2406
  msg[5] = 0; /* slot */
2398
2407
  msg[6] = seqno = handle->seqno++;
2399
2408
  msg[7] = 0; /* bBWI */
2405
2414
  if (handle->id_vendor == VENDOR_SCM)
2406
2415
    {
2407
2416
      /* For the SPR532 the next 2 bytes need to be zero.  We do this
2408
 
         for all SCM product. Kudos to Martin Paljak for this
 
2417
         for all SCM products.  Kudos to Martin Paljak for this
2409
2418
         hint.  */
2410
2419
      msg[13] = msg[14] = 0;
2411
2420
    }
2419
2428
    }
2420
2429
 
2421
2430
  /* The following is a little endian word. */
2422
 
  msg[15] = pinlen_max;   /* wPINMaxExtraDigit-Maximum. */
 
2431
  msg[15] = pinlen_max;   /* wPINMaxExtraDigit-Maximum.  */
2423
2432
  msg[16] = pinlen_min;   /* wPINMaxExtraDigit-Minimum.  */
2424
2433
 
2425
2434
  msg[17] = 0x02; /* bEntryValidationCondition:
2440
2449
  msg[27] = apdu_buf[2]; /* P1 */
2441
2450
  msg[28] = apdu_buf[3]; /* P2 */
2442
2451
  msglen = 29;
 
2452
  if (cherry_mode)
 
2453
    msg[msglen++] = 0;
2443
2454
  /* An EDC is not required. */
2444
2455
  set_msg_len (msg, msglen - 10);
2445
2456