2 * Copyright (c) 2018-2022 Yubico AB. All rights reserved.
3 * Use of this source code is governed by a BSD-style
4 * license that can be found in the LICENSE file.
5 * SPDX-License-Identifier: BSD-2-Clause
11 parse_authkey(const cbor_item_t *key, const cbor_item_t *val, void *arg)
13 es256_pk_t *authkey = arg;
15 if (cbor_isa_uint(key) == false ||
16 cbor_int_get_width(key) != CBOR_INT_8 ||
17 cbor_get_uint8(key) != 1) {
18 fido_log_debug("%s: cbor type", __func__);
19 return (0); /* ignore */
22 return (es256_pk_decode(val, authkey));
26 fido_dev_authkey_tx(fido_dev_t *dev, int *ms)
32 fido_log_debug("%s: dev=%p", __func__, (void *)dev);
34 memset(&f, 0, sizeof(f));
35 memset(argv, 0, sizeof(argv));
37 /* add command parameters */
38 if ((argv[0] = cbor_encode_pin_opt(dev)) == NULL ||
39 (argv[1] = cbor_build_uint8(2)) == NULL) {
40 fido_log_debug("%s: cbor_build", __func__);
41 r = FIDO_ERR_INTERNAL;
45 /* frame and transmit */
46 if (cbor_build_frame(CTAP_CBOR_CLIENT_PIN, argv, nitems(argv),
47 &f) < 0 || fido_tx(dev, CTAP_CMD_CBOR, f.ptr, f.len, ms) < 0) {
48 fido_log_debug("%s: fido_tx", __func__);
55 cbor_vector_free(argv, nitems(argv));
62 fido_dev_authkey_rx(fido_dev_t *dev, es256_pk_t *authkey, int *ms)
68 fido_log_debug("%s: dev=%p, authkey=%p, ms=%d", __func__, (void *)dev,
69 (void *)authkey, *ms);
71 memset(authkey, 0, sizeof(*authkey));
73 if ((msg = malloc(FIDO_MAXMSG)) == NULL) {
74 r = FIDO_ERR_INTERNAL;
78 if ((msglen = fido_rx(dev, CTAP_CMD_CBOR, msg, FIDO_MAXMSG, ms)) < 0) {
79 fido_log_debug("%s: fido_rx", __func__);
84 r = cbor_parse_reply(msg, (size_t)msglen, authkey, parse_authkey);
86 freezero(msg, FIDO_MAXMSG);
92 fido_dev_authkey_wait(fido_dev_t *dev, es256_pk_t *authkey, int *ms)
96 if ((r = fido_dev_authkey_tx(dev, ms)) != FIDO_OK ||
97 (r = fido_dev_authkey_rx(dev, authkey, ms)) != FIDO_OK)
104 fido_dev_authkey(fido_dev_t *dev, es256_pk_t *authkey, int *ms)
106 return (fido_dev_authkey_wait(dev, authkey, ms));