From b26204092bfb26e9bdeb8f94bb4002c86369846f Mon Sep 17 00:00:00 2001 From: Klas Lindfors Date: Fri, 9 Nov 2012 15:47:13 +0100 Subject: [PATCH] add yk_check_firmware2() that takes status instead of key and let yk_check_firmware() call that for testability --- libykpers-1.map | 1 + ykcore/ykcore.c | 37 ++++++++++++++++++++++--------------- ykcore/ykcore.h | 1 + ykpersonalize.c | 2 +- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/libykpers-1.map b/libykpers-1.map index 0ea98e6..91971a3 100644 --- a/libykpers-1.map +++ b/libykpers-1.map @@ -167,5 +167,6 @@ LIBYKPERS_1.10 { # Functions: yk_write_ndef2; ykp_ndef_as_text; + yk_check_firmware_version2; # Variables: } LIBYKPERS_1.9; diff --git a/ykcore/ykcore.c b/ykcore/ykcore.c index 055af0d..f3985d2 100644 --- a/ykcore/ykcore.c +++ b/ykcore/ykcore.c @@ -92,21 +92,28 @@ int yk_check_firmware_version(YK_KEY *k) if (!yk_get_status(k, &st)) return 0; - if (!((st.versionMajor == 0 && - (st.versionMinor == 9 || - st.versionBuild == 9)) || - (st.versionMajor == 1 && - (st.versionMinor == 0 || - st.versionMinor == 1 || - st.versionMinor == 2 || - st.versionMinor == 3)) || - (st.versionMajor == 2 && - (st.versionMinor == 0 || - st.versionMinor == 1 || - st.versionMinor == 2 || - st.versionMinor == 3)) || - (st.versionMajor == 3 && - (st.versionMinor == 0)))) { + + return yk_check_firmware_version2(&st); +} + + +int yk_check_firmware_version2(YK_STATUS *st) +{ + if (!((st->versionMajor == 0 && + (st->versionMinor == 9 || + st->versionBuild == 9)) || + (st->versionMajor == 1 && + (st->versionMinor == 0 || + st->versionMinor == 1 || + st->versionMinor == 2 || + st->versionMinor == 3)) || + (st->versionMajor == 2 && + (st->versionMinor == 0 || + st->versionMinor == 1 || + st->versionMinor == 2 || + st->versionMinor == 3)) || + (st->versionMajor == 3 && + (st->versionMinor == 0)))) { yk_errno = YK_EFIRMWARE; return 0; } diff --git a/ykcore/ykcore.h b/ykcore/ykcore.h index 216a475..ca70e6f 100644 --- a/ykcore/ykcore.h +++ b/ykcore/ykcore.h @@ -89,6 +89,7 @@ extern int yk_close_key(YK_KEY *k); /* closes a previously opened key */ 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); +extern int yk_check_firmware_version2(YK_STATUS *status); /* Read the factory set serial number from a YubiKey 2.0 or higher. */ extern int yk_get_serial(YK_KEY *yk, uint8_t slot, unsigned int flags, unsigned int *serial); /* Wait for the key to either set or clear bits in it's status byte */ diff --git a/ykpersonalize.c b/ykpersonalize.c index ea8a748..1b39839 100644 --- a/ykpersonalize.c +++ b/ykpersonalize.c @@ -109,7 +109,7 @@ int main(int argc, char **argv) else printf("Unconfigured\n"); - if (!(yk_check_firmware_version(yk))) { + if (!(yk_check_firmware_version2(st))) { if (yk_errno == YK_EFIRMWARE) { printf("Unsupported firmware revision - some " "features may not be available\n" -- 2.39.5