xref: /freebsd/contrib/libfido2/tools/fido2-assert.c (revision 1323ec571215a77ddd21294f0871979d5ad6b992)
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 assertion challenge | openssl sha256 -binary | base64 > assert_param
11  * $ echo relying party >> assert_param
12  * $ head -1 cred >> assert_param # credential id
13  * $ tail -n +2 cred > pubkey # credential pubkey
14  * $ fido2-assert -G -i assert_param /dev/hidraw5 | fido2-assert -V pubkey rs256
15  *
16  * See blurb in fido2-cred.c on how to obtain cred.
17  */
18 
19 #include <fido.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 #include "../openbsd-compat/openbsd-compat.h"
25 #include "extern.h"
26 
27 void
28 usage(void)
29 {
30 	fprintf(stderr,
31 "usage: fido2-assert -G [-bdhpruv] [-t option] [-i input_file] [-o output_file] device\n"
32 "       fido2-assert -V [-dhpv] [-i input_file] key_file [type]\n"
33 	);
34 
35 	exit(1);
36 }
37 
38 int
39 main(int argc, char **argv)
40 {
41 	if (argc < 2 || strlen(argv[1]) != 2 || argv[1][0] != '-')
42 		usage();
43 
44 	switch (argv[1][1]) {
45 	case 'G':
46 		return (assert_get(--argc, ++argv));
47 	case 'V':
48 		return (assert_verify(--argc, ++argv));
49 	}
50 
51 	usage();
52 
53 	/* NOTREACHED */
54 }
55