Section 7.33

Security level

Definition

A security level is a number that summarizes how a BLE §7.1 (Bluetooth Low Energy) connection is protected at present: whether the link is encrypted, whether its key came from pairing §7.17 that resisted a man-in-the-middle §7.26 (MITM) attacker, and whether that pairing used LE Secure Connections §7.21 with a 16-byte key. The Bluetooth Core Specification defines levels 1 to 4 of LE security mode 1 [283] (LE stands for Low Energy); stacks expose them under their own names, such as Zephyr’s §6.33 BT_SECURITY_L1 to BT_SECURITY_L4. A level describes the key in use, not a request.

The idea

A medical sensor lets a connected phone change its dose setting only over a protected link. Protection has independent parts: whether the link is encrypted; whether a MITM attacker, who relays the pairing while posing as each device to the other, could have taken part in it; and how long the key is. A rule that spelled out every part at every check would be long and easy to get wrong. A security level packs the parts into one ordered scale, so the rule reads “requires level 3”, and a higher level meets every lower requirement.

The trap is timing. Raising the level runs a procedure over the radio, either pairing or starting encryption with a stored key. The procedure takes several radio exchanges, may wait for a person to compare or type digits, and can fail. An application that grants the dose change as soon as it has asked for level 3 grants it on a link that may still be at level 1. A security level is like the stamp in a passport after the border check: having joined the queue for the check counts for nothing. The picture stops at duration: a stamp lasts for the whole trip, while a security level lasts only as long as the connection.

How it works

The levels of LE security mode 1, as the Generic Access Profile part of the Bluetooth Core Specification defines them:

The specification also defines LE security mode 2, for signed data on unencrypted links, and LE security mode 3, for broadcast isochronous groups, which send streams such as audio to many receivers at once. A device in Secure Connections Only mode demands level 4 for every service that needs any security.

How a connection gets its level.

  1. A new connection starts at level 1.

  2. Encryption raises it. If the devices share a bond, the central (the device that set up the connection) starts encryption with the stored long-term key §7.28 (LTK), and the level becomes whatever that key earned when pairing created it: the stack records with each stored key whether its pairing was authenticated, whether it used LE Secure Connections, and its size. Without a bond, the devices pair first, and the association model that pairing selects decides whether the key is authenticated.

  3. An application asks for a level. In Zephyr, bt_conn_set_security(conn, BT_SECURITY_L3) starts the procedure and returns at once; a return value of 0 means that the request was accepted, not that the level was reached. The stack reports the outcome later through the security_changed callback §14.22, with the level now in force and an error code if the procedure failed. A peripheral cannot start encryption itself; it sends a Security Request that asks the central to do so.

  4. The other side can enforce levels too. A GATT §7.10 (Generic Attribute Profile) server attaches a requirement to each attribute, and a request on a link that is too weak gets an ATT §7.9 (Attribute Protocol) error such as Insufficient Authentication (0x05), Encryption Key Size §7.27 Too Short (0x0C) or Insufficient Encryption (0x0F). The client may then raise the level and try again.

  5. Before each protected operation, the application reads the current level of this connection, in Zephyr with bt_conn_get_security(conn), and compares it with the level the operation requires.

Other stacks. The numbers belong to a stack’s programming interface; devices never exchange them. Zephyr adds BT_SECURITY_L0, used only in special cases of classic Bluetooth, called BR/EDR (Basic Rate/Enhanced Data Rate). The Linux kernel names its levels BT_SECURITY_LOW, BT_SECURITY_MEDIUM, BT_SECURITY_HIGH and BT_SECURITY_FIPS, numbered 1 to 4, with BT_SECURITY_SDP as 0. Apache NimBLE, an open-source Bluetooth stack for small devices, reports separate flags for encrypted, authenticated and bonded, plus the key size, and no single number.

Worked example

A phone that can show a number and accept a yes or no pairs with four devices, and in every pairing it asks for protection against a MITM attacker. The level each pairing yields:

A service requires level 3 before it accepts a new dose. The band, at level 2, is refused; the watch, the meter and, in a stack that reports it at level 3, the lock pass. Yet the three passing links differ in ways the number hides. The meter’s 7-byte key allows 256≈7.2×10162^{56} \approx 7.2 \times 10^{16} values, against 2128≈3.4×10382^{128} \approx 3.4 \times 10^{38} for a 16-byte key. The lock’s legacy passkey pairing falls to anyone who recorded it: the recorder tries all 106=1,000,00010^{6} = 1{,}000{,}000 six-digit passkeys, which a laptop does in seconds, then computes the key and decrypts the lock’s traffic. The band’s level 2 link, made with LE Secure Connections, resists that passive eavesdropper.

