日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

BLE 配对流程(转自襄坤在线)

發布時間:2025/3/21 编程问答 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BLE 配对流程(转自襄坤在线) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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
00 No Bonding
01 Bonding?
10 Reserved?
11 Reserved

2:MITM域設置為1為請求MITM(中間人介入)保護,否則設置為0. 設備將標志設置為1為STK請求認證的安全屬性。
選擇Key生成的方法
如果auth Req中MITM沒有,則說明不需要人參與中間,所以IO capabilities會被忽略,只用Just Works就OK了。?
如果有OOB data,auth Req將可直接忽略,會直接選擇OOB的方式了。

3:SC:雙方設置為1,用LE安全連接進行匹配,否則為LE遺留方式配對
The SC field is a 1-bit flag that is set to one to request LE Secure Connection pairing, otherwise it shall be set to 0 based on the supported features of the initiator and responder, the possible resulting pairing mechanisms are: if both devices support LE Secure Connections, use LE Secure Connections; otherwise use LE legacy pairing.?

4:Keypress:只有在輸入密碼形式配對時起作用,當雙方都設置為1時,配對時按key會發送notify PDU。
The keypress field is a 1-bit flag that is used only in the Passkey Entry protocol and is ignored in other protocols. When both sides set that field to one, Keypress notifications shall be generated and sent using SMP Pairing Keypress Notification PDUs.

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中,以便后續使用。

總結

以上是生活随笔為你收集整理的BLE 配对流程(转自襄坤在线)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。