Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CKS_CRYTPO sample does not work when loading keys via STM32CubeProgrammer #108

Open
james-token opened this issue Nov 1, 2024 · 6 comments
Assignees
Labels
bug Something isn't working cryp Cryptographic processor internal bug tracker Issue confirmed and logged into the internal bug tracking system projects Projects-related (demos, applications, examples) issue or pull-request.

Comments

@james-token
Copy link

Describe the set-up

  • The board (either ST RPN reference or your custom board): STM32 NUCLEO-WB55RG
  • IDE or at least the compiler and its version: STM32CubeIDE 1.16.1, STM32CubeProgrammer 2.17.0

Describe the bug
Using sample CKS_CRYPT (STM32CubeWB\Projects\P-NUCLEO-WB55.Nucleo\Applications\CKS) where the keys are preloaded into FUS by keys/Store_keys.bat and WRITE_KEYS is not defined in the project results in an error (specifically, LED 3 turns on, which as per the sample's readme.txt indicates an error). Debugging the sample, the error occurs when the sample attempts to compare the encrypted text with one that it is expecting. It would appear that the bin files in the Keys directory of the sample are not in the correct format.

How To Reproduce
Follow the steps in readme.txt to load all keys via keys/Store_keys.bat. Make sure that WRITE_KEYS is not defined. Build the project in the IDE and start a debugging session. For the simple, cleartext keys, in file app.cks.c at line 187 the function data_cmp returns a non-zero result, causing function CKS_SimpleKeys to return HAL_ERROR. The same happens for function CKS_EncryptedKeys at line 361.

The file format of the bin files in the Keys directory appear to be wrong, at least for the cleartext keys Simple_128.bin and Simple_256.bin. The structure of the files appears to match the payload described in AN5185 (i.e. key-type, key-len, key). If we remove the key-type and key-length bytes and re-run the process on a new, functioning Nucleo WB55RG, we see that function CKS_SimpleKeys now returns no error.

We are currently unable to to make CKS_EncryptedKeys return correctly. We have attempted to modify Master_Key.bin, Encrypted_128.bin and Encrypted_256.bin by removing the key-type and key-length bytes and loading them onto another new Nucleo WB55 and debugging the sample. We first attempted to only modify Master_Key.bin but also tried with the other two Encrypted files without success.

Keys as provided in the sample appear to not be loaded correctly into FUS such that when they are used the produce incorrect cipher text. AN5185 describes the payload format when communicating the keys, but it does not necessarily indicate the requisite format of the files for simple, master and encrypted key files. As per https://community.st.com/t5/stm32-mcus-security/user-app-not-decrypt/td-p/296628, it would appear that the bin key files might not need the CKS header, but in the referenced link this is only attempted with simple cleartext keys and not master and encrypted keys. If we follow this guidance, we also see that cleartext keys work but not master and encrypted keys.

What is the correct file format for all key types when using STM32CubeProgrammer 2.17.0, or is there a last known working available version that will work with this sample?

Thanks!

@ALABSTM ALABSTM self-assigned this Nov 4, 2024
@ALABSTM ALABSTM added cube prog Issue related to the tool rather than the firmware published within this repository question Further information is requested cryp Cryptographic processor labels Nov 4, 2024
@mmedvedtoken
Copy link

@ALABSTM to provide some context, this is a near term issue for us, we'd like support quickly if possible.

@ALABSTM
Copy link
Contributor

ALABSTM commented Nov 6, 2024

Hi @james-token and @mmedvedtoken,

Your report has been forwarded to our development teams. I will get back to you as soon as I have their feedback.

Meanwhile, did you try to build the application with WRITE_KEYS symbol defined to check whether the issue persists?

With regards,

@ALABSTM ALABSTM moved this from To do to Analyzed in stm32cube-mcu-fw-dashboard Nov 6, 2024
@ALABSTM ALABSTM added the internal bug tracker Issue confirmed and logged into the internal bug tracking system label Nov 6, 2024
@ALABSTM
Copy link
Contributor

ALABSTM commented Nov 6, 2024

ST Internal Reference: 195818

@james-token
Copy link
Author

james-token commented Nov 7, 2024

Hi @ALABSTM,

I re-tested the sample with WRITE_KEYS symbol defined. I stepped through the sample and observed no errors unlike I do when the WRITE_KEYS symbol is not defined. With WRITE_KEYS defined, I observe LED1 is turned on when the sample runs, indicating no error, as per the sample documentation.

Thanks.

@ALABSTM ALABSTM added bug Something isn't working projects Projects-related (demos, applications, examples) issue or pull-request. and removed question Further information is requested cube prog Issue related to the tool rather than the firmware published within this repository labels Nov 27, 2024
@ALABSTM
Copy link
Contributor

ALABSTM commented Nov 27, 2024

Hi @james-token,

It looks like there is an issue with the format of the provided binary keys, as you suggested. Investigation is still ongoing. I will let you know once there is something new.

With regards,

@ALABSTM ALABSTM moved this from Analyzed to In progress in stm32cube-mcu-fw-dashboard Nov 27, 2024
@james-token
Copy link
Author

Thanks @ALABSTM, will wait for follow up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cryp Cryptographic processor internal bug tracker Issue confirmed and logged into the internal bug tracking system projects Projects-related (demos, applications, examples) issue or pull-request.
Projects
Status: In progress
Development

No branches or pull requests

3 participants