1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

scd: Fix internal CCID driver, so that -DTEST works.

* scd/ccid-driver.c: Support a test program by ccid-driver.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2019-07-11 14:37:27 +09:00
parent 2536bf2761
commit b310604252

View File

@ -951,7 +951,7 @@ get_escaped_usb_string (libusb_device_handle *idev, int idx,
rc = libusb_control_transfer (idev, LIBUSB_ENDPOINT_IN,
LIBUSB_REQUEST_GET_DESCRIPTOR,
(LIBUSB_DT_STRING << 8), 0,
(char*)buf, sizeof buf, 1000 /* ms timeout */);
buf, sizeof buf, 1000 /* ms timeout */);
#ifdef USE_NPTH
npth_protect ();
#endif
@ -966,7 +966,7 @@ get_escaped_usb_string (libusb_device_handle *idev, int idx,
rc = libusb_control_transfer (idev, LIBUSB_ENDPOINT_IN,
LIBUSB_REQUEST_GET_DESCRIPTOR,
(LIBUSB_DT_STRING << 8) + idx, langid,
(char*)buf, sizeof buf, 1000 /* ms timeout */);
buf, sizeof buf, 1000 /* ms timeout */);
#ifdef USE_NPTH
npth_protect ();
#endif
@ -1481,7 +1481,9 @@ intr_cb (struct libusb_transfer *transfer)
{
DEBUGOUT ("CCID: card removed\n");
handle->powered_off = 1;
#if defined(GNUPG_MAJOR_VERSION)
scd_kick_the_loop ();
#endif
}
else
{
@ -1496,7 +1498,9 @@ intr_cb (struct libusb_transfer *transfer)
device_removed:
DEBUGOUT ("CCID: device removed\n");
handle->powered_off = 1;
#if defined(GNUPG_MAJOR_VERSION)
scd_kick_the_loop ();
#endif
}
}
@ -1904,7 +1908,7 @@ bulk_out (ccid_driver_t handle, unsigned char *msg, size_t msglen,
npth_unprotect ();
#endif
rc = libusb_bulk_transfer (handle->idev, handle->ep_bulk_out,
(char*)msg, msglen, &transferred,
msg, msglen, &transferred,
5000 /* ms timeout */);
#ifdef USE_NPTH
npth_protect ();
@ -1951,7 +1955,7 @@ bulk_in (ccid_driver_t handle, unsigned char *buffer, size_t length,
npth_unprotect ();
#endif
rc = libusb_bulk_transfer (handle->idev, handle->ep_bulk_in,
(char*)buffer, length, &msglen, timeout);
buffer, length, &msglen, timeout);
#ifdef USE_NPTH
npth_protect ();
#endif
@ -2071,7 +2075,9 @@ bulk_in (ccid_driver_t handle, unsigned char *buffer, size_t length,
{
DEBUGOUT ("CCID: card inactive/removed\n");
handle->powered_off = 1;
#if defined(GNUPG_MAJOR_VERSION)
scd_kick_the_loop ();
#endif
}
}
@ -2085,7 +2091,7 @@ static int
abort_cmd (ccid_driver_t handle, int seqno)
{
int rc;
char dummybuf[8];
unsigned char dummybuf[8];
unsigned char msg[100];
int msglen;
@ -2136,7 +2142,7 @@ abort_cmd (ccid_driver_t handle, int seqno)
npth_unprotect ();
#endif
rc = libusb_bulk_transfer (handle->idev, handle->ep_bulk_out,
(char*)msg, msglen, &transferred,
msg, msglen, &transferred,
5000 /* ms timeout */);
#ifdef USE_NPTH
npth_protect ();
@ -2154,7 +2160,7 @@ abort_cmd (ccid_driver_t handle, int seqno)
npth_unprotect ();
#endif
rc = libusb_bulk_transfer (handle->idev, handle->ep_bulk_in,
(char*)msg, sizeof msg, &msglen,
msg, sizeof msg, &msglen,
5000 /*ms timeout*/);
#ifdef USE_NPTH
npth_protect ();
@ -2275,7 +2281,7 @@ ccid_poll (ccid_driver_t handle)
int i, j;
rc = libusb_interrupt_transfer (handle->idev, handle->ep_intr,
(char*)msg, sizeof msg, &msglen,
msg, sizeof msg, &msglen,
0 /* ms timeout */ );
if (rc == LIBUSB_ERROR_TIMEOUT)
return 0;
@ -3737,7 +3743,7 @@ print_result (int rc, const unsigned char *data, size_t length)
int
main (int argc, char **argv)
{
int rc;
gpg_error_t err;
ccid_driver_t ccid;
int slotstat;
unsigned char result[512];
@ -3746,6 +3752,8 @@ main (int argc, char **argv)
int verify_123456 = 0;
int did_verify = 0;
int no_poll = 0;
int idx_max;
struct ccid_dev_table *ccid_table;
if (argc)
{
@ -3789,27 +3797,36 @@ main (int argc, char **argv)
break;
}
rc = ccid_open_reader (&ccid, argc? *argv:NULL, NULL);
if (rc)
err = ccid_dev_scan (&idx_max, &ccid_table);
if (err)
return 1;
if (idx_max == 0)
return 1;
err = ccid_open_reader (argc? *argv:NULL, 0, ccid_table, &ccid, NULL);
if (err)
return 1;
ccid_dev_scan_finish (ccid_table, idx_max);
if (!no_poll)
ccid_poll (ccid);
fputs ("getting ATR ...\n", stderr);
rc = ccid_get_atr (ccid, NULL, 0, NULL);
if (rc)
err = ccid_get_atr (ccid, NULL, 0, NULL);
if (err)
{
print_error (rc);
print_error (err);
return 1;
}
if (!no_poll)
ccid_poll (ccid);
fputs ("getting slot status ...\n", stderr);
rc = ccid_slot_status (ccid, &slotstat, 1);
if (rc)
err = ccid_slot_status (ccid, &slotstat, 1);
if (err)
{
print_error (rc);
print_error (err);
return 1;
}
@ -3820,10 +3837,10 @@ main (int argc, char **argv)
{
static unsigned char apdu[] = {
0, 0xA4, 4, 0, 6, 0xD2, 0x76, 0x00, 0x01, 0x24, 0x01};
rc = ccid_transceive (ccid,
apdu, sizeof apdu,
result, sizeof result, &resultlen);
print_result (rc, result, resultlen);
err = ccid_transceive (ccid,
apdu, sizeof apdu,
result, sizeof result, &resultlen);
print_result (err, result, resultlen);
}
@ -3833,9 +3850,9 @@ main (int argc, char **argv)
fputs ("getting OpenPGP DO 0x65 ....\n", stderr);
{
static unsigned char apdu[] = { 0, 0xCA, 0, 0x65, 254 };
rc = ccid_transceive (ccid, apdu, sizeof apdu,
result, sizeof result, &resultlen);
print_result (rc, result, resultlen);
err = ccid_transceive (ccid, apdu, sizeof apdu,
result, sizeof result, &resultlen);
print_result (err, result, resultlen);
}
if (!no_pinpad)
@ -3845,22 +3862,18 @@ main (int argc, char **argv)
if (!no_pinpad)
{
static unsigned char apdu[] = { 0, 0x20, 0, 0x81 };
pininfo_t pininfo = { 0, 0, 0 };
if (ccid_transceive_secure (ccid,
apdu, sizeof apdu,
1, 0, 0, 0,
if (ccid_transceive_secure (ccid, apdu, sizeof apdu, &pininfo,
NULL, 0, NULL))
fputs ("can't verify using a PIN-Pad reader\n", stderr);
else
{
fputs ("verifying CHV1 using the PINPad ....\n", stderr);
fputs ("verifying CHV1 using the PINPad ....\n", stderr);
rc = ccid_transceive_secure (ccid,
apdu, sizeof apdu,
1, 0, 0, 0,
result, sizeof result, &resultlen);
print_result (rc, result, resultlen);
err = ccid_transceive_secure (ccid, apdu, sizeof apdu, &pininfo,
result, sizeof result, &resultlen);
print_result (err, result, resultlen);
did_verify = 1;
}
}
@ -3871,20 +3884,20 @@ main (int argc, char **argv)
{
static unsigned char apdu[] = {0, 0x20, 0, 0x81,
6, '1','2','3','4','5','6'};
rc = ccid_transceive (ccid, apdu, sizeof apdu,
result, sizeof result, &resultlen);
print_result (rc, result, resultlen);
err = ccid_transceive (ccid, apdu, sizeof apdu,
result, sizeof result, &resultlen);
print_result (err, result, resultlen);
}
}
if (!rc)
if (!err)
{
fputs ("getting OpenPGP DO 0x5E ....\n", stderr);
{
static unsigned char apdu[] = { 0, 0xCA, 0, 0x5E, 254 };
rc = ccid_transceive (ccid, apdu, sizeof apdu,
result, sizeof result, &resultlen);
print_result (rc, result, resultlen);
err = ccid_transceive (ccid, apdu, sizeof apdu,
result, sizeof result, &resultlen);
print_result (err, result, resultlen);
}
}
@ -3895,7 +3908,7 @@ main (int argc, char **argv)
/*
* Local Variables:
* compile-command: "gcc -DTEST -Wall -I/usr/local/include -lusb -g ccid-driver.c"
* compile-command: "gcc -DTEST -DGPGRT_ENABLE_ES_MACROS -DHAVE_NPTH -DUSE_NPTH -Wall -I/usr/include/libusb-1.0 -I/usr/local/include -lusb-1.0 -g ccid-driver.c -lnpth -lgpg-error"
* End:
*/
#endif /*TEST*/