ZigBee Network Key & Trust Center Link Key等

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_21352095/article/details/83215162

ZigBee中各种用于加密的Key理解

文章涉及到的变量和函数均可在Z-Stack-3.0.2中找到。

1. Network Key
在Z-Stack中就是其实就是DEFAULT_KEY,128位,用来保证网络层的安全传输。所有ZigBee网络中的设备都会对Network Key进行备份。Trust Center可以周期性的更新Network Key,如果设置为0,那么将由Coordinator生成一个随机值,通过APSME_TransportKeyReq()传输给入网的设备,如果变量zgPreConfigKeys为false,那么传送的就是生成的随机值或者不为0的值,如果变量zgPreConfigKeys为true,DEFAULT_KEY必须不为0,否则Coordinator生成的值和其他设备的值不一样,导致不能通信,两个变量的组合:

a、DEFAULT_KEY为0,zgPreConfigKeys为false:Network Key由Coordinator生成并传送给入网的设备;

b、DEFAULT_KEY不为0,zgPreConfigKeys为true,每个设备的DEFAULT_KEY和zgPreConfigKeys都必须一样,那么入网时Coordinator传送的Network Key为0(流程不可缺,但传到设备端后被丢弃,因为已经有了默认的Network Key)。

2. Trust Center Link Key
Trust Center Link Key,默认值为:5A 69 67 42 65 65 41 6C 6C 69 61 6E 63 65 30 39 (ZigBeeAlliance09),用于集中式网络的加密传输,在Z-Stack中,如果需要使用Trust Center Link Key 加密传输,那么需要添加TC_LINKKEY_JOIN这个宏,在以下情况下使用Trust Center Link Key:

a、当节点初次加入网络时,需加密传输Network Key到加入节点。

b、当Network Key更新时,有些节点因未接收到新的Network Key,因此需要Rejoin。此时,Trust Center使用Trust Center Link Key加密 Network Key发送给该重新入网节点。

c、路由器发送给Trust Center,或从Trust Center接收APS安全消息时,需要使用Trust Center Link Key。比如路由器发送节点加入或Rejoin的更新给Trust Center时,或由Trust Center发送到路由器以执行一些安全功能的命令时, 需要使用Trust Center Link Key。

d、启用APS加密的应用程序单播消息,其中发送或接收设备是Trust Center。

由Trust Center决定如何管理Trust Center Link Key的选项。它可以为每个设备选择唯一的密钥 (从设备的IEEE地址导出的密钥),或者对于所有的设备采用相同的全局密钥。
如果不使用默认的Link Key那么标准设备是加不进这个网络的。

3. Distributed security global link key
和Trust Center Link Key一样,只不过不是用在集中式网络而是用在分布式网络。

4. Install code link key
所有终端设备的Install code link key(128位)可以不同,用于生成Link Key,这个生成的Link Key和Trust Center Link Key的全局性(所有设备)不一样,取决于Install code link key。

所以如果采用不同的Install code link key,那么在设备端和Trust Center需要设置一样的Install code link key,现在能实现这种方式入网的最佳方法应该是扫码入网,出厂时给每个设备贴一个二维码,入网时通过手机扫码将获取的Install code link key传送到Trust Center。

5. Application link key
用于两个设备之间的应用层加密。

6. Device Specific trust center link key
设备专用trust center link key,只能用于Trust Center和某个设备,应该也可以将所有设备的Device Specific trust center link key设置为一样。

注意:
ZigBee 3.0中,无论是使用 Preconfigured Trust Center Link Key还是Install code link key,设备入网后都需要更新 Trust center link key,而且这个新的Key是唯一的,在Z-Stack-3.0.2中这个Key生成的代码如下:

//Generate key from the seed, which would be the unique key
ZDSecMgrGenerateKeyFromSeed(TCLKDevEntry.extAddr,TCLKDevEntry.SeedShift_IcIndex,req.key);

更新失败则退出网络,如下图所示:
Request key failed更新Key的流程如下图:
update link key

猜你喜欢

转载自blog.csdn.net/qq_21352095/article/details/83215162
key