Any example of how to add functionality to the TF-M secure zone?

I am working on a security focused project.  This project has some specific cryptographic operations which are to be performed using secrets stored within the secure zone. 

These secrets will be either stored directly in UICR using the KMU, or stored in the TF-M PSA Internal Trusted Storage.  These secrets should never be allowed to exit the secure zone therefore the crypto operations should be completed performed within the secure zone and the results passed back into the NS application.

Is there any existing sample/example/test that demonstrates how to add an custom external API functionality to the TF-M?

Is it possible to add source files into the secure application via the Cmakefile?  

Parents
  • Hi Anthony,

    Thank you for contacting DevZone at NordicSemi.

    I am not an expert on the topic, but I would to point to Nordic blog about TF-M

    Intro to Trusted Firmware-M

    Please have a look at it and its related documentation / samples discussed, and see if it answers your question.

    If not, then let me know and I will ask you query internally.


    Regards,
    Naeem

  • Thanks for the link Naeem. 

    I'm looking for a test or sample that demonstrates passing data from the NS application to a secure service in the Application RoT and for the secure service to reply with some other data. 

    The closes example I've found is the secure peripheral partition which uses psa_call without any parameters.

    I expect that the psa_call can pass pointers to memory where the input and output buffers are located, but it would be really helpful if there were a working demonstration of how it is intended to work..

    Also is there any way to get VSCode to show the TF-M secure partition generated code or at least have it show the input files to TF-M process?

    Also where can I find documentation for the the tfm_manifest_list.yaml.in and the manifest_list and referenced manifests within it? 

    Also I'm wondering how I can set up my secure partition to be able to utilize functions from 

    #include <hw_unique_key.h>
    #include <nrf_cc3xx_platform_identity_key.h>

    These libraries are found in nrfxlib/crypto  but I don't know how to include them into the build of the secure partition.

    Is it possible to use data stored in the identity keys in a tf-m secure partition or am I limited to only using PSA supported features like the internal trusted storage?

  • Thanks yes I have found the ITS_ENCRYPTED flag.

    One issue, is seems that ITS is available in the non-secure app, this would mean the non-secure app could use the ITS interface to request the secret data.  For the security goals of this project we want to prevent the data from every leaving the secure partition. 

    Is there anyway to prevent the non-secure region from retrieving data from ITS?

  • Hi Anthony

    The non-secure will not be able to access data from a different client. i.e a secure partition.

  • Thats good to know. 

    I did a superficial review of  

    modules/tee/tf-m/trusted-firmware-m/secure_fw/internal_trusted_storage/tfm_its_req_mngr.c

    I see the tfm_its_get_req does pair the incoming request with client id from tfm_core_get_caller_client_id.  and this is used to create a unique file id in tfm_its_get when it calls tfm_core_get_caller_client_id, so essentially each client does have its own unique and isolated version of the ITS.

    This however leaves me wondering, how are the client id's assigned AND how do I insure my secure partition gets the same client id after a FOTA if for example some secure partitions are added or removed?

  • Hi Anthony,

    Thank you for your patience.

    Anthony Ambuehl said:
    how are the client id's assigned AND how do I insure my secure partition gets the same client id

    "Client Id of secure partitions are assigned in the manifest file of the secure partition.

    So the standard ones will not change, and the custom ones they are in charge of themselves."

  • How do I set the client id in the manifest?  

    Where do I find the definitions of the platform RoT services?

    I don't see a client id field in the secure_peripheral_partition example, what happens if the yaml doesn't have a client id?

Reply Children
  • Hi Anthony,
    Apologies for the delayed response as many of our experts are on summer vacations and we have huge inflow of tickets. Nonetheless, thank you for your patience, and please find below the response I received regarding your queries:
    "For the secure services, the client id is basically the partition ID. That is when a partition calls another partition inside the TF-M. When an application calls a secure service in TF-M, the client ID is the same for all non-secure applications by default. There is a configuration option to allow the non-secure applications to have different client ids (TFM_NS_MANAGE_NSID Cmake Option in TF-M ) but we don't support it yet.
    You can find some information about the subject in here:
    The client id enforcing is happening in the Secure Partition Manager of TF-M and it is following the PSA Firmware Framework (FF-M) which is also referenced in the documentation. Now the Partition ID (PID) can either be set explicitly in the yaml mainfest file:
    In our sample one can edit this file and add a "pid" field with the number that they want. In the documentation, you can see the range of valid PIDs.
    If someone doesn't explicitly set the PID TF-M will just give the next available PID. To check what PID a partition got you can search in the build folder for the file:
    ./build/tfm/generated/interface/include/psa_manifest/pid.h
    Having said all of that I want to make sure that let me clarify something.
    If the only thing that the customer wants is to store key material in the secure side the best way of doing that is to just use the PSA crypto APIs and store the key as persistent.
    We have a sample for this here:
    In this example we generate an AES key which can be used for encryption and description. The persistent keys are stored internally in the ITS partition by the Crypto partition (so the client_id of the ITS calls will be the crypto partition PID). That means in our example the key material itself can never be read by the non-secure application. The non-secure application can request to encrypt/decrypt data with the key but it cannot access the key material.
    Even though the non-secure application has access to the ITS if it tries to read the key material directly it will not have the correct client id so the ITS will not allow it to happen."
    Moreover, for the definition of the secure services, the header files are located here:
    Regards,
    Naeem
Related