summaryrefslogtreecommitdiff
path: root/examples/cred.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/cred.c')
-rw-r--r--examples/cred.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/examples/cred.c b/examples/cred.c
index 5a2a27fd7771..4fb07868b4e7 100644
--- a/examples/cred.c
+++ b/examples/cred.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2023 Yubico AB. All rights reserved.
+ * Copyright (c) 2018-2024 Yubico AB. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
* SPDX-License-Identifier: BSD-2-Clause
@@ -36,7 +36,8 @@ static void
usage(void)
{
fprintf(stderr, "usage: cred [-t es256|es384|rs256|eddsa] [-k pubkey] "
- "[-ei cred_id] [-P pin] [-T seconds] [-b blobkey] [-c cred_protect] [-hruv] "
+ "[-ei cred_id] [-P pin] [-T seconds] [-b blobkey] [-c cred_protect] "
+ "[-a mode] [-hruv] "
"<device>\n");
exit(EXIT_FAILURE);
}
@@ -106,9 +107,13 @@ verify_cred(int type, const char *fmt, const unsigned char *authdata_ptr,
if (r != FIDO_OK)
errx(1, "fido_cred_set_attstmt: %s (0x%x)", fido_strerr(r), r);
- r = fido_cred_verify(cred);
- if (r != FIDO_OK)
- errx(1, "fido_cred_verify: %s (0x%x)", fido_strerr(r), r);
+ if (fido_cred_x5c_ptr(cred) == NULL) {
+ if ((r = fido_cred_verify_self(cred)) != FIDO_OK)
+ errx(1, "fido_cred_verify_self: %s (0x%x)", fido_strerr(r), r);
+ } else {
+ if ((r = fido_cred_verify(cred)) != FIDO_OK)
+ errx(1, "fido_cred_verify: %s (0x%x)", fido_strerr(r), r);
+ }
out:
if (key_out != NULL) {
@@ -166,11 +171,12 @@ main(int argc, char **argv)
int ch;
int r;
long long cred_protect = 0;
+ long long ea = 0;
if ((cred = fido_cred_new()) == NULL)
errx(1, "fido_cred_new");
- while ((ch = getopt(argc, argv, "P:T:b:e:hi:k:rt:uvc:")) != -1) {
+ while ((ch = getopt(argc, argv, "P:T:a:b:e:hi:k:rt:uvc:")) != -1) {
switch (ch) {
case 'P':
pin = optarg;
@@ -182,6 +188,12 @@ main(int argc, char **argv)
errx(1, "-T: %s must be in (0,30]", optarg);
ms *= 1000; /* seconds to milliseconds */
break;
+ case 'a':
+ if (base10(optarg, &ea) < 0)
+ errx(1, "base10: %s", optarg);
+ if (ea <= 0 || ea > 2)
+ errx(1, "-a: %s must be in (0,2]", optarg);
+ break;
case 'b':
ext |= FIDO_EXT_LARGEBLOB_KEY;
blobkey_out = optarg;
@@ -203,7 +215,7 @@ main(int argc, char **argv)
if (base10(optarg, &cred_protect) < 0)
errx(1, "base10: %s", optarg);
if (cred_protect <= 0 || cred_protect > 3)
- errx(1, "-c: %s must be in (1,3)", optarg);
+ errx(1, "-c: %s must be in (0,3]", optarg);
ext |= FIDO_EXT_CRED_PROTECT;
break;
case 'i':
@@ -293,6 +305,9 @@ main(int argc, char **argv)
if (cred_protect != 0 && (r = fido_cred_set_prot(cred,
(int)cred_protect)) != FIDO_OK)
errx(1, "fido_cred_set_prot: %s (0x%x)", fido_strerr(r), r);
+
+ if (ea != 0 && (r = fido_cred_set_entattest(cred, (int)ea)) != FIDO_OK)
+ errx(1, "fido_cred_set_entattest: %s (0x%x)", fido_strerr(r), r);
/* timeout */
if (ms != 0 && (r = fido_dev_set_timeout(dev, (int)ms)) != FIDO_OK)