Section 17.17

Why Just Works is not authenticated MITM protection

Question

How can key exchange resist passive observation but still allow an active intermediary?

Short answer

Key exchange can hide the key from an eavesdropper without proving who is at the other end. In Diffie–Hellman key agreement §19.1.4, each party sends a public value, and an eavesdropper who sees both values cannot feasibly compute the shared key. Nothing in those values shows who sent them, so an active intermediary can replace each one with its own, complete a separate exchange with each party, and then read everything it relays. Authenticating the exchanged values stops this, and the Just Works §7.22 pairing of Bluetooth Low Energy §7.1 omits that step.

Terms in the question

Full answer

Step 1: the exchange. Diffie–Hellman key agreement uses two public numbers: a large prime pp and a number gg smaller than pp. Write xmodpx \bmod p for the remainder of xx after division by pp. Alice picks a secret number aa and sends A=gamodpA = g^a \bmod p. Bob picks a secret number bb and sends B=gbmodpB = g^b \bmod p. Alice computes BamodpB^a \bmod p, Bob computes AbmodpA^b \bmod p, and both results equal gabmodpg^{ab} \bmod p, the shared secret. Elliptic-curve Diffie–Hellman (ECDH) §19.1.5 works the same way with points on an elliptic curve in place of numbers modulo pp. LE Secure Connections §7.21, the pairing that Bluetooth 4.2 introduced [484] (LE stands for Low Energy), uses ECDH on the curve P-256, which NIST standardized.

Step 2: why an eavesdropper fails. The eavesdropper sees pp, gg, AA and BB. Computing gabmodpg^{ab} \bmod p from these is the computational Diffie–Hellman problem §19.1.3. For the groups used in practice, the best known way to solve it is to recover aa from AA, or bb from BB, which is the discrete logarithm problem. For the P-256 curve, the best known attacks on that problem need about 21282^{128} operations. The key therefore stays secret from anyone who only listens.

Step 3: why an active intermediary succeeds. Mallory, the intermediary, picks two secret numbers mm and nn. Mallory stops BB on its way to Alice and sends M=gmmodpM = g^m \bmod p instead, and stops AA on its way to Bob and sends N=gnmodpN = g^n \bmod p instead. Alice computes KA=MamodpK_A = M^a \bmod p, and Mallory computes the same value as AmmodpA^m \bmod p. Bob computes KB=NbmodpK_B = N^b \bmod p, and Mallory computes the same value as BnmodpB^n \bmod p. Mallory now holds both keys and has solved no hard problem: each honest party ran a correct exchange, but with Mallory. Mallory then decrypts what Alice sends with KAK_A, reads or changes it, encrypts it again with KBK_B and passes it to Bob, and does the same in the other direction.

Step 4: why the exchange cannot notice. A public value is just a number, and a number from Mallory looks exactly like a number from Bob. Even key confirmation §5.42, in which each side proves that it holds the agreed key, succeeds, because each side really does share a key, with Mallory. Secrecy against a listener is a property of the mathematics. Knowing who holds the other half of the key is a property that the mathematics does not provide.

Step 5: what closes the gap. The exchanged values must be bound to the parties’ identities through something Mallory lacks. Three kinds of evidence are used.

All three work because they cover the transcript, the sequence of messages as each party saw it, a technique called transcript binding §19.1.6. A key exchange with this property is an authenticated key exchange. Under attack, Alice saw (A,M)(A, M) and Bob saw (N,B)(N, B). The two transcripts differ, so the check fails.

Step 6: Just Works in LE Secure Connections. LE Secure Connections offers four association methods: numeric comparison §7.24, passkey entry §7.23, out-of-band association §7.25 and Just Works. All four run the same ECDH exchange. In numeric comparison, each device computes a six-digit number from both public keys and from two random numbers that the devices exchange, and the user confirms that both devices show the same number. Under attack the inputs differ, so the numbers match only by chance, with probability about 1 in 10610^6. One device sends a commitment to its random number, a value that fixes the number without revealing it, before it sees the other device’s random number, so Mallory cannot search for random numbers that make the two six-digit numbers match. Just Works runs the same messages but shows no number and asks the user nothing. The ECDH exchange still defeats an eavesdropper, and nothing detects Mallory. The Bluetooth specification therefore classes keys from Just Works as unauthenticated.

