summaryrefslogtreecommitdiff
path: root/examples/cred.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/cred.c')
-rw-r--r--examples/cred.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/examples/cred.c b/examples/cred.c
index e471f7e..3e0a30f 100644
--- a/examples/cred.c
+++ b/examples/cred.c
@@ -139,6 +139,27 @@ verify_cred(int type, const char *fmt, const unsigned char *authdata_ptr,
139 fido_cred_free(&cred); 139 fido_cred_free(&cred);
140} 140}
141 141
142static fido_dev_t *
143open_from_manifest(const fido_dev_info_t *dev_infos, size_t len,
144 const char *path)
145{
146 size_t i;
147 fido_dev_t *dev;
148
149 for (i = 0; i < len; i++) {
150 const fido_dev_info_t *curr = fido_dev_info_ptr(dev_infos, i);
151 if (path == NULL ||
152 strcmp(path, fido_dev_info_path(curr)) == 0) {
153 dev = fido_dev_new_with_info(curr);
154 if (fido_dev_open_with_info(dev) == FIDO_OK)
155 return (dev);
156 fido_dev_free(&dev);
157 }
158 }
159
160 return (NULL);
161}
162
142int 163int
143main(int argc, char **argv) 164main(int argc, char **argv)
144{ 165{
@@ -150,6 +171,7 @@ main(int argc, char **argv)
150 const char *pin = NULL; 171 const char *pin = NULL;
151 const char *key_out = NULL; 172 const char *key_out = NULL;
152 const char *id_out = NULL; 173 const char *id_out = NULL;
174 const char *path = NULL;
153 unsigned char *body = NULL; 175 unsigned char *body = NULL;
154 long long seconds = 0; 176 long long seconds = 0;
155 size_t len; 177 size_t len;
@@ -157,6 +179,8 @@ main(int argc, char **argv)
157 int ext = 0; 179 int ext = 0;
158 int ch; 180 int ch;
159 int r; 181 int r;
182 fido_dev_info_t *dev_infos = NULL;
183 size_t dev_infos_len = 0;
160 184
161 if ((cred = fido_cred_new()) == NULL) 185 if ((cred = fido_cred_new()) == NULL)
162 errx(1, "fido_cred_new"); 186 errx(1, "fido_cred_new");
@@ -218,19 +242,21 @@ main(int argc, char **argv)
218 } 242 }
219 } 243 }
220 244
245 fido_init(0);
246
221 argc -= optind; 247 argc -= optind;
222 argv += optind; 248 argv += optind;
223 249
224 if (argc != 1) 250 if (argc > 1)
225 usage(); 251 usage();
252 dev_infos = fido_dev_info_new(16);
253 fido_dev_info_manifest(dev_infos, 16, &dev_infos_len);
254 if (argc == 1)
255 path = argv[0];
226 256
227 fido_init(0); 257 if ((dev = open_from_manifest(dev_infos, dev_infos_len, path)) == NULL)
228 258 errx(1, "open_from_manifest");
229 if ((dev = fido_dev_new()) == NULL)
230 errx(1, "fido_dev_new");
231 259
232 if ((r = fido_dev_open(dev, argv[0])) != FIDO_OK)
233 errx(1, "fido_dev_open: %s (0x%x)", fido_strerr(r), r);
234 if (u2f) 260 if (u2f)
235 fido_dev_force_u2f(dev); 261 fido_dev_force_u2f(dev);
236 262