Path: blob/main/devices/src/usb/backend/fido_backend/constants.rs
5394 views
// Copyright 2024 The ChromiumOS Authors1// Use of this source code is governed by a BSD-style license that can be2// found in the LICENSE file.34use usb_util::DescriptorType;56// How long it takes for the security key to become inactive and time out all previously pending7// transactions since last activity.8pub const TRANSACTION_TIMEOUT_MILLIS: u64 = 120_000;910// How long to wait before timing out and canceling a USB transfer from the guest if the host11// security key is unresponsive.12pub const USB_TRANSFER_TIMEOUT_MILLIS: u64 = 5_000;1314// 5ms is the default USB interrupt polling rate according to specs.15pub const USB_POLL_RATE_MILLIS: u64 = 5;1617// Some applications expect a very short RTT when handling packets between host key and guest, half18// a millisecond seems like a decent compromise.19pub const PACKET_POLL_RATE_NANOS: u64 = 50_000;2021// Total max number of transactions we can hold in our key. Any more transactions will push older22// transactions away from the stack.23pub const MAX_TRANSACTIONS: usize = 4;2425// Max number of incoming packets still to be processed by the guest26pub const U2FHID_MAX_IN_PENDING: usize = 32;2728pub const U2FHID_PACKET_SIZE: usize = 64;29pub const PACKET_INIT_HEADER_SIZE: usize = 7;30pub const PACKET_CONT_HEADER_SIZE: usize = 5;31pub const PACKET_INIT_DATA_SIZE: usize = U2FHID_PACKET_SIZE - PACKET_INIT_HEADER_SIZE;32pub const PACKET_CONT_DATA_SIZE: usize = U2FHID_PACKET_SIZE - PACKET_CONT_HEADER_SIZE;3334pub const CID_SIZE: usize = 4;35pub const BROADCAST_CID: [u8; CID_SIZE] = [0xFF, 0xFF, 0xFF, 0xFF];3637pub const NONCE_SIZE: usize = 8;38pub const EMPTY_NONCE: [u8; NONCE_SIZE] = [0u8; NONCE_SIZE];3940// It's a valid init packet only if the 7th bit of the cmd field is set41pub const PACKET_INIT_VALID_CMD: u8 = 0b1000_0000;42pub const U2FHID_ERROR_CMD: u8 = 0xBF;4344pub const U2FHID_CONTROL_ENDPOINT: u8 = 0x00;45pub const U2FHID_IN_ENDPOINT: u8 = 0x81;46pub const U2FHID_OUT_ENDPOINT: u8 = 0x01;4748// Generic HID commands49pub const HID_GET_IDLE: u8 = 0x02;50pub const HID_SET_IDLE: u8 = 0x0A;51pub const HID_GET_REPORT_DESC: u8 = 0x22;5253pub const HID_MAX_DESCRIPTOR_SIZE: usize = 4096;5455// Descriptor data taken from: https://github.com/gl-sergei/u2f-token/blob/master/src/usb-hid.c56// With minor modifications for our own PID and VID and other strings57pub const U2FHID_DEVICE_DESC: &[u8] = &[5818,59DescriptorType::Device as u8,600x10,610x01,620x00,630x00,640x00,650x40,66// Google Vendor ID670xd1,680x18,69// Unique Product ID700xd0,710xf1,720x00,730x01,740,750,760,771,78];7980pub const HID_REPORT_DESC_HEADER: &[u8] = &[810x06, 0xd0, 0xf1, // Usage Page (FIDO)820x09, 0x01, // Usage (FIDO)83];8485pub const U2FHID_CONFIG_DESC: &[u8] = &[869,87DescriptorType::Configuration as u8,88/* Configuration Descriptor. */8941,900x00, /* wTotalLength. */910x01, /* bNumInterfaces. */920x01, /* bConfigurationValue. */930, /* iConfiguration. */940x80, /* bmAttributes. */9515, /* bMaxPower (100mA). */96/* Interface Descriptor. */979, /* bLength: Interface Descriptor size */98DescriptorType::Interface as u8,990, /* bInterfaceNumber: Number of Interface */1000x00, /* bAlternateSetting: Alternate setting */1010x02, /* bNumEndpoints: Two endpoints used */1020x03, /* bInterfaceClass: HID */1030x00, /* bInterfaceSubClass: no boot */1040x00, /* bInterfaceProtocol: 0=none */1050x00, /* iInterface */106/* HID Descriptor. */1079, /* bLength: HID Descriptor size */1080x21, /* bDescriptorType: HID */1090x10,1100x01, /* bcdHID: HID Class Spec release number */1110x00, /* bCountryCode: Hardware target country */1120x01, /* bNumDescriptors: Number of HID class descriptors to follow */1130x22, /* bDescriptorType */1140x22,1150, /* wItemLength: Total length of Report descriptor */116/* Endpoint IN1 Descriptor */1177, /* bLength: Endpoint Descriptor size */118DescriptorType::Endpoint as u8,1190x81, /* bEndpointAddress: (IN1) */1200x03, /* bmAttributes: Interrupt */1210x40,1220x00, /* wMaxPacketSize: 64 */1230x05, /* bInterval (5ms) */124/* Endpoint OUT1 Descriptor */1257, /* bLength: Endpoint Descriptor size */126DescriptorType::Endpoint as u8,1270x01, /* bEndpointAddress: (OUT1) */1280x03, /* bmAttributes: Interrupt */1290x40,1300x00, /* wMaxPacketSize: 64 */1310x05, /* bInterval (5ms) */132];133134pub const HID_REPORT_DESC: &[u8] = &[1350x06, 0xd0, 0xf1, /* USAGE_PAGE (FIDO Alliance) */1360x09, 0x01, /* USAGE (Keyboard) */1370xa1, 0x01, /* COLLECTION (Application) */1380x09, 0x20, /* USAGE (Input report data) */1390x15, 0x00, /* LOGICAL_MINIMUM (0) */1400x26, 0xff, 0x00, /* LOGICAL_MAXIMUM (255) */1410x75, 0x08, /* REPORT_SIZE (8) */1420x95, 0x40, /* REPORT_COUNT (64) */1430x81, 0x02, /* INPUT (Data,Var,Abs); Modifier byte */1440x09, 0x21, /* USAGE (Output report data) */1450x15, 0x00, /* LOGICAL_MINIMUM (0) */1460x26, 0xff, 0x00, /* LOGICAL_MAXIMUM (255) */1470x75, 0x08, /* REPORT_SIZE (8) */1480x95, 0x40, /* REPORT_COUNT (64) */1490x91, 0x02, /* OUTPUT (Data,Var,Abs); Modifier byte */1500xc0, /* END_COLLECTION */151];152153154