Closed giuspen closed 1 year ago
Hi @giuspen Thank you for reporting the issue. We will check it and get back to you.
Hi @giuspen Is there a reason for using the CBOR library instead of the standard JSON library in the fleet provisioning demos ? I saw that both fleet provisioning demos use CBOR and I wanted to know the reasoning for that, is there an advantage ? or is it just a preference ?
BR
Hi @ncohen17 it wasn't me who chose the JSON library, I merely created the other demo (KeysCert) starting from a duplication of this one (CSR) so I inherited a choice already done.
Hi @giuspen OK, Thank you for your reply. Would you be able to tell me what is the main difference between the 2 fleet provisioning demos CSR and KeyCert ?
Also, just to confirm are both fleet provisioning demos using CBOR or JSON ?
BR
Sure @ncohen17 the difference is that the KeysCert has the client private key generated on the server and sent to the client while the CSR has the client private key generated locally either from the demo or (as an option I proposed in my PR) already existing prior to running the demo. I haven't analysed the JSON library sorry was not of interest to me.
@giuspen: CorePKCS#11 is meant to simulate how one would use a Secure Element / Hardware Security Module which provides key storage in a secure manner where the private key is not exportable. The restrictions you are running into are intentional.
The corePKCS#11 PAL implementation for linux actually stores keys and certificates on the filesystem.
As I mentioned in PR #1877, you're welcome to contribute a fleet provisioning demo which does not use pkcs11 and instead calls mbedtls or openssl libcrypto APIs directly to store keys and certificates on the filesystem.
I see thanks @paulbartell I've been clearly trying to hijack the demo
There is a bug in the fleet provisioning demo with CSR.
The demo, in
pkcs11_operations.c
,generateKeyAndCsr
is creating a private key viabut then since the API of
C_GenerateKeyPair
is not exposing thembedtls_pk_context
of the generated private key (onlyprivKeyHandle
), it is somehow reconstructing it in order to pass that tombedtls_x509write_csr_set_key
:But then if I save the private key out of this
mbedtls_pk_context
that will fail to be reused as a valid private key in another demo (like mqtt mutual auth)If instead I use directly the private key
mbedtls_pk_context
as generated inside of C_GenerateKeyPair it works fine for reuse in another demo such as the mqtt mutual auth.The rebuilding of the private key
mbedtls_pk_context
in the demo is clearly the issueExample of difference in the keys