"-iFILE read configuration from FILE.\n"
" (if FILE is -, read from stdin)\n"
"-aXXX.. A 32 char hex value (not modhex) of a fixed AES key to use\n"
-"-cXXX.. A 12 char modhex value to use as access code for programming\n"
+"-cXXX.. A 12 char hex value to use as access code for programming\n"
" (this does NOT SET the access code, that's done with -oaccess=)\n"
"-oOPTION change configuration option. Possible OPTION arguments are:\n"
" salt=ssssssss Salt to be used for key generation. If\n"
" none is given, a unique random one will be\n"
" generated.\n"
-" fixed=fffffffffff The public modhex identity of key.\n"
+" fixed=xxxxxxxxxxx The public hex identity of key.\n"
" This is 0-16 characters long.\n"
-" hexfixed=fffffff Fixed part, but encoded in hex.\n"
-" This is 0-16 characters long.\n"
-" uid=uuuuuu The uid part of the generated ticket.\n"
+" uid=xxxxxx The uid part of the generated ticket.\n"
" MUST be 12 characters long.\n"
-" access=fffffffffff New modhex access code to set.\n"
+" access=xxxxxxxxxxx New access code to set, in hex.\n"
" MUST be 12 characters long.\n"
" [-]tab-first set/clear the TAB_FIRST ticket flag.\n"
" [-]append-tab1 set/clear the APPEND_TAB1 ticket flag.\n"
return (int)fwrite(buf, 1, count, (FILE *)stream);
}
+static int hex_modhex_decode(char *result, const char *str, size_t strl)
+{
+ if (strlen >= 2
+ && (strncmp(str, "m:", 2) == 0 || strncmp(str, "M:", 2) == 0)) {
+ return yubikey_modhex_decode(result, str+2, strl-2);
+ }
+ return yubikey_hex_decode(result, str+2, strl-2);
+}
+
static void report_yk_error()
{
if (ykp_errno)
bool aesviahash = false; const char *aeshash = NULL;
bool use_access_code = false, new_access_code = false;
unsigned char access_code[256];
- YK_KEY *yk = NULL;
+ YK_KEY *yk = 0;
YKP_CONFIG *cfg = ykp_create_config();
YK_STATUS *st = ykds_alloc();
exit_code = 1;
goto err;
}
- yubikey_modhex_decode(access_code,
- optarg, strlen(optarg));
+ hex_modhex_decode(access_code,
+ optarg, strlen(optarg));
if (!new_access_code)
ykp_set_access_code(cfg,
access_code,
exit_code = 1;
goto err;
}
- yubikey_modhex_decode (fixedbin, fixed,
- fixedlen);
+ hex_modhex_decode(fixedbin, fixed, fixedlen);
ykp_set_fixed(cfg, fixedbin, fixedlen / 2);
new_access_code = true;
}
- else if (strncmp(optarg, "hexfixed=", 9) == 0) {
- const char *fixed = optarg+9;
- size_t fixedlen = strlen (fixed);
- char fixedbin[256];
- if (fixedlen % 2 || fixedlen > 16)
- {
- fprintf(stderr,
- "Invalid hex fixed string: %s\n",
- fixed);
- exit_code = 1;
- goto err;
- }
- yubikey_hex_decode (fixedbin, fixed, fixedlen);
- ykp_set_fixed(cfg, fixedbin, fixedlen / 2);
- }
else if (strncmp(optarg, "uid=", 4) == 0) {
const char *uid = optarg+4;
size_t uidlen = strlen (uid);
exit_code = 1;
goto err;
}
- yubikey_hex_decode (uidbin, uid, uidlen);
+ hex_modhex_decode(uidbin, uid, uidlen);
ykp_set_uid(cfg, uidbin, uidlen / 2);
}
else if (strncmp(optarg, "access=", 7) == 0) {
exit_code = 1;
goto err;
}
- yubikey_modhex_decode (accbin, acc, acclen);
+ hex_modhex_decode (accbin, acc, acclen);
ykp_set_access_code(cfg, accbin, acclen / 2);
}
else if (strcmp(optarg, "tab-first") == 0)
exit_code = 2;
}
+ if (cfg)
+ ykp_free_config(cfg);
+
exit(exit_code);
}