Skip to content

CloudHSM JCE migration from 3.x to 5.x can't retrieve key by label

0

In version 3 of the CloudHSM SDK we were successfully retrieving a key by its handle. Below is an example where I retrieve it by handle and then print it's label:

byte[] keyAttribute = Util.getKeyAttributes(keyHandle); CaviumKeyAttributes cka = new CaviumKeyAttributes(keyAttribute); String keyLabel = cka.getLabel();

After upgrading to version 5 of the JCE, I expected to be able to use the label that I retrieved using the 3.x sdk keyLabel above, to retrieve the same key

KeyAttributesMap findSpec = new KeyAttributesMap(); findSpec.put(KeyAttribute.LABEL, keyLabel); KeyStoreWithAttributes keyStore = KeyStoreWithAttributes.getInstance(CloudHsmProvider.PROVIDER_NAME, provider); keyStore.load(null, null); Key key = keyStore.getKey(findSpec);

But I get the following error: com.amazonaws.cloudhsm.jce.jni.exception.KeyUsageException: Key does not meet the availability requirements.

I believe that I am connected to the same HSM as I was when using 3.x.

Can anyone confirm that the "label" attribute I retrieved using 3.x, is the same value i should use to get the key in 5.x?

Can you see any other issues with my code?

asked 2 years ago651 views

1 Answer
0

Hello,

As you rightfully noted, you can use the ClientSDK v5 to retrieve the key with the same key label that was retrieved using Client SDK v3.

However, looking at the error that is presented when using ClientSDK v5, I am inclined to note that the error is returned due to the Key availability check that is enabled by default, when using ClientSDK v5[1].

The Key Availability check that is done by the ClientSDK v5 upon performing key operations, is to ensure that the key is available on more than one HSM within the CloudHSM cluster before the application is able to use the key.

To address the error that is being returned, the following 2 approaches can be considered:

a. You can proceed with adding an additional HSM to the CloudHSM cluster, where you would place the additional HSM in another subnet within the same VPC. So when keys are created on the HSM, then the key would get synchronized across all HSMs within the cluster. This is to ensure high availability, in the event that one of the HSMs encounters an issue. We generally recommend having a CloudHSM cluster with atleast 3 HSMs, with each HSM being in a different subnet and availability zone[2].

b. If adding an additional HSM to the CloudHSM cluster, is not possible, then you can also proceed with disabling the Key Availability Check that is performed by the ClientSDK v5, before the application uses the key. Looking at the error being returned, I see that you are using the ClientSDK v5 JCE provider. So to disable the Key Availability Check using JCE, you would generally run the below command on the client instance:

  • On Linux:

sudo /opt/cloudhsm/bin/configure-jce --disable-key-availability-check

  • On Windows:

"C:\Program Files\Amazon\CloudHSM\bin\configure-jce.exe" --disable-key-availability-check

I sincerely hope the above helps with the query of concern.

References:

[1] https://docs.aws.amazon.com/cloudhsm/latest/userguide/working-client-sync.html

[2] See subheader "Configuration" - https://aws.amazon.com/blogs/security/cloudhsm-best-practices-to-maximize-performance-and-avoid-common-configuration-pitfalls/

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.