diff --git a/doc/tools/piv-tool.1.xml b/doc/tools/piv-tool.1.xml index e9b77629..70619cce 100644 --- a/doc/tools/piv-tool.1.xml +++ b/doc/tools/piv-tool.1.xml @@ -163,19 +163,6 @@ - - - driver, - driver - - - Use the given card driver. - The default is to auto-detect the correct card driver. - The literal value ? lists - all available card drivers and terminates - piv-tool. - - , diff --git a/src/tools/piv-tool.c b/src/tools/piv-tool.c index 5be365dc..fbc2ab3f 100644 --- a/src/tools/piv-tool.c +++ b/src/tools/piv-tool.c @@ -52,6 +52,7 @@ #include "libopensc/opensc.h" #include "libopensc/cardctl.h" +#include "libopensc/cards.h" #include "libopensc/asn1.h" #include "util.h" #include "libopensc/sc-ossl-compat.h" @@ -80,7 +81,6 @@ static const struct option options[] = { { "in", 1, NULL, 'i' }, { "send-apdu", 1, NULL, 's' }, { "reader", 1, NULL, 'r' }, - { "card-driver", 1, NULL, 'c' }, { "wait", 0, NULL, 'w' }, { "verbose", 0, NULL, 'v' }, { NULL, 0, NULL, 0 } @@ -98,7 +98,6 @@ static const char *option_help[] = { "Input file for cert", "Sends an APDU in format AA:BB:CC:DD:EE:FF...", "Uses reader number [0]", - "Forces the use of driver [auto-detect; '?' for list]", "Wait for a card to be inserted", "Verbose operation. Use several times to enable debug output.", }; @@ -469,7 +468,7 @@ static void print_serial(sc_card_t *in_card) int main(int argc, char *argv[]) { - int err = 0, r, c, long_optind = 0; + int err = 0, r, c; int do_send_apdu = 0; int do_admin_mode = 0; int do_gen_key = 0; @@ -478,9 +477,7 @@ int main(int argc, char *argv[]) int compress_cert = 0; int do_print_serial = 0; int do_print_name = 0; - int do_list_card_drivers = 0; int action_count = 0; - const char *opt_driver = NULL; const char *out_file = NULL; const char *in_file = NULL; const char *cert_id = NULL; @@ -490,12 +487,7 @@ int main(int argc, char *argv[]) sc_context_param_t ctx_param; char **old_apdus = NULL; - while (1) { - c = getopt_long(argc, argv, "nA:G:O:Z:C:i:o:fvs:c:w", options, &long_optind); - if (c == -1) - break; - if (c == '?') - util_print_usage_and_die(app_name, options, option_help, NULL); + while ((c = getopt_long(argc, argv, "nA:G:O:Z:C:i:o:r:fvs:c:w", options, (int *) 0)) != -1) { switch (c) { case OPT_SERIAL: do_print_serial = 1; @@ -555,19 +547,11 @@ int main(int argc, char *argv[]) case 'v': verbose++; break; - case 'c': - opt_driver = optarg; - - /* special card driver value "?" means: list available drivers */ - if (opt_driver != NULL && strncmp("?", opt_driver, sizeof("?")) == 0) { - opt_driver = NULL; - do_list_card_drivers = 1; - action_count++; - } - break; case 'w': opt_wait = 1; break; + default: + util_print_usage_and_die(app_name, options, option_help, NULL); } } @@ -612,24 +596,25 @@ int main(int argc, char *argv[]) if (action_count <= 0) goto end; - if (do_list_card_drivers) { - err = util_list_card_drivers(ctx); + /* force PIV card driver */ + err = sc_set_card_driver(ctx, "PIV-II"); + if (err) { + fprintf(stderr, "PIV card driver not found!\n"); + err = 1; goto end; } - if (opt_driver != NULL) { - err = sc_set_card_driver(ctx, opt_driver); - if (err) { - fprintf(stderr, "Driver '%s' not found!\n", opt_driver); - err = 1; - goto end; - } - } - err = util_connect_card(ctx, &card, opt_reader, opt_wait, verbose); if (err) goto end; + /* fail if card is not a PIV card */ + if (card->type < SC_CARD_TYPE_PIV_II_BASE || card->type >= SC_CARD_TYPE_PIV_II_BASE+1000) { + fprintf(stderr, "Card type %X: not a PIV card\n", card->type); + err = 1; + goto end; + } + if (do_admin_mode) { if ((err = admin_mode(admin_info))) goto end;