Section 7.19

Security Manager Protocol (SMP)

Definition

The Security Manager Protocol (SMP) is the protocol that two Bluetooth Low Energy (BLE) §7.1 devices use to pair: to agree on security features, choose the association method (the user step, if any, that confirms the right two devices are pairing §7.17), create shared keys and hand over further keys. The Bluetooth Core Specification defines it. SMP messages travel over L2CAP §7.15 (Logical Link Control and Adaptation Protocol), a Bluetooth layer that carries messages between devices, on a channel reserved for SMP. SMP sets up security; the Link Layer §7.6, below it, encrypts packets.

The idea

Two devices that have never met must agree on how to protect their link, and they differ in what they can do. A heart-rate sensor has no screen and no buttons, a phone has both, a keyboard can type but not display. Before any key exists, each device must learn what the other can do and what it requires: whether the user can compare a number or type one, whether the keys should be stored for later, how long the key may be. Only then can both choose the same procedure. SMP is that conversation, followed by the procedure the devices chose.

Think of two people arranging to recognize each other at a station: first they list what they have (a phone with a camera, a printed photo, nothing), then they pick a way of recognizing each other that both can carry out. The choice is made in the open, before any secret exists, so anyone listening sees it and anyone able to alter messages can try to steer it. Each device must therefore check the outcome against its own minimum and not rely on the other side’s claims. The picture stops at one point: in SMP the recognition step also produces the key.

An application sees this conversation only through callbacks §14.22, functions that it registers and that its Bluetooth software calls when an event happens. A callback can affect only what has not yet happened: one that runs when the peer’s first message arrives can still refuse the pairing, while one that runs after encryption has started can only react.

How it works

SMP runs between an initiator and a responder. In BLE the initiator is always the central (the device that set up the connection) and the responder is the peripheral; a peripheral that wants security can ask the central to start, with a Security Request message. Each SMP message, called a command, begins with a one-byte code, for example 0x01 for Pairing Request and 0x05 for Pairing Failed. Pairing has three phases.

Phase 1, pairing feature exchange. The initiator sends a Pairing Request and the responder answers with a Pairing Response. Each is 7 bytes: the code (0x01 or 0x02) and six one-byte fields.

These two messages are sent before any key exists, so they are neither encrypted nor protected against change in transit.

Decisions after phase 1. Both devices now hold both messages and compute the same decisions.

  1. Procedure: LE Secure Connections if both set the SC flag, otherwise LE legacy pairing.

  2. Key size: the smaller of the two maxima. A device whose own minimum is larger stops with Pairing Failed, reason 0x06 (encryption key size).

  3. Association method, by the rule below.

  4. Bonding: the keys are stored only if both bonding flags are 01.

  5. Keys to send: the key distribution fields of the response.

Choosing the association method. Section 2.3.5.1 of the Security Manager part of the specification gives the rule.

  1. Out-of-band association is used under LE legacy pairing if both devices set the OOB flag, and under LE Secure Connections if at least one does.

  2. Otherwise, if neither device set the MITM flag, the method is Just Works §7.22, whatever the IO capabilities.

  3. Otherwise the two IO capabilities decide:

    • If either device is NoInputNoOutput: Just Works.

    • Under LE Secure Connections, if each device is DisplayYesNo or KeyboardDisplay: numeric comparison §7.24.

    • Otherwise, if at least one device has a keyboard (KeyboardOnly or KeyboardDisplay): passkey entry. A device that has a display shows a six-digit passkey and the user types it on a device that has a keyboard. If both are KeyboardOnly, the user types the same number on both; if both are KeyboardDisplay under LE legacy pairing, the initiator displays and the responder takes the input.

    • Otherwise (displays but no keyboard on either side): Just Works.

These cases reproduce table 2.8 of the specification. The table also classes each key: Just Works gives an unauthenticated key; numeric comparison, and passkey entry under LE Secure Connections, give an authenticated key; out-of-band association gives an authenticated key only if the out-of-band channel is safe from eavesdropping. Version 6.2 classes the key of passkey entry under LE legacy pairing as unauthenticated.

Phase 2, key generation. The devices run the chosen method. LE legacy pairing computes a short-term key from a temporary key and two random numbers; LE Secure Connections runs elliptic-curve Diffie–Hellman key agreement §19.1.5 and derives the LTK. At the end the initiator tells its Link Layer to encrypt the link with the new key.

Phase 3, key distribution. Over the encrypted link each device sends the keys agreed in phase 1, one command per item (for example Encryption Information for an LTK, Identity Information for an IRK).

Failure. Either device can stop at any step by sending Pairing Failed with a one-byte reason, for example 0x03 (authentication requirements: the method cannot give the protection required), 0x04 (confirm value failed) or 0x05 (pairing not supported). Each device restarts a 30-second timer whenever it queues an SMP command for sending; if the timer runs out, the procedure fails, no further SMP command may be sent on that connection, and a new pairing needs a new connection. After a failed pairing the device waits before it accepts another attempt from the same claimed identity, and the wait grows exponentially with each further failure, which slows an attacker who guesses repeatedly.

