BLE 配对流程(转自襄坤在线)
BLE配對(duì)是一個(gè)三階段的過(guò)程。
?
前兩個(gè)階段總是使用,可能跟隨著一個(gè)可選的傳輸特定秘鑰分配的階段。
階段1:配對(duì)特征交換
階段2:短期秘鑰(STK)生成
階段3:傳輸特定秘鑰分配
?
STK 生成規(guī)則:
1: Just work 沒(méi)有加密 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.?配對(duì)交換特征
設(shè)備首先在配對(duì)特征交換階段交換IO能力來(lái)決定在第二階段使用下面哪種方法:
?JustWorks:只工作、 PasskeyEntry:輸入密碼 、OutOfBand(OOB):帶外?
LE Legacy Pairing - Just Works
Just Works方式不能抵抗竊聽者和中間人攻擊,只有在配對(duì)過(guò)程時(shí)沒(méi)有遭受攻擊,后面加密的鏈路的數(shù)據(jù)傳輸才是可信的。安全級(jí)別很低。
LE Legacy Pairing - Passkey Entry
這種方式通過(guò)輸入6位數(shù)字的方式來(lái)進(jìn)行配對(duì),生成STK。6位數(shù)是隨機(jī)產(chǎn)生的在000000到999999之間的數(shù)值,這個(gè)數(shù)值相當(dāng)于一個(gè)TK,比如遠(yuǎn)端顯示這個(gè)數(shù)字,需要在本地端輸入這個(gè)數(shù)字給本地設(shè)備與遠(yuǎn)端配對(duì)。如輸入019655,那此時(shí)的臨時(shí)Key–TK是:0x00000000000000000000000000004CC7。
Out of Band 帶外
這種方式是通過(guò)BLE之外的,設(shè)備上的其他方式來(lái)獲取這個(gè)OOB data,比如通過(guò)IR紅外,或其余的方式,因此對(duì)于藍(lán)牙竊聽者/攻擊者而言這個(gè)data的傳輸是不可見的了,因此會(huì)顯得要安全些。
?
1.1 配對(duì)請(qǐng)求報(bào)文格式
a. IO capabilities
表明輸入,輸出的能力。輸入是按鍵、鍵盤,輸出是顯示數(shù)字用的界面。
0x 00 DisplayOnly 只能是顯示000000 ~ 999999的數(shù)字
0x01 ?DisplayYesNo 顯示Yes/No 的按鈕
0x02 KeyboardOnly 只能是輸入000000 ~ 999999的數(shù)字
0x03 NoinputNoOutput 沒(méi)有輸入也沒(méi)有顯示,只能用Just ?work工作方式
0x04 KeyboardDisplay 能輸入000000 ~ 999999的數(shù)字和輸出
b. OOB data flag
?0x00 OOB Authentication data not present,OOB 數(shù)據(jù)沒(méi)有發(fā)送
?0x01 OOB Authentication data from remote device present OOB 數(shù)據(jù)通過(guò)遠(yuǎn)端設(shè)備發(fā)送(如IR)
?0x02-0xFF Reserved?
c. AuthReq
?
| 1:Bonding_Flags b1b0 Bonding Type 5:MaximumEncryptionKeySize:7到16字節(jié)之間 6:InitiatorKeyDistribution:該域表明秘鑰初始化設(shè)備請(qǐng)求分配使用。 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:該字段表明秘鑰初始化設(shè)備請(qǐng)求響應(yīng)設(shè)備來(lái)分配秘鑰分配使用。 |
?
?
?
?
1.1.1 配對(duì)請(qǐng)求報(bào)文實(shí)例
a:主設(shè)備向從設(shè)備發(fā)送配對(duì)請(qǐng)求報(bào)文。
?
| 1: Code (1 octet) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? 0x01 Pairing Request 2: IO Capability (1 octet)? ?0x03 NoInputNoOutput 用于just work 認(rèn)證方式 3: OOB data? ?0x00 OOB(out of band) Authentication data not present 沒(méi)有帶外認(rèn)證,Out of Band 帶外這種方式是通過(guò)BLE之外的,設(shè)備上的其他方式來(lái)獲取這個(gè)OOB data,比如通過(guò)IR紅外,或其余的方式,因此對(duì)于藍(lán)牙竊聽者/攻擊者而言這個(gè)data的傳輸是不可見的了,因此會(huì)顯得要安全些。 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 表示最大認(rèn)證key大小是0x10個(gè)字節(jié) 6:InitiatorKeyDistribution:該域表明秘鑰初始化設(shè)備請(qǐng)求分配秘鑰分配使用。 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 該字段表明秘鑰初始化設(shè)備請(qǐng)求響應(yīng)設(shè)備來(lái)分配秘鑰分配使用。 |
?
?
b:從設(shè)備向主設(shè)備向發(fā)送配對(duì)回復(fù)報(bào)文。
具體字段含義參考 配對(duì)請(qǐng)求報(bào)文。
?
1.2 ?配對(duì)確認(rèn)
配對(duì)確認(rèn)用來(lái)在成功的配對(duì)特征交換之后啟動(dòng)STK生成。
該命令被兩個(gè)對(duì)等設(shè)備使用來(lái)向?qū)Φ仍O(shè)備發(fā)送確認(rèn)值。
初始化設(shè)備通過(guò)向響應(yīng)設(shè)備發(fā)送配對(duì)確認(rèn)命令啟動(dòng)STK生成。
?
報(bào)文格式
?
?
| 啟動(dòng)STK的生成,這一部分可簡(jiǎn)述為以下步驟的實(shí)現(xiàn):? 1. Initiator生成一128-bit隨機(jī)數(shù)Mrand,并使用這個(gè)Mrand結(jié)合一些其他的輸入,使用密碼工具箱中c1計(jì)算出一個(gè)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隨機(jī)數(shù)Srand,并使用這個(gè)Srand結(jié)合一些其他的輸入,使用密碼工具箱中c1計(jì)算出一個(gè)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將其計(jì)算的Mconfirm值通過(guò)Pairing Confirm包發(fā)送給Responder,而Responder也將其計(jì)算的Sconfirm值通過(guò)Pairing Confirm包發(fā)送給Initiator; Initiator收到Sconfirm后,再將Mrand值通過(guò)Pairing Random包發(fā)送給Responder; Responder收到Mrand值后計(jì)算它的Mconfirm值,再跟前面那個(gè)Initiator送過(guò)來(lái)的Mconfirm值進(jìn)行比較,若不同說(shuō)明配對(duì)失敗了。若相同,則Responder也會(huì)將它的Srand值通過(guò)Pairing Random包發(fā)送給Initiator; 而Initiator也會(huì)計(jì)算收到的Srand值的Sconfirm值,并跟前面那個(gè)Responder送過(guò)來(lái)的Sconfirm值進(jìn)行比較,若不同說(shuō)明配對(duì)失敗了,若相同,繼續(xù)。 |
報(bào)文實(shí)例?
主設(shè)備向從設(shè)備發(fā)送配對(duì)確認(rèn)報(bào)文,從設(shè)備也向主設(shè)備發(fā)送配對(duì)確認(rèn)報(bào)文。
?
1.3 配對(duì)隨機(jī)
該命令用來(lái)由初始化和響應(yīng)設(shè)備發(fā)送用來(lái)計(jì)算在配對(duì)確認(rèn)命令中的確認(rèn)值的隨機(jī)數(shù)。
?
報(bào)文格式
?
報(bào)文實(shí)例
主設(shè)備向從設(shè)備發(fā)送配對(duì)隨機(jī)值報(bào)文,從設(shè)備也向主設(shè)備發(fā)送配對(duì)隨機(jī)值報(bào)文。
?
1.4 配對(duì)特定key 分發(fā)
?
| BLE的SMP的一些Key相關(guān)定義 Long Term Key (LTK):加密鏈路用,128-bit; Encrypted Diversifier (EDIV):在LE legacy pairing過(guò)程中,用于識(shí)別LTK分發(fā),16-bit; Random Number (Rand):在LE legacy pairing過(guò)程中,用于識(shí)別LTK分發(fā),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):用于對(duì)數(shù)據(jù)進(jìn)行簽名已經(jīng)驗(yàn)證簽名數(shù)據(jù),128-bit; |
?
?
1.4.1 ?特定key分發(fā)原因
在秘鑰分配階段slave把秘鑰給master所有重連能夠被加密,它的隨機(jī)地址能夠被解析或者master設(shè)備能校驗(yàn)來(lái)自slave簽名數(shù)據(jù)。
Master也向slave提供數(shù)據(jù)所以如果角色交換重連能夠被加密,master的隨機(jī)地址能夠被解析或者slave能夠校驗(yàn)來(lái)自master的簽名數(shù)據(jù)。
如下是藍(lán)牙SPEC的描述:
?
1.5 綁定
就是將配對(duì)階段產(chǎn)生的一系列key 保持到flash中,以便后續(xù)使用。
總結(jié)
以上是生活随笔為你收集整理的BLE 配对流程(转自襄坤在线)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: AB1601 PWM模块
- 下一篇: BLE 绑定流程(转自襄坤在线)