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
\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
#include <ykcore.h>
#include <ykstatus.h>
#include <ykpers-version.h>
+#include <ykdef.h>
const char *usage =
"Usage: ykinfo [options]\n"
"\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"
"\n"
"\n"
;
-const char *optstring = "asmHvtpqhV";
+const char *optstring = "asmHvtpqhV12";
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;
*version = true;
*touch_level = true;
*pgm_seq = true;
+ *slot1 = true;
+ *slot2 = true;
break;
case 's':
*serial_dec = true;
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;
}
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);
bool version = false;
bool touch_level = false;
bool pgm_seq = false;
+ bool slot1 = false;
+ bool slot2 = false;
bool quiet = false;
if (! parse_args(argc, argv,
&serial_dec, &serial_modhex, &serial_hex,
&version, &touch_level, &pgm_seq, &quiet,
+ &slot1, &slot2,
&exit_code))
exit(exit_code);
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);
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);
}