Worked example

A phone, the initiator, sends this Pairing Request, written as bytes in the order sent: 01 04 00 2D 10 02 03.

Decode AuthReq 0x2D: it is 2×16+13=452 \times 16 + 13 = 45 in decimal, and 45=32+8+4+145 = 32 + 8 + 4 + 1, so the bits set are 5, 3, 2 and 0, binary 0010 1101. Bits 1 and 0 read 01: bonding. Bit 2 is 1: MITM protection requested. Bit 3 is 1: LE Secure Connections supported. Bit 4 is 0: no keypress notifications. Bit 5 is 1: CT2 supported.

A door lock with a display and no keypad answers 02 00 00 0D 10 02 02: Pairing Response, IO capability DisplayOnly, no OOB data, AuthReq 0x0D (binary 0000 1101: bonding, MITM, SC), maximum key size 16, and key distribution 02 for each side. The lock cleared bit 0 of the responder field, which a response may do.

Both devices now decide.

  1. Procedure: both SC flags are 1, so LE Secure Connections. Under it, the EncKey bit is ignored, because both devices compute the LTK.

  2. Key size: the smaller of 16 and 16 is 16 bytes.

  3. Method: neither OOB flag is set; at least one MITM flag is set, so the IO capabilities decide. Neither device is NoInputNoOutput. Numeric comparison needs both devices to be DisplayYesNo or KeyboardDisplay, and the lock is DisplayOnly, so it does not apply. The phone has a keyboard, so the method is passkey entry: the lock displays six digits and the user types them on the phone. The key will be authenticated.

  4. Bonding: both bonding flags are 01, so both devices store the keys.

  5. Keys to send: each side sends its IRK and identity address.

Now change one byte: suppose the lock declared NoInputNoOutput (03 in the second byte of its response). Step 3 then gives Just Works, although the phone asked for MITM protection, and the key is unauthenticated. A phone whose policy requires an authenticated key must then stop with Pairing Failed, reason 0x03. The MITM flag is a request, not a guarantee.

Stated precisely

Let MIM_I and MRM_R be the maximum key sizes in the request and the response, in bytes, with 7≤MI,MR≤167 \le M_I, M_R \le 16. The negotiated key size is min(MI,MR)\min(M_I, M_R); each device sends Pairing Failed if it is below that device’s own minimum. LE Secure Connections is used if and only if both SC flags are 1, and the association method is the function of the OOB flags, MITM flags and IO capabilities given above.

After a successful pairing, SMP establishes this: both devices hold the same key, of the negotiated size, created by the chosen method, and that key is authenticated exactly when the method was numeric comparison, passkey entry under LE Secure Connections, or out-of-band association over a channel safe from eavesdropping. SMP gives this result only under the following conditions.

Where application callbacks sit

The specification fixes the order of SMP commands. Each Bluetooth software stack decides where to call the application and whether the callback’s result can stop anything. Three positions are typical.

The software may also have refused a pairing on its own configured rules, such as a key size below its minimum, before calling any of these callbacks. The presence of a callback in the code therefore says nothing about which messages the software had already accepted before calling it.

Limits and common mistakes

Phase 1 fields are claims, not facts. A peer can declare any IO capability, and an attacker in the middle can change the fields in transit, for example to NoInputNoOutput so that Just Works is chosen. This is a downgrade attack §1.27. The defense is local: each device refuses an outcome below its own requirement, for instance by requiring an authenticated key, whatever the flags said.

A device with no display, no keyboard and no out-of-band channel declares NoInputNoOutput and sets no OOB flag, so the rule always gives it Just Works and it can never obtain an authenticated key. Only an added out-of-band channel, such as NFC, changes that.

Pairing is not authorization §1.7. SMP decides how the link is protected, not what the peer may do over it.

LE legacy pairing and LE Secure Connections use different cryptography in phase 2. The same prompt on the screen, such as six digits to type, does not mean the same protection.

Questions answered

Which parameters are negotiated before an application pairing callback runs?

The parameters negotiated first are the six fields of the pairing feature exchange, the opening step of the Security Manager Protocol (SMP), the Bluetooth Low Energy protocol for pairing. The initiator sends them in its Pairing Request and the responder in its Pairing Response:

From the two messages both devices derive five outcomes: the procedure (LE Secure Connections only if both support it), the key size (the smaller maximum), the association method (from the OOB flags, the MITM flags and the IO capabilities), whether to bond, and which keys to send.

Which of these are settled when a callback runs depends on where the Bluetooth software calls it.

The software may also have rejected the pairing on its own configured rules before calling the application at all.

Related entries: LE legacy pairing (§7.20), LE Secure Connections (§7.21), Cross-layer security (§7.38), Encryption key size (§7.27), Pairing (§7.17), Just Works (§7.22), Passkey entry (§7.23), Numeric comparison (§7.24), Out-of-band (OOB) association (§7.25), Security level (§7.33), Callback (§14.22), Protocol downgrade, negotiation, and authenticated capabilities (§19.5.8). Further reading: [18, 104].