diff options
author | James Bottomley <James.Bottomley@HansenPartnership.com> | 2019-03-09 13:01:23 -0800 |
---|---|---|
committer | James Bottomley <James.Bottomley@HansenPartnership.com> | 2019-03-14 14:36:55 -0700 |
commit | 0b72e89e999e3f283e8825f8e15f03419b2a215c (patch) | |
tree | 00019bc4eea74724074d1db8eb32485ee5f100af | |
parent | e8b202262ca44ee642b01d48502e6d5ec8181321 (diff) | |
download | fido2-ctap-gadget-0b72e89e999e3f283e8825f8e15f03419b2a215c.tar.gz |
Add configuration scripts
Add a generator for the fido2 report descriptor and an initial script
to build and configure the gadget device. No listener for the packets
yet.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | fido.c | 49 | ||||
-rwxr-xr-x | fido_configfs.sh | 73 |
5 files changed, 134 insertions, 0 deletions
@@ -17,3 +17,4 @@ libtool ltmain.sh missing test-driver +fido diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..e41caaf --- /dev/null +++ b/Makefile.am @@ -0,0 +1,3 @@ +bin_PROGRAMS=fido + +fido_SOURCES=fido.c diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..4e750eb --- /dev/null +++ b/configure.ac @@ -0,0 +1,8 @@ +AC_INIT(fido2-ctap-gadget, 0.0.1, <James.Bottomley@HansenPartnership.com>) +AM_INIT_AUTOMAKE([foreign 1.6]) + +AC_PROG_CC_STDC +AC_USE_SYSTEM_EXTENSIONS +AC_SYS_LARGEFILE + +AC_OUTPUT([Makefile]) @@ -0,0 +1,49 @@ +/* + * Create the FIDO2 report descriptor for a HID gadget + * + * Copyright (C) 2019 James.Bottomley@HansenPartnership.com + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> + +#include <sys/types.h> +#include <sys/stat.h> + +unsigned char report_desc[] = { + 0x06, 0xd0, 0xf1, /* UsagePage(FIDO_USAGE_PAGE) */ + 0x09, 0x01, /* Usage(FIDO_USAGE_CTAPHID) */ + 0xa1, 0x01, /* Collection(Application) */ + 0x09, 0x20, /* Usage(FIDO_DATA_IN) */ + 0x19, 0x00, /* LogicalMin(0) */ + 0x29, 0xff, /* LogicalMax(FF) */ + 0x75, 0x08, /* ReportSize(8) */ + 0x95, 0x40, /* ReportCount(64) */ + 0x81, 0x02, /* Input(Data, Var, Abs) */ + 0x09, 0x21, /* Usage(FIDO_DATA_OUT) */ + 0x19, 0x00, /* LogicalMin(0) */ + 0x29, 0xff, /* LogicalMax(FF) */ + 0x75, 0x08, /* ReportSize(8) */ + 0x95, 0x40, /* ReportCount(64) */ + 0x91, 0x02, /* Output(Data, Var, Abs) */ + 0xc0, /* EndCollection */ +}; + +int +main(int argc, void *argv[]) +{ + int fd; + + printf("size is %d\n", sizeof(report_desc)); + if (argc != 2) + exit(0); + printf("writing file\n"); + fd = open(argv[1], O_CREAT|O_TRUNC|O_WRONLY); + write (fd, report_desc, sizeof(report_desc)); + + return 0; +} diff --git a/fido_configfs.sh b/fido_configfs.sh new file mode 100755 index 0000000..2519261 --- /dev/null +++ b/fido_configfs.sh @@ -0,0 +1,73 @@ +#!/bin/bash +set -x + +configdir=/sys/kernel/config/usb_gadget +dev=fido2 +report_desc=`pwd`/fido + +if [ `whoami` != "root" ]; then + echo "Must be root to run this script" + exit 1; +fi + +if [ ! -f $report_desc ]; then + echo "ERROR: $report_desc must exist" + exit 1; +fi + +modprobe libcomposite +# expect systemd to have mounted configfs +if [ ! -d $configdir ]; then + echo "systemd failed to mount $configdir" + exit 1; +fi + +cd $configdir +mkdir $dev +cd $dev +## +# create bogus vendor and product +## +echo 0xabcd > idVendor +echo 0xabcd > idProduct +## +# Add identity strings +## +mkdir strings/0x409 +echo jejb > strings/0x409/manufacturer +echo "fido2 ctap" > strings/0x409/product +echo 12345678 > strings/0x409/serialnumber + +## +# Now make the Config +## +mkdir configs/c.1 +# conventional power number +echo 120 > configs/c.1/MaxPower +mkdir configs/c.1/strings/0x409 +# should set configuration but HID would override + +## +# now set up the function +## +mkdir functions/hid.usb0 +# we're a non boot hid +echo 0 > functions/hid.usb0/protocol +echo 0 > functions/hid.usb0/subclass +## +# All CTAP protocols require 64 byte reports +## +echo 64 > functions/hid.usb0/report_length +## +# Set the compiled report descriptor +## +$report_desc functions/hid.usb0/report_desc || exit 1 + +## +# now link the config to the interface +## +ln -s functions/hid.usb0 configs/c.1/ +modprobe dummy_hcd +echo "dummy_udc.0" > UDC + + |