Skip to content

Commit 4ba4f4e

Browse files
Merge pull request #20 from mode51software/develop
Release v0.3.3
2 parents 0bfe62b + e534e3c commit 4ba4f4e

22 files changed

Lines changed: 2279 additions & 1262 deletions

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## v0.3.3
2+
### 18/03/2021
3+
4+
* Bugfix for key label in relation to persistent storage
5+
* pathSignVerbatim
6+
7+
## v0.3.2.beta.1
8+
### 17/Mar/2021
9+
10+
* Improved connection checks
11+
* RSA keys for Generate Root and Generate Intermediate (initially hard coded to EC)
12+
* Remove hardcoded key types except for CSR gen as part of Generate Intermediate
13+
* Detect if in metamode on startup
14+
15+
## v0.3.1.beta.1
16+
### 14/Mar/2021
17+
18+
* Added Generate Root, Generate Intermediate and Sign Intermediate paths
19+
20+
## v0.3.0
21+
### 01/Mar/2021
22+
23+
* Initial release with support for HSM signing using an externally generated CA cert imported using Vault's Set Signed Intermediate command

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,25 @@ pathsetcrlconfig:
4646
pathfetchcrl:
4747
go test -v -run TestPathFetchCRL ./pkg/hsmpki
4848

49+
pathrevokecrl:
50+
go test -v -run TestPathRevokeCRL ./pkg/hsmpki
51+
52+
pathrotatecrl:
53+
go test -v -run TestPathRotateCRL ./pkg/hsmpki
54+
55+
pathtidycrl:
56+
go test -v -run TestPathTidyCRL ./pkg/hsmpki
57+
58+
pathgenerateroot:
59+
go test -v -run TestPathGenerateRoot ./pkg/hsmpki
60+
61+
pathgenerateintermediate:
62+
go test -v -run TestPathGenerateIntermediate ./pkg/hsmpki
63+
64+
pathissue:
65+
go test -v -run TestPathIssue ./pkg/hsmpki
66+
67+
pathdeleteroot:
68+
go test -v -run TestPathDeleteRoot ./pkg/hsmpki
69+
4970
.PHONY: build clean fmt start enable

README.md

Lines changed: 140 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

58128
Create 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+
69157
Now 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

75163
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:
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

95215
View 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

99227
HSM 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.

TESTING.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ If you want to run tests in an IDE then source DPoD in a shell and start the IDE
88

99
## Makefile Command Line Tests
1010

11-
Test the HSM connection where the conf is loaded in from conf/config-hsm.hcl
11+
Test the HSM connection where the conf is loaded in from conf/config-safenet.hcl
1212

1313
`make test hsmconnection`
1414

@@ -19,3 +19,9 @@ Test the HSM connection where the conf is loaded in from conf/config-hsm.hcl
1919
`make test pathfetchcrl`
2020

2121
`make test pathsetsignedintermediate`
22+
23+
`make test pathgenerateroot`
24+
25+
`make test pathgenerateintermediate`
26+
27+
`make test pathdeleteroot`

conf/config-safenet.hcl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
lib = "/opt/apps/safenet/dpod/current/libs/64/libCryptoki2.so"
3+
slot_id = 3
4+
pin = "1234"
5+
# be aware that the key_label can be overridden by dynamically providing it during Set Signed Intermediate
6+
#key_label = "ECTestCAInterKey0016"
7+
connect_timeout_s = 10
8+
read_timeout_s = 5

go.mod

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,31 @@ module github.com/mode51software/vaultplugin-hsmpki
33
go 1.13
44

55
require (
6+
github.com/armon/go-metrics v0.3.4 // indirect
67
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf
8+
github.com/fatih/color v1.9.0 // indirect
79
github.com/fatih/structs v1.1.0
10+
github.com/go-test/deep v1.0.7 // indirect
11+
github.com/google/go-cmp v0.5.2 // indirect
812
github.com/hashicorp/errwrap v1.0.0
913
github.com/hashicorp/go-hclog v0.14.1
14+
github.com/hashicorp/go-retryablehttp v0.6.7 // indirect
15+
github.com/hashicorp/go-version v1.2.1 // indirect
1016
github.com/hashicorp/hcl v1.0.1-vault
11-
github.com/hashicorp/vault v1.6.2
1217
github.com/hashicorp/vault/api v1.0.5-0.20201001211907-38d91b749c77
1318
github.com/hashicorp/vault/sdk v0.1.14-0.20210127182440-8477cfe632c0
19+
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
20+
github.com/kr/pretty v0.2.1 // indirect
21+
github.com/miekg/pkcs11 v1.0.3
22+
github.com/mitchellh/mapstructure v1.3.3 // indirect
23+
github.com/mitchellh/reflectwalk v1.0.1 // indirect
24+
github.com/mode51software/pkcs11helper v0.3.3
25+
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
1426
github.com/ryanuber/go-glob v1.0.0
27+
github.com/stretchr/objx v0.2.0 // indirect
1528
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
1629
golang.org/x/net v0.0.0-20200625001655-4c5254603344
17-
github.com/mode51software/pkcs11helper v0.3.0
30+
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a // indirect
31+
golang.org/x/text v0.3.3 // indirect
32+
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
1833
)

0 commit comments

Comments
 (0)