mirror of
https://github.com/utmapp/swtpm.git
synced 2026-12-01 07:53:17 -10:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce16c32b1a | ||
|
|
28f4893a1d |
No files matched your search
+5
-1
@@ -7,9 +7,13 @@
|
||||
SUBDIRS = \
|
||||
include \
|
||||
man \
|
||||
src
|
||||
|
||||
if !SHARED_LIBRARY_BUILD
|
||||
SUBDIRS += \
|
||||
samples \
|
||||
src \
|
||||
tests
|
||||
endif
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
|
||||
+64
-48
@@ -168,11 +168,17 @@ openssl)
|
||||
;;
|
||||
esac
|
||||
|
||||
LIBTASN1_LIBS=$(pkg-config --libs libtasn1)
|
||||
if test $? -ne 0; then
|
||||
AC_MSG_ERROR("Is libtasn1-devel installed? -- could not get libs for libtasn1")
|
||||
AC_ARG_ENABLE([shared-lib],
|
||||
AS_HELP_STRING([--enable-shared-lib], [Build as a shared library]))
|
||||
AM_CONDITIONAL([SHARED_LIBRARY_BUILD], [test "x$enable_shared_lib" = "xyes"])
|
||||
|
||||
if test "x$enable_shared_lib" != "xyes"; then
|
||||
LIBTASN1_LIBS=$(pkg-config --libs libtasn1)
|
||||
if test $? -ne 0; then
|
||||
AC_MSG_ERROR("Is libtasn1-devel installed? -- could not get libs for libtasn1")
|
||||
fi
|
||||
AC_SUBST([LIBTASN1_LIBS])
|
||||
fi
|
||||
AC_SUBST([LIBTASN1_LIBS])
|
||||
|
||||
PKG_CHECK_MODULES(
|
||||
[LIBTPMS],
|
||||
@@ -196,13 +202,15 @@ else
|
||||
fi
|
||||
AM_CONDITIONAL([HAVE_TCSD], test "$have_tcsd" != "no")
|
||||
|
||||
dnl We either need netstat (more common across systems) or 'ss' for test cases
|
||||
AC_PATH_PROG([NETSTAT], [netstat])
|
||||
if test "x$NETSTAT" = "x"; then
|
||||
AC_PATH_PROG([SS], [ss])
|
||||
if test "x$SS" = "x"; then
|
||||
AC_MSG_ERROR(['netstat' and 'ss' tools are missing for tests: net-tools OR iproute/iproute2 package])
|
||||
fi
|
||||
if test "x$enable_shared_lib" != "xyes"; then
|
||||
dnl We either need netstat (more common across systems) or 'ss' for test cases
|
||||
AC_PATH_PROG([NETSTAT], [netstat])
|
||||
if test "x$NETSTAT" = "x"; then
|
||||
AC_PATH_PROG([SS], [ss])
|
||||
if test "x$SS" = "x"; then
|
||||
AC_MSG_ERROR(['netstat' and 'ss' tools are missing for tests: net-tools OR iproute/iproute2 package])
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([for whether to build with CUSE interface])
|
||||
@@ -245,17 +253,19 @@ fi
|
||||
AM_CONDITIONAL([WITH_CUSE],[test "$with_cuse" = "yes"])
|
||||
AC_MSG_RESULT($with_cuse)
|
||||
|
||||
JSON_GLIB_CFLAGS=$(pkg-config --cflags json-glib-1.0)
|
||||
if test $? -ne 0; then
|
||||
AC_MSG_ERROR("Is libjson-glib-dev/json-glib-devel installed? -- could not get cflags")
|
||||
fi
|
||||
AC_SUBST([JSON_GLIB_CFLAGS])
|
||||
if test "x$enable_shared_lib" != "xyes"; then
|
||||
JSON_GLIB_CFLAGS=$(pkg-config --cflags json-glib-1.0)
|
||||
if test $? -ne 0; then
|
||||
AC_MSG_ERROR("Is libjson-glib-dev/json-glib-devel installed? -- could not get cflags")
|
||||
fi
|
||||
AC_SUBST([JSON_GLIB_CFLAGS])
|
||||
|
||||
JSON_GLIB_LIBS=$(pkg-config --libs json-glib-1.0)
|
||||
if test $? -ne 0; then
|
||||
AC_MSG_ERROR("Is libjson-glib-dev/json-glib-devel installed? -- could not get libs")
|
||||
JSON_GLIB_LIBS=$(pkg-config --libs json-glib-1.0)
|
||||
if test $? -ne 0; then
|
||||
AC_MSG_ERROR("Is libjson-glib-dev/json-glib-devel installed? -- could not get libs")
|
||||
fi
|
||||
AC_SUBST([JSON_GLIB_LIBS])
|
||||
fi
|
||||
AC_SUBST([JSON_GLIB_LIBS])
|
||||
|
||||
GLIB_CFLAGS=$(pkg-config --cflags glib-2.0)
|
||||
if test $? -ne 0; then
|
||||
@@ -380,32 +390,34 @@ AS_IF([test "x$enable_default_pcr_banks" != "x"],[
|
||||
pcr_bank_checks
|
||||
AC_SUBST([DEFAULT_PCR_BANKS])
|
||||
|
||||
AC_PATH_PROG([EXPECT], expect)
|
||||
if test "x$EXPECT" = "x"; then
|
||||
AC_MSG_ERROR([expect is required: expect package])
|
||||
fi
|
||||
if test "x$enable_shared_lib" != "xyes"; then
|
||||
AC_PATH_PROG([EXPECT], expect)
|
||||
if test "x$EXPECT" = "x"; then
|
||||
AC_MSG_ERROR([expect is required: expect package])
|
||||
fi
|
||||
|
||||
AC_PATH_PROG([GAWK], gawk)
|
||||
if test "x$GAWK" = "x"; then
|
||||
AC_MSG_ERROR([gawk is required: gawk package])
|
||||
fi
|
||||
AC_PATH_PROG([GAWK], gawk)
|
||||
if test "x$GAWK" = "x"; then
|
||||
AC_MSG_ERROR([gawk is required: gawk package])
|
||||
fi
|
||||
|
||||
AC_PATH_PROG([SOCAT], socat)
|
||||
if test "x$SOCAT" = "x"; then
|
||||
AC_MSG_ERROR([socat is required: socat package])
|
||||
fi
|
||||
AC_PATH_PROG([SOCAT], socat)
|
||||
if test "x$SOCAT" = "x"; then
|
||||
AC_MSG_ERROR([socat is required: socat package])
|
||||
fi
|
||||
|
||||
AC_PATH_PROG([BASE64], base64)
|
||||
if test "x$BASE64" = "x"; then
|
||||
AC_MSG_ERROR([base64 is required: base64 package])
|
||||
fi
|
||||
AC_PATH_PROG([BASE64], base64)
|
||||
if test "x$BASE64" = "x"; then
|
||||
AC_MSG_ERROR([base64 is required: base64 package])
|
||||
fi
|
||||
|
||||
AC_PATH_PROG([CP], cp)
|
||||
if test "x$CP" = "x"; then
|
||||
AC_MSG_ERROR([cp is required])
|
||||
fi
|
||||
AC_PATH_PROG([CP], cp)
|
||||
if test "x$CP" = "x"; then
|
||||
AC_MSG_ERROR([cp is required])
|
||||
fi
|
||||
|
||||
AM_PATH_PYTHON([3.3])
|
||||
AM_PATH_PYTHON([3.3])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE([hardening],
|
||||
AS_HELP_STRING([--disable-hardening], [Disable hardening flags]))
|
||||
@@ -595,25 +607,29 @@ AC_CONFIG_FILES([Makefile \
|
||||
src/selinux/swtpm.fc \
|
||||
src/selinux/swtpmcuse.fc \
|
||||
src/swtpm/Makefile \
|
||||
src/swtpm_bios/Makefile \
|
||||
src/swtpm_cert/Makefile \
|
||||
src/swtpm_ioctl/Makefile \
|
||||
src/swtpm_localca/Makefile \
|
||||
src/swtpm_setup/Makefile \
|
||||
src/utils/Makefile \
|
||||
src/utils/swtpm_conf.h \
|
||||
man/Makefile \
|
||||
man/man3/Makefile \
|
||||
man/man5/Makefile \
|
||||
man/man8/Makefile \
|
||||
tests/Makefile \
|
||||
tests/test_config \
|
||||
])
|
||||
AC_CONFIG_FILES([samples/swtpm-localca],
|
||||
[chmod 755 samples/swtpm-localca])
|
||||
if test "x$enable_shared_lib" != "xyes"; then
|
||||
AC_CONFIG_FILES([src/swtpm_bios/Makefile \
|
||||
src/swtpm_cert/Makefile \
|
||||
src/swtpm_ioctl/Makefile \
|
||||
src/swtpm_localca/Makefile \
|
||||
src/swtpm_setup/Makefile \
|
||||
tests/Makefile \
|
||||
tests/test_config \
|
||||
])
|
||||
fi
|
||||
AC_OUTPUT
|
||||
|
||||
echo
|
||||
printf "shared_lib : %5s\n" $enable_shared_lib
|
||||
printf "with_gnutls : %5s (no = swtpm_cert will NOT be built)\n" $with_gnutls
|
||||
printf "with_selinux : %5s (no = SELinux policy extensions will NOT be built)\n" $with_selinux
|
||||
printf "with_cuse : %5s (no = no CUSE interface)\n" $with_cuse
|
||||
|
||||
@@ -8,3 +8,10 @@ swtpmincludedir = $(includedir)/swtpm
|
||||
|
||||
swtpminclude_HEADERS = \
|
||||
tpm_ioctl.h
|
||||
|
||||
if SHARED_LIBRARY_BUILD
|
||||
|
||||
swtpminclude_HEADERS += \
|
||||
swtpm.h
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* swtpm.h
|
||||
*
|
||||
* (c) Copyright IBM Corporation 2023.
|
||||
*
|
||||
* This file is licensed under the terms of the 3-clause BSD license
|
||||
*/
|
||||
#ifndef _SWTPM_H_
|
||||
#define _SWTPM_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <libtpms/tpm_library.h>
|
||||
|
||||
struct swtpm_options {
|
||||
int sizeOfStruct;
|
||||
TPMLIB_TPMVersion tpmversion;
|
||||
const char *key;
|
||||
const char *migkey;
|
||||
const char *log;
|
||||
const char *pid;
|
||||
const char *locality;
|
||||
const char *tpmstate;
|
||||
const char *ctrlch;
|
||||
const char *server;
|
||||
const char *flags;
|
||||
const char *seccomp;
|
||||
const char *migration;
|
||||
};
|
||||
|
||||
int swtpm_start(struct swtpm_options *options);
|
||||
void swtpm_stop(void);
|
||||
|
||||
#endif /* _SWTPM_H_ */
|
||||
+5
-1
@@ -6,12 +6,16 @@
|
||||
|
||||
SUBDIRS = \
|
||||
utils \
|
||||
swtpm \
|
||||
swtpm
|
||||
|
||||
if !SHARED_LIBRARY_BUILD
|
||||
SUBDIRS += \
|
||||
swtpm_bios \
|
||||
swtpm_cert \
|
||||
swtpm_ioctl \
|
||||
swtpm_localca \
|
||||
swtpm_setup
|
||||
endif
|
||||
|
||||
if WITH_SELINUX
|
||||
SUBDIRS += \
|
||||
|
||||
@@ -34,9 +34,17 @@ noinst_HEADERS = \
|
||||
utils.h \
|
||||
vtpm_proxy.h
|
||||
|
||||
if SHARED_LIBRARY_BUILD
|
||||
|
||||
noinst_LTLIBRARIES = libswtpm_libtpms.la
|
||||
|
||||
else
|
||||
|
||||
privlibdir = $(libdir)/@PACKAGE@
|
||||
privlib_LTLIBRARIES = libswtpm_libtpms.la
|
||||
|
||||
endif
|
||||
|
||||
libswtpm_libtpms_la_SOURCES = \
|
||||
capabilities.c \
|
||||
common.c \
|
||||
@@ -88,6 +96,39 @@ libswtpm_libtpms_la_LIBADD = \
|
||||
$(LIBSECCOMP_LIBS) \
|
||||
$(LIBCRYPTO_LIBS)
|
||||
|
||||
if SHARED_LIBRARY_BUILD
|
||||
|
||||
lib_LTLIBRARIES = libswtpm.la
|
||||
|
||||
libswtpm_la_DEPENDENCIES = libswtpm_libtpms.la
|
||||
|
||||
libswtpm_la_SOURCES = \
|
||||
swtpm_library.c
|
||||
|
||||
libswtpm_la_CFLAGS = \
|
||||
-I$(top_builddir)/include \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/include/swtpm \
|
||||
-I$(top_srcdir)/src/utils \
|
||||
$(MY_CFLAGS) \
|
||||
$(HARDENING_CFLAGS) \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(LIBFUSE_CFLAGS)
|
||||
|
||||
libswtpm_la_LDFLAGS = \
|
||||
-Wl,-all_load \
|
||||
$(MY_LDFLAGS) \
|
||||
$(HARDENING_LDFLAGS)
|
||||
|
||||
libswtpm_la_LIBADD = \
|
||||
libswtpm_libtpms.la \
|
||||
$(LIBFUSE_LIBS) \
|
||||
$(GLIB_LIBS) \
|
||||
$(GTHREAD_LIBS) \
|
||||
$(LIBTPMS_LIBS)
|
||||
|
||||
else
|
||||
|
||||
bin_PROGRAMS = swtpm
|
||||
if WITH_CUSE
|
||||
bin_PROGRAMS += swtpm_cuse
|
||||
@@ -152,6 +193,8 @@ swtpm_cuse_LDADD = \
|
||||
$(GTHREAD_LIBS) \
|
||||
$(LIBTPMS_LIBS)
|
||||
|
||||
endif
|
||||
|
||||
AM_CPPFLAGS =
|
||||
LDADD = -ltpms
|
||||
|
||||
|
||||
+20
-20
@@ -286,7 +286,7 @@ static const OptionDesc migration_opt_desc[] = {
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
int
|
||||
handle_log_options(char *options)
|
||||
handle_log_options(const char *options)
|
||||
{
|
||||
char *error = NULL;
|
||||
const char *logfile = NULL, *logprefix = NULL;
|
||||
@@ -358,7 +358,7 @@ error:
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
static int
|
||||
parse_key_options(char *options, unsigned char *key, size_t maxkeylen,
|
||||
parse_key_options(const char *options, unsigned char *key, size_t maxkeylen,
|
||||
size_t *keylen, enum encryption_mode *encmode)
|
||||
{
|
||||
OptionValues *ovs = NULL;
|
||||
@@ -472,7 +472,7 @@ error:
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
int
|
||||
handle_key_options(char *options)
|
||||
handle_key_options(const char *options)
|
||||
{
|
||||
enum encryption_mode encmode = ENCRYPTION_MODE_UNKNOWN;
|
||||
unsigned char key[256/8];
|
||||
@@ -508,7 +508,7 @@ error:
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
int
|
||||
handle_migration_key_options(char *options)
|
||||
handle_migration_key_options(const char *options)
|
||||
{
|
||||
enum encryption_mode encmode = ENCRYPTION_MODE_UNKNOWN;
|
||||
unsigned char key[256/8];
|
||||
@@ -546,7 +546,7 @@ error:
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
static int
|
||||
parse_pid_options(char *options, char **pidfile, int *pidfilefd)
|
||||
parse_pid_options(const char *options, char **pidfile, int *pidfilefd)
|
||||
{
|
||||
OptionValues *ovs = NULL;
|
||||
char *error = NULL;
|
||||
@@ -604,7 +604,7 @@ error:
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
int
|
||||
handle_pid_options(char *options)
|
||||
handle_pid_options(const char *options)
|
||||
{
|
||||
char *pidfile = NULL;
|
||||
int pidfilefd = -1;
|
||||
@@ -638,7 +638,7 @@ handle_pid_options(char *options)
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
static int
|
||||
parse_tpmstate_options(char *options, char **tpmstatedir, mode_t *mode,
|
||||
parse_tpmstate_options(const char *options, char **tpmstatedir, mode_t *mode,
|
||||
char **tpmbackend_uri)
|
||||
{
|
||||
OptionValues *ovs = NULL;
|
||||
@@ -696,7 +696,7 @@ error:
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
int
|
||||
handle_tpmstate_options(char *options)
|
||||
handle_tpmstate_options(const char *options)
|
||||
{
|
||||
char *tpmstatedir = NULL;
|
||||
char *tpmbackend_uri = NULL;
|
||||
@@ -933,7 +933,7 @@ error:
|
||||
*
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
static int parse_ctrlchannel_options(char *options, struct ctrlchannel **cc,
|
||||
static int parse_ctrlchannel_options(const char *options, struct ctrlchannel **cc,
|
||||
uint32_t *mainloop_flags)
|
||||
{
|
||||
OptionValues *ovs = NULL;
|
||||
@@ -1058,7 +1058,7 @@ error:
|
||||
*
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
int handle_ctrlchannel_options(char *options, struct ctrlchannel **cc,
|
||||
int handle_ctrlchannel_options(const char *options, struct ctrlchannel **cc,
|
||||
uint32_t *mainloop_flag)
|
||||
{
|
||||
if (!options)
|
||||
@@ -1078,7 +1078,7 @@ int handle_ctrlchannel_options(char *options, struct ctrlchannel **cc,
|
||||
*
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
static int parse_server_options(char *options, struct server **c)
|
||||
static int parse_server_options(const char *options, struct server **c)
|
||||
{
|
||||
OptionValues *ovs = NULL;
|
||||
char *error = NULL;
|
||||
@@ -1201,7 +1201,7 @@ error:
|
||||
*
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
int handle_server_options(char *options, struct server **c)
|
||||
int handle_server_options(const char *options, struct server **c)
|
||||
{
|
||||
if (!options)
|
||||
return 0;
|
||||
@@ -1212,7 +1212,7 @@ int handle_server_options(char *options, struct server **c)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_locality_options(char *options, uint32_t *flags)
|
||||
static int parse_locality_options(const char *options, uint32_t *flags)
|
||||
{
|
||||
OptionValues *ovs = NULL;
|
||||
char *error = NULL;
|
||||
@@ -1247,7 +1247,7 @@ error:
|
||||
*
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
int handle_locality_options(char *options, uint32_t *flags)
|
||||
int handle_locality_options(const char *options, uint32_t *flags)
|
||||
{
|
||||
*flags = 0;
|
||||
|
||||
@@ -1260,7 +1260,7 @@ int handle_locality_options(char *options, uint32_t *flags)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_flags_options(char *options, bool *need_init_cmd,
|
||||
static int parse_flags_options(const char *options, bool *need_init_cmd,
|
||||
uint16_t *startupType, bool *disable_auto_shutdown)
|
||||
{
|
||||
OptionValues *ovs = NULL;
|
||||
@@ -1308,7 +1308,7 @@ error:
|
||||
*
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
int handle_flags_options(char *options, bool *need_init_cmd,
|
||||
int handle_flags_options(const char *options, bool *need_init_cmd,
|
||||
uint16_t *startupType, bool *disable_auto_shutdown)
|
||||
{
|
||||
if (!options)
|
||||
@@ -1322,7 +1322,7 @@ int handle_flags_options(char *options, bool *need_init_cmd,
|
||||
}
|
||||
|
||||
#ifdef WITH_SECCOMP
|
||||
static int parse_seccomp_options(char *options, unsigned int *seccomp_action)
|
||||
static int parse_seccomp_options(const char *options, unsigned int *seccomp_action)
|
||||
{
|
||||
OptionValues *ovs = NULL;
|
||||
char *error = NULL;
|
||||
@@ -1369,7 +1369,7 @@ error:
|
||||
*
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
int handle_seccomp_options(char *options, unsigned int *seccomp_action)
|
||||
int handle_seccomp_options(const char *options, unsigned int *seccomp_action)
|
||||
{
|
||||
*seccomp_action = SWTPM_SECCOMP_ACTION_KILL;
|
||||
|
||||
@@ -1383,7 +1383,7 @@ int handle_seccomp_options(char *options, unsigned int *seccomp_action)
|
||||
}
|
||||
#endif /* WITH_SECCOMP */
|
||||
|
||||
static int parse_migration_options(char *options, bool *incoming_migration,
|
||||
static int parse_migration_options(const char *options, bool *incoming_migration,
|
||||
bool *release_lock_outgoing)
|
||||
{
|
||||
OptionValues *ovs = NULL;
|
||||
@@ -1420,7 +1420,7 @@ error:
|
||||
*
|
||||
* Return 0 on success, -1 on failure.
|
||||
*/
|
||||
int handle_migration_options(char *options, bool *incoming_migration,
|
||||
int handle_migration_options(const char *options, bool *incoming_migration,
|
||||
bool *release_lock_outgoing)
|
||||
{
|
||||
*incoming_migration = false;
|
||||
|
||||
+12
-12
@@ -43,29 +43,29 @@
|
||||
|
||||
#include "compiler_dependencies.h"
|
||||
|
||||
int handle_log_options(char *options);
|
||||
int handle_key_options(char *options);
|
||||
int handle_migration_key_options(char *options);
|
||||
int handle_pid_options(char *options);
|
||||
int handle_tpmstate_options(char *options);
|
||||
int handle_log_options(const char *options);
|
||||
int handle_key_options(const char *options);
|
||||
int handle_migration_key_options(const char *options);
|
||||
int handle_pid_options(const char *options);
|
||||
int handle_tpmstate_options(const char *options);
|
||||
struct ctrlchannel;
|
||||
int handle_ctrlchannel_options(char *options, struct ctrlchannel **cc,
|
||||
int handle_ctrlchannel_options(const char *options, struct ctrlchannel **cc,
|
||||
uint32_t *mainloop_flag);
|
||||
struct server;
|
||||
int handle_server_options(char *options, struct server **s);
|
||||
int handle_locality_options(char *options, uint32_t *flags);
|
||||
int handle_flags_options(char *options, bool *need_init_cmd,
|
||||
int handle_server_options(const char *options, struct server **s);
|
||||
int handle_locality_options(const char *options, uint32_t *flags);
|
||||
int handle_flags_options(const char *options, bool *need_init_cmd,
|
||||
uint16_t *startupType, bool *disable_auto_shutdown);
|
||||
#ifdef WITH_SECCOMP
|
||||
int handle_seccomp_options(char *options, unsigned int *seccomp_action);
|
||||
int handle_seccomp_options(const char *options, unsigned int *seccomp_action);
|
||||
#else
|
||||
static inline int handle_seccomp_options(char *options SWTPM_ATTR_UNUSED,
|
||||
static inline int handle_seccomp_options(const char *options SWTPM_ATTR_UNUSED,
|
||||
unsigned int *seccomp_action SWTPM_ATTR_UNUSED)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
int handle_migration_options(char *options, bool *incoming_migration,
|
||||
int handle_migration_options(const char *options, bool *incoming_migration,
|
||||
bool *release_lock_outgoing);
|
||||
|
||||
#endif /* _SWTPM_COMMON_H_ */
|
||||
|
||||
+1
-1
@@ -205,7 +205,7 @@ option_value_add(OptionValues *ovs, const OptionDesc optdesc, const char *val,
|
||||
* Returns the parse options, types, and values in OptionValues.
|
||||
*/
|
||||
OptionValues *
|
||||
options_parse(char *opts, const OptionDesc optdesc[], char **error)
|
||||
options_parse(const char *opts, const OptionDesc optdesc[], char **error)
|
||||
{
|
||||
char *saveptr;
|
||||
char *tok;
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ typedef struct {
|
||||
.name = NULL, \
|
||||
}
|
||||
|
||||
OptionValues *options_parse(char *opts, const OptionDesc optdesc[],
|
||||
OptionValues *options_parse(const char *opts, const OptionDesc optdesc[],
|
||||
char **error);
|
||||
void option_values_free(OptionValues *ov);
|
||||
const char *option_get_string(OptionValues *ovs, const char *name,
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
/********************************************************************************/
|
||||
/* */
|
||||
/* TPM Main Program */
|
||||
/* Written by Ken Goldman, Stefan Berger */
|
||||
/* IBM Thomas J. Watson Research Center */
|
||||
/* */
|
||||
/* (c) Copyright IBM Corporation 2006, 2010, 2016, 2019. */
|
||||
/* */
|
||||
/* All rights reserved. */
|
||||
/* */
|
||||
/* Redistribution and use in source and binary forms, with or without */
|
||||
/* modification, are permitted provided that the following conditions are */
|
||||
/* met: */
|
||||
/* */
|
||||
/* Redistributions of source code must retain the above copyright notice, */
|
||||
/* this list of conditions and the following disclaimer. */
|
||||
/* */
|
||||
/* Redistributions in binary form must reproduce the above copyright */
|
||||
/* notice, this list of conditions and the following disclaimer in the */
|
||||
/* documentation and/or other materials provided with the distribution. */
|
||||
/* */
|
||||
/* Neither the names of the IBM Corporation nor the names of its */
|
||||
/* contributors may be used to endorse or promote products derived from */
|
||||
/* this software without specific prior written permission. */
|
||||
/* */
|
||||
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
|
||||
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
|
||||
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */
|
||||
/* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
|
||||
/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
|
||||
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */
|
||||
/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
|
||||
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */
|
||||
/* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
|
||||
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */
|
||||
/* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
||||
/********************************************************************************/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <getopt.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <libtpms/tpm_error.h>
|
||||
#include <libtpms/tpm_library.h>
|
||||
#include <libtpms/tpm_memory.h>
|
||||
#include <swtpm/swtpm.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "swtpm_debug.h"
|
||||
#include "swtpm_io.h"
|
||||
#include "swtpm_nvstore.h"
|
||||
#include "server.h"
|
||||
#include "common.h"
|
||||
#include "logging.h"
|
||||
#include "pidfile.h"
|
||||
#include "tpmlib.h"
|
||||
#include "utils.h"
|
||||
#include "mainloop.h"
|
||||
#include "ctrlchannel.h"
|
||||
#include "tpmstate.h"
|
||||
#include "sys_dependencies.h"
|
||||
#include "seccomp_profile.h"
|
||||
#include "options.h"
|
||||
|
||||
/* local variables */
|
||||
static int notify_fd[2] = {-1, -1};
|
||||
|
||||
static struct libtpms_callbacks callbacks = {
|
||||
.sizeOfStruct = sizeof(struct libtpms_callbacks),
|
||||
.tpm_nvram_init = SWTPM_NVRAM_Init,
|
||||
.tpm_nvram_loaddata = SWTPM_NVRAM_LoadData,
|
||||
.tpm_nvram_storedata = SWTPM_NVRAM_StoreData,
|
||||
.tpm_nvram_deletename = SWTPM_NVRAM_DeleteName,
|
||||
.tpm_io_init = SWTPM_IO_Init,
|
||||
.tpm_io_getlocality = mainloop_cb_get_locality,
|
||||
};
|
||||
|
||||
void swtpm_stop(void)
|
||||
{
|
||||
TPM_DEBUG("Terminating...\n");
|
||||
if (write(notify_fd[1], "T", 1) < 0) {
|
||||
logprintf(STDERR_FILENO, "Error: sigterm notification failed: %s\n",
|
||||
strerror(errno));
|
||||
}
|
||||
mainloop_terminate = true;
|
||||
}
|
||||
|
||||
static void swtpm_cleanup(struct ctrlchannel *cc, struct server *server)
|
||||
{
|
||||
pidfile_remove();
|
||||
ctrlchannel_free(cc);
|
||||
server_free(server);
|
||||
log_global_free();
|
||||
tpmstate_global_free();
|
||||
SWTPM_NVRAM_Shutdown();
|
||||
}
|
||||
|
||||
int swtpm_start(struct swtpm_options *options)
|
||||
{
|
||||
TPM_RESULT rc = 0;
|
||||
struct mainLoopParams mlp = {
|
||||
.cc = NULL,
|
||||
.flags = 0,
|
||||
.fd = -1,
|
||||
.locality_flags = 0,
|
||||
.tpmversion = TPMLIB_TPM_VERSION_1_2,
|
||||
.startupType = _TPM_ST_NONE,
|
||||
.lastCommand = TPM_ORDINAL_NONE,
|
||||
.disable_auto_shutdown = false,
|
||||
.incoming_migration = false,
|
||||
.storage_locked = false,
|
||||
};
|
||||
struct server *server = NULL;
|
||||
bool need_init_cmd = true;
|
||||
#ifdef DEBUG
|
||||
time_t start_time;
|
||||
#endif
|
||||
unsigned int seccomp_action;
|
||||
|
||||
if (!options || options->sizeOfStruct != sizeof(*options)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
mlp.tpmversion = options->tpmversion;
|
||||
|
||||
log_set_prefix("swtpm: ");
|
||||
|
||||
if (handle_log_options(options->log) < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (tpmlib_choose_tpm_version(mlp.tpmversion) != TPM_SUCCESS)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if (handle_ctrlchannel_options(options->ctrlch, &mlp.cc, &mlp.flags) < 0 ||
|
||||
handle_server_options(options->server, &server) < 0) {
|
||||
goto exit_failure;
|
||||
}
|
||||
|
||||
tpmstate_set_version(mlp.tpmversion);
|
||||
|
||||
if (handle_key_options(options->key) < 0 ||
|
||||
handle_migration_key_options(options->migkey) < 0 ||
|
||||
handle_pid_options(options->pid) < 0 ||
|
||||
handle_locality_options(options->locality, &mlp.locality_flags) < 0 ||
|
||||
handle_tpmstate_options(options->tpmstate) < 0 ||
|
||||
handle_seccomp_options(options->seccomp, &seccomp_action) < 0 ||
|
||||
handle_flags_options(options->flags, &need_init_cmd,
|
||||
&mlp.startupType, &mlp.disable_auto_shutdown) < 0 ||
|
||||
handle_migration_options(options->migration, &mlp.incoming_migration,
|
||||
&mlp.release_lock_outgoing) < 0) {
|
||||
goto exit_failure;
|
||||
}
|
||||
|
||||
if (server) {
|
||||
if (server_get_fd(server) >= 0) {
|
||||
mlp.fd = server_set_fd(server, -1);
|
||||
SWTPM_IO_SetSocketFD(mlp.fd);
|
||||
}
|
||||
|
||||
mlp.flags |= MAIN_LOOP_FLAG_KEEP_CONNECTION;
|
||||
if ((server_get_flags(server) & SERVER_FLAG_DISCONNECT))
|
||||
mlp.flags &= ~MAIN_LOOP_FLAG_KEEP_CONNECTION;
|
||||
|
||||
if ((server_get_flags(server) & SERVER_FLAG_FD_GIVEN))
|
||||
mlp.flags |= MAIN_LOOP_FLAG_TERMINATE | MAIN_LOOP_FLAG_USE_FD;
|
||||
}
|
||||
|
||||
if (pidfile_write(getpid()) < 0) {
|
||||
goto exit_failure;
|
||||
}
|
||||
|
||||
setvbuf(stdout, 0, _IONBF, 0); /* output may be going through pipe */
|
||||
|
||||
#ifdef DEBUG
|
||||
/* initialization */
|
||||
start_time = time(NULL);
|
||||
#endif
|
||||
|
||||
TPM_DEBUG("main: Initializing TPM at %s", ctime(&start_time));
|
||||
|
||||
tpmlib_debug_libtpms_parameters(mlp.tpmversion);
|
||||
|
||||
if ((rc = tpmlib_register_callbacks(&callbacks)))
|
||||
goto error_no_tpm;
|
||||
|
||||
if (!need_init_cmd) {
|
||||
mlp.storage_locked = !mlp.incoming_migration;
|
||||
|
||||
if ((rc = tpmlib_start(0, mlp.tpmversion, mlp.storage_locked)))
|
||||
goto error_no_tpm;
|
||||
tpm_running = true;
|
||||
}
|
||||
|
||||
if (pipe(notify_fd) < 0)
|
||||
goto error_no_pipe;
|
||||
|
||||
if (create_seccomp_profile(false, seccomp_action) < 0)
|
||||
goto error_seccomp_profile;
|
||||
|
||||
rc = mainLoop(&mlp, notify_fd[0]);
|
||||
|
||||
error_seccomp_profile:
|
||||
uninstall_sighandlers();
|
||||
|
||||
error_no_pipe:
|
||||
TPMLIB_Terminate();
|
||||
|
||||
error_no_tpm:
|
||||
close(notify_fd[0]);
|
||||
notify_fd[0] = -1;
|
||||
close(notify_fd[1]);
|
||||
notify_fd[1] = -1;
|
||||
|
||||
swtpm_cleanup(mlp.cc, server);
|
||||
|
||||
/* Fatal initialization errors cause the program to abort */
|
||||
if (rc == 0) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else {
|
||||
TPM_DEBUG("main: TPM initialization failure %08x, exiting\n", rc);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
exit_failure:
|
||||
swtpm_cleanup(mlp.cc, server);
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
Reference in new issue
Block a user