vtpm: TPM groups and deep quotes
v2 cover vtpm: TPM groups and deep quotes
This is an updated vTPM Manager domain which adds support for using the physical TPM to protect vTPM secrets according to its PCR values, and to allow virtual machines (including dom0) to attest to both the platform's state and to their own state.
Changes since v1:
- Move documentation for the vTPM and vTPM Manager to docs/
- Add patches from Jason Andryuk fixing support for Infineon TPMs
- Add example control tool scripts
[PATCH 1/7] vtpmmgr: add TPM group support
[PATCH 2/7] vtpmmgr: add example control tools [PATCH 3/7] vtpmmgr: Store hardware TPM Locality [PATCH 4/7] vtpmmgr: Convert TPM_Seal to use TPM_PCR_INFO_LONG [PATCH 5/7] vtpm: passthru requests to manager [PATCH 6/7] vtpm: add ordinal for obtaining an EK signature [PATCH 7/7] vtpm: add deep quote support
PATCH v2 1/7 vtpmmgr: add TPM group support
This is a complete rewrite of the disk format and key hierarchy for the TPM Manager. The new format supports multiple groups of vTPMs which define the permitted configurations where a given vTPM's keys are available, allowing upgrades of critical components while retaining the secrecy of cryptographic keys.
New features of the TPM Manager are explained in the README and in the definitions of the management commands in vtpm_manager.h.
New features for vTPMs:
1. The size of the state blob for a vTPM is expanded from 52 to 64 bytes in order to support future vTPMs using SHA-2/3 instead of SHA-1.
2. vTPMs can obtain a quote from the physical TPM with certain resettable PCRs set to include information about the vTPM. This can be used by a vTPM to provide evidence of its integrity, including the secrecy of its EK, and for deep quotes.
Some additional changes made by this rewrite that may impact existing users:
1. The value of WELLKNOWN_OWNER_AUTH was incorrect for the physical TPM; the convention is to use all zero bits for well-known authentication values, not all one bits.
2. Randomly generating the owner auth value for the physical TPM is no longer supported, as it prevents later creation or certification of AIKs (which the old manager did not support).
3. The vTPM Manager needs to be provisioned with a PCR composite and an upgrade authority's public key before it will save data across boots.
The current implementation still has some limitations:
* 5 valid system PCR selections per group
* The vTPM Manager's disk can use at most 2MB of space
* The vTPM domain's build hash is always set to null/zero
Most of the code relating to upgrade and rollback protection is currently stubbed out, but future versions can add:
* Support for using the TPM's monotonic counter to prevent rollback of vTPM data by taking and restoring disk snapshots
* Masking the master disk encryption key using a value stored in the TPM's NVRAM so that revocation of old data is possible without relying on all previously authorized software stacks to respect the monotonic counter's value
--- docs/misc/vtpm-platforms.txt | 127 ++++ docs/misc/vtpm.txt | 247 ++++--- docs/misc/vtpmmgr.txt | 163 +++++ stubdom/vtpm/README | 75 -- stubdom/vtpmmgr/Makefile | 4 +- stubdom/vtpmmgr/README | 75 -- stubdom/vtpmmgr/disk_crypto.c | 231 ++++++ stubdom/vtpmmgr/disk_crypto.h | 17 + stubdom/vtpmmgr/disk_format.h | 193 +++++ stubdom/vtpmmgr/disk_io.c | 125 ++++ stubdom/vtpmmgr/disk_io.h | 25 + stubdom/vtpmmgr/disk_read.c | 606 ++++++++++++++++ stubdom/vtpmmgr/disk_tpm.c | 238 +++++++ stubdom/vtpmmgr/disk_tpm.h | 25 + stubdom/vtpmmgr/disk_write.c | 410 +++++++++++ stubdom/vtpmmgr/endian_int.h | 72 ++ stubdom/vtpmmgr/init.c | 104 +-- stubdom/vtpmmgr/log.h | 8 +- stubdom/vtpmmgr/marshal.h | 824 ++++++++++++++-------- stubdom/vtpmmgr/mgmt_authority.c | 323 +++++++++ stubdom/vtpmmgr/mgmt_authority.h | 11 + stubdom/vtpmmgr/tcg.h | 7 + stubdom/vtpmmgr/tpm.c | 1360 ++++++++++++++++++------------------ stubdom/vtpmmgr/tpm.h | 104 +-- stubdom/vtpmmgr/tpmrsa.c | 25 + stubdom/vtpmmgr/tpmrsa.h | 3 + stubdom/vtpmmgr/vtpm_cmd_handler.c | 858 ++++++++++++++++++++--- stubdom/vtpmmgr/vtpm_disk.c | 237 +++++++ stubdom/vtpmmgr/vtpm_disk.h | 233 ++++++ stubdom/vtpmmgr/vtpm_manager.h | 391 ++++++++++- stubdom/vtpmmgr/vtpm_storage.c | 794 --------------------- stubdom/vtpmmgr/vtpm_storage.h | 68 -- stubdom/vtpmmgr/vtpmmgr.h | 12 +- 33 files changed, 5639 insertions(+), 2356 deletions(-) create mode 100644 docs/misc/vtpm-platforms.txt create mode 100644 docs/misc/vtpmmgr.txt delete mode 100644 stubdom/vtpm/README delete mode 100644 stubdom/vtpmmgr/README create mode 100644 stubdom/vtpmmgr/disk_crypto.c create mode 100644 stubdom/vtpmmgr/disk_crypto.h create mode 100644 stubdom/vtpmmgr/disk_format.h create mode 100644 stubdom/vtpmmgr/disk_io.c create mode 100644 stubdom/vtpmmgr/disk_io.h create mode 100644 stubdom/vtpmmgr/disk_read.c create mode 100644 stubdom/vtpmmgr/disk_tpm.c create mode 100644 stubdom/vtpmmgr/disk_tpm.h create mode 100644 stubdom/vtpmmgr/disk_write.c create mode 100644 stubdom/vtpmmgr/endian_int.h create mode 100644 stubdom/vtpmmgr/mgmt_authority.c create mode 100644 stubdom/vtpmmgr/mgmt_authority.h create mode 100644 stubdom/vtpmmgr/vtpm_disk.c create mode 100644 stubdom/vtpmmgr/vtpm_disk.h delete mode 100644 stubdom/vtpmmgr/vtpm_storage.c delete mode 100644 stubdom/vtpmmgr/vtpm_storage.h
docs/misc/vtpm-platforms.txt new file +127 -0
@@ -0,0 +1,127 @@ +Author: Daniel De Graaf <[email protected]> + +================================================================================ +Overview +================================================================================ + +This document describes example platforms which use virtual TPMs to provide +security properties for guests running on the platforms. There are several +tradeoffs between flexibility and trust which must be considered when +implementing a platform containing vTPMs. + +================================================================================ +Example 1: Trusted Domain 0 +================================================================================ + +This is the simplest example and provides maximal flexibility for testing the +vTPM Manager and vTPMs. The vtpmmgr, vtpm, and guest domains are created using +xl from the command line on domain 0. + +Provisioning on domain 0: +# dd if=/dev/zero of=/images/vtpmmgr-stubdom.img bs=2M count=1 +# dd if=/dev/zero of=/images/vtpm-guest1.img bs=2M count=1 +# dd if=/dev/zero of=/images/vtpm-guest2.img bs=2M count=1 + +The vtpmmgr configuration file (vtpmmgr.cfg): + +name="vtpmmgr" +kernel="/usr/lib/xen/boot/vtpmmgr-stubdom.gz" +extra="tpmlocality=2" +memory=8 +disk=["file:/images/vtpmmgr-stubdom.img,hda,w"] +iomem=["fed42,1"] + +The vtpm configuration files (vtpm-guest1.cfg, vtpm-guest2.cfg): + +name="vtpm-guest1" +kernel="/usr/lib/xen/boot/vtpm-stubdom.gz" +extra="loglevel=debug" +memory=8 +disk=["file:/images/vtpm-guest1.img,hda,w"] +vtpm=["backend=vtpmmgr,uuid=ac0a5b9e-cbe2-4c07-b43b-1d69e46fb839"] + +name="vtpm-guest2" +kernel="/usr/lib/xen/boot/vtpm-stubdom.gz" +extra="loglevel=debug" +memory=8 +disk=["file:/images/vtpm-guest2.img,hda,w"] +vtpm=["backend=vtpmmgr,uuid=6c3ff5f1-8d58-4fed-b00d-a5ea9a817f7f"] + +The guest configuration files (guest1.cfg, guest2.cfg): + +name="guest1" +kernel="/usr/lib/xen/boot/pv-grub-x86_64.gz" +memory=1024 +disk=["file:/images/guest1.img,xvda,w"] +vif=['mac=00:01:02:03:04:05,bridge=br0'] +vtpm=["backend=vtpm-guest1"] + +name="guest2" +kernel="/usr/lib/xen/boot/pv-grub-x86_64.gz" +memory=1024 +disk=["file:/images/guest2.img,xvda,w"] +vif=['mac=00:01:02:03:04:06,bridge=br0'] +vtpm=["backend=vtpm-guest2"] + +Starting domains: + +# xl create vtpmmgr.cfg +# xl create vtpm-guest1.cfg +# xl create guest1.cfg + +================================================================================ +Example 2: Domain Builder with Static vTPMs +================================================================================ + +This example uses the domain builder to construct a TPM Manager and vTPM which +do not require trusting the hardware domain with the vTPM's secrets. However, +it is not possible to construct additional vTPMs after the system is booted, and +the guests with access to vTPMs may not be rebooted without rebooting the entire +platform. + +The domain builder (dom0) constructs: + dom1 - xenstore system_u:system_r:xenstore_t + dom2 - hardware system_u:system_r:hwdom_t + dom3 - vtpmmgr system_u:system_r:vtpmmgr_t + dom4 - vtpm-hw system_u:system_r:vtpm_t + dom5 - vtpm-g1 guest1_u:vm_r:vtpm_t + dom6 - vtpm-g2 guest2_u:vm_r:vtpm_t + dom7 - guest1 guest1_u:vm_r:guest_t + dom8 - guest2 guest2_u:vm_r:guest_t + +It unpauses dom1 and dom2 after setting up Xenstore. The hardware domain is not +permitted access to IO memory at 0xfed42; this IO memory is accessible to the +vtpmmgr domain. The two guest domains may be instantiated using pv-grub or +using the same kernel as the hardware domain to conserve space in the domain +builder's initrd. + +Once the hardware domain boots, it runs: + +# xl block-attach vtpmmgr 'backendtype=phy,backend=hardware,vdev=hda,access=w,target=/dev/lvm/vtpmmgr' +# xl block-attach vtpm-hw 'backendtype=phy,backend=hardware,vdev=hda,access=w,target=/dev/lvm/vtpm-hw' +# xl block-attach vtpm-g1 'backendtype=phy,backend=hardware,vdev=hda,access=w,target=/dev/lvm/vtpm-g1' +# xl block-attach vtpm-g2 'backendtype=phy,backend=hardware,vdev=hda,access=w,target=/dev/lvm/vtpm-g2' +# xl block-attach guest1 'backendtype=phy,backend=hardware,vdev=xvda,access=w,target=/dev/lvm/guest1' +# xl block-attach guest2 'backendtype=phy,backend=hardware,vdev=xvda,access=w,target=/dev/lvm/guest2' +# xl vtpm-attach vtpm-hw uuid=062b6416-ed46-492a-9e65-a2f92dc07f7f backend=vtpmmgr +# xl vtpm-attach vtpm-g1 uuid=e9aa9d0f-ece5-4b84-b129-93004ba61a5f backend=vtpmmgr +# xl vtpm-attach vtpm-g2 uuid=3fb2caf0-d305-4516-96c7-420618d98efb backend=vtpmmgr +# xl vtpm-attach hardware uuid=062b6416-ed46-492a-9e65-a2f92dc07f7f backend=vtpm-hw +# xl vtpm-attach guest1 uuid=e9aa9d0f-ece5-4b84-b129-93004ba61a5f backend=vtpm-g1 +# xl vtpm-attach guest2 uuid=3fb2caf0-d305-4516-96c7-420618d98efb backend=vtpm-g2 + +Once these commands are complete, the domains are unpaused and may boot. The XSM +policy must be configured to not allow any of the domain types named above to be +created by any domain except the domain builder; guests created by the hardware +domain or one of the primary guests acting as a control domain must have a +different type. The type vtpmmgr_t may only map grants from vtpm_t; vtpm_t may +only map grants from a domain of type guest_t or hwdom_t with the same user +field. + +This example may be extended to allow dynamic creation of domains by using a +domain builder that accepts build requests. A single build request would create +a pair of domains using an unused XSM user field: a vTPM and a pv-grub domain +which requires the presence of a vTPM. To bind the configuration of the guest +to the vTPM, the guest may use full-disk encryption which can be unlocked using +an unseal operation; using the wrong vTPM will then yield a non-functioning +guest.
docs/misc/vtpm.txt +137 -110
329 lines not on this page · raw message
docs/misc/vtpmmgr.txt new file +163 -0
163 lines not on this page · raw message
stubdom/vtpm/README deleted +0 -75
75 lines not on this page · raw message
stubdom/vtpmmgr/Makefile +3 -1
@@ -12,7 +12,9 @@ XEN_ROOT=../.. TARGET=vtpmmgr.a -OBJS=vtpmmgr.o vtpm_cmd_handler.o vtpm_storage.o init.o tpmrsa.o tpm.o log.o +OBJS=vtpmmgr.o vtpm_cmd_handler.o init.o tpmrsa.o tpm.o log.o +OBJS += vtpm_disk.o disk_tpm.o disk_io.o disk_crypto.o disk_read.o disk_write.o +OBJS += mgmt_authority.o CFLAGS+=-Werror -Iutil -Icrypto -Itcs CFLAGS+=-Wno-declaration-after-statement -Wno-unused-label
stubdom/vtpmmgr/README deleted +0 -75
75 lines not on this page · raw message
stubdom/vtpmmgr/disk_crypto.c new file +231 -0
231 lines not on this page · raw message
stubdom/vtpmmgr/disk_crypto.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef __VTPMMGR_DISK_CRYPTO_H +#define __VTPMMGR_DISK_CRYPTO_H + +void do_random (void *buf,size_t size); +void aes_encrypt_one (void *target,const void *src,const struct key128 *key); +void aes_decrypt_one (void *target,const void *src,const struct key128 *key); + +void aes_setup (aes_context *ctx,const struct key128 *key); +void aes_encrypt_ctr (void *target,size_t target_size,const void *srcv,size_t src_size,const aes_context *key_e); +void aes_decrypt_ctr (void *target,size_t target_size,const void *srcv,size_t src_size,const aes_context *key_e); +void aes_cmac (struct mac128 *target,const void *src,size_t size,const aes_context *key); +int aes_cmac_verify (const struct mac128 *target,const void *src,size_t size,const aes_context *key); + +void sha256 (struct hash256 *target,const void *src,size_t size); +int sha256_verify (const struct hash256 *targ,const void *data,size_t size); + +#endif
stubdom/vtpmmgr/disk_format.h new file +193 -0
193 lines not on this page · raw message
stubdom/vtpmmgr/disk_io.c new file +125 -0
125 lines not on this page · raw message
stubdom/vtpmmgr/disk_io.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef __VTPMMGR_DISK_IO_H +#define __VTPMMGR_DISK_IO_H + +void *disk_read_sector (sector_t sector); +void disk_write_sector (sector_t sector,void * buf,size_t siz); +void *disk_write_buf (void ); +void disk_write_barrier (void ); + +sector_t disk_find_free (const struct mem_tpm_mgr *mgr); +void disk_flush_slot (const struct mem_tpm_mgr *mgr); +void disk_set_used (sector_t loc,const struct mem_tpm_mgr *mgr); + +void disk_write_all (struct mem_tpm_mgr *mgr); + +static inline sector_t seal_loc (struct mem_tpm_mgr *mgr) +{ +return native_be32 (mgr->active_root); +} + +static inline sector_t root_loc (struct mem_tpm_mgr *mgr) +{ +return native_be32 (2 + mgr->active_root); +} + +#endif
stubdom/vtpmmgr/disk_read.c new file +606 -0
606 lines not on this page · raw message
stubdom/vtpmmgr/disk_tpm.c new file +238 -0
238 lines not on this page · raw message
stubdom/vtpmmgr/disk_tpm.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef __VTPMMGR_DISK_VTPM_H +#define __VTPMMGR_DISK_VTPM_H +#include "vtpm_disk.h" + +/* Read PCR values to determine which unseal to try */ +void TPM_read_pcrs (void ); +void TPM_pcr_digest (struct hash160 *buf,le32_t selection); + +/* Sealing for key storage */ +int TPM_disk_seal (struct disk_seal_entry *dst,const void * src,size_t size); +int TPM_disk_unseal (void *dst,size_t size,const struct disk_seal_entry *src); + +/* NVRAM to allow revocation of TM-KEY */ +int TPM_disk_nvalloc (be32_t *nvram_slot,struct tpm_authdata auth); +int TPM_disk_nvread (void *buf,size_t bufsiz,be32_t nvram_slot,struct tpm_authdata auth); +int TPM_disk_nvwrite (void *buf,size_t bufsiz,be32_t nvram_slot,struct tpm_authdata auth); +int TPM_disk_nvchange (be32_t nvram_slot,struct tpm_authdata old,struct tpm_authdata noo); + +/* Monotonic counters to detect rollback */ +int TPM_disk_alloc_counter (be32_t *slot,struct tpm_authdata auth,be32_t *value); +int TPM_disk_check_counter (be32_t slot,struct tpm_authdata auth,be32_t value); +int TPM_disk_incr_counter (be32_t slot,struct tpm_authdata auth); +int TPM_disk_change_counter (be32_t slot,struct tpm_authdata old,struct tpm_authdata noo); + +#endif
stubdom/vtpmmgr/disk_write.c new file +410 -0
410 lines not on this page · raw message
stubdom/vtpmmgr/endian_int.h new file +72 -0
72 lines not on this page · raw message
stubdom/vtpmmgr/init.c +26 -78
191 lines not on this page · raw message
stubdom/vtpmmgr/log.h +5 -3
@@ -64,18 +64,20 @@ extern char *module_names[];#define SETBIT (num,idx) (num) |= BITMASK(idx)#define CLEARBIT (num,idx) (num) &= ( ~ BITMASK(idx) ) +void printk (const char *fmt, ...); + #define vtpmloginfo(module, fmt, args...) \ if (GETBIT (LOGGING_MODULES, module) == 1) { \ - fprintf (stdout, "INFO[%s]: " fmt, module_names[module], ##args); \ + printk("INFO[%s]: " fmt, module_names[module], ##args); \ } #define vtpmloginfomore(module, fmt, args...) \ if (GETBIT (LOGGING_MODULES, module) == 1) { \ - fprintf (stdout, fmt,##args); \ + printk(fmt,##args); \ } #define vtpmlogerror(module, fmt, args...) \ - fprintf (stderr, "ERROR[%s]: " fmt, module_names[module], ##args); + printk("ERROR[%s]: " fmt, module_names[module], ##args);//typedef UINT32 tpm_size_t;
stubdom/vtpmmgr/marshal.h +532 -292
65 lines not on this page · raw message
stubdom/vtpmmgr/mgmt_authority.c new file +323 -0
323 lines not on this page · raw message
stubdom/vtpmmgr/mgmt_authority.h new file +11 -0
Lines of this file are not shown. View the raw message.
stubdom/vtpmmgr/tpm.c +662 -698
1,360 lines not on this page · raw message
stubdom/vtpmmgr/tpm.h +35 -69
104 lines not on this page · raw message
stubdom/vtpmmgr/vtpm_cmd_handler.c +774 -84
858 lines not on this page · raw message
stubdom/vtpmmgr/vtpm_disk.c new file +237 -0
237 lines not on this page · raw message
stubdom/vtpmmgr/vtpm_disk.h new file +233 -0
233 lines not on this page · raw message
stubdom/vtpmmgr/vtpm_manager.h +386 -5
391 lines not on this page · raw message
stubdom/vtpmmgr/vtpm_storage.c deleted +0 -794
794 lines not on this page · raw message
stubdom/vtpmmgr/vtpm_storage.h deleted +0 -68
68 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.5.3
Part of the diff is not shown here. View the raw message.
Re: [PATCH 1/7] vtpmmgr: add TPM group support
Quoted 47 lines · Daniel De Graaf
This is a complete rewrite of the disk format and key hierarchy for the TPM Manager. The new format supports multiple groups of vTPMs which define the permitted configurations where a given vTPM's keys are available, allowing upgrades of critical components while retaining the secrecy of cryptographic keys.
New features of the TPM Manager are explained in the README and in the definitions of the management commands in
vtpm_manager.h.New features for vTPMs:
1. The size of the state blob for a vTPM is expanded from 52 to 64 bytes in order to support future vTPMs using SHA-2/3 instead of SHA-1.
2. vTPMs can obtain a quote from the physical TPM with certain resettable PCRs set to include information about the vTPM. This can be used by a vTPM to provide evidence of its integrity, including the secrecy of its EK, and for deep quotes.
Some additional changes made by this rewrite that may impact existing users:
1. The value of
WELLKNOWN_OWNER_AUTHwas incorrect for the physical TPM; the convention is to use all zero bits for well-known authentication values, not all one bits.2. Randomly generating the owner auth value for the physical TPM is no longer supported, as it prevents later creation or certification of AIKs (which the old manager did not support).
3. The vTPM Manager needs to be provisioned with a PCR composite and an upgrade authority's public key before it will save data across boots.
The current implementation still has some limitations:
* 5 valid system PCR selections per group
* The vTPM Manager's disk can use at most 2MB of space
* The vTPM domain's build hash is always set to null/zeroMost of the code relating to upgrade and rollback protection is currently stubbed out, but future versions can add:
* Support for using the TPM's monotonic counter to prevent rollback of vTPM data by taking and restoring disk snapshots
* Masking the master disk encryption key using a value stored in the TPM's NVRAM so that revocation of old data is possible without relying on all previously authorized software stacks to respect the monotonic counter's value
Quoted 1 line
Signed-off-by Daniel De Graaf <[email protected]>
As discussed on the previous version I've not extensively reviewed but I think this should go in nonetheless:
Ian.
PATCH v2 2/7 vtpmmgr: add example control tools
In reply to Daniel De GraafThe manage-vtpmmgr.pl script is an example client for interacting with the TPM Manager; it is intended to run in a management domain with a vTPM (which may be dom0). It is used to create and manage vTPMs and vTPM groups.
The calc.pl script is an example manager of a vTPM group. It signs the configuration lists used by the TPM Manager with a locally held private key.
--- config/Tools.mk.in | 1 + tools/Makefile | 1 + tools/vtpmmgr/Makefile | 15 ++++ tools/vtpmmgr/calc.pl | 103 +++++++++++++++++++++++++ tools/vtpmmgr/manage-vtpmmgr.pl | 161 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 281 insertions(+) create mode 100644 tools/vtpmmgr/Makefile create mode 100755 tools/vtpmmgr/calc.pl create mode 100755 tools/vtpmmgr/manage-vtpmmgr.pl
config/Tools.mk.in +1 -0
@@ -56,6 +56,7 @@ CONFIG_QEMU_TRAD := @qemu_traditional@ CONFIG_QEMU_XEN := @qemu_xen@ CONFIG_XEND := @xend@ CONFIG_BLKTAP1 := @blktap1@ +CONFIG_VTPM := @vtpm@ #System options ZLIB := @zlib@
tools/Makefile +1 -0
@@ -39,6 +39,7 @@ SUBDIRS-$(CONFIG_X86) += xenpaging SUBDIRS-$(CONFIG_X86) += debugger/gdbsx SUBDIRS-$(CONFIG_X86) += debugger/kdd SUBDIRS-$(CONFIG_TESTS) += tests +SUBDIRS-$(CONFIG_VTPM) += vtpmmgr # These don't cross-compile ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
tools/vtpmmgr/Makefile new file +15 -0
@@ -0,0 +1,15 @@ +XEN_ROOT=$(CURDIR)/../.. +include $(XEN_ROOT)/tools/Rules.mk + +all: + @true + +install: + $(INSTALL_DIR) "$(DESTDIR)$(LIBEXEC)" + $(INSTALL_DATA) calc.pl "$(DESTDIR)$(LIBEXEC)" + $(INSTALL_DATA) manage-vtpmmgr.pl "$(DESTDIR)$(LIBEXEC)" + +clean: + @true + +.PHONY: all install clean
tools/vtpmmgr/calc.pl new file +103 -0
103 lines not on this page · raw message
tools/vtpmmgr/manage-vtpmmgr.pl new file +161 -0
161 lines not on this page · raw message
Signature · 1 line
1.8.5.3
Re: [PATCH 2/7] vtpmmgr: add example control tools
Quoted 10 lines · Daniel De Graaf
tools/vtpmmgr/calc.pl new file +10
-0+#my @pcr; +#$pcr[$_] = "\0"x20 for 0..23; +# +#sub extend { +# my($n, $v) = @_; +# $pcr[$n] = sha1($pcr[$n], $v); +#} +# +#sub composite { +# my $sel = shift;
tools/vtpmmgr/calc.pl line 27
Quoted 10 lines
tools/vtpmmgr/calc.pl new file +10
-0+# my $bits = unpack 'b24', pack 'V', $sel; +# my @used; +# my $i = 0; +# for (split //, $bits) { +# push @used, $pcr[$i] if $_; +# $i++; +# } +# my $v = pack 'nb*N', 3, $bits, 20*scalar @used; +# sha1($v, @used); +#}
Left over debug?
[...]
tools/vtpmmgr/manage-vtpmmgr.pl line 134
Quoted 12 lines
tools/vtpmmgr/manage-vtpmmgr.pl new file +12
-0+if ($cmd eq 'list') { + cmd_list @ARGV; +} elsif ($cmd eq 'group-add') { + cmd_group_add @ARGV; +} elsif ($cmd eq 'group-update') { + cmd_group_update @ARGV; +} elsif ($cmd eq 'group-del') { + cmd_group_del @ARGV; +} elsif ($cmd eq 'vtpm-add') { + cmd_vtpm_add @ARGV; +} elsif ($cmd eq 'vtpm-del') { + cmd_vtpm_del @ARGV;
A trick I learnt from osstest.git:mg-hosts:
die unless @ARGV;
my $subcmd= shift @ARGV;
$subcmd =~ s/-/_/g;
my $subcmdproc;
{
$subcmdproc= \&{ "cmd_$subcmd" };
}
$subcmdproc->();(not sure what those braces do, Ian?)
Ian.
Re: [PATCH 2/7] vtpmmgr: add example control tools
Ian Campbell writes ("Re: [Xen-devel] [PATCH 2/7] vtpmmgr: add example control tools"):
Quoted 11 lines · Daniel De Graaf
A trick I learnt from osstest.git:mg-hosts:
die unless @ARGV; my $subcmd= shift @ARGV; $subcmd =~ s/-/_/g; my $subcmdproc; { $subcmdproc= \&{ "cmd_$subcmd" }; } $subcmdproc->();
Quoted 1 line
(not sure what those braces do, Ian?)
I think they were there to contain the scope of
no strict qw(refs);
which is mysteriously absent.
...
So it turns out, on experimenting and RTFM, that "use strict" doesn't affect subroutine refs. So the braces are unnecessary.
Also, since I wrote that I have been using a better idiom:
my $funcn = $method;
$funcn =~ y/-/_/;
my $mainfunc = $main::{"main__$funcn"};
reject "unknown method" unless $mainfunc;
#...
&$mainfuncThis makes it possible to print a sensible error message.
Ian.
PATCH v2 3/7 vtpmmgr: Store hardware TPM Locality
In reply to Daniel De GraafFrom: Jason Andryuk <[email protected]>
The TPM locality must be specified when using TPM_PCR_INFO_LONG for TPM_Seal. Store the locality so it can be provided later.
--- stubdom/vtpmmgr/init.c | 4 +++- stubdom/vtpmmgr/vtpmmgr.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-)
stubdom/vtpmmgr/init.c +3 -1
@@ -69,7 +69,8 @@ const TPM_AUTHDATA WELLKNOWN_AUTH = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0struct vtpm_globals vtpm_globals = { .tpm_fd =-1 , - .oiap = { .AuthHandle =0 } + .oiap = { .AuthHandle =0 }, + .hw_locality =0 };static int tpm_entropy_source (void * dummy,unsigned char * data,size_t len,size_t * olen) {
@@ -436,6 +437,7 @@ TPM_RESULT vtpmmgr_init(int argc, char** argv) { } vtpm_globals.tpm_fd =tpm_tis_open (tpm);tpm_tis_request_locality (tpm, opts.tpmlocality); + vtpm_globals.hw_locality = opts.tpmlocality; }break ;case TPMDRV_TPMFRONT :
stubdom/vtpmmgr/vtpmmgr.h +2 -0
@@ -57,6 +57,8 @@ struct vtpm_globals {entropy_context entropy;ctr_drbg_context ctr_drbg; + +int hw_locality; };struct tpm_opaque {
Signature · 1 line
1.8.5.3
PATCH v2 4/7 vtpmmgr: Convert TPM_Seal to use TPM_PCR_INFO_LONG
In reply to Daniel De GraafFrom: Jason Andryuk <[email protected]>
Infineon 1.2 TPMs fail TPM_Seal commands with TPM_BAD_PARAMETER when PCRS are specified by a TPM_PCR_INFO structure. Using a TPM_PCR_INFO_LONG structure to specify PCRs succeeds, so update to use that. This also requires changes to use TPM_STORED_DATA12 for the result.
--- stubdom/vtpmmgr/disk_tpm.c | 52 ++++++++++++++++++++--------- stubdom/vtpmmgr/marshal.h | 82 ++++++++++++++++++++++++++++++++++++++++++++++ stubdom/vtpmmgr/tcg.h | 42 ++++++++++++++++++++++++ stubdom/vtpmmgr/tpm.c | 22 +++++++------ stubdom/vtpmmgr/tpm.h | 8 ++--- 5 files changed, 176 insertions(+), 30 deletions(-)
stubdom/vtpmmgr/disk_tpm.c +36 -16
@@ -74,12 +74,15 @@ void TPM_pcr_digest(struct hash160 *buf, le32_t selection)int TPM_disk_seal (struct disk_seal_entry *dst,const void * src,size_t size) {uint32_t rc; -TPM_PCR_INFO info; -TPM_STORED_DATA out; +uint32_t infoSize; +TPM_PCR_INFO_LONG info; +TPM_STORED_DATA12 out;TPM_AUTH_SESSION osap =TPM_AUTH_SESSION_INIT ;TPM_AUTHDATA sharedsecret;TPM_AUTHDATA auth; +printk ("Calling TPM_disk_seal\n" ); + rc =TPM_OSAP (TPM_ET_KEYHANDLE ,TPM_SRK_KEYHANDLE , (void *)&vtpm_globals.srk_auth, &sharedsecret, &osap);
@@ -94,18 +97,26 @@ int TPM_disk_seal(struct disk_seal_entry *dst, const void* src, size_t size)#endif memset (auth,0 ,20 ); - info.pcrSelection.sizeOfSelect =3 ; - info.pcrSelection.pcrSelect = (void *)&dst->pcr_selection; + info.tag =TPM_TAG_PCR_INFO_LONG ; + info.localityAtCreation =1 << vtpm_globals.hw_locality; + info.localityAtRelease =1 << vtpm_globals.hw_locality; + info.creationPCRSelection.sizeOfSelect =3 ; + info.creationPCRSelection.pcrSelect = (void *)&dst->pcr_selection; + info.releasePCRSelection.sizeOfSelect =3 ; + info.releasePCRSelection.pcrSelect = (void *)&dst->pcr_selection;memcpy (&info.digestAtCreation, &dst->digest_at_seal,20 );memcpy (&info.digestAtRelease, &dst->digest_release,20 ); - rc =TPM_Seal (TPM_SRK_KEYHANDLE ,45 , &info, size, src, &out, + infoSize =2 +1 +1 +2 +3 +2 +3 +20 +20 ; +//infoSize = sizeof_TPM_PCR_INFO_LONG(&info); + + rc =TPM_Seal (TPM_SRK_KEYHANDLE , infoSize, &info, size, src, &out, (void *)&sharedsecret, (void *)&auth, &osap);TPM_TerminateHandle (osap.AuthHandle);#ifdef DEBUG_SEAL_OPS -printk ("TPM_Seal rc=%d encDataSize=%d sealInfoSize=%d\n" , rc, out.encDataSize, out.sealInfoSize); +printk ("TPM_Seal rc=%d encDataSize=%d sealInfoSize=%d\n" , rc, out.encDataSize, out.sealInfoLongSize);#endif if (!rc)memcpy (dst->sealed_data, out.encData,256 );
@@ -113,7 +124,7 @@ int TPM_disk_seal(struct disk_seal_entry *dst, const void* src, size_t size)#ifdef DEBUG_SEAL_OPS uint8_t buf[512 ];uint8_t *start = buf; -uint8_t *end =pack_TPM_STORED_DATA (buf, &out); +uint8_t *end =pack_TPM_STORED_DATA12 (buf, &out);printk ("stored_data:" );while (start != end) {printk (" %02x" , *start);
@@ -122,37 +133,46 @@ int TPM_disk_seal(struct disk_seal_entry *dst, const void* src, size_t size)printk ("\n" );#endif -free_TPM_STORED_DATA (&out); +free_TPM_STORED_DATA12 (&out);return rc; }int TPM_disk_unseal (void *dst,size_t size,const struct disk_seal_entry *src) {uint32_t rc; -TPM_STORED_DATA in; +TPM_STORED_DATA12 in;TPM_AUTH_SESSION oiap =TPM_AUTH_SESSION_INIT ;TPM_AUTHDATA auth;uint32_t outSize =0 ;uint8_t *out =NULL ; +printk ("Calling TPM_disk_unseal\n" ); + rc =TPM_OIAP (&oiap);if (rc)abort ();memset (auth,0 ,20 ); - in.ver =TPM_STRUCT_VER_1_1 ; - in.sealInfoSize =45 ; - in.sealInfo.pcrSelection.sizeOfSelect =3 ; - in.sealInfo.pcrSelection.pcrSelect = (void *)&src->pcr_selection; -memcpy (&in.sealInfo.digestAtCreation, &src->digest_at_seal,20 ); -memcpy (&in.sealInfo.digestAtRelease, &src->digest_release,20 ); + in.tag =TPM_TAG_STORED_DATA12 ; + in.et =0 ; +//in.sealInfoLongSize = sizeof_TPM_PCR_INFO_LONG(&in.sealInfoLong); + in.sealInfoLongSize =2 +1 +1 +2 +3 +2 +3 +20 +20 ; + in.sealInfoLong.tag =TPM_TAG_PCR_INFO_LONG ; + in.sealInfoLong.localityAtCreation =1 << vtpm_globals.hw_locality; + in.sealInfoLong.localityAtRelease =1 << vtpm_globals.hw_locality; + in.sealInfoLong.creationPCRSelection.sizeOfSelect =3 ; + in.sealInfoLong.creationPCRSelection.pcrSelect = (void *)&src->pcr_selection; + in.sealInfoLong.releasePCRSelection.sizeOfSelect =3 ; + in.sealInfoLong.releasePCRSelection.pcrSelect = (void *)&src->pcr_selection; +memcpy (&in.sealInfoLong.digestAtCreation, &src->digest_at_seal,20 ); +memcpy (&in.sealInfoLong.digestAtRelease, &src->digest_release,20 ); in.encDataSize =256 ; in.encData = (void *)src->sealed_data;#ifdef DEBUG_SEAL_OPS uint8_t buf[512 ];uint8_t *start = buf; -uint8_t *end =pack_TPM_STORED_DATA (buf, &in); +uint8_t *end =pack_TPM_STORED_DATA12 (buf, &in);printk ("stored_data:" );while (start != end) {printk (" %02x" , *start);
stubdom/vtpmmgr/marshal.h +82 -0
124 lines not on this page · raw message
stubdom/vtpmmgr/tcg.h +42 -0
60 lines not on this page · raw message
stubdom/vtpmmgr/tpm.c +12 -10
@@ -492,11 +492,11 @@ abort_egress:TPM_RESULT TPM_Seal (TPM_KEY_HANDLE keyHandle,// in -UINT32 pcrInfoSize,// in -TPM_PCR_INFO * pcrInfo,// in +UINT32 pcrInfoLongSize,// in +TPM_PCR_INFO_LONG * pcrInfoLong,// in UINT32 inDataSize,// in const BYTE * inData,// in -TPM_STORED_DATA * sealedData,//out +TPM_STORED_DATA12 * sealedData,//out const TPM_SECRET * osapSharedSecret,//in const TPM_AUTHDATA * sealedDataAuth,//in TPM_AUTH_SESSION* pubAuth // in, out
@@ -509,28 +509,30 @@ TPM_RESULT TPM_Seal(xorEncrypt (osapSharedSecret, &pubAuth->NonceEven, sealedDataAuth,IN_PTR ,NULL ,NULL ); in_pos +=sizeof (TPM_ENCAUTH ); -PACK_IN (UINT32 , pcrInfoSize); -if (pcrInfoSize) -PACK_IN (TPM_PCR_INFO , pcrInfo); + +PACK_IN (UINT32 , pcrInfoLongSize); +if (pcrInfoLongSize) { +PACK_IN (TPM_PCR_INFO_LONG , pcrInfoLong); + }PACK_IN (UINT32 , inDataSize);PACK_IN (BUFFER , inData, inDataSize);TPM_XMIT_AUTH1 (osapSharedSecret, pubAuth); -UNPACK_OUT (TPM_STORED_DATA , sealedData,UNPACK_ALLOC ); +UNPACK_OUT (TPM_STORED_DATA12 , sealedData,UNPACK_ALLOC );TPM_END_AUTH1 (osapSharedSecret, pubAuth); abort_egress:if (status) -free_TPM_STORED_DATA (sealedData); +free_TPM_STORED_DATA12 (sealedData);TPM_AUTH_ERR_CHECK (pubAuth);return status; } TPM_RESULT TPM_Unseal( TPM_KEY_HANDLE parentHandle, // in - const TPM_STORED_DATA* sealedData, + const TPM_STORED_DATA12* sealedData, UINT32* outSize, // out BYTE** out, //out const TPM_AUTHDATA* key_usage_auth, //in
@@ -544,7 +546,7 @@ TPM_RESULT TPM_Unseal(PACK_IN (TPM_KEY_HANDLE , parentHandle);TPM_HASH_IN_BEGIN ; -PACK_IN (TPM_STORED_DATA , sealedData); +PACK_IN (TPM_STORED_DATA12 , sealedData);TPM_XMIT_AUTH2 (key_usage_auth, keyAuth, data_usage_auth, dataAuth);
stubdom/vtpmmgr/tpm.h +4 -4
@@ -88,11 +88,11 @@ TPM_RESULT TPM_Reset(TPM_PCR_SELECTION *sel);TPM_RESULT TPM_Seal (TCS_KEY_HANDLE keyHandle,// in -UINT32 pcrInfoSize,// in -TPM_PCR_INFO * pcrInfo,// in +UINT32 pcrInfoLongSize,// in +TPM_PCR_INFO_LONG * pcrInfoLong,// in UINT32 inDataSize,// in const BYTE * inData,// in -TPM_STORED_DATA * sealedData,//out +TPM_STORED_DATA12 * sealedData,//out const TPM_SECRET * osapSharedSecret,//in const TPM_AUTHDATA * sealDataAuth,//in TPM_AUTH_SESSION* pubAuth // in, out
@@ -100,7 +100,7 @@ TPM_RESULT TPM_Seal( TPM_RESULT TPM_Unseal ( TPM_KEY_HANDLE parentHandle, // in - const TPM_STORED_DATA* sealedData, + const TPM_STORED_DATA12* sealedData, UINT32* outSize, // out BYTE** out, //out const TPM_AUTHDATA* key_usage_auth, //in
Signature · 1 line
1.8.5.3
PATCH v2 5/7 vtpm: passthru requests to manager
In reply to Daniel De GraafWhen sending commands to a vTPM, commands with the VTPM_TAG_REQ2 tag are passed directly to the TPM Manager since they are used in the management interface to the TPM Manager. The VTPM_TAG_REQ tag is translated to TPM_TAG_RQU_COMMAND to allow access to the physical TPM for certain ordinals (PCRRead, Extend, and GetRandom).
--- stubdom/vtpm/vtpm.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)
stubdom/vtpm/vtpm.c +39 -1
@@ -33,6 +33,7 @@#include "vtpm_cmd.h" #include "vtpm_pcrs.h" #include "vtpmblk.h" +#include "vtpm_manager.h" #define TPM_LOG_INFO LOG_INFO#define TPM_LOG_ERROR LOG_ERR
@@ -117,6 +118,40 @@ int init_random(void) {return 0 ; } +int check_passthru (tpmcmd_t * tpmcmd) { +TPM_TAG tag; +UINT32 len =10 ; +BYTE * ptr; +size_t size; + +if (tpmcmd->req_len <10 ) { +return false; + } + + ptr = tpmcmd->req; +tpm_unmarshal_UINT16 (&ptr, &len, &tag); + +if (tag ==VTPM_TAG_REQ2 ) { +info ("VTPM passthru: %d bytes" , (int )tpmcmd->req_len); +tpmfront_cmd (tpmfront_dev, tpmcmd->req, tpmcmd->req_len, &tpmcmd->resp, &size); + tpmcmd->resp_len = size; +info ("VTPM passthru return: %d bytes" , (int )size); +return true; + } + +if (tag ==VTPM_TAG_REQ ) { +info ("VTPM pTPM-cmd: %d bytes" , (int )tpmcmd->req_len); + ptr = tpmcmd->req; +tpm_marshal_UINT16 (&ptr, &len,TPM_TAG_RQU_COMMAND ); +tpmfront_cmd (tpmfront_dev, tpmcmd->req, tpmcmd->req_len, &tpmcmd->resp, &size); + tpmcmd->resp_len = size; +info ("VTPM pTPM-cmd return: %d bytes" , (int )size); +return true; + } + +return false; +} +int check_ordinal (tpmcmd_t * tpmcmd) {TPM_COMMAND_CODE ord;UINT32 len =4 ;
@@ -209,6 +244,9 @@ static void main_loop(void) {error ("Invalid locality (%d) for client in tpm_handle_command" , tpmcmd->locality);create_error_response (tpmcmd,TPM_FAIL ); } +/* Check for TPM Manager passthrough command */ +else if (check_passthru (tpmcmd)) { + }/* Check for disabled ordinals */ else if (!check_ordinal (tpmcmd)) {create_error_response (tpmcmd,TPM_BAD_ORDINAL );
@@ -231,7 +269,7 @@ static void main_loop(void) { } abort_postpcrs: -info ("VTPM Shutting down\n" ); +info ("VTPM Shutting down" );tpm_emulator_shutdown (); }
Signature · 1 line
1.8.5.3
PATCH v2 6/7 vtpm: add ordinal for obtaining an EK signature
In reply to Daniel De GraafFor a vTPM to be useful for remote attestation, proof that the vTPM's EK was generated and held within a secure vTPM implementation is necessary. This patch adds an ordinal to the vTPM which will request a quote providing this evidence from the TPM Manager; it only functions during the first startup of a given vTPM in order to provide proof that the EK was freshly generated (and not a key whose private part is available elsewhere).
--- stubdom/Makefile | 1 + stubdom/vtpm-parent-sign-ek.patch | 196 ++++++++++++++++++++++++++++++++++++++ stubdom/vtpm/vtpm_cmd.c | 45 +++++++++ 3 files changed, 242 insertions(+) create mode 100644 stubdom/vtpm-parent-sign-ek.patch
stubdom/Makefile +1 -0
@@ -208,6 +208,7 @@ tpm_emulator-$(XEN_TARGET_ARCH): tpm_emulator-$(TPMEMU_VERSION).tar.gz patch -d $@ -p1 < tpmemu-$(TPMEMU_VERSION).patch; patch -d $@ -p1 < vtpm-bufsize.patch patch -d $@ -p1 < vtpm-locality.patch + patch -d $@ -p1 < vtpm-parent-sign-ek.patch mkdir $@/build cd $@/build; CC=${CC} $(CMAKE) .. -DCMAKE_C_FLAGS:STRING="-std=c99 -DTPM_NO_EXTERN $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Wno-declaration-after-statement" touch $@
stubdom/vtpm-parent-sign-ek.patch new file +196 -0
196 lines not on this page · raw message
stubdom/vtpm/vtpm_cmd.c +45 -0
51 lines not on this page · raw message
Signature · 1 line
1.8.5.3
PATCH v2 7/7 vtpm: add deep quote support
In reply to Daniel De GraafThis allows the client of a vTPM to request a quote from the physical TPM which includes PCRs from both the physical and virtual TPMs, signed by an AIK from the physical TPM. This quote can be used to provide evidence of the complete launch environment of a virtual machine.
--- stubdom/Makefile | 1 + stubdom/vtpm-deepquote.patch | 187 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+) create mode 100644 stubdom/vtpm-deepquote.patch
stubdom/Makefile +1 -0
@@ -209,6 +209,7 @@ tpm_emulator-$(XEN_TARGET_ARCH): tpm_emulator-$(TPMEMU_VERSION).tar.gz patch -d $@ -p1 < vtpm-bufsize.patch patch -d $@ -p1 < vtpm-locality.patch patch -d $@ -p1 < vtpm-parent-sign-ek.patch + patch -d $@ -p1 < vtpm-deepquote.patch mkdir $@/build cd $@/build; CC=${CC} $(CMAKE) .. -DCMAKE_C_FLAGS:STRING="-std=c99 -DTPM_NO_EXTERN $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Wno-declaration-after-statement" touch $@
stubdom/vtpm-deepquote.patch new file +187 -0
187 lines not on this page · raw message
Signature · 1 line
1.8.5.3