xref: /freebsd/contrib/libfido2/tools/fido2-cred.c (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
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  */
6 
7 /*
8  * Example usage:
9  *
10  * $ echo credential challenge | openssl sha256 -binary | base64 > cred_param
11  * $ echo relying party >> cred_param
12  * $ echo user name >> cred_param
13  * $ dd if=/dev/urandom bs=1 count=32 | base64 >> cred_param
14  * $ fido2-cred -M -i cred_param /dev/hidraw5 | fido2-cred -V -o cred
15  */
16 
17 #include <fido.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 
22 #include "../openbsd-compat/openbsd-compat.h"
23 #include "extern.h"
24 
25 void
26 usage(void)
27 {
28 	fprintf(stderr,
29 "usage: fido2-cred -M [-bdhqruv] [-c cred_protect] [-i input_file] [-o output_file] device [type]\n"
30 "       fido2-cred -V [-dhv] [-c cred_protect] [-i input_file] [-o output_file] [type]\n"
31 	);
32 
33 	exit(1);
34 }
35 
36 int
37 main(int argc, char **argv)
38 {
39 	if (argc < 2 || strlen(argv[1]) != 2 || argv[1][0] != '-')
40 		usage();
41 
42 	switch (argv[1][1]) {
43 	case 'M':
44 		return (cred_make(--argc, ++argv));
45 	case 'V':
46 		return (cred_verify(--argc, ++argv));
47 	}
48 
49 	usage();
50 
51 	/* NOTREACHED */
52 }
53