]> git.proxmox.com Git - swtpm.git/log
swtpm.git
6 years agodebian: add gnutls-dev as build dependency
Stefan Berger [Wed, 7 Feb 2018 02:03:42 +0000 (21:03 -0500)]
debian: add gnutls-dev as build dependency

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: print the NVRAM indices when logging
Stefan Berger [Tue, 6 Feb 2018 23:03:55 +0000 (18:03 -0500)]
swtpm_setup: print the NVRAM indices when logging

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: adjust flags for TPM 2 NVRAM locations
Stefan Berger [Thu, 1 Feb 2018 17:46:11 +0000 (12:46 -0500)]
swtpm_setup: adjust flags for TPM 2 NVRAM locations

Adjust the flags for the TPM 2 NVRAM locations to adhere to the
specification:

TCG PC Client Platform: TPM Profile (PTP) Specification
Family "2.0"; Level 00; Rev 01.03 v22; May 22, 2017

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: use variable for determining the NVRAM index to write into
Stefan Berger [Thu, 4 Jan 2018 13:36:05 +0000 (08:36 -0500)]
swtpm_setup: use variable for determining the NVRAM index to write into

To prepare for writing data into different locations for ECC keys,
assign a variable the location of the NVRAM to write RSA related data
into.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agosamples: add support for signing key password
Stefan Berger [Mon, 1 Jan 2018 21:59:03 +0000 (16:59 -0500)]
samples: add support for signing key password

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: write EK non-standard template into NVRAM location
Stefan Berger [Fri, 29 Dec 2017 18:39:15 +0000 (13:39 -0500)]
swtpm_setup: write EK non-standard template into NVRAM location

We write the EK template into the NVRAM location when it is non-standard.
It's non-standard once the EK can be used for signing.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: refactor code to create template separately
Stefan Berger [Fri, 29 Dec 2017 18:15:35 +0000 (13:15 -0500)]
swtpm_setup: refactor code to create template separately

Refactor the code creating the RSA and ECC key to create the
template separately.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Add a test case for checking certs created by swtpm_localca
Stefan Berger [Fri, 22 Dec 2017 02:08:55 +0000 (21:08 -0500)]
tests: Add a test case for checking certs created by swtpm_localca

Test the certs created by swtpm_localca by verifying the certificate
chain and checking their key usage.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: Add --decryption for enabling key encipherment
Stefan Berger [Thu, 21 Dec 2017 00:06:40 +0000 (01:06 +0100)]
swtpm_setup: Add --decryption for enabling key encipherment

Add the --decryption option to enable key encipherment separately
from enabling signing for the EK. The key encipherment is not set
but needs to be set if --allow-signing is used and key encipherment
is also requested.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agosamples: add support for signing and key encipherment options
Stefan Berger [Wed, 20 Dec 2017 22:11:42 +0000 (23:11 +0100)]
samples: add support for signing and key encipherment options

To allow the creation of EKs with signing and/or key encipherment
capabilities, add the --allow-signing and --decryption options
to swtpm-localca program.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Add option --decryption to use for key encipherment
Stefan Berger [Wed, 20 Dec 2017 22:04:05 +0000 (23:04 +0100)]
swtpm_cert: Add option --decryption to use for key encipherment

In case of a TPM 2 we allow the creation of a signing key by passing
--allow signing. To also enable key encipherment, we add the --decryption
option to allow key encipherment and signing at the same time.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: Also create the primary storage keys as ECC keys
Stefan Berger [Tue, 24 Oct 2017 15:56:30 +0000 (11:56 -0400)]
swtpm_setup: Also create the primary storage keys as ECC keys

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: Prepare code for ECC primary storage key
Stefan Berger [Tue, 24 Oct 2017 11:49:26 +0000 (07:49 -0400)]
swtpm_setup: Prepare code for ECC primary storage key

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: Create EK and SPK with different handles
Stefan Berger [Mon, 23 Oct 2017 12:55:48 +0000 (08:55 -0400)]
swtpm_setup: Create EK and SPK with different handles

Use the standard EK and SRK handles per IWG spec
"TCG TPM v2.0 Provisioning Guidance"; Version 1.0, Rev 1.0, March 15 2017

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: create a storage primary key
Stefan Berger [Mon, 23 Oct 2017 01:02:01 +0000 (21:02 -0400)]
swtpm_setup: create a storage primary key

