Commit Graph

726 Commits

Author SHA1 Message Date
Stefan Berger
89edc2240c swtpm_setup: Support NetBSD
NetBSD support for swptm_setup.sh.in is like OpenBSD and FreeBSD.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 13:05:07 +00:00
Stefan Berger
33bee66cf1 tools: Make compileable on NetBSD
Make the tools compileable on NetBSD.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 13:03:31 +00:00
Stefan Berger
91004268f0 swtpm_setup: Make work on FreeBSD; adapt echo -en
Make swtpm_setup.sh work on FreeBSD.
A common fix for the problem related to echo stopping to write
data into a socket after the first occurrence of \x0a sees to
write it into a pipe and cat the data from there.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-28 22:16:07 -04:00
Stefan Berger
401e670232 tools: Make compileable on FreeBSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 01:18:46 +00:00
Stefan Berger
f37f86c0dc swtpm_setup: Adapt NVRAM indices for ECC keys
A (draft) specification indicates the ECC key NVRAM indices to use.
Adapt the code to use them in case of EK ECC key.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-27 11:03:43 -04:00
Stefan Berger
6d462f2e06 swtpm_setup.sh: wrap stat in get_filesize
The OpenBSD stat tool uses -f%z to return the file size in bytes.
So we wrap stat in get_filesize and call it with different parameters
depending on the system.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-26 16:03:53 -04:00
Stefan Berger
e7194c6648 swtpm_setup.sh: Adapt od and echo usage for OpenBSD
On OpenBSD 6.2 we have an older version of od that does not support the
-w parameter. Also we have to use the bash echo there since /bin/echo
does not support the -e parameter. We are using /bin/echo on the other
systems since there was (once) a bug when \x0a had to be converted to a
hex number.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-26 16:03:53 -04:00
Stefan Berger
4b6a84190c swtpm_setup: OpenBSD: replace access to proc filesystem
OpenBSD does not have a proc file system from which we could
determine the path that swtpm_setup was run from and where we
expect swtpm_setup.sh to be located in as well. Using getenv("_")
seems to work as a replacement in the OpenBSD case.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-26 16:03:53 -04:00
Stefan Berger
e69423f277 swtpm_setup: Replace shuf usage with $RANDOM.
Replace usage of shuf with a get_random function that produces
a random number between an upper and lower bound.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-26 16:03:52 -04:00
Stefan Berger
e4405317b3 swtpm_ioctl: Fix number of bytes passed into and expect from ctrl channel
Fix the number of bytes passed into the control channel for commands
and expected for responses. The pointer to the memory is ok.
This fixes uninitialized memory errors reported by valgrind.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 11:28:08 -04:00
Stefan Berger
cd2f547d6a swtpm_ioctl: Fix memmory leak before process exit
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 11:28:08 -04:00
Stefan Berger
fc36ef35ea swtpm: fix memory leak related to tpmstate directory
This patch fixes a memory leak before process exit.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 11:27:48 -04:00
Stefan Berger
9c8202ed79 swtpm: free a CUSE related parameter upon exit
This patch fixes a memory leak before process exit.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 10:19:52 -04:00
Stefan Berger
321a22cc66 swtpm: Fix memory leak related to log prefix
This patch fixes a memory leak before process exit.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 10:19:31 -04:00
Stefan Berger
40185e481b swtpm: implement ptm_cleanup for cleanup before exit
Implement a common function for cleaning up before exit.
This should now always remove the pid file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 10:19:01 -04:00
Stefan Berger
ccfe1b9654 swtpm: fix memory leak when freeing server struct upon exit
This patch fixes a memory leak before process exit.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 10:18:35 -04:00
Stefan Berger
8cafe9d1df swtpm: free pidfile when cleaning up
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 10:04:03 -04:00
Marc-André Lureau
611a198637 build-sys: fix make distcheck
- fix paths
- ignore chmod issues (they are more package/distro issues)
- scripts are already executable

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-08-08 09:58:22 -04:00
Stefan Berger
64faf455fb build-sys: Build swtpm_setup on all supported platforms
Introduce compile-time variable HAVE_TCSD if the TCSD could
be found. It influences whether TPM 1.2 related swtpm_setup
test cases can be run. If it is set, they can be run.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
04e45e3cde swtpm_setup: get rid of netstat dependency
Get rid of the dependency on netstat so that we can at least support
swtpm_setup with TPM 2 on Cygwin and BSD later on. This is the first
step into this direction.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
db45e52d67 swtpm_setup: Only try to find tcsd in TPM 1.2 case
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
6da1e3c4a6 swtpm_setup: remove duplicate setting of ECHO variable
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
8579c6de36 swtpm_setup: also check availability of netstat tool in TPM 2 case
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
71ee437f7f swtpm_setup: check for availability of netstat tool
Check that the netstat tool, which may not be required to be installed,
is indeed installed and usable with a set of command line options.

If this tool is not installed it may end up causing swtpm_setup to
hang forever.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
430a39d335 build-sys: Use $(top_builddir) instead of $(top_srcdir) for include/swtpm.h
The include file include/swtpm.h will be generated from swtpm.h.in and
reside under the $(top_builddir) rather than the $(top_srcdir).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
7f086ef946 swtpm_setup: Send TPM2_Shutdown(SU_CLEAR) at end of manufacturing
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
9f4d8af2f0 swtpm_setup: Enable allocation of initially active PCR banks
Implement --pcr-banks to allow a user to choose the set of active
PCR banks. We determine the PCR banks available and enable those
that the user chose and that are available.

The log will now print out the following:

