From: Klas Lindfors Date: Fri, 9 Nov 2012 12:39:44 +0000 (+0100) Subject: tool support for writing SLOT_NDEF2 X-Git-Tag: v1.10.0~36 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f32598a15fef2499636b87cb7d3cfac39f094d68;p=yubikey-personalization tool support for writing SLOT_NDEF2 --- diff --git a/ykpers-args.c b/ykpers-args.c index d17ba23..05884e9 100644 --- a/ykpers-args.c +++ b/ykpers-args.c @@ -69,8 +69,8 @@ const char *usage = " char hex value (not modhex)\n" "-cXXX.. A 12 char hex value (not modhex) to use as access code for programming\n" " (this does NOT SET the access code, that's done with -oaccess=)\n" -"-nXXX.. Write NDEF type 2 URI to YubiKey NEO, must be used on it's own\n" -"-tXXX.. Write NDEF type 2 text to YubiKey NEO, must be used on it's own\n" +"-nXXX.. Write NDEF type 2 URI to YubiKey NEO, must be used with -1 or -2\n" +"-tXXX.. Write NDEF type 2 text to YubiKey NEO, must be used with -1 or -2\n" "-oOPTION change configuration option. Possible OPTION arguments are:\n" " salt=ssssssss Salt to be used when deriving key from a\n" " password. If none is given, a unique random\n" @@ -307,11 +307,6 @@ int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, YK_KEY *yk, *exit_code = 1; return 0; } - if (ndef_seen) { - fprintf(stderr, "Slot (-1 / -2) can not be combined with ndef (-n)\n"); - *exit_code = 1; - return 0; - } ykp_set_tktflag_APPEND_CR(cfg, true); if (update_seen) { ykp_set_extflag_ALLOW_UPDATE(cfg, true); @@ -410,21 +405,35 @@ int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, YK_KEY *yk, } case 't': *ndef_type = 'T'; - case 'n': - if(!*ndef_type) { - *ndef_type = 'U'; - } - if (slot_chosen || swap_seen || update_seen || option_seen || *zap) { - fprintf(stderr, "Ndef (-n/-t) must be used on it's own.\n"); - *exit_code = 1; - return 0; - } - if (!ykp_configure_command(cfg, SLOT_NDEF)) { - return 0; - } - memcpy(ndef, optarg, strlen(optarg)); - ndef_seen = true; - break; + case 'n': { + int command; + if(!*ndef_type) { + *ndef_type = 'U'; + } + if (!slot_chosen) { + fprintf(stderr, "A slot (-1/-2) must be chosen before ndef (-n/-t) argument.\n"); + *exit_code = 1; + return 0; + } + if (swap_seen || update_seen || option_seen || *zap) { + fprintf(stderr, "Ndef (-n/-t) can only be used with a slot (-1/-2).\n"); + *exit_code = 1; + return 0; + } + if(ykp_command(cfg) == SLOT_CONFIG) { + command = SLOT_NDEF; + } else if(ykp_command(cfg) == SLOT_CONFIG2) { + command = SLOT_NDEF2; + } else { + return 0; + } + if (!ykp_configure_command(cfg, command)) { + return 0; + } + memcpy(ndef, optarg, strlen(optarg)); + ndef_seen = true; + break; + } case 'o': if (*zap) { fprintf(stderr, "No options can be given with zap (-z).\n"); diff --git a/ykpersonalize.c b/ykpersonalize.c index 6da344e..ae1e595 100644 --- a/ykpersonalize.c +++ b/ykpersonalize.c @@ -202,7 +202,7 @@ int main(int argc, char **argv) if (ykp_command(cfg) == SLOT_SWAP) { fprintf(stderr, "Configuration in slot 1 and 2 will be swapped\n"); - } else if(ykp_command(cfg) == SLOT_NDEF) { + } else if(ykp_command(cfg) == SLOT_NDEF || ykp_command(cfg) == SLOT_NDEF2) { fprintf(stderr, "New NDEF URI will be written\n"); } else if(zap) { fprintf(stderr, "Configuration in slot %d will be deleted\n", ykp_config_num(cfg)); @@ -230,8 +230,9 @@ int main(int argc, char **argv) if (verbose) printf("Attempting to write configuration to the yubikey..."); - if(ykp_command(cfg) == SLOT_NDEF) { + if(ykp_command(cfg) == SLOT_NDEF || ykp_command(cfg) == SLOT_NDEF2) { YK_NDEF *ndef = ykp_alloc_ndef(); + int confnum = 1; if(ndef_type == 'U') { ykp_construct_ndef_uri(ndef, ndef_string); } else if(ndef_type == 'T') { @@ -240,7 +241,10 @@ int main(int argc, char **argv) if(use_access_code) { ykp_set_ndef_access_code(ndef, access_code); } - if (!yk_write_ndef(yk, ndef)) { + if(ykp_command(cfg) == SLOT_NDEF2) { + confnum = 2; + } + if (!yk_write_ndef2(yk, ndef, confnum)) { if (verbose) printf(" failure\n"); goto err;