Path: blob/main/contrib/libfido2/tools/fido2-token.c
39507 views
/*1* Copyright (c) 2018 Yubico AB. All rights reserved.2* Use of this source code is governed by a BSD-style3* license that can be found in the LICENSE file.4* SPDX-License-Identifier: BSD-2-Clause5*/67#include <fido.h>8#include <stdio.h>9#include <stdlib.h>1011#include "../openbsd-compat/openbsd-compat.h"12#include "extern.h"1314static int action;1516void17usage(void)18{19fprintf(stderr,20"usage: fido2-token -C [-d] device\n"21" fido2-token -Db [-k key_path] [-i cred_id -n rp_id] device\n"22" fido2-token -Dei template_id device\n"23" fido2-token -Du device\n"24" fido2-token -Gb [-k key_path] [-i cred_id -n rp_id] blob_path device\n"25" fido2-token -I [-cd] [-k rp_id -i cred_id] device\n"26" fido2-token -L [-bder] [-k rp_id] [device]\n"27" fido2-token -R [-d] device\n"28" fido2-token -S [-adefu] [-l pin_length] [-i template_id -n template_name] device\n"29" fido2-token -Sb [-k key_path] [-i cred_id -n rp_id] blob_path device\n"30" fido2-token -Sc -i cred_id -k user_id -n name -p display_name device\n"31" fido2-token -Sm rp_id device\n"32" fido2-token -V\n"33);3435exit(1);36}3738static void39setaction(int ch)40{41if (action)42usage();43action = ch;44}4546int47main(int argc, char **argv)48{49int ch;50int flags = 0;51char *device;5253while ((ch = getopt(argc, argv, TOKEN_OPT)) != -1) {54switch (ch) {55case 'a':56case 'b':57case 'c':58case 'e':59case 'f':60case 'i':61case 'k':62case 'l':63case 'm':64case 'n':65case 'p':66case 'r':67case 'u':68break; /* ignore */69case 'd':70flags = FIDO_DEBUG;71break;72default:73setaction(ch);74break;75}76}7778if (argc - optind < 1)79device = NULL;80else81device = argv[argc - 1];8283fido_init(flags);8485switch (action) {86case 'C':87return (pin_change(device));88case 'D':89return (token_delete(argc, argv, device));90case 'G':91return (token_get(argc, argv, device));92case 'I':93return (token_info(argc, argv, device));94case 'L':95return (token_list(argc, argv, device));96case 'R':97return (token_reset(device));98case 'S':99return (token_set(argc, argv, device));100case 'V':101fprintf(stderr, "%d.%d.%d\n", _FIDO_MAJOR, _FIDO_MINOR,102_FIDO_PATCH);103exit(0);104}105106usage();107108/* NOTREACHED */109}110111112