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