Skip to content

Commit 6157d30

Browse files
authored
Add documentation for keyless hsm2
1 parent 520deeb commit 6157d30

File tree

1 file changed

+92
-2
lines changed

1 file changed

+92
-2
lines changed

src/content/docs/ssl/keyless-ssl/hardware-security-modules/aws-cloud-hsm.mdx

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,103 @@ Make sure you have:
2323

2424
- Provisioned an [AWS CloudHSM cluster](https://docs.aws.amazon.com/cloudhsm/latest/userguide/getting-started.html) .
2525
- Installed the [appropriate software library for PKCS#11](https://docs.aws.amazon.com/cloudhsm/latest/userguide/pkcs11-library-install.html).
26-
26+
- Installed (openssl version 3 or Higher)[https://openssl-library.org/source/]
27+
- For cloudhsm-cli - [bootstrap the cli to work with your cluster](https://docs.aws.amazon.com/cloudhsm/latest/userguide/gs_cloudhsm_cli-install.html)
2728
---
2829

2930
## 1. Import the public and private key to the HSM
30-
3131
Before importing the public key, extract it from the certificate provided by your CA. Place the contents of your private key in `privkey.pem` and then run the following (replacing certificate.pem with your actual certificate) to populate `pubkey.pm`.
3232

33+
### HSM2 With Cloudhsm-CLI
34+
Setup credentials
35+
```txt
36+
export CLOUDHSM_ROLE="crypto-user"
37+
export CLOUDHSM_PIN="<CRYPTO_USER_NAME>:<CRYPTO_USER_PASSWORD>"
38+
```
39+
Convert PEM Private key to DER
40+
```txt
41+
openssl rsa -in private_key.pem -outform DER -out private_key.der
42+
```
43+
Generate temp wrapping/unwrapping keys within the HSM
44+
```txt
45+
/opt/cloudhsm/bin/cloudhsm-cli key generate-asymmetric-pair rsa \
46+
--public-label wrapping_key_rsa_pub_temp \
47+
--private-label unwrapping_key_rsa_prv_temp \
48+
--modulus-size-bits 2048 \
49+
--public-exponent 65537 \
50+
--private-attributes unwrap=true
51+
```
52+
Export the wrapping public key to local system
53+
```txt
54+
/opt/cloudhsm/bin/cloudhsm-cli key generate-file \
55+
--encoding pem \
56+
--path wrapping_key.pem \
57+
--filter attr.label=wrapping_key_rsa_pub_temp
58+
```
59+
60+
Generate temp AES key
61+
```txt
62+
openssl rand -out temp_aes.bin 32
63+
```
64+
Encrypt/wrap the payload RSA private key with AES key
65+
```txt
66+
openssl enc -id-aes256-wrap-pad \
67+
-K $(hexdump -v -e '/1 "%02X"' < temp_aes.bin) \
68+
-iv A65959A6 \
69+
-in private_key.der \
70+
-out payload_wrapped.bin
71+
```
72+
73+
Encrypt the temp AES key with the exported public wrapping key
74+
```txt
75+
openssl pkeyutl \
76+
-encrypt \
77+
-in temp_aes.bin \
78+
-out temp_aes_wrapped.bin \
79+
-inkey wrapping_key.pem \
80+
-pubin \
81+
-pkeyopt rsa_padding_mode:oaep \
82+
-pkeyopt rsa_oaep_md:sha1 \
83+
-pkeyopt rsa_mgf1_md:sha1
84+
```
85+
Concatenate the two ciphertext blobs
86+
```txt
87+
cat temp_aes_wrapped.bin payload_wrapped.bin > rsa_aes_wrapped.bin
88+
```
89+
90+
Unwrap the blob into the HSM, while adding the required attributes to the unwrapped private RSA key
91+
92+
NOTE: You need to select a hex CKA_ID which should be the same for the private and public keys (example: `0x42`)
93+
```txt
94+
/opt/cloudhsm/bin/cloudhsm-cli key unwrap rsa-aes \
95+
--data-path rsa_aes_wrapped.bin \
96+
--key-type-class rsa-private \
97+
--label <PRIV_KEY_LABEL> \
98+
--attributes sign=true id=<HEX_CKA_ID> \
99+
--filter attr.label=unwrapping_key_rsa_prv_temp \
100+
--hash-function sha1 \
101+
--mgf mgf1-sha1
102+
```
103+
104+
Clean up temp Wrapping/unwrapping keys
105+
```txt
106+
/opt/cloudhsm/bin/cloudhsm-cli key delete --filter attr.label="wrapping_key_rsa_pub_temp"
107+
/opt/cloudhsm/bin/cloudhsm-cli key delete --filter attr.label="unwrapping_key_rsa_prv_temp"
108+
```
109+
110+
Import the public key
111+
112+
NOTE: Use the same CKA_ID as in the private key
113+
```txt
114+
/opt/cloudhsm/bin/cloudhsm-cli key import pem \
115+
--path /root/pub.pem \
116+
--label <PUB_KEY_LABEL> \
117+
--key-type-class rsa-public \
118+
--attributes id=<HEX_CKA_ID>
119+
```
120+
121+
### HSM1 With key_mgmt_util (deprecated)
122+
33123
```txt
34124
keyserver$ openssl x509 -pubkey -noout -in certificate.pem > pubkey.pem
35125
```

0 commit comments

Comments
 (0)