Successfully activated PCR banks sha1,sha256 among sha1,sha256,sha384.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Marc-André Lureau
331d78dbca swtpm: use XDG_CONFIG_HOME to locate config files
This allows to run swtpm_setup as regular user.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
71948dee9d swtpm_setup: Fix 0-size TPM 2 platform certificate in NVRAM
Remove the -s parameter to tpm2_nv_define since it was causing
a 0-size NVRAM location to be created for the platform cert.
Also use the nvindex parameter rather than TPM2_NV_INDEX_PlatformCert
for addressing the platform NVRAM index.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
ec421480cc swtpm_setup: print the NVRAM indices when logging
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
fc60d68597 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>
2018-08-07 12:19:47 -04:00
Stefan Berger
af94ba189e 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>
2018-08-07 12:19:47 -04:00
Stefan Berger
044d4c7f0e 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>
2018-08-07 12:19:47 -04:00
Stefan Berger
230d4a043e 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
bab61563af 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
770e7b8189 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
ab20ebb815 swtpm_setup: Also create the primary storage keys as ECC keys
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
60bee0c78c swtpm_setup: Prepare code for ECC primary storage key
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
2bafefe287 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
7137394899 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
41a1289043 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
391edf1c96 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
cc1c5b7f3f 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
250de46920 swtpm_setup: Pass non evict key handle when creating key
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:46 -04:00
Stefan Berger
814c812e06 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
023423eb41 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
3269485302 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
08da93a96f 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
276eee02b4 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
15226ad9a5 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
e5ffc74dc8 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
8fcec541f8 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
15dfd665c1 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
326e7b5a75 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
fbc596abbb 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>
2018-08-07 12:19:46 -04:00
Stefan Berger
66b42f52ef 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>
2018-08-07 12:19:10 -04:00
Stefan Berger
32af260953 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>
2018-08-07 12:09:56 -04:00
Stefan Berger
3d35c00c52 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>
2018-08-07 09:31:59 -04:00
Stefan Berger
f9b679597f 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>
2018-07-05 18:39:04 -04:00
Stefan Berger
638bd3ba19 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>
2018-07-02 07:28:16 -04:00
Stefan Berger
2536897da6 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>
2018-07-02 07:27:20 -04:00
Stefan Berger
43de0add14 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>
2018-07-02 07:26:17 -04:00
Stefan Berger
ec54294d51 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>
2018-06-30 08:04:42 -04:00
Stefan Berger
d2cd1d6e4e swtpm: get rid of TPM_Malloc/TPM_Free/TPM_Realloc
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-20 10:05:45 -04:00
Stefan Berger
27bf9db67e 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>
2018-06-20 10:05:45 -04:00
Stefan Berger
3c22251dd8 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>
2018-06-20 09:23:18 -04:00
Stefan Berger
7849b6c67f 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>
2018-06-15 09:08:24 -04:00
Stefan Berger
5409034b5f build-sys: Remove '/' after $(DESTDIR)
Remove the unnecessary '/' after $(DESTDIR).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-29 12:16:49 -04:00
Stefan Berger
39f684b39a 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>
2018-05-14 16:58:08 -04:00
Stefan Berger
5b63c5dbff 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>
2018-05-14 16:54:04 -04:00
Stefan Berger
2fe082cde6 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>
2018-05-14 09:22:11 -04:00
Stefan Berger
a6e219a6cb 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>
2018-05-08 12:04:04 -04:00
Stefan Berger
649bd18a14 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>
2018-05-07 15:40:54 -04:00
Stefan Berger
53161369f4 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>
2018-05-07 15:40:54 -04:00
Stefan Berger
f8883a4749 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>
2018-05-07 15:40:54 -04:00
Stefan Berger
1bbd38e97f 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>
2018-05-07 15:40:54 -04:00
Stefan Berger
23234a3859 swtpm_cert: fix a copy and paste error related to TPM attributes
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-05 01:24:15 -04:00
Stefan Berger
2ba290ac56 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>
2018-05-05 01:09:39 -04:00
Stefan Berger
ff641f7cdc 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>
2018-05-04 17:02:03 -04:00
Stefan Berger
81b4af8722 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>
2018-05-04 13:31:30 -04:00
Stefan Berger
4f769ec675 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>
2018-05-04 11:36:16 -04:00
Stefan Berger
3b70a0afa4 SELinux: yet more rules needed for recent Fedora
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-27 12:55:07 -04:00
Stefan Berger
73e136cbc1 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>
2018-04-27 12:21:07 -04:00
Stefan Berger
a6780589b4 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>
2018-04-23 13:55:05 -04:00
Stefan Berger
9670d26d99 swtpm_cert: make the TPM spec parameters mandatory for the EK cert 2018-04-23 10:03:43 -04:00
Stefan Berger
e2951df791 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>
2018-04-23 10:03:43 -04:00
Stefan Berger
0dda8245d2 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>
2018-04-23 10:01:07 -04:00
Stefan Berger
2b8a668dbb 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>
2018-04-23 10:00:26 -04:00
Stefan Berger
e32c525f5f 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>
2018-04-17 10:52:35 -04:00
Stefan Berger
a692723e9d 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>
2018-04-17 10:52:35 -04:00
Stefan Berger
c6436e4821 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>
2018-04-17 10:52:35 -04:00
Stefan Berger
68baacd721 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>
2018-04-16 21:22:19 -04:00
Stefan Berger
1fe885aaba swtpm_cert: cleanup whitespace errors
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-16 21:22:19 -04:00
Stefan Berger
c8c2ff3eaa swtpm_cert: factor out encode_asn1 function
Move common code into encode_asn1 function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-16 21:22:19 -04:00
Stefan Berger
8c473d6176 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>
2018-04-12 13:17:39 -04:00
Stefan Berger
640f1fab05 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>
2018-04-10 14:30:14 -04:00
Stefan Berger
6fcd12236a 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>
2018-04-09 12:08:46 -04:00
Stefan Berger
8e2525924d 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>
2018-04-05 18:24:28 -04:00
Stefan Berger
cebb1a9c1f 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>
2018-04-05 18:24:28 -04:00
Stefan Berger
f4286d0a0e 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>
2018-04-05 18:24:26 -04:00
Stefan Berger
db60877590 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>
2018-04-05 10:43:25 -04:00
Stefan Berger
0d00e18f87 selinux: update policy for swtpm to support libvirt integration
Update the SELinux for swtpm so that swtpm can be launched from
libvirtd and QEMU can access swtpm's UnixIO socket and talk to it.

Use this as follows:

> cd src/selinux
> make clean all
> semodule -i *.pp
> restorecon /usr/bin/swtpm*

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-04 12:37:18 -04:00
Stefan Berger
f34e01a5a9 swtpm: Add 'uid' and 'gid' parameter to set UnxiIO file ownership
Implement support for uid and gid parameters that allows us to set the file
ownership of a UnixIO socket.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-03 07:48:25 -04:00
Stefan Berger
682fe58172 swtpm: Add 'mode' parameter to allow setting UnixIO path file mode bits
Implement support for a mode parameter that allows us to set the file
mode bits on a UnixIO socket.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-03 07:30:56 -04:00
Stefan Berger
7f46fa867f Register libtpms callbacks a lot earlier
Create tpmlib_register_callbacks and call it to register the
libtpms callbacks a lot earlier. Before it was done in tpmlib_start,
which was invoked by CMD_INIT, which was after state blobs could
have been set already.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-03-27 22:00:20 -04:00
Stefan Berger
66a10b3028 swtpm: Fix memory leak in ctrlchannel related to sockpath
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 21:11:12 -05:00
Stefan Berger
716608eca2 swtpm: fix memory leaks when getting or setting state
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 21:00:25 -05:00
Stefan Berger
98059a2908 swtpm: Also check the state blob in the CUSE TPM
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 15:31:09 -05:00
Stefan Berger
b085ff2335 swtpm: Validate state blobs after setting them
Validate the state blobs after they have been set (during
state migration) so that we can fall back to the migration
source in case they are not accepted by the TPM.

This patch requires the latest version of libtpms 0.6
from the master branch.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-17 14:24:06 -05:00
Stefan Berger
6e79c3b32d swtpm_setup: avoid using expect tool whenever possible
Avoid using the expect tool as much as possible. Use it only if
the user requested a special owner and/or SRK password.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-12 10:29:37 -05:00
Stefan Berger
78c185487e swtpm_setup: Strictly use passwords as specified by user
Use the passwords as specified by the user also when only temporarily
taking ownership. Use the zero password in case nothing has been
provided by the user. This is a first step to loosen the dependency
on expect, which pulls in too many dependencies.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-02-12 10:10:33 -05:00
Stefan Berger
bf544661b0 swtpm: loop in case poll sets errno EINTR
In case the poll() is interrupted by a signal handler and we
get EINTR, we loop again assuming that the signal handler will
send us a notification to end.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-30 09:07:46 -05:00
Stefan Berger
4a10cb1380 swtpm: close client file descriptor if POLLERR is indicated
POLLERR is indicated in some error cases when using the chardev with the
vtpm_proxy with runc. In case the flag is set, we terminate the client
connection rather than endlessly looping.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-30 09:01:01 -05:00
Stefan Berger
83764896f0 swtpm: Refuse to accept passed file descriptors < 3
File descriptors 0, 1, and 2, when used for file descriptor passing,
as is the case in some older version of runc/docker-ce (17.06), do
not work. So we refuse accepting these values and log the error message.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-30 09:01:01 -05:00
Marc Kleine-Budde
3f548f90a0 treewide: remove executable bit from config files and c-code
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2018-01-17 10:45:25 -05:00
Stefan Berger
e5477e193f swtpm_setup: fix typo in help screen
--no-overwrite -> --not-overwrite

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-12 09:48:40 -05:00
Stefan Berger
be5557f3ff swtpm_cert: Sign cert using SHA256
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-01-02 09:41:34 -05:00
Stefan Berger
a8bc74fd01 swtpm_setup: Only pass through vmid parameter if it was set
Only pass through the vmid parameter to the tool creating the cert
if this parameter was set. The tool creating the cert may require
it or ignore it and is supposed to be able to track certificates
for which it minted certs using this parameter.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-20 20:18:54 -05:00
Stefan Berger
5b1090a583 swtpm_cert: Fix broken certificate verification
The certificate chain could not be verified due to a wrong
API call for getting the authority key id where the key id
was gotten instead.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-20 11:12:15 -05:00
Stefan Berger
8e9edf696a swtpm: reformat iovec and initialize input variable with zeros
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-10 11:28:59 -05:00
Stefan Berger
7306ee278a swtpm: check for invalid file descriptor (< 0)
Check for an invalid file descriptor in SWTPM_IO_Read before accessing
it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-08 09:44:17 -05:00
Stefan Berger
a56a22540e swtpm_bios: only copy the size of the source string + 1 byte
Determine the size of the unix_path parameter and then only copy
those number of bytes + terminating null into the destination.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 19:53:41 -05:00
Stefan Berger
f42eec69f3 swtpm_ioctl: only copy the size of the source string + 1 byte
Determine the size of the unix_path parameter and then only copy
those number of bytes + terminating null into the destination.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 18:06:38 -05:00
Stefan Berger
3bb2b4675a swtpm_ioctl: check for filename and input NULL pointers
Check whether filename and input pointers are NULL pointers.
Per previous code this is currently not possibly but should
resolve some issues with Coverity.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 17:52:27 -05:00
Stefan Berger
5d62484fb7 swtpm_ioctl: in get_blobtype() check for blobtype NULL pointer
Check whether the passed blobtype is a NULL pointer

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 17:45:20 -05:00
Stefan Berger
aaab5d0b16 swtpm_bios: Coverity: use void * for the command
Use void * for the command rather than tpm_header *, which we do
not need. This addresses a few Coverity complaints.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-07 17:06:00 -05:00
Stefan Berger
4f4f2f0a7e swtpm: Remove usage of TPMVersion enum
To allow it to compile with libtpms's master, remove the usage of
TPMLIB_TPMVersion type.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-05 12:50:21 -05:00
Stefan Berger
182fbb20d6 swtpm_ioctl: explicitly check for numbytes < 0
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-12-05 12:45:31 -05:00
Stefan Berger
6c441a5272 swtpm: Do not pass a negative file descriptor
Do not a pass a negative file descriptor to getsockopt(). This fixes
a Coverity issue.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-21 12:45:53 -05:00
Stefan Berger
3ca520fd1c swtpm_ioctl: print error message in case setting state blob fails
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-13 20:44:08 -05:00
Stefan Berger
e396140204 swtpm: log when the decryption of a state blob fails
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-13 20:43:11 -05:00
Stefan Berger
cf47149f88 swtpm: log when the decryption of the NVRAM file fails
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-13 19:35:23 -05:00
Stefan Berger
3760c34251 swtpm: Add truncate parameter for --log option
Enable the resetting of the log using a truncate parameter for the
--log option.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-11 14:47:27 -05:00
Stefan Berger
41deaf616e swtpm: always set the logging file descriptor on libtpms
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-11 14:24:12 -05:00
Stefan Berger
addf7c5e45 swtpm: Also log the control channel exchanges
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 21:48:17 -05:00
Stefan Berger
ccd1aeb15b swtpm: also log control channel commands 2017-11-10 21:32:44 -05:00
Stefan Berger
60afebf116 swtpm: Log an error if data encryption failed
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 19:04:57 -05:00
Stefan Berger
73fb0412ea swtpm: Remove file if errors occured writing it
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 19:04:57 -05:00
Stefan Berger
f1389afb87 swtpm: Move debugging output into own function
Move some of the debugging output into its own function and
differentiate output by TPM Version number.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-10 18:55:54 -05:00
Stefan Berger
eff9cc1672 swtpm_setup: Add options to overwrite or not overwrite TPM state
Add options --overwrite and --not-overwrite to allow or prevent
overwriting of existing TPM state. If neiter of the options is
given and existing state is found, an error is returned.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-09 10:54:07 -05:00
Stefan Berger
38304e9c81 swtpm: remove debug include file
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-05 15:38:13 -05:00
Stefan Berger
688c8e2400 swtpm: Implemented support for PTM_SET_BUFFERSIZE command
Implement a command for setting and querying the buffer size the
TPM implementation (libtpms) is using. The setting of the
buffersize allows to reduce the size of the buffer to a size
that the interface can support so that these two sizes match
and the TPM will not produce larger responses than what the
interface can support.

Extend swtpm_ioctl with an option to set the buffersize.

Adapt the existing tests to reflect the newly supported command.
Implement a new test for getting/setting of the buffer size.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-11-05 14:53:00 -05:00
Stefan Berger
ca7f7a4006 swtpm: fix segfault introduced in aa3999
Changeset aa3999 introduced a segfault when calling
ctrlchannel_set_client_fd() with a NULL pointer. Like all the other
functions, we return with -1 in this case.

Since the segfault occurred on process shutdown no problems were
noticeable through bad test results or so.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-30 12:02:56 -04:00
Stefan Berger
061f9dce5e swtpm: Install SIGPIPE signal handler to ignore signal
Install a SIGPIPE signal handler to ignore the signal from trying
to write to a broken pipe.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-27 08:37:40 -04:00
Stefan Berger
e09966f603 swtpm_setup: Fix a couple of typos
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-27 08:37:40 -04:00
Stefan Berger
298d17822c swtpm: clean up server and ctrlchannel at the end
Introduce another parameter to ctrlchannel_new and server_new
to pass the Unix socket's path. Implement ctrlchannel_free and
server_free to clean up and remove the Unix socket's path.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
aa3999d387 swtpm: Implement ctrlchannel_set_client_fd()
Implement ctrlchannel_set_client_fd() to set a new client
fd and return its current value.

Use this new function to set the file descriptor to -1 upon
closing its associate file descriptor in the main loop.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
75f9f0d300 swtpm: Implement server_set_fd()
Implement server_set_fd() function to get the current file descriptor
and set a new one on the server structure.

Use this function to transfer the server file descriptor from the
server structure to the mainloop structure and have the main loop
close the file descriptor.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
fa3d8e4910 swtpm_ioctl: Display error in case of read() returns < 0
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-16 14:19:48 -04:00
Stefan Berger
6ee0bd79d7 swtpm: Fix header inclusion for OpenBSD
Signed-off-by: Stefan Berger <stefanb@linx.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
2dc486cb97 swtpm_ioctl: Define missing #define's for OpenBSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
730ed7c32e swtpm_bios: include sys/socket.h for OpenBSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
54ed795b60 swtpm: Fix off-by-one for sockaddr len for OpenBSD
On OpenBSD the socket's name would be cut short by one letter at the
end due to an off-by-one for the calculated sockaddr struct's length.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
b20eafa7b4 swtpm: reformat source
Signed-off-by: Stefan Berger <stefanb@linx.vnet.ibm.com>
2017-10-12 13:07:46 -04:00
Stefan Berger
1d92a4df07 swtpm: Do not set PTM_CAP_SET_DATAFD flag on Cygwin
The control channel of a UnixIO socket is not supported
on Cygwin, so do not present this flag. Return an error
if this command is run.

Adapt the test case.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-11 18:57:16 -04:00
Stefan Berger
6d42968570 swtpm_cert: add cast to avoid compile error on i686
Cast the exponent to unsigned long int to avoid a compiler
error reporting comparison of signed and unsigned integers.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-10-05 07:17:25 -04:00
Stefan Berger
a00e882c0a swtpm: remove whitespace error
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-29 13:55:56 -04:00
Amarnath Valluri
c310f1d7a0 Remove code duplication related to TCP socket creation
Consider TPM_PORT environment at the time of parsing server options. This way we
can avoid the code duplication, hence removed obslote code.

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2017-09-29 13:11:44 -04:00
Amarnath Valluri
1fb8bb790f Support added to receive data socket over control socket
As objected by QEMU upstream developers to use two different sockets for
starting/using of swtpm, This commit adds support for passing unix domain
socket over control channel.

The summary of the changes include:
 - Defined new control command CMD_SET_DATAFD, using this clients can send data
   socket.
 - set mlp.fd and mlp.flags outside of the mainloop
 - updated the testcases

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2017-09-29 13:11:01 -04:00
Stefan Berger
52d1090b74 swtpm: switch to recvmsg for receiving data
In preparation for receiving control messages via UnixIO sockets,
switch to recvmsg() for receiving the first chunk of data.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-28 09:40:16 -04:00
Stefan Berger
ec3352ff7f swtpm: enable receiving control commands in chunks
Enable receiving control commands in small chnunks. Allow 500ms
for the whole control command to be received.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-28 09:40:15 -04:00
Stefan Berger
dd96bd5417 swtpm: add missing PTM_CAP_GET_CONFIG to returned flags
Add the missing PTM_CAP_GET_CONFIG to the returned flags.

Fix the order of the flags on the way.

Fix the test cases that test for the flags.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-27 07:11:32 -04:00
Stefan Berger
b1fe8710d7 swtpm: Make 32bit CUSE swtpm work on 64bit host
Remove the check for the FUSE_IOCTL_COMPAT flag to make a 32bit
CUSE swtpm work on 64bit host.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-09-26 11:44:51 -04:00
Stefan Berger
f1766b31b3 swtpm: raise error on unhandle command line parameters
Raise an error on unhandled non-option command line parameters.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-25 10:59:14 -04:00
Stefan Berger
5817b1e497 Fix possible illegal buffer access
Fix possible illegal buffer access in case a character device
is used via ioctl. In this case we have to make sure we only
access the number of bytes in the ioctl structure itself.