Create a storage primary key and print the handle of the created key.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: rename tpm2_createprimary to tpm2_create_ek
Stefan Berger [Sun, 22 Oct 2017 19:03:13 +0000 (15:03 -0400)]
swtpm_setup: rename tpm2_createprimary to tpm2_create_ek

Rename tpm_createprimary to tpm2_create_ek and print handle of
created EK.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild: Build Debian 0.1.0-1-dev2
Stefan Berger [Mon, 13 Nov 2017 20:21:15 +0000 (15:21 -0500)]
build: Build Debian 0.1.0-1-dev2

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: rename key creation function to have _ek in the name
Stefan Berger [Sun, 22 Oct 2017 01:09:31 +0000 (21:09 -0400)]
swtpm_setup: rename key creation function to have _ek in the name

Rename all TPM 2 key creation functions to have _ek in the name.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: create tpm2_createprimary_rsa_params for common code
Stefan Berger [Sun, 22 Oct 2017 01:05:37 +0000 (21:05 -0400)]
swtpm_setup: create tpm2_createprimary_rsa_params for common code

Create the tpm2_createprimary_rsa_params function that has common code
for creating a primary RSA key with parameters.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: Pass non evict key handle when creating key
Stefan Berger [Sat, 21 Oct 2017 12:33:22 +0000 (08:33 -0400)]
swtpm_setup: Pass non evict key handle when creating key

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: Don't require root privileges to run it for a TPM 2
Stefan Berger [Tue, 11 Jul 2017 16:49:20 +0000 (12:49 -0400)]
swtpm_setup: Don't require root privileges to run it for a TPM 2

Don't require root privileges to run swtpm_setup with a TPM 2 target.
For TPM 1.2 we need the high privilges due to TrouSerS wanting to be
started as root (or 'tss'), but for TPM 2 we do not use any tools
to manufacture the initial state that would require high privileges.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Add test cases for encrypted state
Stefan Berger [Fri, 30 Jun 2017 15:40:39 +0000 (11:40 -0400)]
tests: Add test cases for encrypted state

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Add test_tpm2_migration_key test case
Stefan Berger [Thu, 15 Jun 2017 13:53:48 +0000 (09:53 -0400)]
tests: Add test_tpm2_migration_key test case

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Add TPM 2 test case tpm_tpm2_resume_volatile
Stefan Berger [Thu, 15 Jun 2017 00:52:32 +0000 (20:52 -0400)]
tests: Add TPM 2 test case tpm_tpm2_resume_volatile

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Add test case for testing TPM 2 volatile state
Stefan Berger [Wed, 14 Jun 2017 18:17:28 +0000 (14:17 -0400)]
tests: Add test case for testing TPM 2 volatile state

Add a test case that tests the TPM 2 volatile state. This test
requires the latest TPM2 version of libtpms that also writes the
TPM Established bit into the volatile state.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Check TPM2 state using TPM2 utilities
Stefan Berger [Wed, 22 Mar 2017 13:36:21 +0000 (09:36 -0400)]
tests: Check TPM2 state using TPM2 utilities

Check the TPM2 state using the TPM2 utilities, if available.

Create persistent state and check it, then shut down the TPM 2 and
restart it, and check the persistent state again.

Use previously created state and have the TPM 2 start with it
and check the persistent state. The persistent state must be
readable on little and big endian machines.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Add test cases for state suspension and resumption
Stefan Berger [Thu, 16 Mar 2017 19:52:40 +0000 (15:52 -0400)]
tests: Add test cases for state suspension and resumption

libtpms preview branch tpm2-preview.rev142 enables volatile state
marshalling and unmarshalling which in turn enables the suspending
and resumption of the TPM state. This patch enables the capabilty
bits and adds test cases for testing the TPM state suspending and
resumption.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Fix --tpm2 parameter handling for socket version of TPM
Stefan Berger [Fri, 17 Mar 2017 15:47:49 +0000 (11:47 -0400)]
swtpm: Fix --tpm2 parameter handling for socket version of TPM

Fix the --tpm2 parameter handlng for the socket version of the TPM. It did
not work so far.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: Implement support for ECC keys
Stefan Berger [Wed, 21 Dec 2016 22:06:40 +0000 (17:06 -0500)]
swtpm_setup: Implement support for ECC keys

Implement support in swtpm_setup.sh so that the TPM's primary key
can be an ECC key.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Support for Elliptic Curve keys
Stefan Berger [Wed, 21 Dec 2016 22:06:17 +0000 (17:06 -0500)]
swtpm_cert: Support for Elliptic Curve keys

