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

« back to all changes in this revision

Viewing changes to scd/ccid-driver.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:
1240
1240
  if (CCID_COMMAND_FAILED (buffer))
1241
1241
    print_command_failed (buffer);
1242
1242
 
1243
 
  /* Check whether a card is at all available. */
 
1243
  /* Check whether a card is at all available.  Note: If you add new
 
1244
     error codes here, check whether they need to be ignored in
 
1245
     send_escape_cmd. */
1244
1246
  switch ((buffer[7] & 0x03))
1245
1247
    {
1246
1248
    case 0: /* no error */ break;
1253
1255
 
1254
1256
 
1255
1257
/* Note that this function won't return the error codes NO_CARD or
1256
 
   CARD_INACTIVE */
 
1258
   CARD_INACTIVE.  IF RESULT is not NULL, the result from the
 
1259
   operation will get returned in RESULT and its length in RESULTLEN.
 
1260
   If the response is larger than RESULTMAX, an error is returned and
 
1261
   the required buffer length returned in RESULTLEN.  */
1257
1262
static int 
1258
1263
send_escape_cmd (ccid_driver_t handle,
1259
 
                 const unsigned char *data, size_t datalen)
 
1264
                 const unsigned char *data, size_t datalen,
 
1265
                 unsigned char *result, size_t resultmax, size_t *resultlen)
1260
1266
{
1261
1267
  int i, rc;
1262
1268
  unsigned char msg[100];
1263
1269
  size_t msglen;
1264
1270
  unsigned char seqno;
1265
1271
 
 
1272
  if (resultlen)
 
1273
    *resultlen = 0;
 
1274
 
1266
1275
  if (datalen > sizeof msg - 10)
1267
1276
    return CCID_DRIVER_ERR_INV_VALUE; /* Escape data too large.  */
1268
1277
 
1285
1294
    return rc;
1286
1295
  rc = bulk_in (handle, msg, sizeof msg, &msglen, RDR_to_PC_Escape,
1287
1296
                seqno, 5000, 0);
1288
 
 
 
1297
  if (result)
 
1298
    switch (rc)
 
1299
      {
 
1300
        /* We need to ignore certain errorcode here. */
 
1301
      case 0:
 
1302
      case CCID_DRIVER_ERR_CARD_INACTIVE:
 
1303
      case CCID_DRIVER_ERR_NO_CARD:
 
1304
        {
 
1305
          if (msglen > resultmax)
 
1306
            rc = CCID_DRIVER_ERR_INV_VALUE; /* Response too large. */
 
1307
          else
 
1308
            {
 
1309
              memcpy (result, msg, msglen);
 
1310
              *resultlen = msglen;
 
1311
            }
 
1312
          rc = 0;
 
1313
        }
 
1314
        break;
 
1315
      default:
 
1316
        break;
 
1317
      }
 
1318
  
1289
1319
  return rc;
1290
1320
}
1291
1321
 
1292
1322
 
 
1323
int
 
1324
ccid_transceive_escape (ccid_driver_t handle,
 
1325
                        const unsigned char *data, size_t datalen,
 
1326
                        unsigned char *resp, size_t maxresplen, size_t *nresp)
 
1327
{
 
1328
  return send_escape_cmd (handle, data, datalen, resp, maxresplen, nresp);
 
1329
}
 
1330
 
 
1331
 
 
1332
 
1293
1333
/* experimental */
1294
1334
int
1295
1335
ccid_poll (ccid_driver_t handle)
1445
1485
    {
1446
1486
      tried_iso = 1;
1447
1487
      /* Try switching to ISO mode. */
1448
 
      if (!send_escape_cmd (handle, (const unsigned char*)"\xF1\x01", 2))
 
1488
      if (!send_escape_cmd (handle, (const unsigned char*)"\xF1\x01", 2,
 
1489
                            NULL, 0, NULL))
1449
1490
        goto again;
1450
1491
    }
1451
1492
  else if (CCID_COMMAND_FAILED (msg))
1957
1998
}
1958
1999
 
1959
2000
 
1960
 
/* Send the CCID Secure command to the reader.  APDU_BUF should contain the APDU   template.  PIN_MODE defines now the pin gets formatted:
 
2001
/* Send the CCID Secure command to the reader.  APDU_BUF should
 
2002
   contain the APDU template.  PIN_MODE defines how the pin gets
 
2003
   formatted:
1961
2004
   
1962
2005
     1 := The PIN is ASCII encoded and of variable length.  The
1963
2006
          length of the PIN entered will be put into Lc by the reader.
1964
2007
          The APDU should me made up of 4 bytes without Lc.
1965
2008
 
1966
2009
   PINLEN_MIN and PINLEN_MAX define the limits for the pin length. 0
1967
 
   may be used t enable usbale defaults.  PIN_PADLEN should be 0
 
2010
   may be used t enable reasonable defaults.  PIN_PADLEN should be 0.
1968
2011
   
1969
2012
   When called with RESP and NRESP set to NULL, the function will
1970
2013
   merely check whether the reader supports the secure command for the
1996
2039
  else if (apdu_buflen >= 4 && apdu_buf[1] == 0x24 && (handle->has_pinpad & 2))
1997
2040
    return CCID_DRIVER_ERR_NOT_SUPPORTED; /* Not yet by our code. */
1998
2041
  else
1999
 
    return CCID_DRIVER_ERR_NOT_SUPPORTED;
 
2042
    return CCID_DRIVER_ERR_NO_KEYPAD;
2000
2043
    
2001
2044
  if (pin_mode != 1)
2002
2045
    return CCID_DRIVER_ERR_NOT_SUPPORTED;
2027
2070
  if (handle->id_vendor == VENDOR_SCM)
2028
2071
    {
2029
2072
      DEBUGOUT ("sending escape sequence to switch to a case 1 APDU\n");
2030
 
      rc = send_escape_cmd (handle, (const unsigned char*)"\x80\x02\x00", 3);
 
2073
      rc = send_escape_cmd (handle, (const unsigned char*)"\x80\x02\x00", 3,
 
2074
                            NULL, 0, NULL);
2031
2075
      if (rc)
2032
2076
        return rc;
2033
2077
    }
2044
2088
  if (handle->id_vendor == VENDOR_SCM)
2045
2089
    {
2046
2090
      /* For the SPR532 the next 2 bytes need to be zero.  We do this
2047
 
         for all SCM product. Kudos to to Martin Paljak for this
 
2091
         for all SCM product. Kudos to Martin Paljak for this
2048
2092
         hint.  */
2049
2093
      msg[13] = msg[14] = 0;
2050
2094
    }