From 4cec763410af7c06e597de53311038bc91c5b1d7 Mon Sep 17 00:00:00 2001 From: Klas Lindfors Date: Tue, 18 Jun 2013 08:52:27 +0200 Subject: [PATCH] give ykinfo -1 and -2 for programming status of the slots --- ykinfo.1 | 8 +++++++- ykinfo.c | 31 ++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/ykinfo.1 b/ykinfo.1 index dacd5b3..b7e04fd 100644 --- a/ykinfo.1 +++ b/ykinfo.1 @@ -35,7 +35,7 @@ ykinfo - Get basic information from a YubiKey .SH SYNOPSIS .B ykinfo -[\fI-s\fR] [\fI-m\fR] [\fI-H\fR] [\fI-v\fR] [\fI-t\fR] [\fI-p\fR] [\fI-q\fR] [\fI-V\fR] [\fI-h\fR] +[\fI-s\fR] [\fI-m\fR] [\fI-H\fR] [\fI-v\fR] [\fI-t\fR] [\fI-p\fR] [\fI-1\fR] [\fI-2\fR] [\fI-q\fR] [\fI-V\fR] [\fI-h\fR] .SH DESCRIPTION .PP Get basic information from a YubiKey. Can get serial number, version @@ -62,6 +62,12 @@ get the touch level and output it. \fB\-p\fR get the programming sequence and output it. .TP +\fB\-1\fR +get the status of slot 1, 1 for programmed and 0 for empty +.TP +\fB\-2\fR +get the status of slot 2, 1 for programmed and 0 for empty +.TP \fB\-a\fR get all the information above. .TP diff --git a/ykinfo.c b/ykinfo.c index 0015e7f..55425ff 100644 --- a/ykinfo.c +++ b/ykinfo.c @@ -38,6 +38,7 @@ #include #include #include +#include const char *usage = "Usage: ykinfo [options]\n" @@ -49,6 +50,8 @@ const char *usage = "\t-H Get serial in hex from YubiKey\n" "\t-v Get version from YubiKey\n" "\t-t Get touchlevel from YubiKey\n" + "\t-1 Check if slot 1 is programmed\n" + "\t-2 Check if slot 2 is programmed\n" "\t-p Get programming sequence from YubiKey\n" "\t-a Get all information above\n" "\n" @@ -59,7 +62,7 @@ const char *usage = "\n" "\n" ; -const char *optstring = "asmHvtpqhV"; +const char *optstring = "asmHvtpqhV12"; static void report_yk_error(void) { @@ -77,6 +80,7 @@ static void report_yk_error(void) static int parse_args(int argc, char **argv, bool *serial_dec, bool *serial_modhex, bool *serial_hex, bool *version, bool *touch_level, bool *pgm_seq, bool *quiet, + bool *slot1, bool *slot2, int *exit_code) { int c; @@ -90,6 +94,8 @@ static int parse_args(int argc, char **argv, *version = true; *touch_level = true; *pgm_seq = true; + *slot1 = true; + *slot2 = true; break; case 's': *serial_dec = true; @@ -112,6 +118,12 @@ static int parse_args(int argc, char **argv, case 'q': *quiet = true; break; + case '1': + *slot1 = true; + break; + case '2': + *slot2 = true; + break; case 'V': fputs(YKPERS_VERSION_STRING "\n", stderr); *exit_code = 0; @@ -125,7 +137,7 @@ static int parse_args(int argc, char **argv, } if (!*serial_dec && !*serial_modhex && !*serial_hex && - !*version && !*touch_level && !*pgm_seq) { + !*version && !*touch_level && !*pgm_seq && !*slot1 && !*slot2) { /* no options at all */ fputs("You must give at least one option.\n", stderr); fputs(usage, stderr); @@ -149,6 +161,8 @@ int main(int argc, char **argv) bool version = false; bool touch_level = false; bool pgm_seq = false; + bool slot1 = false; + bool slot2 = false; bool quiet = false; @@ -157,6 +171,7 @@ int main(int argc, char **argv) if (! parse_args(argc, argv, &serial_dec, &serial_modhex, &serial_hex, &version, &touch_level, &pgm_seq, &quiet, + &slot1, &slot2, &exit_code)) exit(exit_code); @@ -200,7 +215,7 @@ int main(int argc, char **argv) printf("%s\n", modhex_serial); } } - if(version || touch_level || pgm_seq) { + if(version || touch_level || pgm_seq || slot1 || slot2) { YK_STATUS *st = ykds_alloc(); if(!yk_get_status(yk, st)) { ykds_free(st); @@ -223,6 +238,16 @@ int main(int argc, char **argv) printf("programming_sequence: "); printf("%d\n", ykds_pgm_seq(st)); } + if(slot1) { + if(!quiet) + printf("slot1_status: "); + printf("%d\n", (ykds_touch_level(st) & CONFIG1_VALID) == CONFIG1_VALID); + } + if(slot2) { + if(!quiet) + printf("slot2_status: "); + printf("%d\n", (ykds_touch_level(st) & CONFIG2_VALID) == CONFIG2_VALID); + } ykds_free(st); } -- 2.39.5