diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/CMakeLists.txt | 2 | ||||
-rw-r--r-- | examples/cred.c | 40 | ||||
-rw-r--r-- | examples/info.c | 12 |
3 files changed, 46 insertions, 8 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 957311e..1203592 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt | |||
@@ -8,7 +8,7 @@ list(APPEND COMPAT_SOURCES | |||
8 | ../openbsd-compat/strlcpy.c | 8 | ../openbsd-compat/strlcpy.c |
9 | ) | 9 | ) |
10 | 10 | ||
11 | if(WIN32) | 11 | if(WIN32 AND NOT CYGWIN AND NOT MSYS) |
12 | list(APPEND COMPAT_SOURCES ../openbsd-compat/posix_win.c) | 12 | list(APPEND COMPAT_SOURCES ../openbsd-compat/posix_win.c) |
13 | endif() | 13 | endif() |
14 | 14 | ||
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 | ||
142 | static fido_dev_t * | ||
143 | open_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 | |||
142 | int | 163 | int |
143 | main(int argc, char **argv) | 164 | main(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 | ||
diff --git a/examples/info.c b/examples/info.c index e79729c..ef0d97e 100644 --- a/examples/info.c +++ b/examples/info.c | |||
@@ -131,6 +131,15 @@ print_maxmsgsiz(uint64_t maxmsgsiz) | |||
131 | } | 131 | } |
132 | 132 | ||
133 | /* | 133 | /* |
134 | * Auxiliary function to print an authenticator's firmware version on stdout. | ||
135 | */ | ||
136 | static void | ||
137 | print_fwversion(uint64_t fwversion) | ||
138 | { | ||
139 | printf("fwversion: 0x%x\n", (int)fwversion); | ||
140 | } | ||
141 | |||
142 | /* | ||
134 | * Auxiliary function to print an array of bytes on stdout. | 143 | * Auxiliary function to print an array of bytes on stdout. |
135 | */ | 144 | */ |
136 | static void | 145 | static void |
@@ -190,6 +199,9 @@ getinfo(const char *path) | |||
190 | /* print maximum message size */ | 199 | /* print maximum message size */ |
191 | print_maxmsgsiz(fido_cbor_info_maxmsgsiz(ci)); | 200 | print_maxmsgsiz(fido_cbor_info_maxmsgsiz(ci)); |
192 | 201 | ||
202 | /* print firmware version */ | ||
203 | print_fwversion(fido_cbor_info_fwversion(ci)); | ||
204 | |||
193 | /* print supported pin protocols */ | 205 | /* print supported pin protocols */ |
194 | print_byte_array("pin protocols", fido_cbor_info_protocols_ptr(ci), | 206 | print_byte_array("pin protocols", fido_cbor_info_protocols_ptr(ci), |
195 | fido_cbor_info_protocols_len(ci)); | 207 | fido_cbor_info_protocols_len(ci)); |