]> err.no Git - yubikey-personalization/commitdiff
tool support for writing SLOT_NDEF2
authorKlas Lindfors <klas@yubico.com>
Fri, 9 Nov 2012 12:39:44 +0000 (13:39 +0100)
committerKlas Lindfors <klas@yubico.com>
Fri, 9 Nov 2012 12:40:47 +0000 (13:40 +0100)
ykpers-args.c
ykpersonalize.c

index d17ba23b6c5df75728a06b05a5741fd8417d76ab..05884e9b91e2267e1101e05e5c94552ff4785629 100644 (file)
@@ -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");
index 6da344e718d979da55bb8e5916043b225c2ee59e..ae1e595732b6ce04ece7145b8b8457a06a0641f0 100644 (file)
@@ -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;