WIP: Feature/pkcs11 token - #461
Conversation
b99a779 to
cb36751
Compare
14e15bd to
20f9bb3
Compare
eb35e2b to
2c49d9f
Compare
2c49d9f to
28e753e
Compare
5e8f238 to
f8c7d67
Compare
3a80617 to
da880e5
Compare
da880e5 to
b07efe0
Compare
fdc37d7 to
8352011
Compare
8352011 to
691ffaf
Compare
691ffaf to
b8549f6
Compare
b8549f6 to
1d8ae17
Compare
6e19fc5 to
b78b1f3
Compare
b78b1f3 to
54b8cd2
Compare
54b8cd2 to
7f2da99
Compare
06bef70 to
997d86b
Compare
997d86b to
ccffae4
Compare
ccffae4 to
d1041ec
Compare
d1041ec to
555c1b4
Compare
555c1b4 to
41b165c
Compare
|
Refactored module loading, addressed change request. This PR currently depends on #586 |
41b165c to
1c9cb1e
Compare
87cb2d9 to
5069b87
Compare
| // An open session handle is the ground truth for "already unlocked". | ||
| // Do not rely on the generic token->locked flag here: p11token_unlock may | ||
| // be invoked directly (e.g. from p11token_change_pin) without going through | ||
| // the token_unlock() wrapper that maintains that flag. |
There was a problem hiding this comment.
multi-line comments pleas use following style:
/*
* line1
* line2
*/
| // flag: when called directly (e.g. from p11token_change_pin) that flag is | ||
| // not maintained, and keying off it would skip C_Logout/C_CloseSession/ | ||
| // C_Finalize/dlclose, leaking the session and leaving the module | ||
| // C_Initialize'd (breaking the next unlock with CKR_CRYPTOKI_ALREADY_INITIALIZED). |
| } p11_cipher_params_t; | ||
|
|
||
| int | ||
| int_pkcs11_wrap_to_pkcs7(const unsigned char *ciphertext, size_t ct_len, |
There was a problem hiding this comment.
declare static, isn't exposed by header
| } | ||
|
|
||
| int | ||
| int_pkcs7_unwrap_to_pkcs11(const unsigned char *der, int der_len, p11_cipher_params_t *params, |
There was a problem hiding this comment.
declare static, isn't exposed by header
|
|
||
| // TODO: use pairing secret? | ||
| token_err_t | ||
| p11token_unlock(void *int_token, const char *passwd, UNUSED const unsigned char *pairing_secret, |
| * lock token and cleanup data structure | ||
| */ | ||
| void | ||
| p11token_free(void *int_token) |
| error: | ||
| if (pt) { | ||
| mem_free0(pt); | ||
| } |
There was a problem hiding this comment.
if (ct) mem_free0(ct); evtl. mem_memset0 beforehand (is encrypted anyway but wrapped key)
| IF_TRUE_GOTO_ERROR(pt_len > INT_MAX, error); | ||
| *plain_key = pt; | ||
| *plain_key_len = (int)pt_len; | ||
|
|
There was a problem hiding this comment.
if (ct) mem_free0(ct); evtl. mem_memset0 beforehand (is encrypted anyway but wrapped key)
| P11_CHECK_RV_GOTO(ctx->C_CloseSession(sh), error); | ||
|
|
||
| // free slot id ptr | ||
| mem_free(slot); |
There was a problem hiding this comment.
possible double free if next check failes and goes to error_init.
move mem_free(slot) after the Unload Module block? Double safe with mem_free0
| token->ctx = NULL; | ||
| token->sh = NULL; | ||
| token->module = NULL; | ||
| token->initialized = true; |
c7fef9e to
165f5c4
Compare
This commit unifies the usage of the 'const' qualifier in the token API. Signed-off-by: Maximilian Peisl <maximilian.peisl@aisec.fraunhofer.de>
Add a new PKCS11-backed token (TOKEN_TYPE_PKCS11) implementation to scd. Support is enabled at compile time using the PKCS11 build flag. PKCS#11-modules are loaded dynamically at runtime based on a configurable module path. Signed-off-by: Maximilian Peisl <maximilian.peisl@aisec.fraunhofer.de>
Add support for new tokentype offered by scd. Add new 'pkcs11_module' configuration option. Similar to usbtoken or softtoken one can now configure a container to use a specific PKCS#11 module. Signed-off-by: Maximilian Peisl <maximilian.peisl@aisec.fraunhofer.de>
Pass scd-specific environment variables defined in 'device.conf' to scd-unit. Signed-off-by: Maximilian Peisl <maximilian.peisl@aisec.fraunhofer.de>
This commit contains several enhancements and security hardening improvements to the PKCS#11 token type. Parts are based on severall rounds of AI-based security audits with corresponding code suggestions. All proposed changes have been manually reviewed and applied on a per case basis. Assisted-by: Claude:claude-fable-5 Signed-off-by: Maximilian Peisl <maximilian.peisl@aisec.fraunhofer.de>
Guard PKCS#11 related changes to the protobuf files such that they are excluded in CC_MODE builds. Signed-off-by: Maximilian Peisl <maximilian.peisl@aisec.fraunhofer.de>
Add key derivation function which implements PBKDF2-HMAC-SHA256. Assisted-by: Claude:claude-fable-5 Signed-off-by: Maximilian Peisl <maximilian.peisl@aisec.fraunhofer.de>
Bind user-pin to pairing device secret using a KDF. Assisted-by: Claude:claude-fable-5 Signed-off-by: Maximilian Peisl <maximilian.peisl@aisec.fraunhofer.de>
165f5c4 to
44937e8
Compare
Support for generic PKCS#11 tokens:
TODO: integration in daemonTODO: integration testing
TODO before merging: squash commits