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 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8 #include <fido.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 #include "../openbsd-compat/openbsd-compat.h"
13 #include "extern.h"
14
15 static int action;
16
17 void
usage(void)18 usage(void)
19 {
20 fprintf(stderr,
21 "usage: fido2-token -C [-d] device\n"
22 " fido2-token -Db [-k key_path] [-i cred_id -n rp_id] device\n"
23 " fido2-token -Dei template_id device\n"
24 " fido2-token -Du device\n"
25 " fido2-token -Gb [-k key_path] [-i cred_id -n rp_id] blob_path device\n"
26 " fido2-token -I [-cd] [-k rp_id -i cred_id] device\n"
27 " fido2-token -L [-bder] [-k rp_id] [device]\n"
28 " fido2-token -R [-d] device\n"
29 " fido2-token -S [-adefu] [-l pin_length] [-i template_id -n template_name] device\n"
30 " fido2-token -Sb [-k key_path] [-i cred_id -n rp_id] blob_path device\n"
31 " fido2-token -Sc -i cred_id -k user_id -n name -p display_name device\n"
32 " fido2-token -Sm rp_id device\n"
33 " fido2-token -V\n"
34 );
35
36 exit(1);
37 }
38
39 static void
setaction(int ch)40 setaction(int ch)
41 {
42 if (action)
43 usage();
44 action = ch;
45 }
46
47 int
main(int argc,char ** argv)48 main(int argc, char **argv)
49 {
50 int ch;
51 int flags = 0;
52 char *device;
53
54 while ((ch = getopt(argc, argv, TOKEN_OPT)) != -1) {
55 switch (ch) {
56 case 'a':
57 case 'b':
58 case 'c':
59 case 'e':
60 case 'f':
61 case 'i':
62 case 'k':
63 case 'l':
64 case 'm':
65 case 'n':
66 case 'p':
67 case 'r':
68 case 'u':
69 break; /* ignore */
70 case 'd':
71 flags = FIDO_DEBUG;
72 break;
73 default:
74 setaction(ch);
75 break;
76 }
77 }
78
79 if (argc - optind < 1)
80 device = NULL;
81 else
82 device = argv[argc - 1];
83
84 fido_init(flags);
85
86 switch (action) {
87 case 'C':
88 return (pin_change(device));
89 case 'D':
90 return (token_delete(argc, argv, device));
91 case 'G':
92 return (token_get(argc, argv, device));
93 case 'I':
94 return (token_info(argc, argv, device));
95 case 'L':
96 return (token_list(argc, argv, device));
97 case 'R':
98 return (token_reset(device));
99 case 'S':
100 return (token_set(argc, argv, device));
101 case 'V':
102 fprintf(stderr, "%d.%d.%d\n", _FIDO_MAJOR, _FIDO_MINOR,
103 _FIDO_PATCH);
104 exit(0);
105 }
106
107 usage();
108
109 /* NOTREACHED */
110 }
111