char *salt = NULL;
char ndef[128];
char ndef_type = NULL;
+ bool zap = false;
int rc;
&autocommit, salt,
st, &verbose,
access_code, &use_access_code,
- &aesviahash, &ndef_type, ndef,
+ &aesviahash, &ndef_type, ndef, &zap,
&exit_code);
return rc;
char *salt = NULL;
char ndef[128];
char ndef_type = NULL;
+ bool zap = false;
char *argv[] = {
"unittest", "-1", "-sout", "-iin", "-c313233343536", "-y", "-v",
&autocommit, salt,
st, &verbose,
access_code, &use_access_code,
- &aesviahash, &ndef_type, ndef,
+ &aesviahash, &ndef_type, ndef, &zap,
&exit_code);
assert(rc == 1);
i = strcmp(infname, "in"); assert(i == 0);
" are set by default.\n"
"-x swap the configuration in slot 1 and 2. This is for YubiKey 2.3\n"
" and newer only\n"
+"-z delete the configuration in slot 1 or 2.\n"
"-sFILE save configuration to FILE instead of key.\n"
" (if FILE is -, send to stdout)\n"
"-iFILE read configuration from FILE.\n"
"-v verbose\n"
"-h help (this text)\n"
;
-const char *optstring = "u12xa:c:n:t:hi:o:s:vy";
+const char *optstring = "u12xza:c:n:t:hi:o:s:vy";
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);
bool *autocommit, char *salt,
YK_STATUS *st, bool *verbose,
unsigned char *access_code, bool *use_access_code,
- bool *aesviahash, char *ndef_type, char *ndef,
+ bool *aesviahash, char *ndef_type, char *ndef, bool *zap,
int *exit_code)
{
int c;
}
swap_seen = true;
break;
+ case 'z':
+ if (swap_seen) {
+ fprintf(stderr, "Swap (-x) and zap (-z) can't be combined.\n");
+ *exit_code = 1;
+ return 0;
+ }
+ if (update_seen) {
+ fprintf(stderr, "Update (-u) and zap (-z) can't be combined.\n");
+ *exit_code = 1;
+ return 0;
+ }
+ if (!slot_chosen) {
+ fprintf(stderr, "A slot must be chosen (-1 / -2) before adding zap (-z)\n");
+ *exit_code = 1;
+ return 0;
+ }
+ *zap = true;
+ break;
case 'i':
*infname = optarg;
break;
if(!*ndef_type) {
*ndef_type = 'U';
}
- if (slot_chosen || swap_seen || update_seen || option_seen) {
+ 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;
ndef_seen = true;
break;
case 'o':
+ if (*zap) {
+ fprintf(stderr, "No options can be given with zap (-z).\n");
+ *exit_code = 1;
+ return 0;
+ }
if (strncmp(optarg, "salt=", 5) == 0)
salt = strdup(optarg+5);
else if (strncmp(optarg, "fixed=", 6) == 0) {
bool *autocommit, char *salt,
YK_STATUS *st, bool *verbose,
unsigned char *access_code, bool *use_access_code,
- bool *aesviahash, char *ndef_type, char *ndef,
+ bool *aesviahash, char *ndef_type, char *ndef, bool *zap,
int *exit_code);
void report_yk_error(void);
char *salt = NULL;
char ndef_string[128] = {0};
char ndef_type;
+ bool zap = false;
bool error = false;
int exit_code = 0;
&autocommit, salt,
st, &verbose,
access_code, &use_access_code,
- &aesviahash, &ndef_type, ndef_string,
+ &aesviahash, &ndef_type, ndef_string, &zap,
&exit_code)) {
goto err;
}
if (inf) {
if (!ykp_read_config(cfg, reader, inf))
goto err;
- } else if (! aesviahash && (ykp_command(cfg) == SLOT_CONFIG || ykp_command(cfg) == SLOT_CONFIG2)) {
+ } else if (! aesviahash && ! zap && (ykp_command(cfg) == SLOT_CONFIG || ykp_command(cfg) == SLOT_CONFIG2)) {
char passphrasebuf[256]; size_t passphraselen;
fprintf(stderr, "Passphrase to create AES key: ");
fflush(stderr);
fprintf(stderr, "Configuration in slot 1 and 2 will be swapped\n");
} else if(ykp_command(cfg) == SLOT_NDEF) {
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));
} else {
if (ykp_command(cfg) == SLOT_CONFIG || ykp_command(cfg) == SLOT_CONFIG2) {
fprintf(stderr, "Configuration data to be written to key configuration %d:\n\n", ykp_config_num(cfg));
}
ykp_free_ndef(ndef);
} else {
+ YK_CONFIG *ycfg = NULL;
+ /* if we're deleting a slot we send the configuration as NULL */
+ if (!zap) {
+ ycfg = ykp_core_config(cfg);
+ }
if (!yk_write_command(yk,
- ykp_core_config(cfg), ykp_command(cfg),
+ ycfg, ykp_command(cfg),
use_access_code ? access_code : NULL)) {
if (verbose)
printf(" failure\n");