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.
IO capability, where IO stands for input and output: what the device can show to and accept from a user. The values are
0x00DisplayOnly,0x01DisplayYesNo(a display and yes and no buttons),0x02KeyboardOnly,0x03NoInputNoOutputand0x04KeyboardDisplay.OOB §7.25 data flag:
0x01if the device holds authentication §1.6 data that it received from the peer out of band (OOB), that is, over a channel other than the Bluetooth radio, such as NFC (near-field communication); otherwise0x00.AuthReq(authentication requirements), a set of bits. Bits 1 and 0 are the bonding §7.18 flags:01asks to store the keys as a bond,00does not. Bit 2 is the MITM §7.26 flag, set to ask for protection against a man-in-the-middle (MITM) attacker who relays and alters pairing messages. Bit 3 is the SC flag, set if the device supports LE Secure Connections §7.21 (LE stands for Low Energy). Bit 4 asks for a notification at each digit typed during passkey entry §7.23. Bit 5, the CT2 flag, announces support for a key-derivation function §5.20 named h7, used when a key for one Bluetooth radio mode is derived from a key for the other. Bits 6 and 7 are reserved.Maximum encryption key size §7.27: 7 to 16 bytes.
Initiator key distribution and responder key distribution: which keys each side will send in phase 3. Bit 0 (
EncKey) is the long-term key §7.28 (LTK), sent only in LE legacy pairing §7.20; bit 1 (IdKey) is the identity resolving key §7.29 (IRK) with the device’s identity address §7.30; bit 2 (SignKey) is the connection signature resolving key (CSRK); bit 3 (LinkKey) asks to derive a key for Bluetooth Classic, the older radio mode. In the response the responder may set only bits that the request set.
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.
Procedure: LE Secure Connections if both set the SC flag, otherwise LE legacy pairing.
Key size: the smaller of the two maxima. A device whose own minimum is larger stops with Pairing Failed, reason
0x06(encryption key size).Association method, by the rule below.
Bonding: the keys are stored only if both bonding flags are
01.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.
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.
Otherwise, if neither device set the MITM flag, the method is Just Works §7.22, whatever the IO capabilities.
Otherwise the two IO capabilities decide:
If either device is
NoInputNoOutput: Just Works.Under LE Secure Connections, if each device is
DisplayYesNoorKeyboardDisplay: numeric comparison §7.24.Otherwise, if at least one device has a keyboard (
KeyboardOnlyorKeyboardDisplay): 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 areKeyboardOnly, the user types the same number on both; if both areKeyboardDisplayunder 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.
01: Pairing Request.04: IO capabilityKeyboardDisplay.00: no OOB data.2D:AuthReq, decoded below.10: maximum key size, hexadecimal 10, which is 16 bytes.02: initiator key distribution, bit 1 only, so the phone will send its IRK.03: responder key distribution, bits 0 and 1, so the phone asks the responder for an LTK and an IRK.
Decode AuthReq 0x2D: it is in decimal, and , 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.
Procedure: both SC flags are 1, so LE Secure Connections. Under it, the
EncKeybit is ignored, because both devices compute the LTK.Key size: the smaller of 16 and 16 is 16 bytes.
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 beDisplayYesNoorKeyboardDisplay, and the lock isDisplayOnly, 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.Bonding: both bonding flags are
01, so both devices store the keys.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 and be the maximum key sizes in the request and the response, in bytes, with . The negotiated key size is ; 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.
Local enforcement. Each device checks the outcome (procedure, method, key size) against its own requirements, because the phase 1 fields are not protected when they are sent.
Binding of phase 1. Under LE Secure Connections the final check values of phase 2 cover each device’s IO capability, OOB flag and
AuthReq, so a change to those three fields in transit makes pairing fail, unless the attacker is an endpoint of both key agreements, which only an authenticated method prevents. The maximum key size is not covered by these check values. Under LE legacy pairing the confirm values cover both complete 7-byte messages, but anyone who knows the temporary key, which is zero under Just Works, can recompute them.
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.
When the peer’s Pairing Request or Pairing Response arrives. The callback sees the peer’s six fields before any key exists and, if the software lets it return a verdict, can refuse the pairing. In the Bluetooth software of the Zephyr RTOS §6.33 (real-time operating system), the callback
pairing_acceptreceives these fields and returns a result; a result other than success stops the pairing. Zephyr calls it only when the build optionCONFIG_BT_SMP_APP_PAIRING_ACCEPTis enabled.During phase 2. Callbacks that display a passkey, ask the user to type one, or ask the user to confirm a number run after the method has been chosen. They can cancel the pairing but cannot change the method or the key size.
After encryption has started. A callback that reports the new security level §7.33, such as Zephyr’s
security_changed, returns nothing to the software. The application can only react, for example by disconnecting.
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:
the IO capability, meaning what each device can display or accept as input;
the OOB data flag, which says whether authentication data received out of band, over a channel other than Bluetooth, is present;
AuthReq, the authentication requirement bits: bonding, MITM (protection against a man-in-the-middle attacker), LE Secure Connections support, keypress notifications and CT2 (support for the key-derivation function h7);the maximum encryption key size, 7 to 16 bytes;
the initiator key distribution field and
the responder key distribution field, which say which keys each side will send after encryption starts.
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.
A callback run when the peer’s Pairing Request reaches the responder, such as
pairing_acceptin the Bluetooth software of the Zephyr operating system, sees the initiator’s proposed values before the responder has answered: nothing is negotiated yet, and the callback can still refuse. On the initiator the same callback runs when the Pairing Response arrives, and all five outcomes then follow from the two messages.A passkey or confirmation callback runs in the second phase of pairing, after all five outcomes are fixed, and can only cancel.
A callback that reports the finished security level runs after encryption has started and can only react, for example by disconnecting.
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].