Ok, here's the answer from AWS support - hopefully, they will add it to their docs
Determine CloudHSM file handles for private and public key (you can do this by dumping the modulus from the cert and using the hsm tools to hunt for the key. However, I reported on handles prior to generating my CSR and after so I could add them to my secure documentation - so I didn't need to do that
Create a KSP container
C:\Program Files\Amazon\CloudHSM>import_key.exe -from HSM
-privateKeyHandle <private key handle> -publicKeyHandle <public key handle>
This should output something similar to:
"Represented 1 keypairs in Cavium Key Storage Provider."
If you receive an error message "n3fips_password is not set" make sure to set the login credentials for the HSM on your system as detailed in [4] below.
- Run the following command to verify the new key container is in your key storage provider:
C:\Program Files\Amazon\CloudHSM>certutil -key -csp "Cavium Key Storage provider"
"Cavius Key Storage Provider" may not be the name given to your key container. This name is retrieved from the output generated from the first step.
If the container was successfully created, the output should be similar to the following:
Cavium Key Storage provider:
<key container name>
RSA
CertUtil: -key command completed successfully.
- Create a repair.txt so we can update the cert store to use the container
[Properties]
11 = "" ; Add friendly name property
2 = "{text}" ; Add Key Provider Information property
_continue_="Container=<key container name>&"
_continue_="Provider=Cavium Key Storage Provider&"
_continue_="Flags=0&"
_continue_="KeySpec=2"
- Make sure that the CloudHSM Client daemon is still running, and use the
certutil verb -repairstore
to update the certificate serial number. This command would look something similar to the following:
certutil -repairstore my <certificate serial number> repair.txt
- After repairing the certificate store, please run the following command to verify that the certificate has been properly associated with the new key container successfully:
certutil -store my
You'll expect something like this
================ Certificate 0 ================
Serial Number: <certificate serial number>
Issuer: CN=MYRootCA
NotBefore: 2/5/2020 1:38 PM
NotAfter: 2/5/2021 1:48 PM
Subject: CN=www.mydomain.com, OU=Certificate Management, O=Information Technology, L=Houston, S=Texas, C=US
Non-root Certificate
Cert Hash(sha1): 5a...24
Key Container = CNGRSAPriv-...d
Provider = Cavium Key Storage Provider
Private key is NOT exportable
Encryption test passed
CertUtil: -store command completed successfully.
If Key Container = CNGRSAPriv-...d
shows the proper container, then you know the cert KSP relationship is good
If you see Private key is NOT exportable
and Encryption test passed
you know that you are using the corrent file handles.
If you use signtool, you will need to add /sm
to force it to use machine store and not user store as the process above generates the container tied to the machine store. There's no option around that.