2013-06-26 09:45:06 +08:00
|
|
|
#
|
2013-10-28 04:59:46 +08:00
|
|
|
# Copyright 2011, 2013 Red Hat, Inc.
|
2013-10-28 04:59:47 +08:00
|
|
|
# Copyright 2013 IBM Corporation
|
2013-06-26 09:45:06 +08:00
|
|
|
#
|
2018-04-04 21:35:41 +08:00
|
|
|
# This work is licensed under the GNU GPLv2 or later.
|
2018-03-21 03:00:02 +08:00
|
|
|
# See the COPYING file in the top-level directory.
|
2013-06-26 09:45:06 +08:00
|
|
|
|
2018-03-21 00:18:35 +08:00
|
|
|
from .device import Device
|
2022-02-04 05:33:08 +08:00
|
|
|
from ..xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty
|
|
|
|
|
|
|
|
|
|
|
|
class _ActivePCRBanks(XMLBuilder):
|
|
|
|
XML_NAME = "active_pcr_banks"
|
|
|
|
|
|
|
|
sha1 = XMLProperty("./sha1", is_bool=True)
|
|
|
|
sha256 = XMLProperty("./sha256", is_bool=True)
|
|
|
|
sha384 = XMLProperty("./sha384", is_bool=True)
|
|
|
|
sha512 = XMLProperty("./sha512", is_bool=True)
|
2013-06-26 09:45:06 +08:00
|
|
|
|
|
|
|
|
2018-03-21 00:18:35 +08:00
|
|
|
class DeviceTpm(Device):
|
2018-03-21 22:53:34 +08:00
|
|
|
XML_NAME = "tpm"
|
2013-06-26 09:45:06 +08:00
|
|
|
|
2018-06-09 05:42:41 +08:00
|
|
|
VERSION_1_2 = "1.2"
|
|
|
|
VERSION_2_0 = "2.0"
|
|
|
|
VERSIONS = [VERSION_1_2, VERSION_2_0]
|
|
|
|
|
2013-07-16 00:18:23 +08:00
|
|
|
TYPE_PASSTHROUGH = "passthrough"
|
2018-06-09 05:42:41 +08:00
|
|
|
TYPE_EMULATOR = "emulator"
|
|
|
|
TYPES = [TYPE_PASSTHROUGH, TYPE_EMULATOR]
|
2013-06-26 09:45:06 +08:00
|
|
|
|
2013-07-16 00:18:23 +08:00
|
|
|
MODEL_TIS = "tpm-tis"
|
2018-06-09 05:42:40 +08:00
|
|
|
MODEL_CRB = "tpm-crb"
|
2018-06-09 02:24:42 +08:00
|
|
|
MODEL_SPAPR = "tpm-spapr"
|
|
|
|
MODELS = [MODEL_TIS, MODEL_CRB, MODEL_SPAPR]
|
2013-06-26 09:45:06 +08:00
|
|
|
|
2018-09-02 05:50:31 +08:00
|
|
|
type = XMLProperty("./backend/@type")
|
|
|
|
version = XMLProperty("./backend/@version")
|
|
|
|
model = XMLProperty("./@model")
|
|
|
|
device_path = XMLProperty("./backend/device/@path")
|
2019-09-04 20:29:58 +08:00
|
|
|
encryption_secret = XMLProperty("./backend/encryption/@secret")
|
2021-01-25 07:53:22 +08:00
|
|
|
persistent_state = XMLProperty(
|
|
|
|
"./backend/@persistent_state", is_yesno=True)
|
2018-06-09 05:42:41 +08:00
|
|
|
|
2022-02-04 05:33:08 +08:00
|
|
|
active_pcr_banks = XMLChildProperty(_ActivePCRBanks, is_single=True)
|
|
|
|
|
2018-06-09 05:42:41 +08:00
|
|
|
|
2018-09-02 05:50:31 +08:00
|
|
|
##################
|
|
|
|
# Default config #
|
|
|
|
##################
|
2018-06-09 05:42:41 +08:00
|
|
|
|
2022-02-18 03:51:04 +08:00
|
|
|
@staticmethod
|
|
|
|
def default_model(guest):
|
|
|
|
domcaps = guest.lookup_domcaps()
|
|
|
|
|
|
|
|
if not domcaps.devices.tpm.present and not guest.os.is_pseries():
|
|
|
|
# Preserve the old default when domcaps is old
|
|
|
|
return DeviceTpm.MODEL_CRB
|
|
|
|
if domcaps.devices.tpm.get_enum("model").has_value(DeviceTpm.MODEL_CRB):
|
|
|
|
# CRB is the modern version, and it implies version 2.0
|
|
|
|
return DeviceTpm.MODEL_CRB
|
|
|
|
|
|
|
|
# Let libvirt decide so we don't need to duplicate its arch logic
|
|
|
|
return None
|
|
|
|
|
2018-09-02 05:50:31 +08:00
|
|
|
def set_defaults(self, guest):
|
2022-02-18 03:51:04 +08:00
|
|
|
if self.device_path and not self.type:
|
2018-09-02 05:50:31 +08:00
|
|
|
self.type = self.TYPE_PASSTHROUGH
|
2022-02-18 03:51:04 +08:00
|
|
|
if not self.type:
|
|
|
|
# Libvirt requires a backend type to be specified. 'emulator'
|
|
|
|
# may not be available if swtpm is not installed, but trying to
|
|
|
|
# fallback to 'passthrough' in that case isn't really workable.
|
|
|
|
# Instead we specify it unconditionally and let libvirt error.
|
|
|
|
self.type = self.TYPE_EMULATOR
|
2020-06-03 21:14:36 +08:00
|
|
|
|
2022-02-18 03:51:04 +08:00
|
|
|
# passthrough and model and version are all interconnected, so
|
|
|
|
# don't try to set a default model if other bits are set
|
|
|
|
if (self.type == self.TYPE_EMULATOR and
|
|
|
|
not self.model and not self.version):
|
|
|
|
self.model = self.default_model(guest)
|