Skip to content

Commit 8050937

Browse files
authored
Merge pull request #2 from smallstep/readme
Readme
2 parents afd72fe + 92d90cf commit 8050937

File tree

10 files changed

+417
-81
lines changed

10 files changed

+417
-81
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
uses: golangci/golangci-lint-action@v2
2424
with:
2525
version: latest
26+
args: --timeout=5m
2627
- name: Test, Build
2728
id: lintTestBuild
2829
run: V=1 make ci

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
uses: golangci/golangci-lint-action@v3
2626
with:
2727
version: "latest"
28+
args: --timeout=5m
2829
- name: Test, Build
2930
id: testAndBuild
3031
run: V=1 make ci

README.md

Lines changed: 261 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,263 @@
11
# step-kms-plugin
2-
step plugin to manage keys and certificates on a cloud KMSs and HSMs
2+
[step](https://github.com/smallstep/cli) plugin to manage keys and certificates
3+
on a cloud KMSs and HSMs.
34

4-
> ⚠️ This tool is currently in development, and its usage of it will change without announcements.
5+
> ⚠️ This tool is currently in beta mode and its usage of might change without
6+
> announcements.
7+
8+
**TL;DR** You can use `go install` to compile and install `step-kms-plugin` in
9+
your `$GOBIN`:
10+
11+
```console
12+
go install github.com/smallstep/step-kms-plugin@latest
13+
```
14+
15+
## Installation
16+
17+
The most generic way to install `step-kms-plugin` is to use `go install` to
18+
compile it and install it in your `$GOBIN`, which defaults to `$(go env GOPATH)/bin`.
19+
20+
You can also download the last release for your platform in the [releases
21+
page](https://github.com/smallstep/step-kms-plugin/releases).
22+
23+
To use `step-kms-plugin` as a `step` plugin, you need the binary located either
24+
in a `plugins` directory of your `$STEPPATH` (`$(step path --base)/plugins`) or
25+
in your `$PATH`.
26+
27+
## Supported KMSs
28+
29+
The following "Key Management Systems" or KMSs are supported, but not all of
30+
them provide the full functionality:
31+
32+
* PKCS #11 modules
33+
* [Amazon AWS KMS](https://aws.amazon.com/kms/)
34+
* [Google Cloud Key Management](https://cloud.google.com/security-key-management)
35+
* [Microsoft Azure Key Vault](https://azure.microsoft.com/en-us/services/key-vault/)
36+
* [YubiKey PIV](https://developers.yubico.com/PIV/)
37+
* ssh-agent
38+
39+
## Usage
40+
41+
`step-kms-plugin` can be used as a standalone application or in conjunction with
42+
`step`.
43+
44+
The commands under `step kms` will directly call `step-kms-plugin` with the
45+
given arguments. For example, these two commands are equivalent:
46+
47+
```console
48+
step kms create --kty EC --crv P384 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;id=1000;object=mykey?pin-value=password'
49+
step-kms-plugin create --kty EC --crv P384 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;id=1000;object=mykey?pin-value=password'
50+
```
51+
52+
For the rest of the examples, we are going to use the plugin usage, `step kms`,
53+
using the PKCS #11 KMS with [SoftHSM 2](https://github.com/opendnssec/SoftHSMv2).
54+
To initialize the SoftHSM 2 we will run:
55+
56+
```console
57+
$ softhsm2-util --init-token --free --token smallstep \
58+
--label smallstep --so-pin password --pin password
59+
Slot 0 has a free/uninitialized token.
60+
The token has been initialized and is reassigned to slot 715175552
61+
```
62+
63+
You can later delete it running:
64+
65+
```console
66+
softhsm2-util --delete-token --token smallstep
67+
```
68+
69+
### Creating a new key
70+
71+
Our PKCS #11 implementation requires always an object id (`id=1000`) and label
72+
(`object=my-key`) to create the key. We will add those as part of the URI that
73+
defines the module to use.
74+
75+
By default, the create command creates an EC P-256 key:
76+
77+
```console
78+
$ step kms create 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;id=1000;object=my-p256?pin-value=password'
79+
-----BEGIN PUBLIC KEY-----
80+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEjg5Zs/fSuvfodhZQcxcu07deKsdX
81+
sQf46/JPxQ39kPIkhD+onVVxCl462yMGVTQeLDCN3fwImoOdqZ3eKhoQOA==
82+
-----END PUBLIC KEY-----
83+
```
84+
85+
We can use `--kty`, `--crv`, and `--size` to create other types of keys. On
86+
other KMS implementations you can also use the `--pss` and `--alg` flags to
87+
define precisely the key to generate. Here we are creating a P-384 and a
88+
3072-bit RSA key:
89+
90+
```console
91+
$ step kms create --kty EC --crv P384 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;id=1001;object=my-p384?pin-value=password'
92+
-----BEGIN PUBLIC KEY-----
93+
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEBDdy2wnC6r8n2qZTa3kefjo3CEkaWXz6
94+
rWTbDNEYrzc9LXEoA7zI1j+liSGR9wLmu91keOBnweQOIR06QV12InEKFX2l3lRx
95+
nDPvq7P3MeRo9UqzKlZT+D+dhYQjB54K
96+
-----END PUBLIC KEY-----
97+
$ step kms create --kty RSA --size 3072 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;id=1002;object=my-rsa?pin-value=password'
98+
-----BEGIN PUBLIC KEY-----
99+
MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAzAtriAh4ABfboPff15CD
100+
Skzxghaeb5SqcCwvZYdlZDRlZHlcbweY80bHjFvcU+ytSZOoMgBw+XooUnTmeVo3
101+
hOy039wlZwkfv/MEL4HP1AUVNA2iS19tmybAUTK0Myl/Ui+1iGllYA3e1ChCEZwV
102+
3B5KPfpG5KiPurhKfv5q3edIVcMKL8qj8Y9HYrzFBebQil23vkWrFylb1r/54W/O
103+
5kT2emYEGaJ8lJqzvJaIsvQpk8EqkJ7FHuAMeZyb3BK8cGjIP/GI22mL6NO3LpFc
104+
PK3Zjo7mZS5tQlFR9CULEbCuM+jiOs7FRJdyhUhdkygDxuWk1hfrCMYcG59P8pQX
105+
mPaCwE78GB3Bsi50Bp4+UI9KBcp+JARdPKocd6RvASDX1KpALpFhgqrC05+JfKA+
106+
/51QMYY1mlJn7izHmwYJr0DRn1usrh5mtJEcOtwiNKR3bo1LI00XW93DIA442IzA
107+
KqMBZrEYmuy+oL6Jy9Ys4nOVWEzFcOjmUWyjFOMMG/89AgMBAAE=
108+
-----END PUBLIC KEY-----
109+
```
110+
111+
SoftHSM 2 does not support creating an extractable key, but on other devices, it
112+
is recommended to use the `--extractable` flag so you can backup a wrapped
113+
version of the new keys.
114+
115+
### Getting the public key
116+
117+
To retrieve the public key, we can use the `id`, the `object`, or both at the
118+
same time:
119+
120+
```console
121+
$ step kms key 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;id=1000;object=my-p256?pin-value=password'
122+
-----BEGIN PUBLIC KEY-----
123+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEjg5Zs/fSuvfodhZQcxcu07deKsdX
124+
sQf46/JPxQ39kPIkhD+onVVxCl462yMGVTQeLDCN3fwImoOdqZ3eKhoQOA==
125+
-----END PUBLIC KEY-----
126+
$ step kms key 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;id=1001?pin-value=password'
127+
-----BEGIN PUBLIC KEY-----
128+
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEBDdy2wnC6r8n2qZTa3kefjo3CEkaWXz6
129+
rWTbDNEYrzc9LXEoA7zI1j+liSGR9wLmu91keOBnweQOIR06QV12InEKFX2l3lRx
130+
nDPvq7P3MeRo9UqzKlZT+D+dhYQjB54K
131+
-----END PUBLIC KEY-----
132+
$ step kms key 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;object=my-rsa?pin-value=password'
133+
-----BEGIN PUBLIC KEY-----
134+
MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAzAtriAh4ABfboPff15CD
135+
Skzxghaeb5SqcCwvZYdlZDRlZHlcbweY80bHjFvcU+ytSZOoMgBw+XooUnTmeVo3
136+
hOy039wlZwkfv/MEL4HP1AUVNA2iS19tmybAUTK0Myl/Ui+1iGllYA3e1ChCEZwV
137+
3B5KPfpG5KiPurhKfv5q3edIVcMKL8qj8Y9HYrzFBebQil23vkWrFylb1r/54W/O
138+
5kT2emYEGaJ8lJqzvJaIsvQpk8EqkJ7FHuAMeZyb3BK8cGjIP/GI22mL6NO3LpFc
139+
PK3Zjo7mZS5tQlFR9CULEbCuM+jiOs7FRJdyhUhdkygDxuWk1hfrCMYcG59P8pQX
140+
mPaCwE78GB3Bsi50Bp4+UI9KBcp+JARdPKocd6RvASDX1KpALpFhgqrC05+JfKA+
141+
/51QMYY1mlJn7izHmwYJr0DRn1usrh5mtJEcOtwiNKR3bo1LI00XW93DIA442IzA
142+
KqMBZrEYmuy+oL6Jy9Ys4nOVWEzFcOjmUWyjFOMMG/89AgMBAAE=
143+
-----END PUBLIC KEY-----
144+
```
145+
146+
### Signing
147+
148+
Let's first, initialize a hello world to sign:
149+
150+
```console
151+
echo "Hello World" > data.txt
152+
```
153+
154+
And then use the previous keys to sign, as before we can either use `id`,
155+
`object`, or both:
156+
157+
```console
158+
$ step kms sign --in data.txt 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;id=1000;object=my-p256?pin-value=password'
159+
MEQCIH2WfsgVRfCJs/sgIftT3i7xbpslS+9ShW/3qO9jXeA7AiBZFkcum+68zQ7pxluUE1v1yjCDyo34OEGIIyic9ItBcA==
160+
$ step kms sign --in data.txt 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;id=1001?pin-value=password'
161+
MGUCMQDtK5cADG4D3AXRLeTLvOpcDoOfYHJqt8eVVhKPg+Q5z9Hk3DSBlz/h1+YGyV11crYCMEVnQIqSdYQLB096DyLrZG28+cMjKfs+mlg+UUeVShnjHgBNGt2tHCeAZAS0VV4u4A==
162+
$ step kms sign --in data.txt 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;object=my-rsa?pin-value=password'
163+
AYbuQf6JfQMxrnaolaOyaddW4dfHU4Rg/mXXYTzSns3WUxuxJ2yXysm2Af0DrSaoqg3J4pFAmKiadDf+AZeBi0Lwwx1GpTxxOaiGDAuCuUJyUDcA/G2mTNX9+eEQkI/vOIM6Z+5T9kqP48BN3GKV5e51feSmkP6ihnQVXhW7kgPDOWt2Qq3GjJvOrn0pIjSgiYMYviMDvgcgxPuIhktYc7ZBWW63gmZ40nR3TFzTveWn7vBCGPJMOi6eOjPKRvpzo0II5froUgbTZXXFfb0r7xhMx872i2/MlRL/xhc0iy2BEXWWcoJovrbO5SdMGM0iDDkAOYceQxqW+HPf6Ghd7KA/hP6Rr0PwpfdxW7h8fF45bHrKDCXzIY4U+tHF9E16adA5axDwHVSnO8Hm5tajhB0VM7w3DYnu3npX/ko4RJw/kXe0PzhBqr+f67mhoCOuKkrsc8p8ABensZA5LeWivo78i1KMFWkh9SMRcq728GUx5/wdkc9boYr/jFNJ4WKf
164+
```
165+
166+
We can use `step` to verify one of these signatures:
167+
168+
```console
169+
$ step kms key 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;id=1000?pin-value=password' > my-p256.key
170+
$ step crypto key verify --key my-p256.key \
171+
--signature MEQCIH2WfsgVRfCJs/sgIftT3i7xbpslS+9ShW/3qO9jXeA7AiBZFkcum+68zQ7pxluUE1v1yjCDyo34OEGIIyic9ItBcA== data.txt
172+
true
173+
```
174+
175+
By default, RSA signatures use the RSA PKCS #1 scheme with SHA256, but we can
176+
use the `--alg` to select the hash function and `--pss` to use the RSA-PSS
177+
scheme:
178+
179+
```console
180+
$ step kms sign --alg SHA512 --in data.txt 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;object=my-rsa?pin-value=password'
181+
ljdurcImEwOgAOxntf4+U56w1+lf8V/wOWrRfMS3PvtSz3KSfRZZu10ZxtIG7ilZFNUnb0svTM9e3+ViYCOX+3zxu22F4DWp6E5S92TbS7AImQbMybl7rYtYloDBSagJ5T0d1h3wVg77Npi5Fkcn39ekWDeSmrEK359H0EJAoSFTVfYJ4vYUvFHbO5Zn/BgWQNtTVoSCDSnSX1cu3Nar9N2bAcGbbfjBcwQsjg+NDRgdxxNJESKYHL280gvZR0wLpYvX4jf57UUVLF4WdMEh1YGPsBGzO/M1rSMS8pYZVD1kNOwIq7buFGAVAgl8UirtIe0joUYQekVhFbGEgADTv33fWOa8B95ARGraR5mE0lg5vwC/8SeZL9M4iIS5cdn+lOs/Nj5GDySykpgsCPi+irqKRgMcC88omv8/ofqcUIJpm+IOhE47IvL3CjlItEJV55kQjC4qrdNb9/w4vk7fFtW/amdxb5juajU2AIfuKFduaHhwSJpyguzmi2Zc0r7e
182+
$ step kms sign --alg SHA256 --pss --in data.txt 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;object=my-rsa?pin-value=password'
183+
iT/enoe6zXfz4bZolrQUoYf+B5bDhn++cfkgM4x4ozqX8xd6lljPMODGB3Z43rfvUHc3A//ULzN8DjAzA7nuExneexrlAalwhqeMHSLHAmJsztgpuQ2OHdpsEfWIbkQgd4lfZWBq0Srri32SEqTnqp+s2Itf1R1By6PFcsftVMFvH3foXn3bEwWK8gHsxLRt/bnqC7ubXU+b/xjUQiu/LMl+p7RSFVjDtm3e0j07G6cbsABsr4EA0Xlw7JRrYbiP3hz4GwfRbfSBKBXrCF+edpBhGtscJnrdwL9LD/MbaDgEWrf8lO1UFmLp2B6NsjvNiQhZJ4ruQ4isHOF669z5cFcB5Hc14i4ZI81dYAI8AjG7NZvF07bH32gM2h6vVEgesrTqqcKpLW/dge3cpcEimA0Nfzpeg6ZnhnugCtI8FBDZAbo3KP9e4O2mXydP5MmZu4vWajjWc4h3sReBFXg888j2dh8gsJXCIGNUXUzULHysfdTVivnewtW2sDDnEK+L
184+
```
185+
186+
### Signing certificates with step
187+
188+
The `step-kms-plugin` is automatically used by `step certificate create` and
189+
`step certificate sign` commands if we use the `--kms` flag. With these
190+
commands, we can initialize our PKI using a key stored in a KMS.
191+
192+
Let's create first a root key:
193+
194+
```console
195+
$ step kms create 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;id=2000;object=root?pin-value=password'
196+
-----BEGIN PUBLIC KEY-----
197+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE5fbczGkGeLrLu3nD7mbdS0PmqDUT
198+
jT/f0r5U71dCAhP2T4rTfdrgnFPacX/a4jeQ1sMn4grtNFc1A4CE6vBt0A==
199+
-----END PUBLIC KEY-----
200+
```
201+
202+
And use it to create the root certificate:
203+
204+
```console
205+
$ step certificate create --profile root-ca \
206+
--kms 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep?pin-value=password' \
207+
--key 'pkcs11:id=2000'
208+
"Smallstep Root CA" root_ca.crt
209+
Your certificate has been saved in root_ca.crt.
210+
```
211+
212+
Note that currently, the configuration of the KMS and the reference to the key
213+
is passed using two different flags. This might be improved in the future.
214+
215+
Now let's create a key for the intermediate certificate:
216+
217+
```console
218+
$ step kms create 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;id=2001;object=intermediate?pin-value=password'
219+
-----BEGIN PUBLIC KEY-----
220+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEZUm9hNkXPn9KrXrG1vzhgzTwqD4+
221+
j0Wo9CQOP7GQApJLcVO9TGpzpLQHEUsUEU2zAnrGlxH7oFAlbZGXH4ueHQ==
222+
-----END PUBLIC KEY-----
223+
```
224+
225+
And create the intermediate ca:
226+
227+
```console
228+
$ step certificate create --profile intermediate-ca \
229+
--kms 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep?pin-value=password' \
230+
--ca root_ca.crt --ca-key 'pkcs11:id=2000' \
231+
--key pkcs11:id=2001 \
232+
"Smallstep IntermediateCA" intermediate_ca.crt
233+
Your certificate has been saved in intermediate_ca.crt.
234+
```
235+
236+
We can also create a CSR backed by a key in the KMS and sign it using the intermediate key:
237+
238+
```console
239+
$ step kms create 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep;id=2002;object=leaf?pin-value=password'
240+
-----BEGIN PUBLIC KEY-----
241+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE6fMBiDFPAOCrHSQszpoLMQX9JYuk
242+
JVX8J8X9t/OydimJAgBujwY8xRSgnWdU1SXXdMck+wPZZNBYvcWJWpLN9Q==
243+
-----END PUBLIC KEY-----
244+
$ step certificate create --csr \
245+
--kms 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep?pin-value=password' \
246+
--key pkcs11:id=2002 \
247+
leaf.internal leaf.csr
248+
Your certificate signing request has been saved in leaf.csr.
249+
$ step certificate sign --kms 'pkcs11:module-path=/usr/local/lib/softhsm/libsofthsm2.so;token=smallstep?pin-value=password' \
250+
leaf.csr intermediate_ca.crt pkcs11:id=2001
251+
-----BEGIN CERTIFICATE-----
252+
MIIBxTCCAWygAwIBAgIQeauacIrgtv7uPgzk+Z4puzAKBggqhkjOPQQDAjAjMSEw
253+
HwYDVQQDExhTbWFsbHN0ZXAgSW50ZXJtZWRpYXRlQ0EwHhcNMjIwNzEyMjE0MTI4
254+
WhcNMjIwNzEzMjE0MTI4WjAYMRYwFAYDVQQDEw1sZWFmLmludGVybmFsMFkwEwYH
255+
KoZIzj0CAQYIKoZIzj0DAQcDQgAE6fMBiDFPAOCrHSQszpoLMQX9JYukJVX8J8X9
256+
t/OydimJAgBujwY8xRSgnWdU1SXXdMck+wPZZNBYvcWJWpLN9aOBjDCBiTAOBgNV
257+
HQ8BAf8EBAMCB4AwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMB0GA1Ud
258+
DgQWBBRx1wnkugvbRewcTzIyBDwkeM2qVzAfBgNVHSMEGDAWgBRWvP5Nn9rbZ5Go
259+
24uF0oUqmHEghjAYBgNVHREEETAPgg1sZWFmLmludGVybmFsMAoGCCqGSM49BAMC
260+
A0cAMEQCICWSdIWIStDm5OJqBlqo1fd4lpzkcM0AOQcCwer+AgO1AiAF3sK+26LI
261+
mX6QduO/H/k8GZzcx923U54bRPCxKUaPvg==
262+
-----END CERTIFICATE-----
263+
```

cmd/sign.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,15 @@ func getSignerOptions(pub crypto.PublicKey, alg string, pss bool) (crypto.Signer
197197
return nil, fmt.Errorf("unsupported hashing algorithm %q", alg)
198198
}
199199
if pss {
200+
// rsa.PSSSaltLengthAuto is not supported by crypto11. The salt
201+
// length here is the same used by Go when PSSSaltLengthAuto is
202+
// used.
203+
//
204+
// This can be fixed if https://github.com/ThalesIgnite/crypto11/pull/96
205+
// gets merged.
200206
return &rsa.PSSOptions{
201207
Hash: h,
202-
SaltLength: rsa.PSSSaltLengthAuto,
208+
SaltLength: (k.N.BitLen()-1+7)/8 - 2 - h.Size(),
203209
}, nil
204210
}
205211
return h, nil

0 commit comments

Comments
 (0)