G4: F17 — re-raise BLE pairing failure instead of swallowing

Why: When BLE pairing failed during connect(), the exception was caught
as a warning and connect() continued normally. This left the transport
in a half-usable state — the BLE link was up but the pairing handshake
never completed, so encrypted characteristics could silently fail.
Now the pairing exception disconnects the client and re-raises, giving
the caller a clean failure. Updated the pre-existing
test_ble_connection_with_pin_failed_pairing test to assert the re-raise
behavior instead of the old swallow-and-continue behavior.
Refs: Forensics report finding F17
This commit is contained in:
Matthew Wolter
2026-04-11 20:25:04 -07:00
parent fe0dcac90f
commit 76e2e54157
2 changed files with 15 additions and 13 deletions

View File

@@ -116,9 +116,12 @@ class BLEConnection:
await self.client.pair()
logger.info("BLE pairing successful")
except Exception as e:
logger.warning(f"BLE pairing failed: {e}")
# Don't fail the connection if pairing fails, as the device
# might already be paired or not require pairing
logger.error(f"BLE pairing failed: {e}")
# A failed pairing leaves the transport in a half-usable
# state — re-raise so the caller gets a clean failure
# instead of a silently degraded connection.
await self.client.disconnect()
raise
except BleakDeviceNotFoundError:
return None