}
int ykp_json_import_cfg(const char *json, size_t len, YKP_CONFIG *cfg) {
- ykp_errno = YKP_ENOTYETIMPL;
+ if(cfg) {
+ json_object *jobj = json_tokener_parse(json);
+ json_object *yprod_json = json_object_object_get(jobj, "yubiProdConfig");
+ json_object *jmode = json_object_object_get(yprod_json, "mode");
+ const char *raw_mode = json_object_get_string(jmode);
+ int mode = MODE_OTP_YUBICO;
+
+ struct map_st *p;
+
+ for(p = _modes_map; p->flag; p++) {
+ if(strcmp(raw_mode, p->json_text) == 0) {
+ mode = p->flag;
+ break;
+ }
+ }
+
+ if(mode == MODE_OATH_HOTP) {
+ ykp_set_tktflag_OATH_HOTP(cfg, true);
+ } else if(mode == MODE_CHAL_HMAC) {
+ ykp_set_tktflag_CHAL_RESP(cfg, true);
+ ykp_set_cfgflag_CHAL_HMAC(cfg, true);
+ } else if(mode == MODE_CHAL_YUBICO) {
+ ykp_set_tktflag_CHAL_RESP(cfg, true);
+ ykp_set_cfgflag_CHAL_YUBICO(cfg, true);
+ } else if(mode == MODE_STATIC_TICKET) {
+ ykp_set_cfgflag_STATIC_TICKET(cfg, true);
+ }
+
+ json_object_put(jobj);
+ return 1;
+ }
+ ykp_errno = YKP_EINVAL;
return 0;
}
#include "ykpers-args.h"
-static int reader(char *buf, size_t count, void *stream)
-{
- return (int)fread(buf, 1, count, (FILE *)stream);
-}
-
int main(int argc, char **argv)
{
FILE *inf = NULL; const char *infname = NULL;
YKP_CONFIG *cfg = ykp_alloc();
YK_STATUS *st = ykds_alloc();
bool autocommit = false;
- char exported_data[1024];
+ char data[1024];
/* Options */
char *salt = NULL;
}
if (inf) {
- if (!ykp_read_config(cfg, reader, inf))
+ if(!fread(data, 1, 1024, inf))
+ goto err;
+ if (!ykp_import_config(data, strlen(data), cfg, data_format))
goto err;
} else if (! aesviahash && ! zap && (ykp_command(cfg) == SLOT_CONFIG || ykp_command(cfg) == SLOT_CONFIG2)) {
char passphrasebuf[256]; size_t passphraselen;
goto err;
}
- ykp_export_config(cfg, exported_data, 1024, data_format);
+ ykp_export_config(cfg, data, 1024, data_format);
if (outf) {
- if(!(fwrite(exported_data, 1, strlen(exported_data), outf))) {
+ if(!(fwrite(data, 1, strlen(data), outf))) {
goto err;
}
} else {
} else {
fprintf(stderr, "Configuration data to be updated in key configuration %d:\n\n", ykp_command(cfg) == SLOT_UPDATE1 ? 1 : 2);
}
- fwrite(exported_data, 1, strlen(exported_data), stderr);
+ fwrite(data, 1, strlen(data), stderr);
}
fprintf(stderr, "\nCommit? (y/n) [n]: ");
if (autocommit) {
if (!fgets(commitbuf, sizeof(commitbuf), stdin))
{
perror ("fgets");
- exit_code;
goto err;
}
}