10afa8e06SEd Maste /*
20afa8e06SEd Maste * Copyright (c) 2018 Yubico AB. All rights reserved.
30afa8e06SEd Maste * Use of this source code is governed by a BSD-style
40afa8e06SEd Maste * license that can be found in the LICENSE file.
5*2ccfa855SEd Maste * SPDX-License-Identifier: BSD-2-Clause
60afa8e06SEd Maste */
70afa8e06SEd Maste
80afa8e06SEd Maste #include <fido.h>
90afa8e06SEd Maste #include <stdio.h>
100afa8e06SEd Maste #include <stdlib.h>
110afa8e06SEd Maste
120afa8e06SEd Maste #include "../openbsd-compat/openbsd-compat.h"
130afa8e06SEd Maste #include "extern.h"
140afa8e06SEd Maste
150afa8e06SEd Maste static int action;
160afa8e06SEd Maste
170afa8e06SEd Maste void
usage(void)180afa8e06SEd Maste usage(void)
190afa8e06SEd Maste {
200afa8e06SEd Maste fprintf(stderr,
210afa8e06SEd Maste "usage: fido2-token -C [-d] device\n"
220afa8e06SEd Maste " fido2-token -Db [-k key_path] [-i cred_id -n rp_id] device\n"
230afa8e06SEd Maste " fido2-token -Dei template_id device\n"
240afa8e06SEd Maste " fido2-token -Du device\n"
250afa8e06SEd Maste " fido2-token -Gb [-k key_path] [-i cred_id -n rp_id] blob_path device\n"
260afa8e06SEd Maste " fido2-token -I [-cd] [-k rp_id -i cred_id] device\n"
270afa8e06SEd Maste " fido2-token -L [-bder] [-k rp_id] [device]\n"
280afa8e06SEd Maste " fido2-token -R [-d] device\n"
290afa8e06SEd Maste " fido2-token -S [-adefu] [-l pin_length] [-i template_id -n template_name] device\n"
300afa8e06SEd Maste " fido2-token -Sb [-k key_path] [-i cred_id -n rp_id] blob_path device\n"
310afa8e06SEd Maste " fido2-token -Sc -i cred_id -k user_id -n name -p display_name device\n"
32f540a430SEd Maste " fido2-token -Sm rp_id device\n"
330afa8e06SEd Maste " fido2-token -V\n"
340afa8e06SEd Maste );
350afa8e06SEd Maste
360afa8e06SEd Maste exit(1);
370afa8e06SEd Maste }
380afa8e06SEd Maste
390afa8e06SEd Maste static void
setaction(int ch)400afa8e06SEd Maste setaction(int ch)
410afa8e06SEd Maste {
420afa8e06SEd Maste if (action)
430afa8e06SEd Maste usage();
440afa8e06SEd Maste action = ch;
450afa8e06SEd Maste }
460afa8e06SEd Maste
470afa8e06SEd Maste int
main(int argc,char ** argv)480afa8e06SEd Maste main(int argc, char **argv)
490afa8e06SEd Maste {
500afa8e06SEd Maste int ch;
510afa8e06SEd Maste int flags = 0;
520afa8e06SEd Maste char *device;
530afa8e06SEd Maste
540afa8e06SEd Maste while ((ch = getopt(argc, argv, TOKEN_OPT)) != -1) {
550afa8e06SEd Maste switch (ch) {
560afa8e06SEd Maste case 'a':
570afa8e06SEd Maste case 'b':
580afa8e06SEd Maste case 'c':
590afa8e06SEd Maste case 'e':
600afa8e06SEd Maste case 'f':
610afa8e06SEd Maste case 'i':
620afa8e06SEd Maste case 'k':
630afa8e06SEd Maste case 'l':
64f540a430SEd Maste case 'm':
650afa8e06SEd Maste case 'n':
660afa8e06SEd Maste case 'p':
670afa8e06SEd Maste case 'r':
680afa8e06SEd Maste case 'u':
690afa8e06SEd Maste break; /* ignore */
700afa8e06SEd Maste case 'd':
710afa8e06SEd Maste flags = FIDO_DEBUG;
720afa8e06SEd Maste break;
730afa8e06SEd Maste default:
740afa8e06SEd Maste setaction(ch);
750afa8e06SEd Maste break;
760afa8e06SEd Maste }
770afa8e06SEd Maste }
780afa8e06SEd Maste
790afa8e06SEd Maste if (argc - optind < 1)
800afa8e06SEd Maste device = NULL;
810afa8e06SEd Maste else
820afa8e06SEd Maste device = argv[argc - 1];
830afa8e06SEd Maste
840afa8e06SEd Maste fido_init(flags);
850afa8e06SEd Maste
860afa8e06SEd Maste switch (action) {
870afa8e06SEd Maste case 'C':
880afa8e06SEd Maste return (pin_change(device));
890afa8e06SEd Maste case 'D':
900afa8e06SEd Maste return (token_delete(argc, argv, device));
910afa8e06SEd Maste case 'G':
920afa8e06SEd Maste return (token_get(argc, argv, device));
930afa8e06SEd Maste case 'I':
940afa8e06SEd Maste return (token_info(argc, argv, device));
950afa8e06SEd Maste case 'L':
960afa8e06SEd Maste return (token_list(argc, argv, device));
970afa8e06SEd Maste case 'R':
980afa8e06SEd Maste return (token_reset(device));
990afa8e06SEd Maste case 'S':
1000afa8e06SEd Maste return (token_set(argc, argv, device));
1010afa8e06SEd Maste case 'V':
1020afa8e06SEd Maste fprintf(stderr, "%d.%d.%d\n", _FIDO_MAJOR, _FIDO_MINOR,
1030afa8e06SEd Maste _FIDO_PATCH);
1040afa8e06SEd Maste exit(0);
1050afa8e06SEd Maste }
1060afa8e06SEd Maste
1070afa8e06SEd Maste usage();
1080afa8e06SEd Maste
1090afa8e06SEd Maste /* NOTREACHED */
1100afa8e06SEd Maste }
111