BLE Privacy, Address Randomisation and GATT Security
Two questions remain once a BLE device is paired. Privacy: can strangers recognise the device, and therefore its owner, wherever it goes? A fitness band that advertises the same address every day is a tracking beacon. Access control: once connected, what may a client read and write? A smart plug whose "relay" characteristic accepts writes from anyone in range can be switched by anyone in range. This lesson computes Bluetooth's private addresses with the specification's own function and test vector, then audits a GATT table.
Resolvable private addresses
A device with LE privacy doesn't advertise a fixed address. It generates a resolvable private address (RPA) every few minutes (15 minutes is the usual default) from a 128-bit identity resolving key (IRK) that it shares only with bonded peers during pairing:
- choose 24 bits whose top two bits are
01(the RPA marker, address types); - compute , where encrypts padded with zeros using AES-128 and keeps the lowest 24 bits;
- the address is followed by (48 bits).
A bonded phone holds the watch's IRK, so for every address it sees it recomputes the hash and checks for a match. Strangers see a new, unrelated-looking address every few minutes. The program checks against the sample data in the Bluetooth Core Specification, then generates three addresses for the same watch and resolves everything a phone hears:
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
def ah(irk, prand):
"""Bluetooth's address hash: ah(k, r) = AES-128(k, 104 zero bits || r), keep the low 24 bits."""
enc = Cipher(algorithms.AES(irk), modes.ECB()).encryptor()
return (enc.update(bytes(13) + prand) + enc.finalize())[-3:]
# Bluetooth Core Specification sample data for ah
irk = bytes.fromhex("ec0234a357c8ad05341010a60a397d9b")
print("ah test vector:", ah(irk, bytes.fromhex("708194")).hex(), "(expected 0dfbaa)")
def make_rpa(irk, prand): # prand: 24 bits whose two top bits are 01
assert prand[0] >> 6 == 0b01
return ":".join(f"{b:02x}" for b in prand + ah(irk, prand))
def resolve(addr, bonded):
raw = bytes.fromhex(addr.replace(":", ""))
if raw[0] >> 6 != 0b01:
return "not a resolvable private address"
for name, k in bonded.items():
if ah(k, raw[:3]) == raw[3:]:
return f"resolves to bonded device '{name}'"
return "unknown device (can't be linked)"
watch_irk = irk # the watch's identity resolving key (test value)
bonded = {"my-watch": watch_irk, "my-plug": bytes.fromhex("00112233445566778899aabbccddeeff")}
# The watch changes its address every ~15 minutes; prand values are fixed here, real ones are fresh
seen = [make_rpa(watch_irk, bytes.fromhex(p)) for p in ("708194", "4a01b2", "55c3d4")]
seen += ["5f:00:11:22:33:44", "c2:00:00:b1:e0:07"]
for addr in seen:
print(f"{addr} phone: {resolve(addr, bonded):38} stranger: {resolve(addr, {})}")ah test vector: 0dfbaa (expected 0dfbaa)
70:81:94:0d:fb:aa phone: resolves to bonded device 'my-watch' stranger: unknown device (can't be linked)
4a:01:b2:0d:98:e1 phone: resolves to bonded device 'my-watch' stranger: unknown device (can't be linked)
55:c3:d4:d8:5c:7c phone: resolves to bonded device 'my-watch' stranger: unknown device (can't be linked)
5f:00:11:22:33:44 phone: unknown device (can't be linked) stranger: unknown device (can't be linked)
c2:00:00:b1:e0:07 phone: not a resolvable private address stranger: not a resolvable private address
The three watch addresses look unrelated, and to a stranger they are; the phone links all three to "my-watch". The plug uses a static address (top bits 11) and is recognisable by anyone, which is acceptable for a device fixed to a wall and not for one that travels with a person.
Where privacy still leaks: an RPA is useless if the advertisement carries a fixed name, serial number or a counter that doesn't change with the address. Researchers have tracked devices through exactly such payload fields, and through addresses that rotate at a different moment than the payload. Rotate everything together, and put identifying data behind authenticated reads.
How it is detected: scan your own device over an hour in a lab and check whether any field (address, name, manufacturer data, TX power, service data) stays constant; check the rotation interval; check that the device doesn't fall back to its identity address after a reboot.
How it is fixed: enable LE privacy (controller-based address resolution is standard since Bluetooth 4.2), rotate addresses at least every 15 minutes, keep the advertising payload free of identifiers, and keep IRKs in protected storage.
GATT permissions
Every characteristic in a GATT server has properties (read, write, write-without-response, notify) and permissions that the stack enforces before the application sees a request:
| Permission level | Means | Gives |
|---|---|---|
| open | any connected client | nothing; anyone in range |
| encryption required | the link is encrypted, after any pairing | protection from listeners; with Just Works anyone can pair and then write |
| authentication required | encrypted link from an authenticated pairing (Numeric Comparison, Passkey, OOB) | protection from listeners and from strangers who can't complete authenticated pairing |
| authorisation | the application decides per request | e.g. only the owner's account, checked by an app-layer token |
The lab plug's GATT table and an audit that flags sensitive characteristics without the right level:
# GATT table of the lab smart plug, as its firmware declares it (synthetic). Permissions per characteristic:
# "open" = no security, "enc" = encrypted link (any pairing, also Just Works), "auth" = authenticated pairing (MITM-protected)
GATT = [
# (service, characteristic, properties, read permission, write permission)
("Device Information", "Model Number", "read", "open", None),
("Device Information", "Serial Number", "read", "open", None),
("Device Information", "Firmware Revision","read", "open", None),
("LabPlug Control", "Relay State", "read,write", "open", "open"),
("LabPlug Control", "Schedule", "read,write", "enc", "enc"),
("LabPlug Setup", "Wi-Fi Credentials","write", None, "enc"),
("LabPlug Setup", "Factory Reset", "write", None, "open"),
("LabPlug Update", "Firmware Chunk", "write-no-resp", None, "auth"),
]
SENSITIVE_WRITE = {"Relay State", "Wi-Fi Credentials", "Factory Reset", "Firmware Chunk", "Schedule"}
SENSITIVE_READ = {"Serial Number", "Schedule"}
RANK = {None: 3, "open": 0, "enc": 1, "auth": 2}
for svc, ch, props, rd, wr in GATT:
f = []
if ch in SENSITIVE_WRITE and wr is not None and RANK[wr] < 2:
f.append(f"write needs only '{wr}': require authenticated pairing")
if ch in SENSITIVE_READ and rd is not None and RANK[rd] < 1:
f.append("readable without pairing")
print(f"{svc:18} {ch:18} r={str(rd):4} w={str(wr):4} " + ("; ".join(f) if f else "ok"))Device Information Model Number r=open w=None ok
Device Information Serial Number r=open w=None readable without pairing
Device Information Firmware Revision r=open w=None ok
LabPlug Control Relay State r=open w=open write needs only 'open': require authenticated pairing
LabPlug Control Schedule r=enc w=enc write needs only 'enc': require authenticated pairing
LabPlug Setup Wi-Fi Credentials r=None w=enc write needs only 'enc': require authenticated pairing
LabPlug Setup Factory Reset r=None w=open write needs only 'open': require authenticated pairing
LabPlug Update Firmware Chunk r=None w=auth ok
Four writes are too weak. The relay and the factory reset accept writes from anyone in range without pairing. The schedule and the Wi-Fi credentials require encryption only, which with a display-less plug means Just Works: anyone who can pair during the pairing window can write them (pairing methods). The serial number is readable without pairing. The firmware characteristic passes the permission check, but permissions alone don't make updates safe: the image itself must be signed and checked by the device (update security).
How GATT weaknesses are detected
- Enumerate your own device with a generic GATT client app on a test phone: list services, characteristics and properties, then try reads and writes without pairing, after Just Works, and after authenticated pairing. Record which succeed.
- Read the firmware's GATT declarations (most SDKs declare permissions in a table like the one above) and compare with a list of sensitive characteristics.
- Check app-layer protections: some products "encrypt" characteristic values with a key embedded in the app, which anyone can extract (hard-coded secrets).
How it is fixed
- Classify characteristics (read-sensitive, write-sensitive) and give every sensitive one authenticated permissions.
- Combine with a pairing design that can actually authenticate (OOB via a QR code, a pairing window opened by a button press).
- For multi-user devices, add authorisation: the app proves the user's identity with a token from the cloud account, checked by the device.
- Put destructive operations (factory reset, firmware) behind both a physical action and authenticated access.
Pitfalls
- Treating "encryption required" as "only the owner": with Just Works, any nearby phone can become a paired client.
- Relying on the companion app to hide characteristics: any BLE client sees the whole GATT table.
- Rotating the address but advertising a fixed device name.
Practice
1. Generate a fourth watch address with prand c00001. What goes wrong and why?
make_rpa refuses it: the top bits of 0xc0 are 11, the marker of a static address, not 01. An RPA's prand must start with the bits 01.
2. Fix the plug's GATT table so the audit reports only "ok". What else do you need for the fix to be real?
Set write permissions of Relay State, Schedule, Wi-Fi Credentials and Factory Reset to auth, and Serial Number's read to enc (or auth). For auth to be reachable, the plug needs an authenticated pairing method, such as OOB through a QR code, or the owner can't pair at all.
3. A tracker rotates its RPA every 15 minutes but advertises a battery level and a 4-byte counter that increments by one every minute. Can a stranger follow it?
Yes. The counter continues across address changes, linking old and new addresses; the battery level helps too. The counter must reset or be hidden when the address changes.
Test yourself
Who can resolve a device's resolvable private address?
- Anyone
- Only bonded peers that hold its IRK
- Only the Bluetooth SIG
- Nobody
What are the top two bits of an RPA?
- 00
- 01
- 10
- 11
The plug's Wi-Fi credentials characteristic requires encryption only. Why is that insufficient?
- Encryption is broken
- The plug can only do Just Works pairing, so anyone who pairs can write it
- Writes are never encrypted
- GATT has no permissions
What can still leak identity despite address rotation?
- Nothing
- Constant fields in the advertisement, such as a fixed name or counter
- The channel number
- The AES key