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