Provide support for creating certificates for TPM2 ECC type of keys.

Extend the test cases and the man pages.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoSupport TPM 2 in swtpm_setup and swtpm_setup.sh
Stefan Berger [Wed, 21 Dec 2016 22:05:56 +0000 (17:05 -0500)]
Support TPM 2 in swtpm_setup and swtpm_setup.sh

Support TPM 2 in swtpm_setup and swtpm_setup.sh.
Implement support for all command line options except for:
 o --take-ownership and anything related to ownership passwords
 o --lock-nvram
 o --display

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Add support for TPM2
Stefan Berger [Wed, 21 Dec 2016 22:05:40 +0000 (17:05 -0500)]
swtpm_cert: Add support for TPM2

TPM2 allows the primary key to also be a signing key, so in case
--tpm2 is provided, --allow-signing can be provided as well in
case the primary can also be used for signing operations.

We use SHA256 for the signing algorithm when TPM 2 is being used.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoExtend swtpm_bios with --tpm2 to support a TPM 2
Stefan Berger [Wed, 21 Dec 2016 22:03:19 +0000 (17:03 -0500)]
Extend swtpm_bios with --tpm2 to support a TPM 2

Extend the swtpm_bios tool with a --tpm2 command line parameter
to support TPM 2 initialization.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Add test cases for TPM2
Stefan Berger [Wed, 21 Dec 2016 22:01:19 +0000 (17:01 -0500)]
tests: Add test cases for TPM2

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Call API call for resetting the TPM Established flag
Stefan Berger [Wed, 21 Dec 2016 22:01:07 +0000 (17:01 -0500)]
swtpm: Call API call for resetting the TPM Established flag

Call the libtpms API for resetting the TPM Established flag rather
than sending a TPM command, which only works for TPM1.2.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Implement support for TPM2 command cancellation
Stefan Berger [Wed, 21 Dec 2016 22:01:06 +0000 (17:01 -0500)]
swtpm: Implement support for TPM2 command cancellation

Extend the TPM2 support with command cancellation support.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Provide support for TPM2 using --tpm2
Stefan Berger [Wed, 21 Dec 2016 22:01:06 +0000 (17:01 -0500)]
swtpm: Provide support for TPM2 using --tpm2

Implement support for TPM2. Some of the capabilities are not supported yet in
this patch.

Extend the man pages with description for --tpm2.

Missing: configure should probe for needed API calls in libtpms

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Prepend a 'special' ASN.1 byte sequence to the SAN data
Stefan Berger [Tue, 7 Aug 2018 16:07:38 +0000 (12:07 -0400)]
swtpm_cert: Prepend a 'special' ASN.1 byte sequence to the SAN data

The subject alternative name need to have a special sequence of
bytes prepended to them for certtool to accept the data. Also TCG's
sample certificate does show the sequence. The byte sequence is of
the form: 0x30 <subsequent length> 0xa4 <subsequent length> <data>

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Do set authority key id explicitly
Stefan Berger [Tue, 7 Aug 2018 14:26:31 +0000 (10:26 -0400)]
swtpm_cert: Do set authority key id explicitly

The previous patch's reversal was partially wrong. The authority
key id needs to be set explicitly from the key id of the signing
key of the issuing CA.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Remove copying of authority key id
Stefan Berger [Tue, 7 Aug 2018 13:24:35 +0000 (09:24 -0400)]
swtpm_cert: Remove copying of authority key id

Remove the copying of the authority key id from the given issuer
cert to the created cert since this copies the wrong key id and
besides that it will be set automatically when the certificate is
created.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Use file lock to prevent concurrent access to state files
Stefan Berger [Thu, 5 Jul 2018 18:17:53 +0000 (14:17 -0400)]
swtpm: Use file lock to prevent concurrent access to state files

Create a .lock file in the directory with the TPM state and get
a lock on this file and hold on to the lock until swtpm ends.
This precludes other swtpm instances to step on the same state.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Use wait_process_gone rather than kill -0
Stefan Berger [Mon, 2 Jul 2018 12:10:26 +0000 (08:10 -0400)]
tests: Use wait_process_gone rather than kill -0

