From: Richard Levitte Date: Mon, 24 Aug 2009 13:00:43 +0000 (+0000) Subject: Make all input numbers hexadecimal by default. It's still possible to give modhex... X-Git-Tag: yubikey-personalisation_1.3.5-1~4^2~103 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53af97c41113dfd908d397c62e71173141f48fb9;p=yubikey-personalization.old Make all input numbers hexadecimal by default. It's still possible to give modhex ones by prefixing them with 'm:' --- diff --git a/NEWS b/NEWS index d47f74f..dbb9838 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,11 @@ Yubikey-personalize NEWS -- History of user-visible changes. -*- outline -*- +* Version 0.96 (released 2009-08-xx) + +** Make all input numbers hex by default. +It's still possible to give modhex numbers by preceding them with +`m:'. + * Version 0.95 (released 2009-08-17) ** Enable handling of programming access code. diff --git a/ykpersonalize.c b/ykpersonalize.c index 67c873a..19630b0 100644 --- a/ykpersonalize.c +++ b/ykpersonalize.c @@ -44,19 +44,17 @@ const char *usage = "-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" @@ -101,6 +99,15 @@ static int writer(const char *buf, size_t count, void *stream) 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) @@ -126,7 +133,7 @@ main(int argc, char **argv) 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(); @@ -191,8 +198,8 @@ main(int argc, char **argv) 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, @@ -214,26 +221,10 @@ main(int argc, char **argv) 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); @@ -246,7 +237,7 @@ main(int argc, char **argv) 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) { @@ -261,7 +252,7 @@ main(int argc, char **argv) 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) @@ -454,5 +445,8 @@ err: exit_code = 2; } + if (cfg) + ykp_free_config(cfg); + exit(exit_code); }