Closed ximon18 closed 2 years ago
An AWS EC2 instance with:
$ $ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.6 LTS"
$ uname -r
5.4.0-1083-aws
The AWS CloudHSM was setup as above.
Setup the VM to install proposed
DEB packages from https://packages.nlnetlabs.nl/ per https://krill.docs.nlnetlabs.nl/en/stable/install-and-run.html#installing-specific-versions.
Install the keyls
helper tool and prepare our krill.conf
:
[1]> cargo install --git https://github.com/ximon18/keyls --branch main --locked
[1]> keyls 'pkcs11:2305843009213693953:krill:password@/opt/cloudhsm/lib/libcloudhsm_pkcs11.so'
Using PKCS#11 slot id 2305843009213693953 (0x2000000000000001)
No keys found
[1]> cat /tmp/krill.conf
admin_token = "abc"
data_dir = "/tmp/krill"
service_uri = "https://localhost:3000/"
log_level = "trace"
log_type = "stderr"
[[signers]]
type = "PKCS#11"
name = "AWS Cloud HSM"
lib_path = "/opt/cloudhsm/lib/libcloudhsm_pkcs11.so"
slot = 0x2000000000000001
user_pin = "krill:password"
Also prepare two additional terminals for communicating with the local Krill and the external testbed:
In another terminal [2]:
[2]> $ export KRILL_CLI_TOKEN=abc
In yet another terminal [3] prepare to manage the testbed side of the setup:
[3]> export KRILL_CLI_SERVER=https://testbed.krill.cloud/
[3]> export KRILL_CLI_TOKEN=********
Install and run Krill:
[1]> sudo apt install -y krill
[1]> krill --version
Krill 0.10.0-rc2
[1]> krill -c /tmp/krill.conf
In terminal [2] add a CA to Krill:
[2]> krillc add --ca some_ca
Using TWO DIFFERENT TERMINALS register Krill with the NLnet Labs public testbed as a publisher:
[2]> krillc repo request --ca some_ca > /tmp/req.xml
[3]> krillc pubserver publishers add --request /tmp/req.xml >/tmp/res.xml
[2]> krillc repo configure --ca some_ca --response /tmp/res.xml
Using TWO DIFFERENT TERMINALS register Krill as a child CA under the testbed:
[2]> krillc parents request --ca some_ca > /tmp/req2.xml
[3]> krillc children add --ca testbed --asn 18 --ipv4 10.0.0.0/24 --child some_ca --request /tmp/req2.xml >/tmp/res2.xml
[2]> krillc parents add --ca some_ca --response /tmp/res2.xml --parent testbed
NOTE: At the [3]> krillc children add
step above I hit issue https://github.com/NLnetLabs/krill/issues/868, a problem with the testbed running v0.10.0-rc2. To work around this I invoked the HTTP API directly like so:
[3]> wget -qO- --header="Authorization: Bearer ${KRILL_CLI_TOKEN}" https://testbed.krill.cloud/api/v1/cas/testbed/children/some_ca/parent_response.xml >/tmp/res2.xml
Finally, create a ROA:
[2]> krillc roas update --ca some_ca --add "10.0.0.1/32 => 18"
And look at which keys we have now:
[2]> keyls 'pkcs11:2305843009213693953:krill:password@/opt/cloudhsm/lib/libcloudhsm_pkcs11.so'
Using PKCS#11 slot id 2305843009213693953 (0x2000000000000001)
Found 6 keys
+------------------------------------------+-------------+-------+-----------+--------+
| ID | Type | Name | Algorithm | Length |
+------------------------------------------+-------------+-------+-----------+--------+
| 06933ABADC3138D24291CEB37E439F94FF3AA898 | Private Key | Krill | RSA | 2048 |
| 06933ABADC3138D24291CEB37E439F94FF3AA898 | Public Key | Krill | RSA | 2048 |
| 23DB2ABCF5C275DCB715A02AD989398EDE41F668 | Private Key | Krill | RSA | 2048 |
| 23DB2ABCF5C275DCB715A02AD989398EDE41F668 | Public Key | Krill | RSA | 2048 |
| BB5283F1FE648A5B5120D6C25C6F71640600C0A9 | Private Key | Krill | RSA | 2048 |
| BB5283F1FE648A5B5120D6C25C6F71640600C0A9 | Public Key | Krill | RSA | 2048 |
+------------------------------------------+-------------+-------+-----------+--------+
:champagne: :+1:
Finally, cleanup the testbed:
[3]> krillc children remove --ca testbed --child some_ca
[3]> krillc pubserver publishers remove -p some_ca
And here are the signer store files on disk:
[2]> cat /tmp/krill/signers/02507cd0-75bf-42ec-a43f-9e9ac9471447/snapshot.json
{
"id": "02507cd0-75bf-42ec-a43f-9e9ac9471447",
"version": 3,
"signer_name": "AWS Cloud HSM",
"signer_info": "PKCS#11 Signer [token: hsm1 (model: NITROX-III CNN35, vendor: Marvell Semiconductors, Inc.), slot: 2305843009213693953, server: CloudHSM (Cryptoki v5.5), library: /opt/cloudhsm/lib/libcloudhsm_pkcs11.so]",
"signer_identity": {
"public_key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAh19AzWAqol5uxdY+1JnIMTjbRu7bmGJTGS14qPMHm23PBZGuEDPfxLQfjKrsRVv5eYgHf/KVkdvSInojWlXz/Z9JkAJaaj1DdSTq522hYGSBaCbllp4Y52i4vUqBbbsdlPtJgmvfbEZ1O/RpPdngv9ptC3omAam0uuUvSe7lh4+gJuEhPcjRhgGjneUFxBAp8GjHqjH8/oiIcrhkqb4GHSasvnLynLwQioNSDbLHZPy+5JpMk74/tSNwDu8In/S8hzs45e9ltEpvbxr7d85I1GLftiEFesZ0cM5xe0fcZD8QAOl/miWxsyNkFTnAn+4fNkIUXrwzXUWxDqu2e94lRwIDAQAB",
"private_key_internal_id": "bb5283f1fe648a5b5120d6c25c6f71640600c0a9"
},
"keys": {
"29B6D0589D702A8CEF67D72F90A5EB4673D56FB7": "06933abadc3138d24291ceb37e439f94ff3aa898",
"65AB52E8A1996265EE351F88D7AB1D7A0F3A50D1": "23db2abcf5c275dcb715a02ad989398ede41f668"
}
}
[2]> cat /tmp/krill/signers/512dabb5-085d-4ba7-a9f5-5e54a0c8842e/snapshot.json
{
"id": "1d10c562-3bb7-4741-88bd-1a91c850b862",
"version": 1,
"signer_name": "OpenSSL one-off signer",
"signer_info": "OpenSSL Soft Signer [version: OpenSSL 1.1.1 11 Sep 2018, keys dir: /tmp/krill/keys]",
"signer_identity": {
"public_key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsqKaPai9VFstv5A02nJxSQ5c6H3uvKrPBoTuVe2tm7Df5ccEyzvzP1YldDkL9QiEPZktWdGDqvzvQw8T4iWSqLkQUE1hmhoCPnnrXMcggASw+NmZ9Q0KLTf1G3V7Ryug9LojNKFOzQ8lYlrKdzRHAkjeFydcz+WBBUORPb6/c+9qEhYczFMuPQ8QfHyol27se6ppTr02uN3VXNtwyxwnDLRnk+v3jr8q+dTWT3lqaBQSPD9UfZM3AXj+mOY26Fz9ROd3wMykT9f8c+3vTpAc7+H3cKjyVBMMQURhMzbjA9zJU/F8qvKlH3/eTLZyOMPwyC/B7s4BMh1IHepJQDyh/QIDAQAB",
"private_key_internal_id": "B9114780849FBE24C8040E15C0B4848446C17B8A"
},
"keys": {}
}
HSM support was delivered with the Krill v0.10.0 release.
Tested using Krill commit 5b444bf (the current head of the
hsm
branch) and AWS Cloud HSM on Ubuntu 21.10.Prepare to use AWS Cloud HSM:
Uninitialized
state.At a terminal create a certificate using the CSR:
Next we SSH to the EC2 instance in the VPC and install the CloudHSM software and Krill.
Now disable CloudHSM replication otherwise the
C_SignInit
PKCS#11 function will fail with errorCKR_FUNCTION_FAILED
:Now install the AWS PKCS#11 library:
Let's use the
keyls
tool to verify that we can connect to the HSM and that it is empty:The AWS PKCS#11 library by default outputs a lot of logging which I've stripped from the output above.
A special note about 2305843009213693953: this is the integer equivalent of the 0x2000000000000001 slot id, as the keyls tool doesn't currently support hex slot IDs. The 0x2000000000000001 slot ID was found using the
pkcs11-tool
from theopensc
package.Inspect the token using
pkcs11-tool
:Krill was installed like so:
The Krill config file looked like this:
Run Krill:
Krill configures itself to use the PKCS#11 signer for and a fallback OpenSSL signer:
In another terminal use
krillc
to create a CA:On creation of a CA, Krill attempts to initialize the signers and contact the PKCS#11 token:
Prepare another terminal for issuing commands to a testbed instance of Krill, in this case the NLnet Labs public testbed:
Using TWO DIFFERENT TERMINALS register Krill with the NLnet Labs public testbed as a publisher:
Using TWO DIFFERENT TERMINALS register Krill as a child CA under the testbed:
Finally, create a ROA:
There will now be three key pairs stored in SoftHSM:
There will now be two key identifiers mapped for the PKCS#11 signer and none to the OpenSSL signer:
And the OpenSSL keys directory contains only the identity key that Krill created for it:
Finally, cleanup the testbed: