Skip to content

Commit

Permalink
credman: support non-preview command
Browse files Browse the repository at this point in the history
If credMgmt option ID is present in the authenticatorGetInfo response,
use the authenticatorCredentialManagement (0x0A) command instead of the
preview command (0x41).
  • Loading branch information
LDVG authored and kongeo committed Nov 27, 2023
1 parent da07482 commit 1b55726
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/credman.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ credman_prepare_hmac(uint8_t cmd, const void *body, cbor_item_t **param,
return (ok);
}

static uint8_t
credman_get_cmd(const fido_dev_t *dev)
{
if (dev->flags & FIDO_DEV_CREDMAN)
return (CTAP_CBOR_CRED_MGMT);

return (CTAP_CBOR_CRED_MGMT_PRE);
}

static int
credman_tx(fido_dev_t *dev, uint8_t subcmd, const void *param, const char *pin,
const char *rp_id, fido_opt_t uv, int *ms)
Expand All @@ -120,7 +129,7 @@ credman_tx(fido_dev_t *dev, uint8_t subcmd, const void *param, const char *pin,
fido_blob_t hmac;
es256_pk_t *pk = NULL;
cbor_item_t *argv[4];
const uint8_t cmd = CTAP_CBOR_CRED_MGMT_PRE;
const uint8_t cmd = credman_get_cmd(dev);
int r = FIDO_ERR_INTERNAL;

memset(&f, 0, sizeof(f));
Expand Down
8 changes: 5 additions & 3 deletions src/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ fido_dev_set_option_flags(fido_dev_t *dev, const fido_cbor_info_t *info)
if (strcmp(ptr[i], "clientPin") == 0) {
dev->flags |= val[i] ?
FIDO_DEV_PIN_SET : FIDO_DEV_PIN_UNSET;
} else if (strcmp(ptr[i], "credMgmt") == 0 ||
strcmp(ptr[i], "credentialMgmtPreview") == 0) {
} else if (strcmp(ptr[i], "credMgmt") == 0) {
if (val[i])
dev->flags |= FIDO_DEV_CREDMAN;
} else if (strcmp(ptr[i], "credentialMgmtPreview") == 0) {
if (val[i])
dev->flags |= FIDO_DEV_CREDMAN_PRE;
} else if (strcmp(ptr[i], "uv") == 0) {
dev->flags |= val[i] ?
FIDO_DEV_UV_SET : FIDO_DEV_UV_UNSET;
Expand Down Expand Up @@ -538,7 +540,7 @@ fido_dev_supports_cred_prot(const fido_dev_t *dev)
bool
fido_dev_supports_credman(const fido_dev_t *dev)
{
return (dev->flags & FIDO_DEV_CREDMAN);
return (dev->flags & (FIDO_DEV_CREDMAN|FIDO_DEV_CREDMAN_PRE));
}

bool
Expand Down
1 change: 1 addition & 0 deletions src/extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ uint32_t uniform_random(uint32_t);
#define FIDO_DEV_UV_UNSET 0x080
#define FIDO_DEV_TOKEN_PERMS 0x100
#define FIDO_DEV_WINHELLO 0x200
#define FIDO_DEV_CREDMAN_PRE 0x400

/* miscellanea */
#define FIDO_DUMMY_CLIENTDATA ""
Expand Down
1 change: 1 addition & 0 deletions src/fido/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#define CTAP_CBOR_CLIENT_PIN 0x06
#define CTAP_CBOR_RESET 0x07
#define CTAP_CBOR_NEXT_ASSERT 0x08
#define CTAP_CBOR_CRED_MGMT 0x0a
#define CTAP_CBOR_LARGEBLOB 0x0c
#define CTAP_CBOR_CONFIG 0x0d
#define CTAP_CBOR_BIO_ENROLL_PRE 0x40
Expand Down
1 change: 1 addition & 0 deletions src/pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ encode_uv_permission(uint8_t cmd)
case CTAP_CBOR_MAKECRED:
return (cbor_build_uint8(CTAP21_UV_TOKEN_PERM_MAKECRED));
case CTAP_CBOR_CRED_MGMT_PRE:
case CTAP_CBOR_CRED_MGMT:
return (cbor_build_uint8(CTAP21_UV_TOKEN_PERM_CRED_MGMT));
case CTAP_CBOR_LARGEBLOB:
return (cbor_build_uint8(CTAP21_UV_TOKEN_PERM_LARGEBLOB));
Expand Down

0 comments on commit 1b55726

Please sign in to comment.