Skip to content

Implement BLE MAC address randomization for privacy - #144

Merged
Mrwicks00 merged 7 commits into
StellarConduit:mainfrom
BigNathan1:implement/mac-randomization
Jun 22, 2026
Merged

Implement BLE MAC address randomization for privacy#144
Mrwicks00 merged 7 commits into
StellarConduit:mainfrom
BigNathan1:implement/mac-randomization

Conversation

@BigNathan1

Copy link
Copy Markdown

Implement BLE MAC address randomization for privacy

closes #38

Adds privacy enhancement through BLE Central MAC address rotation to prevent passive location tracking. This implementation defines the interface and rotation policy for both simulation and future Android JNI binding.

Changes:

  • Added MacAddressProvider trait and RandomMacProvider implementation for injectable MAC address generation with locally-administered bit set
  • Enhanced BleCentral with MAC rotation state management including rotate_mac_if_due() method with configurable 15-minute default interval
  • Added TopologyFlag::MacRotated variant to signal MAC rotation events to connected peers via topology updates
  • Implemented TransportManager.notify_mac_rotated() to drop all BLE connections after rotation (WiFi-Direct connections unaffected)
  • Integrated MAC rotation check into power_tick_at() to emit MacRotated flag on rotation

Implementation Details:

  • RandomMacProvider generates random 6-byte MAC addresses with locally-administered bit set (bit 1 of byte 0)
  • BleCentral tracks last rotation timestamp and checks if interval has elapsed before generating new MAC
  • Upon rotation, all BLE connections are dropped as they reference the old MAC address
  • New MAC address is broadcast to peers via TopologyFlag::MacRotated for peer re-discovery
  • Comprehensive test coverage including:
    • 1000 random MAC generations verify locally-administered bit compliance
    • Rotation timing and double-rotation prevention tests
    • BLE connection cleanup while preserving WiFi-Direct connections
    • Power tick integration with MacRotated flag in topology updates

Acceptance Criteria Met:

  • RandomMacProvider::generate() always sets locally-administered bit and clears multicast bit
  • BleCentral::rotate_mac_if_due() returns None before interval and Some(new_mac) after
  • No double-rotation: consecutive immediate calls return None after first rotation
  • TopologyFlag::MacRotated included in PowerTickOutcome::topology_flags on rotation
  • BLE connections dropped after notify_mac_rotated() call
  • WiFi-Direct connections survive MAC rotation
  • Full test suite coverage for BLE transport module

Brooks Student Portal added 4 commits June 22, 2026 02:56
Remove trailing blank line at end of ble_transport.rs and trailing
whitespace on an empty doc-comment line in unified.rs. Both are
normalized by `cargo fmt --check`, which was failing the CI step.
@BigNathan1
BigNathan1 force-pushed the implement/mac-randomization branch from 84ad68b to 1154da2 Compare June 22, 2026 10:48
Brooks Student Portal added 3 commits June 22, 2026 03:58
Sort the ble_transport import group in unified.rs and wrap two
over-length send_with_timeout calls in the gossip integration test,
matching cargo fmt output. The test-file lines were pre-existing
formatting violations on main.
- Avoid use-after-move of ble_peers in notify_mac_rotated by iterating
  over a reference so the subsequent len() read stays valid.
- Drop unused mut bindings in two BleCentral rotation tests.

These were masked by the earlier formatting failure and surface once
cargo clippy --all-targets --all-features -- -D warnings runs.
The 'outer loop only ever exits via `break 'outer`, so it never iterates
a second time, tripping clippy::never_loop (deny-by-default). Convert it
to a labeled block, preserving the advertise-once-then-accept behavior
and the two `break 'outer` exit paths.
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.

2 participants