Commit Graph

1523 Commits

Author SHA1 Message Date
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
03e5abef60 tests: Skip CUSE tests if not compiled with CUSE interface
Check for a '#define WITH_CUSE 1' line in config.h to determine whether
the swtpm was compiled with the CUSE interface and skip the tests with
the CUSE interface if no such line can be found.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-11 10:35:14 -04:00
Stefan Berger
c85b2cc35f test: Add PKG_CONFIG_PATH in front of configure for i386
More recent glib-2.0 needs a specific different include files for
32 and 64 bit x86 architectures. We get this through pkg-config but
need to set its search path accordingly.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-04 16:11:24 -04:00
Stefan Berger
142a2974ae tests: Poll for 1 second after PID file was found to be gone
Poll for process to be gone for 1 seconds after a shutdown was requested
and it was found that the PID file had been removed.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-04 16:10:27 -04:00
Stefan Berger
00ae0d2c40 swtpm_ioctl: add padding bytes for 32 bit architectures
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-04 15:40:33 -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
2fb204666a samples: remove the TPM attribute parameters from the options file
Since swtpm_setup now uses the swtpm_ioctl tool to get some of the
TPM attributes directly from the TPM, we don't need to pass these
options via the options file anymore.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-05 01:09:46 -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
029e1bd05a tests: wait for 0.5 seconds before swtpm must be gone
To avoid test failures in test_ctrchannel2 due to the swtpm process
still running after it has removed the PID file, give it 0.5 seconds
to actually terminate.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-05-04 13:45:21 -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
f6accfb869 sample: propagate and log error if swtpm_cert is missing
If the swtpm_cert was missing, nothing was reported in the error log. Change
this and report it in the error log rather than writing the error in the
certificate file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-23 11:58:59 -04:00
Stefan Berger
f0a22e6e32 tests: set PATH so swtpm_cert can be found
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-23 11:58:59 -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
ab37e6f383 samples: implement options for pass TPM spec parameters
Implement options --tpm-spec-family, --tpm-spec-revision, and
tpm-spec-level to pass to swtpm_cert for EK creation.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-23 10:00:47 -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
d40700020b tests: source common rather than test_common 2018-04-23 09:56:40 -04:00
Stefan Berger
026a2efe66 man: add an example to swtpm_setup man page
Add an example for how to run swtpm_setup to simulate TPM 1.2
manufacturing.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-18 14:53:55 -04:00
Stefan Berger
4713f2996a samples: Error out if key exists but is not readable for user
If the key is not readable as the current user, such as tss:tss,
but it is there, we don't try to create it but error out.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-18 14:53:55 -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
a8667992e0 tests: Use a root CA for creating the issuercert for test_swtpm_cert
Update the test case test_swtpm_cert to have its issuercert signed
by a created root CA so that we have the Authority Key Id in the cert.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-17 10:52:35 -04:00
Stefan Berger
373a90840c samples: Create a root CA that signs the cert used for creating TPM certs
We are currently missing the Authority Key Id in the certificate used for
creating the EK cert. To get this, we create a root CA for our local CA
and use that root CA to sign the local CA's certificate. Our local
CA is now an intermediate CA and the Authority Key Id can now be copied
into the EK cert.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
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
8740ec5765 samples: Use the --add-header option for TPM 1.2
Use the --add-header option when writing a cert for a TPM 1.2

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-12 13:20:21 -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
929a112936 rpm build: Update SELinux policy files for swtpm and swtpm_cuse
swtpm use swtpm.pp and swtpm_svirt.pp. swtpm_cuse only uses
swtpm_cuse.pp now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-04-09 15:08:52 -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