diff --git a/cmdline.ggo b/cmdline.ggo index 4993b8a..19fa5ca 100644 --- a/cmdline.ggo +++ b/cmdline.ggo @@ -27,7 +27,7 @@ option "verbose" v "Print more information" int optional default="0" argoptional option "reader" r "Only use a matching reader" string optional option "key" k "Authentication key to use" string optional default="010203040506070801020304050607080102030405060708" -option "action" a "Action to take" values="version","generate","set-mgm-key","reset","pin-retries","import-key" enum +option "action" a "Action to take" values="version","generate","set-mgm-key","reset","pin-retries","import-key" enum multiple option "slot" s "What key slot to operate on" values="9a","9c","9d","9e" enum optional option "algorithm" A "What algorithm to use" values="RSA1024","RSA2048","ECCP256" enum optional default="RSA2048" option "new-key" n "New authentication key to use" string optional diff --git a/yubico-piv-tool.c b/yubico-piv-tool.c index 6a3abcb..abce761 100644 --- a/yubico-piv-tool.c +++ b/yubico-piv-tool.c @@ -568,6 +568,8 @@ int main(int argc, char *argv[]) { SCARDCONTEXT context; unsigned char key[KEY_LEN]; int verbosity; + enum enum_action action; + unsigned int i; if(cmdline_parser(argc, argv, &args_info) != 0) { return EXIT_FAILURE; @@ -591,48 +593,54 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - if(args_info.action_arg == action_arg_version) { - print_version(&card, verbosity); - } else if(args_info.action_arg == action_arg_generate) { - if(args_info.slot_arg != slot__NULL) { - generate_key(&card, args_info.slot_orig, args_info.algorithm_arg, verbosity); - } else { - fprintf(stderr, "The generate action needs a slot (-s) to operate on.\n"); - return EXIT_FAILURE; + for(i = 0; i < args_info.action_given; i++) { + action = *args_info.action_arg++; + if(verbosity) { + fprintf(stderr, "Now processing for action %d.\n", action); } - } else if(args_info.action_arg == action_arg_setMINUS_mgmMINUS_key) { - if(args_info.new_key_arg) { - unsigned char new_key[KEY_LEN]; - if(parse_key(args_info.new_key_arg, new_key, verbosity) == false) { + if(action == action_arg_version) { + print_version(&card, verbosity); + } else if(action == action_arg_generate) { + if(args_info.slot_arg != slot__NULL) { + generate_key(&card, args_info.slot_orig, args_info.algorithm_arg, verbosity); + } else { + fprintf(stderr, "The generate action needs a slot (-s) to operate on.\n"); return EXIT_FAILURE; } - if(set_mgm_key(&card, new_key, verbosity) == false) { + } else if(action == action_arg_setMINUS_mgmMINUS_key) { + if(args_info.new_key_arg) { + unsigned char new_key[KEY_LEN]; + if(parse_key(args_info.new_key_arg, new_key, verbosity) == false) { + return EXIT_FAILURE; + } + if(set_mgm_key(&card, new_key, verbosity) == false) { + return EXIT_FAILURE; + } + } else { + fprintf(stderr, "The set-mgm-key action needs the new-key (-n) argument.\n"); return EXIT_FAILURE; } - } else { - fprintf(stderr, "The set-mgm-key action needs the new-key (-n) argument.\n"); - return EXIT_FAILURE; - } - } else if(args_info.action_arg == action_arg_reset) { - if(reset(&card, verbosity) == false) { - return EXIT_FAILURE; - } - } else if(args_info.action_arg == action_arg_pinMINUS_retries) { - if(args_info.pin_retries_arg && args_info.puk_retries_arg) { - if(set_pin_retries(&card, args_info.pin_retries_arg, args_info.puk_retries_arg, verbosity) == false) { + } else if(action == action_arg_reset) { + if(reset(&card, verbosity) == false) { return EXIT_FAILURE; } - } else { - return EXIT_FAILURE; - } - } else if(args_info.action_arg == action_arg_importMINUS_key) { - if(args_info.slot_arg != slot__NULL) { - if(import_key(&card, args_info.key_format_arg, args_info.input_arg, args_info.slot_orig, verbosity) == false) { + } else if(action == action_arg_pinMINUS_retries) { + if(args_info.pin_retries_arg && args_info.puk_retries_arg) { + if(set_pin_retries(&card, args_info.pin_retries_arg, args_info.puk_retries_arg, verbosity) == false) { + return EXIT_FAILURE; + } + } else { + return EXIT_FAILURE; + } + } else if(action == action_arg_importMINUS_key) { + if(args_info.slot_arg != slot__NULL) { + if(import_key(&card, args_info.key_format_arg, args_info.input_arg, args_info.slot_orig, verbosity) == false) { + return EXIT_FAILURE; + } + } else { + fprintf(stderr, "The generate action needs a slot (-s) to operate on.\n"); return EXIT_FAILURE; } - } else { - fprintf(stderr, "The generate action needs a slot (-s) to operate on.\n"); - return EXIT_FAILURE; } }