Have the test cases wait for the process to be gone after 1s using
wait_process_gone rather than trying use kill -0 once after 0.5s.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Encrypt the data with a random IV every time
Stefan Berger [Sat, 30 Jun 2018 00:55:47 +0000 (20:55 -0400)]
swtpm: Encrypt the data with a random IV every time

Whenever we encrypt the data we generate a new random IV and append a
tlv block with the IV to the byte stream. We mark the IV with different
tags depending on whether they are for the migration data or the (TPM)
data directly. All IVs are part of the HMAC and are added to it after
the data blob.

Adjust test cases that now return larger sizes of data. A constant
checksum over the data cannot be expected anymore, thus we have to remove
the verification of the checksum over the returned state (IV changes
every time).

The size of the blobs grow by 22 bytes, 6 for the tlv header, 16 bytes
for the IV (128 bit AES key).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Get the IV from a tag-length-value block in the data stream
Stefan Berger [Fri, 29 Jun 2018 20:57:24 +0000 (16:57 -0400)]
swtpm: Get the IV from a tag-length-value block in the data stream

Get the IV from a tlv block in the data stream. If none is found, which
is the case when reading older state, we get a NULL pointer for the IV
and call the functions with the NULL pointer, which provides backwards
compatibility.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Add IV as parameter to AES CBC encryption/decryption function
Stefan Berger [Fri, 29 Jun 2018 20:37:17 +0000 (16:37 -0400)]
swtpm: Add IV as parameter to AES CBC encryption/decryption function

Enable a caller to pass an IV into the AES CBC encryption/decryption
function. If the caller passes NULL, we use the IV with all zeroes.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Refactor HMAC calculation so we can later pass the IV as well
Stefan Berger [Sat, 30 Jun 2018 04:45:40 +0000 (00:45 -0400)]
swtpm: Refactor HMAC calculation so we can later pass the IV as well

Refactor the functions calculating the HMAC so that we can later on
pass the IV for the AES CBC encryption as well.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: get rid of TPM_Malloc/TPM_Free/TPM_Realloc
Stefan Berger [Fri, 15 Jun 2018 20:26:19 +0000 (16:26 -0400)]
swtpm: get rid of TPM_Malloc/TPM_Free/TPM_Realloc

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Use tag-length-value blocks to store data in v2 format
Stefan Berger [Fri, 13 Apr 2018 22:14:40 +0000 (18:14 -0400)]
swtpm: Use tag-length-value blocks to store data in v2 format

Prepend tag-length-value (tlv) headers in front of all data being stored in
the byte stream following the header. This lets us uniquely identify plain
data (= TPM state), encrypted data (= encrytped TPM state), migration data
(which is wrapped plain or encrytped TPM state), and an HMAC block to
validate the plain data.

We keep support for version 1 for reading the data but convert them to
version 2 when writing them out. This way we loose backwards compatibility
(downgrading of swtpm is not possible), but it allows us to extend the state
in the future by adding addition blocks with tlv headers.

Version 1 of the encryption was prepending the hash on the plaintext data
then encrypting all of it. This method is not so good. In version 2 we now
use Encrypt-then-MAC (EtM) where we encrypt the data and then calculate an
HMAC on the encrypted data.

Files written by the swtpm didn't have a header before. Now they also get a
header. This means that the state written into files and the state retrieved
using the API (swtpm_ioctl --save) have the same format, but still differ
in so far as the API wraps the data in a tlv header for migration, which the
files written out as state would never get.

Adapt a couple of test cases show file sizes and hashes have changed now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Implement functions for supporting tag-length-value
Stefan Berger [Thu, 14 Jun 2018 21:13:11 +0000 (17:13 -0400)]
swtpm: Implement functions for supporting tag-length-value

Implement functions for supporting tag-length-value headers
in the byte stream we store the TPM's data into.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild: Remove FreeBL support since libtpms does not support it
Stefan Berger [Fri, 15 Jun 2018 12:43:03 +0000 (08:43 -0400)]
build: Remove FreeBL support since libtpms does not support it

Remove FreeBL support for swtpm since there will not be support
for FreeBL with TPM 2 in libtpms.

Since a lot of documentation shows --with-openssl, we leave that for
now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Skip CUSE tests if not compiled with CUSE interface
Stefan Berger [Mon, 11 Jun 2018 14:35:10 +0000 (10:35 -0400)]
tests: Skip CUSE tests if not compiled with CUSE interface

