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

Experimental support for pkcs#11 #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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)

#define DEBUG(fmt, ...) do { \

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.
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.

4 participants