- a few more changes from Andreas
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1013 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
088a346bdd
commit
e04b90f5b2
|
@ -155,7 +155,21 @@ int cardos_info(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
printf("Current life cycle: %d\n", rbuf[0]);
|
||||
|
||||
printf("Current life cycle: ");
|
||||
if (rbuf[0] == 0x34) {
|
||||
printf("%d (manufacturing)\n", rbuf[0]);
|
||||
} else if (rbuf[0] == 0x26) {
|
||||
printf("%d (initialization)\n", rbuf[0]);
|
||||
} else if (rbuf[0] == 0x24) {
|
||||
printf("%d (personalization)\n", rbuf[0]);
|
||||
} else if (rbuf[0] == 0x20) {
|
||||
printf("%d (administration)\n", rbuf[0]);
|
||||
} else if (rbuf[0] == 0x10) {
|
||||
printf("%d (operational)\n", rbuf[0]);
|
||||
} else {
|
||||
printf("%d (unknown)\n", rbuf[0]);
|
||||
}
|
||||
|
||||
apdu.p2 = 0x84;
|
||||
apdu.resplen = sizeof(rbuf);
|
||||
|
@ -218,25 +232,6 @@ int cardos_info(void)
|
|||
printf("ATR Status: 0x%d unknown\n",rbuf[0]);
|
||||
}
|
||||
|
||||
apdu.p2 = 0x87;
|
||||
apdu.resplen = sizeof(rbuf);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
if (r) {
|
||||
fprintf(stderr, "APDU transmit failed: %s\n",
|
||||
sc_strerror(r));
|
||||
return 1;
|
||||
}
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 00 || opt_debug) {
|
||||
fprintf(stderr, "Received (SW1=0x%02X, SW2=0x%02X)%s\n",
|
||||
apdu.sw1, apdu.sw2, apdu.resplen ? ":" : "");
|
||||
if (apdu.resplen)
|
||||
hex_dump_asc(stdout, apdu.resp, apdu.resplen, -1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Path to current DF:\n");
|
||||
hex_dump_asc(stdout, apdu.resp, apdu.resplen, -1);
|
||||
|
||||
apdu.p2 = 0x88;
|
||||
apdu.resplen = sizeof(rbuf);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
|
@ -314,6 +309,25 @@ int cardos_info(void)
|
|||
printf("System keys: StartKey (version %d, retries %d)\n",
|
||||
rbuf[2], rbuf[3]);
|
||||
|
||||
apdu.p2 = 0x87;
|
||||
apdu.resplen = sizeof(rbuf);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
if (r) {
|
||||
fprintf(stderr, "APDU transmit failed: %s\n",
|
||||
sc_strerror(r));
|
||||
return 1;
|
||||
}
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 00 || opt_debug) {
|
||||
fprintf(stderr, "Received (SW1=0x%02X, SW2=0x%02X)%s\n",
|
||||
apdu.sw1, apdu.sw2, apdu.resplen ? ":" : "");
|
||||
if (apdu.resplen)
|
||||
hex_dump_asc(stdout, apdu.resp, apdu.resplen, -1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Path to current DF:\n");
|
||||
hex_dump_asc(stdout, apdu.resp, apdu.resplen, -1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,6 +75,7 @@ int etoken_init()
|
|||
buffer);
|
||||
if (rc != sizeof(cookie)) {
|
||||
/* the whole cookie should have been send */
|
||||
syslog(LOG_ERR, "etoken fatal: cookie not completly send: rc=%d", rc);
|
||||
return USBTOKEN_ERROR;
|
||||
}
|
||||
|
||||
|
@ -82,11 +83,13 @@ int etoken_init()
|
|||
rc = usb_control_xmit(0xc0, 0x82, 0x0000, 0x0000, 0x0001, buffer);
|
||||
if (rc != 1) {
|
||||
/* we should have got one byte */
|
||||
syslog(LOG_ERR, "etoken fatal: did not receive one byte response to cookie: rc=%d", rc);
|
||||
return USBTOKEN_ERROR;
|
||||
}
|
||||
|
||||
if (buffer[0] != 0) {
|
||||
/* the answer should have bin 0x00 */
|
||||
syslog(LOG_ERR, "etoken fatal: received one byte response to cookie but it is: %d!=0", buffer[0]);
|
||||
return USBTOKEN_ERROR;
|
||||
}
|
||||
|
||||
|
@ -98,13 +101,47 @@ int etoken_transmit(uint8_t * buf_send, int len_send,
|
|||
uint8_t * buf_recv, int *len_recv)
|
||||
{
|
||||
int rc;
|
||||
uint8_t wtx_resp[] = { 0xe0, 0xc3, 0x01, 0x01, 0xc3 };
|
||||
uint8_t wtx_send[] = { 0x00, 0x00, 0x01, 0x00, 0x10, 0x27 };
|
||||
uint8_t wtx_recv[] = { 0x00 };
|
||||
|
||||
/* waiting time extension works without this,
|
||||
* but the windows driver send a magic sequence first
|
||||
* and asks for a magic answer, so we copied this */
|
||||
if (len_send == sizeof(wtx_resp)
|
||||
&& memcmp(buf_send, wtx_resp, sizeof(wtx_resp) == 0)) {
|
||||
|
||||
rc = usb_control_xmit(0x40, 0x02, 0x0000, 0x0000,
|
||||
sizeof(wtx_send), wtx_send);
|
||||
|
||||
if (rc != sizeof(wtx_send)) {
|
||||
syslog(LOG_ERR,
|
||||
"etoken fatal: wtx special send'd wrong len %d",
|
||||
rc);
|
||||
return USBTOKEN_ERROR;
|
||||
}
|
||||
rc = usb_control_xmit(0xc0, 0x82, 0x0000, 0x0000, 01,
|
||||
buf_recv);
|
||||
if (rc != sizeof(wtx_recv)) {
|
||||
syslog(LOG_ERR,
|
||||
"etoken fatal: wtx special recv'd wrong len %d",
|
||||
rc);
|
||||
return USBTOKEN_ERROR;
|
||||
}
|
||||
if (memcmp(buf_recv, wtx_recv, sizeof(wtx_recv) != 0)) {
|
||||
syslog(LOG_ERR,
|
||||
"etoken fatal: wtx special recv does not match");
|
||||
return USBTOKEN_ERROR;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* send via usb */
|
||||
rc = usb_control_xmit(0x40, 0x06, 0x0000, 0x0000, len_send,
|
||||
buf_send);
|
||||
if (rc != len_send) {
|
||||
syslog(LOG_ERR, "etoken fatal: received %d != %d", rc,
|
||||
len_send);
|
||||
syslog(LOG_ERR, "etoken fatal: received %d != %d",
|
||||
rc, len_send);
|
||||
return USBTOKEN_ERROR;
|
||||
}
|
||||
|
||||
|
@ -117,6 +154,5 @@ int etoken_transmit(uint8_t * buf_send, int len_send,
|
|||
}
|
||||
|
||||
*len_recv = rc;
|
||||
|
||||
return USBTOKEN_OK;
|
||||
}
|
||||
|
|
|
@ -17,11 +17,34 @@ int main(int argc, char **argv)
|
|||
{
|
||||
char *action, *device, *product;
|
||||
int rc;
|
||||
int pid;
|
||||
|
||||
/* some hotplugs script do not pass "usb" as parameter
|
||||
if (argc == 0) {
|
||||
perror("usbtoken hotplug should be called by the kernel");
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
||||
/* usb device? first parameter shoiuld be "usb". */
|
||||
/* some hotplug scripts to not pass usb as parameter
|
||||
if (!argv || argc < 1 || !argv[1] || strcmp(argv[1], "usb") != 0) {
|
||||
syslog(LOG_DEBUG, "%s called with %s (not \"usb\")\n",
|
||||
argv[0], argv[1]);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
pid = fork();
|
||||
if (pid == -1) {
|
||||
fprintf(stderr, "fork failed: %s (%d)", strerror(errno), errno);
|
||||
return 1;
|
||||
}
|
||||
if (pid) {
|
||||
/* parent process */
|
||||
return 0;
|
||||
}
|
||||
/* child: continue */
|
||||
|
||||
openlog(SYSLOG_NAME, LOG_CONS | LOG_PERROR | LOG_PID, LOG_KERN);
|
||||
|
||||
|
@ -31,13 +54,6 @@ int main(int argc, char **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* usb device? first parameter shoiuld be "usb". */
|
||||
if (!argv || argc < 1 || !argv[1] || strcmp(argv[1], "usb") != 0) {
|
||||
syslog(LOG_DEBUG, "%s called with %s (not \"usb\")\n",
|
||||
argv[0], argv[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* action should be "add".
|
||||
* we will notice removes ourself. */
|
||||
action = getenv("ACTION");
|
||||
|
|
Loading…
Reference in New Issue