In case of a socket, make sure we received enough bytes to
be able to access the payload.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-18 17:16:55 -04:00
Stefan Berger
b79146caa2 Fix memory leak of tpmstatedir in case of error
Fix memory leak of tpmstatedir in case of error.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-18 17:08:11 -04:00
Stefan Berger
c4b8d7b443 Fix memory leak of pidfile in case of error
Fix memory leak of pidfile in case of error.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-18 17:07:59 -04:00
Stefan Berger
63ab6c3c21 Introduce '--flag not-need-init' for socket and chardev
Change the startup behavior with respect to requiring an INIT command
via control channel. We change this for the socket and chardev
interfaces so that the behavior now is the same as that of the CUSE
interface.

Introduce the --flag not-need-init command line option for the socket
and chardev interfaces to allow the old behavior using this option.

Adapt some of the test cases and swtpm_setup.sh.in that now need this
command line flag.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-11 14:04:40 -04:00
Stefan Berger
cf618c3d10 swtpm_setup: Allow running swtpm_setup as tss directly
Allow running swtpm_setup directly as tss user using the following
command lines as an example for how to do it:

mkdir /tmp/test-tss
chown tss:tss /tmp/test-tss
chmod 770 /tmp/test-tss
su -c "swtpm_setup --tpm-state /tmp/test-tss" -s /bin/sh tss

This change prevents us from requiring invocation under the root
user.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-11 14:04:19 -04:00
Stefan Berger
df28cf6258 swtpm_setup: replace show_help variable by change_user
Replace the show_help variable with change_user varaible with
opposite logic. The name of the variable is better for upcoming
changes.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-11 13:59:36 -04:00
Stefan Berger
70cb447a99 Fix return code for ResetEstablishmentBit
If the return code from the command processing function is 0,
get the error code from the command response and return that one
instead. The problem was that clients though resetting the
establishment bit worked in locality 0 for example, while it did
not.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-10 12:13:45 -04:00
Stefan Berger
ac78c63634 Fix a parameter problem in non-Linux function prototype
A parameter from the TPM2 backport had not been removed. Fix it so
it compiles on cygwin.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-07-10 12:12:44 -04:00
Stefan Berger
970faf77b7 swtpm_ioctl: fix ctrlcmd return parameter and fix state recv logic
Return the number of bytes received in case ctrlcmd does not
use an ioctl because in this case we need to know how many bytes
we received in the response.

The receiving of the state blob also needs to take into account
how many bytes were received in the initial response so we write
the proper amount of bytes from that response into the file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-30 16:09:27 -04:00
Stefan Berger
5130f4e357 swtpm: silence printf's in TPM1.2 inherited code
Silence the printf's in code taken from TPM1.2.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-29 15:49:08 -04:00
Stefan Berger
84259c17df swtpm: Enable --migration-key for socket and chardev interfaces
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-15 19:11:33 -04:00
Stefan Berger
8a1de2ce47 swtpm: log error if broken header is detected
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-15 19:10:13 -04:00
Stefan Berger
1ff4c6c54a swtpm: work on a copy of argv[] variables
While parsing the options we modified the argv[] values and
the commas disappeared, which showed when checking for the
swtpm processes using 'ps'. So, work on a copy of the options
parameter.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-15 19:10:13 -04:00
Stefan Berger
95a0542a26 swtpm: Fix an endianess issue in ctrlchannel and offset bug
There was an offset bug in the code getting the state blobs
from a client.

Also fix an endianess bug in a control channel command.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-15 18:54:15 -04:00
Stefan Berger
e3d8093b00 swtpm_ioctl: enable state migration for socket interface 2017-06-15 18:53:31 -04:00
Stefan Berger
dc1111362b Implement allow-set-locality for CUSE TPM and extend test case.
Implement allow-set-locality for CUSE TPM and extend the existing
locality test case with commands that try to write the SetLocality
comamnd to the device.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-06 16:51:45 -04:00
Stefan Berger
3b563487b6 Extend help screen with allow-set-locality option
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-06 16:42:39 -04:00
Stefan Berger
a2f81ea2c6 Implement support for --locality allow-set-locality option
Implement support for --locality allow-set-locality option that
is primarily useful in cases when the VTPM proxy access is enabled
by file descriptor passing.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-06 14:10:01 -04:00
Stefan Berger
4a56541491 Add options for locality handling and SetLocality command
Add options for locality handling so that commands in locality
4 for example are rejected per command line parameter. This is
useful when the vTPM is used with containers.

