From: Klas Lindfors Date: Wed, 25 Apr 2012 10:20:48 +0000 (+0200) Subject: convert the existing vcheck_ arguments to descriptive capabilities instead, prepare... X-Git-Tag: v1.7.0~1^2~32 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6169674e12f544347e8e5d965e16c1d585ec8a14;p=yubikey-personalization convert the existing vcheck_ arguments to descriptive capabilities instead, prepare for NEO --- diff --git a/ykpers.c b/ykpers.c index 92beb0c..2336da2 100644 --- a/ykpers.c +++ b/ykpers.c @@ -354,9 +354,79 @@ static bool vcheck_v23_or_greater(const YKP_CONFIG *cfg) cfg->yk_major_version > 2; } +static bool capability_has_hidtrig(const YKP_CONFIG *cfg) +{ + return vcheck_v1(cfg); +} + +static bool capability_has_ticket_first(const YKP_CONFIG *cfg) +{ + return vcheck_v1(cfg); +} + +static bool capability_has_static(const YKP_CONFIG *cfg) +{ + return vcheck_all(cfg); +} + +static bool capability_has_static_extras(const YKP_CONFIG *cfg) +{ + return vcheck_no_v1(cfg); +} + +static bool capability_has_slot_two(const YKP_CONFIG *cfg) +{ + return vcheck_no_v1(cfg); +} + +static bool capability_has_chal_resp(const YKP_CONFIG *cfg) +{ + return vcheck_v22_or_greater(cfg); +} + +static bool capability_has_oath_imf(const YKP_CONFIG *cfg) +{ + return vcheck_v22_or_greater(cfg); +} + +static bool capability_has_serial(const YKP_CONFIG *cfg) +{ + return vcheck_v22_or_greater(cfg); +} + +static bool capability_has_oath(const YKP_CONFIG *cfg) +{ + return vcheck_v21_or_greater(cfg); +} + +static bool capability_has_ticket_mods(const YKP_CONFIG *cfg) +{ + return vcheck_all(cfg); +} + +static bool capability_has_update(const YKP_CONFIG *cfg) +{ + return vcheck_v23_or_greater(cfg); +} + +static bool capability_has_fast(const YKP_CONFIG *cfg) +{ + return vcheck_v23_or_greater(cfg); +} + +static bool capability_has_numeric(const YKP_CONFIG *cfg) +{ + return vcheck_v23_or_greater(cfg); +} + +static bool capability_has_dormant(const YKP_CONFIG *cfg) +{ + return vcheck_v23_or_greater(cfg); +} + int ykp_set_oath_imf(YKP_CONFIG *cfg, unsigned long imf) { - if (!vcheck_v22_or_greater(cfg)) { + if (!capability_has_oath_imf(cfg)) { ykp_errno = YKP_EYUBIKEYVER; return 0; } @@ -377,7 +447,7 @@ int ykp_set_oath_imf(YKP_CONFIG *cfg, unsigned long imf) unsigned long ykp_get_oath_imf(const YKP_CONFIG *cfg) { - if (!vcheck_v22_or_greater(cfg)) { + if (!capability_has_oath_imf(cfg)) { return 0; } @@ -386,13 +456,13 @@ unsigned long ykp_get_oath_imf(const YKP_CONFIG *cfg) | cfg->ykcore_config.uid[5]) << 4; } -#define def_set_charfield(fnname,fieldname,size,extra,vcheck) \ +#define def_set_charfield(fnname,fieldname,size,extra,capability) \ int ykp_set_ ## fnname(YKP_CONFIG *cfg, unsigned char *input, size_t len) \ { \ if (cfg) { \ size_t max_chars = len; \ \ - if (!vcheck(cfg)) { \ + if (!capability(cfg)) { \ ykp_errno = YKP_EYUBIKEYVER; \ return 0; \ } \ @@ -414,11 +484,11 @@ def_set_charfield(access_code,accCode,ACC_CODE_SIZE,,vcheck_all) def_set_charfield(fixed,fixed,FIXED_SIZE,cfg->ykcore_config.fixedSize = max_chars,vcheck_all) def_set_charfield(uid,uid,UID_SIZE,,vcheck_all) -#define def_set_tktflag(type,vcheck) \ +#define def_set_tktflag(type,capability) \ int ykp_set_tktflag_ ## type(YKP_CONFIG *cfg, bool state) \ { \ if (cfg) { \ - if (!vcheck(cfg)) { \ + if (!capability(cfg)) { \ ykp_errno = YKP_EYUBIKEYVER; \ return 0; \ } \ @@ -432,11 +502,11 @@ int ykp_set_tktflag_ ## type(YKP_CONFIG *cfg, bool state) \ return 0; \ } -#define def_set_cfgflag(type,vcheck) \ -int ykp_set_cfgflag_ ## type(YKP_CONFIG *cfg, bool state) \ +#define def_set_cfgflag(type,capability) \ +int ykp_set_cfgflag_ ## type(YKP_CONFIG *cfg, bool state) \ { \ if (cfg) { \ - if (!vcheck(cfg)) { \ + if (!capability(cfg)) { \ ykp_errno = YKP_EYUBIKEYVER; \ return 0; \ } \ @@ -450,11 +520,11 @@ int ykp_set_cfgflag_ ## type(YKP_CONFIG *cfg, bool state) \ return 0; \ } -#define def_set_extflag(type,vcheck) \ -int ykp_set_extflag_ ## type(YKP_CONFIG *cfg, bool state) \ +#define def_set_extflag(type,capability) \ +int ykp_set_extflag_ ## type(YKP_CONFIG *cfg, bool state) \ { \ if (cfg) { \ - if (!vcheck(cfg)) { \ + if (!capability(cfg)) { \ ykp_errno = YKP_EYUBIKEYVER; \ return 0; \ } \ @@ -468,42 +538,42 @@ int ykp_set_extflag_ ## type(YKP_CONFIG *cfg, bool state) \ return 0; \ } -def_set_tktflag(TAB_FIRST,vcheck_all) -def_set_tktflag(APPEND_TAB1,vcheck_all) -def_set_tktflag(APPEND_TAB2,vcheck_all) -def_set_tktflag(APPEND_DELAY1,vcheck_all) -def_set_tktflag(APPEND_DELAY2,vcheck_all) -def_set_tktflag(APPEND_CR,vcheck_all) -def_set_tktflag(PROTECT_CFG2,vcheck_no_v1) -def_set_tktflag(OATH_HOTP,vcheck_v21_or_greater) -def_set_tktflag(CHAL_RESP,vcheck_v22_or_greater) - -def_set_cfgflag(SEND_REF,vcheck_all) -def_set_cfgflag(TICKET_FIRST,vcheck_v1) -def_set_cfgflag(PACING_10MS,vcheck_all) -def_set_cfgflag(PACING_20MS,vcheck_all) -def_set_cfgflag(ALLOW_HIDTRIG,vcheck_v1) -def_set_cfgflag(STATIC_TICKET,vcheck_all) -def_set_cfgflag(SHORT_TICKET,vcheck_no_v1) -def_set_cfgflag(STRONG_PW1,vcheck_no_v1) -def_set_cfgflag(STRONG_PW2,vcheck_no_v1) -def_set_cfgflag(MAN_UPDATE,vcheck_no_v1) -def_set_cfgflag(OATH_HOTP8,vcheck_v21_or_greater) -def_set_cfgflag(OATH_FIXED_MODHEX1,vcheck_v21_or_greater) -def_set_cfgflag(OATH_FIXED_MODHEX2,vcheck_v21_or_greater) -def_set_cfgflag(OATH_FIXED_MODHEX,vcheck_v21_or_greater) -def_set_cfgflag(CHAL_YUBICO,vcheck_v22_or_greater) -def_set_cfgflag(CHAL_HMAC,vcheck_v22_or_greater) -def_set_cfgflag(HMAC_LT64,vcheck_v22_or_greater) -def_set_cfgflag(CHAL_BTN_TRIG,vcheck_v22_or_greater) - -def_set_extflag(SERIAL_BTN_VISIBLE,vcheck_v22_or_greater) -def_set_extflag(SERIAL_USB_VISIBLE,vcheck_v22_or_greater) -def_set_extflag(SERIAL_API_VISIBLE,vcheck_v22_or_greater) -def_set_extflag(USE_NUMERIC_KEYPAD,vcheck_v23_or_greater) -def_set_extflag(FAST_TRIG,vcheck_v23_or_greater) -def_set_extflag(ALLOW_UPDATE,vcheck_v23_or_greater) -def_set_extflag(DORMANT,vcheck_v23_or_greater) +def_set_tktflag(TAB_FIRST,capability_has_ticket_mods) +def_set_tktflag(APPEND_TAB1,capability_has_ticket_mods) +def_set_tktflag(APPEND_TAB2,capability_has_ticket_mods) +def_set_tktflag(APPEND_DELAY1,capability_has_ticket_mods) +def_set_tktflag(APPEND_DELAY2,capability_has_ticket_mods) +def_set_tktflag(APPEND_CR,capability_has_ticket_mods) +def_set_tktflag(PROTECT_CFG2,capability_has_slot_two) +def_set_tktflag(OATH_HOTP,capability_has_oath) +def_set_tktflag(CHAL_RESP,capability_has_chal_resp) + +def_set_cfgflag(SEND_REF,capability_has_ticket_mods) +def_set_cfgflag(TICKET_FIRST,capability_has_ticket_first) +def_set_cfgflag(PACING_10MS,capability_has_ticket_mods) +def_set_cfgflag(PACING_20MS,capability_has_ticket_mods) +def_set_cfgflag(ALLOW_HIDTRIG,capability_has_hidtrig) +def_set_cfgflag(STATIC_TICKET,capability_has_static) +def_set_cfgflag(SHORT_TICKET,capability_has_static_extras) +def_set_cfgflag(STRONG_PW1,capability_has_static_extras) +def_set_cfgflag(STRONG_PW2,capability_has_static_extras) +def_set_cfgflag(MAN_UPDATE,capability_has_static_extras) +def_set_cfgflag(OATH_HOTP8,capability_has_oath) +def_set_cfgflag(OATH_FIXED_MODHEX1,capability_has_oath) +def_set_cfgflag(OATH_FIXED_MODHEX2,capability_has_oath) +def_set_cfgflag(OATH_FIXED_MODHEX,capability_has_oath) +def_set_cfgflag(CHAL_YUBICO,capability_has_chal_resp) +def_set_cfgflag(CHAL_HMAC,capability_has_chal_resp) +def_set_cfgflag(HMAC_LT64,capability_has_chal_resp) +def_set_cfgflag(CHAL_BTN_TRIG,capability_has_chal_resp) + +def_set_extflag(SERIAL_BTN_VISIBLE,capability_has_serial) +def_set_extflag(SERIAL_USB_VISIBLE,capability_has_serial) +def_set_extflag(SERIAL_API_VISIBLE,capability_has_serial) +def_set_extflag(USE_NUMERIC_KEYPAD,capability_has_numeric) +def_set_extflag(FAST_TRIG,capability_has_fast) +def_set_extflag(ALLOW_UPDATE,capability_has_update) +def_set_extflag(DORMANT,capability_has_dormant) const char str_key_value_separator[] = ": "; const char str_hex_prefix[] = "h:"; @@ -519,21 +589,21 @@ const char str_flags_separator[] = "|"; struct map_st { uint8_t flag; const char *flag_text; - bool (*vcheck)(const YKP_CONFIG *cfg); + bool (*capability)(const YKP_CONFIG *cfg); unsigned char tkt_context; }; const char str_ticket_flags[] = "ticket_flags"; struct map_st ticket_flags_map[] = { - { TKTFLAG_TAB_FIRST, "TAB_FIRST", vcheck_all, 0 }, - { TKTFLAG_APPEND_TAB1, "APPEND_TAB1", vcheck_all, 0 }, - { TKTFLAG_APPEND_TAB2, "APPEND_TAB2", vcheck_all, 0 }, - { TKTFLAG_APPEND_DELAY1, "APPEND_DELAY1", vcheck_all, 0 }, - { TKTFLAG_APPEND_DELAY2, "APPEND_DELAY2", vcheck_all, 0 }, - { TKTFLAG_APPEND_CR, "APPEND_CR", vcheck_all, 0 }, - { TKTFLAG_PROTECT_CFG2, "PROTECT_CFG2", vcheck_no_v1, 0 }, - { TKTFLAG_OATH_HOTP, "OATH_HOTP", vcheck_v21_or_greater, 0 }, - { TKTFLAG_CHAL_RESP, "CHAL_RESP", vcheck_v22_or_greater, 0 }, + { TKTFLAG_TAB_FIRST, "TAB_FIRST", capability_has_ticket_mods, 0 }, + { TKTFLAG_APPEND_TAB1, "APPEND_TAB1", capability_has_ticket_mods, 0 }, + { TKTFLAG_APPEND_TAB2, "APPEND_TAB2", capability_has_ticket_mods, 0 }, + { TKTFLAG_APPEND_DELAY1, "APPEND_DELAY1", capability_has_ticket_mods, 0 }, + { TKTFLAG_APPEND_DELAY2, "APPEND_DELAY2", capability_has_ticket_mods, 0 }, + { TKTFLAG_APPEND_CR, "APPEND_CR", capability_has_ticket_mods, 0 }, + { TKTFLAG_PROTECT_CFG2, "PROTECT_CFG2", capability_has_slot_two, 0 }, + { TKTFLAG_OATH_HOTP, "OATH_HOTP", capability_has_oath, 0 }, + { TKTFLAG_CHAL_RESP, "CHAL_RESP", capability_has_chal_resp, 0 }, { 0, "", 0 } }; @@ -550,36 +620,36 @@ struct map_st config_flags_map[] = { cfgFlag 0x40 as OATH_FIXED_MODHEX2 and not STRONG_PW2 if TKTFLAG_OATH_HOTP is set. */ - { CFGFLAG_CHAL_YUBICO, "CHAL_YUBICO", vcheck_v22_or_greater, TKTFLAG_CHAL_RESP }, - { CFGFLAG_CHAL_HMAC, "CHAL_HMAC", vcheck_v22_or_greater, TKTFLAG_CHAL_RESP }, - { CFGFLAG_HMAC_LT64, "HMAC_LT64", vcheck_v22_or_greater, TKTFLAG_CHAL_RESP }, - { CFGFLAG_CHAL_BTN_TRIG, "CHAL_BTN_TRIG", vcheck_v22_or_greater, TKTFLAG_CHAL_RESP }, - { CFGFLAG_OATH_HOTP8, "OATH_HOTP8", vcheck_v21_or_greater, TKTFLAG_OATH_HOTP }, - { CFGFLAG_OATH_FIXED_MODHEX1, "OATH_FIXED_MODHEX1", vcheck_v21_or_greater, TKTFLAG_OATH_HOTP }, - { CFGFLAG_OATH_FIXED_MODHEX2, "OATH_FIXED_MODHEX2", vcheck_v21_or_greater, TKTFLAG_OATH_HOTP }, - { CFGFLAG_OATH_FIXED_MODHEX, "OATH_FIXED_MODHEX", vcheck_v21_or_greater, TKTFLAG_OATH_HOTP }, - { CFGFLAG_SEND_REF, "SEND_REF", vcheck_all, 0 }, - { CFGFLAG_TICKET_FIRST, "TICKET_FIRST", vcheck_v1, 0 }, - { CFGFLAG_PACING_10MS, "PACING_10MS", vcheck_all, 0 }, - { CFGFLAG_PACING_20MS, "PACING_20MS", vcheck_all, 0 }, - { CFGFLAG_ALLOW_HIDTRIG, "ALLOW_HIDTRIG", vcheck_v1, 0 }, - { CFGFLAG_STATIC_TICKET, "STATIC_TICKET", vcheck_all, 0 }, - { CFGFLAG_SHORT_TICKET, "SHORT_TICKET", vcheck_no_v1, 0 }, - { CFGFLAG_STRONG_PW1, "STRONG_PW1", vcheck_no_v1, 0 }, - { CFGFLAG_STRONG_PW2, "STRONG_PW2", vcheck_no_v1, 0 }, - { CFGFLAG_MAN_UPDATE, "MAN_UPDATE", vcheck_no_v1, 0 }, + { CFGFLAG_CHAL_YUBICO, "CHAL_YUBICO", capability_has_chal_resp, TKTFLAG_CHAL_RESP }, + { CFGFLAG_CHAL_HMAC, "CHAL_HMAC", capability_has_chal_resp, TKTFLAG_CHAL_RESP }, + { CFGFLAG_HMAC_LT64, "HMAC_LT64", capability_has_chal_resp, TKTFLAG_CHAL_RESP }, + { CFGFLAG_CHAL_BTN_TRIG, "CHAL_BTN_TRIG", capability_has_chal_resp, TKTFLAG_CHAL_RESP }, + { CFGFLAG_OATH_HOTP8, "OATH_HOTP8", capability_has_oath, TKTFLAG_OATH_HOTP }, + { CFGFLAG_OATH_FIXED_MODHEX1, "OATH_FIXED_MODHEX1", capability_has_oath, TKTFLAG_OATH_HOTP }, + { CFGFLAG_OATH_FIXED_MODHEX2, "OATH_FIXED_MODHEX2", capability_has_oath, TKTFLAG_OATH_HOTP }, + { CFGFLAG_OATH_FIXED_MODHEX, "OATH_FIXED_MODHEX", capability_has_oath, TKTFLAG_OATH_HOTP }, + { CFGFLAG_SEND_REF, "SEND_REF", capability_has_ticket_mods, 0 }, + { CFGFLAG_TICKET_FIRST, "TICKET_FIRST", capability_has_ticket_first, 0 }, + { CFGFLAG_PACING_10MS, "PACING_10MS", capability_has_ticket_mods, 0 }, + { CFGFLAG_PACING_20MS, "PACING_20MS", capability_has_ticket_mods, 0 }, + { CFGFLAG_ALLOW_HIDTRIG, "ALLOW_HIDTRIG", capability_has_hidtrig, 0 }, + { CFGFLAG_STATIC_TICKET, "STATIC_TICKET", capability_has_static, 0 }, + { CFGFLAG_SHORT_TICKET, "SHORT_TICKET", capability_has_static_extras, 0 }, + { CFGFLAG_STRONG_PW1, "STRONG_PW1", capability_has_static_extras, 0 }, + { CFGFLAG_STRONG_PW2, "STRONG_PW2", capability_has_static_extras, 0 }, + { CFGFLAG_MAN_UPDATE, "MAN_UPDATE", capability_has_static_extras, 0 }, { 0, "" } }; const char str_extended_flags[] = "extended_flags"; struct map_st extended_flags_map[] = { - { EXTFLAG_SERIAL_BTN_VISIBLE, "SERIAL_BTN_VISIBLE", vcheck_v22_or_greater, 0 }, - { EXTFLAG_SERIAL_USB_VISIBLE, "SERIAL_USB_VISIBLE", vcheck_v22_or_greater, 0 }, - { EXTFLAG_SERIAL_API_VISIBLE, "SERIAL_API_VISIBLE", vcheck_v22_or_greater, 0 }, - { EXTFLAG_USE_NUMERIC_KEYPAD, "USE_NUMERIC_KEYPAD", vcheck_v23_or_greater, 0 }, - { EXTFLAG_FAST_TRIG, "FAST_TRIG", vcheck_v23_or_greater, 0 }, - { EXTFLAG_ALLOW_UPDATE, "ALLOW_UPDATE", vcheck_v23_or_greater, 0 }, - { EXTFLAG_DORMANT, "DORMANT", vcheck_v23_or_greater, 0 }, + { EXTFLAG_SERIAL_BTN_VISIBLE, "SERIAL_BTN_VISIBLE", capability_has_serial, 0 }, + { EXTFLAG_SERIAL_USB_VISIBLE, "SERIAL_USB_VISIBLE", capability_has_serial , 0 }, + { EXTFLAG_SERIAL_API_VISIBLE, "SERIAL_API_VISIBLE", capability_has_serial, 0 }, + { EXTFLAG_USE_NUMERIC_KEYPAD, "USE_NUMERIC_KEYPAD", capability_has_numeric, 0 }, + { EXTFLAG_FAST_TRIG, "FAST_TRIG", capability_has_fast, 0 }, + { EXTFLAG_ALLOW_UPDATE, "ALLOW_UPDATE", capability_has_update, 0 }, + { EXTFLAG_DORMANT, "DORMANT", capability_has_dormant, 0 }, { 0, "", 0 } }; @@ -657,7 +727,7 @@ int ykp_write_config(const YKP_CONFIG *cfg, /* OATH IMF: */ if ((cfg->ykcore_config.tktFlags & TKTFLAG_OATH_HOTP) == TKTFLAG_OATH_HOTP && - vcheck_v22_or_greater(cfg)) { + capability_has_oath_imf(cfg)) { writer(str_oath_imf, strlen(str_oath_imf), userdata); writer(str_key_value_separator, strlen(str_key_value_separator), @@ -674,7 +744,7 @@ int ykp_write_config(const YKP_CONFIG *cfg, buffer[0] = '\0'; for (p = ticket_flags_map; p->flag; p++) { if ((cfg->ykcore_config.tktFlags & p->flag) == p->flag - && p->vcheck(cfg)) { + && p->capability(cfg)) { if (*buffer) { strcat(buffer, str_flags_separator); strcat(buffer, p->flag_text); @@ -695,7 +765,7 @@ int ykp_write_config(const YKP_CONFIG *cfg, t_flags = cfg->ykcore_config.cfgFlags; for (p = config_flags_map; p->flag; p++) { if ((t_flags & p->flag) == p->flag - && p->vcheck(cfg) + && p->capability(cfg) && (cfg->ykcore_config.tktFlags & p->tkt_context) == p->tkt_context) { if (*buffer) { strcat(buffer, str_flags_separator); @@ -720,7 +790,7 @@ int ykp_write_config(const YKP_CONFIG *cfg, buffer[0] = '\0'; for (p = extended_flags_map; p->flag; p++) { if ((cfg->ykcore_config.extFlags & p->flag) == p->flag - && p->vcheck(cfg)) { + && p->capability(cfg)) { if (*buffer) { strcat(buffer, str_flags_separator); strcat(buffer, p->flag_text);