Step 7: the key carries its status, and the application must check it. Bluetooth records whether a key came from an authenticated method, and LE security mode §7.33 1 grades an encrypted link by that record. Level 2 means encryption with an unauthenticated key. Level 3 means encryption with an authenticated key. Level 4 means encryption with an authenticated key of 128 bits from LE Secure Connections. Pairing can end in Just Works even when one device asked for protection against an intermediary, if the two devices’ input and output capabilities, such as a display or a keypad, allow nothing stronger. A device that needs that protection must therefore require level 3 or 4 for its sensitive data and refuse access over a link at level 2.

Step 8: the name Just Works does not say what is protected. LE legacy pairing §7.20, the pairing of Bluetooth 4.0 and 4.1, which later versions still accept, has no Diffie–Hellman exchange. The short-term key that encrypts the rest of the pairing is computed from a temporary key (TK) and from two random numbers that the devices send unencrypted. Just Works sets the TK to zero, so an eavesdropper who records the pairing computes the short-term key and then reads the long-term key §7.28 that the devices send under it. Legacy Just Works therefore resists neither the eavesdropper nor the intermediary. The resistance to passive observation comes from the ECDH exchange of LE Secure Connections, not from the method’s name.

Worked example

The numbers are far too small for real use; they make every step checkable by hand. Let p=23p = 23 and g=5g = 5.

Honest exchange. Alice picks a=4a = 4 and sends A=54mod23=625mod23=4A = 5^4 \bmod 23 = 625 \bmod 23 = 4, because 625=27×23+4625 = 27 \times 23 + 4. Bob picks b=3b = 3 and sends B=53mod23=125mod23=10B = 5^3 \bmod 23 = 125 \bmod 23 = 10, because 125=5×23+10125 = 5 \times 23 + 10. Alice computes 104mod23=10000mod23=1810^4 \bmod 23 = 10000 \bmod 23 = 18, because 10000=434×23+1810000 = 434 \times 23 + 18. Bob computes 43mod23=64mod23=184^3 \bmod 23 = 64 \bmod 23 = 18, because 64=2×23+1864 = 2 \times 23 + 18. Both hold 18. An eavesdropper sees 4 and 10 and needs aa or bb. In this tiny example, trying the 22 possible exponents is easy; on the P-256 curve, the corresponding search takes about 21282^{128} operations.

Mallory in the middle. Mallory picks m=7m = 7 and n=9n = 9.

Alice holds key 8, Bob holds key 20, and Mallory holds both. Neither honest party sees anything wrong, and Mallory never computed a discrete logarithm. The transcripts reveal the attack: Alice saw the pair (4, 17), and Bob saw the pair (11, 10). In numeric comparison, the two six-digit numbers are computed from these different pairs, so they disagree except with probability about 1 in 10610^6, and the user refuses the pairing. Just Works never shows the numbers, so the pairing succeeds.

Follow-up questions and limits

Does a larger key or a larger curve stop the intermediary? No. Size protects against computing a discrete logarithm, and Mallory never computes one.

Is Just Works then worthless? No. Under LE Secure Connections it keeps out every attacker who only listens, and the danger from an intermediary is confined to the pairing itself. Once two genuine devices have paired and bonded, meaning that they stored the keys for later use, every later connection uses the stored long-term key, which an intermediary who arrives later does not have.

Why not always use numeric comparison? It needs a display and a yes-or-no input on both devices, which a sensor without a screen lacks. Out-of-band association, for example over near-field communication, needs no display. A fixed passkey printed on a device is weak under LE Secure Connections: the protocol reveals the passkey one bit per round, so an attacker who observes or takes part in one pairing with that passkey learns it.

Does an authenticated pairing make the peer trustworthy? No. It shows that the keys are shared with the device the user confirmed. Whether that device may read or change a given value is authorization §1.7, which the application decides.

Can an implementation weaken a correct protocol? Yes. A device must check that a received public key is a point on the agreed curve, a step called public-key validation. Biham and Neumann showed in 2018 that devices which skipped part of this check could be attacked during pairing [279]. This answer covers the protocol, not such implementation flaws.

Fullest treatment: Just Works (§7.22).

Related entries: LE Secure Connections (§7.21), LE legacy pairing (§7.20), Numeric comparison (§7.24), MITM attack (§7.26). Further reading: [279, 484].