Check for a '#define WITH_CUSE 1' line in config.h to determine whether
the swtpm was compiled with the CUSE interface and skip the tests with
the CUSE interface if no such line can be found.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotest: Add PKG_CONFIG_PATH in front of configure for i386
Stefan Berger [Mon, 4 Jun 2018 19:41:54 +0000 (15:41 -0400)]
test: Add PKG_CONFIG_PATH in front of configure for i386

More recent glib-2.0 needs a specific different include files for
32 and 64 bit x86 architectures. We get this through pkg-config but
need to set its search path accordingly.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Poll for 1 second after PID file was found to be gone
Stefan Berger [Mon, 4 Jun 2018 19:45:56 +0000 (15:45 -0400)]
tests: Poll for 1 second after PID file was found to be gone

Poll for process to be gone for 1 seconds after a shutdown was requested
and it was found that the PID file had been removed.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_ioctl: add padding bytes for 32 bit architectures
Stefan Berger [Mon, 4 Jun 2018 19:40:31 +0000 (15:40 -0400)]
swtpm_ioctl: add padding bytes for 32 bit architectures

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild-sys: Remove '/' after $(DESTDIR)
Stefan Berger [Tue, 29 May 2018 16:15:22 +0000 (12:15 -0400)]
build-sys: Remove '/' after $(DESTDIR)

Remove the unnecessary '/' after $(DESTDIR).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoDo not call close() with a negative value
Stefan Berger [Mon, 14 May 2018 20:37:56 +0000 (16:37 -0400)]
Do not call close() with a negative value

Check the value of *pidfilefd before calling close(*pidfilefd).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoUse memcpy rather than strncpy and leave note in code
Stefan Berger [Mon, 14 May 2018 20:46:07 +0000 (16:46 -0400)]
Use memcpy rather than strncpy and leave note in code

Coverity found that the usage of strncpy may leave an unterminated
string. In this case it is ok, if the string is unterminated since
it would only be the part of a response and the client would have
to collect all the parts as indicated by the total length of the
string. So we use memcpy instead and leave a note in the code. So
far the strings would not nearly be 3k to get close to the maximum.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoUse TPMLIB_SetState to set state blobs
Stefan Berger [Mon, 14 May 2018 13:03:09 +0000 (09:03 -0400)]
Use TPMLIB_SetState to set state blobs

Rather than writing to files directly and having to validate the state in
those files using TPMLIB_ValidatetState(), we now use the new
TPMLIB_SetState() call to set the TPM's state blobs. The advantage of this
call is that it doesn't overwrite state files and ends up leaving state in
files that the TPM cannot use. Instead, it validates the state immediately
when the blob is set and returns an error in case the state cannot be
accepted.

We need to adapt one test case that now gets a failure earlier than before.
Before the TPM_INIT failed, now setting the encrypted blob fails because it
cannot be decrypted and thus cannot be accepted by the TPM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: do not set the subject in the certificate
Stefan Berger [Tue, 8 May 2018 15:56:29 +0000 (11:56 -0400)]
swtpm_cert: do not set the subject in the certificate

For TPM 1.2 the spec says that we must not set the subject, so we
do not set it but keep it around for TPM 2 certificates.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Usa sha-1WithRSAEncryption for TPM 1.2 signature algorithm
Stefan Berger [Mon, 7 May 2018 16:02:46 +0000 (12:02 -0400)]
swtpm_cert: Usa sha-1WithRSAEncryption for TPM 1.2 signature algorithm

Use sha1 rather than sha256 for the TPM 1.2 signature algorithm.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Build platform and TPM info for platform certificate
Stefan Berger [Mon, 7 May 2018 19:23:46 +0000 (15:23 -0400)]
swtpm_cert: Build platform and TPM info for platform certificate

Build the platform and TPM information into the platform certificate.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Set SAN's ASN.1 using lower level function
Stefan Berger [Mon, 7 May 2018 15:54:00 +0000 (11:54 -0400)]
swtpm_cert: Set SAN's ASN.1 using lower level function

To make the ASN.1 look like the one from the spec. we have to
use a lower-level GNUTLS API function to set it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: put ASN.1 creation code into own functions
Stefan Berger [Mon, 7 May 2018 15:40:30 +0000 (11:40 -0400)]
swtpm_cert: put ASN.1 creation code into own functions

