GnuTLS 3.1.0 (when compiled with libtrousers) adds support for keys stored in the TPM chip. This support is transparent, and such keys can be used similarly to keys stored in files. What is required is that TPM keys are specified using a URI of the following forms.
tpmkey:uuid=c0208efa-8fe3-431a-9e0b-b8923bb0cdc4;storage=system tpmkey:file=/path/to/the/tpmkey
The first URI contains a UUID which is an identifier of the key, and the storage area of the chip (TPM allows for system and user keys). The latter URI is used for TPM keys that are stored outside the TPM storage area, i.e., in an (encrypted by the TPM) file.
Let's see how we can generate a TPM key, and use it for TLS authentication. We'll need to generate a key and the corresponding certificate. The following command generates a key which will be stored in the TPM's user section.
$ tpmtool --generate-rsa --bits 2048 --register --user
The output of the command is the key ID.
tpmkey:uuid=58ad734b-bde6-45c7-89d8-756a55ad1891;storage=user
So now that we have the ID of the key, let's extract the public key from it.
$ tpmtool --pubkey "tpmkey:uuid=58ad734b-bde6-45c7-89d8-756a55ad1891;storage=user" --outfile=pubkey.pem
And given the public key we can easily generate a certificate using the following command.
$ certtool --generate-certificate --outfile cert.pem --load-privkey "tpmkey:uuid=58ad734b-bde6-45c7-89d8-756a55ad1891;storage=user" --load-pubkey pubkey.pem --load-ca-certificate ca-cert.pem --load-ca-privkey ca-key.pem
The generated certificate can now be used with any program using the gnutls library, such as gnutls-cli to connect to a server. For example:
$ gnutls-cli --x509keyfile "tpmkey:uuid=58ad734b-bde6-45c7-89d8-756a55ad1891;storage=user" --x509certfile cert.pem -p 443 my_host.name
An easy to notice issue with TPM keys is that they are not mnemonic. There is only an UUID identifying the key, but no labels making the distinction of multiple keys a troublesome task. Nevertheless, TPM keys provide a cheap way to protect keys used in your system.
Hi
ReplyDeleteI have a little problem with your guide.
If i insert the following line:
certtool --generate-certificate --outfile cert.pem --load-privkey "tpmkey:uuid=62785ea7-99c2-4685-8a31-87c2314c708d;storage=user" --load-pubkey pubkey.pem --load-ca-certificate ca-cert.pem --load-ca-privkey ca-key.pem
I get this output:
Generating a signed certificate...
certtool: reading --load-ca-privkey: ca-key.pem: No such file or directory
where was my mistake?
thx for your help
Hi,
ReplyDeleteThanks for the post. I'm curious about if the keys generated using tpmtool are storage keys, signing keys or binding keys? Is it possible to use tpmtool to use the private part of the key decrypt a message encrypted by a third party with the public key?
Thanks!
Xiao
By default signing keys are being generated. About whether you can do key operations with tpmtool, the answer is no.
DeleteBut how does the Master Key come in? If we add another set of pins into the equation then a lot of possibilities open up.автоключар
ReplyDelete