From a16aaed41e859e4c350deeaf27c69d367cd8af31 Mon Sep 17 00:00:00 2001 From: Nuno Goncalves Date: Thu, 10 Nov 2016 11:24:41 +0100 Subject: [PATCH] pkcs15-tool: add --list-info option Signed-off-by: Nuno Goncalves --- src/tools/pkcs15-tool.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/tools/pkcs15-tool.c b/src/tools/pkcs15-tool.c index 43807aea..340c7fc9 100644 --- a/src/tools/pkcs15-tool.c +++ b/src/tools/pkcs15-tool.c @@ -98,7 +98,8 @@ enum { OPT_LIST_SKEYS, OPT_NO_PROMPT, OPT_RAW, - OPT_PRINT_VERSION + OPT_PRINT_VERSION, + OPT_LIST_INFO, }; #define NELEMENTS(x) (sizeof(x)/sizeof((x)[0])) @@ -107,6 +108,7 @@ static int authenticate(sc_pkcs15_object_t *obj); static const struct option options[] = { { "version", 0, NULL, OPT_PRINT_VERSION }, + { "list-info", no_argument, NULL, OPT_LIST_INFO }, { "list-applications", no_argument, NULL, OPT_LIST_APPLICATIONS }, { "read-certificate", required_argument, NULL, 'r' }, { "list-certificates", no_argument, NULL, 'c' }, @@ -145,6 +147,7 @@ static const struct option options[] = { static const char *option_help[] = { "Print OpenSC package version", + "List card information", "List the on-card PKCS#15 applications", "Reads certificate with ID ", "Lists certificates", @@ -1403,8 +1406,7 @@ static int list_apps(FILE *fout) return 0; } -static int dump(void) -{ +static void list_info(void){ const char *flags[] = { "Read-only", "Login required", @@ -1433,8 +1435,12 @@ static int dump(void) count++; } } - printf("\n\n"); + printf("\n"); +} +static int dump(void) +{ + list_info(); list_pins(); list_private_keys(); list_public_keys(); @@ -1872,6 +1878,7 @@ int main(int argc, char * const argv[]) int do_test_update = 0; int do_update = 0; int do_print_version = 0; + int do_list_info = 0; int action_count = 0; sc_context_param_t ctx_param; @@ -1890,6 +1897,10 @@ int main(int argc, char * const argv[]) do_print_version = 1; action_count++; break; + case OPT_LIST_INFO: + do_list_info = 1; + action_count++; + break; case 'r': opt_cert = optarg; do_read_cert = 1; @@ -2070,6 +2081,12 @@ int main(int argc, char * const argv[]) if (verbose) fprintf(stderr, "Found %s!\n", p15card->tokeninfo->label); + if (do_list_info) { + if (!do_dump) + list_info(); + action_count--; + } + if (do_verify_pin) if ((err = verify_pin())) goto end;