RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: [email protected] Module: rpm Date: 24-Jul-2010 20:05:51 Branch: HEAD Handle: 2010072418054802 Added files: rpm/rpmio rpmtpm.h ttpm.c Modified files: rpm CHANGES configure.ac rpm/rpmio Makefile.am librpmio.vers rpmtpm.c Log: - tpm: stub in client startup code and ttpm executable. - tpm: rework the AutoFu through *.pc to set CFLAGS. Summary: Revision Changes Path 1.3407 +2 -0 rpm/CHANGES 2.443 +3 -2 rpm/configure.ac 1.281 +5 -1 rpm/rpmio/Makefile.am 2.187 +2 -0 rpm/rpmio/librpmio.vers 1.2 +90 -7 rpm/rpmio/rpmtpm.c 2.1 +102 -0 rpm/rpmio/rpmtpm.h 2.1 +53 -0 rpm/rpmio/ttpm.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/CHANGES ============================================================================ $ cvs diff -u -r1.3406 -r1.3407 CHANGES --- rpm/CHANGES 24 Jul 2010 14:12:17 -0000 1.3406 +++ rpm/CHANGES 24 Jul 2010 18:05:48 -0000 1.3407 @@ -1,4 +1,6 @@ 5.3.2 -> 5.4a1: + - jbj: tpm: stub in client startup code and ttpm executable. + - jbj: tpm: rework the AutoFu through *.pc to set CFLAGS. - jbj: tpm: glue in an rpmtpm object wrapper. - jbj: tpm: stub in the AutoFu to detect libtpm. - jbj: fix: debugedit produce empty list file on MIPS (#61). @@ . patch -p0 <<'@@ .' Index: rpm/configure.ac ============================================================================ $ cvs diff -u -r2.442 -r2.443 configure.ac --- rpm/configure.ac 23 Jul 2010 18:19:52 -0000 2.442 +++ rpm/configure.ac 24 Jul 2010 18:05:48 -0000 2.443 @@ -1228,7 +1228,8 @@ [Mozilla NSS], [nss], [nss3 nss], [NSS_NoDB_Init], [nss.h], [no,external:none], [], - [], []) + [ AC_DEFINE(WITH_NSS, 1, [Define if building with Mozilla NSS]) + ], []) dnl # OpenSSL RPM_CHECK_LIB( @@ -1249,7 +1250,7 @@ dnl # IBM TPM 1.2 software emulation RPM_CHECK_LIB( [IBM TPM], [tpm], - [tpm], [TPM_Init], [tpm/tpm.h], + [tpm], [TPM_Init], [tpm.h], [no,external:none], [], [ AC_DEFINE(WITH_TPM, 1, [Define if building with IBM TPM 1.2 emulator]) ], []) @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/Makefile.am ============================================================================ $ cvs diff -u -r1.280 -r1.281 Makefile.am --- rpm/rpmio/Makefile.am 24 Jul 2010 14:12:18 -0000 1.280 +++ rpm/rpmio/Makefile.am 24 Jul 2010 18:05:50 -0000 1.281 @@ -19,7 +19,8 @@ rpmgenbasedir rpmgenpkglist rpmgensrclist rpmgpg \ rpmpbzip2 rpmpigz rpmtar rpmz \ tasn tdir tfts tget tglob thkp thtml tinv tkey tmacro tmagic tmire \ - tperl tpython tput tpw trpmio tsexp tsw ttcl dumpasn1 lookup3 + tperl tpython tput tpw trpmio tsexp tsw ttcl ttpm \ + dumpasn1 lookup3 bin_PROGRAMS = man_MANS = @@ -381,6 +382,9 @@ ttcl_SOURCES = ttcl.c ttcl_LDADD = $(RPMIO_LDADD_COMMON) -ltcl +ttpm_SOURCES = ttpm.c +ttpm_LDADD = $(RPMIO_LDADD_COMMON) + dumpasn1_SOURCES = dumpasn1.c dumpasn1_LDFLAGS = $(RPMIO_LDADD_COMMON) @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/librpmio.vers ============================================================================ $ cvs diff -u -r2.186 -r2.187 librpmio.vers --- rpm/rpmio/librpmio.vers 30 Jun 2010 17:38:33 -0000 2.186 +++ rpm/rpmio/librpmio.vers 24 Jul 2010 18:05:50 -0000 2.187 @@ -599,6 +599,8 @@ rpmtclNew; rpmtclRun; rpmtclRunFile; + _rpmtpm_debug; + rpmtpmNew; rpmUndefineMacro; rpmuuidMake; _rpmvc_debug; @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmtpm.c ============================================================================ $ cvs diff -u -r1.1 -r1.2 rpmtpm.c --- rpm/rpmio/rpmtpm.c 24 Jul 2010 14:12:19 -0000 1.1 +++ rpm/rpmio/rpmtpm.c 24 Jul 2010 18:05:50 -0000 1.2 @@ -5,8 +5,18 @@ #include "system.h" #if defined(WITH_TPM) -#include <tpm/tpm.h> -#endif + +#define TPM_POSIX 1 /* XXX FIXME: move to tpm-sw */ +#define TPM_V12 1 +#define TPM_NV_DISK 1 +#define TPM_MAXIMUM_KEY_SIZE 4096 +#define TPM_AES 1 + +#include <tpm.h> +#include <tpmutil.h> +#include <tpmfunc.h> + +#endif /* WITH_TPM */ #include <rpmiotypes.h> #include <rpmio.h> /* for *Pool methods */ @@ -16,7 +26,19 @@ #include "debug.h" /*...@unchecked@*/ -int _rpmtpm_debug = 0; +int _rpmtpm_debug = -1; + +static +int rpmtpmErr(rpmtpm tpm, const char * msg, uint32_t rc) + /*...@*/ +{ + /* XXX Don't spew on expected failures ... */ + if (rc || _rpmtpm_debug) + fprintf (stderr, "*** TPM_%s rc %u: %s\n", msg, rc, + (rc ? TPM_GetErrMsg(rc) : "Success")); + return rc; +} + /*...@-mustmod@*/ /* XXX splint on crack */ static void rpmtpmFini(void * _tpm) @@ -25,7 +47,9 @@ { rpmtpm tpm = _tpm; - tpm->fn = _free(tpm->fn); + tpm->digest = _free(tpm->digest); + tpm->digestlen = 0; + } /*...@=mustmod@*/ @@ -43,16 +67,75 @@ NULL, NULL, rpmtpmFini); pool = _rpmtpmPool; } - return (rpmtpm) rpmioGetPool(pool, sizeof(*tpm)); + tpm = (rpmtpm) rpmioGetPool(pool, sizeof(*tpm)); + memset(((char *)tpm)+sizeof(tpm->_item), 0, sizeof(*tpm)-sizeof(tpm->_item)); + return tpm; +} + +static int rpmtpmGetPhysicalCMDEnable(rpmtpm tpm) +{ + int xx; + STACK_TPM_BUFFER( subcap ); + STACK_TPM_BUFFER( resp ); + STACK_TPM_BUFFER( tb ); + TPM_PERMANENT_FLAGS permanentFlags; + + STORE32(subcap.buffer, 0, TPM_CAP_FLAG_PERMANENT); + + subcap.used = 4; + xx = rpmtpmErr(tpm, "GetCapability", + TPM_GetCapability(TPM_CAP_FLAG, &subcap, &resp)); + if (xx) + goto exit; + + TSS_SetTPMBuffer(&tb, resp.buffer, resp.used); + + xx = rpmtpmErr(tpm, "ReadPermanentFlags", + TPM_ReadPermanentFlags(&tb, 0, &permanentFlags, resp.used)); + if (xx) + goto exit; + + tpm->enabled = permanentFlags.physicalPresenceCMDEnable; + +exit: + return xx; } rpmtpm rpmtpmNew(const char * fn, int flags) { rpmtpm tpm = rpmtpmGetPool(_rpmtpmPool); + +#if defined(WITH_TPM) + unsigned char startupparm = 0x1; /* startup_clear: non-volatile state */ int xx; - if (fn) - tpm->fn = xstrdup(fn); + TPM_setlog(0); /* turn off verbose output */ + + xx = rpmtpmErr(tpm, "Startup", + TPM_Startup(startupparm)); + + /* Enable TPM (if not already done). */ + xx = rpmtpmGetPhysicalCMDEnable(tpm); + if (!xx && !tpm->enabled) { + /* TSC_PhysicalPresence to turn on physicalPresenceCMDEnable */ + xx = rpmtpmErr(tpm, "PhysicalPresence(0x20)", + TSC_PhysicalPresence(0x20)); + /* TSC_PhysicalPresence to turn on physicalPresence */ + if (!xx) + xx = rpmtpmErr(tpm, "PhysicalPresence(0x08)", + TSC_PhysicalPresence(0x08)); + /* TPM_Process_PhysicalEnable to clear disabled */ + if (!xx) + xx = rpmtpmErr(tpm, "PhysicalEnable()", + TPM_PhysicalEnable()); + /* TPM_Process_PhysicalSetDeactivated to clear deactivated */ + if (!xx) + xx = rpmtpmErr(tpm, "PhysicalSetDeactivated(FALSE)", + TPM_PhysicalSetDeactivated(FALSE)); + if (!xx) + tpm->enabled = 1; + } +#endif return rpmtpmLink(tpm); } @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmtpm.h ============================================================================ $ cvs diff -u -r0 -r2.1 rpmtpm.h --- /dev/null 2010-07-24 20:05:51.000000000 +0200 +++ rpmtpm.h 2010-07-24 20:05:51.677082090 +0200 @@ -0,0 +1,102 @@ +#ifndef H_RPMTPM +#define H_RPMTPM + +/** \ingroup rpmio + * \file rpmio/rpmtpm.h + */ + +#include <rpmiotypes.h> +#include <rpmpgp.h> +#include <rpmsw.h> + +/** \ingroup rpmio + */ +/*...@unchecked@*/ +extern int _rpmtpm_debug; + +/** \ingroup rpmio + */ +typedef /*...@refcounted@*/ struct rpmtpm_s * rpmtpm; + +#if defined(_RPMTPM_INTERNAL) + +/** \ingroup rpmio + */ +struct rpmtpm_s { + struct rpmioItem_s _item; /*!< usage mutex and pool identifier. */ + + int in_fips_mode; /* XXX trsa */ + int nbits; /* XXX trsa */ + int qbits; /* XXX trsa */ + int badok; /* XXX trsa */ + int err; + + void * digest; + size_t digestlen; + + int enabled; + +#if defined(__LCLINT__) +/*...@refs@*/ + int nrefs; /*!< (unused) keep splint happy */ +#endif +}; +#endif /* _RPMTPM_INTERNAL */ + +/*...@unchecked@*/ +extern pgpImplVecs_t rpmtpmImplVecs; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Unreference a TPM wrapper instance. + * @param tpm TPM wrapper + * @return NULL on last dereference + */ +/*...@unused@*/ /*...@null@*/ +rpmtpm rpmtpmUnlink (/*...@killref@*/ /*...@only@*/ /*...@null@*/ rpmtpm tpm) + /*...@modifies tpm @*/; +#define rpmtpmUnlink(_tpm) \ + ((rpmtpm)rpmioUnlinkPoolItem((rpmioItem)(_tpm), __FUNCTION__, __FILE__, __LINE__)) + +/** + * Reference a TPM wrapper instance. + * @param tpm TPM wrapper + * @return new TPM wrapper reference + */ +/*...@unused@*/ /*...@newref@*/ /*...@null@*/ +rpmtpm rpmtpmLink (/*...@null@*/ rpmtpm tpm) + /*...@modifies tpm @*/; +#define rpmtpmLink(_tpm) \ + ((rpmtpm)rpmioLinkPoolItem((rpmioItem)(_tpm), __FUNCTION__, __FILE__, __LINE__)) + +/** + * Destroy a TPM wrapper. + * @param tpm TPM wrapper + * @return NULL on last dereference + */ +/*...@null@*/ +rpmtpm rpmtpmFree(/*...@killref@*/ /*...@null@*/rpmtpm tpm) + /*...@globals fileSystem @*/ + /*...@modifies tpm, fileSystem @*/; +#define rpmtpmFree(_tpm) \ + ((rpmtpm)rpmioFreePoolItem((rpmioItem)(_tpm), __FUNCTION__, __FILE__, __LINE__)) + +/** + * Create and load a TPM wrapper. + * @param fn TPM file + * @param flags TPM flags + * @return new TPM wrapper + */ +/*...@newref@*/ /*...@null@*/ +rpmtpm rpmtpmNew(const char * fn, int flags) + /*...@globals fileSystem, internalState @*/ + /*...@modifies fileSystem, internalState @*/; + +#ifdef __cplusplus +} +#endif + +#endif /* H_RPMTPM */ @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/ttpm.c ============================================================================ $ cvs diff -u -r0 -r2.1 ttpm.c --- /dev/null 2010-07-24 20:05:50.000000000 +0200 +++ ttpm.c 2010-07-24 20:05:51.367066022 +0200 @@ -0,0 +1,53 @@ +#include "system.h" + +#include <rpmio.h> +#include <poptIO.h> + +#define _RPMTPM_INTERNAL +#include <rpmtpm.h> + +#include "debug.h" + +/*...@access pgpDig @*/ +/*...@access pgpDigParams @*/ + +/*...@-redecl@*/ +/*...@unchecked@*/ +extern int _pgp_debug; + +/*...@unchecked@*/ +extern int _pgp_print; +/*...@=redecl@*/ + +static int use_fips; +static int selftest_only; + +/*==============================================================*/ +static struct poptOption optionsTable[] = { + { "fips", '\0', POPT_ARG_VAL, &use_fips, 1, + N_("test in FIPS 140-2 mode"), NULL }, + { "selftest", '\0', POPT_ARG_VAL, &selftest_only, 1, + N_("test in FIPS 140-2 mode"), NULL }, + + { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmioAllPoptTable, 0, + N_("Common options:"), NULL }, + + POPT_AUTOHELP + POPT_TABLEEND +}; + + +int main(int argc, char *argv[]) +{ + poptContext con = rpmioInit(argc, argv, optionsTable); + rpmtpm tpm; + int ec = 0; + + tpm = rpmtpmNew(NULL, 0); + + tpm = rpmtpmFree(tpm); + + con = rpmioFini(con); + + return ec; +} @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository [email protected]
