refactor: do not use service_data mac#323
refactor: do not use service_data mac#323IvoGruber wants to merge 1 commit intoBluetooth-Devices:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #323 +/- ##
==========================================
- Coverage 83.55% 83.30% -0.26%
==========================================
Files 6 6
Lines 663 653 -10
Branches 99 96 -3
==========================================
- Hits 554 544 -10
- Misses 84 85 +1
+ Partials 25 24 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
What I remember is that we had an option to include a different MAC address in the message, for a device that is sending the data from a second device, e.g. the indoor temperature sensor is sending the data from the outdoor temperature sensor. In the V1 docs, I still see something in the docs, in the table in the BTHome Data format section (type 4) (although I agree there isn’t any additional information how this should work). Moreover, looking at the current code, this isn’t functional in v1. In v2, in the test, test_bthome_with_mac is a test which includes a MAC address in the payload. Apparanty 0x42 means Mac included in the payload, but I don’t see anything in the v2 docs. The test isn’t really good, as the Mac of the device is the same as what is added in the payload. Question is, should we remove it, or add it to the docs. I think removing it should be ok, as we already have the option to have multiple sensors. The only downside it that using a different Mac will create a different device in HA, which is no longer possible than. |
This is another thing I do not understand. Current code does not use adv_info for V1 at all. It is even not removed when creating the payload for the sensor data. So reading the code I would assume V1 never hat that extra byte in contrast to the spec. Maybe refactoring things broke that, but I doubt, since all the v1 tests are still running. |
Also not sure. I doubt that current code would create a different device in HA yet, since that mac is used for logging only and for the nonce for decryption. So removing it would maybe break some devices using encryption if they use that feature. |
I don’t think this was functional in v1. In 3.15.0, this was the code bthome-ble/src/bthome_ble/parser.py Line 244 in 5b9e2ce |
|
Maybe check this issue. #42 On macOS iOS systems apparently the MAC address isn’t included. There is also a note that I should still update the docs :-). I think this is related to the fact that some devices use a rotating MAC address, that changes every x minutes, to prevent tracking. In these cases, you can use a alternative fixed MAC as a workaround. |
So use case is following: They want to use bthome on Mac OS, but can not access the MAC. So to have encrypted data, they want to put that again in the non encrypted part of the service_data. The even want to do that on a mobile device. Reading on some famous LLM why MacOS is hiding/randomizing MACs makes me even more skeptical whether we should do that. A user that want's encryption very likely also wants privacy. So instead of having MAC exposed even more we should stop using the MAC for encryption. |
@Ernst79 Decision is up to you but this would be my proposal:
|
This would be my first proposal to solve use case described in issue #42:
We can burn another bit in the adv_info to support that mode. |
@Ernst79 can you explain how HA decides when to create a new device based on the bthome code base? |
I don’t know exactly (anymore), but it all starts with the Bluetooth integration, which filters the uuid. If it is a BTHome uuid, the message gets forwarded to the BTHome integration. I think a device gets it unique id here. however, I don’t see the get_mac_readable function being used to set it as a different device in HA. I think you are right, it isn’t being used to create a second device. It looks like it is only being used in the nonce for encryption. |
|
I agree with your proposal, let’s use another bit in the adv_info to create a better implementation. After finishing, I do propose to add the documentation for the non-documented option with the MAC address, and add a warning block that the method contains some security flaws, after which we can tell the user to use the new method instead. |
Shall we invite authors in issue #42 to also discuss this or is this automatically done by mentioning the issue here?! |
|
It’s always good to invite them. Not sure if they are already informed. |
Bluetooth 5.4 standard implements the Encrypted Advertising Data (EAD) function. |
This is for discussion first. Do not understand, why this was used. The spec on bthome.io does not even talk about the flag (at least i did not found anything about it).
@Ernst79:
Can you explain why it exists in the code base?
Can we even get rid of checking for this flag?