fall back to ctap1 if the key claims to, but does not support ctap2

fixes gh#99
This commit is contained in:
pedro martelletto
2019-12-16 13:39:22 +01:00
parent 32f07254d7
commit ba94688308
3 changed files with 37 additions and 0 deletions

View File

@@ -145,6 +145,13 @@ fido_dev_open_rx(fido_dev_t *dev, int ms)
dev->cid = dev->attr.cid;
if (fido_dev_is_fido2(dev)) {
if (fido_dev_dummy_get_cbor_info_wait(dev, ms) != FIDO_OK) {
fido_log_debug("%s: falling back to u2f", __func__);
fido_dev_force_u2f(dev);
}
}
return (FIDO_OK);
fail:
dev->io.close(dev->io_handle);

View File

@@ -114,6 +114,7 @@ int u2f_authenticate(fido_dev_t *, fido_assert_t *, int);
/* unexposed fido ops */
int fido_dev_authkey(fido_dev_t *, es256_pk_t *);
int fido_dev_dummy_get_cbor_info_wait(fido_dev_t *, int);
int fido_dev_get_pin_token(fido_dev_t *, const char *, const fido_blob_t *,
const es256_pk_t *, fido_blob_t *);
int fido_do_ecdh(fido_dev_t *, es256_pk_t **, fido_blob_t **);

View File

@@ -278,6 +278,35 @@ fido_dev_get_cbor_info(fido_dev_t *dev, fido_cbor_info_t *ci)
return (fido_dev_get_cbor_info_wait(dev, ci, -1));
}
static int
fido_dev_dummy_get_cbor_info_rx(fido_dev_t *dev, int ms)
{
const uint8_t cmd = CTAP_FRAME_INIT | CTAP_CMD_CBOR;
unsigned char reply[512];
int reply_len;
fido_log_debug("%s: dev=%p, ms=%d", __func__, (void *)dev, ms);
if ((reply_len = fido_rx(dev, cmd, &reply, sizeof(reply), ms)) < 0) {
fido_log_debug("%s: fido_rx", __func__);
return (FIDO_ERR_RX);
}
return (FIDO_OK);
}
int
fido_dev_dummy_get_cbor_info_wait(fido_dev_t *dev, int ms)
{
int r;
if ((r = fido_dev_get_cbor_info_tx(dev)) != FIDO_OK ||
(r = fido_dev_dummy_get_cbor_info_rx(dev, ms)) != FIDO_OK)
return (r);
return (FIDO_OK);
}
/*
* get/set functions for fido_cbor_info_t; always at the end of the file
*/