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:   15-Sep-2013 23:56:56
  Branch: HEAD                             Handle: 2013091521565500

  Modified files:
    libtpm/libtpm/utils     createkey.c

  Log:
    - WIP.

  Summary:
    Revision    Changes     Path
    1.13        +105 -16    libtpm/libtpm/utils/createkey.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: libtpm/libtpm/utils/createkey.c
  ============================================================================
  $ cvs diff -u -r1.12 -r1.13 createkey.c
  --- libtpm/libtpm/utils/createkey.c   15 Sep 2013 21:13:38 -0000      1.12
  +++ libtpm/libtpm/utils/createkey.c   15 Sep 2013 21:56:55 -0000      1.13
  @@ -46,6 +46,7 @@
   static char *hp_str;
   
   static ARGV_t av_ix;
  +static ARGV_t av_hash;
   
   static void printUsage(void)
   {
  @@ -131,6 +132,17 @@
         }
       }
   
  +    ec = rpmtpmErr(tpm, "GetNumPCRRegisters", 0,
  +                     TPM_GetNumPCRRegisters(&pcrs));
  +    if (ec) {
  +     printf("Error reading number of PCR register.\n");
  +     goto exit;
  +    }
  +    if (pcrs > TPM_NUM_PCR) {
  +     printf("Library does not support that many PCRs\n");
  +     goto exit;
  +    }
  +
       for (i = 1; i < argc; i++) {
        if (!strcmp(argv[i], "-v1")) {
            use_oldversion = TRUE;
  @@ -213,15 +225,20 @@
            TPM_setlog(1);
            verbose = 1;
        } else if (!strcmp(argv[i], "-ix")) {
  +#ifdef       DYING
            int j = 0;
            int shift = 4;
            char *hash_str = NULL;
  +#endif
  +
            i++;
            if (i >= argc) {
                printf("Missing parameter for option -ix\n");
                printUsage();
                goto exit;
            }
  +
  +#ifdef       DYING
            ix = atoi(argv[i]);
   
            if ((int) ix <= max_index) {
  @@ -229,6 +246,9 @@
                goto exit;
            }
            max_index = ix;
  +#else
  +         (void) argvAdd(&av_ix, argv[i]);
  +#endif
   
            i++;
            if (i >= argc) {
  @@ -236,15 +256,14 @@
                printUsage();
                goto exit;
            }
  +#ifdef       DYING
            hash_str = argv[i];
            if (strlen(hash_str) != 40) {
                printf("The hash must be exactly 40 characters long!\n");
                goto exit;
            }
            memset(future_hash, 0x0, TPM_HASH_SIZE);
  -         shift = 4;
  -         j = 0;
  -         while (j < (2 * TPM_HASH_SIZE)) {
  +         for (j = 0, shift = 4; j < (2 * TPM_HASH_SIZE); j__, shift ^= 4) {
                unsigned char c = hash_str[j];
   
                if (c >= '0' && c <= '9') {
  @@ -257,19 +276,6 @@
                    printf("Hash contains non-hex character!\n");
                    goto exit;
                }
  -             shift ^= 4;
  -             j++;
  -         }
  -
  -         ec = rpmtpmErr(tpm, "GetNumPCRRegisters", 0,
  -                     TPM_GetNumPCRRegisters(&pcrs));
  -         if (ec) {
  -             printf("Error reading number of PCR register.\n");
  -             goto exit;
  -         }
  -         if (pcrs > TPM_NUM_PCR) {
  -             printf("Library does not support that many PCRs\n");
  -             goto exit;
            }
   
            if ((int) ix < 0 || ix >= pcrs) {
  @@ -302,6 +308,9 @@
            memcpy((char *) pcrComp.pcrValue.buffer +
                   (index_ctr - 1) * TPM_HASH_SIZE, future_hash,
                   TPM_HASH_SIZE);
  +#else
  +         (void) argvAdd(&av_hash, argv[i]);
  +#endif
        } else if (!strcmp(argv[i], "-vlong")) {
            use_struct = PCR_INFO_LONG;
        } else if (!strcmp(argv[i], "-vinfo")) {
  @@ -350,6 +359,86 @@
        goto exit;
       }
   
  +    if (av_ix) {
  +     int ac_ix = argvCount(av_ix);
  +     int ac_hash = argvCount(av_hash);
  +     const char *hash_str;
  +     int shift;
  +     int j;
  +
  +     if (ac_ix != ac_hash) {
  +         printf("No. of indices(%d) != No. of hashes(%d)\n",
  +                     ac_ix, ac_hash);
  +         goto exit;
  +     }
  +
  +     for (i = 0; i < ac_ix; i++) {
  +
  +         ix = atoi(av_ix[i]);
  +         if ((int)ix < 0 || ix > (pcrs - 1)) {
  +             printf("Index out of range! Max PCR is %d.\n", pcrs - 1);
  +             goto exit;
  +         }
  +
  +         if ((int) ix <= max_index) {
  +             printf("Indices must be given in ascending order\n");
  +             goto exit;
  +         }
  +         max_index = ix;
  +
  +         hash_str = av_hash[i];
  +         if (strlen(hash_str) != (2*TPM_HASH_SIZE)) {
  +             printf("The hash must be exactly 40 characters long!\n");
  +             goto exit;
  +         }
  +
  +         memset(future_hash, 0x0, TPM_HASH_SIZE);
  +         for (j = 0, shift = 4; j < (2 * TPM_HASH_SIZE); j++, shift ^= 4) {
  +             unsigned char c = hash_str[j];
  +
  +             if (c >= '0' && c <= '9') {
  +                 future_hash[j >> 1] |= ((c - '0') << shift);
  +             } else if (c >= 'a' && c <= 'f') {
  +                 future_hash[j >> 1] |= ((c - 'a' + 10) << shift);
  +             } else if (c >= 'A' && c <= 'F') {
  +                 future_hash[j >> 1] |= ((c - 'A' + 10) << shift);
  +             } else {
  +                 printf("Hash contains non-hex character!\n");
  +                 goto exit;
  +             }
  +         }
  +
  +         if ((int) ix < 0 || ix >= pcrs) {
  +             printf("Index out of range!\n");
  +             goto exit;
  +         }
  +
  +         /* Now build the pcrInfo */
  +         pcrInfoLong.tag = TPM_TAG_PCR_INFO_LONG;
  +         pcrInfoLong.localityAtCreation = TPM_LOC_ZERO;
  +         pcrInfoLong.localityAtRelease = TPM_LOC_ZERO;
  +         pcrInfoLong.releasePCRSelection.sizeOfSelect = pcrs / 8;
  +         pcrInfoLong.releasePCRSelection.pcrSelect[ix >> 3] |=
  +             (1 << (ix & 0x7));
  +
  +         index_ctr += 1;
  +
  +         /* Update the PCR Composite structure. */
  +         pcrComp.select.sizeOfSelect = pcrs / 8;
  +         pcrComp.select.pcrSelect[ix >> 3] |= (1 << (ix & 0x7));
  +         pcrComp.pcrValue.size = index_ctr * TPM_HASH_SIZE;
  +         pcrComp.pcrValue.buffer = realloc(pcrComp.pcrValue.buffer,
  +                                           pcrComp.pcrValue.size);
  +         /* force usage of pcrInfoLong */
  +         if (ix >= 16)
  +             use_struct = PCR_INFO_LONG;
  +
  +         memcpy((char *) pcrComp.pcrValue.buffer +
  +                (index_ctr - 1) * TPM_HASH_SIZE, future_hash,
  +                TPM_HASH_SIZE);
  +     }
  +    }
  +
       /*
        * If indices and hashes were given, calculate the hash over the
        * PCR Composite structure.
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to