xref: /freebsd-src/contrib/libfido2/tools/fido2-cred.c (revision 60a517b66a69b8c011b04063ef63a938738719bd)
10afa8e06SEd Maste /*
2*60a517b6SEd Maste  * Copyright (c) 2018-2023 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.
52ccfa855SEd Maste  * SPDX-License-Identifier: BSD-2-Clause
60afa8e06SEd Maste  */
70afa8e06SEd Maste 
80afa8e06SEd Maste /*
90afa8e06SEd Maste  * Example usage:
100afa8e06SEd Maste  *
110afa8e06SEd Maste  * $ echo credential challenge | openssl sha256 -binary | base64 > cred_param
120afa8e06SEd Maste  * $ echo relying party >> cred_param
130afa8e06SEd Maste  * $ echo user name >> cred_param
140afa8e06SEd Maste  * $ dd if=/dev/urandom bs=1 count=32 | base64 >> cred_param
150afa8e06SEd Maste  * $ fido2-cred -M -i cred_param /dev/hidraw5 | fido2-cred -V -o cred
160afa8e06SEd Maste  */
170afa8e06SEd Maste 
180afa8e06SEd Maste #include <fido.h>
190afa8e06SEd Maste #include <stdio.h>
200afa8e06SEd Maste #include <stdlib.h>
210afa8e06SEd Maste #include <string.h>
220afa8e06SEd Maste 
230afa8e06SEd Maste #include "../openbsd-compat/openbsd-compat.h"
240afa8e06SEd Maste #include "extern.h"
250afa8e06SEd Maste 
260afa8e06SEd Maste void
usage(void)270afa8e06SEd Maste usage(void)
280afa8e06SEd Maste {
290afa8e06SEd Maste 	fprintf(stderr,
30*60a517b6SEd Maste "usage: fido2-cred -M [-bdhqruvw] [-c cred_protect] [-i input_file] [-o output_file] device [type]\n"
310afa8e06SEd Maste "       fido2-cred -V [-dhv] [-c cred_protect] [-i input_file] [-o output_file] [type]\n"
320afa8e06SEd Maste 	);
330afa8e06SEd Maste 
340afa8e06SEd Maste 	exit(1);
350afa8e06SEd Maste }
360afa8e06SEd Maste 
370afa8e06SEd Maste int
main(int argc,char ** argv)380afa8e06SEd Maste main(int argc, char **argv)
390afa8e06SEd Maste {
400afa8e06SEd Maste 	if (argc < 2 || strlen(argv[1]) != 2 || argv[1][0] != '-')
410afa8e06SEd Maste 		usage();
420afa8e06SEd Maste 
430afa8e06SEd Maste 	switch (argv[1][1]) {
440afa8e06SEd Maste 	case 'M':
450afa8e06SEd Maste 		return (cred_make(--argc, ++argv));
460afa8e06SEd Maste 	case 'V':
470afa8e06SEd Maste 		return (cred_verify(--argc, ++argv));
480afa8e06SEd Maste 	}
490afa8e06SEd Maste 
500afa8e06SEd Maste 	usage();
510afa8e06SEd Maste 
520afa8e06SEd Maste 	/* NOTREACHED */
530afa8e06SEd Maste }
54