Put the code that creates the ASN.1 for the platform and
TPM manufacturer info into their own functions.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: fix a copy and paste error related to TPM attributes
Stefan Berger [Sat, 5 May 2018 05:22:49 +0000 (01:22 -0400)]
swtpm_cert: fix a copy and paste error related to TPM attributes

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agosamples: remove the TPM attribute parameters from the options file
Stefan Berger [Sat, 5 May 2018 05:02:28 +0000 (01:02 -0400)]
samples: remove the TPM attribute parameters from the options file

Since swtpm_setup now uses the swtpm_ioctl tool to get some of the
TPM attributes directly from the TPM, we don't need to pass these
options via the options file anymore.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: get tpm manufacturer, fw version, etc. via swtpm_ioctl
Stefan Berger [Sat, 5 May 2018 05:00:32 +0000 (01:00 -0400)]
swtpm_setup: get tpm manufacturer, fw version, etc. via swtpm_ioctl

Use the swtpm_ioctl tool also to get TPM manufacturer, firmware
version and TPM model and pass it to the external tool creating
the certificate.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: simplify two's completement implementation
Stefan Berger [Fri, 4 May 2018 20:53:19 +0000 (16:53 -0400)]
swtpm_cert: simplify two's completement implementation

Simplify the two's complement implementation by converting the number
into a big endian and writing it out into a byte array that is prefixed
with a 0-byte. This covers all unsigned ints while the previous imple-
mentation would have been wrong once the number exceeded 255.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: wait for 0.5 seconds before swtpm must be gone
Stefan Berger [Fri, 4 May 2018 17:41:41 +0000 (13:41 -0400)]
tests: wait for 0.5 seconds before swtpm must be gone

To avoid test failures in test_ctrchannel2 due to the swtpm process
still running after it has removed the PID file, give it 0.5 seconds
to actually terminate.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: calculate two's complement of numbers for ASN.1
Stefan Berger [Fri, 4 May 2018 17:29:52 +0000 (13:29 -0400)]
swtpm_cert: calculate two's complement of numbers for ASN.1

Calculate the two's completement of the spec_level and spec_revision
numbers so that ASN.1 properly stores them as unsigned integers.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Use certificate specific OIDs in Extended Key Usage field
Stefan Berger [Fri, 4 May 2018 15:23:46 +0000 (11:23 -0400)]
swtpm_cert: Use certificate specific OIDs in Extended Key Usage field

Create ASN.1 for the Extended Key Usage field for the EK certificate
that has the oid 2.23.133.8.1 and for the platform certificate the
oid 2.23.133.8.2. Both are registered OIDs:

http://oid-info.com/get/2.23.133.8.1
http://oid-info.com/get/2.23.133.8.2

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoSELinux: yet more rules needed for recent Fedora
Stefan Berger [Fri, 27 Apr 2018 16:55:04 +0000 (12:55 -0400)]
SELinux: yet more rules needed for recent Fedora

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoSELinux: add yet more rules for svirt for libvirt support
Stefan Berger [Fri, 27 Apr 2018 16:15:10 +0000 (12:15 -0400)]
SELinux: add yet more rules for svirt for libvirt support

Non-privileged mode needs another rule and on Fedora 27 we need
a swtpm_exec_t related rule we did not need on Fedora 23.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: fix missing space after --vmid parameter
Stefan Berger [Mon, 23 Apr 2018 17:55:03 +0000 (13:55 -0400)]
swtpm_setup: fix missing space after --vmid parameter

The extern cert program was called with --vmid <foo>--tpm-spec-family ...
and failed due to a missing whitespace. This patch fixes it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agosample: propagate and log error if swtpm_cert is missing
Stefan Berger [Wed, 7 Feb 2018 01:57:28 +0000 (20:57 -0500)]
sample: propagate and log error if swtpm_cert is missing

If the swtpm_cert was missing, nothing was reported in the error log. Change
this and report it in the error log rather than writing the error in the
certificate file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: set PATH so swtpm_cert can be found
Stefan Berger [Mon, 23 Apr 2018 15:50:50 +0000 (11:50 -0400)]
tests: set PATH so swtpm_cert can be found

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: make the TPM spec parameters mandatory for the EK cert
Stefan Berger [Sun, 22 Apr 2018 02:10:36 +0000 (22:10 -0400)]
swtpm_cert: make the TPM spec parameters mandatory for the EK cert

6 years agoswtpm_setup: Use swtpm_ioctl to get TPM specification info for EK cert
Stefan Berger [Sun, 22 Apr 2018 02:01:26 +0000 (22:01 -0400)]
swtpm_setup: Use swtpm_ioctl to get TPM specification info for EK cert

