FIDO-Raw
view release on metacpan or search on metacpan
deps/libfido2/src/cred.c view on Meta::CPAN
#include <openssl/x509.h>
#include <string.h>
#include "fido.h"
#include "fido/es256.h"
static int
parse_makecred_reply(const cbor_item_t *key, const cbor_item_t *val, void *arg)
{
fido_cred_t *cred = arg;
if (cbor_isa_uint(key) == false ||
cbor_int_get_width(key) != CBOR_INT_8) {
fido_log_debug("%s: cbor type", __func__);
return (0); /* ignore */
}
switch (cbor_get_uint8(key)) {
case 1: /* fmt */
return (cbor_decode_fmt(val, &cred->fmt));
case 2: /* authdata */
return (cbor_decode_cred_authdata(val, cred->type,
&cred->authdata_cbor, &cred->authdata, &cred->attcred,
&cred->authdata_ext));
case 3: /* attestation statement */
return (cbor_decode_attstmt(val, &cred->attstmt));
default: /* ignore */
fido_log_debug("%s: cbor type", __func__);
return (0);
}
}
static int
fido_dev_make_cred_tx(fido_dev_t *dev, fido_cred_t *cred, const char *pin)
{
fido_blob_t f;
fido_blob_t *ecdh = NULL;
es256_pk_t *pk = NULL;
cbor_item_t *argv[9];
int r;
memset(&f, 0, sizeof(f));
memset(argv, 0, sizeof(argv));
if (cred->cdh.ptr == NULL || cred->type == 0) {
fido_log_debug("%s: cdh=%p, type=%d", __func__,
(void *)cred->cdh.ptr, cred->type);
r = FIDO_ERR_INVALID_ARGUMENT;
goto fail;
}
if ((argv[0] = fido_blob_encode(&cred->cdh)) == NULL ||
(argv[1] = cbor_encode_rp_entity(&cred->rp)) == NULL ||
(argv[2] = cbor_encode_user_entity(&cred->user)) == NULL ||
(argv[3] = cbor_encode_pubkey_param(cred->type)) == NULL) {
fido_log_debug("%s: cbor encode", __func__);
r = FIDO_ERR_INTERNAL;
goto fail;
}
/* excluded credentials */
if (cred->excl.len)
if ((argv[4] = cbor_encode_pubkey_list(&cred->excl)) == NULL) {
fido_log_debug("%s: cbor_encode_pubkey_list", __func__);
r = FIDO_ERR_INTERNAL;
goto fail;
}
/* extensions */
if (cred->ext.mask)
if ((argv[5] = cbor_encode_extensions(&cred->ext)) == NULL) {
fido_log_debug("%s: cbor_encode_extensions", __func__);
r = FIDO_ERR_INTERNAL;
goto fail;
}
/* options */
if (cred->rk != FIDO_OPT_OMIT || cred->uv != FIDO_OPT_OMIT)
if ((argv[6] = cbor_encode_options(cred->rk,
cred->uv)) == NULL) {
fido_log_debug("%s: cbor_encode_options", __func__);
r = FIDO_ERR_INTERNAL;
goto fail;
}
/* pin authentication */
if (pin) {
if ((r = fido_do_ecdh(dev, &pk, &ecdh)) != FIDO_OK) {
fido_log_debug("%s: fido_do_ecdh", __func__);
goto fail;
}
if ((r = cbor_add_pin_params(dev, &cred->cdh, pk, ecdh, pin,
&argv[7], &argv[8])) != FIDO_OK) {
fido_log_debug("%s: cbor_add_pin_params", __func__);
goto fail;
}
}
/* framing and transmission */
if (cbor_build_frame(CTAP_CBOR_MAKECRED, argv, nitems(argv), &f) < 0 ||
fido_tx(dev, CTAP_CMD_CBOR, f.ptr, f.len) < 0) {
fido_log_debug("%s: fido_tx", __func__);
r = FIDO_ERR_TX;
goto fail;
}
r = FIDO_OK;
fail:
es256_pk_free(&pk);
fido_blob_free(&ecdh);
cbor_vector_free(argv, nitems(argv));
free(f.ptr);
return (r);
}
static int
fido_dev_make_cred_rx(fido_dev_t *dev, fido_cred_t *cred, int ms)
{
unsigned char reply[FIDO_MAXMSG];
int reply_len;
( run in 0.787 second using v1.01-cache-2.11-cpan-0b5f733616e )