1. 蓝牙安全概述
蓝牙安全模型最初只包括五个不同的安全特性:配对,绑定,设备鉴权,加密和消息完整性,随着版本升级,有如下变化。
- 2.1+EDR版本引入了安全简易配对(Secure Simple Pairing,SSP),SSP有两个安全目标:防止被动偷听和中间人攻击,man-in-the-middle (MITM) attack(主动偷听)。它使用SHA-256、HMAC-SHA-256和P-192椭圆曲线等算法,并引入四个相关模型:Just Works(直接连接),Numeric Comparison(数值比较,仅用于LE Secure Connections), Passkey Entry(输入密钥) 和 Out-Of-Band(带外,很少用到) ,设备鉴权和加密保持不变。
- 3.0 + HS版本支持了AMPs。
- 4.0版本添加了LE的整个安全模型,BR/EDR和AMP安全不变。
- 4.1版本添加了BR/EDR Secure Connections特性,SSP更新算法P-256椭圆曲线,设备鉴权使用算法HMAC-SHA-256和AES-CTR,Secure Connections添加了消息完整性。
- 4.2版本添加了LE Secure Connections特性,LE配对更新算法AES-CMAC和P-256 elliptic curve,并改变数值比较关联模型,包括了使用Secure Connections生成密钥的规定。
- 5.0以上版本增加了传输距离和带宽,安全方面暂未涉及变化。
2. 蓝牙的安全模式
我们常常会听到mode 4. level 3, 但对于具体什么是mode 4? 什么是level 3,基于Bluetooth Spec初步关于蓝牙安全的mode和level相关的知识点。
2.1 Legacy security modes
包含了一下四种:
Security mode 1 (non-secure):当对端的设备为Security mode1时,就不需要做任何的加密的行为.
Security mode 2 (service level enforced security):当对端设备为security mode 2,就需要做service level的安全化(也就是加密),什么是service level?可以理解为是再L2CAP 之上的安全化(加密),对于建立L2CAP之前的ACL和LMP是不需要加密的
Security mode 3 (link level enforced security):当对端的设备为Security mode3时, 需要在发起LMP_SETUP_COMPLETE之前就需要启动安全流程
Security mode 4 (service level enforced security):处于Security mode 4的蓝牙设备应至少使用以下属性对其服务的安全需求进行分类(按安全性降低的顺序)。
- Authenticated link key required
- Unauthenticated link key required
- Security optional; limited to specific services
2.2 Legacy security level
包含了一下5种
Level 4:for services with the following attributes:
MITM protection required
128-bit equivalent strength for link and encryption keys required using FIPS
approved algorithms (E0 not allowed, SAFER+ not allowed, and P-192 not
allowed; encryption key not shortened)
User interaction acceptable
Level 3:for services with the following attributes:
MITM protection required
Encryption required
At least 56-bit equivalent strength for encryption key should be used
User interaction acceptable
Level 2:for services with the following attributes:
MITM protection not required
Encryption required
At least 56-bit equivalent strength for encryption key should be used
Level 1:for services with the following attributes:
MITM protection not required
At least 56-bit equivalent strength for encryption key when encryption is
enabled should be used
Minimal user interaction desired
Level 0: Service requires the following:
MITM protection not required
No encryption required
No user interaction required
2.3 其他说明
蓝牙为了兼容不通版本,有一些要求如下:
security mode 2 for backwards compatibility with remote devices that do not support Secure Simple Pairing(security mode 2是对于不支持SSP的蓝牙设备)
security mode 4 for devices that support Secure Simple Pairing(security mode 4是对于支持SSP的设备)
SSP对应的association models(交互模型)中,numeric comparison, out-of-band, or passkey entry使用的是“Authenticated link key required”,而“just works Secure Simple Pairing association model“对应的是"Unauthenticated link key required"
An unauthenticated link key does not have protection against MITM attacks.
更详细的说明请看: Bluetooth Core Specification v5.2 -> Host -> Part C: Generic Access Profile -> 5 Security aspects - BR/EDR physical transport -> Securtiy modes
3. 蓝牙的安全认证
以PCI 安全认证为例子,讲述蓝牙安全认证的一些明确定义的规范。
对于BR/EDR蓝牙,在2.1-4.0的版本必须 使用Mode 4 Level 3; 在4.1或以上版本必须使用Mode 4 Level 4。Mode 1、Mode 2 和Mode 4 of Just Works 任何时候不允许。
对于BLE蓝牙, 由于没有ssp模式,必须使用4.2或以上版本且使用Mode 1 Level 4。Mode 2、Mode 4 of Just Works and level 1,2,3 任何时候不允许。
4. 测试工具
hcitool是最常见测试蓝牙工具:
语法格式:hcitool [参数]
常用参数:
lescan | 扫描周围低功耗设备(BLE) |
scan | 远程扫描设备 |
-i [设备] dev | 显示本地设备 |
name | 从远程设备获取名称 |
info | 从远程设备获取信息 |
扫描所有hci0设备:
[root@linux ~]# hcitool -i hci0 scan
扫描周围hcio低功耗设备(BLE):
[root@linux ~]# hcitool -i hci0 lescan
扫描设备具体信息(查看蓝牙版本,设备信息,公司等):
[root@linux ~]# hcitool info F8:05:09:23:6F
[root@linux ~]# hcitool leinfo F3:065:18:31:35
以下是LMP版本及其对应的蓝牙版本(x代表LMP Subversion):
LMP 1.x - 对应 蓝牙1.1
LMP 2.x - 对应 蓝牙1.2
LMP 3.x - 对应 蓝牙2.0
LMP 4.x - 对应 蓝牙2.1
LMP 5.x - 对应 蓝牙3.0+HS
LMP 6.x - 对应 蓝牙4.0
LMP 7.x - 对应 蓝牙4.1
LMP 8.x - 对应 蓝牙4.2
LMP 9.x - 对应 蓝牙5.0
LMP 10.x - 对应 蓝牙5.1
LMP 11.x - 对应 蓝牙5.2