diff options
author | djm@openbsd.org <djm@openbsd.org> | 2021-12-02 22:40:05 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2021-12-03 10:27:40 +1100 |
commit | ca709e27c41c90f4565b17282c48dca7756e083c (patch) | |
tree | 245e2d75a87494097ddb202180856c829952e1f0 /sk-usbhid.c | |
parent | b711bc01a7ec76bb6a285730990cbce9b8ca5773 (diff) |
upstream: move check_sk_options() up so we can use it earlier
OpenBSD-Commit-ID: 67fe98ba1c846d22035279782c4664c1865763b4
Diffstat (limited to 'sk-usbhid.c')
-rw-r--r-- | sk-usbhid.c | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/sk-usbhid.c b/sk-usbhid.c index bfa1d1ed..89196c8b 100644 --- a/sk-usbhid.c +++ b/sk-usbhid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sk-usbhid.c,v 1.34 2021/11/03 22:00:56 deraadt Exp $ */ +/* $OpenBSD: sk-usbhid.c,v 1.35 2021/12/02 22:40:05 djm Exp $ */ /* * Copyright (c) 2019 Markus Friedl * Copyright (c) 2020 Pedro Martelletto @@ -386,6 +386,48 @@ sk_try(const struct sk_usbhid *sk, const char *application, return r != FIDO_OK ? -1 : 0; } +static int +check_sk_options(fido_dev_t *dev, const char *opt, int *ret) +{ + fido_cbor_info_t *info; + char * const *name; + const bool *value; + size_t len, i; + int r; + + *ret = -1; + + if (!fido_dev_is_fido2(dev)) { + skdebug(__func__, "device is not fido2"); + return 0; + } + if ((info = fido_cbor_info_new()) == NULL) { + skdebug(__func__, "fido_cbor_info_new failed"); + return -1; + } + if ((r = fido_dev_get_cbor_info(dev, info)) != FIDO_OK) { + skdebug(__func__, "fido_dev_get_cbor_info: %s", fido_strerr(r)); + fido_cbor_info_free(&info); + return -1; + } + name = fido_cbor_info_options_name_ptr(info); + value = fido_cbor_info_options_value_ptr(info); + len = fido_cbor_info_options_len(info); + for (i = 0; i < len; i++) { + if (!strcmp(name[i], opt)) { + *ret = value[i]; + break; + } + } + fido_cbor_info_free(&info); + if (*ret == -1) + skdebug(__func__, "option %s is unknown", opt); + else + skdebug(__func__, "option %s is %s", opt, *ret ? "on" : "off"); + + return 0; +} + static struct sk_usbhid * sk_select_by_cred(const fido_dev_info_t *devlist, size_t ndevs, const char *application, const uint8_t *key_handle, size_t key_handle_len) @@ -504,48 +546,6 @@ sk_probe(const char *application, const uint8_t *key_handle, return sk; } -static int -check_sk_options(fido_dev_t *dev, const char *opt, int *ret) -{ - fido_cbor_info_t *info; - char * const *name; - const bool *value; - size_t len, i; - int r; - - *ret = -1; - - if (!fido_dev_is_fido2(dev)) { - skdebug(__func__, "device is not fido2"); - return 0; - } - if ((info = fido_cbor_info_new()) == NULL) { - skdebug(__func__, "fido_cbor_info_new failed"); - return -1; - } - if ((r = fido_dev_get_cbor_info(dev, info)) != FIDO_OK) { - skdebug(__func__, "fido_dev_get_cbor_info: %s", fido_strerr(r)); - fido_cbor_info_free(&info); - return -1; - } - name = fido_cbor_info_options_name_ptr(info); - value = fido_cbor_info_options_value_ptr(info); - len = fido_cbor_info_options_len(info); - for (i = 0; i < len; i++) { - if (!strcmp(name[i], opt)) { - *ret = value[i]; - break; - } - } - fido_cbor_info_free(&info); - if (*ret == -1) - skdebug(__func__, "option %s is unknown", opt); - else - skdebug(__func__, "option %s is %s", opt, *ret ? "on" : "off"); - - return 0; -} - #ifdef WITH_OPENSSL /* * The key returned via fido_cred_pubkey_ptr() is in affine coordinates, |