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