From 75073d0a8478441cc97a6efa10b566c5fb1dac81 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Fri, 17 Apr 2020 20:57:17 +0100 Subject: New upstream version 1.4.0 --- examples/CMakeLists.txt | 2 +- examples/cred.c | 40 +++++++++++++++++++++++++++++++++------- examples/info.c | 12 ++++++++++++ 3 files changed, 46 insertions(+), 8 deletions(-) (limited to 'examples') diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 957311e..1203592 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -8,7 +8,7 @@ list(APPEND COMPAT_SOURCES ../openbsd-compat/strlcpy.c ) -if(WIN32) +if(WIN32 AND NOT CYGWIN AND NOT MSYS) list(APPEND COMPAT_SOURCES ../openbsd-compat/posix_win.c) endif() diff --git a/examples/cred.c b/examples/cred.c index e471f7e..3e0a30f 100644 --- a/examples/cred.c +++ b/examples/cred.c @@ -139,6 +139,27 @@ verify_cred(int type, const char *fmt, const unsigned char *authdata_ptr, fido_cred_free(&cred); } +static fido_dev_t * +open_from_manifest(const fido_dev_info_t *dev_infos, size_t len, + const char *path) +{ + size_t i; + fido_dev_t *dev; + + for (i = 0; i < len; i++) { + const fido_dev_info_t *curr = fido_dev_info_ptr(dev_infos, i); + if (path == NULL || + strcmp(path, fido_dev_info_path(curr)) == 0) { + dev = fido_dev_new_with_info(curr); + if (fido_dev_open_with_info(dev) == FIDO_OK) + return (dev); + fido_dev_free(&dev); + } + } + + return (NULL); +} + int main(int argc, char **argv) { @@ -150,6 +171,7 @@ main(int argc, char **argv) const char *pin = NULL; const char *key_out = NULL; const char *id_out = NULL; + const char *path = NULL; unsigned char *body = NULL; long long seconds = 0; size_t len; @@ -157,6 +179,8 @@ main(int argc, char **argv) int ext = 0; int ch; int r; + fido_dev_info_t *dev_infos = NULL; + size_t dev_infos_len = 0; if ((cred = fido_cred_new()) == NULL) errx(1, "fido_cred_new"); @@ -218,19 +242,21 @@ main(int argc, char **argv) } } + fido_init(0); + argc -= optind; argv += optind; - if (argc != 1) + if (argc > 1) usage(); + dev_infos = fido_dev_info_new(16); + fido_dev_info_manifest(dev_infos, 16, &dev_infos_len); + if (argc == 1) + path = argv[0]; - fido_init(0); - - if ((dev = fido_dev_new()) == NULL) - errx(1, "fido_dev_new"); + if ((dev = open_from_manifest(dev_infos, dev_infos_len, path)) == NULL) + errx(1, "open_from_manifest"); - if ((r = fido_dev_open(dev, argv[0])) != FIDO_OK) - errx(1, "fido_dev_open: %s (0x%x)", fido_strerr(r), r); if (u2f) fido_dev_force_u2f(dev); diff --git a/examples/info.c b/examples/info.c index e79729c..ef0d97e 100644 --- a/examples/info.c +++ b/examples/info.c @@ -130,6 +130,15 @@ print_maxmsgsiz(uint64_t maxmsgsiz) printf("maxmsgsiz: %d\n", (int)maxmsgsiz); } +/* + * Auxiliary function to print an authenticator's firmware version on stdout. + */ +static void +print_fwversion(uint64_t fwversion) +{ + printf("fwversion: 0x%x\n", (int)fwversion); +} + /* * Auxiliary function to print an array of bytes on stdout. */ @@ -190,6 +199,9 @@ getinfo(const char *path) /* print maximum message size */ print_maxmsgsiz(fido_cbor_info_maxmsgsiz(ci)); + /* print firmware version */ + print_fwversion(fido_cbor_info_fwversion(ci)); + /* print supported pin protocols */ print_byte_array("pin protocols", fido_cbor_info_protocols_ptr(ci), fido_cbor_info_protocols_len(ci)); -- cgit v1.2.3