From: Matthew Fioravante Subject: [PATCH 10/12] VTPM mini-os: vtpm-stubdom Date: Fri, 11 Mar 2011 18:15:14 -0500 Message-ID: <4D7AAD02.8040806@jhuapl.edu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0990231674==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a cryptographically signed message in MIME format. --===============0990231674== Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha1; boundary="------------ms090807050006050001070206" This is a cryptographically signed message in MIME format. --------------ms090807050006050001070206 Content-Type: multipart/mixed; boundary="------------000007050806000305080601" This is a multi-part message in MIME format. --------------000007050806000305080601 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable This patch adds the vtpm-stubdom mini-os domain to the stubdom directory.= To build it: cd stubdom make vtpm-stubdom It uses the berlios tpm_emulator version 0.6.1 as a base and the=20 paravirtualized tpm drivers to communicate with the guest and the vtpm=20 manager domain. An examples directory was added to studom/vtpm with 2 example config=20 files to show how to use the vtpm domain. The vtpm can use either vtpm_managerd running as a process in dom0 or=20 vtpmmgrdom running as its own domain. You must change the backend=20 parameter for the vtpm=3D entry in the vtpm config file to point to eithe= r=20 dom0 or vtpmmgrdom. You must also give each vtpm a unique uuid. When using vtpm-stubdom with vtpm_managerd in dom0, vtpm_managerd must=20 be built and installed in stubdom mode. To do this: cd tools/vtpm_manager vi Rules.mk Uncomment the line that says: CFLAGS +=3D -DVTPM_STUBDOM make clean and then make && make install Further more complete documentation will be forthcoming Signed off by: Matthew Fioravante --------------000007050806000305080601 Content-Type: text/x-patch; name="10-vtpm-stubdom.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="10-vtpm-stubdom.patch" diff -Naur xen-unstable-trp-sdp-pristine/stubdom/vtpm/examples/myguest.cf= g xen-unstable-trp-sdp/stubdom/vtpm/examples/myguest.cfg --- xen-unstable-trp-sdp-pristine/stubdom/vtpm/examples/myguest.cfg 1969-= 12-31 19:00:00.000000000 -0500 +++ xen-unstable-trp-sdp/stubdom/vtpm/examples/myguest.cfg 2011-02-23 19:= 40:48.000000000 -0500 @@ -0,0 +1,5 @@ +bootloader =3D pygrub +memory =3D 192 +name =3D 'myguest' +disk =3D ['file:/tmp/myguest.img,hda1,w'] +vtpm =3D ['backend=3Dmyvtpm'] diff -Naur xen-unstable-trp-sdp-pristine/stubdom/vtpm/examples/myvtpm.cfg= xen-unstable-trp-sdp/stubdom/vtpm/examples/myvtpm.cfg --- xen-unstable-trp-sdp-pristine/stubdom/vtpm/examples/myvtpm.cfg 1969-1= 2-31 19:00:00.000000000 -0500 +++ xen-unstable-trp-sdp/stubdom/vtpm/examples/myvtpm.cfg 2011-02-23 19:4= 0:48.000000000 -0500 @@ -0,0 +1,8 @@ +kernel =3D '/boot/vtpm-stubdom.gz' +memory =3D '8' +name =3D 'vtpm' +on_shutdown =3D 'destroy' +on_crash =3D 'destroy' +disk =3D ['file:/tmp/myvtpm.img,hda,w'] +extra =3D 'loglevel=3Dinfo pvm clear' +vtpm =3D ['backend=3Dvtpmmgrdom,uuid=3D4209a551-9b79-4feb-ad4d-b4ff1c1bc= 355'] diff -Naur xen-unstable-trp-sdp-pristine/stubdom/vtpm/Makefile xen-unstab= le-trp-sdp/stubdom/vtpm/Makefile --- xen-unstable-trp-sdp-pristine/stubdom/vtpm/Makefile 1969-12-31 19:00:= 00.000000000 -0500 +++ xen-unstable-trp-sdp/stubdom/vtpm/Makefile 2011-02-23 19:40:48.000000= 000 -0500 @@ -0,0 +1,53 @@ +#LICENSE AND DISCLAIMER +# +#Copyright =C2=A9 2010 The Johns Hopkins University/Applied Physics=20 +#Laboratory +# +#This software was developed at The Johns Hopkins University/Applied=20 +#Physics Laboratory (=E2=80=9CJHU/APL=E2=80=9D) that is the author there= of under the=20 +#=E2=80=9Cwork made for hire=E2=80=9D provisions of the copyright law. = Permission is=20 +#hereby granted, free of charge, to any person obtaining a copy of this = +#software and associated documentation (the =E2=80=9CSoftware=E2=80=9D),= to use the=20 +#Software without restriction, including without limitation the rights t= o=20 +#copy, modify, merge, publish, distribute, sublicense, and/or sell copie= s=20 +#of the Software, and to permit others to do so, subject to the followin= g=20 +#conditions: +# +#1. This LICENSE AND DISCLAIMER, including the copyright notice, shall = +#be included in all copies of the Software, including copies of=20 +#substantial portions of the Software;=20 +# +#2. JHU/APL assumes no obligation to provide support of any kind with=20 +#regard to the Software. This includes no obligation to provide assista= nce=20 +#in using the Software nor to provide updated versions of the Software; = and +# +#3. THE SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT A= NY=20 +#EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES INCLUDING, BU= T=20 +#NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS FOR A PARTICULAR = +#PURPOSE, AND NONINFRINGEMENT ARE HEREBY DISCLAIMED. USERS ASSUME THE=20 +#ENTIRE RISK AND LIABILITY OF USING THE SOFTWARE. USERS ARE ADVISED TO = +#TEST THE SOFTWARE THOROUGHLY BEFORE RELYING ON IT. IN NO EVENT SHALL T= HE=20 +#JOHNS HOPKINS UNIVERSITY BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDIN= G,=20 +#WITHOUT LIMITATION, ANY LOST PROFITS, LOST SAVINGS OR OTHER INCIDENTAL = OR=20 +#CONSEQUENTIAL DAMAGES, ARISING OUT OF THE USE OR INABILITY TO USE THE=20 +#SOFTWARE. + +TPMEMU_DIR=3D../tpm_emulator-$(XEN_TARGET_ARCH)/tpmd +TPMEMU_OBJS=3D$(wildcard $(TPMEMU_DIR)/*.o) +XEN_ROOT=3D../.. + +PSSL_DIR=3D../polarssl-$(XEN_TARGET_ARCH)/library +PSSL_OBJS=3Daes.o padlock.o sha1.o + +TARGET=3Dvtpm.a +OBJS=3Dvtpm.o vtpm_cmd.o vtpmblk.o=20 + +CPPFLAGS+=3D-I$(MNGR_ROOT)/manager -I${TPMEMU_DIR} + +$(TARGET): $(OBJS) + ar -cr $@ $(OBJS) $(TPMEMU_OBJS) $(foreach obj,$(PSSL_OBJS),$(PSSL_DIR)= /$(obj)) + +clean:=20 + -rm $(TARGET) $(OBJS) + +.PHONY: clean diff -Naur xen-unstable-trp-sdp-pristine/stubdom/vtpm/vtpmblk.c xen-unsta= ble-trp-sdp/stubdom/vtpm/vtpmblk.c --- xen-unstable-trp-sdp-pristine/stubdom/vtpm/vtpmblk.c 1969-12-31 19:00= :00.000000000 -0500 +++ xen-unstable-trp-sdp/stubdom/vtpm/vtpmblk.c 2011-02-23 19:40:48.00000= 0000 -0500 @@ -0,0 +1,335 @@ +/* LICENSE AND DISCLAIMER + * + * Copyright =C2=A9 2010 The Johns Hopkins University/Applied Physics=20 + * Laboratory + + * This software was developed at The Johns Hopkins University/Applied=20 + * Physics Laboratory (=E2=80=9CJHU/APL=E2=80=9D) that is the author the= reof under the=20 + * =E2=80=9Cwork made for hire=E2=80=9D provisions of the copyright law.= Permission is=20 + * hereby granted, free of charge, to any person obtaining a copy of thi= s=20 + * software and associated documentation (the =E2=80=9CSoftware=E2=80=9D= ), to use the=20 + * Software without restriction, including without limitation the rights= to=20 + * copy, modify, merge, publish, distribute, sublicense, and/or sell cop= ies=20 + * of the Software, and to permit others to do so, subject to the follow= ing=20 + * conditions: + + * 1. This LICENSE AND DISCLAIMER, including the copyright notice, shal= l=20 + * be included in all copies of the Software, including copies of=20 + * substantial portions of the Software;=20 + + * 2. JHU/APL assumes no obligation to provide support of any kind with= =20 + * regard to the Software. This includes no obligation to provide assis= tance=20 + * in using the Software nor to provide updated versions of the Software= ; and + + * 3. THE SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT= ANY=20 + * EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES INCLUDING, = BUT=20 + * NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS FOR A PARTICULA= R=20 + * PURPOSE, AND NONINFRINGEMENT ARE HEREBY DISCLAIMED. USERS ASSUME THE= =20 + * ENTIRE RISK AND LIABILITY OF USING THE SOFTWARE. USERS ARE ADVISED T= O=20 + * TEST THE SOFTWARE THOROUGHLY BEFORE RELYING ON IT. IN NO EVENT SHALL= THE=20 + * JOHNS HOPKINS UNIVERSITY BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUD= ING,=20 + * WITHOUT LIMITATION, ANY LOST PROFITS, LOST SAVINGS OR OTHER INCIDENTA= L OR=20 + * CONSEQUENTIAL DAMAGES, ARISING OUT OF THE USE OR INABILITY TO USE THE= =20 + * SOFTWARE. + */ + +#include +#include "tpm_emulator_config.h" +#include "vtpmblk.h" +#include "tpm/tpm_marshalling.h" +#include "vtpm_cmd.h" +#include "polarssl/aes.h" +#include "polarssl/sha1.h" +#include +#include +#include +#include + +/*Encryption key and block sizes */ +#define BLKSZ 16 + +static struct blkfront_dev* blkdev =3D NULL; +static int blkfront_fd =3D -1; + +int init_vtpmblk(struct tpmfront_dev* tpmfront_dev)=20 +{ + struct blkfront_info blkinfo; + info("Initializing persistent NVM storage\n"); + + if((blkdev =3D init_blkfront(NULL, &blkinfo)) =3D=3D NULL) { + error("BLKIO: ERROR Unable to initialize blkfront"); + return -1; + } + if (blkinfo.info & VDISK_READONLY || blkinfo.mode !=3D O_RDWR) { + error("BLKIO: ERROR block device is read only!"); + goto error; + } + if((blkfront_fd =3D blkfront_open(blkdev)) =3D=3D -1) { + error("Unable to open blkfront file descriptor!"); + goto error; + } + + return 0; +error: + shutdown_blkfront(blkdev); + blkdev =3D NULL; + return -1; +} + +void shutdown_vtpmblk(void) +{ + close(blkfront_fd); + blkfront_fd =3D -1; + blkdev =3D NULL; +} + +int write_vtpmblk_raw(uint8_t *data, size_t data_length) +{ + int rc; + uint32_t lenbuf; + debug("Begin Write data=3D%p len=3D%u", data, data_length); + + lenbuf =3D cpu_to_be32((uint32_t)data_length); + + lseek(blkfront_fd, 0, SEEK_SET); + if((rc =3D write(blkfront_fd, (uint8_t*)&lenbuf, 4)) !=3D 4) { + error("write(length) failed! error was %s", strerror(errno)); + return -1; + } + if((rc =3D write(blkfront_fd, data, data_length)) !=3D data_length) {= + error("write(data) failed! error was %s", strerror(errno)); + return -1; + } + + info("Wrote %u bytes to NVM persistent storage", data_length); + + return 0; +} + +int read_vtpmblk_raw(uint8_t **data, size_t *data_length) +{ + int rc; + uint32_t lenbuf; + + lseek(blkfront_fd, 0, SEEK_SET); + if(( rc =3D read(blkfront_fd, (uint8_t*)&lenbuf, 4)) !=3D 4) { + error("read(length) failed! error was %s", strerror(errno)); + return -1; + } + *data_length =3D (size_t) cpu_to_be32(lenbuf); + if(*data_length =3D=3D 0) { + error("read 0 data_length for NVM"); + return -1; + } + + *data =3D tpm_malloc(*data_length); + if((rc =3D read(blkfront_fd, *data, *data_length)) !=3D *data_length)= { + error("read(data) failed! error was %s", strerror(errno)); + return -1; + } + + info("Read %u bytes from NVM persistent storage", *data_length); + return 0; +} + +int encrypt_vtpmblk(uint8_t* clear, size_t clear_len, uint8_t** cipher, = size_t* cipher_len, uint8_t* symkey) +{ + int rc =3D 0; + uint8_t iv[BLKSZ]; + aes_context aes_ctx; + UINT32 temp; + int mod; + + uint8_t* clbuf =3D NULL; + + uint8_t* ivptr; + int ivlen; + + uint8_t* cptr; //Cipher block pointer + int clen; //Cipher block length + + /*Create a new 256 bit encryption key */ + if(symkey =3D=3D NULL) { + rc =3D -1; + goto abort_egress; + } + tpm_get_extern_random_bytes(symkey, NVMKEYSZ); + + /*Setup initialization vector - random bits and then 4 bytes clear te= xt size at the end*/ + temp =3D sizeof(UINT32); + ivlen =3D BLKSZ - temp; + tpm_get_extern_random_bytes(iv, ivlen); + ivptr =3D iv + ivlen; + tpm_marshal_UINT32(&ivptr, &temp, (UINT32) clear_len); + + /*The clear text needs to be padded out to a multiple of BLKSZ */ + mod =3D clear_len % BLKSZ; + clen =3D mod ? clear_len + BLKSZ - mod : clear_len; + clbuf =3D malloc(clen); + if (clbuf =3D=3D NULL) { + rc =3D -1; + goto abort_egress; + } + memcpy(clbuf, clear, clear_len); + /* zero out the padding bits - FIXME: better / more secure way to han= dle these? */ + if(clen - clear_len) { + memset(clbuf + clear_len, 0, clen - clear_len); + } + + /* Setup the ciphertext buffer */ + *cipher_len =3D BLKSZ + clen; /*iv + ciphertext */ + cptr =3D *cipher =3D malloc(*cipher_len); + if (*cipher =3D=3D NULL) { + rc =3D -1; + goto abort_egress; + } + + /* Copy the IV to cipher text blob*/ + memcpy(cptr, iv, BLKSZ); + cptr +=3D BLKSZ; + + /* Setup encryption */ + aes_setkey_enc(&aes_ctx, symkey, 256); + + /* Do encryption now */ + aes_crypt_cbc(&aes_ctx, AES_ENCRYPT, clear_len, iv, clbuf, cptr); + + goto egress; +abort_egress: +egress: + free(clbuf); + return rc; +} +int decrypt_vtpmblk(uint8_t* cipher, size_t cipher_len, uint8_t** clear,= size_t* clear_len, uint8_t* symkey) +{ + int rc =3D 0; + uint8_t iv[BLKSZ]; + uint8_t* ivptr; + UINT32 u32, temp; + aes_context aes_ctx; + + uint8_t* cptr =3D cipher; //cipher block pointer + int clen =3D cipher_len; //cipher block length + + /* Pull out the initialization vector */ + memcpy(iv, cipher, BLKSZ); + cptr +=3D BLKSZ; + clen -=3D BLKSZ; + + /* Setup the clear text buffer */ + if((*clear =3D malloc(clen)) =3D=3D NULL) { + rc =3D -1; + goto abort_egress; + } + + /* Get the length of clear text from last 4 bytes of iv */ + temp =3D sizeof(UINT32); + ivptr =3D iv + BLKSZ - temp; + tpm_unmarshal_UINT32(&ivptr, &temp, &u32); + *clear_len =3D u32; + + /* Setup decryption */ + aes_setkey_dec(&aes_ctx, symkey, 256); + + /* Do decryption now */ + if ((clen % BLKSZ) !=3D 0) { + error("Decryption Error: Cipher block size was not a multiple of %= u", BLKSZ); + rc =3D -1; + goto abort_egress; + } + aes_crypt_cbc(&aes_ctx, AES_DECRYPT, clen, iv, cptr, *clear); + + /* Chop off extra block padding bits */ + *clear =3D realloc(*clear, *clear_len); + + goto egress; +abort_egress: +egress: + return rc; +} + +int write_vtpmblk(struct tpmfront_dev* tpmfront_dev, uint8_t* data, size= _t data_length) { + int rc; + uint8_t* cipher =3D NULL; + size_t cipher_len =3D 0; + uint8_t hashkey[HASHKEYSZ]; + uint8_t* symkey =3D hashkey + HASHSZ; + + /* Encrypt the data */ + if((rc =3D encrypt_vtpmblk(data, data_length, &cipher, &cipher_len, s= ymkey))) { + goto abort_egress; + } + /* Write to disk */ + if((rc =3D write_vtpmblk_raw(cipher, cipher_len))) { + goto abort_egress; + } + /* Get sha1 hash of data */ + sha1(cipher, cipher_len, hashkey); + + /* Send hash and key to manager */ + if((rc =3D VTPM_SaveHashKey(tpmfront_dev, hashkey, HASHKEYSZ)) !=3D T= PM_SUCCESS) { + goto abort_egress; + } + goto egress; +abort_egress: +egress: + free(cipher); + return rc; +} + +int read_vtpmblk(struct tpmfront_dev* tpmfront_dev, uint8_t** data, size= _t *data_length) { + int rc; + uint8_t* cipher =3D NULL; + size_t cipher_len =3D 0; + size_t keysize; + uint8_t* hashkey =3D NULL; + uint8_t hash[HASHSZ]; + uint8_t* symkey; + + /* Retreive the hash and the key from the manager */ + if((rc =3D VTPM_LoadHashKey(tpmfront_dev, &hashkey, &keysize)) !=3D T= PM_SUCCESS) { + goto abort_egress; + } + if(keysize !=3D HASHKEYSZ) { + error("Manager returned a hashkey of invalid size! expected %d, ac= tual %d", NVMKEYSZ, keysize); + rc =3D -1; + goto abort_egress; + } + symkey =3D hashkey + HASHSZ; + + /* Read from disk now */ + if((rc =3D read_vtpmblk_raw(&cipher, &cipher_len))) { + goto abort_egress; + } + + /* Compute the hash of the cipher text and compare */ + sha1(cipher, cipher_len, hash); + if(memcmp(hash, hashkey, HASHSZ)) { + int i; + error("NVM Storage Checksum failed!"); + printf("Expected: "); + for(i =3D 0; i < HASHSZ; ++i) { + printf("%02hhX ", hashkey[i]); + } + printf("\n"); + printf("Actual: "); + for(i =3D 0; i < HASHSZ; ++i) { + printf("%02hhX ", hash[i]); + } + printf("\n"); + rc =3D -1; + goto abort_egress; + } + + /* Decrypt the blob */ + if((rc =3D decrypt_vtpmblk(cipher, cipher_len, data, data_length, sym= key))) { + goto abort_egress; + } + goto egress; +abort_egress: +egress: + free(cipher); + free(hashkey); + return rc; +} + diff -Naur xen-unstable-trp-sdp-pristine/stubdom/vtpm/vtpmblk.h xen-unsta= ble-trp-sdp/stubdom/vtpm/vtpmblk.h --- xen-unstable-trp-sdp-pristine/stubdom/vtpm/vtpmblk.h 1969-12-31 19:00= :00.000000000 -0500 +++ xen-unstable-trp-sdp/stubdom/vtpm/vtpmblk.h 2011-02-23 19:40:48.00000= 0000 -0500 @@ -0,0 +1,54 @@ +/* LICENSE AND DISCLAIMER + * + * Copyright =C2=A9 2010 The Johns Hopkins University/Applied Physics=20 + * Laboratory + + * This software was developed at The Johns Hopkins University/Applied=20 + * Physics Laboratory (=E2=80=9CJHU/APL=E2=80=9D) that is the author the= reof under the=20 + * =E2=80=9Cwork made for hire=E2=80=9D provisions of the copyright law.= Permission is=20 + * hereby granted, free of charge, to any person obtaining a copy of thi= s=20 + * software and associated documentation (the =E2=80=9CSoftware=E2=80=9D= ), to use the=20 + * Software without restriction, including without limitation the rights= to=20 + * copy, modify, merge, publish, distribute, sublicense, and/or sell cop= ies=20 + * of the Software, and to permit others to do so, subject to the follow= ing=20 + * conditions: + + * 1. This LICENSE AND DISCLAIMER, including the copyright notice, shal= l=20 + * be included in all copies of the Software, including copies of=20 + * substantial portions of the Software;=20 + + * 2. JHU/APL assumes no obligation to provide support of any kind with= =20 + * regard to the Software. This includes no obligation to provide assis= tance=20 + * in using the Software nor to provide updated versions of the Software= ; and + + * 3. THE SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT= ANY=20 + * EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES INCLUDING, = BUT=20 + * NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS FOR A PARTICULA= R=20 + * PURPOSE, AND NONINFRINGEMENT ARE HEREBY DISCLAIMED. USERS ASSUME THE= =20 + * ENTIRE RISK AND LIABILITY OF USING THE SOFTWARE. USERS ARE ADVISED T= O=20 + * TEST THE SOFTWARE THOROUGHLY BEFORE RELYING ON IT. IN NO EVENT SHALL= THE=20 + * JOHNS HOPKINS UNIVERSITY BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUD= ING,=20 + * WITHOUT LIMITATION, ANY LOST PROFITS, LOST SAVINGS OR OTHER INCIDENTA= L OR=20 + * CONSEQUENTIAL DAMAGES, ARISING OUT OF THE USE OR INABILITY TO USE THE= =20 + * SOFTWARE. + */ + +#ifndef NVM_H +#define NVM_H +#include +#include +#include + +#define NVMKEYSZ 32 +#define HASHSZ 20 +#define HASHKEYSZ (NVMKEYSZ + HASHSZ) + +int init_vtpmblk(struct tpmfront_dev* tpmfront_dev); +void shutdown_vtpmblk(void); + +/* Encrypts and writes data to blk device */ +int write_vtpmblk(struct tpmfront_dev* tpmfront_dev, uint8_t *data, size= _t data_length); +/* Reads, Decrypts, and returns data from blk device */ +int read_vtpmblk(struct tpmfront_dev* tpmfront_dev, uint8_t **data, size= _t *data_length); + +#endif diff -Naur xen-unstable-trp-sdp-pristine/stubdom/vtpm/vtpm.c xen-unstable= -trp-sdp/stubdom/vtpm/vtpm.c --- xen-unstable-trp-sdp-pristine/stubdom/vtpm/vtpm.c 1969-12-31 19:00:00= =2E000000000 -0500 +++ xen-unstable-trp-sdp/stubdom/vtpm/vtpm.c 2011-02-23 19:40:48.00000000= 0 -0500 @@ -0,0 +1,415 @@ +/* LICENSE AND DISCLAIMER + * + * Copyright =C2=A9 2010 The Johns Hopkins University/Applied Physics=20 + * Laboratory + + * This software was developed at The Johns Hopkins University/Applied=20 + * Physics Laboratory (=E2=80=9CJHU/APL=E2=80=9D) that is the author the= reof under the=20 + * =E2=80=9Cwork made for hire=E2=80=9D provisions of the copyright law.= Permission is=20 + * hereby granted, free of charge, to any person obtaining a copy of thi= s=20 + * software and associated documentation (the =E2=80=9CSoftware=E2=80=9D= ), to use the=20 + * Software without restriction, including without limitation the rights= to=20 + * copy, modify, merge, publish, distribute, sublicense, and/or sell cop= ies=20 + * of the Software, and to permit others to do so, subject to the follow= ing=20 + * conditions: + + * 1. This LICENSE AND DISCLAIMER, including the copyright notice, shal= l=20 + * be included in all copies of the Software, including copies of=20 + * substantial portions of the Software;=20 + + * 2. JHU/APL assumes no obligation to provide support of any kind with= =20 + * regard to the Software. This includes no obligation to provide assis= tance=20 + * in using the Software nor to provide updated versions of the Software= ; and + + * 3. THE SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT= ANY=20 + * EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES INCLUDING, = BUT=20 + * NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS FOR A PARTICULA= R=20 + * PURPOSE, AND NONINFRINGEMENT ARE HEREBY DISCLAIMED. USERS ASSUME THE= =20 + * ENTIRE RISK AND LIABILITY OF USING THE SOFTWARE. USERS ARE ADVISED T= O=20 + * TEST THE SOFTWARE THOROUGHLY BEFORE RELYING ON IT. IN NO EVENT SHALL= THE=20 + * JOHNS HOPKINS UNIVERSITY BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUD= ING,=20 + * WITHOUT LIMITATION, ANY LOST PROFITS, LOST SAVINGS OR OTHER INCIDENTA= L OR=20 + * CONSEQUENTIAL DAMAGES, ARISING OUT OF THE USE OR INABILITY TO USE THE= =20 + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "tpm_emulator_config.h" +#include "tpm/tpm_emulator.h" +#include "vtpm.h" +#include "vtpm_cmd.h" +#include "vtpmblk.h" + +//FIXME: 0.6.1 hacks +#define TPM_LOG_INFO LOG_INFO +#define TPM_LOG_ERROR LOG_ERR +#define TPM_LOG_DEBUG LOG_DEBUG + +/* Global commandline options - default values */ +struct Opt_args opt_args =3D { + .mode =3D MODE_PVM, + .startup =3D ST_CLEAR, + .loglevel =3D TPM_LOG_INFO, + .entropysrc =3D ENT_TPM, + .tpmconf =3D 0, + .exclusive_uuids =3D NULL +}; + +struct tpmfront_dev* tpmfront_dev; + +void get_rand_bytes_rand(uint8_t* buf, size_t nbytes)=20 +{ + int r, i; + while (nbytes > 0) { + r =3D rand(); + for(i =3D sizeof(int); i > 0 && nbytes > 0; --i) { + --nbytes; + buf[nbytes] =3D ((uint8_t*)&r)[i]; + } + } +} + +void tpm_get_extern_random_bytes(void *buf, size_t nbytes) +{ + switch(opt_args.entropysrc) { + case ENT_TPM: + VTPM_GetRandom(tpmfront_dev, buf, nbytes); + break; + case ENT_RAND: + get_rand_bytes_rand(buf, nbytes); + break; + default: + break; + } +} + +int tpm_read_from_file(uint8_t **data, size_t *data_length) { + return read_vtpmblk(tpmfront_dev, data, data_length); +} + +int tpm_write_to_file(uint8_t *data, size_t data_length) { + return write_vtpmblk(tpmfront_dev, data, data_length); +} + +int tpm_extern_init_fake(void) { + return 0; +} + +void tpm_extern_release_fake(void) { +} + + +void *vtpm_malloc(size_t size) +{ + return malloc(size); +} + +void vtpm_free(/*const*/ void *ptr) +{ + if (ptr !=3D NULL) free((void*)ptr); +} + +uint64_t tpm_get_ticks(void) +{ + static uint64_t old_t =3D 0; + uint64_t new_t, res_t; + struct timeval tv; + gettimeofday(&tv, NULL); + new_t =3D (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec; + res_t =3D (old_t > 0) ? new_t - old_t : 0; + old_t =3D new_t; + return res_t; +} + + +void tpm_log(int priority, const char *fmt, ...) +{ + if(opt_args.loglevel >=3D priority) { + va_list v; + va_start(v, fmt); + vprintf(fmt, v); + va_end(v); + } +}=20 + + +int init_random(void) { + int rc; + unsigned int seed =3D 0; + + if((rc =3D VTPM_GetRandom(tpmfront_dev, (BYTE*)&seed, sizeof(seed))))= { + error("VTPM_GetRandom failed with error code %d", rc); + return rc; + } + srand(seed); + + info("Seeded the RNG with %lu bytes of entropy", (unsigned long) size= of(seed)); + return 0; + +} + +static void main_loop(void) { + tpmcmd_t* tpmcmd =3D NULL; + domid_t domid; /* Domid of frontend */ + unsigned int handle; /* handle of frontend */ + uint8_t* out; + uint32_t out_len; + int res =3D -1; + + info("VTPM Initializing\n"); + /* Set require tpm config args */ +#if 0 + opt_args.tpmconf |=3D TPM_CONF_STRONG_PERSISTENCE; + opt_args.tpmconf &=3D ~TPM_CONF_USE_INTERNAL_PRNG; + opt_args.tpmconf |=3D TPM_CONF_GENERATE_EK; + opt_args.tpmconf |=3D TPM_CONF_GENERATE_SEED_DAA; +#endif + /* Initialize the emulator */ + tpm_emulator_init(opt_args.startup); + + /* Wait for the frontend domain to connect */ + info("Waiting for frontend domain to connect.."); + if(tpmback_wait_for_frontend_connect(&domid, &handle) =3D=3D 0) { + info("VTPM attached to Frontend %u/%u", (unsigned int) domid, hand= le); + } else { + error("Unable to attach to a frontend"); + } + + tpmcmd =3D tpmback_req(domid, handle); + while(tpmcmd) { + /* Handle the request */ + if(tpmcmd->req_len) { + out =3D NULL; + out_len =3D 0; + res =3D tpm_handle_command(tpmcmd->req, tpmcmd->req_len, &out, &out_le= n); + if(res < 0) { + error("tpm_handle_command() failed"); + } + else=20 + { + tpmcmd->resp =3D out; + tpmcmd->resp_len =3D out_len; + } + }=20 + + /* Send the response */ + tpmback_resp(tpmcmd); + + /* Free the out buffer if it was allocated */ + if(tpmcmd->req_len && res >=3D 0) { + tpm_free(out); + } + + /* Wait for the next request */ + tpmcmd =3D tpmback_req(domid, handle); + + } + + info("VTPM Shutting down\n"); + + tpm_emulator_shutdown(); +} + +int parse_cmd_line(int argc, char** argv) +{ + char sval[25]; + char* logstr =3D NULL; + /* Parse the command strings */ + for(unsigned int i =3D 1; i < argc; ++i) { + if (sscanf(argv[i], "loglevel=3D%25s", sval) =3D=3D 1){ + if (!strcmp(sval, "debug")) { + opt_args.loglevel =3D TPM_LOG_DEBUG; + logstr =3D "debug"; + } + else if (!strcmp(sval, "info")) { + logstr =3D "info"; + opt_args.loglevel =3D TPM_LOG_INFO; + } + else if (!strcmp(sval, "error")) { + logstr =3D "error"; + opt_args.loglevel =3D TPM_LOG_ERROR; + } + } + else if (!strcmp(argv[i], "pvm")) { + opt_args.mode =3D MODE_PVM; + } + else if (!strcmp(argv[i], "hvm")) { + opt_args.mode =3D MODE_HVM; + } + else if (!strcmp(argv[i], "clear")) { + opt_args.startup =3D ST_CLEAR; + } + else if (!strcmp(argv[i], "save")) { + opt_args.startup =3D ST_SAVE; + } + else if (!strcmp(argv[i], "deactivated")) { + opt_args.startup =3D ST_DEACTIVATED; + } + else if (!strncmp(argv[i], "entropysrc=3D", 11)) { + if (!strcmp(argv[i] + 11, "tpm")) { + opt_args.entropysrc =3D ENT_TPM; + }=20 + else if (!strcmp(argv[i] + 11, "rand")) { + opt_args.entropysrc =3D ENT_RAND; + } + } + else if (!strncmp(argv[i], "tpmconf=3D", 8)) { + opt_args.tpmconf =3D strtol(argv[i] + 8, NULL, 0); + } + else if (!strncmp(argv[i], "hostuuids=3D", 10)) { + char* uuid; + int num_alloc =3D 4; + int num_uuids =3D 0; + opt_args.exclusive_uuids =3D malloc(sizeof(char*) * num_alloc); + opt_args.exclusive_uuids[0] =3D NULL; + + uuid =3D strtok(argv[i] + 10, ","); + while(uuid !=3D NULL) { + if(num_uuids + 1 =3D=3D num_alloc) { + num_alloc*=3D2; + opt_args.exclusive_uuids =3D realloc(opt_args.exclusive_uuids, n= um_alloc); + } + opt_args.exclusive_uuids[num_uuids] =3D uuid; + opt_args.exclusive_uuids[num_uuids+1] =3D NULL; + ++num_uuids; + uuid =3D strtok(NULL, ","); + } + } + else { + error("Invalid command line option `%s'", argv[i]); + } + + } + + /* Check Errors and print results */ + switch (opt_args.mode) { + case MODE_HVM: + error("hvm mode is not currently supported!"); + return -1; + break; + case MODE_PVM: + info("Running in pvm mode"); + break; + default: + error("Mode not specified! You must specify either pvm or hvm on the c= ommand line"); + return -1; + } + + switch(opt_args.startup) { + case ST_CLEAR: + info("Startup mode is `clear'"); + break; + case ST_SAVE: + info("Startup mode is `save'"); + break; + case ST_DEACTIVATED: + info("Startup mode is `deactivated'"); + break; + default: + error("Invalid startup mode %d", opt_args.startup); + return -1; + } + + switch(opt_args.entropysrc) + { + case ENT_TPM: + info("Will use Hardware TPM for entropy source"); + break; + case ENT_RAND: + info("Will use rand() for entropy source"); + break; + default: + error("Invalid entropy source %d", opt_args.entropysrc); + return -1; + } + + if(opt_args.exclusive_uuids !=3D NULL) { + char** ptr; + info("Exclusive Host UUIDs set:"); + for(ptr =3D opt_args.exclusive_uuids; *ptr !=3D NULL; ++ptr) { + info("\t%s", *ptr); + } + } + + info("Log level set to %s", logstr); + + return 0; +} + +void cleanup_opt_args(void) { + if(opt_args.exclusive_uuids !=3D NULL) { + free(opt_args.exclusive_uuids); + } +} + +int main(int argc, char **argv) +{ + //FIXME: initializing blkfront without this sleep causes the domain t= o crash on boot + sleep(2); + +#if 0 //Disable for 0.6.1 + /* Setup extern function pointers */ + tpm_extern_init =3D tpm_extern_init_fake; + tpm_extern_release =3D tpm_extern_release_fake; + tpm_malloc =3D vtpm_malloc; + tpm_free =3D vtpm_free; + tpm_log =3D vtpm_log; + tpm_get_extern_random_bytes =3D vtpm_get_extern_random_bytes; + tpm_get_ticks =3D vtpm_get_ticks; + tpm_write_to_storage =3D vtpm_write_to_file; + tpm_read_from_storage =3D vtpm_read_from_file; +#endif + + info("starting TPM Emulator (1.2.%s.%s-%s)", TPM_STR(VERSION_MAJOR), = TPM_STR(VERSION_MINOR), TPM_STR(VERSION_BUILD)); + if(parse_cmd_line(argc, argv)) { + error("Error parsing commandline\n"); + return -1; + } + + /* Initialize devices */ + init_tpmback(opt_args.exclusive_uuids); + if((tpmfront_dev =3D init_tpmfront(NULL)) =3D=3D NULL) { + error("Unable to initialize tpmfront device"); + goto abort_posttpmfront; + } + + /* Seed the RNG with entropy from hardware TPM */ + if(init_random()) { + error("Unable to initialize RNG"); + goto abort_postrng; + } + + /* Initialize blkfront device */ + if(init_vtpmblk(tpmfront_dev)) { + error("Unable to initialize Blkfront persistent storage"); + goto abort_postvtpmblk; + } + + /* Run main loop */ + main_loop(); + + /* Shutdown blkfront */ + shutdown_vtpmblk(); +abort_postvtpmblk: +abort_postrng: + + /* Close devices */ + shutdown_tpmfront(tpmfront_dev); +abort_posttpmfront: + shutdown_tpmback(); + + cleanup_opt_args(); + + return 0; +} diff -Naur xen-unstable-trp-sdp-pristine/stubdom/vtpm/vtpm_cmd.c xen-unst= able-trp-sdp/stubdom/vtpm/vtpm_cmd.c --- xen-unstable-trp-sdp-pristine/stubdom/vtpm/vtpm_cmd.c 1969-12-31 19:0= 0:00.000000000 -0500 +++ xen-unstable-trp-sdp/stubdom/vtpm/vtpm_cmd.c 2011-02-23 19:40:48.0000= 00000 -0500 @@ -0,0 +1,217 @@ +/* LICENSE AND DISCLAIMER + * + * Copyright =C2=A9 2010 The Johns Hopkins University/Applied Physics=20 + * Laboratory + + * This software was developed at The Johns Hopkins University/Applied=20 + * Physics Laboratory (=E2=80=9CJHU/APL=E2=80=9D) that is the author the= reof under the=20 + * =E2=80=9Cwork made for hire=E2=80=9D provisions of the copyright law.= Permission is + * hereby granted, free of charge, to any person obtaining a copy of thi= s=20 + * software and associated documentation (the =E2=80=9CSoftware=E2=80=9D= ), to use the=20 + * Software without restriction, including without limitation the rights= to=20 + * copy, modify, merge, publish, distribute, sublicense, and/or sell cop= ies=20 + * of the Software, and to permit others to do so, subject to the follow= ing=20 + * conditions: + + * 1. This LICENSE AND DISCLAIMER, including the copyright notice, shal= l=20 + * be included in all copies of the Software, including copies of=20 + * substantial portions of the Software;=20 + + * 2. JHU/APL assumes no obligation to provide support of any kind with= =20 + * regard to the Software. This includes no obligation to provide assis= tance=20 + * in using the Software nor to provide updated versions of the Software= ; and + + * 3. THE SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT= ANY=20 + * EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES INCLUDING, = BUT=20 + * NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS FOR A PARTICULA= R=20 + * PURPOSE, AND NONINFRINGEMENT ARE HEREBY DISCLAIMED. USERS ASSUME THE= =20 + * ENTIRE RISK AND LIABILITY OF USING THE SOFTWARE. USERS ARE ADVISED T= O=20 + * TEST THE SOFTWARE THOROUGHLY BEFORE RELYING ON IT. IN NO EVENT SHALL= THE=20 + * JOHNS HOPKINS UNIVERSITY BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUD= ING,=20 + * WITHOUT LIMITATION, ANY LOST PROFITS, LOST SAVINGS OR OTHER INCIDENTA= L OR=20 + * CONSEQUENTIAL DAMAGES, ARISING OUT OF THE USE OR INABILITY TO USE THE= =20 + * SOFTWARE. + */ + +#include +#include +#include +#include +#include "tpm/tpm_marshalling.h" +#include +#include "vtpm_cmd.h" + +#define TRYFAILGOTO(C) \ + if((C)) { \ + status =3D TPM_FAIL; \ + goto abort_egress; \ + } +#define TRYFAILGOTOMSG(C, msg) \ + if((C)) { \ + status =3D TPM_FAIL; \ + error(msg); \ + goto abort_egress; \ + } +#define CHECKSTATUSGOTO(ret, fname) \ + if((ret) !=3D TPM_SUCCESS) { \ + error("%s failed with error code (%lu)", fname, (unsigned long) re= t); \ + status =3D ord; \ + goto abort_egress; \ + } + +#define ERR_MALFORMED "Malformed response from backend" +#define ERR_TPMFRONT "Error sending command through frontend device" + +struct shpage { + void* page; + grant_ref_t grantref; +}; + +typedef struct shpage shpage_t; + +static inline int pack_header(uint8_t** bptr, UINT32* len, TPM_TAG tag, = UINT32 size, TPM_COMMAND_CODE ord)=20 +{ + return *bptr =3D=3D NULL ||=20 + tpm_marshal_UINT16(bptr, len, tag) ||=20 + tpm_marshal_UINT32(bptr, len, size) ||=20 + tpm_marshal_UINT32(bptr, len, ord); +} + +static inline int unpack_header(uint8_t** bptr, UINT32* len, TPM_TAG* ta= g, UINT32* size, TPM_COMMAND_CODE* ord)=20 +{ + return *bptr =3D=3D NULL || + tpm_unmarshal_UINT16(bptr, len, tag) || + tpm_unmarshal_UINT32(bptr, len, size) || + tpm_unmarshal_UINT32(bptr, len, ord); +} + +TPM_RESULT VTPM_GetRandom(struct tpmfront_dev* tpmfront_dev, BYTE* bytes= , UINT32 numbytes) { + TPM_RESULT status =3D TPM_SUCCESS; + uint8_t* cmdbuf, *resp, *bptr; + size_t resplen =3D 0; + UINT32 len; + + /*Ask the real tpm for random bytes for the seed */ + TPM_TAG tag =3D TPM_TAG_RQU_COMMAND; + UINT32 size; + TPM_COMMAND_CODE ord =3D TPM_ORD_GetRandom; + len =3D size =3D sizeof(TPM_TAG) + sizeof(UINT32) + sizeof(TPM_COMMAN= D_CODE) + sizeof(UINT32); + + /*Create the raw tpm command */ + bptr =3D cmdbuf =3D malloc(size); + TRYFAILGOTO(pack_header(&bptr, &len, tag, size, ord)); + TRYFAILGOTO(tpm_marshal_UINT32(&bptr, &len, numbytes)); + + /* Send cmd, wait for response */ + TRYFAILGOTOMSG(tpmfront_cmd(tpmfront_dev, cmdbuf, size, &resp, &respl= en),=20 + ERR_TPMFRONT); + + bptr =3D resp; len =3D resplen; + TRYFAILGOTOMSG(unpack_header(&bptr, &len, &tag, &size, &ord), ERR_MAL= FORMED); + + //Check return status of command + CHECKSTATUSGOTO(ord, "TPM_GetRandom()"); + + // Get the number of random bytes in the response + TRYFAILGOTOMSG(tpm_unmarshal_UINT32(&bptr, &len, &size), ERR_MALFORME= D); + + /* FIXME: Does this ever really happen? */ + if(size !=3D numbytes) { + error("TPM_GetRandom() returned insufficient number of bytes!"); + status =3D TPM_FAIL; + goto abort_egress; + } + + //Get the random bytes out, tpm may give us less bytes than what we w= anrt + TRYFAILGOTOMSG(tpm_unmarshal_BYTE_ARRAY(&bptr, &len, bytes, numbytes)= , ERR_MALFORMED); + + goto egress; +abort_egress: +egress: + free(cmdbuf); + return status; + +} + +TPM_RESULT VTPM_LoadHashKey(struct tpmfront_dev* tpmfront_dev, uint8_t**= data, size_t* data_length)=20 +{ + TPM_RESULT status =3D TPM_SUCCESS; + uint8_t* bptr, *resp; + uint8_t* cmdbuf =3D NULL; + size_t resplen =3D 0; + UINT32 len; + + TPM_TAG tag =3D VTPM_TAG_REQ; + UINT32 size; + TPM_COMMAND_CODE ord =3D VTPM_ORD_LOADHASHKEY; + + /*Create the command*/ + len =3D size =3D VTPM_COMMAND_HEADER_SIZE_CLT; + bptr =3D cmdbuf =3D malloc(size); + TRYFAILGOTO(pack_header(&bptr, &len, tag, size, ord)); + + /* Send the command to vtpm_manager */ + info("Requesting Encryption key from backend"); + TRYFAILGOTOMSG(tpmfront_cmd(tpmfront_dev, cmdbuf, size, &resp, &respl= en), ERR_TPMFRONT); + + /* Unpack response header */ + bptr =3D resp; + len =3D resplen; + TRYFAILGOTOMSG(unpack_header(&bptr, &len, &tag, &size, &ord), ERR_MAL= FORMED); + + /* Check return code */ + CHECKSTATUSGOTO(ord, "VTPM_LoadHashKey()"); + + /* Get the size of the key */ + *data_length =3D size - VTPM_COMMAND_HEADER_SIZE_CLT; + + /* Copy the key bits */ + *data =3D malloc(*data_length); + memcpy(*data, bptr, *data_length); + + goto egress; +abort_egress: + error("VTPM_LoadHashKey failed"); +egress: + free(cmdbuf); + return status; +} + +TPM_RESULT VTPM_SaveHashKey(struct tpmfront_dev* tpmfront_dev, uint8_t* = data, size_t data_length)=20 +{ + TPM_RESULT status =3D TPM_SUCCESS; + uint8_t* bptr, *resp; + uint8_t* cmdbuf =3D NULL; + size_t resplen =3D 0; + UINT32 len; + + TPM_TAG tag =3D VTPM_TAG_REQ; + UINT32 size; + TPM_COMMAND_CODE ord =3D VTPM_ORD_SAVEHASHKEY; + + /*Create the command*/ + len =3D size =3D VTPM_COMMAND_HEADER_SIZE_CLT + data_length; + bptr =3D cmdbuf =3D malloc(size); + TRYFAILGOTO(pack_header(&bptr, &len, tag, size, ord)); + memcpy(bptr, data, data_length); + bptr +=3D data_length; + + /* Send the command to vtpm_manager */ + info("Sending encryption key to backend"); + TRYFAILGOTOMSG(tpmfront_cmd(tpmfront_dev, cmdbuf, size, &resp, &respl= en), ERR_TPMFRONT); + + /* Unpack response header */ + bptr =3D resp; + len =3D resplen; + TRYFAILGOTOMSG(unpack_header(&bptr, &len, &tag, &size, &ord), ERR_MAL= FORMED); + + /* Check return code */ + CHECKSTATUSGOTO(ord, "VTPM_SaveHashKey()"); + + goto egress; +abort_egress: + error("VTPM_SaveHashKey failed"); +egress: + free(cmdbuf); + return status; +} diff -Naur xen-unstable-trp-sdp-pristine/stubdom/vtpm/vtpm_cmd.h xen-unst= able-trp-sdp/stubdom/vtpm/vtpm_cmd.h --- xen-unstable-trp-sdp-pristine/stubdom/vtpm/vtpm_cmd.h 1969-12-31 19:0= 0:00.000000000 -0500 +++ xen-unstable-trp-sdp/stubdom/vtpm/vtpm_cmd.h 2011-02-23 19:40:48.0000= 00000 -0500 @@ -0,0 +1,51 @@ +/* LICENSE AND DISCLAIMER + * + * Copyright =C2=A9 2010 The Johns Hopkins University/Applied Physics=20 + * Laboratory + + * This software was developed at The Johns Hopkins University/Applied=20 + * Physics Laboratory (=E2=80=9CJHU/APL=E2=80=9D) that is the author the= reof under the=20 + * =E2=80=9Cwork made for hire=E2=80=9D provisions of the copyright law.= Permission is=20 + * hereby granted, free of charge, to any person obtaining a copy of thi= s=20 + * software and associated documentation (the =E2=80=9CSoftware=E2=80=9D= ), to use the=20 + * Software without restriction, including without limitation the rights= to=20 + * copy, modify, merge, publish, distribute, sublicense, and/or sell cop= ies=20 + * of the Software, and to permit others to do so, subject to the follow= ing=20 + * conditions: + + * 1. This LICENSE AND DISCLAIMER, including the copyright notice, shal= l=20 + * be included in all copies of the Software, including copies of=20 + * substantial portions of the Software;=20 + + * 2. JHU/APL assumes no obligation to provide support of any kind with= =20 + * regard to the Software. This includes no obligation to provide assis= tance=20 + * in using the Software nor to provide updated versions of the Software= ; and + + * 3. THE SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT= ANY=20 + * EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES INCLUDING, = BUT=20 + * NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS FOR A PARTICULA= R=20 + * PURPOSE, AND NONINFRINGEMENT ARE HEREBY DISCLAIMED. USERS ASSUME THE= =20 + * ENTIRE RISK AND LIABILITY OF USING THE SOFTWARE. USERS ARE ADVISED T= O=20 + * TEST THE SOFTWARE THOROUGHLY BEFORE RELYING ON IT. IN NO EVENT SHALL= THE=20 + * JOHNS HOPKINS UNIVERSITY BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUD= ING,=20 + * WITHOUT LIMITATION, ANY LOST PROFITS, LOST SAVINGS OR OTHER INCIDENTA= L OR=20 + * CONSEQUENTIAL DAMAGES, ARISING OUT OF THE USE OR INABILITY TO USE THE= =20 + * SOFTWARE. + */ + +#ifndef MANAGER_H +#define MANAGER_H + +#include "tpm_emulator_config.h" +#include +#include "tpm/tpm_emulator.h" +#include "tpm/tpm_structures.h" + +/* Request random bytes from hardware tpm, returns 0 on success */ +TPM_RESULT VTPM_GetRandom(struct tpmfront_dev* tpmfront_dev, BYTE* bytes= , UINT32 numbytes); +/* Retreive 256 bit AES encryption key from manager */ +TPM_RESULT VTPM_LoadHashKey(struct tpmfront_dev* tpmfront_dev, uint8_t**= data, size_t* data_length); +/* Manager securely saves our 256 bit AES encryption key */ +TPM_RESULT VTPM_SaveHashKey(struct tpmfront_dev* tpmfront_dev, uint8_t* = data, size_t data_length); + +#endif diff -Naur xen-unstable-trp-sdp-pristine/stubdom/vtpm/vtpm.h xen-unstable= -trp-sdp/stubdom/vtpm/vtpm.h --- xen-unstable-trp-sdp-pristine/stubdom/vtpm/vtpm.h 1969-12-31 19:00:00= =2E000000000 -0500 +++ xen-unstable-trp-sdp/stubdom/vtpm/vtpm.h 2011-02-23 19:40:48.00000000= 0 -0500 @@ -0,0 +1,66 @@ +/* LICENSE AND DISCLAIMER + * + * Copyright =C2=A9 2010 The Johns Hopkins University/Applied Physics=20 + * Laboratory + + * This software was developed at The Johns Hopkins University/Applied=20 + * Physics Laboratory (=E2=80=9CJHU/APL=E2=80=9D) that is the author the= reof under the=20 + * =E2=80=9Cwork made for hire=E2=80=9D provisions of the copyright law.= Permission is=20 + * hereby granted, free of charge, to any person obtaining a copy of thi= s=20 + * software and associated documentation (the =E2=80=9CSoftware=E2=80=9D= ), to use the=20 + * Software without restriction, including without limitation the rights= to=20 + * copy, modify, merge, publish, distribute, sublicense, and/or sell cop= ies=20 + * of the Software, and to permit others to do so, subject to the follow= ing=20 + * conditions: + + * 1. This LICENSE AND DISCLAIMER, including the copyright notice, shal= l=20 + * be included in all copies of the Software, including copies of=20 + * substantial portions of the Software;=20 + + * 2. JHU/APL assumes no obligation to provide support of any kind with= =20 + * regard to the Software. This includes no obligation to provide assis= tance=20 + * in using the Software nor to provide updated versions of the Software= ; and + + * 3. THE SOFTWARE AND ITS DOCUMENTATION ARE PROVIDED AS IS AND WITHOUT= ANY=20 + * EXPRESS OR IMPLIED WARRANTIES WHATSOEVER. ALL WARRANTIES INCLUDING, = BUT=20 + * NOT LIMITED TO, PERFORMANCE, MERCHANTABILITY, FITNESS FOR A PARTICULA= R=20 + * PURPOSE, AND NONINFRINGEMENT ARE HEREBY DISCLAIMED. USERS ASSUME THE= =20 + * ENTIRE RISK AND LIABILITY OF USING THE SOFTWARE. USERS ARE ADVISED T= O=20 + * TEST THE SOFTWARE THOROUGHLY BEFORE RELYING ON IT. IN NO EVENT SHALL= THE=20 + * JOHNS HOPKINS UNIVERSITY BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUD= ING,=20 + * WITHOUT LIMITATION, ANY LOST PROFITS, LOST SAVINGS OR OTHER INCIDENTA= L OR=20 + * CONSEQUENTIAL DAMAGES, ARISING OUT OF THE USE OR INABILITY TO USE THE= =20 + * SOFTWARE. + */ + +#ifndef VTPM_H +#define VTPM_H + +/* For testing */ +#define VERS_CMD "\x00\xC1\x00\x00\x00\x16\x00\x00\x00\x65\x00\x00\x00\x= 05\x00\x00\x00\x04\x00\x00\x01\x03" +#define VERS_CMD_LEN 22 + +/* Global commandline options */ +struct Opt_args { + enum Mode{ + MODE_INVALID, + MODE_PVM, + MODE_HVM + } mode; + enum StartUp { + ST_CLEAR =3D 1, + ST_SAVE =3D 2, + ST_DEACTIVATED =3D 3 + } startup; + enum EntropySource { + ENT_TPM, + ENT_RAND + } entropysrc; + int loglevel; + int tpmconf; + char** exclusive_uuids; +}; +extern struct Opt_args opt_args; + +#endif + --------------000007050806000305080601-- --------------ms090807050006050001070206 Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" Content-Description: S/MIME Cryptographic Signature MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIHZzCC A5kwggMCoAMCAQICBD/xkcEwDQYJKoZIhvcNAQEFBQAwLzELMAkGA1UEBhMCVVMxDzANBgNV BAoTBkpIVUFQTDEPMA0GA1UECxMGQklTRENBMB4XDTA5MDcxNzE1MDgwOVoXDTEyMDcxNzE1 MzgwOVowZjELMAkGA1UEBhMCVVMxDzANBgNVBAoTBkpIVUFQTDEPMA0GA1UECxMGUGVvcGxl MTUwFgYDVQQLEw9WUE5Hcm91cC1CSVNEQ0EwGwYDVQQDExRNYXR0aGV3IEUgRmlvcmF2YW50 ZTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAyzeGk9zPA33fsB3uvk/Izs9GGHCpHI8b zXdBIVg6++S+jK53PoaWgmtSLr/c732ea1zPR6ACymwAWON+U5rB+VJAUZ4l/p0T3LZjE1Kq nbQJ+pgb+WAmBtdrxrtky61E9HD8dO70x37+ejhunpF9OuSU5MnOPmMx6ranvahUsOsCAwEA AaOCAYkwggGFMAsGA1UdDwQEAwIFIDAbBg0rBgEEAbMlCwMBAQEBBAoWCGZpb3JhbWUxMBsG DSsGAQQBsyULAwEBAQIEChIIMDAxMDQyNjEwWAYJYIZIAYb6ax4BBEsMSVRoZSBwcml2YXRl IGtleSBjb3JyZXNwb25kaW5nIHRvIHRoaXMgY2VydGlmaWNhdGUgbWF5IGhhdmUgYmVlbiBl eHBvcnRlZC4wKAYDVR0RBCEwH4EdTWF0dGhldy5GaW9yYXZhbnRlQGpodWFwbC5lZHUwUgYD VR0fBEswSTBHoEWgQ6RBMD8xCzAJBgNVBAYTAlVTMQ8wDQYDVQQKEwZKSFVBUEwxDzANBgNV BAsTBkJJU0RDQTEOMAwGA1UEAxMFQ1JMNDkwHwYDVR0jBBgwFoAUCDUpmxH52EU2CyWmF2EJ MB1yqeswHQYDVR0OBBYEFO3ziReJlElP3ilaLQ5gwsg0RlgoMAkGA1UdEwQCMAAwGQYJKoZI hvZ9B0EABAwwChsEVjcuMQMCBLAwDQYJKoZIhvcNAQEFBQADgYEAMOY3Zf6gx3gv/fDd11cz h2Daj+8NExx/2Le3c88gfDVhPVgVX5S52EjeFbK5yVP0Xlm82vRADO47dTA2PKbpp50rJcAZ rl5bg5tQ/WbLAaRITCtOJWVVKXD9V7X2o3Z/IM2op3hb4mmDXSDS+Hzn0Jd2mAXl4iHPfI0p XlXqA9QwggPGMIIDL6ADAgECAgQ/8cn9MA0GCSqGSIb3DQEBBQUAMC8xCzAJBgNVBAYTAlVT MQ8wDQYDVQQKEwZKSFVBUEwxDzANBgNVBAsTBkJJU0RDQTAeFw0xMDA2MTExODIyMDZaFw0x MzA2MTExODUyMDZaMGYxCzAJBgNVBAYTAlVTMQ8wDQYDVQQKEwZKSFVBUEwxDzANBgNVBAsT BlBlb3BsZTE1MBYGA1UECxMPVlBOR3JvdXAtQklTRENBMBsGA1UEAxMUTWF0dGhldyBFIEZp b3JhdmFudGUwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJ6W8FUj+qNTW+ZXFu3Xd8k6 PYgSXYu6s+JwDTjBTyuyTsuZ6SjdYoqLrJdvFP7HFCREueYD8AFmCSt7lckALAOGnYAyouQ6 A9VBw0BMKW2O4hyyXqtDT6+AamDapwhT2xOhwvM0ia6+Kip/oFVEE9/UiBanYiDycGS/BWE0 UP87AgMBAAGjggG2MIIBsjALBgNVHQ8EBAMCB4AwKwYDVR0QBCQwIoAPMjAxMDA2MTExODIy MDZagQ8yMDEyMDcxNzIyNTIwNlowGwYNKwYBBAGzJQsDAQEBAQQKFghmaW9yYW1lMTAbBg0r BgEEAbMlCwMBAQECBAoSCDAwMTA0MjYxMFgGCWCGSAGG+mseAQRLDElUaGUgcHJpdmF0ZSBr ZXkgY29ycmVzcG9uZGluZyB0byB0aGlzIGNlcnRpZmljYXRlIG1heSBoYXZlIGJlZW4gZXhw b3J0ZWQuMCgGA1UdEQQhMB+BHU1hdHRoZXcuRmlvcmF2YW50ZUBqaHVhcGwuZWR1MFIGA1Ud HwRLMEkwR6BFoEOkQTA/MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGSkhVQVBMMQ8wDQYDVQQL EwZCSVNEQ0ExDjAMBgNVBAMTBUNSTDU2MB8GA1UdIwQYMBaAFAg1KZsR+dhFNgslphdhCTAd cqnrMB0GA1UdDgQWBBTui2MYOq/cB2fs3ULQR59XWf2EzTAJBgNVHRMEAjAAMBkGCSqGSIb2 fQdBAAQMMAobBFY3LjEDAgSwMA0GCSqGSIb3DQEBBQUAA4GBACTvR0IeGDQoVS87maiuQESQ EQ/CaLoxmX3aO+arr4No1xUHtrBI7y58SWYJv6b/H3WWpKuPAlsI2ByrryKe7A40xLEH6Psu 0qTfzdjbyVlOUqnytVYGLTS0UaBiVAeUNWmfg4PeYN5Kqcn6VDCEiS/CClS7SVXzeH4IBVVG GfcMMYICMTCCAi0CAQEwNzAvMQswCQYDVQQGEwJVUzEPMA0GA1UEChMGSkhVQVBMMQ8wDQYD VQQLEwZCSVNEQ0ECBD/xyf0wCQYFKw4DAhoFAKCCAVAwGAYJKoZIhvcNAQkDMQsGCSqGSIb3 DQEHATAcBgkqhkiG9w0BCQUxDxcNMTEwMzExMjMxNTE0WjAjBgkqhkiG9w0BCQQxFgQUNJ1I 2mM3jY495fexs40rhE0CIvQwRgYJKwYBBAGCNxAEMTkwNzAvMQswCQYDVQQGEwJVUzEPMA0G A1UEChMGSkhVQVBMMQ8wDQYDVQQLEwZCSVNEQ0ECBD/xkcEwSAYLKoZIhvcNAQkQAgsxOaA3 MC8xCzAJBgNVBAYTAlVTMQ8wDQYDVQQKEwZKSFVBUEwxDzANBgNVBAsTBkJJU0RDQQIEP/GR wTBfBgkqhkiG9w0BCQ8xUjBQMAsGCWCGSAFlAwQBAjAKBggqhkiG9w0DBzAOBggqhkiG9w0D AgICAIAwDQYIKoZIhvcNAwICAUAwBwYFKw4DAgcwDQYIKoZIhvcNAwICASgwDQYJKoZIhvcN AQEBBQAEgYBSU0Y6SeJJCoCznJp8mb4dKFtRKWrKcbYZe2JcA9uhhHxE5aAJOQLmHv+GGJg5 sBHWGbbGBRFLGsduc207mY/2U/BCcvTIwvJJCxphj7XQw3scpzvF/4yX+a4QF8Ew9XHFpfFw WPXaHW7iuJ8+DWkLF1ry8NppCOsf0zXCVGlLMAAAAAAAAA== --------------ms090807050006050001070206-- --===============0990231674== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============0990231674==--