Commit Graph

745 Commits

Author SHA1 Message Date
Stefan Berger
b63000fa8d samples: set CERTTOOL to gnutls-certtool on OS/X
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 15:39:00 -04:00
Stefan Berger
f13d2a045c sample: wrap flock in flock_fd for support on OS/X
OS/X has a flock (v0.2.3) implementation using

brew tap discoteq/discoteq
brew install flock

The current version doesn't support -x as a parameter for
an exclusive lock but uses an exclusive lock when no parameter
is passed at all.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 15:27:25 -04:00
Stefan Berger
bd8f4cae3a swtpm_setup: Use env var '_' to get path of program on OS/X
OS/X also does not have a proc filesystem, so we use the '_'
environment variable to determine the path of the program.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 14:59:37 -04:00
Stefan Berger
af23737e6e swtpm: Work around deprecated daemon() on OS X
The daemon() call is deprecated on OS X. This patch works around it so
that we can compiled with -Wall -Werror and still can use the daemon()
call while avoiding compiler errors due to this function's deprecation
marking in stdlib.h.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 14:22:09 -04:00
Stefan Berger
c7d22cf60a swtpm: Remove unused mainloop parameter from functions
Remove the struct mainLoopParams type of parameter from functions
where it is not needed.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 12:38:08 -04:00
Stefan Berger
1294b307b5 swtpm: Fix typo in name of header guards
OS X compiler detected a typo in the name of the header guards.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 12:33:41 -04:00
Stefan Berger
2559aa9451 Move conditional includes into sys_dependencies.h
Move the OS specific conditional includes into sys_dependencies.h
while adding OS X support.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 11:48:10 -04:00
Stefan Berger
518a042cf7 build-sys: Use X="$X ..." rather than X+="..." in configure.ac
Some configure interpreters do not like X+='...' but need
X="$X ..." instead.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 17:44:21 +00:00
Stefan Berger
526bf3754e tests: Use --cs for swtpm_bios rather than ambiguous -cs
The -cs parameter to swtpm_bios is like -c -s and therefore ambiguous.
Use the unambiguous long version --cs. This makes the test case work
on NetBSD, which does not support getopt_long_only().

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 13:10:01 +00:00
Stefan Berger
df9eccd404 tests: Make test_ctrlchannel work on NetBSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 13:07:20 +00:00
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
44eac994b6 samples: use flock -x rather than flock -e
flock -e does not work on NetBSD, so replace it with flock -x,
which should work everywhere.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 13:01:40 +00:00
Stefan Berger
33be7be2a0 Replace tests with '==' through '='
On NetBSD configure.ac cannot have '==' in tests. So we have to replace
them with '='.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 12:59:29 +00:00
Stefan Berger
acdf48b0bd tests: Make test_ctrlchannel work on FreeBSD
To get /dev/ptmx on FreeBSD we need to run `kldload pty`.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 02:31:21 +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
2266da36d9 samples: create lock with name .lock.swtpm-localca rather than .lock
To avoid clashes with the lock files created by swtpm, have
swtpm-localca creata a lock file with the name .lock.swtpm-localca
so they can share directories if necessary.

This patch makes tests/test_tpm2_swtpm_setup_create_cert run on
OpenBSD since the swtpm and swtpm-localca then do not interfere
with the file locks. This doesn't seem to be an issue on Linux
or Cygwin, though, where probably the file locking is implemented
differently.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.om>
2018-08-26 16:03:53 -04:00
Stefan Berger
b096be2603 build-sys: explicitly adapt sysconfdir and datarootdir follow $prefix
When using --prefix=/usr never install into /etc/usr.
When using --prefix=/ never install into //share/.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-26 16:03:53 -04:00
Stefan Berger
571a8eed77 build-sys: Add GNUTLS_C/LDFLAGS to CFLAGS when checking for gnutls
On OpenBSD the gnutls library is in /usr/local/lib and AC_CHECK_LIB does
find it there without explicitly adding GNUTLS_CFLAGS and GNUTLS_LDFLAGS to
CFLAGS.

Also add the GNUTLS_CFLAGS to CFLAGS at the end.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-26 16:03:53 -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
da6ca6fab6 samples: OpenBSD scripting fixes
OpenBSD uses an older sed implementation that doesn't understand the
meaning of the '+' for getting one or multiple occurrences of a letter.
Work around this by not using it and trimming white spaces at the end
of a variable using bash.

Use 100 as file descriptor rather than 200 to accomodate OpenBSD,
which only support file descriptors <= 127.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-26 16:03:52 -04:00
Stefan Berger
f2458ef7d6 build-sys: Replace PKG_CHECK_VAR with direct call to $PKG_CONFIG
Older distros may not have PKG_CHECK_VAR due to usage of pkg-config
older than v0.28. So, replace the call to PKG_CHECK_VAR with a direct
call to $PKG_CONFIG. Also use PKG_PROG_PKG_CONFIG to determine the
location of pkg-config.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-24 17:08:05 -04:00
Stefan Berger
4f1912e8e8 tests: fix and enable test_tpm2_ctrlchannel2
test_tpm2_ctrlchannel2 was not active and was not complete. This
patch fixes the test case and activates it. It uses chardev, so
it needs to be gated by WITH_CHARDEV.

Signed-off-by: Stefran Berger <stefanb@linux.vnet.ibm.com>
2018-08-09 14:54: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
Stefan Berger
9df216134f rpmbuild: Make build work in Copr and revise spec file
Make the build work in Copr and take a first pass at
revising the spec file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-08 11:52:28 -04:00
Stefan Berger
dfd53161a7 buils-sys: Include autogen.sh in tarball and use for RPM build
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-08 10:29:19 -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
28c4645454 tests: Activate test case for swtpm-localca
With the SAN data in the certificate properly generated and accepted by
certtool, we can now activate the test case for swtpm-localca.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 14:22:12 -04:00
Stefan Berger
e92942a8b0 tests: quirk for Cygwin
On Cygwin the swtpm_setup executable is located in src/swtpm_setup/.libs
dir and we need to copy the swtpm_setup.sh file there as well.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -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
c50cb6cba9 tests: Run TPM 2 related swtpm_setup tests under less restrictions
Run TPM 2 related swtpm_setup tests under less restrictions.
For TPM 2 related tests only WITH_GNUTLS, which allows swtpm_cert
to be built, needs to be set since swtpm_setup is now being built
under all conditions.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
5d0136d07b tests: Remove root requirement for test_tpm2_swtpm_setup_create_cert
Remove the requirement to run the test_tpm2_swtpm_setup_create_cert
test with root rights. It's not necessary to run this as root.

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
dbb399de05 build-sys: Make sure python is installed for test cases
Some test cases need either python 2 or 3. Make sure it is installed.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-07 12:19:47 -04:00
Stefan Berger
5cd844d09e build-sys: require netstat to be available if swtpm_setup can be built
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