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