" (if FILE is -, send to stdout)\n"
"-iFILE read configuration from FILE.\n"
" (if FILE is -, read from stdin)\n"
+"-fformat set the data format for -s and -i (and for standard write to console\n"
+" valid values are json or legacy.\n"
"-aXXX.. The AES secret key as a 32 (or 40 for OATH-HOTP/HMAC CHAL-RESP)\n"
" char hex value (not modhex)\n"
"-cXXX.. A 12 char hex value (not modhex) to use as access code for programming\n"
"-v verbose\n"
"-h help (this text)\n"
;
-const char *optstring = "u12xza:c:n:t:hi:o:s:vym:S::";
+const char *optstring = "u12xza:c:n:t:hi:o:s:f:vym:S::";
static int _set_fixed(char *opt, YKP_CONFIG *cfg);
static int _format_decimal_as_hex(uint8_t *dst, size_t dst_len, uint8_t *src);
*/
int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, YK_KEY *yk,
const char **infname, const char **outfname,
+ int *data_format,
bool *autocommit, char *salt,
YK_STATUS *st, bool *verbose,
unsigned char *access_code, bool *use_access_code,
case 's':
*outfname = optarg;
break;
+ case 'f':
+ if(strcmp(optarg, "json") == 0) {
+ *data_format = YKP_FORMAT_JSON;
+ } else if(strcmp(optarg, "legacy") == 0) {
+ *data_format = YKP_FORMAT_LEGACY;
+ } else {
+ fprintf(stderr, "The only valid formats to -f is json and legacy.\n");
+ *exit_code = 1;
+ return 0;
+ }
+ break;
case 'a':
*aesviahash = true;
aeshash = optarg;
int args_to_config(int argc, char **argv, YKP_CONFIG *cfg, YK_KEY *yk,
const char **infname, const char **outfname,
+ int *data_format,
bool *autocommit, char *salt,
YK_STATUS *st, bool *verbose,
unsigned char *access_code, bool *use_access_code,
{
return (int)fread(buf, 1, count, (FILE *)stream);
}
-static int writer(const char *buf, size_t count, void *stream)
-{
- return (int)fwrite(buf, 1, count, (FILE *)stream);
-}
int main(int argc, char **argv)
{
FILE *inf = NULL; const char *infname = NULL;
FILE *outf = NULL; const char *outfname = NULL;
+ int data_format = YKP_FORMAT_LEGACY;
bool verbose = false;
bool aesviahash = false;
bool use_access_code = false;
YKP_CONFIG *cfg = ykp_alloc();
YK_STATUS *st = ykds_alloc();
bool autocommit = false;
+ char exported_data[1024];
/* Options */
char *salt = NULL;
/* Parse all arguments in a testable way */
if (! args_to_config(argc, argv, cfg, yk,
&infname, &outfname,
+ &data_format,
&autocommit, salt,
st, &verbose,
access_code, &use_access_code,
goto err;
}
+ ykp_export_config(cfg, exported_data, 1024, data_format);
if (outf) {
- if (!ykp_write_config(cfg, writer, outf))
+ if(!(fwrite(exported_data, 1, strlen(exported_data), outf))) {
goto err;
+ }
} else {
char commitbuf[256]; size_t commitlen;
} else {
fprintf(stderr, "Configuration data to be updated in key configuration %d:\n\n", ykp_command(cfg) == SLOT_UPDATE1 ? 1 : 2);
}
- ykp_write_config(cfg, writer, stderr);
+ fwrite(exported_data, 1, strlen(exported_data), stderr);
}
fprintf(stderr, "\nCommit? (y/n) [n]: ");
if (autocommit) {