Use the new --info parameter for swtpm_ioctl to get TPM specification
info from the swtpm and use this as a parameter for creating the EK
certificate.

Extend the man page.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_ioctl: implement --info option to get implementation info
Stefan Berger [Sun, 22 Apr 2018 01:49:03 +0000 (21:49 -0400)]
swtpm_ioctl: implement --info option to get implementation info

Implement the --info option that takes a flag as an argument
and returns information about the TPM implementation. Only the
value '1' has been defined for now, which returns a line as
the following:

{"TPMSpecification":{"family":"1.2","level":2,"revision":116}}

Extend the man page.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agosamples: implement options for pass TPM spec parameters
Stefan Berger [Sun, 22 Apr 2018 02:07:47 +0000 (22:07 -0400)]
samples: implement options for pass TPM spec parameters

Implement options --tpm-spec-family, --tpm-spec-revision, and
tpm-spec-level to pass to swtpm_cert for EK creation.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Implement CMD_GETINFO to retrieve TPM specification info
Stefan Berger [Sun, 22 Apr 2018 01:44:31 +0000 (21:44 -0400)]
swtpm: Implement CMD_GETINFO to retrieve TPM specification info

We quetry the swtpm for TPM specification info that goes into the
certificate for the EK.

Update the test cases that now see more capabilties being returned
by the swtpm.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: source common rather than test_common
Stefan Berger [Sun, 22 Apr 2018 02:13:17 +0000 (22:13 -0400)]
tests: source common rather than test_common

6 years agoman: add an example to swtpm_setup man page
Stefan Berger [Wed, 18 Apr 2018 18:51:42 +0000 (14:51 -0400)]
man: add an example to swtpm_setup man page

Add an example for how to run swtpm_setup to simulate TPM 1.2
manufacturing.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agosamples: Error out if key exists but is not readable for user
Stefan Berger [Wed, 18 Apr 2018 17:53:13 +0000 (13:53 -0400)]
samples: Error out if key exists but is not readable for user

If the key is not readable as the current user, such as tss:tss,
but it is there, we don't try to create it but error out.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Error out if the Authority Key Id could not be gotten
Stefan Berger [Tue, 17 Apr 2018 12:58:04 +0000 (08:58 -0400)]
swtpm_cert: Error out if the Authority Key Id could not be gotten

Since the EK cert must have an Authority Key Id, we error out if
the signing certificate we are given does not have an Authority
Key Id. The typical reason why it wouldn't have it is that we are
using a self-signed (rootCA) certificate directly.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: Use a root CA for creating the issuercert for test_swtpm_cert
Stefan Berger [Tue, 17 Apr 2018 14:22:02 +0000 (10:22 -0400)]
tests: Use a root CA for creating the issuercert for test_swtpm_cert

Update the test case test_swtpm_cert to have its issuercert signed
by a created root CA so that we have the Authority Key Id in the cert.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agosamples: Create a root CA that signs the cert used for creating TPM certs
Stefan Berger [Tue, 17 Apr 2018 12:52:26 +0000 (08:52 -0400)]
samples: Create a root CA that signs the cert used for creating TPM certs

We are currently missing the Authority Key Id in the certificate used for
creating the EK cert. To get this, we create a root CA for our local CA
and use that root CA to sign the local CA's certificate. Our local
CA is now an intermediate CA and the Authority Key Id can now be copied
into the EK cert.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: log output of tool creating cert
Stefan Berger [Tue, 17 Apr 2018 14:13:16 +0000 (10:13 -0400)]
swtpm_setup: log output of tool creating cert

Log the output of the tool that is creating the certificate and
prefix every line with the name of the tool.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_setup: run exec in a subshell when suppressing errors
Stefan Berger [Tue, 17 Apr 2018 14:02:14 +0000 (10:02 -0400)]
swtpm_setup: run exec in a subshell when suppressing errors

To not loose stderr we have to run the exec command in a subshell
and suppress the output of the subshell otherwise the exec command
seems to close stderr on us.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Add Subject Directory Attributes to EK cert
Stefan Berger [Mon, 16 Apr 2018 19:18:52 +0000 (15:18 -0400)]
swtpm_cert: Add Subject Directory Attributes to EK cert

Create the TPMSpecification SEQUENCE and add it to the subject
directory attributes of an EK cert.

