BLE配对是一个三阶段的过程。
前两个阶段总是使用,可能跟随着一个可选的传输特定秘钥分配的阶段。
阶段1:配对特征交换阶段2:短期秘钥(STK)生成
阶段3:传输特定秘钥分配
STK 生成规则:
1: Just work 没有加密 TK=0x00
2: passkey entry 密码输入如果 passkey 是 ‘019655’ then TK shall be 0x00000000000000000000000000004CC7.
3: OOB The TK value shall be a 128-bit random number using the requirements for random generation
STK = s1(TK, Srand, Mrand)
1. 配对交换特征
设备首先在配对特征交换阶段交换IO能力来决定在第二阶段使用下面哪种方法:
JustWorks:只工作、 PasskeyEntry:输入密码 、OutOfBand(OOB):带外
LE Legacy Pairing - Just Works
Just Works方式不能抵抗窃听者和中间人攻击,只有在配对过程时没有遭受攻击,后面加密的链路的数据传输才是可信的。安全级别很低。
LE Legacy Pairing - Passkey Entry
这种方式通过输入6位数字的方式来进行配对,生成STK。6位数是随机产生的在000000到999999之间的数值,这个数值相当于一个TK,比如远端显示这个数字,需要在本地端输入这个数字给本地设备与远端配对。如输入019655,那此时的临时Key–TK是:0x00000000000000000000000000004CC7。
Out of Band 带外
这种方式是通过BLE之外的,设备上的其他方式来获取这个OOB data,比如通过IR红外,或其余的方式,因此对于蓝牙窃听者/攻击者而言这个data的传输是不可见的了,因此会显得要安全些。
1.1 配对请求报文格式
a. IO capabilities
表明输入,输出的能力。输入是按键、键盘,输出是显示数字用的界面。
0x 00 DisplayOnly 只能是显示000000 ~ 999999的数字
0x01 DisplayYesNo 显示Yes/No 的按钮
0x02 KeyboardOnly 只能是输入000000 ~ 999999的数字
0x03 NoinputNoOutput 没有输入也没有显示,只能用Just work工作方式
0x04 KeyboardDisplay 能输入000000 ~ 999999的数字和输出
b. OOB data flag
0x00 OOB Authentication data not present,OOB 数据没有发送
0x01 OOB Authentication data from remote device present OOB 数据通过远端设备发送(如IR)
0x02-0xFF Reserved
c. AuthReq
1:Bonding_Flags b1b0 Bonding Type 5:MaximumEncryptionKeySize:7到16字节之间 6:InitiatorKeyDistribution:该域表明秘钥初始化设备请求分配使用。 7:The Initiator Key Distribution / Generation field in the Pairing Request command is used by the master to request which keys are distributed or generated by the initiator to the responder 8:ResponderKeyDistribution:该字段表明秘钥初始化设备请求响应设备来分配秘钥分配使用。 |
1.1.1 配对请求报文实例
a:主设备向从设备发送配对请求报文。
1: Code (1 octet) 0x01 Pairing Request 2: IO Capability (1 octet) 0x03 NoInputNoOutput 用于just work 认证方式 3: OOB data 0x00 OOB(out of band) Authentication data not present 没有带外认证,Out of Band 带外这种方式是通过BLE之外的,设备上的其他方式来获取这个OOB data,比如通过IR红外,或其余的方式,因此对于蓝牙窃听者/攻击者而言这个data的传输是不可见的了,因此会显得要安全些。 4: AuthReq (1 octet) The AuthReq field is a bit field that indicates the requested security properties for the STK and LTK and GAP bonding information 0x01 :表示绑定 5:MaxEncKeySize 0x10 表示最大认证key大小是0x10个字节 6:InitiatorKeyDistribution:该域表明秘钥初始化设备请求分配秘钥分配使用。 The Initiator Key Distribution / Generation field in the Pairing Request command is used by the master to request which keys are distributed or generated by the initiator to the responder 7:ResponderKeyDistribution::001 该字段表明秘钥初始化设备请求响应设备来分配秘钥分配使用。 |
b:从设备向主设备向发送配对回复报文。
具体字段含义参考 配对请求报文。
1.2 配对确认
配对确认用来在成功的配对特征交换之后启动STK生成。
该命令被两个对等设备使用来向对等设备发送确认值。
初始化设备通过向响应设备发送配对确认命令启动STK生成。
报文格式
启动STK的生成,这一部分可简述为以下步骤的实现: 1. Initiator生成一128-bit随机数Mrand,并使用这个Mrand结合一些其他的输入,使用密码工具箱中c1计算出一个128-bit的Mconfirm值: Mconfirm = c1(TK, Mrand, Pairing Request command, Pairing Response command, initiating device address type, initiating device address, responding device address type, responding device address) Responder也生成一128-bit随机数Srand,并使用这个Srand结合一些其他的输入,使用密码工具箱中c1计算出一个128-bit的Sconfirm值: Sconfirm = c1(TK, Srand, Pairing Request command, Pairing Response command, initiating device address type, initiating device address, responding device address type, responding device address) 然后Initiator将其计算的Mconfirm值通过Pairing Confirm包发送给Responder,而Responder也将其计算的Sconfirm值通过Pairing Confirm包发送给Initiator; Initiator收到Sconfirm后,再将Mrand值通过Pairing Random包发送给Responder; Responder收到Mrand值后计算它的Mconfirm值,再跟前面那个Initiator送过来的Mconfirm值进行比较,若不同说明配对失败了。若相同,则Responder也会将它的Srand值通过Pairing Random包发送给Initiator; 而Initiator也会计算收到的Srand值的Sconfirm值,并跟前面那个Responder送过来的Sconfirm值进行比较,若不同说明配对失败了,若相同,继续。 |
报文实例
主设备向从设备发送配对确认报文,从设备也向主设备发送配对确认报文。
1.3 配对随机
该命令用来由初始化和响应设备发送用来计算在配对确认命令中的确认值的随机数。
报文格式
报文实例
主设备向从设备发送配对随机值报文,从设备也向主设备发送配对随机值报文。
1.4 配对特定key 分发
BLE的SMP的一些Key相关定义 Long Term Key (LTK):加密链路用,128-bit; Encrypted Diversifier (EDIV):在LE legacy pairing过程中,用于识别LTK分发,16-bit; Random Number (Rand):在LE legacy pairing过程中,用于识别LTK分发,64-bit。 Identity Resolving Key (IRK):用于生成和解析random address用的,128-bit; AddrType (1 octet) If BD_ADDR is a public device address, then AddrType shall be set to 0x00. If BD_ADDR is a static random device address then AddrType shall be set to 0x01. BD_ADDR (6 octets) This field is set to the distributing device’s public device address or static random address. Connection Signature Resolving Key (CSRK):用于对数据进行签名已经验证签名数据,128-bit; |
1.4.1 特定key分发原因
在秘钥分配阶段slave把秘钥给master所有重连能够被加密,它的随机地址能够被解析或者master设备能校验来自slave签名数据。
Master也向slave提供数据所以如果角色交换重连能够被加密,master的随机地址能够被解析或者slave能够校验来自master的签名数据。
如下是蓝牙SPEC的描述:
1.5 绑定
就是将配对阶段产生的一系列key 保持到flash中,以便后续使用。
附录:
以上这个过程的报文交互如下图,