BLE 安全
此模块包含用于控制 BLE 安全(基于 BLE 的 TLS)通信的功能。
摘要
此模块包含用于实现 TCAT 通信的函数。
启用 BLE Secure API 功能 (OPENTHREAD_CONFIG_BLE_TCAT_ENABLE) 后,才能使用此模块中的函数。
启用 TCAT 功能 (OPENTHREAD_CONFIG_BLE_TCAT_ENABLE) 后,才能使用此模块中的函数。
| 枚举 | |
|---|---|
| otTcatApplicationProtocol{ | 枚举 表示 TCAT 应用协议。 | 
| otTcatCommandClass{ | 枚举 表示 TCAT 命令类。 | 
| otTcatStatusCode{ | 枚举 表示 TCAT 状态代码。 | 
| 类型定义符 | |
|---|---|
| otHandleBleSecureConnect)(otInstance *aInstance, bool aConnected, bool aBleConnectionOpen, void *aContext) | typedef void(*要在安全连接状态发生更改时调用的指针。 | 
| otHandleBleSecureReceive | typedef 通过 BLE 安全 TLS 连接接收数据时要调用的指针。 | 
| otHandleTcatApplicationDataReceive)(otInstance *aInstance, const otMessage *aMessage, int32_t aOffset, otTcatApplicationProtocol aTcatApplicationProtocol, const char *aServiceName, void *aContext) | typedef void(*通过 TCAT TLS 连接接收应用数据时调用的指针。 | 
| otHandleTcatJoin)(otError aError, void *aContext) | typedef void(*用于通知联接操作完成的调用指针。 | 
| otTcatApplicationProtocol | typedef 表示 TCAT 应用协议。 | 
| otTcatCommandClass | typedef enum otTcatCommandClass表示 TCAT 命令类。 | 
| otTcatStatusCode | typedef enum otTcatStatusCode表示 TCAT 状态代码。 | 
| otTcatVendorInfo | typedef struct otTcatVendorInfo此结构表示 TCAT 供应商信息。 | 
| 函数 | |
|---|---|
| otBleSecureConnect(otInstance *aInstance) | 初始化与使用已打开的 BLE 连接的对等方的 TLS 会话。 | 
| otBleSecureDisconnect(otInstance *aInstance) | void停止 BLE 和 TLS 连接。 | 
| otBleSecureFlush(otInstance *aInstance) | 刷新发送缓冲区。 | 
| otBleSecureGetPeerCertificateBase64(otInstance *aInstance, unsigned char *aPeerCert, size_t *aCertLength) | 返回对等 x509 证书(采用 base64 编码)。 | 
| otBleSecureGetPeerSubjectAttributeByOid(otInstance *aInstance, const char *aOid, size_t aOidLength, uint8_t *aAttributeBuffer, size_t *aAttributeLength, int *aAsn1Type) | 返回由对等 x509 证书主题的 OID 标识的属性值。 | 
| otBleSecureGetThreadAttributeFromOwnCertificate(otInstance *aInstance, int aThreadOidDescriptor, uint8_t *aAttributeBuffer, size_t *aAttributeLength) | 返回自身 x509 证书的 v3 扩展中的 OID 1.3.6.1.4.1.44970.x 的属性值,其中最后一位数 x 设置为 aThreadOidDescriptor。 | 
| otBleSecureGetThreadAttributeFromPeerCertificate(otInstance *aInstance, int aThreadOidDescriptor, uint8_t *aAttributeBuffer, size_t *aAttributeLength) | 返回对等 x509 证书的 v3 扩展的 OID 1.3.6.1.4.1.44970.x 的属性值,最后一位数 x 设置为 aThreadOidDescriptor。 | 
| otBleSecureIsCommandClassAuthorized(otInstance *aInstance, otTcatCommandClass aCommandClass) | bool指明 TCAT 命令类是否已获得授权。 | 
| otBleSecureIsConnected(otInstance *aInstance) | bool指示是否已连接 TLS 会话。 | 
| otBleSecureIsConnectionActive(otInstance *aInstance) | bool指示 TLS 会话是否处于活跃状态(已连接或正在连接)。 | 
| otBleSecureIsTcatEnabled(otInstance *aInstance) | bool指明 TCAT 代理是否已启用。 | 
| otBleSecureSend(otInstance *aInstance, uint8_t *aBuf, uint16_t aLength) | 发送安全的 BLE 数据包。 | 
| otBleSecureSendApplicationTlv(otInstance *aInstance, uint8_t *aBuf, uint16_t aLength) | 发送包含 TCAT 发送应用数据 TLV 的安全 BLE 数据包。 | 
| otBleSecureSendMessage(otInstance *aInstance, otMessage *aMessage) | 发送安全的 BLE 消息。 | 
| otBleSecureSetCaCertificateChain(otInstance *aInstance, const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength) | void设置可信顶级 CA。 | 
| otBleSecureSetCertificate(otInstance *aInstance, const uint8_t *aX509Cert, uint32_t aX509Length, const uint8_t *aPrivateKey, uint32_t aPrivateKeyLength) | void通过 TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 使用 TLS 会话的相应私钥设置本地设备的 X509 证书。 | 
| otBleSecureSetPsk(otInstance *aInstance, const uint8_t *aPsk, uint16_t aPskLength, const uint8_t *aPskIdentity, uint16_t aPskIdLength) | void设置预共享密钥 (PSK) 和加密套件 TLS_PSK_WITH_AES_128_CCM_8。 | 
| otBleSecureSetSslAuthMode(otInstance *aInstance, bool aVerifyPeerCertificate) | void为 BLE 安全连接设置身份验证模式。 | 
| otBleSecureStart(otInstance *aInstance, otHandleBleSecureConnect aConnectHandler, otHandleBleSecureReceive aReceiveHandler, bool aTlvMode, void *aContext) | 启动 BLE Secure 服务。 | 
| otBleSecureStop(otInstance *aInstance) | void停止 BLE 安全服务器。 | 
| otBleSecureTcatStart(otInstance *aInstance, const otTcatVendorInfo *aVendorInfo, otHandleTcatJoin aHandler) | 启用基于 BLE 安全的 TCAT 协议。 | 
| 结构体 | |
|---|---|
| otTcatVendorInfo | 此结构表示 TCAT 供应商信息。 | 
枚举
otTcatApplicationProtocol
otTcatApplicationProtocol
表示 TCAT 应用协议。
| 属性 | |
|---|---|
| OT_TCAT_APPLICATION_PROTOCOL_NONE | 在未启用 TCAT 代理的情况下发送的消息。 | 
| OT_TCAT_APPLICATION_PROTOCOL_STATUS | 定向到 UDP 服务的消息。 | 
| OT_TCAT_APPLICATION_PROTOCOL_TCP | 定向到 TCP 服务的消息。 | 
otTcatCommandClass
otTcatCommandClass
表示 TCAT 命令类。
| 属性 | |
|---|---|
| OT_TCAT_COMMAND_CLASS_APPLICATION | 与应用层相关的 TCAT 命令。 | 
| OT_TCAT_COMMAND_CLASS_COMMISSIONING | 与调试相关的 TCAT 命令。 | 
| OT_TCAT_COMMAND_CLASS_DECOMMISSIONING | 与停用相关的 TCAT 命令。 | 
| OT_TCAT_COMMAND_CLASS_EXTRACTION | 与密钥提取相关的 TCAT 命令。 | 
| OT_TCAT_COMMAND_CLASS_GENERAL | 与常规操作相关的 TCAT 命令。 | 
otTcatStatusCode
otTcatStatusCode
表示 TCAT 状态代码。
| 属性 | |
|---|---|
| OT_TCAT_STATUS_BUSY | 资源正忙,因此无法执行命令。 | 
| OT_TCAT_STATUS_GENERAL_ERROR | 出现与任何其他类别均不匹配的错误。 | 
| OT_TCAT_STATUS_HASH_ERROR | 该专员提供的哈希值不正确。 | 
| OT_TCAT_STATUS_PARSE_ERROR | 无法正确解析请求 / 命令。 | 
| OT_TCAT_STATUS_SUCCESS | 命令或请求已成功处理。 | 
| OT_TCAT_STATUS_UNAUTHORIZED | 发件人没有足够的授权执行指定命令。 | 
| OT_TCAT_STATUS_UNDEFINED | 请求的值、数据或服务未定义(当前)或不存在。 | 
| OT_TCAT_STATUS_UNSUPPORTED | 请求的命令或收到的 TLV 不受支持。 | 
| OT_TCAT_STATUS_VALUE_ERROR | 传输的 TLV 的值存在错误。 | 
类型定义符
otHandleBleSecureConnect
void(* otHandleBleSecureConnect)(otInstance *aInstance, bool aConnected, bool aBleConnectionOpen, void *aContext)
要在安全连接状态发生更改时调用的指针。
| 具体说明 | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| 参数 | 
 | ||||||||
otHandleBleSecureReceive
otHandleTcatApplicationDataReceive otHandleBleSecureReceive
通过 BLE 安全 TLS 连接接收数据时要调用的指针。
otHandleTcatApplicationDataReceive
void(* otHandleTcatApplicationDataReceive)(otInstance *aInstance, const otMessage *aMessage, int32_t aOffset, otTcatApplicationProtocol aTcatApplicationProtocol, const char *aServiceName, void *aContext)
通过 TCAT TLS 连接接收应用数据时调用的指针。
| 具体说明 | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 参数 | 
 | ||||||||||||
otHandleTcatJoin
void(* otHandleTcatJoin)(otError aError, void *aContext)
用于通知联接操作完成的调用指针。
| 具体说明 | |||||
|---|---|---|---|---|---|
| 参数 | 
 | ||||
otTcatVendorInfo
struct otTcatVendorInfo otTcatVendorInfo
此结构表示 TCAT 供应商信息。
在运行 TCAT 会话时,此结构的内容必须保持不变。
函数
otBleSecureConnect
otError otBleSecureConnect( otInstance *aInstance )
初始化与使用已打开的 BLE 连接的对等方的 TLS 会话。
| 具体说明 | |||
|---|---|---|---|
| 参数 | 
 | ||
| 返回值 | 
 | ||
otBleSecureDisconnect
void otBleSecureDisconnect( otInstance *aInstance )
停止 BLE 和 TLS 连接。
| 具体说明 | |||
|---|---|---|---|
| 参数 | 
 | ||
otBleSecureFlush
otError otBleSecureFlush( otInstance *aInstance )
刷新发送缓冲区。
| 具体说明 | |||||||
|---|---|---|---|---|---|---|---|
| 参数 | 
 | ||||||
| 返回值 | 
 | ||||||
otBleSecureGetPeerCertificateBase64
otError otBleSecureGetPeerCertificateBase64( otInstance *aInstance, unsigned char *aPeerCert, size_t *aCertLength )
返回对等 x509 证书(采用 base64 编码)。
| 具体说明 | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| 参数 | 
 | ||||||||
| 返回值 | 
 | ||||||||
otBleSecureGetPeerSubjectAttributeByOid
otError otBleSecureGetPeerSubjectAttributeByOid( otInstance *aInstance, const char *aOid, size_t aOidLength, uint8_t *aAttributeBuffer, size_t *aAttributeLength, int *aAsn1Type )
返回由对等 x509 证书主题的 OID 标识的属性值。
对等 OID 以二进制格式提供。如果属性读取成功,则设置属性长度;如果读取失败,则设置零。如果属性被成功读取,则按照 ITU-T X.690 标准中定义的 ASN.1 类型进行设置。
| 具体说明 | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 参数 | 
 | ||||||||||||
| 返回值 | 
 | ||||||||||||
otBleSecureGetThreadAttributeFromOwnCertificate
otError otBleSecureGetThreadAttributeFromOwnCertificate( otInstance *aInstance, int aThreadOidDescriptor, uint8_t *aAttributeBuffer, size_t *aAttributeLength )
返回自身 x509 证书的 v3 扩展中的 OID 1.3.6.1.4.1.44970.x 的属性值,其中最后一位数 x 设置为 aThreadOidDescriptor。
如果属性读取成功,则设置属性长度;如果读取失败,则设置零。需要连接才能生效。
| 具体说明 | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 参数 | 
 | ||||||||||||||
| 返回值 | 
 | ||||||||||||||
otBleSecureGetThreadAttributeFromPeerCertificate
otError otBleSecureGetThreadAttributeFromPeerCertificate( otInstance *aInstance, int aThreadOidDescriptor, uint8_t *aAttributeBuffer, size_t *aAttributeLength )
返回对等 x509 证书的 v3 扩展的 OID 1.3.6.1.4.1.44970.x 的属性值,最后一位数 x 设置为 aThreadOidDescriptor。
如果属性读取成功,则设置属性长度;如果读取失败,则设置零。需要连接才能生效。
| 具体说明 | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 参数 | 
 | ||||||||||||||
| 返回值 | 
 | ||||||||||||||
otBleSecureIsCommandClassAuthorized
bool otBleSecureIsCommandClassAuthorized( otInstance *aInstance, otTcatCommandClass aCommandClass )
指明 TCAT 命令类是否已获得授权。
| 具体说明 | |||||
|---|---|---|---|---|---|
| 参数 | 
 | ||||
| 返回值 | 
 | ||||
otBleSecureIsConnected
bool otBleSecureIsConnected( otInstance *aInstance )
指示是否已连接 TLS 会话。
| 具体说明 | |||||
|---|---|---|---|---|---|
| 参数 | 
 | ||||
| 返回值 | 
 | ||||
otBleSecureIsConnectionActive
bool otBleSecureIsConnectionActive( otInstance *aInstance )
指示 TLS 会话是否处于活跃状态(已连接或正在连接)。
| 具体说明 | |||||
|---|---|---|---|---|---|
| 参数 | 
 | ||||
| 返回值 | 
 | ||||
otBleSecureIsTcatEnabled
bool otBleSecureIsTcatEnabled( otInstance *aInstance )
指明 TCAT 代理是否已启用。
| 具体说明 | |||||
|---|---|---|---|---|---|
| 返回值 | 
 | ||||
otBleSecureSend
otError otBleSecureSend( otInstance *aInstance, uint8_t *aBuf, uint16_t aLength )
发送安全的 BLE 数据包。
| 具体说明 | |||||||
|---|---|---|---|---|---|---|---|
| 参数 | 
 | ||||||
| 返回值 | 
 | ||||||
otBleSecureSendApplicationTlv
otError otBleSecureSendApplicationTlv( otInstance *aInstance, uint8_t *aBuf, uint16_t aLength )
发送包含 TCAT 发送应用数据 TLV 的安全 BLE 数据包。
| 具体说明 | |||||||
|---|---|---|---|---|---|---|---|
| 参数 | 
 | ||||||
| 返回值 | 
 | ||||||
otBleSecureSendMessage
otError otBleSecureSendMessage( otInstance *aInstance, otMessage *aMessage )
发送安全的 BLE 消息。
如果返回值为 OT_ERROR_NONE,则 OpenThread 将获得 aMessage 的所有权,并且调用方不应再引用 aMessage。如果返回值不是 OT_ERROR_NONE,调用方会保留 aMessage 的所有权,包括在不再需要消息缓冲区时释放 aMessage。
| 具体说明 | |||||
|---|---|---|---|---|---|
| 参数 | 
 | ||||
| 具体说明 | |||||||
|---|---|---|---|---|---|---|---|
| 返回值 | 
 | ||||||
otBleSecureSetCaCertificateChain
void otBleSecureSetCaCertificateChain( otInstance *aInstance, const uint8_t *aX509CaCertificateChain, uint32_t aX509CaCertChainLength )
设置可信顶级 CA。
验证对等方的证书需要它。
用于安全 BLE 的 TLS 模式“ECDHE ECDSA with AES 128 CCM 8”。
| 具体说明 | |||||||
|---|---|---|---|---|---|---|---|
| 参数 | 
 | ||||||
otBleSecureSetCertificate
void otBleSecureSetCertificate( otInstance *aInstance, const uint8_t *aX509Cert, uint32_t aX509Length, const uint8_t *aPrivateKey, uint32_t aPrivateKeyLength )
通过 TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 使用 TLS 会话的相应私钥设置本地设备的 X509 证书。
| 具体说明 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 参数 | 
 | ||||||||||
otBleSecureSetPsk
void otBleSecureSetPsk( otInstance *aInstance, const uint8_t *aPsk, uint16_t aPskLength, const uint8_t *aPskIdentity, uint16_t aPskIdLength )
设置预共享密钥 (PSK) 和加密套件 TLS_PSK_WITH_AES_128_CCM_8。
| 具体说明 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 参数 | 
 | ||||||||||
otBleSecureSetSslAuthMode
void otBleSecureSetSslAuthMode( otInstance *aInstance, bool aVerifyPeerCertificate )
为 BLE 安全连接设置身份验证模式。
停用或启用对等证书验证。必须在启动前调用。
| 具体说明 | |||||
|---|---|---|---|---|---|
| 参数 | 
 | ||||
otBleSecureStart
otError otBleSecureStart( otInstance *aInstance, otHandleBleSecureConnect aConnectHandler, otHandleBleSecureReceive aReceiveHandler, bool aTlvMode, void *aContext )
启动 BLE Secure 服务。
当 TLV 模式处于活动状态时,在收到完整 TLV 并且消息偏移量指向 TLV 值后,系统会调用函数 aReceiveHandler。
| 具体说明 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 参数 | 
 | ||||||||||
| 返回值 | 
 | ||||||||||
otBleSecureStop
void otBleSecureStop( otInstance *aInstance )
停止 BLE 安全服务器。
| 具体说明 | |||
|---|---|---|---|
| 参数 | 
 | ||
otBleSecureTcatStart
otError otBleSecureTcatStart( otInstance *aInstance, const otTcatVendorInfo *aVendorInfo, otHandleTcatJoin aHandler )
启用基于 BLE 安全的 TCAT 协议。
| 具体说明 | |||||||
|---|---|---|---|---|---|---|---|
| 参数 | 
 | ||||||
| 返回值 | 
 | ||||||
宏
OT_TCAT_MAX_SERVICE_NAME_LENGTH
OT_TCAT_MAX_SERVICE_NAME_LENGTH 15
UDP 或 TCP 服务名称的最大字符串长度(不包括 null 字符)。
资源
OpenThread API 参考文档源自 GitHub 上提供的源代码。如需了解详情,或者为我们的文档做贡献,请参阅资源。