The code generates the same ASN.1 for the Subject Directory Attributes
as the example in the EK spec has.

> openssl asn1parse -in ${cert} -strparse 603
    0:d=0  hl=2 l=  30 cons: SEQUENCE
    2:d=1  hl=2 l=  28 cons: SEQUENCE
    4:d=2  hl=2 l=   5 prim: OBJECT            :2.23.133.2.16
   11:d=2  hl=2 l=  19 cons: SET
   13:d=3  hl=2 l=  17 cons: SEQUENCE
   15:d=4  hl=2 l=   3 prim: UTF8STRING        :1.2
   20:d=4  hl=2 l=   4 prim: INTEGER           :41010000
   26:d=4  hl=2 l=   4 prim: INTEGER           :7B000000

Extend existing test case so they create the ASN.1 as well.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: cleanup whitespace errors
Stefan Berger [Mon, 16 Apr 2018 19:39:50 +0000 (15:39 -0400)]
swtpm_cert: cleanup whitespace errors

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: factor out encode_asn1 function
Stefan Berger [Mon, 16 Apr 2018 19:16:17 +0000 (15:16 -0400)]
swtpm_cert: factor out encode_asn1 function

Move common code into encode_asn1 function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agosamples: Use the --add-header option for TPM 1.2
Stefan Berger [Thu, 12 Apr 2018 17:19:46 +0000 (13:19 -0400)]
samples: Use the --add-header option for TPM 1.2

Use the --add-header option when writing a cert for a TPM 1.2

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm_cert: Implement --add-header option for adding TPM 1.2 NVRAM header
Stefan Berger [Thu, 12 Apr 2018 17:17:37 +0000 (13:17 -0400)]
swtpm_cert: Implement --add-header option for adding TPM 1.2 NVRAM header

TPM 1.2 certificates need a header when written to NVRAM. This patch
adds a --add-header option for this and prepends the header to.
Also see TCG PC Specific Inmplementation Specification section 7.4.4 and
7.4.5.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Implement mode parameter for --tpmstate option
Stefan Berger [Tue, 10 Apr 2018 18:21:42 +0000 (14:21 -0400)]
swtpm: Implement mode parameter for --tpmstate option

Implement a mode parameter for the tpmstate option so that the user
can choose what the file mode bits of the TPM's state files will be.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agorpm build: Update SELinux policy files for swtpm and swtpm_cuse
Stefan Berger [Mon, 9 Apr 2018 18:38:12 +0000 (14:38 -0400)]
rpm build: Update SELinux policy files for swtpm and swtpm_cuse

swtpm use swtpm.pp and swtpm_svirt.pp. swtpm_cuse only uses
swtpm_cuse.pp now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoselinux: replace swtpmcuse_svirt with swtpm_svirt
Stefan Berger [Mon, 9 Apr 2018 16:06:47 +0000 (12:06 -0400)]
selinux: replace swtpmcuse_svirt with swtpm_svirt

Replace the previously used swtpmcuse_svirt type of policy with
swtpm_svirt. This policy contains the minimum set of rules necessary
to start swtpm from within libvirt.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
6 years agoswtpm_setup: allow passing of uid numbers for user Ids.
Stefan Berger [Thu, 5 Apr 2018 17:42:27 +0000 (13:42 -0400)]
swtpm_setup: allow passing of uid numbers for user Ids.

Try to parse a userid as an integer first and only if that fails,
interpret it as a name.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: allow passing of uid numbers for user Ids.
Stefan Berger [Thu, 5 Apr 2018 17:40:46 +0000 (13:40 -0400)]
swtpm: allow passing of uid numbers for user Ids.

Try to parse a userid as an integer first and only if that fails,
interpret it as a name.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Also remove pidfile at end if fd was passed
Stefan Berger [Thu, 5 Apr 2018 17:12:21 +0000 (13:12 -0400)]
swtpm: Also remove pidfile at end if fd was passed

Address the issue that the pidfile needs to be removed at the end if
a file descriptor was passed in. So we have to look up the file
given the file descriptor and by using /proc/self/fd/.
We also want to make sure that the given file descriptor describes
a regular file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoswtpm: Allow file desciptor passing for pid file
Stefan Berger [Thu, 5 Apr 2018 14:43:23 +0000 (10:43 -0400)]
swtpm: Allow file desciptor passing for pid file

Allow the passing of a file descriptor where the PID file will
be written into.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>