2 * Copyright (c) 2021 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.
17 #define MAXMSEC 6000 * 1000
18 #define VENDORID 0x045e
21 struct winhello_assert {
22 WEBAUTHN_CLIENT_DATA cd;
23 WEBAUTHN_AUTHENTICATOR_GET_ASSERTION_OPTIONS opt;
24 WEBAUTHN_ASSERTION *assert;
28 struct winhello_cred {
29 WEBAUTHN_RP_ENTITY_INFORMATION rp;
30 WEBAUTHN_USER_ENTITY_INFORMATION user;
31 WEBAUTHN_COSE_CREDENTIAL_PARAMETER alg;
32 WEBAUTHN_COSE_CREDENTIAL_PARAMETERS cose;
33 WEBAUTHN_CLIENT_DATA cd;
34 WEBAUTHN_AUTHENTICATOR_MAKE_CREDENTIAL_OPTIONS opt;
35 WEBAUTHN_CREDENTIAL_ATTESTATION *att;
40 wchar_t *display_name;
44 to_utf16(const char *utf8)
50 fido_log_debug("%s: NULL", __func__);
53 if ((nch = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0)) < 1 ||
54 (size_t)nch > MAXCHARS) {
55 fido_log_debug("%s: MultiByteToWideChar %d", __func__, nch);
58 if ((utf16 = calloc((size_t)nch, sizeof(*utf16))) == NULL) {
59 fido_log_debug("%s: calloc", __func__);
62 if (MultiByteToWideChar(CP_UTF8, 0, utf8, -1, utf16, nch) != nch) {
63 fido_log_debug("%s: MultiByteToWideChar", __func__);
72 to_utf8(const wchar_t *utf16)
78 fido_log_debug("%s: NULL", __func__);
81 if ((nch = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, utf16,
82 -1, NULL, 0, NULL, NULL)) < 1 || (size_t)nch > MAXCHARS) {
83 fido_log_debug("%s: WideCharToMultiByte %d", __func__);
86 if ((utf8 = calloc((size_t)nch, sizeof(*utf8))) == NULL) {
87 fido_log_debug("%s: calloc", __func__);
90 if (WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, utf16, -1,
91 utf8, nch, NULL, NULL) != nch) {
92 fido_log_debug("%s: WideCharToMultiByte", __func__);
101 to_fido_str_array(fido_str_array_t *sa, const char **v, size_t n)
103 if ((sa->ptr = calloc(n, sizeof(char *))) == NULL) {
104 fido_log_debug("%s: calloc", __func__);
107 for (size_t i = 0; i < n; i++) {
108 if ((sa->ptr[i] = strdup(v[i])) == NULL) {
109 fido_log_debug("%s: strdup", __func__);
122 case NTE_NOT_SUPPORTED:
123 return FIDO_ERR_UNSUPPORTED_OPTION;
124 case NTE_INVALID_PARAMETER:
125 return FIDO_ERR_INVALID_PARAMETER;
126 case NTE_TOKEN_KEYSET_STORAGE_FULL:
127 return FIDO_ERR_KEY_STORE_FULL;
128 case NTE_DEVICE_NOT_FOUND:
130 return FIDO_ERR_NOT_ALLOWED;
132 fido_log_debug("%s: hr=0x%x", __func__, hr);
133 return FIDO_ERR_INTERNAL;
138 pack_cd(WEBAUTHN_CLIENT_DATA *out, const fido_blob_t *in)
140 if (in->ptr == NULL) {
141 fido_log_debug("%s: NULL", __func__);
144 if (in->len > ULONG_MAX) {
145 fido_log_debug("%s: in->len=%zu", __func__, in->len);
148 out->dwVersion = WEBAUTHN_CLIENT_DATA_CURRENT_VERSION;
149 out->cbClientDataJSON = (DWORD)in->len;
150 out->pbClientDataJSON = in->ptr;
151 out->pwszHashAlgId = WEBAUTHN_HASH_ALGORITHM_SHA_256;
157 pack_credlist(WEBAUTHN_CREDENTIALS *out, const fido_blob_array_t *in)
159 WEBAUTHN_CREDENTIAL *c;
162 return 0; /* nothing to do */
164 if (in->len > MAXCREDS) {
165 fido_log_debug("%s: in->len=%zu", __func__, in->len);
168 if ((out->pCredentials = calloc(in->len, sizeof(*c))) == NULL) {
169 fido_log_debug("%s: calloc", __func__);
172 out->cCredentials = (DWORD)in->len;
173 for (size_t i = 0; i < in->len; i++) {
174 if (in->ptr[i].len > ULONG_MAX) {
175 fido_log_debug("%s: %zu", __func__, in->ptr[i].len);
178 c = &out->pCredentials[i];
179 c->dwVersion = WEBAUTHN_CREDENTIAL_CURRENT_VERSION;
180 c->cbId = (DWORD)in->ptr[i].len;
181 c->pbId = in->ptr[i].ptr;
182 c->pwszCredentialType = WEBAUTHN_CREDENTIAL_TYPE_PUBLIC_KEY;
189 set_uv(DWORD *out, fido_opt_t uv, const char *pin)
192 *out = WEBAUTHN_USER_VERIFICATION_REQUIREMENT_REQUIRED;
198 *out = WEBAUTHN_USER_VERIFICATION_REQUIREMENT_ANY;
201 *out = WEBAUTHN_USER_VERIFICATION_REQUIREMENT_DISCOURAGED;
204 *out = WEBAUTHN_USER_VERIFICATION_REQUIREMENT_REQUIRED;
212 pack_rp(wchar_t **id, wchar_t **name, WEBAUTHN_RP_ENTITY_INFORMATION *out,
215 /* keep non-const copies of pwsz* for free() */
216 out->dwVersion = WEBAUTHN_RP_ENTITY_INFORMATION_CURRENT_VERSION;
217 if ((out->pwszId = *id = to_utf16(in->id)) == NULL) {
218 fido_log_debug("%s: id", __func__);
221 if (in->name && (out->pwszName = *name = to_utf16(in->name)) == NULL) {
222 fido_log_debug("%s: name", __func__);
229 pack_user(wchar_t **name, wchar_t **icon, wchar_t **display_name,
230 WEBAUTHN_USER_ENTITY_INFORMATION *out, fido_user_t *in)
232 if (in->id.ptr == NULL || in->id.len > ULONG_MAX) {
233 fido_log_debug("%s: id", __func__);
236 out->dwVersion = WEBAUTHN_USER_ENTITY_INFORMATION_CURRENT_VERSION;
237 out->cbId = (DWORD)in->id.len;
238 out->pbId = in->id.ptr;
239 /* keep non-const copies of pwsz* for free() */
240 if (in->name != NULL) {
241 if ((out->pwszName = *name = to_utf16(in->name)) == NULL) {
242 fido_log_debug("%s: name", __func__);
246 if (in->icon != NULL) {
247 if ((out->pwszIcon = *icon = to_utf16(in->icon)) == NULL) {
248 fido_log_debug("%s: icon", __func__);
252 if (in->display_name != NULL) {
253 if ((out->pwszDisplayName = *display_name =
254 to_utf16(in->display_name)) == NULL) {
255 fido_log_debug("%s: display_name", __func__);
264 pack_cose(WEBAUTHN_COSE_CREDENTIAL_PARAMETER *alg,
265 WEBAUTHN_COSE_CREDENTIAL_PARAMETERS *cose, int type)
269 alg->lAlg = WEBAUTHN_COSE_ALGORITHM_ECDSA_P256_WITH_SHA256;
272 alg->lAlg = -8; /* XXX */;
275 alg->lAlg = WEBAUTHN_COSE_ALGORITHM_RSASSA_PKCS1_V1_5_WITH_SHA256;
278 fido_log_debug("%s: type %d", __func__, type);
281 alg->dwVersion = WEBAUTHN_COSE_CREDENTIAL_PARAMETER_CURRENT_VERSION;
282 alg->pwszCredentialType = WEBAUTHN_CREDENTIAL_TYPE_PUBLIC_KEY;
283 cose->cCredentialParameters = 1;
284 cose->pCredentialParameters = alg;
290 pack_cred_ext(WEBAUTHN_EXTENSIONS *out, fido_cred_ext_t *in)
292 WEBAUTHN_EXTENSION *e;
293 WEBAUTHN_CRED_PROTECT_EXTENSION_IN *p;
298 return 0; /* nothing to do */
300 if (in->mask & ~(FIDO_EXT_HMAC_SECRET | FIDO_EXT_CRED_PROTECT)) {
301 fido_log_debug("%s: mask 0x%x", in->mask);
304 if (in->mask & FIDO_EXT_HMAC_SECRET)
306 if (in->mask & FIDO_EXT_CRED_PROTECT)
308 if ((out->pExtensions = calloc(n, sizeof(*e))) == NULL) {
309 fido_log_debug("%s: calloc", __func__);
312 out->cExtensions = (DWORD)n;
313 if (in->mask & FIDO_EXT_HMAC_SECRET) {
314 if ((b = calloc(1, sizeof(*b))) == NULL) {
315 fido_log_debug("%s: calloc", __func__);
319 e = &out->pExtensions[i];
320 e->pwszExtensionIdentifier =
321 WEBAUTHN_EXTENSIONS_IDENTIFIER_HMAC_SECRET;
323 e->cbExtension = sizeof(*b);
326 if (in->mask & FIDO_EXT_CRED_PROTECT) {
327 if ((p = calloc(1, sizeof(*p))) == NULL) {
328 fido_log_debug("%s: calloc", __func__);
331 p->dwCredProtect = (DWORD)in->prot;
332 p->bRequireCredProtect = true;
333 e = &out->pExtensions[i];
334 e->pwszExtensionIdentifier =
335 WEBAUTHN_EXTENSIONS_IDENTIFIER_CRED_PROTECT;
337 e->cbExtension = sizeof(*p);
345 unpack_fmt(fido_cred_t *cred, WEBAUTHN_CREDENTIAL_ATTESTATION *att)
350 if ((fmt = to_utf8(att->pwszFormatType)) == NULL) {
351 fido_log_debug("%s: fmt", __func__);
354 r = fido_cred_set_fmt(cred, fmt);
358 fido_log_debug("%s: fido_cred_set_fmt: %s", __func__,
367 unpack_cred_authdata(fido_cred_t *cred, WEBAUTHN_CREDENTIAL_ATTESTATION *att)
371 if (att->cbAuthenticatorData > SIZE_MAX) {
372 fido_log_debug("%s: cbAuthenticatorData", __func__);
375 if ((r = fido_cred_set_authdata_raw(cred, att->pbAuthenticatorData,
376 (size_t)att->cbAuthenticatorData)) != FIDO_OK) {
377 fido_log_debug("%s: fido_cred_set_authdata_raw: %s", __func__,
386 unpack_cred_sig(fido_cred_t *cred, WEBAUTHN_COMMON_ATTESTATION *attr)
390 if (attr->cbSignature > SIZE_MAX) {
391 fido_log_debug("%s: cbSignature", __func__);
394 if ((r = fido_cred_set_sig(cred, attr->pbSignature,
395 (size_t)attr->cbSignature)) != FIDO_OK) {
396 fido_log_debug("%s: fido_cred_set_sig: %s", __func__,
405 unpack_x5c(fido_cred_t *cred, WEBAUTHN_COMMON_ATTESTATION *attr)
409 fido_log_debug("%s: %u cert(s)", __func__, attr->cX5c);
412 return 0; /* self-attestation */
413 if (attr->lAlg != WEBAUTHN_COSE_ALGORITHM_ECDSA_P256_WITH_SHA256) {
414 fido_log_debug("%s: lAlg %d", __func__, attr->lAlg);
417 if (attr->pX5c[0].cbData > SIZE_MAX) {
418 fido_log_debug("%s: cbData", __func__);
421 if ((r = fido_cred_set_x509(cred, attr->pX5c[0].pbData,
422 (size_t)attr->pX5c[0].cbData)) != FIDO_OK) {
423 fido_log_debug("%s: fido_cred_set_x509: %s", __func__,
432 unpack_assert_authdata(fido_assert_t *assert, WEBAUTHN_ASSERTION *wa)
436 if (wa->cbAuthenticatorData > SIZE_MAX) {
437 fido_log_debug("%s: cbAuthenticatorData", __func__);
440 if ((r = fido_assert_set_authdata_raw(assert, 0, wa->pbAuthenticatorData,
441 (size_t)wa->cbAuthenticatorData)) != FIDO_OK) {
442 fido_log_debug("%s: fido_assert_set_authdata_raw: %s", __func__,
451 unpack_assert_sig(fido_assert_t *assert, WEBAUTHN_ASSERTION *wa)
455 if (wa->cbSignature > SIZE_MAX) {
456 fido_log_debug("%s: cbSignature", __func__);
459 if ((r = fido_assert_set_sig(assert, 0, wa->pbSignature,
460 (size_t)wa->cbSignature)) != FIDO_OK) {
461 fido_log_debug("%s: fido_assert_set_sig: %s", __func__,
470 unpack_cred_id(fido_assert_t *assert, WEBAUTHN_ASSERTION *wa)
472 if (wa->Credential.cbId > SIZE_MAX) {
473 fido_log_debug("%s: Credential.cbId", __func__);
476 if (fido_blob_set(&assert->stmt[0].id, wa->Credential.pbId,
477 (size_t)wa->Credential.cbId) < 0) {
478 fido_log_debug("%s: fido_blob_set", __func__);
486 unpack_user_id(fido_assert_t *assert, WEBAUTHN_ASSERTION *wa)
488 if (wa->cbUserId == 0)
489 return 0; /* user id absent */
490 if (wa->cbUserId > SIZE_MAX) {
491 fido_log_debug("%s: cbUserId", __func__);
494 if (fido_blob_set(&assert->stmt[0].user.id, wa->pbUserId,
495 (size_t)wa->cbUserId) < 0) {
496 fido_log_debug("%s: fido_blob_set", __func__);
504 translate_fido_assert(struct winhello_assert *ctx, fido_assert_t *assert,
507 WEBAUTHN_AUTHENTICATOR_GET_ASSERTION_OPTIONS *opt;
509 /* not supported by webauthn.h */
510 if (assert->up == FIDO_OPT_FALSE) {
511 fido_log_debug("%s: up %d", __func__, assert->up);
512 return FIDO_ERR_UNSUPPORTED_OPTION;
514 /* not implemented */
515 if (assert->ext.mask) {
516 fido_log_debug("%s: ext 0x%x", __func__, assert->ext.mask);
517 return FIDO_ERR_UNSUPPORTED_EXTENSION;
519 if ((ctx->rp_id = to_utf16(assert->rp_id)) == NULL) {
520 fido_log_debug("%s: rp_id", __func__);
521 return FIDO_ERR_INTERNAL;
523 if (pack_cd(&ctx->cd, &assert->cd) < 0) {
524 fido_log_debug("%s: pack_cd", __func__);
525 return FIDO_ERR_INTERNAL;
529 opt->dwVersion = WEBAUTHN_AUTHENTICATOR_GET_ASSERTION_OPTIONS_VERSION_1;
530 opt->dwTimeoutMilliseconds = MAXMSEC;
531 if (pack_credlist(&opt->CredentialList, &assert->allow_list) < 0) {
532 fido_log_debug("%s: pack_credlist", __func__);
533 return FIDO_ERR_INTERNAL;
535 if (set_uv(&opt->dwUserVerificationRequirement, assert->uv, pin) < 0) {
536 fido_log_debug("%s: set_uv", __func__);
537 return FIDO_ERR_INTERNAL;
544 translate_winhello_assert(fido_assert_t *assert, WEBAUTHN_ASSERTION *wa)
548 if (assert->stmt_len > 0) {
549 fido_log_debug("%s: stmt_len=%zu", __func__, assert->stmt_len);
550 return FIDO_ERR_INTERNAL;
552 if ((r = fido_assert_set_count(assert, 1)) != FIDO_OK) {
553 fido_log_debug("%s: fido_assert_set_count: %s", __func__,
555 return FIDO_ERR_INTERNAL;
557 if (unpack_assert_authdata(assert, wa) < 0) {
558 fido_log_debug("%s: unpack_assert_authdata", __func__);
559 return FIDO_ERR_INTERNAL;
561 if (unpack_assert_sig(assert, wa) < 0) {
562 fido_log_debug("%s: unpack_assert_sig", __func__);
563 return FIDO_ERR_INTERNAL;
565 if (unpack_cred_id(assert, wa) < 0) {
566 fido_log_debug("%s: unpack_cred_id", __func__);
567 return FIDO_ERR_INTERNAL;
569 if (unpack_user_id(assert, wa) < 0) {
570 fido_log_debug("%s: unpack_user_id", __func__);
571 return FIDO_ERR_INTERNAL;
578 translate_fido_cred(struct winhello_cred *ctx, fido_cred_t *cred,
581 WEBAUTHN_AUTHENTICATOR_MAKE_CREDENTIAL_OPTIONS *opt;
583 if (pack_rp(&ctx->rp_id, &ctx->rp_name, &ctx->rp, &cred->rp) < 0) {
584 fido_log_debug("%s: pack_rp", __func__);
585 return FIDO_ERR_INTERNAL;
587 if (pack_user(&ctx->user_name, &ctx->user_icon, &ctx->display_name,
588 &ctx->user, &cred->user) < 0) {
589 fido_log_debug("%s: pack_user", __func__);
590 return FIDO_ERR_INTERNAL;
592 if (pack_cose(&ctx->alg, &ctx->cose, cred->type) < 0) {
593 fido_log_debug("%s: pack_cose", __func__);
594 return FIDO_ERR_INTERNAL;
596 if (pack_cd(&ctx->cd, &cred->cd) < 0) {
597 fido_log_debug("%s: pack_cd", __func__);
598 return FIDO_ERR_INTERNAL;
602 opt->dwVersion = WEBAUTHN_AUTHENTICATOR_MAKE_CREDENTIAL_OPTIONS_VERSION_1;
603 opt->dwTimeoutMilliseconds = MAXMSEC;
604 if (pack_credlist(&opt->CredentialList, &cred->excl) < 0) {
605 fido_log_debug("%s: pack_credlist", __func__);
606 return FIDO_ERR_INTERNAL;
608 if (pack_cred_ext(&opt->Extensions, &cred->ext) < 0) {
609 fido_log_debug("%s: pack_cred_ext", __func__);
610 return FIDO_ERR_UNSUPPORTED_EXTENSION;
612 if (set_uv(&opt->dwUserVerificationRequirement, cred->uv, pin) < 0) {
613 fido_log_debug("%s: set_uv", __func__);
614 return FIDO_ERR_INTERNAL;
616 if (cred->rk == FIDO_OPT_TRUE) {
617 opt->bRequireResidentKey = true;
624 translate_winhello_cred(fido_cred_t *cred, WEBAUTHN_CREDENTIAL_ATTESTATION *att)
626 if (unpack_fmt(cred, att) < 0) {
627 fido_log_debug("%s: unpack_fmt", __func__);
628 return FIDO_ERR_INTERNAL;
630 if (unpack_cred_authdata(cred, att) < 0) {
631 fido_log_debug("%s: unpack_cred_authdata", __func__);
632 return FIDO_ERR_INTERNAL;
635 switch (att->dwAttestationDecodeType) {
636 case WEBAUTHN_ATTESTATION_DECODE_NONE:
637 if (att->pvAttestationDecode != NULL) {
638 fido_log_debug("%s: pvAttestationDecode", __func__);
639 return FIDO_ERR_INTERNAL;
642 case WEBAUTHN_ATTESTATION_DECODE_COMMON:
643 if (att->pvAttestationDecode == NULL) {
644 fido_log_debug("%s: pvAttestationDecode", __func__);
645 return FIDO_ERR_INTERNAL;
647 if (unpack_cred_sig(cred, att->pvAttestationDecode) < 0) {
648 fido_log_debug("%s: unpack_cred_sig", __func__);
649 return FIDO_ERR_INTERNAL;
651 if (unpack_x5c(cred, att->pvAttestationDecode) < 0) {
652 fido_log_debug("%s: unpack_x5c", __func__);
653 return FIDO_ERR_INTERNAL;
657 fido_log_debug("%s: dwAttestationDecodeType: %u", __func__,
658 att->dwAttestationDecodeType);
659 return FIDO_ERR_INTERNAL;
666 winhello_manifest(BOOL *present)
672 if ((n = WebAuthNGetApiVersionNumber()) < 1) {
673 fido_log_debug("%s: unsupported api %u", __func__, n);
674 return FIDO_ERR_INTERNAL;
676 fido_log_debug("%s: api version %u", __func__, n);
677 hr = WebAuthNIsUserVerifyingPlatformAuthenticatorAvailable(present);
680 fido_log_debug("%s: %ls -> %s", __func__,
681 WebAuthNGetErrorName(hr), fido_strerr(r));
688 winhello_get_assert(HWND w, struct winhello_assert *ctx)
693 hr = WebAuthNAuthenticatorGetAssertion(w, ctx->rp_id, &ctx->cd,
694 &ctx->opt, &ctx->assert);
697 fido_log_debug("%s: %ls -> %s", __func__,
698 WebAuthNGetErrorName(hr), fido_strerr(r));
705 winhello_make_cred(HWND w, struct winhello_cred *ctx)
710 hr = WebAuthNAuthenticatorMakeCredential(w, &ctx->rp, &ctx->user,
711 &ctx->cose, &ctx->cd, &ctx->opt, &ctx->att);
714 fido_log_debug("%s: %ls -> %s", __func__,
715 WebAuthNGetErrorName(hr), fido_strerr(r));
722 winhello_assert_free(struct winhello_assert *ctx)
726 if (ctx->assert != NULL)
727 WebAuthNFreeAssertion(ctx->assert);
730 free(ctx->opt.CredentialList.pCredentials);
735 winhello_cred_free(struct winhello_cred *ctx)
739 if (ctx->att != NULL)
740 WebAuthNFreeCredentialAttestation(ctx->att);
744 free(ctx->user_name);
745 free(ctx->user_icon);
746 free(ctx->display_name);
747 free(ctx->opt.CredentialList.pCredentials);
748 for (size_t i = 0; i < ctx->opt.Extensions.cExtensions; i++) {
749 WEBAUTHN_EXTENSION *e;
750 e = &ctx->opt.Extensions.pExtensions[i];
751 free(e->pvExtension);
753 free(ctx->opt.Extensions.pExtensions);
758 fido_winhello_manifest(fido_dev_info_t *devlist, size_t ilen, size_t *olen)
767 if (devlist == NULL) {
768 return FIDO_ERR_INVALID_ARGUMENT;
770 if ((r = winhello_manifest(&present)) != FIDO_OK) {
771 fido_log_debug("%s: winhello_manifest", __func__);
774 if (present == false) {
775 fido_log_debug("%s: not present", __func__);
779 di = &devlist[*olen];
780 memset(di, 0, sizeof(*di));
781 di->path = strdup(FIDO_WINHELLO_PATH);
782 di->manufacturer = strdup("Microsoft Corporation");
783 di->product = strdup("Windows Hello");
784 di->vendor_id = VENDORID;
785 di->product_id = PRODID;
786 if (di->path == NULL || di->manufacturer == NULL ||
787 di->product == NULL) {
789 free(di->manufacturer);
791 explicit_bzero(di, sizeof(*di));
792 return FIDO_ERR_INTERNAL;
800 fido_winhello_open(fido_dev_t *dev)
803 return FIDO_ERR_INVALID_ARGUMENT;
805 dev->attr.flags = FIDO_CAP_CBOR | FIDO_CAP_WINK;
806 dev->flags = FIDO_DEV_WINHELLO | FIDO_DEV_CRED_PROT | FIDO_DEV_PIN_SET;
812 fido_winhello_close(fido_dev_t *dev)
814 memset(dev, 0, sizeof(*dev));
820 fido_winhello_cancel(fido_dev_t *dev)
824 return FIDO_ERR_INTERNAL;
828 fido_winhello_get_assert(fido_dev_t *dev, fido_assert_t *assert,
832 struct winhello_assert *ctx;
833 int r = FIDO_ERR_INTERNAL;
837 if ((ctx = calloc(1, sizeof(*ctx))) == NULL) {
838 fido_log_debug("%s: calloc", __func__);
841 if ((w = GetForegroundWindow()) == NULL) {
842 fido_log_debug("%s: GetForegroundWindow", __func__);
845 if ((r = translate_fido_assert(ctx, assert, pin)) != FIDO_OK) {
846 fido_log_debug("%s: translate_fido_assert", __func__);
849 if ((r = winhello_get_assert(w, ctx)) != S_OK) {
850 fido_log_debug("%s: winhello_get_assert", __func__);
853 if ((r = translate_winhello_assert(assert, ctx->assert)) != FIDO_OK) {
854 fido_log_debug("%s: translate_winhello_assert", __func__);
859 winhello_assert_free(ctx);
865 fido_winhello_get_cbor_info(fido_dev_t *dev, fido_cbor_info_t *ci)
867 const char *v[3] = { "U2F_V2", "FIDO_2_0", "FIDO_2_1_PRE" };
868 const char *e[2] = { "credProtect", "hmac-secret" };
869 const char *t[2] = { "nfc", "usb" };
870 const char *o[4] = { "rk", "up", "plat", "clientPin" };
874 fido_cbor_info_reset(ci);
876 if (to_fido_str_array(&ci->versions, v, nitems(v)) < 0 ||
877 to_fido_str_array(&ci->extensions, e, nitems(e)) < 0 ||
878 to_fido_str_array(&ci->transports, t, nitems(t)) < 0) {
879 fido_log_debug("%s: to_fido_str_array", __func__);
880 return FIDO_ERR_INTERNAL;
882 if ((ci->options.name = calloc(nitems(o), sizeof(char *))) == NULL ||
883 (ci->options.value = calloc(nitems(o), sizeof(bool))) == NULL) {
884 fido_log_debug("%s: calloc", __func__);
885 return FIDO_ERR_INTERNAL;
887 for (size_t i = 0; i < nitems(o); i++) {
888 if ((ci->options.name[i] = strdup(o[i])) == NULL) {
889 fido_log_debug("%s: strdup", __func__);
890 return FIDO_ERR_INTERNAL;
892 ci->options.value[i] = true;
900 fido_winhello_make_cred(fido_dev_t *dev, fido_cred_t *cred, const char *pin)
903 struct winhello_cred *ctx;
904 int r = FIDO_ERR_INTERNAL;
908 if ((ctx = calloc(1, sizeof(*ctx))) == NULL) {
909 fido_log_debug("%s: calloc", __func__);
912 if ((w = GetForegroundWindow()) == NULL) {
913 fido_log_debug("%s: GetForegroundWindow", __func__);
916 if ((r = translate_fido_cred(ctx, cred, pin)) != FIDO_OK) {
917 fido_log_debug("%s: translate_fido_cred", __func__);
920 if ((r = winhello_make_cred(w, ctx)) != FIDO_OK) {
921 fido_log_debug("%s: winhello_make_cred", __func__);
924 if ((r = translate_winhello_cred(cred, ctx->att)) != FIDO_OK) {
925 fido_log_debug("%s: translate_winhello_cred", __func__);
931 winhello_cred_free(ctx);