// Copyright (C) 2022 Robin Krahl // SPDX-License-Identifier: CC0-1.0 //! Executes a CTAP1/U2F command on all available CTAPHID devices that support it. fn main() -> Result<(), Box> { env_logger::init(); let hidapi = hidapi::HidApi::new()?; let devices: Vec<_> = hidapi .device_list() .filter(|device| ctaphid::is_known_device(*device)) .collect(); for device_info in devices { let device = device_info.open_device(&hidapi)?; let device = ctaphid::Device::new(device, device_info.to_owned())?; let status = if device.capabilities().has_msg() { let response = device.ctap1(&[0x00, 0x03, 0x00, 0x00, 0x00])?; let n = response.len(); assert!(n > 2); assert_eq!(&response[n - 2..], &[0x90, 0x00]); String::from_utf8_lossy(&response[..n - 2]).into_owned() } else { "no CTAP1 support".to_owned() }; println!("- {}: {}", device_info.path().to_string_lossy(), status); } Ok(()) }