Skip to content

daemon: Offer hybrid once Bluetooth is turned on during a request - #266

Open
kpanuragh wants to merge 1 commit into
linux-credentials:mainfrom
kpanuragh:update-transports
Open

kpanuragh wants to merge 1 commit into
linux-credentials:mainfrom
kpanuragh:update-transports

Conversation

@kpanuragh

@kpanuragh kpanuragh commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #206 (first part: updating the transports offered; prompting the user to turn Bluetooth on is left for a follow-up).

Rebased on main, and reworked for main's transport model: transports are now detected once in init_request, stored in the request context, sent to the UI in CreateSession, and start_discovery starts exactly those.

Problem

libwebauthn's available_transports() reports Ble/Hybrid whenever a Bluetooth adapter exists. BlueZ keeps the adapter while Bluetooth is turned off, so the QR code option was offered even though it couldn't work. And the transports were only detected once, so turning Bluetooth on mid-request didn't help.

Changes

  • credential_service/bluetooth.rs: asks BlueZ (GetManagedObjects on the system bus) whether any org.bluez.Adapter1 is Powered. init_request only offers hybrid then. The call gives up after 1 s, so a stuck bluetoothd can't hold up a request, and sets NO_AUTO_START, so it never starts BlueZ.
  • start_discovery: if hybrid wasn't offered, a watcher asks BlueZ every 2 s while it has an adapter that is turned off. It stops if BlueZ isn't running or has no adapter, and when the request's cancellation token fires. Once an adapter is powered on, add_hybrid adds HybridQr to the request's transports (checking the request ID, so a late start can't attach to a different request), the UI gets the new list, and hybrid discovery starts.
  • New UI control method NotifyTransportsChanged(session_handle, as transports, a{sv} options) / BackgroundEvent::TransportsChanged: the full new list, in the same form as CreateSession's transports. Listed in the changelog under UI Controller API.
  • UI: applies the new list, but keeps transports that gave up earlier in the request (TransportUnavailable) hidden, since the daemon still lists them.

Limitations

  • Hybrid is added at most once per request. If Bluetooth is turned off again and hybrid gives up, it isn't offered again, and a request that started with Bluetooth on doesn't watch for it.
  • A late HybridStarted sets the QR prompt even if the user is on another transport's page. That's existing UI behaviour, but it can now happen mid-request.

Open questions

  • Polling: I poll instead of subscribing to PropertiesChanged/InterfacesAdded from BlueZ, to keep this small. It only runs while a request waits for an adapter that is turned off. Happy to switch to signals if you prefer.
  • Behaviour change: with Bluetooth off (or BlueZ unreachable), hybrid is no longer in the initial list.
  • Multiple adapters: the check accepts any powered adapter, but libwebauthn uses the first one btleplug reports. With several adapters where that one is off, hybrid can still fail (noted in a comment).

Testing

  • Watcher: hybrid starts after Bluetooth is turned on, and the new list is sent first. The watcher ends on cancellation, when there is no Bluetooth to wait for, and when the request is gone, without starting hybrid.
  • Other unit tests: BlueZ adapter state parsing, dropping Bluetooth transports when nothing is powered, the request-ID check in add_hybrid, and the UI applying a new list while keeping stopped transports hidden.
  • BlueZ: the same no-auto-start call against this machine's BlueZ reports the adapter as powered.
  • cargo test --bins (daemon 70, UI 7), cargo clippy --all-targets -D warnings, cargo fmt --check.
  • Not yet re-run on this version: the end-to-end test I did on the first version (Bluetooth off at request start, turned on mid-request, QR code appearing in the open dialog, then a full hybrid registration with a phone).

@kpanuragh

kpanuragh commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Also tested the full flow with a real phone. I started a create request with Bluetooth off, turned Bluetooth on about 8 s in, and the QR code appeared within the same second. I scanned it with a phone and approved; the phone went through ProximityCheck → Connecting → Connected → PresenceRequired, and CreateCredential returned a public-key registration response for https://example.com (about 30 s from Bluetooth on to completion). Daemon → UI calls: CreateSession (Usb), NotifyDevicesChanged (Usb), NotifyDevicesChanged (Usb, HybridQr), NotifyHybridStarted, NotifyHybridConnecting, NotifyHybridConnected, NotifyCeremonyCompleted.

@iinuwa

iinuwa commented Nov 13, 2026

Copy link
Copy Markdown
Member

I think I'd like ultimately like to resolve this at the libwebauthn layer, where libwebauthn gives an API to wait for a suitable bluetooth adapter and starts a request, rather than that being credentialsd's responsibility.

However, I think this PR is good for dicsussing how we might consume that API though on the UI side. As far as the backend API, @msirringhaus and I have been discussing this a bit. I'm leaning toward having a Transports and Devices property that can be subscribed to, but we can discuss other options too. It's a bit confusing whether hybrid is a "device" or a "transport" though. It should probably be presented to the UI as a single thing rather than one-per-adapter, because that doesn't mean anything to the UI; the user just scans, and probably whichever adapter gets the advertisement first wins, just like with USB devices.

@kpanuragh

Copy link
Copy Markdown
Contributor Author

Thanks, agreed: waiting for a usable adapter belongs in libwebauthn. The polling of BlueZ here is a stopgap until it has an API for that.

Some notes from wiring up the UI side, in case they help with the API:

  • What the UI needs is the list of things the user can use right now, plus a notification when it changes. In this PR that's NotifyDevicesChanged(Vec<Device>), which is effectively a Devices property with change notification. A real D-Bus property with PropertiesChanged would fit it directly: the UI already just re-renders its device list from whatever it gets.
  • Hybrid as one entry: agreed. Here it's already a single HybridQr device no matter how many adapters there are, offered when any adapter is powered.
  • Transports vs Devices: for showing choices, Devices alone is enough. A separate Transports property would be useful if it also says why a transport is unavailable, e.g. "Bluetooth is off". Then the UI could offer "turn on Bluetooth to use your phone" instead of just not showing hybrid, which was the follow-up I had in mind for Update authenticator source list #206.

How would you like to handle this PR in the meantime? I can keep it open as the UI-side piece and switch it to the Devices property (with Transports if you want it) once the libwebauthn API exists, or close it and come back with a new PR then.

1 similar comment
@kpanuragh

Copy link
Copy Markdown
Contributor Author

Thanks, agreed: waiting for a usable adapter belongs in libwebauthn. The polling of BlueZ here is a stopgap until it has an API for that.

Some notes from wiring up the UI side, in case they help with the API:

  • What the UI needs is the list of things the user can use right now, plus a notification when it changes. In this PR that's NotifyDevicesChanged(Vec<Device>), which is effectively a Devices property with change notification. A real D-Bus property with PropertiesChanged would fit it directly: the UI already just re-renders its device list from whatever it gets.
  • Hybrid as one entry: agreed. Here it's already a single HybridQr device no matter how many adapters there are, offered when any adapter is powered.
  • Transports vs Devices: for showing choices, Devices alone is enough. A separate Transports property would be useful if it also says why a transport is unavailable, e.g. "Bluetooth is off". Then the UI could offer "turn on Bluetooth to use your phone" instead of just not showing hybrid, which was the follow-up I had in mind for Update authenticator source list #206.

How would you like to handle this PR in the meantime? I can keep it open as the UI-side piece and switch it to the Devices property (with Transports if you want it) once the libwebauthn API exists, or close it and come back with a new PR then.

libwebauthn reports Bluetooth as available whenever an adapter exists,
even while it is powered off, and the transports were only detected once
at the start of a request. So with Bluetooth off, the QR code option was
offered but could not work, and turning Bluetooth on did not help.

- Ask BlueZ whether an adapter is powered on, and only offer hybrid then.
  The check gives up after 1 s and doesn't start BlueZ if it isn't
  running.
- If hybrid was not offered when discovery starts, check BlueZ every 2 s
  while it has an adapter that is turned off. Once one is turned on, add
  hybrid to the request's transports, send the UI the new list (new
  NotifyTransportsChanged UI control method) and start hybrid discovery.
  This happens at most once per request.
- The UI keeps transports that gave up earlier in the request hidden
  when it gets a new list.

Closes linux-credentials#206
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update authenticator source list

2 participants