File: fido2-token.c

package info (click to toggle)
mysql-8.0 8.0.43-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,904 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,184; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,196; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (110 lines) | stat: -rw-r--r-- 2,240 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright (c) 2018 Yubico AB. All rights reserved.
 * Use of this source code is governed by a BSD-style
 * license that can be found in the LICENSE file.
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <fido.h>
#include <stdio.h>
#include <stdlib.h>

#include "../openbsd-compat/openbsd-compat.h"
#include "extern.h"

static int action;

void
usage(void)
{
	fprintf(stderr,
"usage: fido2-token -C [-d] device\n"
"       fido2-token -Db [-k key_path] [-i cred_id -n rp_id] device\n"
"       fido2-token -Dei template_id device\n"
"       fido2-token -Du device\n"
"       fido2-token -Gb [-k key_path] [-i cred_id -n rp_id] blob_path device\n"
"       fido2-token -I [-cd] [-k rp_id -i cred_id]  device\n"
"       fido2-token -L [-bder] [-k rp_id] [device]\n"
"       fido2-token -R [-d] device\n"
"       fido2-token -S [-adefu] [-l pin_length] [-i template_id -n template_name] device\n"
"       fido2-token -Sb [-k key_path] [-i cred_id -n rp_id] blob_path device\n"
"       fido2-token -Sc -i cred_id -k user_id -n name -p display_name device\n"
"       fido2-token -Sm rp_id device\n"
"       fido2-token -V\n"
	);

	exit(1);
}

static void
setaction(int ch)
{
	if (action)
		usage();
	action = ch;
}

int
main(int argc, char **argv)
{
	int ch;
	int flags = 0;
	char *device;

	while ((ch = getopt(argc, argv, TOKEN_OPT)) != -1) {
		switch (ch) {
		case 'a':
		case 'b':
		case 'c':
		case 'e':
		case 'f':
		case 'i':
		case 'k':
		case 'l':
		case 'm':
		case 'n':
		case 'p':
		case 'r':
		case 'u':
			break; /* ignore */
		case 'd':
			flags = FIDO_DEBUG;
			break;
		default:
			setaction(ch);
			break;
		}
	}

	if (argc - optind < 1)
		device = NULL;
	else
		device = argv[argc - 1];

	fido_init(flags);

	switch (action) {
	case 'C':
		return (pin_change(device));
	case 'D':
		return (token_delete(argc, argv, device));
	case 'G':
		return (token_get(argc, argv, device));
	case 'I':
		return (token_info(argc, argv, device));
	case 'L':
		return (token_list(argc, argv, device));
	case 'R':
		return (token_reset(device));
	case 'S':
		return (token_set(argc, argv, device));
	case 'V':
		fprintf(stderr, "%d.%d.%d\n", _FIDO_MAJOR, _FIDO_MINOR,
		    _FIDO_PATCH);
		exit(0);
	}

	usage();

	/* NOTREACHED */
}