Skip to content

CloudHSM - Unable to extract secret created with CKM_ECDH1_DERIVE

0

I am attempting to derive a shared secret in pkcs11 with CKM_ECDH1_DERIVE. I am using CloudHSM SDK3, because this functionality is not supported in SDK5. I need to be able to extract the secret after deriving it in order to run a custom key derivation function with it.

When I use the following template, the derive function fails with 0x5: CKR_GENERAL_ERROR

sharedSecretTemplate := []*pkcs11.Attribute{
	pkcs11.NewAttribute(pkcs11.CKA_TOKEN, false),
	pkcs11.NewAttribute(pkcs11.CKA_CLASS, pkcs11.CKO_SECRET_KEY),
	pkcs11.NewAttribute(pkcs11.CKA_KEY_TYPE, pkcs11.CKK_GENERIC_SECRET),
	pkcs11.NewAttribute(pkcs11.CKA_SENSITIVE, false),
	pkcs11.NewAttribute(pkcs11.CKA_EXTRACTABLE, true),
	pkcs11.NewAttribute(pkcs11.CKA_VALUE_LEN, 32),
}

This template should be valid based on the SDK3 docs: https://docs.aws.amazon.com/cloudhsm/latest/userguide/pkcs11-v3-attributes-interpreting.html#pkcs11-v3-f9

If I modify the template to set CKA_SENSITIVE = true and CKA_EXTRACTABLE = false, then the derivation succeeds. However, I'm not able to extract the derived secret so it doesn't help.

Is it possible to extract the result?

asked 2 years ago305 views

1 Answer
0

The issue you're experiencing with AWS CloudHSM and ECDH key derivation is a known limitation of the current implementation. Unfortunately, with the current setup, it's not possible to extract the derived secret key directly from the HSM while maintaining full FIPS compliance.

When using CKM_ECDH1_DERIVE in AWS CloudHSM, the key derivation process is performed in multiple steps, with some operations happening on the client side. This means that intermediate results from each step are available on the client, but the final derived key is imported into the HSM and cannot be directly extracted if you want to maintain FIPS boundary compliance.

The behavior you're seeing where the derivation succeeds with CKA_SENSITIVE set to true and CKA_EXTRACTABLE set to false is the expected behavior for maintaining key security within the HSM. However, this prevents you from extracting the secret for your custom key derivation function.

If your application absolutely requires the ability to extract the derived secret for further processing, you may need to consider alternative approaches:

  1. If FIPS compliance is not a strict requirement for your use case, you could perform the ECDH key derivation entirely on the client side using a different cryptographic library.

  2. If you're implementing SSL/TLS offload with AWS CloudHSM, this limitation may not be an issue for your specific use case.

  3. You might need to explore using a different key agreement protocol that doesn't rely on ECDH key derivation and is fully supported within the HSM.

AWS is aware of this limitation and is working on developing an option to perform ECDH key derivation entirely within the HSM. When this becomes available, it will be announced in the AWS CloudHSM version history. Until then, you'll need to work within the current constraints or explore alternative solutions based on your specific security requirements.
Sources
Known issues for the JCE SDK for AWS CloudHSM - AWS CloudHSM

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.