BLE Pairing Methods and Their MITM Resistance
When your phone pairs with a smart plug, the two devices have never met, share no secret and may have no screen or keyboard between them. Pairing has to create a shared key anyway, and the protection that key gets depends almost entirely on which pairing method the devices pick, which in turn depends on their buttons and displays. A plug with no display can't do better than "Just Works", which a man in the middle defeats, unless the product adds an out-of-band channel. This lesson turns the Bluetooth specification's method selection into a decision table and reads off what each choice protects.
Two pairing generations
LE Legacy Pairing (Bluetooth 4.0 and 4.1) derives the keys from a temporary key (TK): zero for Just Works, a six-digit number for Passkey Entry, or 128 bits from an out-of-band channel. Everything else in the exchange is visible on air. Someone who records a legacy pairing can try every TK: Just Works has one value and Passkey Entry , a second's work. Mike Ryan's crackle tool demonstrated this in 2013. Legacy pairing protects nothing against a passive listener who records the pairing, except with a strong OOB key.
LE Secure Connections (Bluetooth 4.2, 2014) starts with an elliptic-curve Diffie–Hellman exchange on P-256 (Diffie–Hellman). A passive listener learns nothing, whatever the method. The method now only decides whether the exchange is authenticated, that is, whether a man in the middle who runs two separate ECDH exchanges (one with each device) would be noticed:
| Method | How the user takes part | MITM resistance (LE Secure Connections) |
|---|---|---|
| Just Works | nothing, or "Pair?" yes/no | none: the two ECDH exchanges of a MITM go unnoticed |
| Numeric Comparison | both devices show the same 6-digit number; the user confirms they match | a MITM succeeds with probability per attempt, since its two exchanges give different numbers |
| Passkey Entry | one device shows a 6-digit passkey, the user types it on the other (or types the same on both) | about per attempt if the passkey is fresh; the passkey is revealed bit by bit during the protocol, so a static passkey must never be reused |
| Out of Band (OOB) | data exchanged over NFC or a QR code | as strong as the OOB channel; 128-bit values |
How the method is chosen
At the start of pairing both devices send their IO capabilities (DisplayOnly, DisplayYesNo, KeyboardOnly, NoInputNoOutput, KeyboardDisplay), whether they have OOB data, and an MITM flag saying whether they require authentication. The specification's mapping table then fixes the method. The program encodes that table and evaluates typical pairs:
# Pairing-method selection of Bluetooth LE from the two devices' IO capabilities
# (initiator row, responder column; after the Core Specification's mapping table). JW = Just Works,
# PK = Passkey Entry, NC = Numeric Comparison (LE Secure Connections only).
IO = ["DisplayOnly", "DisplayYesNo", "KeyboardOnly", "NoInputNoOutput", "KeyboardDisplay"]
SC_TABLE = {
"DisplayOnly": ["JW", "JW", "PK", "JW", "PK"],
"DisplayYesNo": ["JW", "NC", "PK", "JW", "NC"],
"KeyboardOnly": ["PK", "PK", "PK", "JW", "PK"],
"NoInputNoOutput": ["JW", "JW", "JW", "JW", "JW"],
"KeyboardDisplay": ["PK", "NC", "PK", "JW", "NC"],
}
NAMES = {"JW": "Just Works", "PK": "Passkey Entry", "NC": "Numeric Comparison", "OOB": "Out of Band"}
def method(init, resp, secure_connections, oob=(False, False), mitm_required=True):
if (secure_connections and any(oob)) or all(oob):
m = "OOB"
elif not mitm_required:
m = "JW"
else:
m = SC_TABLE[init][IO.index(resp)]
if m == "NC" and not secure_connections: # legacy pairing has no numeric comparison
m = "JW" if (init, resp) == ("DisplayYesNo", "DisplayYesNo") else "PK"
eavesdrop_safe = secure_connections or m == "OOB" # legacy keys come from a TK of at most 10^6 values
mitm_safe = m != "JW"
return NAMES[m], eavesdrop_safe, mitm_safe
cases = [
("phone + smart plug (no display)", "KeyboardDisplay", "NoInputNoOutput", True),
("phone + watch (display, yes/no)", "KeyboardDisplay", "DisplayYesNo", True),
("phone + lock with a display", "KeyboardDisplay", "DisplayOnly", True),
("phone + old keyboard, legacy", "KeyboardDisplay", "KeyboardOnly", False),
("phone + old sensor, legacy", "KeyboardDisplay", "NoInputNoOutput", False),
]
print(f"{'pair':34} {'SC':3} {'method':19} {'passive listener':17} MITM")
for name, init, resp, sc in cases:
m, eav, mitm = method(init, resp, sc)
print(f"{name:34} {'yes' if sc else 'no':3} {m:19} {'safe' if eav else 'EXPOSED':17} {'resisted' if mitm else 'NOT resisted'}")
m, eav, mitm = method("KeyboardDisplay", "NoInputNoOutput", True, oob=(True, False))
print(f"{'phone + plug, QR code (OOB)':34} yes {m:19} {'safe' if eav else 'EXPOSED':17} {'resisted' if mitm else 'NOT resisted'}")pair SC method passive listener MITM
phone + smart plug (no display) yes Just Works safe NOT resisted
phone + watch (display, yes/no) yes Numeric Comparison safe resisted
phone + lock with a display yes Passkey Entry safe resisted
phone + old keyboard, legacy no Passkey Entry EXPOSED resisted
phone + old sensor, legacy no Just Works EXPOSED NOT resisted
phone + plug, QR code (OOB) yes Out of Band safe resisted
Read it row by row:
- Phone and plug: the plug has no input and no output, so even with Secure Connections the method is Just Works. The link is encrypted against listeners, but anyone who gets between phone and plug during pairing can sit in the middle for good.
- Watch and lock with a display: Numeric Comparison and Passkey Entry give real MITM protection.
- Legacy devices: Passkey Entry resists a MITM only in principle (the passkey space is small enough to search during the pairing), and a recording exposes all keys.
- QR code on the plug's label (OOB): the cheapest way to give a display-less device authenticated pairing. The phone scans a code with the plug's public-key commitment or a 128-bit secret, and the pairing becomes as strong as keeping that label private.
Note the mitm_required parameter: if neither device asks for MITM protection, Just Works is used even between two devices with displays. Firmware that forgets to set the flag silently downgrades its own pairing.
Known pairing-protocol attacks, briefly
- Invalid curve attack (2018, CVE-2018-5383): some implementations didn't check that the peer's ECDH public key lay on P-256, letting a MITM learn the key. Fix: validate public keys (the specification was updated to require it).
- Method confusion (2020): a MITM makes one device use Numeric Comparison and the other Passkey Entry, so the user compares a passkey as if it were a confirmation number. Fix: user interfaces that clearly distinguish the two; specification guidance.
- Downgrade to legacy pairing when one side still allows it. Fix: Secure Connections Only mode.
How weak pairing is detected
- Design review: the device's IO capabilities and MITM flag, whether it allows legacy pairing, whether it reuses a static passkey (often printed on the device or hard-coded as
000000or123456). - Lab test of your own device with a BLE sniffer during pairing: the Pairing Request/Response packets are in the clear and show IO capabilities, the auth requirements (bonding, MITM, SC flags) and the key size. Legacy pairing or a missing MITM flag is visible at once.
- GATT permissions that accept "unauthenticated encryption" for sensitive characteristics, which is what Just Works gives (GATT security).
How it is fixed
- Secure Connections Only: refuse legacy pairing.
- Give display-less devices an authenticated path: OOB via a QR code or NFC, or a physical action (a button on the device that opens a short pairing window) combined with application-layer verification.
- Set the MITM flag and require "authenticated encryption" on characteristics that change state.
- Never reuse a fixed passkey; generate a fresh one per pairing on the device that has the display.
- Limit the pairing window: accept pairing only after a button press, for a minute.
- Validate ECDH public keys (use current, maintained Bluetooth stacks).
Pitfalls
- "It's encrypted, so it's secure": Just Works encryption stops listeners, not a man in the middle.
- A static passkey printed on the device: it is reused, and Passkey Entry leaks it bit by bit to a MITM.
- Allowing pairing at any time: a plug that accepts new pairings forever can be taken over by anyone in range.
Practice
1. Change the watch case to secure_connections=False. Which method results and what does it protect?
Legacy pairing between KeyboardDisplay and DisplayYesNo falls back to Passkey Entry. A passive recording of the pairing exposes the keys (the TK has only values), and MITM protection is weak.
2. A smart lock has no display but a button and an NFC tag. Propose a pairing design.
LE Secure Connections Only; pairing accepted only for a minute after the button is pressed; OOB data (a public-key commitment) read from the NFC tag or a QR code inside the box, giving authenticated pairing; MITM flag set; the unlock characteristic requires authenticated encryption.
3. Both devices have displays, but the log shows Just Works. What is the likely cause?
Neither side set the MITM flag in its pairing request, so the specification selects Just Works regardless of IO capabilities. Set the flag (and require authenticated encryption) in the firmware.
Test yourself
What does LE Secure Connections add over legacy pairing?
- A longer device name
- An ECDH P-256 exchange, so a passive listener can't recover the keys
- Wi-Fi support
- Static passkeys
Which method gives a phone and a display-less plug MITM protection?
- Just Works
- Numeric Comparison
- Out of Band (e.g. a QR code)
- None is possible
Why must a Passkey Entry passkey never be reused?
- It expires
- The protocol reveals it bit by bit, so a MITM learns it during one attempt
- It is too long
- It is sent in the advertisement
What happens if neither device sets the MITM flag?
- Pairing fails
- Just Works is selected regardless of IO capabilities
- OOB is used
- Legacy pairing is forced