@@ -47,53 +47,181 @@ Now open a new terminal window and login to Vault. This is an example for a dev
4747
4848### Setup
4949
50- Enable the HSM PKI plugin:
50+ #### Setup Without CA Generation
5151
52- ` vault secrets enable -path=hsmpki -options="config=conf/config-softhsm.hcl" vaultplugin-hsmpki `
52+ These instructions apply if the Intermediate CA has been created and signed by a Root CA externally to Vault.
5353
54- ### Run
54+ ##### Enable the HSM PKI plugin:
55+
56+ ` vault secrets enable -path=hsmpki_inter -options="config=conf/config-softhsm.hcl" vaultplugin-hsmpki `
57+
58+ #### Setup With CA Generation
59+
60+ These instructions apply if the Root and Intermediate CAs need to be created and signed by Vault.
61+
62+ ##### Enable the HSM PKI plugin paths:
63+
64+ * Different configuration files can be passed to each instance of the plugin.
65+ * These may contain alternative HSM slot and PIN settings.
66+ * If no key label is specified then one will be automatically generated and stored within Vault.
67+ * The automatically generated key label is provided in the response to the Generate Root and Generate Intermediate commands.
68+
69+ Root CA path:
70+ ` vault secrets enable -path=hsmpki_root -options="config=conf/config-safenet.hcl" vaultplugin-hsmpki `
71+
72+ Intermediate CA path:
73+ ` vault secrets enable -path=hsmpki_inter -options="config=conf/config-safenet.hcl" vaultplugin-hsmpki `
74+
75+ ### Run Create CA certs and Issue
76+
77+ In this sequence of steps Vault:
78+
79+ * generates a Root CA cert using the hsmpki_root path
80+ * generate an Intermediate CA and CSR using the hsmpki_inter path
81+ * signs the Intermediate CA's CSR producing the cert using the hsmpki_root path
82+ * sets the signed Intermediate CA using the hsmpki_inter path
83+ * creates a role
84+ * issues a new private key and a new cert signed by the Intermediate CA using the hsmpki_path
85+
86+ #### Generate Root CA
87+
88+ Notice that key_label is returned alongside serial_number. Also note that the certificate is the same as the issuing certificate.
89+
90+ A key label for the HSM will be generated automatically if a key_label isn't specified in the conf file.
91+
92+ The format of the automatically generated key_label is eg. ROOTCA20210314232939
93+
94+ ` vault write hsmpki_root/root/generate/internal common_name=safenet.ec.ca.mode51.software key_type=ec key_bits=521 permitted_dns_domains=localhost organization="mode51 Software Ltd" ou="Software" country="GB" locality="Cambridge" province="Cambridgeshire" street_address="1 A Street" postal_code="CB1" `
95+
96+ Save the signed Intermediate CA to a file eg. data/root.cert.pem
97+
98+ This CA cert can be imported into a browser for testing.
99+
100+ #### Generate Intermediate CA and CSR
101+
102+ The format of the automatically generated key_label is eg. INCA20210314233609
103+
104+ ` vault write hsmpki_inter/intermediate/generate/internal common_name=safenet.ec.interca.mode51.software key_type=ec key_bits=384 permitted_dns_domains=localhost organization="mode51 Software Ltd" ou="Software" country="GB" locality="Cambridge" province="Cambridgeshire" street_address="1 A Street" postal_code="CB1" `
105+
106+ Save the CSR to a file, eg. data/intermediate.csr.pem
107+
108+ Use openssl to check the CSR:
109+
110+ ` openssl req -in ./data/intermediate.csr.pem -text `
111+
112+ #### Sign the Intermediate CA
113+
114+ ` vault write hsmpki_root/root/sign-intermediate csr=@data/intermediate.csr.pem common_name=safenet.ec.interca.mode51.software key_type=ec key_bits=384 permitted_dns_domains=localhost organization="mode51 Software Ltd" ou="Software" country="GB" locality="Cambridge" province="Cambridgeshire" street_address="1 A Street" postal_code="CB1" `
115+
116+ Save the signed Intermediate CA to a file eg. data/intermediate.cert.pem
117+
118+ This CA cert can be imported into a browser for testing.
119+
120+ #### Set the Signed Intermediate CA
121+
122+ If the key label has been automatically generated as part of the Generate Intermediate command then it doesn't need to be specified here or in the conf file:
123+
124+ ` vault write hsmpki_inter/intermediate/set-signed certificate=@data/intermediate.cert.pem hash_algo="SHA-512" `
55125
56126#### Create a Role
57127
58128Create a role for the allowed domain, which configures the certificate signing template, in this case localhost:
59129
60- ` vault write hsmpki/roles/localhost allowed_domains=localhost allow_subdomains=true ttl=24h max_ttl=72h key_type="ec" key_bits="384" `
130+ ` vault write hsmpki_inter/roles/localhost allowed_domains=localhost allow_subdomains=true ttl=24h max_ttl=72h key_type="ec" key_bits="384" `
131+
132+ #### Issue a New Signed Cert
133+
134+ Ask Vault to create a new key pair, generate a CSR and sign it using the HSM, returning both the private key, the CA and the signed certificate:
135+
136+ ` vault write hsmpki_inter/issue/localhost common_name=localhost `
137+
138+
139+ ### Run Signing Using an Externally Generated and Signed CA
61140
62141#### Set the Signed Intermediate CA
63142
64- Set the signed Intermediate certificate and use the HSM PKI extensions supporting the configuration of the HSM key alias and the preferred SHA algorithm :
143+ Set the signed Intermediate certificate and use the HSM PKI extensions supporting the configuration of the HSM key alias and the preferred SHA algorithm.
144+
145+ The key label can also be configured in the conf file passed in to the secrets enable command:
146+
147+ ` vault write hsmpki_inter/intermediate/set-signed certificate=@data/safenet-inter-0016.ca.cert.pem key_label="ECTestCAInterKey0016" hash_algo="SHA-512" `
148+
149+ #### Create a Role
150+
151+ Create a role for the allowed domain, which configures the certificate signing template, in this case localhost:
65152
66- ` vault write hsmpki/intermediate/set-signed certificate=@data/safenet-inter-0016.ca.cert.pem key_alias="ECTestCAInterKey0016" hash_algo="SHA-512 " `
153+ ` vault write hsmpki_inter/roles/localhost allowed_domains=localhost allow_subdomains=true ttl=24h max_ttl=72h key_type="ec" key_bits="384 " `
67154
68155#### Sign a CSR
156+
69157Now that Vault is ready for signing, sign a standalone CSR file using the HSM returning the CA and the signed certificate:
70158
71- ` vault write hsmpki /sign/localhost csr=@data/localhost512.csr.pem `
159+ ` vault write hsmpki_inter /sign/localhost csr=@data/localhost512.csr.pem `
72160
73- #### Generate a Key, CSR and Sign
161+ #### Issue a New Cert
74162
75163Ask Vault to create a new key pair, generate a CSR and sign it using the HSM, returning both the private key, the CA and the signed certificate:
76164
77- ` vault write hsmpki /issue/localhost common_name=localhost `
165+ ` vault write hsmpki_inter /issue/localhost common_name=localhost `
78166
79167#### Revoke a Certificate
80168
81- ` vault write hsmpki /revoke serial_number="<your serial number>" `
169+ ` vault write hsmpki_inter /revoke serial_number="<your serial number>" `
82170
83171#### View Revocation Time of Certificate
84172
85- ` vault read hsmpki /cert/<your serial number> `
173+ ` vault read hsmpki_inter /cert/<your serial number> `
86174
87175#### View CRL
88176
89- ` curl --header "X-Vault-Token: root" http://127.0.0.1:8200/v1/hsmpki /crl/pem > data/crl.txt `
177+ ` curl --header "X-Vault-Token: root" http://127.0.0.1:8200/v1/hsmpki_inter /crl/pem > data/crl.txt `
90178
91179` openssl crl -in ./data/crl.txt -text `
92180
181+ ### Verify Certs
182+
183+ Install nginx and setup the TLS certificate and private key for the test site,
184+ referred to below as localhost.crt and localhost.key.
185+
186+ These are the private key and the certificate generated by Vault's issue command.
187+
188+ Separately import the Root CA and Intermediate CA into a web browser.
189+
190+ Visit https://localhost:444/ and confirm that the TLS certificate is accepted.
191+
192+ ```
193+ server {
194+
195+ listen 444 ssl http2 default_server;
196+
197+ server_name localhost;
198+
199+ ssl_certificate /etc/nginx/certs/localhost.crt;
200+
201+ ssl_certificate_key /etc/nginx/certs/localhost.key;
202+
203+ ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
204+
205+ ssl_ciphers HIGH:!aNULL:!MD5;
206+
207+ location / {
208+ root /usr/share/nginx/html;
209+ index index.html index.htm;
210+ }
211+ ```
212+
93213### Testing
94214
95215View the [ TESTING] ( TESTING.md ) README
96216
217+ ### Troubleshooting
218+
219+ #### SafeNet DPoD [ Troubleshooting] ( https://thalesdocs.com/dpod/services/hsmod_services/hsmod_troubleshooting/index.html )
220+
221+ ##### HSM error code 0x80001604
222+
223+ This may indicate that the SafeNet DPoD partition is full
224+
97225## License
98226
99227HSM PKI for Vault was sponsored by [ BT UK] ( https://www.globalservices.bt.com/en/aboutus/our-services/security ) , developed by [ mode51 Software] ( https://mode51.software ) , and contributed to the [ HashiCorp community] ( https://www.vaultproject.io/docs/plugin-portal ) under the Mozilla Public License v2.
0 commit comments