Add event-based device discovery

Abierto
#328 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
rust

Línea de trabajo

Start by reading the device discovery and NFC/USB handling entry points; the issue does not name specific files or tests. Work out how the library represents FIDO devices and asynchronous events, then define an API for connection and disconnection notifications, including cancellation and device lifetimes. Done means callers can track devices as they connect and disconnect without polling.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

One thing I noticed is that we treat NFC readers like FIDO devices, but they're more akin to the Bluetooth adapter or USB host. I think we need to add an API to await the presence of a FIDO adapter on any NFC reader notifies that the a key is connected. I think doing something similar would be useful for USB too.

An example of what I'm thinking (might not be the best API):

/// Stream HID devices with FIDO usage pages as they connect and disconnect.
fn discover_devices(cancellation_token: CancellationToken): impl Stream<Output = HidDeviceEvent> { }

// The caller would likely want to collect the full list of devices
let devices: Arc<Mutex<HashMap<String, HidDevice>>> = Mutex::new(HashMap::new());

while let Some(device) = usb::discover_devices(cancellation_token).next().await {
  let devices = devices.clone();
  match event {
    // A HID device filters for devices with FIDO usage pages.
    // Open FIDO channel on connection
    HidDeviceEvent::Connected(id, device) => {
      let process_device_fut = async move {
        let channel = device.channel().await;
        // the device object will have to live longer than the monitor object, or else we'll have to do something funky with lifetimes.
        devices.lock().unwrap().insert(id, device);
        // process device
      });
      tokio::spawn(cancellation_token.child_token().run_until_cancelled(process_device_fut));
    },
    HidDeviceEvent::Disconnected(id) => {
      devices.lock().unwrap().remove(id);
    }
  }    
});

This allows caller to keep track of candidate devices as they come and go without spending CPU time polling or having to re-arm the request during a ceremony.

Maybe some of this could be abstracted into a monitor object for an easier to use API.

This can be useful for https://github.com/linux-credentials/credentialsd/issues/256.

Lenguaje dominante
Rust
Estrellas
602
Forks
33
Merge medio
1 d 13 h
PR fusionados (30 d)
9

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de linux-credentials/libwebauthn

Todos los issues de linux-credentials/libwebauthn

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.