ykp_set_extflag_ALLOW_UPDATE;
ykp_set_extflag_DORMANT;
yk_write_ndef;
- ykp_construct_ndef;
+ ykp_construct_ndef_uri;
+ ykp_construct_ndef_text;
# Variables:
} LIBYKPERS_1.6;
/* Options */
char *salt = NULL;
char *ndef = NULL;
+ char ndef_type;
int rc;
&autocommit, salt,
st, &verbose,
access_code, &use_access_code,
- &aesviahash, ndef,
+ &aesviahash, &ndef_type, ndef,
&exit_code);
return rc;
" char hex value (not modhex)\n"
"-cXXX.. A 12 char hex value (not modhex) to use as access code for programming\n"
" (this does NOT SET the access code, that's done with -oaccess=)\n"
-"-nXXX.. The URI to prepend to the OTP when sending OTP over NFC as ndef-type2\n"
-" smart-tag. Only available with the YubiKey NEO.\n"
+"-nXXX.. Write NDEF type 2 URI to YubiKey NEO, must be used on it's own\n"
+"-tXXX.. Write NDEF type 2 text to YubiKey NEO, must be used on it's own\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 = "u12xa:c:n:hi:o:s:vy";
+const char *optstring = "u12xa:c:n:t:hi:o:s:vy";
static const YK_CONFIG default_config1 = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* fixed */
bool *autocommit, char *salt,
YK_STATUS *st, bool *verbose,
unsigned char *access_code, bool *use_access_code,
- bool *aesviahash, char *ndef,
+ bool *aesviahash, char *ndef_type, char *ndef,
int *exit_code)
{
int c;
*use_access_code = true;
break;
}
+ case 't':
+ *ndef_type = 'T';
case 'n':
+ if(!*ndef_type) {
+ *ndef_type = 'U';
+ }
if (slot_chosen || swap_seen || update_seen || option_seen) {
- fprintf(stderr, "Ndef (-n) must be used on it's own.\n");
+ fprintf(stderr, "Ndef (-n/-t) must be used on it's own.\n");
*exit_code = 1;
return 0;
}
bool *autocommit, char *salt,
YK_STATUS *st, bool *verbose,
unsigned char *access_code, bool *use_access_code,
- bool *aesviahash, char *ndef,
+ bool *aesviahash, char *ndef_type, char *ndef,
int *exit_code);
void report_yk_error();
}
/* Fill in the data and len parts of the YKNDEF struct based on supplied uri. */
-int ykp_construct_ndef(YKNDEF *ndef, const char *uri)
+int ykp_construct_ndef_uri(YKNDEF *ndef, const char *uri)
{
int num_identifiers = sizeof(ndef_identifiers) / sizeof(char*);
int index = 0;
}
memcpy(ndef->data + 1, uri, data_length);
ndef->len = data_length + 1;
+ ndef->type = 'U';
+ return 0;
+}
+
+/* Fill in the data and len parts of the YKNDEF struct based on supplied text. */
+int ykp_construct_ndef_text(YKNDEF *ndef, const char *text)
+{
+ size_t data_length = strlen(text);
+ if(data_length > NDEF_DATA_SIZE) {
+ ykp_errno = YKP_EINVAL;
+ return 1;
+ }
+ memcpy(ndef->data, text, data_length);
+ ndef->len = data_length;
+ ndef->type = 'T';
return 0;
}
static bool vcheck_neo_before_5(const YKP_CONFIG *cfg)
{
- return vcheck_neo && cfg->yk_build_version < 5;
+ return vcheck_neo(cfg) && cfg->yk_build_version < 5;
}
static bool capability_has_hidtrig(const YKP_CONFIG *cfg)
#include <stddef.h>
#include <stdbool.h>
#include <ykstatus.h>
+#include <ykdef.h>
# ifdef __cplusplus
extern "C" {
const char *salt);
int ykp_HMAC_key_from_hex(YKP_CONFIG *cfg, const char *hexkey);
+/* Functions for constructing the YKNDEF struct before writing it to a neo */
+int ykp_construct_ndef_uri(YKNDEF *ndef, const char *uri);
+int ykp_construct_ndef_text(YKNDEF *ndef, const char *text);
+
int ykp_set_access_code(YKP_CONFIG *cfg, unsigned char *access_code, size_t len);
int ykp_set_fixed(YKP_CONFIG *cfg, unsigned char *fixed, size_t len);
int ykp_set_uid(YKP_CONFIG *cfg, unsigned char *uid, size_t len);
/* Options */
char *salt = NULL;
- char ndef_uri[128];
+ char ndef_string[128];
+ char ndef_type;
bool error = false;
int exit_code = 0;
&autocommit, salt,
st, &verbose,
access_code, &use_access_code,
- &aesviahash, ndef_uri,
+ &aesviahash, &ndef_type, ndef_string,
&exit_code)) {
goto err;
}
if(ykp_command(cfg) == SLOT_NDEF) {
YKNDEF ndef;
memset(&ndef, 0, sizeof(YKNDEF));
- ykp_construct_ndef(&ndef, ndef_uri);
+ if(ndef_type == 'U') {
+ ykp_construct_ndef_uri(&ndef, ndef_string);
+ } else if(ndef_type == 'T') {
+ ykp_construct_ndef_text(&ndef, ndef_string);
+ }
if(use_access_code) {
memcpy(ndef.curAccCode, access_code, ACC_CODE_SIZE);
}
- ndef.type = 'U';
if (!yk_write_ndef(yk, &ndef)) {
if (verbose)
printf(" failure\n");