]> err.no Git - yubikey-personalization/commitdiff
add parsing of targetConfig to import
authorKlas Lindfors <klas@yubico.com>
Thu, 25 Apr 2013 08:44:19 +0000 (10:44 +0200)
committerKlas Lindfors <klas@yubico.com>
Thu, 25 Apr 2013 08:59:38 +0000 (10:59 +0200)
ykpers-json.c

index 285f1a71297a860fda991910e413771b5c461847..1c19e3ea1dbf52ce6799a485f211bd5aaf91c1c9 100644 (file)
@@ -185,6 +185,7 @@ int _ykp_json_import_cfg(YKP_CONFIG *cfg, const char *json, size_t len) {
                json_object *yprod_json = json_object_object_get(jobj, "yubiProdConfig");
                json_object *jmode = json_object_object_get(yprod_json, "mode");
                json_object *options = json_object_object_get(yprod_json, "options");
+               json_object *jtarget;
                const char *raw_mode;
                int mode = MODE_OTP_YUBICO;
                struct map_st *p;
@@ -199,6 +200,20 @@ int _ykp_json_import_cfg(YKP_CONFIG *cfg, const char *json, size_t len) {
                        return 0;
                }
 
+               jtarget = json_object_object_get(yprod_json, "targetConfig");
+               if(jtarget) {
+                       int target_config = json_object_get_int(jtarget);
+                       if(target_config == 1 &&
+                                       cfg->command != SLOT_CONFIG) {
+                               ykp_errno = YKP_EINVAL;
+                               return 0;
+                       } else if(target_config == 2 &&
+                                       cfg->command != SLOT_CONFIG2) {
+                               ykp_errno = YKP_EINVAL;
+                               return 0;
+                       }
+               }
+
                raw_mode = json_object_get_string(jmode);
 
                for(p = _modes_map; p->flag; p++) {