This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Get in flash stored appkey via dsm

Hi,

I have a question about getting the appkey from flash:

I am using the device state manager for key management. I do a ramdom generation of netkey and appkey on first start of a clean device. The netkey and appkey are stored in flash (PERSITENT STORAGE) .

After rebooting the device, I would like to load the netkey and appkey to configure new server nodes with the same keys.

Getting the netkey (subnetkey) is very easy with dsm_subnet_key_get(). Why it is so hard to get the appkey???? There is no dsm_appkey_get() function?
I have to use dsm_tx_secmat_get() and search in the scmat struct for the appkey which is stored as .p_key->key.

Is there a better/easier way to load the appkey from flash? Generating a new appkey each time on reboot (like in the provisioner example mesh v4.2) makes no sense for me. 

Best regards,
Jeff

  • Hi Jeff,


    Could you elaborate more on which firmware you are asking about ? Is it a provisioner ? Or it's a normal node ?
    In our provisioner example the application key is stored and restored on each booting when mesh_config_load() is called (then provisioner_setter() is called and then m_nw_state will be assigned the value). As far as I know the provisioner only generate new random appkey when prov_helper_provision_self() is called. And this function is only called once because next boot the stored data will be used. 

  • Hi Hung Bui,

    thank you for response.

    It is not firmware specific, it is in general. If you look for example into the SDK Mesh v4.2 /examples/provisioner/project:

    1. In node_setup.c in function config_step_execute() you have the case NODE_SETUP_CONFIG_APPKEY_ADD, where you sent config_client_appkey_add(m_netkey_idx, m_appkey_idx, mp_appkey) to the new server node.

    2. mp_appkey which is set in  node_setup_start() in provisioner_helper.c file by m_provisioner.p_nw_data->appkey

    3. m_provisioner.p_nw_data->appkey is generated by rand_hw_rng_get() in function prov_helper_provision_self()

    There is no other place in the whole provisioner project where a value (appkey) is assigned to m_provisioner.p_nw_data->appkey. If I would reboot the provisioner m_provisioner.p_nw_data->appkey would be something else but not the appkey which was generated by rand_hw_rng_get() on first boot.

    Or am I wrong? Can you show me the place where the "flash stored appkey" is assigned to m_provisioner.p_nw_data->appkey after mesh_config_load()?

    Best regards

    Jeff

  • Hi Jeff,

    Please make sure that you have PERSISTENT_STORAGE set to 1 in your firmware so that the mesh configuration is stored.

    I assume that you have the same m_nw_state.appkey printed out on every new boot ? (the value in the log "Appkey : " when booting)


    This m_nw_state.appkey is what fed to node_setup_start() in main.c to wait for next node to be provisioned.


    Also in prov_helper_init() inside mesh_init() you can find that m_nw_state is fed into p_nw_data. And that the exact value of m_provisioner.p_nw_data->appkey when node_setup_start() is called inside provisioner_helper().


    I don't see the appkey is regenerated except from prov_helper_provision_self() which is only called once when the provisioner first boot.

  • Hi Hung Bui,

    thanks a lot! I did not recognized the setter and getter callbacks for mesh entry. Now everything makes sense for me. Have a great weekend!

    Best regards,
    Jeff

Related