Section 7.17

Pairing

Definition

Pairing in BLE §7.1 (Bluetooth Low Energy) is the procedure by which two devices that share no secret create a shared key for encrypting their link. The Security Manager Protocol §7.19 runs it in three phases: the devices state their capabilities, generate a key, and may hand over further keys. The key is authenticated when a check outside the radio, such as a user comparing two numbers, ties it to the intended device, so that a man-in-the-middle §7.26 (MITM) attacker, who relays traffic while posing as each device to the other, would be detected. Otherwise it is unauthenticated.

The idea

A person unpacks a glucose monitor and wants their phone to read it privately. Radio traffic reaches everyone nearby, so the two devices need a shared secret key that no listener can compute. A key agreement such as elliptic-curve Diffie–Hellman §19.1.5 (ECDH) produces one from values exchanged in the open: each device sends a public key, and each combines the other’s public key with its own private key to reach the same secret. A listener who sees only the public keys cannot compute that secret.

Key agreement alone leaves a gap. An attacker in the middle can answer each device with the attacker’s own public key, end up with one key shared with each device, and read everything that passes. Neither device can see this in the radio traffic. Something outside the radio must confirm that both devices used the same public keys: a person who checks that two screens show the same six-digit number, a person who types into one device a number the other displays, or data passed over a separate channel such as NFC (Near Field Communication). The specification calls the ways of making this check, including making none, association models: numeric comparison §7.24, passkey entry §7.23, out-of-band association §7.25 and Just Works §7.22. A monitor with no screen and no buttons cannot take part in such a check. With LE Secure Connections §7.21 its pairing still protects the link against listeners, but it cannot detect a MITM attack.

How it works

The central, the device that initiated the connection, sends the first pairing message; the peripheral, the device that accepted it, can ask the central to begin by sending a Security Request.

  1. Phase 1, feature exchange. The central sends a Pairing Request and the peripheral answers with a Pairing Response. Both travel unencrypted, and each states:

    • its IO (input and output) capability: DisplayOnly, DisplayYesNo, KeyboardOnly, NoInputNoOutput or KeyboardDisplay;

    • whether it holds out-of-band data about the other device, meaning data received over a channel other than this radio link;

    • its authentication §1.6 requirements: whether it wants to store the keys for later connections (bonding §7.18), whether it wants protection against a MITM attack, and whether it supports LE Secure Connections;

    • the largest encryption key size §7.27 it accepts, from 7 to 16 bytes;

    • which further keys each side will hand over in phase 3.

    At this point no key exists, nothing either device stated has been verified, and each device knows the other only by the address it uses on this connection.

  2. Phase 2, key generation. If both devices support LE Secure Connections, they use it. Each sends an ECDH public key on the curve named P-256, both compute the same shared secret, and they run the association model. They then exchange check values computed from the shared secret, which also cover each device’s stated IO capability, out-of-band flag and authentication requirements; a mismatch fails the pairing. Both derive the LTK §7.28 (long-term key) from the shared secret. Otherwise the devices use LE legacy pairing §7.20: the association model supplies a TK (temporary key), which is zero for Just Works, the six-digit passkey for passkey entry, or a 16-byte out-of-band value, and the devices derive an STK (short-term key) from the TK and from random numbers they exchange. Either way, the link is then encrypted with the new key.

  3. Phase 3, key distribution. Over the encrypted link the devices hand over the keys agreed in phase 1: in legacy pairing, the LTK itself; the IRK §7.29 (identity resolving key) together with the device’s fixed identity address §7.30, where the IRK lets the other device recognize this device behind its resolvable private address §7.31, a random address it changes regularly to avoid being tracked; and the CSRK (connection signature resolving key), for signing data on unencrypted links. If both devices asked for bonding, they store these keys.

The association model follows from phase 1. Under LE Secure Connections, if either device has out-of-band data, the model is out-of-band association. Otherwise, if neither device asked for MITM protection, the model is Just Works. Otherwise the IO capabilities decide, in this order:

  1. if either device is NoInputNoOutput, Just Works;

  2. if both can display a number and accept a yes or no (DisplayYesNo or KeyboardDisplay), numeric comparison;

  3. if at least one has a keyboard (KeyboardOnly or KeyboardDisplay), passkey entry;

  4. otherwise Just Works.

LE legacy pairing has no numeric comparison, so it skips step 2, and it uses out-of-band data only when both devices have it.

The outcome is recorded as a security level §7.33. In LE security mode 1, level 1 means no security; level 2, encryption with an unauthenticated key; level 3, encryption with an authenticated key; and level 4, encryption with an authenticated 16-byte key from LE Secure Connections. A device whose requirement cannot be met, for example one that asked for MITM protection while the other device is NoInputNoOutput, may fail the pairing with the reason “Authentication Requirements” or may accept the weaker result. A pairing that does not finish within 30 seconds is abandoned.

Worked example

