summaryrefslogtreecommitdiff
path: root/tools/fido2-token.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/fido2-token.c')
-rw-r--r--tools/fido2-token.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/tools/fido2-token.c b/tools/fido2-token.c
new file mode 100644
index 0000000..0b02fea
--- /dev/null
+++ b/tools/fido2-token.c
@@ -0,0 +1,95 @@
1/*
2 * Copyright (c) 2018 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.
5 */
6
7#include <fido.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11
12#include "../openbsd-compat/openbsd-compat.h"
13#include "extern.h"
14
15static int action;
16
17void
18usage(void)
19{
20 fprintf(stderr,
21"usage: fido2-token [-CR] [-d] device\n"
22" fido2-token -D [-de] -i id device\n"
23" fido2-token -I [-cd] [-k rp_id -i cred_id] device\n"
24" fido2-token -L [-der] [-k rp_id] [device]\n"
25" fido2-token -S [-de] [-i template_id -n template_name] device\n"
26" fido2-token -V\n"
27 );
28
29 exit(1);
30}
31
32static void
33setaction(int ch)
34{
35 if (action)
36 usage();
37 action = ch;
38}
39
40int
41main(int argc, char **argv)
42{
43 int ch;
44 int flags = 0;
45 char *device;
46
47 while ((ch = getopt(argc, argv, TOKEN_OPT)) != -1) {
48 switch (ch) {
49 case 'b':
50 case 'c':
51 case 'e':
52 case 'i':
53 case 'k':
54 case 'n':
55 case 'r':
56 break; /* ignore */
57 case 'd':
58 flags = FIDO_DEBUG;
59 break;
60 default:
61 setaction(ch);
62 break;
63 }
64 }
65
66 if (argc - optind == 1)
67 device = argv[optind];
68 else
69 device = NULL;
70
71 fido_init(flags);
72
73 switch (action) {
74 case 'C':
75 return (pin_change(device));
76 case 'D':
77 return (token_delete(argc, argv, device));
78 case 'I':
79 return (token_info(argc, argv, device));
80 case 'L':
81 return (token_list(argc, argv, device));
82 case 'R':
83 return (token_reset(device));
84 case 'S':
85 return (token_set(argc, argv, device));
86 case 'V':
87 fprintf(stderr, "%d.%d.%d\n", _FIDO_MAJOR, _FIDO_MINOR,
88 _FIDO_PATCH);
89 exit(0);
90 }
91
92 usage();
93
94 /* NOTREACHED */
95}