The timing trap with real calls: the phone’s application is connected to the band at level 2 and calls bt_conn_set_security(conn, BT_SECURITY_L3). The call returns 0. Pairing cannot reach level 3, because the band has no display and no keypad, so the procedure fails, the security_changed callback reports an error, and the link stays at level 2. An application that wrote the dose when the call returned 0 wrote it over a link that never reached level 3. A correct application waits for the callback, reads bt_conn_get_security(conn), sees BT_SECURITY_L2, and refuses, because 2 is less than 3.

Stated precisely

For one connection at one moment, let EE be true if the link is encrypted, AA true if the key in use came from authenticated pairing (numeric comparison, passkey entry or out-of-band association; version 6.2 of the specification no longer counts passkey entry under LE legacy pairing), SS true if that pairing used LE Secure Connections, and kk the key size in bytes, from 7 to 16. LE security mode 1 assigns the level level={1if not E,2if E and not A,3if E and A, but not both S and k=16,4if E,A,S and k=16.\mathrm{level} = \begin{cases} 1 & \text{if not } E, \\ 2 & \text{if } E \text{ and not } A, \\ 3 & \text{if } E \text{ and } A, \text{ but not both } S \text{ and } k = 16, \\ 4 & \text{if } E,\ A,\ S \text{ and } k = 16. \end{cases} An operation requiring level nn passes its link-security check when the current level is at least nn. The application can still require separate authorization §1.7.

Each property holds only under its own assumptions.

Limits and common mistakes

A requested level is not an achieved level. Act only after the stack reports completion, and check the current level at the moment of each protected operation.

A level belongs to one connection at one moment, and the next connection starts again at level 1. Stacks reuse connection objects, so a stale pointer §4.1 kept from an earlier connection, or a late callback about it, must never authorize an operation on a new connection with a different peer.

“Authenticated” says how the key was made, not who the peer is: no MITM attacker took part in pairing, and the peer is whatever device the user approved. A level grants no authorization for any particular operation, says nothing about the origin of data that the peer forwards from elsewhere, and ends at this link.

Level 3 allows keys as short as 7 bytes, and levels 2 and 3 include LE legacy pairing, whose key a recorded pairing exposes. A level 3 requirement can therefore be met by a link that a passive eavesdropper reads. Require level 4, or check the key size and LE Secure Connections separately.

A downgrade attack §1.27 can push a connection to a lower level, for example by an attacker that claims to have no display and no keypad so that pairing falls back to Just Works. Only the requirement check at the operation stops it; asking for a higher level does not.

The numbers differ between stacks. A log line that says “level 3” means something definite only together with the stack that wrote it.

Questions answered

What exact properties does each numeric level guarantee in the relevant stack?

In LE security mode 1 of the Bluetooth Core Specification (LE stands for Low Energy), and in Zephyr’s BT_SECURITY_L1 to BT_SECURITY_L4, which follow it, level 1 guarantees nothing. Level 2 guarantees that the link is encrypted, with a key from pairing that did not protect against a man-in-the-middle (MITM) attacker. Level 3 guarantees encryption with a key from authenticated pairing, meaning passkey entry, numeric comparison or out-of-band association, of any size from 7 to 16 bytes; version 6.2 of the specification no longer counts passkey entry under LE legacy pairing as authenticated. Level 4 guarantees, in addition, that the pairing used LE Secure Connections and that the key is 16 bytes. Zephyr’s extra BT_SECURITY_L0 applies only to classic Bluetooth.

These are properties of the key encrypting this connection now, established by a completed pairing or re-encryption, not by a request; read the level after the stack reports completion. Levels 2 and 3 can come from LE legacy pairing, whose key an eavesdropper who recorded the pairing can compute, and level 3 can mean a 7-byte key. No level says who the peer is, whether it may perform an operation, or whether data it forwards came from a trusted author. Other stacks use other names and numbers, such as BT_SECURITY_LOW to BT_SECURITY_FIPS in Linux or separate flags in Apache NimBLE, so read the definition in the stack actually used.

Related entries: Encryption key size (§7.27), Channel confidentiality versus object authenticity (§7.34), Pairing (§7.17), Bonding (§7.18), LE legacy pairing (§7.20), LE Secure Connections (§7.21). Further reading: [104, 283].