A band without a screen. A phone (DisplayYesNo; asks for MITM protection and bonding; supports LE Secure Connections) pairs with a fitness band (NoInputNoOutput; asks for bonding; supports LE Secure Connections). Both support LE Secure Connections, so it is used. Neither has out-of-band data. The phone asked for MITM protection, so the IO capabilities decide, and because the band is NoInputNoOutput the model is Just Works. The result is an encrypted link with an unauthenticated key, security level 2. The phone’s request for MITM protection was not met, so the phone’s software must now either accept level 2 or fail the pairing.

Two devices with screens. The same phone pairs with a watch (DisplayYesNo). Both support LE Secure Connections and both can display a number and confirm, so the model is numeric comparison. Each device computes a six-digit number from both public keys and two random values, and both show it, say 304128. The user checks that the two screens agree and confirms on both. There are 106=1,000,00010^6 = 1{,}000{,}000 possible six-digit values, from 000000 to 999999. An attacker in the middle has given each device a different public key, so the two devices compute numbers that agree only by chance: with probability 1/106=0.0001%1 / 10^6 = 0.0001\% per attempt. With a 16-byte key the result is security level 4.

A listener breaks legacy passkey entry. In LE legacy pairing with passkey entry, the TK is the six-digit passkey, so it has only 10610^6 possible values, about log2106≈19.9\log_2 10^6 \approx 19.9 bits. A listener who recorded the pairing tries every candidate offline: for each of the 1,000,000 values it recomputes the confirm value, a check value the devices exchanged, and compares. Each try costs two AES (Advanced Encryption Standard) block encryptions, 2×1062 \times 10^6 in all, which an ordinary computer finishes in well under a second. The listener then derives the STK and decrypts the rest of the traffic, including the LTK handed over in phase 3. LE Secure Connections closes this hole, because its key comes from ECDH, which a listener cannot compute from the public keys.

Stated precisely

After a pairing, five questions have separate answers, and one “paired” flag cannot hold them all:

  1. Was a key established, and by LE legacy pairing or by LE Secure Connections?

  2. Is the current link encrypted with it?

  3. Is the key authenticated? Under LE Secure Connections it is when the association model was numeric comparison, passkey entry or out-of-band association rather than Just Works; under LE legacy pairing only out-of-band association over a channel safe from eavesdropping gives an authenticated key.

  4. How long is the key, from 7 to 16 bytes?

  5. Were the keys stored for later connections (bonding)?

A sixth question, whether the peer may perform a given operation, is not answered by pairing at all; it is an authorization §1.7 decision of the application.

The guarantee of an authenticated pairing under LE Secure Connections, for numeric comparison and for passkey entry, is that an active attacker who relays and alters the radio traffic of one pairing succeeds with probability about one in a million under numeric comparison and at most about four in a million under passkey entry, the figures the specification gives. The guarantee rests on these assumptions:

A Just Works key under LE Secure Connections resists a listener who only records traffic, and nothing more.

Limits and common mistakes

Pairing authenticates a link, not an identity. An authenticated key is shared with the device the user compared numbers with, nothing more. Pairing does not establish that device’s name (advertised names are not authenticated), its manufacturer, or that its software can be trusted.

Phase 1 can be altered. The feature exchange is unencrypted, so an attacker can make a device appear to be NoInputNoOutput and steer both devices to Just Works, which is a downgrade attack §1.27. The check values of LE Secure Connections cover the stated capabilities, but under Just Works the attacker computes those values with each device separately, and the check passes. The defense is a minimum: each device refuses any result below the security level it requires.

A fixed passkey is weak even under LE Secure Connections. Passkey entry reveals the passkey one bit per round to an attacker who takes part, so a passkey printed on a device and used for every pairing can be learned during one pairing attempt and used in the next.

LE legacy pairing protects little. Except with a strong out-of-band value, a listener who records the pairing can recover its keys, as the third worked example shows.

Pairing protects the link, not the author of the data. Data sent over an encrypted link came from whoever holds the other end of the link; who wrote it, and whether it may be acted on, are separate questions.

Questions answered

Does pairing always authenticate a human-approved device identity?

No. Pairing, the BLE (Bluetooth Low Energy) procedure that creates the keys for an encrypted link, authenticates the other device only when the association model adds a check outside the radio: numeric comparison, in which a person confirms that both screens show the same six-digit number; passkey entry, in which a person types a number; or out-of-band association, in which data travels over a separate channel. Under LE legacy pairing, the older procedure, passkey entry does not count: an active attacker can find the passkey during the pairing itself, so there only out-of-band association authenticates. When either device has no means of input or output, or neither device asks for protection against a man-in-the-middle (MITM) attacker, the model is Just Works. No person approves anything, and the key is unauthenticated: an attacker relaying the radio traffic could have paired with each device in the other’s place.

Even an authenticated pairing approves less than an identity. It shows that the key is shared with the device the person compared numbers with, provided the person compared carefully and the protocol’s assumptions hold. It does not show the device’s name, owner, manufacturer or trustworthiness, and it does not decide what the device may do; that is a separate authorization decision of the application.

Related entries: Security Manager Protocol (SMP) (§7.19), LE Secure Connections (§7.21), Just Works (§7.22), Security level (§7.33), Bonding (§7.18), LE legacy pairing (§7.20), Numeric comparison (§7.24), MITM attack (§7.26). Further reading: [18].