为 iOS 上的 BLE 配对设置 IO 功能

Set IO capabilities for BLE pairing on iOS

在我的用例中,BLE 外围设备没有任何真正的 IO 功能,但需要 MITM 保护。

作为一种解决方案,密码输入配对方法与通过其他渠道交换的 6 位密码一起使用。与带外配对的理念相同,但 iOS 不支持 OOB,因此次佳的做法是以与 OOB 相同的方式使用密码输入 - 区别在于 6 位密码而不是 128 位密钥(聊胜于无)。

问题是,要使这种情况按预期工作,中央和外围设备都需要将其 IO 上限设置为 KeyboardOnly,这将导致 PasskeyEntry: initiator and responder inputs 配对方法。

可能的组合,复制自BT Core Specification [第 3 卷] H 部分,第 2.3.5.1 节,Table 2.8:IO 功能与密钥生成方法的映射:

                    /--------------------------------------------------------------------\  
   /-----------\   /                        Initiator (iOS/Android)                       \ 
  /  Responder  \ |-------------+--------------+---------------------+---------------------|
 /  (Peripheral) \| DisplayOnly | DisplayYesNo |     KeyboardOnly    |   KeyboardDisplay   |
|-----------------|-------------+--------------+---------------------+---------------------+
|   DisplayOnly   |             M1             |                     M3                    |
+-----------------+         Just Works         |               Passkey Entry:              |
|   DisplayYesNo  |                            |    Responder displays, initiator inputs   |
+-----------------+----------------------------+---------------------+---------------------+
|                 |                            |          M4         |                     |
|   KeyboardOnly  |                            |    Passkey Entry:   |                     |
|                 |             M2             |    initiator and    |          M2         |
|                 |       Passkey Entry:       |   responder inputs  |    Passkey Entry:   |
+-----------------+     Initiator displays,    +---------------------+ Initiator displays, |
|                 |      responder inputs      |          M3         |   responder inputs  |
| KeyboardDisplay |                            |    Passkey Entry:   |                     |
|                 |                            | Responder displays, |                     |
|                 |                            |   initiator inputs  |                     |
+-----------------+----------------------------+---------------------+---------------------+

M1:不适合,因为它不提供身份验证、窃听保护、MITM 保护。
M2: 不可能,因为Initiator显示的密码是在iOS/Android堆栈中生成的随机数,无法手动设置。
M3:与M2相同,但理论上外设上的BT堆栈最终可以修补生成"specific random number"。
M4:唯一可以在两台设备上输入自定义密钥的方法。

Android 有 BluetoothConfigManager::setLeIoCapability 方法用于此目的

import com.google.android.things.bluetooth.BluetoothConfigManager

val manager = BluetoothConfigManager.getInstance()
// Report that this device can accept keyboard user input only
manager.leIoCapability = BluetoothConfigManager.IO_CAPABILITY_IN
// TODO: Adapter needs to be restarted using BluetoothAdapter::disable() and enable()!

是否可以在 iOS(核心蓝牙)上做到这一点?

感谢您的帮助!

您已经回答了自己的问题。我认为 M3 是你所能达到的极限(在你的从设备上生成一个随机数,然后使用 OOB 将其传输给用户,这样 he/she 就可以在 iOS 设备上输入密码)。除此之外,您无法更改 iOS 行为。不幸的是,Apple 没有在 iOS 上提供任何 pairing/bonding/security API,这很糟糕,因此您永远无法知道 BLE 操作是否 "secure"。

如果您真的想要 iOS/BLE 上的安全性,那么您应该在 BLE 之上拥有自己的安全层(然后假定 BLE 是不安全的)。