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
Key exchange, also called key agreement: a protocol by which two parties who share no secret create a shared secret key by exchanging messages that others can see.
Passive observation: an attacker reads every message but sends, changes and blocks none. Such an attacker is called an eavesdropper.
Active intermediary: an attacker on the path between the two parties who can block, change and insert messages, and so can pretend to be each party to the other. The attack is called a man-in-the-middle §7.26 (MITM) attack.
Just Works: the association method of BLE (Bluetooth Low Energy) pairing in which the user compares nothing and types nothing. Pairing is the procedure in which two BLE devices create shared keys, and an association method is the way pairing checks, or does not check, which device is at the other end.
Full answer
Step 1: the exchange. Diffie–Hellman key agreement uses two public numbers: a large prime and a number smaller than . Write for the remainder of after division by . Alice picks a secret number and sends . Bob picks a secret number and sends . Alice computes , Bob computes , and both results equal , 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 . 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 , , and . Computing 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 from , or from , which is the discrete logarithm problem. For the P-256 curve, the best known attacks on that problem need about 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 and . Mallory stops on its way to Alice and sends instead, and stops on its way to Bob and sends instead. Alice computes , and Mallory computes the same value as . Bob computes , and Mallory computes the same value as . 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 , reads or changes it, encrypts it again with 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.
A long-term signing key: each party signs the exchanged values, and the other party already trusts the matching public key.
A secret shared in advance, such as a passkey, used so that each run of the protocol gives an attacker at most one guess.
A check outside the radio channel: a user compares a short value, computed from both public values, on the two devices, or the devices exchange data over a second channel, such as near-field communication, that Mallory does not control.
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 and Bob saw . 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 . 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 and .
Honest exchange. Alice picks and sends , because . Bob picks and sends , because . Alice computes , because . Bob computes , because . Both hold 18. An eavesdropper sees 4 and 10 and needs or . In this tiny example, trying the 22 possible exponents is easy; on the P-256 curve, the corresponding search takes about operations.
Mallory in the middle. Mallory picks and .
To Alice, Mallory sends . From and , the product reduces to , and . So .
To Bob, Mallory sends . Since reduces to , reduces to , and . So .
Alice computes : , and ; then , and . So . Mallory computes : ; , and ; reduces to , and . Mallory gets the same 8.
Bob computes , because . Mallory computes : , and ; reduces to , and ; reduces to , and ; reduces to . Mallory gets the same 20.
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 , 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].