2 * Copyright (c) 2018 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.
10 parse_authkey(const cbor_item_t *key, const cbor_item_t *val, void *arg)
12 es256_pk_t *authkey = arg;
14 if (cbor_isa_uint(key) == false ||
15 cbor_int_get_width(key) != CBOR_INT_8 ||
16 cbor_get_uint8(key) != 1) {
17 fido_log_debug("%s: cbor type", __func__);
18 return (0); /* ignore */
21 return (es256_pk_decode(val, authkey));
25 fido_dev_authkey_tx(fido_dev_t *dev)
31 fido_log_debug("%s: dev=%p", __func__, (void *)dev);
33 memset(&f, 0, sizeof(f));
34 memset(argv, 0, sizeof(argv));
36 /* add command parameters */
37 if ((argv[0] = cbor_encode_pin_opt(dev)) == NULL ||
38 (argv[1] = cbor_build_uint8(2)) == NULL) {
39 fido_log_debug("%s: cbor_build", __func__);
40 r = FIDO_ERR_INTERNAL;
44 /* frame and transmit */
45 if (cbor_build_frame(CTAP_CBOR_CLIENT_PIN, argv, nitems(argv),
46 &f) < 0 || fido_tx(dev, CTAP_CMD_CBOR, f.ptr, f.len) < 0) {
47 fido_log_debug("%s: fido_tx", __func__);
54 cbor_vector_free(argv, nitems(argv));
61 fido_dev_authkey_rx(fido_dev_t *dev, es256_pk_t *authkey, int ms)
63 unsigned char reply[FIDO_MAXMSG];
66 fido_log_debug("%s: dev=%p, authkey=%p, ms=%d", __func__, (void *)dev,
69 memset(authkey, 0, sizeof(*authkey));
71 if ((reply_len = fido_rx(dev, CTAP_CMD_CBOR, &reply, sizeof(reply),
73 fido_log_debug("%s: fido_rx", __func__);
77 return (cbor_parse_reply(reply, (size_t)reply_len, authkey,
82 fido_dev_authkey_wait(fido_dev_t *dev, es256_pk_t *authkey, int ms)
86 if ((r = fido_dev_authkey_tx(dev)) != FIDO_OK ||
87 (r = fido_dev_authkey_rx(dev, authkey, ms)) != FIDO_OK)
94 fido_dev_authkey(fido_dev_t *dev, es256_pk_t *authkey)
96 return (fido_dev_authkey_wait(dev, authkey, -1));