在APS层用来加密的密钥被称为Link key。在ZigBee网络中,虽然APS层和网络层都有加密,但是绝大部分通信都只是在网络层的加密。
一般来说,只有在传输Network Key的时候需要在应用层被加密,并且这仅在Trust Center和新设备之间发生。因此,在这种情况下,我们也将其称为Trust Center Link key。
新设备和Trust Center之间必须要在组网之前就使用哪一个Link Key达成共识,所以新设备和Trust Center之间是不需要一个Link Key的传输过程的。
网络中的设备可以使用相同的Link key或不同的Link key,只要新设备和Trust Center之间达成共识即可。
一般来说有四种Link Key,但是我们以前两种为主。后两种目前可能用得很少了,这里仅作简要描述,不做深入探讨。
又被称为the well-known link key,其内容如下:
Default global Trust Center link key (0:15) = 0x5a 0x69 0x67 0x42 0x65 0x65 0x41 0x6c 0x6c 0x69 0x61 0x6e 0x63 0x65 0x30 0x39
其实就是字符串“ ZigBeeAlliance09 ”。这个是在ZigBee 3.0之前就一直在广泛使用的一个相同的默认的密钥,如今得以保留主要是为了保持向后的兼容性。
所有的ZigBee设备都会有这个Default Global Trust Center Link Key。如果没有指定其他的link key的话,Default Global Trust Center Link Key就是设备在入网过程中第一个被尝试使用的密钥。
如果希望能保证和其他的ZigBee 3.0的设备之间互联互通的话,这个密钥时不能改变的。

Install Code并不是一个Key,而是一个Key的输入。Install Code是16字节多项式+ 2字节CRC,再通过固定的算法,计算可以得出Link Key。这种Link Key的传输是由人工来完成的,Install Code的实际应用场景如下图所示:

待入网的新设备这边计算得出的Link Key应与Trust Center端的派生Link Key相同。这样,即使消息已加密,他们也可以在应用程序层进行通信。接下来就开始组网的过程了。
An Install Code is a sequence of 16 bytes followed by 2 bytes of CRC. A complete 18 bytes sequence is needed to generate a unique TCLK. The usage of install codes defined in Z3.0 was added to allow a generalized out-of-band key delivery method for network commissioning. It works as follows:
For further details on how to generate the install codes, see the Base Device Specification [7]. This is supported only by R21 or later revisions, so to allow backwards compatibility the application must have a way to attempt joining networks without the usage of Install Codes.
在Distributed Security Network中,没有Trust Center,每个Router都可以分发 network key。
由Router父节点向新入网设备分发的network key,在APS层是使用Distributed Security Global Link Key进行加密的。
如果希望能保证和其他的ZigBee 3.0的设备之间互联互通的话,这个密钥时不能改变的。
Distributed Security Global Link Key (0:15) = 0xd0 0xd1 0xd2 0xd3 0xd4 0xd5 0xd6 0xd7 0xd8 0xd9 0xda 0xdb 0xdc 0xdd 0xde 0xdf
如果新设备是要通过touchlink的方式进行组网的话,就需要使用Touchlink Preconfigured Link Key。
Touchlink Preconfigured Link Key (0:15) = 0xc0 0xc1 0xc2 0xc3 0xc4 0xc5 0xc6 0xc7 0xc8 0xc9 0xca 0xcb 0xcc 0xcd 0xce 0xcf
(注:任何相关问题,欢迎在文末技术交流QQ群中交流讨论。)

