- prevent problem with get/get_do ambiguity

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1596 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
okir 2003-11-03 06:54:30 +00:00
parent f5f5f7f57c
commit 3d0e266886
1 changed files with 27 additions and 13 deletions

View File

@ -594,40 +594,53 @@ int do_verify(int argc, char **argv)
{ "PRO", SC_AC_PRO }, { "PRO", SC_AC_PRO },
{ NULL, -1 } { NULL, -1 }
}; };
int i, type = -1, ref, r, tries_left = -1; int i, r, tries_left = -1;
u8 buf[30]; u8 buf[30];
const char *s; const char *s;
size_t buflen = sizeof(buf); size_t buflen = sizeof(buf);
struct sc_pin_cmd_data data;
if (argc < 1 || argc > 2) if (argc < 1 || argc > 2)
goto usage; goto usage;
memset(&data, 0, sizeof(data));
data.cmd = SC_PIN_CMD_VERIFY;
data.pin_type = -1;
for (i = 0; typeNames[i].name; i++) { for (i = 0; typeNames[i].name; i++) {
if (strncasecmp(argv[0], typeNames[i].name, 3) == 0) { if (strncasecmp(argv[0], typeNames[i].name, 3) == 0) {
type = typeNames[i].type; data.pin_type = typeNames[i].type;
break; break;
} }
} }
if (type == -1) { if (data.pin_type == -1) {
printf("Invalid type.\n"); printf("Invalid type.\n");
goto usage; goto usage;
} }
if (sscanf(argv[0] + 3, "%d", &ref) != 1) { if (sscanf(argv[0] + 3, "%d", &data.pin_reference) != 1) {
printf("Invalid key reference.\n"); printf("Invalid key reference.\n");
goto usage; goto usage;
} }
if (argc < 2) { if (argc < 2) {
/* just return the retry counter */ if (!(card->reader->slot[0].capabilities & SC_SLOT_CAP_PIN_PAD)) {
buflen = 0; printf("Card reader or driver doesn't support PIN PAD\n");
} return -1;
if (argv[1][0] == '"') { }
printf("Please enter PIN on the reader's pin pad.\n");
data.pin1.prompt = "Please enter PIN";
data.flags |= SC_PIN_CMD_USE_PINPAD;
} else if (argv[1][0] == '"') {
for (s=argv[1]+1, i=0; i < sizeof(buf) && *s && *s != '"';i++) for (s=argv[1]+1, i=0; i < sizeof(buf) && *s && *s != '"';i++)
buf[i] = *s++; buf[i] = *s++;
buflen = i; data.pin1.data = buf;
data.pin1.len = i;
} else if (sc_hex_to_bin(argv[1], buf, &buflen) != 0) { } else if (sc_hex_to_bin(argv[1], buf, &buflen) != 0) {
printf("Invalid key value.\n"); printf("Invalid key value.\n");
goto usage; goto usage;
} }
r = sc_verify(card, type, ref, buf, buflen, &tries_left); r = sc_pin_cmd(card, &data, &tries_left);
if (r) { if (r) {
if (r == SC_ERROR_PIN_CODE_INCORRECT) { if (r == SC_ERROR_PIN_CODE_INCORRECT) {
if (tries_left >= 0) if (tries_left >= 0)
@ -646,6 +659,7 @@ usage:
for (i = 0; typeNames[i].name; i++) for (i = 0; typeNames[i].name; i++)
printf("\t%s\n", typeNames[i].name); printf("\t%s\n", typeNames[i].name);
printf("Example: verify CHV2 31:32:33:34:00:00:00:00\n"); printf("Example: verify CHV2 31:32:33:34:00:00:00:00\n");
printf("If key is omitted, card reader's keypad will be used to collect PIN.\n");
return -1; return -1;
} }
@ -1232,8 +1246,8 @@ struct command cmds[] = {
{ "unblock", do_unblock, "unblock a PIN" }, { "unblock", do_unblock, "unblock a PIN" },
{ "put", do_put, "copy a local file to the card" }, { "put", do_put, "copy a local file to the card" },
{ "get", do_get, "copy an EF to a local file" }, { "get", do_get, "copy an EF to a local file" },
{ "get_do", do_get_data, "get a data object" }, { "do_get", do_get_data, "get a data object" },
{ "put_do", do_put_data, "put a data object" }, { "do_put", do_put_data, "put a data object" },
{ "mkdir", do_mkdir, "create a DF" }, { "mkdir", do_mkdir, "create a DF" },
{ "pksign", do_pksign, "create a public key signature" }, { "pksign", do_pksign, "create a public key signature" },
{ "pkdecrypt", do_pkdecrypt, "perform a public key decryption" }, { "pkdecrypt", do_pkdecrypt, "perform a public key decryption" },