ykp_set_device_mode;
ykp_set_device_chalresp_timeout;
ykp_set_device_autoeject_time;
+ yk_write_scan_map;
# Variables:
} LIBYKPERS_1.9;
unsigned char usb_mode = -1;
bool zap = false;
+ unsigned char scan_map[strlen(SCAN_MAP)];
+
int rc;
ykp_errno = 0;
st, &verbose,
access_code, &use_access_code,
&aesviahash, &ndef_type, ndef, &usb_mode, &zap,
- &exit_code);
+ scan_map, &exit_code);
return rc;
}
unsigned char usb_mode = -1;
bool zap = false;
+ unsigned char scan_map[strlen(SCAN_MAP)];
+
char *argv[] = {
"unittest", "-1", "-sout", "-iin", "-c313233343536", "-y", "-v",
NULL
st, &verbose,
access_code, &use_access_code,
&aesviahash, &ndef_type, ndef, &usb_mode, &zap,
- &exit_code);
+ scan_map, &exit_code);
assert(rc == 1);
i = strcmp(infname, "in"); assert(i == 0);
i = strcmp(outfname, "out"); assert(i == 0);
return _yk_write(yk, SLOT_DEVICE_CONFIG, buf, sizeof(YK_DEVICE_CONFIG));
}
+int yk_write_scan_map(YK_KEY *yk, unsigned char *scan_map)
+{
+ return _yk_write(yk, SLOT_SCAN_MAP, scan_map, strlen(SCAN_MAP));
+}
+
/*
* This function is for doing HMAC-SHA1 or Yubico challenge-response with a key.
*/
extern int yk_write_ndef2(YK_KEY *yk, YK_NDEF *ndef, int confnum);
/* writes a device config block to the key. */
extern int yk_write_device_config(YK_KEY *yk, YK_DEVICE_CONFIG *device_config);
+/* writes a scanmap to the key. */
+extern int yk_write_scan_map(YK_KEY *yk, unsigned char *scan_map);
/* Write something to the YubiKey (a command that is). */
extern int yk_write_to_key(YK_KEY *yk, uint8_t slot, const void *buf, int bufcount);
/* Do a challenge-response round with the key. */
" 1 CCID device only.\n"
" 2 HID/CCID composite device.\n"
" Add 80 to set MODE_FLAG_EJECT, for example: 81\n"
+"-S0605.. Set the scanmap to use with the YubiKey NEO. Must be 44 unique bytes,\n"
+" in hex. Use with no argument to reset to the default.\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"
"-v verbose\n"
"-h help (this text)\n"
;
-const char *optstring = "u12xza:c:n:t:hi:o:s:vym:";
+const char *optstring = "u12xza:c:n:t:hi:o:s: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);
bool *autocommit, char *salt,
YK_STATUS *st, bool *verbose,
unsigned char *access_code, bool *use_access_code,
- bool *aesviahash, char *ndef_type, char *ndef, unsigned char *usb_mode, bool *zap,
- int *exit_code)
+ bool *aesviahash, char *ndef_type, char *ndef,
+ unsigned char *usb_mode, bool *zap,
+ unsigned char *scan_bin, int *exit_code)
{
int c;
const char *aeshash = NULL;
bool update_seen = false;
bool ndef_seen = false;
bool usb_mode_seen = false;
+ bool scan_map_seen = false;
struct config_st *ycfg;
ykp_configure_version(cfg, st);
return 0;
break;
+ case 'S':
+ {
+ size_t scanlength = strlen(SCAN_MAP);
+ if(optarg) {
+ size_t scanbinlen;
+ size_t scanlen = strlen (optarg);
+ int rc = hex_modhex_decode(scan_bin, &scanbinlen,
+ optarg, scanlen,
+ scanlength * 2, scanlength * 2,
+ false);
+
+ if (rc <= 0) {
+ fprintf(stderr,
+ "Invalid scanmap string %s\n",
+ optarg);
+ *exit_code = 1;
+ return 0;
+ }
+ } else {
+ memset(scan_bin, 0, scanlength);
+ }
+ scan_map_seen = true;
+ }
+ if (!ykp_configure_command(cfg, SLOT_SCAN_MAP))
+ return 0;
+ break;
case 'o':
if (*zap) {
fprintf(stderr, "No options can be given with zap (-z).\n");
}
}
- if (!slot_chosen && !ndef_seen && !usb_mode_seen) {
+ if (!slot_chosen && !ndef_seen && !usb_mode_seen && !scan_map_seen) {
fprintf(stderr, "A slot must be chosen with -1 or -2.\n");
*exit_code = 1;
return 0;
YK_STATUS *st, bool *verbose,
unsigned char *access_code, bool *use_access_code,
bool *aesviahash, char *ndef_type, char *ndef, unsigned char *usb_mode,
- bool *zap, int *exit_code);
+ bool *zap, unsigned char *scan_bin, int *exit_code);
void report_yk_error(void);
return 0;
}
break;
- /* TODO: Make sure this is correct */
case SLOT_DEVICE_CONFIG:
- /* For testing only */
+ case SLOT_SCAN_MAP:
+ case SLOT_NDEF2:
if(!(cfg->yk_major_version >= 3)) {
ykp_errno = YKP_EYUBIKEYVER;
return 0;
}
break;
- case SLOT_NDEF2:
- if (!(cfg->yk_major_version == 3)) {
- ykp_errno = YKP_EYUBIKEYVER;
- return 0;
- }
case SLOT_NDEF:
/* NDEF is available for neo, thus within 2.1 from build 4 */
if (!((cfg->yk_major_version == 2 && cfg->yk_minor_version == 1 &&
bool aesviahash = false;
bool use_access_code = false;
unsigned char access_code[256];
+ unsigned char scan_codes[strlen(SCAN_MAP)];
YK_KEY *yk = 0;
YKP_CONFIG *cfg = ykp_alloc();
YK_STATUS *st = ykds_alloc();
&autocommit, salt,
st, &verbose,
access_code, &use_access_code,
- &aesviahash, &ndef_type, ndef_string,
- &usb_mode, &zap, &exit_code)) {
+ &aesviahash, &ndef_type, ndef_string,
+ &usb_mode, &zap, scan_codes, &exit_code)) {
goto err;
}
fprintf(stderr, "New NDEF will be written as:\n%s\n", ndef_string);
} else if(ykp_command(cfg) == SLOT_DEVICE_CONFIG) {
fprintf(stderr, "The USB mode will be set to: 0x%x\n", usb_mode);
+ } else if(ykp_command(cfg) == SLOT_SCAN_MAP) {
+ fprintf(stderr, "A new scanmap will be written.\n");
} else if(zap) {
fprintf(stderr, "Configuration in slot %d will be deleted\n", ykp_config_num(cfg));
} else {
goto err;
}
ykp_free_device_config(device_config);
+
+
+ } else if(ykp_command(cfg) == SLOT_SCAN_MAP) {
+ if(!yk_write_scan_map(yk, scan_codes)) {
+ if(verbose)
+ printf(" failure\n");
+ goto err;
+ }
} else {
YK_CONFIG *ycfg = NULL;
/* if we're deleting a slot we send the configuration as NULL */