From: Tollef Fog Heen Date: Thu, 28 Jan 2010 22:43:09 +0000 (+0000) Subject: Stop bailing out on unknown firmwares X-Git-Tag: yubikey-personalisation_1.3.5-1~4^2~41 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89935580f4494864f95a01d7ddbdab40b6b4182d;p=yubikey-personalization.old Stop bailing out on unknown firmwares Previously, we would bail out if we saw an unsupported firmware. Stop doing that and instead write out a warning message saying not all features might be supported. --- diff --git a/configure.ac b/configure.ac index b20ae70..6d9df4d 100644 --- a/configure.ac +++ b/configure.ac @@ -36,9 +36,9 @@ AC_CONFIG_MACRO_DIR([m4]) # Interfaces changed/added/removed: CURRENT++ REVISION=0 # Interfaces added: AGE++ # Interfaces removed: AGE=0 -AC_SUBST(LT_CURRENT, 1) -AC_SUBST(LT_REVISION, 7) -AC_SUBST(LT_AGE, 0) +AC_SUBST(LT_CURRENT, 2) +AC_SUBST(LT_REVISION, 0) +AC_SUBST(LT_AGE, 1) AM_INIT_AUTOMAKE([-Wall -Werror]) AC_PROG_CC diff --git a/libykpers-1.map b/libykpers-1.map index f7c8443..2f07de5 100644 --- a/libykpers-1.map +++ b/libykpers-1.map @@ -29,6 +29,7 @@ LIBYKPERS_1.0 { global: # Functions: + yk_check_firmware_version; yk_close_key; yk_endian_swap_16; yk_force_key_update; diff --git a/ykcore/ykcore.c b/ykcore/ykcore.c index 1f61106..36ffe7d 100644 --- a/ykcore/ykcore.c +++ b/ykcore/ykcore.c @@ -62,19 +62,6 @@ YK_KEY *yk_open_first_key(void) rc = yk_errno; yk_close_key(yk); yk = NULL; - } else { - if (!((st.versionMajor == 1 && - (st.versionMinor == 0 || - st.versionMinor == 1 || - st.versionMinor == 2 || - st.versionMinor == 3)) || - (st.versionMajor == 2 && - (st.versionMinor == 0 || - st.versionMinor == 1)))) { - rc = YK_EFIRMWARE; - yk_close_key(yk); - yk = NULL; - } } } yk_errno = rc; @@ -86,6 +73,26 @@ int yk_close_key(YK_KEY *yk) return _ykusb_close_device(yk); } +int yk_check_firmware_version(YK_KEY *k) +{ + YK_STATUS st; + + if (!yk_get_status(k, &st)) + return 0; + if (!((st.versionMajor == 1 && + (st.versionMinor == 0 || + st.versionMinor == 1 || + st.versionMinor == 2 || + st.versionMinor == 3)) || + (st.versionMajor == 2 && + (st.versionMinor == 0 || + st.versionMinor == 1)))) { + yk_errno = YK_EFIRMWARE; + return 0; + } + return 1; +} + int yk_get_status(YK_KEY *k, YK_STATUS *status) { unsigned int status_count = 0; diff --git a/ykcore/ykcore.h b/ykcore/ykcore.h index 01f4fac..8468d86 100644 --- a/ykcore/ykcore.h +++ b/ykcore/ykcore.h @@ -81,6 +81,8 @@ extern int yk_close_key(YK_KEY *k); /* closes a previously opened key */ ****/ /* fetches key status into the structure given by `status' */ extern int yk_get_status(YK_KEY *k, YK_STATUS *status /*, int forceUpdate */); +/* checks that the firmware revision of the key is supported */ +extern int yk_check_firmware_version(YK_KEY *k); /************************************************************************* * diff --git a/ykpersonalize.c b/ykpersonalize.c index effd8d0..06cc097 100644 --- a/ykpersonalize.c +++ b/ykpersonalize.c @@ -217,6 +217,15 @@ int main(int argc, char **argv) else printf("Unconfigured\n"); + if (!(yk_check_firmware_version(yk))) { + if (yk_errno == YK_EFIRMWARE) { + printf("Unsupported firmware revision - some " + "features may not be available\n"); + } else { + goto err; + } + } + if (!ykp_configure_for(cfg, 1, st)) goto err;