cancel
Showing results for 
Search instead for 
Did you mean: 

SATSAFE-A110 fails pairing.

Takim.l
Associate II

Dear all,

Now I would like to use TLS on BLE connection because my module cannot use pairing.

So, I was starting to learn about STSAFE-A110, and have bought B-L4S5I-IOT01A. I found X-CUBE-IOTA1 project,and I had mimicked it on CubeMX/IDE bare environment of the development kit instead of import it. And I called stsafe_wrap_unwrap().

As the result, It failed StSafeA_PutAttribute() once as STSAFEA_COMMUNICATION_ERROR. Then, the calling result is always STSAFEA_UNSATISFIED_ACCESS_CONDITION.

Also I called StSafeA_GenerateLocalEnvelopeKey() without PutAttribute, but it also fails as UNSATISFIED.

I also imported the X-CUBE-IOTA1, and execute "STSAFE Wrap/Unwrap". The result is same. pairing_stsafe() falls in UNSATISFIED.

What "UNSATISFIED" means in this case? How can I recover it to "SATISFIED" state?

I found a FAQ page in STCommunity which says the "Host Key" is onetime writable. "A temporary(dummy) key was written and can't change" is acceptable at the development kit, but at least, I would like to use wrap/unwrap function... How should I do?

Best regards,

4 REPLIES 4
Takim.l
Associate II

@Benjamin BARATTE​ @Jocelyn RICARD​ 

Excuse me, dear ST members, could you give me any advice?

Best regards,

Benjamin BARATTE
ST Employee

Hi Takim,

I have check the code and I see that the stsafe_l2sec_init() function always call the stsafe_pairing() which execute the StSafeA_PutAttribute() on the host key slot. This operation is a one-time operation so the first time the return shall be 0x00 and all other time the return will be 0x11 STSAFEA_UNSATIFIED_ACCESS_CONDITION meaning that the Host keys are already set.

As the new call stsafe_PSK_init() return is ORed with the stsafe_pairing() the stsafe_l2sec_init() will always return STSAFEA_UNSATISFIED_ACCESS_CONDITION.

now in the stsafe_wrap_unwrap() function there is a call to the stsafe_pairing() which still return STSAFEA_UNSATISFIED_ACCESS_CONDITION as explained before, then the stsafe_wrap_unwrap() will not work.

What I would recommend is to change the stsafe_pairing() with the following code :

/* Perform pairing between Host MCU and STSAFE (set Host Keys)

 * Send host cipher key & host MAC key to STSAFE for pairing

 */

static int stsafe_pairing(void)

{

 int status_code = STSAFEA_INVALID_PARAMETER;

  

 uint8_t K_CMAC_Host[32] = {

  0x11, 0x11, 0x22, 0x22, 0x33, 0x33, 0x44, 0x44, 0x55, 0x55, 0x66, 0x66, 0x77, 0x77, 0x88, 0x88,

  0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};

 StSafeA_HostKeySlotBuffer_t out;

/* check pairing keys */

status_code = StSafeA_HostKeySlotQuery(stsafea_handle, &out, STSAFEA_MAC_NONE);

if (status_code == STSAFEA_OK)

{

if (out.HostKeyPresenceFlag == 0)

{

   printf("\nstsafe pairing not set");

   status_code = StSafeA_PutAttribute(&stsafea_handle,      // STSAFE obj ptr

                   STSAFEA_TAG_HOST_KEY_SLOT, // Attribute tag

                   K_CMAC_Host,        // dataIn (Keys)

                   sizeof(K_CMAC_Host),    // dataInLen

                   STSAFEA_MAC_NONE);     // MAC

   printf("\npairing_stsafe result (0 means success): %d\n", (int)status_code);

  }

 }

 return status_code;

}

in that case, we check if the pairing is already done and if yes, we return STSAFEA_OK.

hope this will help.

Best Regards,

Benjamin

Takim.l
Associate II

Dear @Benjamin BARATTE​ ,

Thank you ​for your advice. I have applied your code.

StSafeA_HostKeySlotQuery returns STSAFEA_OK, and the HostKeyPresenceFlag is 1.

But unfortunately, the problem was not improved.

The error is same as previously, as shown as;

>stsafe_wrap_unwrap result (StSafeA_GenerateLocalEnvelopeKey - 0 means success): 17

I have no idea why StSafeA_GenerateLocalEnvelopeKey() returns UNSATISFIED...

Do you have any other advice for this problem?

Further, StSafeA_GenerateLocalEnvelopeKey returns error, but StSafeA_Echo, StSafeA_ProductDataQuery, StSafeA_LifeCycleStateQuery, StSafeA_HostKeySlotQuery, and StSafeA_GenerateRandom are working correctly.

Just in case, I attached the result of LifeCycleStateQuery, and HostKeySlotQuery;

[LifeCycleStateQuery]

 Length:1

 LifeCycleStatus:3

[HostKeySlotQuery]

 Length:4

 HostKeyPresenceFlag:1

 HostCMacSequenceCounter:1

Best regards,

Benjamin BARATTE
ST Employee

Hi @Takim.l​ 

I forget the generation of the LocalEnvelopKey...

if the local envelop key is already generated, you will get the error 0x11 STSAFEA_UNSATISFIED_ACCESS_CONDITION.

here is code snippet to patch the stsafe_wrap_unwrap() test function to avoid generating the key if already present :

it's for the file stsafe.c around line 481 :

StSafeA_LocalEnvelopeKeyTableBuffer_t out_env;

 StSafeA_LocalEnvelopeKeyInformationRecordBuffer_t out_rec0;

 StSafeA_LocalEnvelopeKeyInformationRecordBuffer_t out_rec1;

status_code = StSafeA_LocalEnvelopeKeySlotQuery(stsafea_handle, &out_env, &out_rec0, &out_rec1, STSAFEA_MAC_NONE); 

if (status_code == STSAFEA_OK)

{

if (out_rec0.PresenceFlag == 0)

{

   status_code = StSafeA_GenerateLocalEnvelopeKey(&stsafea_handle,

                         STSAFEA_KEY_SLOT_0,

                         STSAFEA_KEY_TYPE_AES_128,

                         NULL,

                         0U,

                         STSAFEA_MAC_NONE);

   printf("\n\rstsafe_wrap_unwrap result (StSafeA_GenerateLocalEnvelopeKey - 0 means success): %d\n", status_code);

   if(status_code != STSAFEA_OK)

   {

    return status_code;

   }

  }

 }

 printf("\n\rstsafe check envelop key result (StSafeA_LocalEnvelopeKeySlotQuery - 0 means success): %d\n", status_code);

 if(status_code != STSAFEA_OK)

 {

  return status_code;

 }

This should unlock the test.

Nevertheless, the L2SEC-PSK implementation using STSAFE-A wrap mechanism should be working on your board as all preliminary step has been fulfilled.

Best Regards,

Benjamin