RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: libtpm Date: 13-Sep-2013 04:04:29 Branch: HEAD Handle: 2013091302042800 Modified files: libtpm/libtpm/utils bindfile.c chgauth.c dumpkey.c loadkey.c loadmigrationblob.c loadownerdelegation.c migratekey.c sealfile.c sealfile2.c sealxfile.c unbindfile.c unsealfile.c unsealxfile.c updateverification.c verifydelegation.c verifyfile.c Log: - use TPM_ReadFile where possible. Summary: Revision Changes Path 1.8 +2 -1 libtpm/libtpm/utils/bindfile.c 1.9 +8 -23 libtpm/libtpm/utils/chgauth.c 1.8 +8 -20 libtpm/libtpm/utils/dumpkey.c 1.9 +7 -20 libtpm/libtpm/utils/loadkey.c 1.11 +5 -42 libtpm/libtpm/utils/loadmigrationblob.c 1.10 +4 -26 libtpm/libtpm/utils/loadownerdelegation.c 1.12 +3 -45 libtpm/libtpm/utils/migratekey.c 1.9 +9 -26 libtpm/libtpm/utils/sealfile.c 1.10 +9 -26 libtpm/libtpm/utils/sealfile2.c 1.10 +7 -29 libtpm/libtpm/utils/sealxfile.c 1.10 +5 -26 libtpm/libtpm/utils/unbindfile.c 1.9 +7 -25 libtpm/libtpm/utils/unsealfile.c 1.9 +7 -25 libtpm/libtpm/utils/unsealxfile.c 1.11 +4 -27 libtpm/libtpm/utils/updateverification.c 1.9 +5 -30 libtpm/libtpm/utils/verifydelegation.c 1.8 +12 -22 libtpm/libtpm/utils/verifyfile.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/bindfile.c ============================================================================ $ cvs diff -u -r1.7 -r1.8 bindfile.c --- libtpm/libtpm/utils/bindfile.c 13 Sep 2013 00:29:02 -0000 1.7 +++ libtpm/libtpm/utils/bindfile.c 13 Sep 2013 02:04:28 -0000 1.8 @@ -88,6 +88,8 @@ stat(ifn, &sb); datlen = MIN((int) sb.st_size, (int) sizeof(bound.data)); + memset(bound.data, 0, sizeof(bound.data)); + /* read the data file */ dfile = fopen(ifn, "rb"); if (dfile == NULL) { @@ -96,7 +98,6 @@ goto exit; } - memset(bound.data, 0, sizeof(bound.data)); nr = fread(bound.data, 1, datlen, dfile); fclose(dfile); if (nr != datlen) { @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/chgauth.c ============================================================================ $ cvs diff -u -r1.8 -r1.9 chgauth.c --- libtpm/libtpm/utils/chgauth.c 13 Sep 2013 00:29:02 -0000 1.8 +++ libtpm/libtpm/utils/chgauth.c 13 Sep 2013 02:04:28 -0000 1.9 @@ -61,9 +61,8 @@ rpmtpm tpm = _tpm; int ec = -1; /* assume failure */ - struct stat sb; - unsigned char keyblob[4096]; - unsigned int keyblen; + unsigned char * keyblob = NULL; + uint32_t keyblen; STACK_TPM_BUFFER(outblob) unsigned int outblen; char filename[256]; @@ -72,7 +71,6 @@ unsigned char newphash[TPM_HASH_SIZE]; unsigned char keyphash[TPM_HASH_SIZE]; unsigned char *passptr1 = NULL; - FILE *ifp = NULL; keydata key; STACK_TPM_BUFFER(buffer); @@ -96,23 +94,10 @@ TSS_sha1((unsigned char *) newpass, strlen(newpass), newphash); /* read the key blob */ - ifp = fopen(keyname, "rb"); - if (ifp == NULL) { - printf("Unable to open key/sealed file\n"); - ec = 3; - goto exit; - } - - fstat(fileno(ifp), &sb); - keyblen = (int) sb.st_size; - - if (fread(keyblob, 1, keyblen, ifp) != keyblen) { - printf("Unable to read key/sealed data file\n"); - ec = 4; + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(keyname, &keyblob, &keyblen)); + if (ec) goto exit; - } - fclose(ifp); - ifp = NULL; SET_TPM_BUFFER(&buffer, keyblob, keyblen); ec = TSS_KeyExtract(&buffer, 0, &key); @@ -149,8 +134,8 @@ outblen = ec; } - sprintf(filename2, "%s.save", keyname); sprintf(filename, "%s", keyname); + sprintf(filename2, "%s.save", keyname); if (rename(filename, filename2)) { printf("Unable to rename old key file\n"); ec = 6; @@ -163,8 +148,8 @@ goto exit; exit: - if (ifp) - fclose(ifp); + if (keyblob) + free(keyblob); if (keypass) free(keypass); if (newpass) @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/dumpkey.c ============================================================================ $ cvs diff -u -r1.7 -r1.8 dumpkey.c --- libtpm/libtpm/utils/dumpkey.c 13 Sep 2013 00:29:02 -0000 1.7 +++ libtpm/libtpm/utils/dumpkey.c 13 Sep 2013 02:04:28 -0000 1.8 @@ -44,13 +44,11 @@ int main(int argc, char *argv[]) { poptContext con = rpmioInit(argc, argv, optionsTable); + rpmtpm tpm = _tpm; int ec = -1; /* assume failure */ - size_t nr; - struct stat sb; - unsigned char keyblob[4096]; - size_t keyblen; - FILE *kinfile; + unsigned char *keyblob = NULL; + uint32_t keyblen = 0; keydata k; STACK_TPM_BUFFER(buffer); @@ -61,21 +59,10 @@ goto exit; } - kinfile = fopen(ifn, "rb"); - if (kinfile == NULL) { - printf("Unable to open key file\n"); - ec = 3; + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(ifn, &keyblob, &keyblen)); + if (ec) goto exit; - } - stat(ifn, &sb); - keyblen = sb.st_size; - nr = fread(keyblob, 1, keyblen, kinfile); - if (nr != keyblen) { - printf("Unable to read key file\n"); - ec = 4; - goto exit; - } - fclose(kinfile); SET_TPM_BUFFER(&buffer, keyblob, keyblen); TSS_KeyExtract(&buffer, 0, &k); @@ -92,9 +79,10 @@ printf("Pub KeyLength: %04x\n", k.pub.pubKey.keyLength); printf("Pub Exp Size: %02X\n", k.pub.algorithmParms.u.rsaKeyParms.exponentSize); - ec = 0; exit: + if (keyblob) + free(keyblob); if (ifn) free(ifn); con = rpmioFini(con); @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/loadkey.c ============================================================================ $ cvs diff -u -r1.8 -r1.9 loadkey.c --- libtpm/libtpm/utils/loadkey.c 8 Sep 2013 23:40:23 -0000 1.8 +++ libtpm/libtpm/utils/loadkey.c 13 Sep 2013 02:04:28 -0000 1.9 @@ -59,13 +59,11 @@ rpmtpm tpm = _tpm; int ec = -1; /* assume failure */ - struct stat sb; unsigned char pass1hash[20]; - unsigned char keyblob[4096]; - unsigned int keyblen; + unsigned char *keyblob = NULL; + uint32_t keyblen = 0; uint32_t newhandle; unsigned char *pptr = NULL; - FILE *kfp = NULL; keydata k; STACK_TPM_BUFFER(buffer); @@ -87,21 +85,10 @@ } /* read the Key File */ - kfp = fopen(kfn, "rb"); - if (kfp == NULL) { - printf("Unable to open key file\n"); - ec = -3; - goto exit; - } - - fstat(fileno(kfp), &sb); - keyblen = (int) sb.st_size; - - if (fread(keyblob, 1, keyblen, kfp) != keyblen) { - printf("Unable to read key file\n"); - ec = -4; + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(kfn, &keyblob, &keyblen)); + if (ec) goto exit; - } SET_TPM_BUFFER(&buffer, keyblob, keyblen); TSS_KeyExtract(&buffer, 0, &k); @@ -117,8 +104,8 @@ printf("New Key Handle = %08X\n", newhandle); exit: - if (kfp) - fclose(kfp); + if (keyblob) + free(keyblob); if (kfn) free(kfn); if (parpass) @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/loadmigrationblob.c ============================================================================ $ cvs diff -u -r1.10 -r1.11 loadmigrationblob.c --- libtpm/libtpm/utils/loadmigrationblob.c 11 Sep 2013 07:44:37 -0000 1.10 +++ libtpm/libtpm/utils/loadmigrationblob.c 13 Sep 2013 02:04:28 -0000 1.11 @@ -16,46 +16,6 @@ #include "debug.h" -static unsigned char *readFile(const char *ifn) -{ - unsigned char *b = NULL; - size_t nb; - size_t nr; - FILE * ifp = NULL; - struct stat sb; - - ifp = fopen(ifn, "rb"); - if (ifp == NULL) { - printf("Error. Could not open file %s\n", ifn); - goto exit; - } - - if (fstat(fileno(ifp), &sb) != 0) { - printf("Error determining size of file %s\n", ifn); - goto exit; - } - nb = sb.st_size; - - b = malloc(sb.st_size); - if (b == NULL) { - printf("Error allocating memory\n"); - goto exit; - } - - nr = fread(b, 1, nb, ifp); - if (nr != nb) { - printf("Error. Could not read file %s\n", ifn); - free(b); - b = NULL; - goto exit; - } - -exit: - if (ifp) - fclose(ifp); - return b; -} - static uint32_t handle = -1; static char *ifn; static char *keypass; @@ -105,6 +65,8 @@ uint32_t newhandle; unsigned char *b = NULL; + uint32_t nb = 0; + unsigned char keypasshash[TPM_HASH_SIZE]; unsigned char *keyhashptr = NULL; @@ -135,8 +97,9 @@ keyhashptr = keypasshash; } - b = readFile(ifn); - if (b == NULL) + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(ifn, &b, &nb)); + if (ec) goto exit; rndsize = LOAD32(b, offset); @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/loadownerdelegation.c ============================================================================ $ cvs diff -u -r1.9 -r1.10 loadownerdelegation.c --- libtpm/libtpm/utils/loadownerdelegation.c 8 Sep 2013 22:04:40 -0000 1.9 +++ libtpm/libtpm/utils/loadownerdelegation.c 13 Sep 2013 02:04:28 -0000 1.10 @@ -52,13 +52,11 @@ poptContext con = rpmioInit(argc, argv, optionsTable); rpmtpm tpm = NULL; int ec = -1; /* assume failure */ - FILE *fp = NULL; unsigned char *b = NULL; - size_t nb = 0; + uint32_t nb = 0; unsigned char ownerpasshash[TPM_HASH_SIZE]; unsigned char *ownerHashPtr = NULL; - struct stat sb; TPM_setlog(rpmIsVerbose() ? 1 : 0); @@ -76,28 +74,10 @@ ownerHashPtr = ownerpasshash; } - if (stat(ifn, &sb)) { - printf("Error, file %s not accessible.\n", ifn); - goto exit; - } - - nb = sb.st_size; - b = malloc(nb); - if (b == NULL) { - printf("Could not allocate memory!\n"); - goto exit; - } - - fp = fopen(ifn, "rb"); - if (fp == NULL) { - printf("Could not open file for reading.\n"); - goto exit; - } - - if (fread(b, 1, nb, fp) != nb) { - printf("Could not read the file.\n"); + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(ifn, &b, &nb)); + if (ec) goto exit; - } ec = rpmtpmErr(tpm, "Delegate_LoadOwnerDelegation", 0, TPM_Delegate_LoadOwnerDelegation(ix, ownerHashPtr, b, nb)); @@ -107,8 +87,6 @@ printf("Successfully loaded the blob.\n"); exit: - if (fp) - fclose(fp); if (b) free(b); if (ifn) @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/migratekey.c ============================================================================ $ cvs diff -u -r1.11 -r1.12 migratekey.c --- libtpm/libtpm/utils/migratekey.c 11 Sep 2013 07:44:37 -0000 1.11 +++ libtpm/libtpm/utils/migratekey.c 13 Sep 2013 02:04:28 -0000 1.12 @@ -66,47 +66,6 @@ return ec; } -static unsigned char *readFile(char *ifn, uint32_t * nbp) -{ - unsigned char *b = NULL; - size_t nb; - size_t nr; - FILE *ifp = NULL; - struct stat sb; - - ifp = fopen(ifn, "rb"); - if (ifp == NULL) { - printf("Error. Could not open migration file %s\n", ifn); - goto exit; - } - - if (fstat(fileno(ifp), &sb) != 0) { - printf("Error determining size of file %s\n", ifn); - goto exit; - } - nb = sb.st_size; - b = malloc(nb); - if (b == NULL) { - printf("Error allocating memory.\n"); - goto exit; - } - - nr = fread(b, 1, nb, ifp); - if (nr != nb) { - printf("Error. Could not read file %s\n", ifn); - free(b); - b = NULL; - goto exit; - } - -exit: - if (ifp) - fclose(ifp); - if (nbp) - *nbp = (b ? nb : 0); - return b; -} - static char *ikfn; static char *ifn; static char *migpass; @@ -200,11 +159,10 @@ } /* load the key to be migrated from a file. */ - b = readFile(ifn, &nb); - if (b == NULL) { - printf("Error. Could not load the blob from file '%s'.\n", ifn); + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(ifn, &b, &nb)); + if (ec) goto exit; - } rndsize = LOAD32(b, offset); offset += 4; @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/sealfile.c ============================================================================ $ cvs diff -u -r1.8 -r1.9 sealfile.c --- libtpm/libtpm/utils/sealfile.c 13 Sep 2013 00:29:02 -0000 1.8 +++ libtpm/libtpm/utils/sealfile.c 13 Sep 2013 02:04:28 -0000 1.9 @@ -62,18 +62,15 @@ poptContext con = rpmioInit(argc, argv, optionsTable); rpmtpm tpm = _tpm; int ec = -1; /* assume failure */ - size_t nr; - struct stat sb; - unsigned char databuff[256]; /* data read work buffer */ - unsigned int datalen; /* size of data file */ + unsigned char *databuff = NULL; /* data read work buffer */ + unsigned int datalen = 0; /* size of data file */ unsigned char passhash1[20]; /* hash of parent key password */ unsigned char passhash2[20]; /* hash of data password */ unsigned char blob[4096]; /* resulting sealed blob */ uint32_t bloblen = sizeof(blob); /* blob length */ unsigned char *passptr1 = NULL; unsigned char *passptr2 = NULL; - FILE *ifp = NULL; TPM_setlog(rpmIsVerbose() ? 1 : 0); @@ -93,31 +90,17 @@ passptr2 = passhash2; } - /* check size of data file */ - stat(ifn, &sb); - datalen = (int) sb.st_size; + /* read the data file */ + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(ifn, &databuff, &datalen)); + if (ec) + goto exit; if (datalen > 256) { printf("Data file too large for seal operation\n"); ec = -3; goto exit; } - /* read the data file */ - ifp = fopen(ifn, "rb"); - if (ifp == NULL) { - printf("Unable to open input file '%s'\n", ifn); - ec = -4; - goto exit; - } - nr = fread(databuff, 1, datalen, ifp); - if (nr != datalen) { - printf("I/O Error while reading input file '%s'\n", ifn); - ec = -5; - goto exit; - } - fclose(ifp); - ifp = NULL; - ec = rpmtpmErr(tpm, "SealCurrPCR", 0, TPM_SealCurrPCR(keyhandle, /* KEY Entity Value */ 0x0000007F, /* specify PCR registers 0-6 */ @@ -134,8 +117,8 @@ goto exit; exit: - if (ifp) - fclose(ifp); + if (databuff) + free(databuff); if (keypass) free(keypass); if (datpass) @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/sealfile2.c ============================================================================ $ cvs diff -u -r1.9 -r1.10 sealfile2.c --- libtpm/libtpm/utils/sealfile2.c 13 Sep 2013 00:29:02 -0000 1.9 +++ libtpm/libtpm/utils/sealfile2.c 13 Sep 2013 02:04:28 -0000 1.10 @@ -77,12 +77,10 @@ poptContext con = rpmioInit(argc, argv, optionsTable); rpmtpm tpm = _tpm; int ec = -1; /* assume failure */ - size_t nr; int ix; - struct stat sb; - unsigned char databuff[256]; /* data read work buffer */ - unsigned int datalen; /* size of data file */ + unsigned char * databuff = NULL; /* data read work buffer */ + uint32_t datalen = 0; /* size of data file */ unsigned char passhash1[20]; /* hash of parent key password */ unsigned char passhash2[20]; /* hash of data password */ unsigned char blob[4096]; /* resulting sealed blob */ @@ -90,7 +88,6 @@ unsigned char *passptr1 = NULL; unsigned char *passptr2 = NULL; unsigned char future_hash[TPM_HASH_SIZE]; - FILE *ifp = NULL; int i; int index_ctr = 0; int max_index = -1; @@ -247,31 +244,17 @@ passptr2 = passhash2; } - /* check size of data file */ - stat(ifn, &sb); - datalen = (int) sb.st_size; + /* read the data file */ + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(ifn, &databuff, &datalen)); + if (ec) + goto exit; if (datalen > 256) { printf("Data file too large for seal operation\n"); ec = -3; goto exit; } - /* read the data file */ - ifp = fopen(ifn, "rb"); - if (ifp == NULL) { - printf("Unable to open input file '%s'\n", ifn); - ec = -4; - goto exit; - } - nr = fread(databuff, 1, datalen, ifp); - if (nr != datalen) { - printf("I/O Error while reading input file '%s'\n", ifn); - ec = -5; - goto exit; - } - fclose(ifp); - ifp = NULL; - ec = rpmtpmErr(tpm, "Seal", 0, TPM_Seal(keyhandle, /* KEY Entity Value */ serPcrInfo.buffer, pcrInfoSize, /* pcrInfo to lock the seal to */ @@ -288,8 +271,8 @@ goto exit; exit: - if (ifp) - fclose(ifp); + if (databuff) + free(databuff); av_ix = argvFree(av_ix); if (keypass) free(keypass); @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/sealxfile.c ============================================================================ $ cvs diff -u -r1.9 -r1.10 sealxfile.c --- libtpm/libtpm/utils/sealxfile.c 13 Sep 2013 00:29:02 -0000 1.9 +++ libtpm/libtpm/utils/sealxfile.c 13 Sep 2013 02:04:28 -0000 1.10 @@ -72,12 +72,10 @@ poptContext con = rpmioInit(argc, argv, optionsTable); rpmtpm tpm = _tpm; int ec = -1; /* assume failure */ - size_t nr; int ix; - struct stat sb; - unsigned char databuff[256]; /* data read work buffer */ - unsigned int datalen; /* size of data file */ + unsigned char *databuff = NULL; /* data read work buffer */ + uint32_t datalen = 0; /* size of data file */ unsigned char passhash1[20]; /* hash of parent key password */ unsigned char passhash2[20]; /* hash of data password */ unsigned char blob[4096]; /* resulting sealed blob */ @@ -85,7 +83,6 @@ unsigned char *passptr1 = NULL; unsigned char *passptr2 = NULL; unsigned char future_hash[TPM_HASH_SIZE]; - FILE *ifp = NULL; int i; int index_ctr = 0; int max_index = -1; @@ -208,30 +205,11 @@ passptr2 = passhash2; } - /* check size of data file */ - stat(ifn, &sb); - datalen = (int) sb.st_size; - if (datalen > 256) { - printf("Data file too large for seal operation\n"); - ec = -3; - goto exit; - } - /* read the data file */ - ifp = fopen(ifn, "rb"); - if (ifp == NULL) { - printf("Unable to open input file '%s'\n", ifn); - ec = -4; - goto exit; - } - nr = fread(databuff, 1, datalen, ifp); - if (nr != datalen) { - printf("I/O Error while reading input file '%s'\n", ifn); - ec = -5; + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(ifn, &databuff, &datalen)); + if (ec) goto exit; - } - fclose(ifp); - ifp = NULL; ec = rpmtpmErr(tpm, "Sealx", 0, TPM_Sealx(keyhandle, /* KEY Entity Value */ @@ -249,8 +227,8 @@ goto exit; exit: - if (ifp) - fclose(ifp); + if (databuff) + free(databuff); av_ix = argvFree(av_ix); if (keypass) free(keypass); @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/unbindfile.c ============================================================================ $ cvs diff -u -r1.9 -r1.10 unbindfile.c --- libtpm/libtpm/utils/unbindfile.c 13 Sep 2013 00:29:02 -0000 1.9 +++ libtpm/libtpm/utils/unbindfile.c 13 Sep 2013 02:04:28 -0000 1.10 @@ -64,16 +64,13 @@ poptContext con = rpmioInit(argc, argv, optionsTable); rpmtpm tpm = _tpm; int ec = -1; /* assume failure */ - size_t nr; unsigned char *databuff = NULL; /* encrypted data read work buffer */ + uint32_t datlen; unsigned char *blob = NULL; /* un-encrypted blob */ - size_t datlen; uint32_t bloblen; unsigned char passhash[20]; /* hash of parent key password */ unsigned char *passptr = NULL; - struct stat sb; - FILE *dfp = NULL; TPM_setlog(rpmIsVerbose() ? 1 : 0); @@ -88,32 +85,16 @@ passptr = passhash; } - /* get size of data file */ - stat(dfn, &sb); - datlen = sb.st_size; - databuff = malloc(datlen); - if (databuff == NULL) + /* read the data file */ + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(dfn, &databuff, &datlen)); + if (ec) goto exit; blob = malloc(datlen); if (blob == NULL) goto exit; - /* read the data file */ - dfp = fopen(dfn, "rb"); - if (dfp == NULL) { - printf("Unable to open data file '%s'\n", dfn); - ec = -3; - goto exit; - } - nr = fread(databuff, 1, datlen, dfp); - fclose(dfp); - dfp = NULL; - if (nr != datlen) { - printf("Unable to read data file\n"); - ec = -4; - goto exit; - } ec = rpmtpmErr(tpm, "UnBind", 0, TPM_UnBind(handle, passptr, databuff, datlen, blob, &bloblen)); if (ec) @@ -125,8 +106,6 @@ goto exit; exit: - if (dfp) - fclose(dfp); if (blob) free(blob); if (databuff) @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/unsealfile.c ============================================================================ $ cvs diff -u -r1.8 -r1.9 unsealfile.c --- libtpm/libtpm/utils/unsealfile.c 13 Sep 2013 00:29:02 -0000 1.8 +++ libtpm/libtpm/utils/unsealfile.c 13 Sep 2013 02:04:28 -0000 1.9 @@ -63,18 +63,15 @@ poptContext con = rpmioInit(argc, argv, optionsTable); rpmtpm tpm = _tpm; int ec = -1; /* assume failure */ - size_t nr; - struct stat sb; unsigned char databuff[256]; /* data buffer */ uint32_t datalen; /* size of data */ unsigned char passhash1[20]; /* hash of parent key password */ unsigned char passhash2[20]; /* hash of data password */ - unsigned char blob[4096]; /* sealed blob */ - unsigned int bloblen; /* blob length */ + unsigned char *blob = NULL; /* sealed blob */ + uint32_t bloblen = 0; /* blob length */ unsigned char *passptr1 = NULL; unsigned char *passptr2 = NULL; - FILE *ifp = NULL; TPM_setlog(rpmIsVerbose() ? 1 : 0); @@ -96,25 +93,10 @@ } /* read the blob file */ - ifp = fopen(ifn, "rb"); - if (ifp == NULL) { - printf("Unable to open input file '%s'\n", ifn); - ec = -4; - goto exit; - } - - /* get size of blob file */ - fstat(fileno(ifp), &sb); - bloblen = (int) sb.st_size; - - nr = fread(blob, 1, bloblen, ifp); - if (nr != bloblen) { - printf("I/O Error while reading input file '%s'\n", ifn); - ec = -5; + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(ifn, &blob, &bloblen)); + if (ec) goto exit; - } - fclose(ifp); - ifp = NULL; ec = rpmtpmErr(tpm, "Unseal", 0, TPM_Unseal(keyhandle, /* KEY Entity Value */ @@ -131,8 +113,8 @@ goto exit; exit: - if (ifp) - fclose(ifp); + if (blob) + free(blob); if (keypass) free(keypass); if (datpass) @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/unsealxfile.c ============================================================================ $ cvs diff -u -r1.8 -r1.9 unsealxfile.c --- libtpm/libtpm/utils/unsealxfile.c 13 Sep 2013 00:29:02 -0000 1.8 +++ libtpm/libtpm/utils/unsealxfile.c 13 Sep 2013 02:04:28 -0000 1.9 @@ -63,18 +63,15 @@ poptContext con = rpmioInit(argc, argv, optionsTable); rpmtpm tpm = _tpm; int ec = -1; /* assume failure */ - size_t nr; - struct stat sb; unsigned char databuff[256]; /* data buffer */ uint32_t datalen; /* size of data */ unsigned char passhash1[20]; /* hash of parent key password */ unsigned char passhash2[20]; /* hash of data password */ - unsigned char blob[4096]; /* sealed blob */ - unsigned int bloblen; /* blob length */ + unsigned char *blob = NULL; /* sealed blob */ + uint32_t bloblen = 0; /* blob length */ unsigned char *passptr1 = NULL; unsigned char *passptr2 = NULL; - FILE *ifp = NULL; TPM_setlog(rpmIsVerbose() ? 1 : 0); @@ -96,25 +93,10 @@ } /* read the blob file */ - ifp = fopen(ifn, "rb"); - if (ifp == NULL) { - printf("Unable to open input file '%s'\n", ifn); - ec = -4; - goto exit; - } - - /* get size of blob file */ - fstat(fileno(ifp), &sb); - bloblen = (int) sb.st_size; - - nr = fread(blob, 1, bloblen, ifp); - if (nr != bloblen) { - printf("I/O Error while reading input file '%s'\n", ifn); - ec = -5; + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(ifn, &blob, &bloblen)); + if (ec) goto exit; - } - fclose(ifp); - ifp = NULL; ec = rpmtpmErr(tpm, "Unsealx", 0, TPM_Unsealx(keyhandle, /* KEY Entity Value */ @@ -131,8 +113,8 @@ goto exit; exit: - if (ifp) - fclose(ifp); + if (blob) + free(blob); if (keypass) free(keypass); if (datpass) @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/updateverification.c ============================================================================ $ cvs diff -u -r1.10 -r1.11 updateverification.c --- libtpm/libtpm/utils/updateverification.c 13 Sep 2013 00:29:02 -0000 1.10 +++ libtpm/libtpm/utils/updateverification.c 13 Sep 2013 02:04:28 -0000 1.11 @@ -54,15 +54,14 @@ poptContext con = rpmioInit(argc, argv, optionsTable); rpmtpm tpm = _tpm; int ec = -1; /* assume failure */ + unsigned char *ib = NULL; uint32_t ibn = 0; unsigned char ob[1024]; uint32_t obn = sizeof(ob); - FILE *fp = NULL; unsigned char ownerpasshash[TPM_HASH_SIZE]; unsigned char *ownerHashPtr = NULL; - struct stat sb; TPM_setlog(rpmIsVerbose() ? 1 : 0); @@ -80,35 +79,15 @@ ownerHashPtr = ownerpasshash; } - if (stat(ifn, &sb)) { - printf("Error, file %s not accessible.\n", ifn); - goto exit; - } - - ibn = sb.st_size; - ib = malloc(ibn); - if (ib == NULL) { - printf("Could not allocate memory!\n"); - goto exit; - } - - fp = fopen(ifn, "rb"); - if (fp == NULL) { - printf("Could not open file for reading.\n"); - goto exit; - } - - if (fread(ib, 1, ibn, fp) != ibn) { - printf("Could not read the file.\n"); + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(ifn, &ib, &ibn)); + if (ec) goto exit; - } ec = rpmtpmErr(tpm, "Delegate_UpdateVerification", 0, TPM_Delegate_UpdateVerification(ib, ibn, ownerHashPtr, ob, &obn)); if (ec) goto exit; - fclose(fp); - fp = NULL; printf("Successfully loaded the blob.\n"); @@ -120,8 +99,6 @@ printf("Successfully wrote blob to file.\n"); exit: - if (fp) - fclose(fp); if (ib) free(ib); if (ifn) @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/verifydelegation.c ============================================================================ $ cvs diff -u -r1.8 -r1.9 verifydelegation.c --- libtpm/libtpm/utils/verifydelegation.c 8 Sep 2013 22:04:41 -0000 1.8 +++ libtpm/libtpm/utils/verifydelegation.c 13 Sep 2013 02:04:28 -0000 1.9 @@ -44,11 +44,9 @@ poptContext con = rpmioInit(argc, argv, optionsTable); rpmtpm tpm = NULL; int ec = -1; /* assume failure */ - unsigned char *b = NULL; - size_t nb = 0; - FILE *fp = NULL; - struct stat sb; + unsigned char *b = NULL; + uint32_t nb = 0; TPM_setlog(rpmIsVerbose() ? 1 : 0); @@ -57,31 +55,10 @@ goto exit; } - if (stat(ifn, &sb)) { - printf("Error, file %s not accessible.\n", ifn); - goto exit; - } - - nb = sb.st_size; - b = malloc(nb); - if (b == NULL) { - printf("Could not allocate memory!\n"); - ec = -1; - goto exit; - } - - fp = fopen(ifn, "rb"); - if (fp == NULL) { - printf("Could not open file for reading.\n"); - ec = -1; - goto exit; - } - - if (fread(b, 1, nb, fp) != nb) { - printf("Could not read the file.\n"); - ec = -1; + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(ifn, &b, &nb)); + if (ec) goto exit; - } ec = rpmtpmErr(tpm, "Delegate_VerifyDelegation", 0, TPM_Delegate_VerifyDelegation(b, nb)); @@ -90,8 +67,6 @@ printf("Successfully verified the blob.\n"); exit: - if (fp) - fclose(fp); if (b) free(b); if (ifn) @@ . patch -p0 <<'@@ .' Index: libtpm/libtpm/utils/verifyfile.c ============================================================================ $ cvs diff -u -r1.7 -r1.8 verifyfile.c --- libtpm/libtpm/utils/verifyfile.c 13 Sep 2013 00:29:02 -0000 1.7 +++ libtpm/libtpm/utils/verifyfile.c 13 Sep 2013 02:04:28 -0000 1.8 @@ -57,13 +57,11 @@ int ec = -1; /* assume failure */ int ret; - struct stat sb; unsigned char databuff[65535]; /* data read work buffer */ unsigned char datahash[20]; /* hash of data file */ unsigned char digest[20]; SHA_CTX sha; FILE *datafile; - FILE *sigfile; FILE *keyfile; EVP_PKEY *pkey; RSA *rsa; @@ -73,6 +71,8 @@ unsigned char plainarray[4096]; TPM_SIGN_INFO tsi; STACK_TPM_BUFFER(tsi_ser); + unsigned char *sigbuff = NULL; + uint32_t sigblen = 0; STACK_TPM_BUFFER(signature); TPM_setlog(rpmIsVerbose() ? 1 : 0); @@ -89,13 +89,14 @@ } /* read and hash the data file */ + SHA1_Init(&sha); + datafile = fopen(ifn, "rb"); if (datafile == NULL) { printf("Unable to open data file '%s'\n", ifn); ec = 2; goto exit; } - SHA1_Init(&sha); for (;;) { ret = fread(databuff, 1, sizeof databuff, datafile); if (ret < 0) { @@ -108,30 +109,17 @@ break; } fclose(datafile); - SHA1_Final(datahash, &sha); - /* get size of signature file */ - stat(sigfn, &sb); - signature.used = (int) sb.st_size; - sigfile = fopen(sigfn, "rb"); - if (sigfile == NULL) { - printf("Unable to open signature file '%s'\n", sigfn); - ec = 4; - goto exit; - } + SHA1_Final(datahash, &sha); /* read the signature file */ - ret = fread(signature.buffer, 1, signature.used, sigfile); - if (ret != (int) signature.used) { - printf("I/O Error while reading signature file '%s'\n", sigfn); - ec = 5; + ec = rpmtpmErr(tpm, "ReadFile", 0, + TPM_ReadFile(sigfn, &sigbuff, &sigblen)); + if (ec) goto exit; - } - fclose(sigfile); + SET_TPM_BUFFER(&signature, sigbuff, sigblen); - /* - ** read the key file - */ + /* read the key file */ keyfile = fopen(keyfn, "rb"); if (keyfile == NULL) { printf("Unable to open public key file '%s'\n", keyfn); @@ -214,6 +202,8 @@ ec = 0; exit: + if (sigbuff) + free(sigbuff); if (ifn) free(ifn); if (sigfn) @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org