Ejemplo n.º 1
0
uint32_t TPM_HashMSAComposite(TPM_MSA_COMPOSITE * comp,
			      unsigned char *digest)
{
    uint32_t ret = 0;
    struct tpm_buffer *buffer =
	TSS_AllocTPMBuffer(comp->MSAlist * TPM_HASH_SIZE + TPM_U32_SIZE);
    if (buffer) {
	uint32_t len = TPM_WriteMSAComposite(buffer, comp);
	TSS_sha1(buffer->buffer, len, digest);
	TSS_FreeTPMBuffer(buffer);
    } else
	ret = ERR_MEM_ERR;
    return ret;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	unsigned char passhash1[20];
	char * ownerpass = NULL;
	char * filename = NULL;
	int ret;
	int verbose = FALSE;
	TPM_MSA_COMPOSITE msaList = {0, NULL};
	unsigned char migAuthDigest[TPM_DIGEST_SIZE];
	unsigned char hmac[TPM_DIGEST_SIZE];
	char * msa_list_filename = NULL;
	
	int i = 1;
	
	TPM_setlog(0);
	
	while (i < argc) {
		if (!strcmp("-pwdo",argv[i])) {
			i++;
			if (i < argc) {
				ownerpass = argv[i];
			} else {
				printf("Missing parameter for -pwdo.\n");
				usage();
				exit(-1);
			}
		} else
		if (!strcmp("-of",argv[i])) {
			i++;
			if (i < argc) {
				filename = argv[i];
			} else {
				printf("Missing parameter for -of.\n");
				usage();
				exit(-1);
			}
		} else
		if (!strcmp("-msa",argv[i])) {
			i++;
			if (i < argc) {
				msa_list_filename = argv[i];
			} else {
				printf("Missing parameter for -msa.\n");
				usage();
				exit(-1);
			}
		} else
		if (!strcmp("-ik",argv[i])) {
			i++;
			if (i < argc) {
				if (0 != addKeyToMSAList(&msaList,argv[i])) {
					exit(-1);
				}
			} else {
				printf("Missing parameter for -ik.\n");
				usage();
				exit(-1);
			}
		} else
		if (!strcmp("-v",argv[i])) {
			verbose = TRUE;
			TPM_setlog(1);
		} else
		if (!strcmp("-h",argv[i])) {
		    usage();
		    exit(-1);
		} else {
		        printf("\n%s is not a valid option\n",argv[i]);
			usage();
			exit(-1);
		}
		i++;
	}
	(void)verbose;

	if (NULL == ownerpass ||
	    msaList.MSAlist == 0 ||
	    NULL == filename) {
		printf("Missing argument.\n");
		usage();
		exit(-1);
	}
	
	if (NULL != ownerpass) {
		TSS_sha1(ownerpass,strlen(ownerpass),passhash1);
	}
	
   
   
	TPM_HashMSAComposite(&msaList, migAuthDigest);
   	ret = TPM_CMK_ApproveMA(migAuthDigest,
	                        passhash1,
	                        hmac);


	if (0 != ret) {
		printf("CMK_ApproveMA returned error '%s' (%d).\n",
		       TPM_GetErrMsg(ret),
		       ret);
	} else {
		FILE * f = fopen(filename, "wb+");
		if (f != NULL) {
			if (TPM_DIGEST_SIZE == fwrite(hmac, 1, TPM_DIGEST_SIZE, f) &&
			    TPM_DIGEST_SIZE == fwrite(migAuthDigest, 1, TPM_DIGEST_SIZE, f) ) {
				printf("Successfully wrote HMAC and digest to %s.\n",
				       filename);
			}
			fclose(f);
			
		} else {
			printf("Could not open file %s for writing.\n",
			       filename);
		}
	}

	if (NULL != msa_list_filename) {
		struct tpm_buffer * buffer = TSS_AllocTPMBuffer(sizeof(msaList) + msaList.MSAlist * TPM_HASH_SIZE);
		if (NULL != buffer) {
			uint32_t len = TPM_WriteMSAComposite(buffer, &msaList);
			FILE * f = fopen(msa_list_filename, "wb");
			if (NULL != f) {
				fwrite(buffer->buffer,len,1, f);
				printf("Successfully wrote msa list to %s.\n",
				       msa_list_filename);
				fclose(f);
			} else {
				printf("Could not open file %s for writing.\n",
				       msa_list_filename);
			}
			TSS_FreeTPMBuffer(buffer);
		}
		
	}
	
	exit(ret);
}