This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Trust Link Key in ZigBee pro

Other Parts Discussed in Thread: Z-STACK, CC2530

Hi

I am trying to make a secure zigbee network 

I have enbaled NV INIT and NV REESTORE feature in node and coordinator both 

but by default "DTC_LINKKEY_JOIN" this is commented

Coordinator - I am using znp Mesh

Nodes are zigbee router devices

Do i have to match some keys in both the ZigBee coordinator and Nodes ( Router )

  • You have to enable TC Link key on coordinator and device to enable security. What is ZAP for coordinator?
  • Zigbee pro

    So you meant that if i change the secure link key array of 16 bytes in both coordinator and router(nodes)

    And in compile option enable tc link key as true??

  • You don't have to change the key unless you think it's necessary to your application and yes, you have to enable TC_LINKKEY_JOIN in compile option to use TC link key security.
  • Will it work in Mesh Network also I mean when one router R2 is associated with Coordinator via some router R1?
  • Yes, it works on mesh network.
  • I enables TC_LINK_KEY in both coordinator and Node ( ZigBee Router device ), now the node

    even though while debugging the node code the PC reaches in the function
    "void ZDO_JoinConfirmCB( uint16 PanId, ZStatus_t Status )"

    But the device is not getting announces

    I have only enabled the TC_LINK macro in both coordinator and node

    However when i revert the old code ONLY to the node, the node device is getting announced

    have i missed some thing ?
  • What coordinator do you use? ZAP-ZNP or SOC mode? Can you elaborate your setup?
  • When I am changing the unique key value in Coordinator ZNP code
    in
    <nwk_globals.h> it is not working

    However for Nodes, If I am changing the key like shown below

    #define DEFAULT_TC_LINK_KEY { 0x5b, 0x70, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6c,\
    0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x30, 0x39 }

    ******************* In nodes ****************************
    inside <zglobals.c>
    uint8 zgPreConfigKeys = TRUE
    uint8 zgApsLinkKeyType = ZG_UNIQUE_LINK_KEY
    ----------------------------------------------------------------------------------

    ---------------IN coordinator ZNP -------------
    uint8 zgPreConfigKeys = TRUE
    uint8 zgApsLinkKeyType = ZG_GLOBAL_LINK_KEY
    -------------------------------------------------------------------------

    then node is not getting announced in coordinator, however if revert back to the original keys it is working
    { 0x5a, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6c, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x30, 0x39 }
    That means from node side if i change the keys the nodes are not getting announced which is fine and in the node if i set the keys as mentioned just above nodes are getting announced

    But what about coordinator, I want to change that also
    Like for a given set of coordinator and nodes each will be having TCL_LINK_KEY
  • Don't set zgPreConfigKeys = TRUE which would use preconfigured network key instead of using TC link key security.
  • But I have a doubt on this
    According to z stack developers guide

    """If it is set to TRUE, then the value of default key must be preconfigured on each device (to the exact same value). If it is set to FALSE, then the default key parameter needs to be set only on the coordinator device. Note that in the latter case, the key will be distributed to each joining device over-air. So there is a “moment of vulnerability” during the joining process during which an adversary can determine the key by listening to the on-air traffic and compromise the network security
    """

    that's why i have kept is as true

    and also in my case i have set up two coordinators and one node

    each coordinator have different TCL_KEY and i have made two node code with key matching as per the firmware, in this case some times it is working  ( node getting announced only to matched key coordinator ) but some times it is not working and node is restarting itself 


    what is your suggestion on this ?

  • IF you intend to use preconfigured key, you should disable TC_LINKKEY_JOIN. These two settings cannot coexist.
  • So you meant to say that

    I will disable the tclinkkey from compile option for both coordinator and nodes

    And i can customize/change the key mentioned in the macro of nwk_globals.h for both coordinator and node

    To establish a close network like one particular node gets announced only to matched macro value of coordinator(macro value used in coord'snwk_globals. h)?

  • Hi Yikai

    I run the set up with following configuration
    NV_INIT and NV_RESTORE enbaled and TC_LINK_KEY disabled

    Set up 1
    znp coord code with
    #define DEFAULT_TC_LINK_KEY { 0x5a, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6c, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x30, 0x39 }
    Node ( router ) code with
    #define DEFAULT_TC_LINK_KEY { 0x5a, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6c, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x30, 0x39 }

    Set up 2 // here I have changed the key
    znp coord code with
    #define DEFAULT_TC_LINK_KEY { 0x5b, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6c, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x30, 0x39 }
    Node ( router ) code with
    #define DEFAULT_TC_LINK_KEY { 0x5b, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6c, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x30, 0x39 }


    RESULT - Node with key {5a} joined to Coordinator with '5a' but Failure is even with Key {5b} node is joining to the same coordinator as in set up 1

    Is there some other unique Key or some thing still I am missing ?
  • Since you disable TC_LINKKEY_JOIN, you should use -DDEFAULT_KEY="{0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0D}" for preconfig network key.
  • How to set the default key in the coordinator ?
    No where it is present
    shall I only define the
    -DDEFAULT_KEY="{0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0D}
    in the coordinator ZNP code inside ,znp,cfg
  • You can also change it in f8wconfig.cfg of ZNP project.
  • There are only two files
    i have addded in znp.cfg, In the znp config file I have added the default key as same in the node ( router ) code


    The node is getting the join confirmation ( i have checked through setting a break point in zdapp.c "ZDO_JoinConfirmCB"
    but NOT getting ANNOUNCED In the coordinator
  • I think there is something wrong with your ZAP-ZNP coordinator. I suggest you to test this with SampeLight and SampleSwitch to make sure it works first.
  • any other settings or parts which I have missed out ?
  • Do you test this with SampeLight and SampleSwitch to make sure it works?
  • No Chen I was not able to do that
    but I have done some changes in my znp coordinator code
    like zgPreconfigKeyInit defined in <zGlobalc.c>
    ---------------------------------------------------------------------------------
    if ( setDefault ) // THIS CONDITION HAS BEEN REMOVED BY ME
    {
    // Write the default value back to NV
    status = osal_nv_write( ZCD_NV_PRECFGKEY, 0, SEC_KEY_LEN, zgPreConfigKey );
    }
    --------------------------------------------------------------------------
    so that the Key value defined in config file should be copied to NV memory effectively

    and from the z-tools also now the key value is getting correct ( earlier when i had not set the above logic different values were coming in RX
    *********************************************************************************************************************
    RX>07:18:32.72 COM8 UTIL_GET_NV_INFO_RESPONSE (0x6701)
    Status: 8 (0x8)
    IEEEAddress: 0x00124B0008EA156A
    ScanChannels: NONE (0x0)
    PanID: 0x0000
    SecurityLevel: 0x10
    PreConfigKey: ................ (0x00, 0x10, 0x00, 0xFF, 0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x00, 0x02, 0x04, 0x06)
    ***********************************************************************************************************************

    IN the Node Code I Have disabled NV INIT and NV RESTORE for time being

    NOW THE CASE
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    1st CASE
    Coordinator - Programmed with one key value
    Node 1st - < SAME KEY VALUE >

    RESULT - Communication is SUCCESSFUL and Data transmission is also happening

    ###################################
    Node 2nd - < DIFFERENT KEY VALUE >

    RESULT - Although the keys are different the node is getting associated but NO DATA transmission from Z tools (AF Data transmission ) is Happening
    #######################################
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


    My question is wrt Node 2nd -
    As it is not resetting/rebooting if i place a coordinator having matched key value with this particular node < will it communicate to this new coordinator ?
  • I think you have to use Ubiqua Packet Analyzer to verify it.
  • HI
    Its working ( In coordinator I have enabled NV_INIT and NV_RESTORE also )
    I have checked with two coordinator and two nodes

    But there is a problem
    I have to use NV_INIT and NV_RESTORE in NODES firmware ( Zigbee ROuter Device )
    Now as the device is not getting authenticated but still the short address is assigned to the node (which is having MISMATCHED KEY with coordinator's Key) so the node will get some short address only data transmission won't happen ( correct me if i am wrong ), and the node will remember it and it will never send fresh beacon request again to get associated with other coordinator ( having matched key )

    how to solve this ?
  • Yes, device still join but stay non-transmission If you have mismatched key. Device example in Z-Stack would enter UNAUTHORIZED status and reset itself. Do you see this?
  • No it was not resetting

    I had connected led to view this

    And yes no communication will happen that i have checked

    But one more question come to my mind

    When i used AF DATA REQUEST

    It was not giving me fail response either like

    0xE9

    0xe1

    0xCD

    although no data got recieved through that unauthorized node

  • Do you run SOC mode on device or ZAP-ZNP mode?
  • Here is the ubiqua Packet analyzer log

    case

    Coordintaor key

    -DDEFAULT_KEY="{0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0E, 0x0F}"

    Node Key

    -DDEFAULT_KEY="{0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0D}"

    SOC on ZNP means ?

    How to attach the ubiqua packet analyzer log file as it is not uploading ( problem with file format )

  • SOC means you run Zigbee application and Zigbee Stack kernel on the same CC253x. ZNP means you run Zigbee Stack kernel on CC253x and Zigbee application on another processor which acts as ZAP. You can zip Ubiqua file and attach it.
  • I am using znp stack on cc2530 and for application  I am using Z tools

    CC2530 is connected to MY PC using Serial To USB Converter

    The problem when the node device is unauthenticated it should Restart or reboot ( watchdog reset )  or some thing similar it should start RE searching for new network ( correct me if I am missing some thing ) 

    Key_mismatched_log.zip

  • If you use ZNP, I think you need to do reset/restart by yourself when device is unauthorized.
  • Any other way
    so that the node itself will know that he is having no parent coordinator and some logic addition can be done there itself like watch dog reset or start network formation again
  • Try to set a breakpoint at "ZDApp_DeviceAuthEvt();" in ZDApp_ProcessSecEvent() and debug to see how it goes.
  • HI yikai,

    I have set the logic like
    when there is a valid key match scenario
    this functions get called
    "ZDO_ProcessMatchDescReq"
    INSIDE this ( "ZDP_MatchDescRsp" )
    is called

    So i had made a logic that when ZDO END DEVICE ANNOUNCE function gets called i am setting a osal timer for 10 seconds
    as the function "ZDO_ProcessMatchDescReq" gets called ( here I am stopping that timer ) within a second as soon as ZDO END DEVICE ANNOUNCE function gets called
    and it worked also but couple of times it FAILED like after several power on reset
    How it failed - the function "ZDO_ProcessMatchDescReq" is not getting called as i have validated it


    Now the two functions mentioned by you ( "ZDApp_DeviceAuthEvt();" in ZDApp_ProcessSecEvent() ) are not getting called


    " IF DEFAULT KEY of node and coordinator doesn't match is there any way to check that scenario ?
  • I am confused by your descriptions. Can you elaborate your latest status and problem?
  • The set up is same
    ZNP coordinator ( Z stack mesh with NV init and NV Restore enabled ) CC2530
    Zstack lightning - Router ( with NV INIT and NV RESTORE enabled ) cc2530

    Scenario 1
    when default key matches
    every thing is working smoothly

    Scenario 2
    when default key doesn't match
    i have added a logic

    when PC reached ZDO_JOINconfirmCB - i m starting a timer for 10 seconds to set an event
    if that event is set after 10 seconds the node will understand that It has been connected to the wrong coordinator
    inside that event it will add that coordinator as black listed and perform a reset
    So next time onwards it will search for a coordinator apart from the blacklisted ONE

    Here if the key matched I am stopping the timer ( of 10 seconds ) as t he function "ZDO_ProcessMatchDescReq" in <Zdobject.c> is getting called instantly after ZDO_joinConfirmCB function
    So in this I am stopping the timer
    and clearing the black listed coordinator list also

    Now what is happening some times even when the key matched this particular function "ZDO_ProcessMatchDescReq" is not getting called and even though the key matches it is adding that matched key's coord in the blacklisted as the timer is not getting stopped which was started in ZDo_joinconfirmCB

    SO that's why i am asking is there any event there from which i can find that
    DEFAULT KEY has not matched and perform some action ? instead of doing all these what i have mentioned above
  • In ZDApp_ProcessNetworkJoin, it will create a ZDO_DEVICE_RESET event by calling "ZDApp_ResetTimerStart( MAX_DEVICE_UNAUTH_TIMEOUT );". If the NWK is not delivered or TC_LINK_KEY isn't matched, it would go to the red part of the following code in ZDApp_event_loop and I suppose you can do your process there.

    if ( events & ZDO_DEVICE_RESET )
    {
    #ifdef ZBA_FALLBACK_NWKKEY
    if ( devState == DEV_END_DEVICE_UNAUTH )
    {
    ZDSecMgrFallbackNwkKey();
    }
    else
    #endif
    {
    // Set the NV startup option to force a "new" join.
    zgWriteStartupOptions( ZG_STARTUP_SET, ZCD_STARTOPT_DEFAULT_NETWORK_STATE );

    // The device has been in the UNAUTH state, so reset
    // Note: there will be no return from this call
    SystemResetSoft();
    }
    }

  • I have checked by changing the default key value in the node
    Although as expected Device announce has not happened in the coordinator
    but the PC didn't reach in the event,
    if ( events & ZDO_DEVICE_RESET )

    are you saying that I have to use TC_LINK_KEY instead of default key

    and try to this by changing the  tc_link_key value in "nwk_globals.h"  in node
    and check

    As right now TC_LINKKEY_JOIN preprocessor is disabled in my code 

    Please correct me if i am wrong ?

  • I miss the point that you use ZNP. I know my theory works under SOC mode but I am not sure about ZNP.
  • The key value in file "f8wconfig.cfg"
    -DDEFAULT_KEY="{0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0E, 0x09}"
    // This is changed the last TWO bytes (0x0E, 0x09)//

    I can change the bytes to any number or is there any specific rule to change the bytes
  • What do you intend to do by changing default key?
  • That is working even by changing but the absolute thing is i was looking to create different keys for my different clients
  • If you use one DEFAULT_KEY when you build ZC and use another DEFAULT_KEY on ZED, this ZED should be not able to join ZC successfully. You can test and verify this first.
  • Yes that i have verified

  • Is it clear now?
  • Yes thanks for your responses
  • You are welcome and it's good to know it's clear now.