Also implement the custom TPM/TPM2_SetLocality command to allow
the Linux vTPM proxy driver to set the locality in which subsequent
TPM commands will be executed.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-06-01 16:59:20 -04:00
Stefan Berger
768d657b69 Fix compilation errors on Debian Jessie 32bit ARM
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-05-31 13:45:44 -04:00
Stefan Berger
b12d77106c swtpm: Refactor error response creation
Refactor the function creating the error response.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-04-19 19:16:29 -04:00
Stefan Berger
811a255869 swtpm: Have the tpm_req_header struct packed
Add missing __attribute__((packed) to tpm_req_header struct.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-04-19 18:45:35 -04:00
Stefan Berger
43153f3d26 swtpm: Check return code < 0 from handle_server_options
Fix the missing check of return code from handle_server_options
to check for negative value like all the other checks also do.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-04-19 18:44:47 -04:00
Stefan Berger
073e71f99e swtpm: Add missing space after hex number
Add a missing space character after display of a hex number.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-04-07 11:23:30 -04:00
Stefan Berger
510f184896 swtpm: Fix memory leak related to option parameters
Fix a memory leak related to the option parameters.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-31 08:55:08 -04:00
Stefan Berger
cba815690c swtpm: Use logprintf wherever possible
Use logprintf wherever possible. While the logging is not set up,
print error messages to stderr and prefix them with 'swtpm: '. After
the logging has been set up all error messages go into the log file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-31 08:55:08 -04:00
Stefan Berger
93f4a38940 swtpm: add logging option prefix=<prefix>
Add support for logging each line of output with a prefix.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-31 08:55:08 -04:00
Stefan Berger
8e794c635a swtpm: Use buffer printing for TPM_PrintAll
Use a buffer for printing in TPM_PrintAll. Emit the buffer
upon a new line. This prepares for printing every line with
a prefix.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-31 08:28:21 -04:00
Amarnath Valluri
87d56f936c Read all data at once incase of non-stream sockets.
Add MAIN_LOOP_FLAG_READALL for non SOCK_STREAM client sockets. This allows
reading all socket data once.

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2017-03-31 08:17:05 -04:00
Amarnath Valluri
0a0885cf9d swtpm: Keep client data connection alive
swtpm server is closing the client data connection after serving a single
request, which shall not happen. Hence added MAIN_LOOP_FLAG_KEEP_CONNECTION
mainloop flag to keep the client data connection alive, till client is alive.

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2017-03-31 08:17:05 -04:00
Amarnath Valluri
93edca48a2 swtpm: Added support for passing control channel client fd.
New option '--ctrl clientfd=<fd>' is added to the control socket parameters.
The passed 'fd' is used as control channel client-fd and treated as single
client mode.

Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2017-03-31 08:15:51 -04:00
Amarnath Valluri
4cb30804d6 mainloop: enumerate the pollfd indexes.
Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2017-03-31 08:14:33 -04:00
Stefan Berger
3f37cc3e5f swtpm: Set errno to 0 before calling strtoul
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-31 08:14:33 -04:00
Stefan Berger
d7bbe3de5c swtpm_ioctl: Rearrange code for Unix client socket setup
Rearrange the code of the setup of the Unix client socket.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-14 08:37:56 -04:00
Stefan Berger
faceb515c4 swtpm_bios: Rearrange code for Unix client socket setup
Rearrange the code of the setup of the Unix client socket.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-14 08:37:56 -04:00
Stefan Berger
753770033a swtpm: Initialize variables in ctrlchannel_return_state
Initialize variables in ctrlchannel_return_state so that all error cases
are properly handled.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-14 08:37:56 -04:00
Stefan Berger
5569ab5674 swtpm: describe ctrlchannel_process_fd function
Describe purpose and parameters of the ctrlchannel_process_fd function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-14 08:37:56 -04:00
Stefan Berger
f5b286fc7d swtpm_ioctl: initialize locality variable
Initialize the locality variable.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-03-14 08:37:34 -04:00
Stefan Berger
51c41a4862 swtpm: set default log level to 1
Set the default log level to 1 so that console output is shown.
This can be turned off with --log level=0

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-02-03 11:21:31 -05:00
Stefan Berger
380763be6b swtpm: Set loglevel to 1 if log file or file descriptor is given
Set the default log level to 1 if log file or file descriptors are
given.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-02-03 10:23:38 -05:00
Stefan Berger
c7c657ec3d swtpm_cuse: Add log level parameter to help screen and man page
Add the log level parameter to the CUSE TPM's help screen and man
page.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-02-02 17:52:30 -05:00
Stefan Berger
540a9a9632 swtpm_cert: Create sets of items
Following the example in the Appendix A.1 of the TCG EK Credential
Profile Spec Version 2.0, a ASN.1 SET is supposed to be created for
each one of the items. This patch fixes the format.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-02-02 13:07:32 -05:00
Stefan Berger
624b11d860 swtpm_cert: use GNUTLS 3.5 function to set TPM data
Use the GNUTLS 3.5 function gnutls_x509_crt_set_subject_alt_othername
to set the TP<M and platform manufacturer info since the other function
does not accept binary data.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-02-02 10:50:35 -05:00
Stefan Berger
e8b5115f1a swtpm: Expose logging level to command line
Expose the logging level to the command line by extending the
log option with a level parameter.
Extend the man swtpm man page with the level parameter.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-23 19:09:50 -05:00
Stefan Berger
a167784102 swtpm: Support unsigned int option
Implement support for an unsigned int option.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-23 18:20:18 -05:00
Stefan Berger
e34f4ef8eb swtpm: Implement logging following indentation level
Introduce a log level for the logging functions. The log level
is defined by the number of spaces used for indentation. Adapt
the log functions to only log when the number of leading spaces
in a string is appropriate for logging.

Call the log function of libtpms to set the file descriptor to
log to, the log level, and log line prefix.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-23 18:20:17 -05:00
Stefan Berger
f44aec27e0 swtpm: Fix buffer used in logging output
Fix the buffer used in the logging output.

Signed-off-b: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-23 17:52:25 -05:00
Stefan Berger
8047b5d62d Add bindaddr and ifname parameters to --server option on help screen
Fix the missing mentioning of the bindaddr and ifname parameters for
the --server option on the help screen.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-15 08:55:53 -05:00
Stefan Berger
4c6fc24467 Errno is not set after inet_pton
Do not call strerror(errno) after failure from inet_pton.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-15 08:55:49 -05:00
Stefan Berger
c751e32ec7 Only compile vTPM proxy support if available on platform
Support for vTPM proxy is only available on Linux.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-15 08:55:07 -05:00
Stefan Berger
099c9cb64b Announce the TPM frontend device name and major/minor numbers
Announce the TPM frontend device name and major/minor numbers.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-14 15:28:05 -05:00
Stefan Berger
794f84982d swtpm: print TPM commands read from file descriptor
Print TPM commands read from the file descriptor.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-13 21:48:12 -05:00
Stefan Berger
ee8b6c2d65 Implement option --vtpm-proxy to create Linux vtpm proxy device
Implement the option --vtpm-proxy that create a Linux vtpm proxy device
and makes the chardev TPM listen on the anaonymous file descriptor that
is returned from the ioctl creating the device.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-13 21:45:04 -05:00
Stefan Berger
3a8a06ad0a Display chardev choice only if compiled in
Only display the chardev choice if chardev support has been
compiled in.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-03 08:22:55 -05:00
Stefan Berger
498433f7b5 Detect whether to build with chardev
Detect whether to build with the chardev interface and only run tests that
need the chardev if it is supported on a particular platform.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-03 07:18:38 -05:00
Stefan Berger
9d64b92375 Return EXIT_FAILURE if unknown command was given
Return EXIT_FAILURE to the caller if an unknown command was given.

Signed-off-by: Stefan Berger <stefan@linux.vnet.ibm.com>
2017-01-02 20:53:28 -05:00
Stefan Berger
6286beacd2 Enable building on cygwin
Enable building the swtpm on cygwin.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-02 20:53:28 -05:00
Stefan Berger
c3fdf68860 Skip swtpm_setup build if NVRAM tools are not available
When NVRAM tools are not available we skip building swtpm_setup.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-02 20:53:28 -05:00
Stefan Berger
09d1a532ba Add configure option --with-cuse to enable building without CUSE
Enable building without CUSE interface using --without-cuse.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-01-02 18:54:30 -05:00
Stefan Berger
3aa53709a1 swtpm_setup: support --tpmstate as alias for --tpm-state
Support --tpm-state option as an alias for the --tpmstate option.
--tpm-state is a parameter that is also supported by the swtpm
program, so for consistency reasons we should have the same name
for the option here.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-06-26 20:26:53 -04:00
Stefan Berger
471d8daef2 swtpm_ioctl: Add missing option descriptions to usage page
Add missing --unix and tcp option descriptions to the usage page.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-06-26 20:15:01 -04:00
Stefan Berger
4c707474d5 swtpm_bios: Fix typo in usage page
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-06-26 20:14:00 -04:00
Stefan Berger
01eb4d3a3b swtpm_ioctl: Add support for UnixIO and TCP control channel
Add support for UnixIO and TCP control channels. Both types of
transport require that packets are sent in big endian format
and therefore some code needs to be adjusted for that. The
ioctl interface is local and in that case no endianess conversion
is done.

Add a new test case that uses the extended swtpm_ioctl tool to
test the control channel.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-20 16:58:48 -04:00
Stefan Berger
aeee2dc88b swtpm: Fix typo in command name
Fix a typo in two command names so that they are similar to
the command name spelling used for the ioctl's.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-20 16:58:44 -04:00
Stefan Berger
bf2cee5c73 swtpm_ioctl: replace return codes in main()
Replace the return codes in main with EXIT_SUCCESS and EXIT_FAILURE.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-20 10:55:28 -04:00
Stefan Berger
37dcf15b86 swtpm_ioctl: add --tpm-device command line option
Add support for providing the TPM device via command line option
--tpm-device <device>.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-20 10:46:10 -04:00
Stefan Berger
96cc5d6027 swtpm_ioctl: switch to using getopt_long for option parsing
Rather than parsing the option on our own use getopt_long() now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-19 14:21:58 -04:00
Stefan Berger
fc4e289617 swtpm_bios: Add support for UnixIO socket
Add support for UnixIO socker using --unixio command line
option.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-18 17:21:20 -04:00
Stefan Berger
7382352955 swtpm: Add support for commands over UnixIO socket
Add support for receiving TPM commands over UnixIO socket.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-18 17:15:08 -04:00
Stefan Berger
ea898d5b63 swtpm_bios: Add option parameter --tcp to connect to TCP socket
Add support for connecting to a TCP socket where a TPM is listening
for commands.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-18 15:46:23 -04:00
Stefan Berger
e8e4cbe52c swtpm_bios: Add empty option as last one in the list.
Add an empty option as the last one in the list.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-18 15:44:44 -04:00
Stefan Berger
4ec7d70fe8 swtpm_bios: redirect error output to stderr
Redirect all error output to stderr.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-15 21:51:55 -04:00
Stefan Berger
04b607b346 swtpm_bios: add --tpm-device command line option
Add support for providing the TPM device via command line option
--tpm-device <device>.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-15 21:51:18 -04:00
Stefan Berger
8d69193426 swtpm_bios: switch to using getopt_long for option parsing
Rather than parsing the option on our own use getopt_long()
now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-15 18:20:35 -04:00
Stefan Berger
5647fe1536 Fix the size of the receive buffer
Fix the size of the receive buffer input.body to match the largest
buffer any type of command has.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-04-14 14:25:09 -04:00
Stefan Berger
492a635e69 swtpm: Add support for setting the locality on the TPM
Implement the CMD_SET_LOCALITY command.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-26 13:27:03 -04:00
Stefan Berger
6a2dd35b41 swtpm: Add support for sending state blobs to the TPM
Implement the CMD_SET_STATE_BLOB command.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-25 23:47:44 -04:00
Stefan Berger
8f387d55e6 swtpm: Add support for getting state blobs from the TPM
Add support for CMD_GET_STATE_BLOB to get the current state of
the TPM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-25 23:39:24 -04:00
Stefan Berger
a7a261a7e0 swtpm: move function to convert blobtype to name to tpmlib.c
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-25 10:30:56 -04:00
Stefan Berger
73e0c38d8e swtpm: Check for bad input packets sizes
Check all commands for bad input packet sizes.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-25 09:52:54 -04:00
Stefan Berger
3488d25f45 swtpm: Implement resetting the establishment bit with a command
Implement the resetting of the establishment bit with a command

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-24 22:00:24 -04:00
Stefan Berger
b5fbddbcf1 swtpm: deactivate reset establishment
Deactivate the code around resetting the TPM established bit
since its implementation currently requires libtpms 0.6.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-24 14:33:58 -04:00
Stefan Berger
03e0099137 swtpm: Implement two more control channel commands.
Implement two more control channel commands:
- CMD_STORE_VOLATILE
- CMD_HASH_DATA

Implement test cases.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-24 09:34:59 -04:00
Stefan Berger
f56a0cd2a5 swtpm: Further implement the control channel for socket and chardev
Further implement the control channel for the socket and chardev
interface swtpms.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-21 15:25:18 -04:00
Stefan Berger
3f4b2d599e Make TCP socket port reusable
Set the SO_REUSEADDR socket option.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-21 12:59:24 -04:00
Stefan Berger
708a1a471e swtpm: Fix parsing of the options
Fix the parsing of the command line options.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-21 12:47:00 -04:00
Stefan Berger
c2d04f537b swtpm: Fix application of flag mask
Fix the application of the flag mask.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-21 12:46:56 -04:00
Stefan Berger
9195be7f87 swtpm: Listen for TCP connections
Fix a problem with the socket TPM not listening for TCP connections.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-21 11:29:54 -04:00
Stefan Berger
4716d35a69 swtpm: Rename --connect to --server
Rename the --connect option to --server.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-20 14:50:40 -04:00
Stefan Berger
16eb0ff25a swtpm: Extend TCP server parameters with bind address
Extend TCP server parameters with an IPv4/IPv6 bind address
parameter.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-20 14:49:36 -04:00
Stefan Berger
9ddc699812 swtpm: Add the control channel to the socket interface TPM
Add the control channel to the socket interface TPM as well.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-18 16:51:19 -04:00
Stefan Berger
b959335e5d swtpm: let socket and character interfaces share the mainloop
Let the socket and character interfaces share the same mainloop
function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-18 15:55:35 -04:00
Stefan Berger
bfa865a7a1 Prepare the mainloop function for usage by the socket interface
Prepare the mainloop function so that it can be used by the socket
interface as well.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-18 15:14:16 -04:00
Stefan Berger
320d90641e swtpm: move chardev's mainloop into own file
Move the swtpm chardev main loop into its own file for sharing
with the socket interface.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-18 14:27:09 -04:00
Stefan Berger
7c0a033f96 swtpm: add --connect option support
Add support for --connect option for the socket version of the TPM.
This parameter takes the type, port, file descriptor and disconnect
options. Only TCP connections are currently supported.

See updated man pages.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-18 13:36:40 -04:00
Stefan Berger
45cfd52628 tpm_fastpath
Only let certain commands that are cancelable be processed
by the thread. Directly process all other commands.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-03-16 20:03:06 -04:00
Stefan Berger
81c55814dd swtpm_bios: Exit with error if TPM needs to be reset for activation
Exit with error code 129 if the TPM needs to be reset to become activated.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-02-18 09:55:23 -05:00
Stefan Berger
37c73b4ba7 build: Add tpm_bios.h to noinst_HEADERS
tpm_bios.h was missing in the tar created by 'make dist'. This patch
fixes it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-25 16:26:00 -05:00
Stefan Berger
3b64478713 swtpm_bios: use data structures to write commands
Use TPM data structures and constants to write commands.

Fix white space errors on the way.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-24 11:21:14 -05:00
Stefan Berger
ed29bd7229 swtpm: do not compare positive integer with < 0
Do not compare positive integer with < 0.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-24 10:07:55 -05:00
Stefan Berger
71b91c9cef swtpm: do not compare positive integer with < 0
Do not compare positivie integer with < 0.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-24 09:42:50 -05:00
Stefan Berger
feee88b0d8 swtpm: use ioctl structure to return values
Use the ioctl structures to return values. Properly initialize the
TPM result value.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-24 09:40:44 -05:00
Stefan Berger
1e0296851f swtpm: check for unsupported file descriptor types
Rather than checking whether the given file descriptor is a character
device, check whether it is one of the unsupported ones. This addresses
a problem when passing anonymous file descriptors that are not character
devices.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-22 07:43:59 -05:00
Stefan Berger
ffc498b4ca swtpm_setup: send command for EK creation directly
Send the TPM command for EK creation directly; it requires no
crytpo and can be hard coded.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-13 20:07:12 -05:00
Stefan Berger
4a37440a4d build: Link libswtpm_libtpms with glib libs
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2016-01-12 19:52:29 -05:00
Stefan Berger
c9de5f0ab1 build: add threadpool.h
Add the threadpool.h to the noinst headers, so it ends up in the tgz file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-29 04:30:27 -05:00
Stefan Berger
c3c7e8f364 swtpm_bios: Introduce durations to wait for command completions
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-29 04:25:42 -05:00
Stefan Berger
abac744529 swtpm_bios: use select for waiting for response
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-28 20:35:29 -05:00
Stefan Berger
1c1efe2dab swtpm: move threadpool code out of cuse-tpm
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-28 16:13:53 -05:00
Stefan Berger
28a18c29b3 swtpm_setup: improve error handling
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-28 16:10:10 -05:00
Stefan Berger
bb420d7481 swtpm: move process owership to common file and enable in all implementations
Move the code to change process ownership into its own function and enable
--runas|-r <owner> in all implementations.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-27 18:17:49 -05:00
Stefan Berger
e11a75527e tests: add timeout to socat
Add a timeout to socat so that on slower machines the tests succeed.

Clean up an #include.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-21 03:26:46 -05:00
Stefan Berger
804e74728e swtpm: add CMD_SHUTDOWN to control channel
Extend the control channel with CMD_SHUTDOWN to shut down the TPM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-20 20:55:15 -05:00
Stefan Berger
78c5f924bf swtpm: add cuse TPM interface option to swtpm
Now that the CUSE TPM part is BSD licensed, extend the swtpm
program with the cuse option.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-20 20:06:57 -05:00
Stefan Berger
ddf99d057a swtpm: clean up single letter options
Remove single letter options that are not described in the help screen.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-20 13:17:08 -05:00
Stefan Berger
12837911ce swtpm: do not ignore write return value
If the 'swtpm chardev' receives an error on write() or not all bytes
could be written, log an error and terminate.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-13 21:49:49 -05:00
Stefan Berger
86b6ffca75 swtpm: use endian.hi for endianess conversion
Use the macros defined in endian.h for endianess conversion.

Fix the conversion of a 64bit variable.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 17:25:17 -05:00
Stefan Berger
2b4c6da540 swtpm: add missing dirent.h include
On PowerKVM dirent.h needs to be included.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 17:24:43 -05:00
Stefan Berger
db33da6b78 build: fix build of rpm
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 17:24:23 -05:00
Stefan Berger
5f1ef9565d swtpm: Replace the CUSE TPM with the new implementation
Replace the CUSE TPM with the new BSD implementation.
Update the license references and the license itself.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 15:01:57 -05:00
Stefan Berger
57d542a01c swtpm: transfer the rest of the code
Transfer the rest of the CUSE TPM code into the new application.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 14:57:54 -05:00
Stefan Berger
82cf754a79 swtpm: Implement ptm_init_done function
Implement the ptm_init_done function

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 14:57:54 -05:00
Stefan Berger
6a102bc764 swtpm: Implement command line option parsing and main function
Implement the command line option parsing and the main() function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 14:57:54 -05:00
Stefan Berger
6e0dc3ddd5 swtpm: Re-implement CUSE TPM under BSD license
Eric Richter implemented a clean-room skeleton CUSE driver which
we will now convert to the CUSE TPM. The goal is to replace the
GPL CUSE TPM implementation with this 3-clause BSD implementation.
Among other things, this makes it easier to link with OpenSSL.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-07 14:57:54 -05:00
Stefan Berger
ffcb6535d3 swtpm_bios: Add option to give up physical presence
Extend the swtpm_bios tool with an option to give up physical presence.

Have the TPM error codes reflected in the exit error of 128.

Add a test case for the tool.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-04 18:23:13 -05:00
Stefan Berger
a1030ba771 swtpm_ioctl: do not display help screen on -h
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-04 09:31:55 -05:00
Stefan Berger
57e53b78ea swtpm: Add option to only display version info
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-04 07:32:53 -05:00
Stefan Berger
a1fa5d77e2 swtpm: add version info to all programs
Move src/swtpm/swtpm.h.in to include/swtpm.h.in to make it commonly
available. Adapt all other programs to use it and display version information
in the help screen.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-03 19:31:10 -05:00
Stefan Berger
a7bd0ebffc swtpm: poll for HUP as well
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-12-03 09:15:59 -05:00
Stefan Berger
8a68446e73 swtpm_setup: enable help screen for normal users
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-29 17:05:22 -05:00
Stefan Berger
a3c8e71a1d swtpm: fix some coverity errors
Fix some errors raised by Coverity.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-29 01:48:13 -05:00
Stefan Berger
6852f6c89b swtpm: introduce control channel for chardev TPM
Implement a control channel for the 'chardev' swtpm that implements
a minimal set of control messages for now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-27 22:13:37 -05:00
Stefan Berger
7a00ba8b7c swtpm: Fix typo in error message
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-27 22:13:36 -05:00
Stefan Berger
1bebb6be04 swtpm: consoldiate code
Consolidate common code.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-27 17:58:32 -05:00
Stefan Berger
c8ba316097 swtpm: fix TPM_DEBUG define
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-27 10:25:17 -05:00
Stefan Berger
12ef7d4e47 swtpm chardev: remove not supported command line option
Remove a not supported command line option from the help screen of
'swtpm chardev'.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-27 10:24:00 -05:00
Stefan Berger
e47bd065ff swtpm: remove pidfile after process exits
Remove the pidfile once swtpm process exits.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-15 13:55:06 -05:00
Stefan Berger
29cfd0a4fd swtpm: add support for listening on chardev
Add support for 'swtpm chardev' that listens for TPM commands on a given
character device and sends responses through it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-08 14:13:23 -05:00
Stefan Berger
27a3c23967 swtpm: make all possible variables static
Some of the variables in swtpm.c were not static, fix this.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-08 13:46:17 -05:00
Stefan Berger
c4ac0a11e9 build: remove hardcoded tss user and group
Remove the hardcodes tss user and group and to configure with
--with-tss-user=tss --with-tss-group=tss to set the tss user
and group to be used.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-11-02 20:47:37 -05:00
Stefan Berger
118cc15230 swtpm: Check for existing device
Check for an existing device with the same name and print an error
if the device already exists.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-10-29 11:00:56 -04:00
Stefan Berger
6e710866f3 swtpm: report missing TPM state path
Report missing TPM state path as soon as possible.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-10-29 10:48:30 -04:00
Stefan Berger
bc525ccdab swtpm: Add support for --tpmstate dir=<dir> command line parameter
Add support for the --tpmstate dir=<dir> command line parameter.
It will be used instead of the TPM_PATH, unless it is not set.

Adapt two test cases for the new parameter.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-10-27 21:58:10 -04:00
Stefan Berger
b215173767 swtpm: Add command line parameter for pidfile
Add support for --pid file=<pidfile> command line parameter support.
The swtpm_cuse and swtpm now write their process IDs (pids) into
a file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-10-26 06:34:14 -04:00
Stefan Berger
7d4b4514a3 build: enable RPM building for non-root users
Disable the chown commands when building an RPM; we try to detect this
by the usage of DESTDIR.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-10-16 19:08:43 -04:00
Stefan Berger
373a9be985 Some more changes to the ioctl's
Some more changes to tpm_ioctl.h including
- comment for request and response part of an ioctl
- unified format
- prefix all constants with PTM_

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-10-03 18:41:33 -04:00
Stefan Berger
8e45d3e25e swtpm_cert: remove unnecessary file
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-07-02 18:05:17 -04:00
Stefan Berger
84d2e89a74 swtpm_setup: remove PATH extension to local dir
Remove the extension of PATH to the local dir('.') from swtpm_setup.sh
and adapt test cases accordingly.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-07-02 10:50:05 -04:00
Stefan Berger
4f185f6e45 swtpm_setup: cleanup
Cleanup the code a bit:
 o added description to several functions
 o remove empty lines between functions
 o cleanup the usage screen
 o fix the parameters to logerr

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-07-01 21:01:59 -04:00
Stefan Berger
a209a01816 swtpm_cuse: be more consistent with input buffer size checks
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-06-23 14:04:59 -04:00
Stefan Berger
ff1a99d7e6 swtpm: receiving of TPM state blob ends once last byte has been copied
The receiving of TPM state blob ends when the last byte has been copied
into a response to the user. No more request need to be sent afterwards.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-06-05 16:28:09 -04:00
Stefan Berger
c896156107 swtpm: delete blob file if set blob has length 0
If a blob with length 0 is set, we make sure the corresponding file
that would hold this blob is not available.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-06-05 16:25:33 -04:00
Stefan Berger
05cd79b843 Support read()/write() for TPM state blob transfer
Support the read/write interface and POSIX API calls for transfer of
TPM state blobs.

Extend the swtpm_ioctl program to support this as well. Use the
environment variable SWTPM_IOCTL_BUFFERSIZE to set the size of the
buffer to use and enable the read/write interface in this (test)
program.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-06-04 18:49:25 -04:00
Stefan Berger
5e60c24f40 remove the tpm_number from the public interface
Remove the tpm_number from the public interface (while we still can do that)

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-28 12:55:30 -04:00
Stefan Berger
31380fe68e tpm_ioctl: Remove _t from the types
Since POSIX reserves the *_t namespace of types, remove it from
all our typedefs. While doing that, adjust the typedefs to all have
the prefix ptm_ .

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-28 12:55:30 -04:00
Stefan Berger
857daa32b9 tpm_ioctl: convert blob type to 32 bit int
Convert the blob type to 32bit int (while we still can do that ... )

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-28 12:55:30 -04:00
Stefan Berger
8f3b270ab0 swtpm: move code to set state blob into own function
Move the code that sets the TPM's state blob into its own function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-28 12:55:30 -04:00
Stefan Berger
22fda83bf9 swtpm: move code to get the TPM state blobs into own function
Move the code to get the TPM state blobs into is own function and introduce
a caching layer that retrieves the state blob from the TPM once and has
subsequent requests to copy the state work on the cached blob.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-28 12:55:30 -04:00
Stefan Berger
ad976d1a2e Add copyright stanza where missing; update date
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-26 20:52:40 -04:00
Stefan Berger
bd98690a4a Add ioctl to get configuration flags about keys in use
Add an ioctl that lets an application retrieve which keys are in use by the
TPM, i.e., file encryption or migration key

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-26 07:30:38 -04:00
Stefan Berger
1680c41d9e swtpm: Add a command line option for a migration key
The migration key ensures that TPM state blobs, when retrieved using the
ioctl for getting state blobs, are always encrypted with this key.
When the state is later on loaded back into the TPM using the ioctl
to set the state blobs, the migration key is used to decrypt them.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-25 11:18:44 -04:00
Stefan Berger
082533af22 swtpm: Have crypto functions use a key as parameter
Have the crypto functions use a key as a parameter rather than having them
operate on a specific fixed key.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-25 11:12:23 -04:00
Stefan Berger
81264f7356 swtpm: break apart key parsing function
Break the key parsing function apart into a common parsing function
and one specific to the file encryption key.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-25 11:12:23 -04:00
Stefan Berger
bed4894cd7 swtpm: prepend a header in front of all blobs retrieved from the TPM
Prepend a header in front of all blobs retrieved from the TPM.
Write flags into this header indicating whether the blob is
encrypted.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-25 11:12:23 -04:00
Stefan Berger
b902468900 swtpm: integrity protect the encrypt TPM state
Integrity protect the TPM state when it is written in entrypted form.
libtpms state (for TPM1.2) is also integrity protecting the blobs, but
we better determine the integrity of the decrypted data on the layer
above it.
2015-05-19 16:35:08 -04:00
Stefan Berger
fdbc203585 swtpm: more precise error message if setuid doesn't work
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-16 17:59:39 -04:00
Stefan Berger
af0ef0205a swtpm: assign value to saveptr used in strtok_r
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:59:16 -04:00
Stefan Berger
c6ba40fc53 swtpm: Ignore the return value of a write op before closing connection
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:54:45 -04:00
Stefan Berger
0a7e8d236d swtpm_setup: Annotate that we pass argv to execv intentionately
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:51:16 -04:00
Stefan Berger
74e53a6268 swtpm: No need to compare locality with negative values
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:48:20 -04:00
Stefan Berger
0268ef45d2 swtpm: change type of len from size_t to ssize_t
Change the type of the len variable from size_t to ssize_t for
comparison against neg. values to work.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:48:20 -04:00
Stefan Berger
414e0e8960 swtpm_ioclt: no need to compare locality with values < 0
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:48:11 -04:00
Stefan Berger
38a9453322 swtpm_cert: change variable type from unsigned char to char
Change variable type of val1 and val2 from unsigned char to char for
the comparison with neg. numbers to work.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:24:27 -04:00
Stefan Berger
3df8cbf91b swtpm_cuse: no need to compare uint8_t locality with < 0.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:20:16 -04:00
Stefan Berger
da521f048b swtpm: replace size_t with ssize_t for variable taking read() return value
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:18:23 -04:00
Stefan Berger
fddbb58d48 swtpm: Check file descriptor >= 0 before closing
Check the file descriptor for >= 0 before closing it. Hopefully
this makes Coverity happy.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:09:05 -04:00
Stefan Berger
9e89ffa12d swtpm_bios: Remove UNIXIO socket related code since not used
We do not support UNIXIO sockets for communicatin with the swtpm
yet, so remove this.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-12 14:04:03 -04:00
Stefan Berger
e387a34eab swtpm_ioctl: Move code for loading TPM stateblobs to own function
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-11 06:42:27 -04:00
Stefan Berger
eafb7054d8 swtpm_ioctl: Move code for saving TPM stateblobs to own function
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-11 06:41:42 -04:00
Stefan Berger
5ef047fedf swtpm_ioctl: move hashing code into own function
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-10 10:28:57 -04:00
Stefan Berger
6b7aefa9c2 swtpm: cleanup and commented ptm_ioctl
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-09 08:44:11 -04:00
Stefan Berger
6d7d0dd5e6 swtpm_ioctl: source formatting
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-09 08:41:04 -04:00
Stefan Berger
cdbfb7be1a swtpm_setup: Print error in case 'eval' fails on file permissions etc.
Also have the log function print out all parameters.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-04 01:27:48 -04:00
Stefan Berger
798694516e swtpm_setup: fix variable name typo
Fix a typo in a variable name.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-05-04 02:58:17 -04:00
Stefan Berger
58548ac677 swtpm: document some more code
Add documentation to the include file and some functions in  the source
code files.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>jo
2015-03-30 10:06:49 -04:00
Stefan Berger
337247ef6c swtpm: add documentation to options source code
Add documentation to the options source code and introduce an explicit
default value to return in case an option was not found while parsing.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-03-30 07:24:08 -04:00
Stefan Berger
292fc83f3e swtpm_cuse: automatically remove volatile state after retireval
Automatically remove the volatile state file after retrieval.
2015-03-19 15:44:22 -04:00
Stefan Berger
950040f03c swtpm_cuse: implement STOP ioctl
Implement a STOP ioctl in the swtpm and swtpm_ioctl client.
Modify test cases to used swtpm_ioctl --stop.
2015-03-16 11:50:03 -04:00
Stefan Berger
33e241b562 swtpm_ioctl: if blob cannot be found TPM_NON_FATAL is returned
It's not a fatal error if a blob is not returned and the CUSE TPM replies
with TPM_NON_FATAL error code.
2015-03-16 11:19:44 -04:00
Stefan Berger
c552bcdca3 swtpm_setup: reuse existing function to stop processes 2015-03-16 11:14:53 -04:00
Stefan Berger
36a7d09481 swtpm_setup: check swtpm port
Also check the port of the swtpm before proceeding.
Fix a typo in the code.
2015-03-14 20:43:10 -04:00
Stefan Berger
ba3535aa9c swtpm_setup: remove debugging code 2015-03-13 14:52:11 -04:00
Stefan Berger
3e5085efff swtpm_setup: Test connection with tcsd
On rare occassions TCSD refuses connections after start and nothing
works; so we test the connection with TCSD and kill it if it doesn't
work.

This now seems to fix the tests/test_parameters that occosionally
had been reporting an error.
2015-03-13 12:35:59 -04:00
Stefan Berger
f55b697663 Only allow a single command per TCP connection to be sent
Only allow a single command per TCP connection to be sent to
the socket TPM. This solves a problem with the test_parameters
testcase where the TPM seems to get stuck in the poll().
However, the testcase still is not entirely error-free.
2015-03-12 21:45:34 -04:00
Stefan Berger
bba74db294 Only list LISTEN sockets when checking on tcsd
Only list LISTEN sockets when checking whether tcsd has started
listening on a socket, yet.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-03-12 14:21:59 -04:00
Stefan Berger
198ebab3c1 Add new ioctls for getting and setting state blobs
Add new ioctls to get and set the 3 different types of state blobs
from and to the CUSE TPM. Add test cases for testing the new ioctl's
on a CUSE TPM that stores the state encrypted and on a CUSE TPM that
stores it non-encrypted.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-03-12 09:32:28 -04:00
Stefan Berger
5fd9856094 Show error message when not installing as root
Only root can change the ownership of swtpm_setup.sh to tss:tss, so
only root can install the file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-02-20 18:44:47 -05:00
Stefan Berger
f97114cc4c Fix build on RHEL6 where we need -lgthread-2.0
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-01-30 18:16:09 -05:00
Stefan Berger
ca84b6cde7 Allocate TPM command buffer on heap rather than on the stack
Allocate the TPM command buffer on the heap. Previously it was
allocated on the stack.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-01-30 17:56:26 -05:00
Stefan Berger
a84f2372ba Change void * to concrete structure.
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-01-30 17:29:54 -05:00
Stefan Berger
e6085e9615 Add some hardening flags to compiler and linker
Protect the stack, create position indep. executables, use Relocation
Read-Only (RELRO) and have the linker resolve all symbols upon
program start.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-01-30 17:08:40 -05:00
Stefan Berger
410683fa05 Remove unused wrapper tcsd-launcher.c
Remove the unused wrapper program tcsd-launcher.c.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-01-19 14:47:35 -05:00
Stefan Berger
ec37bb56cb Make SELinux policy extension support chooseable
Extend configure.ac to make SELinux policy extension support
chooseable. By default configure will check whether SELinux
support is installed on the local system and will add SELinux
policy extension support if support is found.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2014-12-19 09:28:47 -05:00
Stefan Berger
3bbdd7bc76 Support for openssl
Also support swtpm using OpenSSL library. 
Introduce --with-openssl in configure.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2014-12-18 22:19:57 -05:00
Stefan Berger
ba2f0af638 Enable building of rpms on RHEL 7
Some tweaks to enable building of RPMs on RHEL 7.
2014-12-09 20:37:27 -05:00
Stefan Berger
09c58b7003 Make compileable on RHEL 7 for ppc64
There are some tiny adjustments needed for linking on RHEL 7 for ppc64.
Otherwise it works there now as well.
2014-12-09 20:10:00 -05:00
Stefan Berger
baecda4040 Link programs with minimal set of libraries
Don't build up a global LIBS variable but put the libraries into
individual variables that can be used for linking individual programs
with. Do the same for CFLAGS.
2014-12-09 19:59:27 -05:00
Stefan Berger
0321a3808d Add ioctl to reset the establishment bit
Add an ioctl to reset the establishment bit. It takes as an
argument the locality to use.
2014-12-08 11:35:16 -05:00
Stefan Berger
6e93fdef0f add new README files for the tools and modify main README file 2014-12-05 15:11:15 -05:00
Stefan Berger
e46a2b6686 merging swtpm-tools into this project 2014-12-05 13:43:21 -05:00
Stefan Berger
6fc8fb9f4c initialize errno to 0 before strtoul call 2014-12-05 12:43:45 -05:00
Stefan Berger
f163b20210 initial check-in 2014-12-05 11:16:03 -05:00