Skip to content

Experimental support for pkcs#11#5

Open
junkmejl63 wants to merge 8 commits intonxp-imx-support:masterfrom
junkmejl63:master
Open

Experimental support for pkcs#11#5
junkmejl63 wants to merge 8 commits intonxp-imx-support:masterfrom
junkmejl63:master

Conversation

@junkmejl63
Copy link

Use nxp-cst-signer with cst, and sign images using pkcs11 tokens

  • Follow the README
  • Have been tested with cst-3.4.1 (re-compiled version)
  • Yubikey 5
  • Ubuntu 22.04 LTS

Use nxp-cst-signer with pkcs11 tokens
@sdrabb
Copy link

sdrabb commented Jan 30, 2025

can we provide also the way we can modify the cfg file once we select pkcs#11?

Copy link

@kadirc kadirc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problematic call to DEBUG macro

src/cst_signer.c Outdated
fprintf(fp_csf_file, "\tSource = \"%s/crts/%s\"\n", g_cst_path, rvalue);

} else { // use PKCS#11
DEBUG("PKCS11:\n");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line results in a syntax error because the VA_ARGS is empty, leading to an extra comma before the closing parenthesis.

I get following error trying to compile this PR:

| In file included from cst_signer.c:9:
| cst_signer.c: In function ‘create_csf_file_v3’:
| ../inc/cst_signer.h:67:107: error: expected expression before ‘)’ token
|    67 |                                     printf("%s:%s:%d: " fmt, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__); \
|       |                                                                                                           ^
| cst_signer.c:552:17: note: in expansion of macro ‘DEBUG’
|   552 |                 DEBUG("PKCS11:\n");
|       |                 ^~~~~

Following change to the macro fixes my problem:

--- a/inc/cst_signer.h
+++ b/inc/cst_signer.h
@@ -64,7 +64,7 @@ const char* desc_opt[] =
 
 #define DEBUG(fmt, ...)     do { \
                                 if (1 == g_debug) { \
-                                    printf("%s:%s:%d: " fmt, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__); \
+                                    printf("%s:%s:%d: " fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
                                 } \
                             } while(0)

https://github.com/nxp-imx-support/nxp-cst-signer/blob/c632233fc5cf7186740d143c180478c76758580a/inc/cst_signer.h#L65

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it, I must have added between testing and comitting (I'm not an expert on git).
Also added some details on how to find the pkcs#11 url, and an example (that must be changed), on PKCS#11 URL in the cfg.

Added some more details on pkcs#11 and csf example file.
Fixed a typo in the debug() statement.
Three changes
- When adding pkcs#11, accidentially s swapped arguments, causing HAB4 images to not work
- nxp-cst signer is sensitive if the cfg have empty "variable=\x0" on last line,as may  cause segementation failure
- nxp-cst-siger fails invokation of of cst, if the cfg file contains CRLF.
@utkarshguptanxp
Copy link
Contributor

Thank you for the contribution. As we cannot accept the PR directly, we will make this change and commit acknowledging the PR.

- The solution protects the private key from exposure of normal usage.

PKCS#11 is expeimental support is added for linux, append --pkcs11
In order for this to work, PKCS11_MODULE_PATH must be set before invoking
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will reword this description. CST does have HSM docker environment to experiment with this feature, so would refer to it as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite still experimental, still working on it, have also made some adjustment for it to work with i.MX8MN and i.MX8MP.

Docker make and standalone make, places binaries on different places.
Support pkcs11: keys for csf and img signing on hab4.
Some clarifications on the cst_signer.c
utkarshguptanxp pushed a commit that referenced this pull request Jan 30, 2026
…r cst hab and spsdk ahab

Merge in IMXS/cst-signer from feature/MICRSE-3703-imx-signer-add-pkcs11-backend-for-cst-hab-and-spsdk-ahab to master

* commit '1c477bda6e2625cae88832212a2457868002b6cb':
  [MICRSE-3703] Create build_pkcs11_uri routine for the pkcs11 string and Support for NOCAK Fast Authentication
  Applying Suggestion, env_result, replacing conditions about the pkcs11 token
  Applying suggestion. The parse method is looking for an extact string.
  Fix format and adding .gitignore
  [MICRSE-3703] Updating Pull Request Requirements
  MICRSE-3703: PCKS11 Support for HAB, with/wihtout token and usr pin definition
  PCKS11 Implementation withe img file.
  PKCS11 Support for CSF Complete TODO: Working to create a function that implements this routine
  PCKS11 Implementation defining token in the csf file
  PKCS11 Token support. 	- CSF config file is looking for the token in the csfk_file and img_file 	- Adding -b pkcs11 extra param 	- TODO Implement a new strncpy and avoid overwrite --verbose command
  Adding verify routing if there is a Interact Token for the image0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants