int main(int argc, char * argv[]) { char * ownerpass = NULL; char * counterpass = NULL; unsigned char * passptr1 = NULL; unsigned char * passptr2 = NULL; unsigned char passhash1[20]; unsigned char passhash2[20]; uint32_t ret; int i = 0; uint32_t id = -1; i = 1; TPM_setlog(0); while (i < argc) { if (!strcmp("-ix",argv[i])) { i++; if (i < argc) { id = atoi(argv[i]); } else { printf("Missing mandatory parameter for -ix.\n"); usage(); } } else if (!strcmp("-pwdc",argv[i])) { i++; if (i < argc) { counterpass = argv[i]; } else { printf("Missing parameter for -pwdc.\n"); usage(); } } else if (!strcmp("-pwdo",argv[i])) { i++; if (i < argc) { ownerpass = argv[i]; } else { printf("Missing parameter for -pwdo.\n"); usage(); } } else if (!strcmp("-v",argv[i])) { TPM_setlog(1); } else if (!strcmp("-h",argv[i])) { usage(); } else { printf("\n%s is not a valid option\n",argv[i]); usage(); } i++; } if ((NULL == counterpass && NULL == ownerpass) || (int)id < 0) { printf("Input parameter missing!\n"); usage(); } if (NULL != ownerpass) { TSS_sha1(ownerpass,strlen(ownerpass),passhash1); passptr1 = passhash1; } else { passptr1 = NULL; } if (NULL != counterpass) { TSS_sha1(counterpass,strlen(counterpass),passhash2); passptr2 = passhash2; } else { passptr2 = NULL; } if (counterpass != NULL) { ret= TPM_ReleaseCounter(id, passptr2); if (0 != ret) { printf("Got error '%s' (0x%x) from TPM_ReleaseCounter.\n", TPM_GetErrMsg(ret), ret); } } else { ret = TPM_ReleaseCounterOwner(id, passptr1); if (0 != ret) { printf("Got error '%s' (0x%x) from TPM_ReleaseCounterOwner.\n", TPM_GetErrMsg(ret), ret); } } if (0 == ret) { printf("Successfully released the counter.\n"); } return ret; }
int main(int argc, char * argv[]) { uint32_t ret; int i; const char * ownerPassword = NULL; const char *ownerAuthFilename = NULL; const char * counterPassword = NULL; unsigned char * ownerAuthPtr = NULL; unsigned char * counterAuthPtr = NULL; unsigned char ownerAuth[TPM_HASH_SIZE]; unsigned char counterAuth[TPM_HASH_SIZE]; uint32_t id = -1; TPM_setlog(0); for (i=1 ; i<argc ; i++) { if (!strcmp("-pwdo",argv[i])) { i++; if (i < argc) { ownerPassword = argv[i]; } else { printf("Missing parameter for -pwdo.\n"); usage(); } } else if (strcmp(argv[i],"-pwdof") == 0) { i++; if (i < argc) { ownerAuthFilename = argv[i]; } else { printf("Missing parameter for -pwdof.\n"); usage(); } } else if (!strcmp("-pwdc",argv[i])) { i++; if (i < argc) { counterPassword = argv[i]; } else { printf("Missing parameter for -pwdc.\n"); usage(); } } else if (!strcmp("-ix",argv[i])) { i++; if (i < argc) { id = atoi(argv[i]); } else { printf("Missing mandatory parameter for -ix.\n"); usage(); } } else if (!strcmp("-v",argv[i])) { TPM_setlog(1); } else if (!strcmp("-h",argv[i])) { usage(); } else { printf("\n%s is not a valid option\n",argv[i]); usage(); } } if ((int)id < 0) { printf("Input parameter -idx missing or invalid\n"); usage(); } /* use the SHA1 hash of the password string as the Owner Authorization Data */ if (ownerPassword != NULL) { TSS_sha1((unsigned char *)ownerPassword, strlen(ownerPassword), ownerAuth); ownerAuthPtr = ownerAuth; } /* get the ownerAuth from a file */ else if (ownerAuthFilename != NULL) { unsigned char *buffer = NULL; uint32_t buffersize; ret = TPM_ReadFile(ownerAuthFilename, &buffer, &buffersize); if ((ret & ERR_MASK)) { printf("Error reading %s.\n", ownerAuthFilename); exit(-1); } if (buffersize != sizeof(ownerAuth)) { printf("Error reading %s, size %u should be %lu.\n", ownerAuthFilename, buffersize, (unsigned long)sizeof(ownerAuth)); exit(-1); } memcpy(ownerAuth, buffer, sizeof(ownerAuth)); ownerAuthPtr = ownerAuth; free(buffer); } else if (counterPassword != NULL) { TSS_sha1((unsigned char *)counterPassword, strlen(counterPassword), counterAuth); counterAuthPtr = counterAuth; } else { printf("Input authorization -pwdo or -pwdof or -pwdc missing\n"); usage(); } if (counterAuthPtr != NULL) { ret= TPM_ReleaseCounter(id, counterAuthPtr); if (ret != 0) { printf("Got error '%s' (0x%x) from TPM_ReleaseCounter.\n", TPM_GetErrMsg(ret), ret); } } else { ret = TPM_ReleaseCounterOwner(id, ownerAuthPtr); if (ret != 0) { printf("Got error '%s' (0x%x) from TPM_ReleaseCounterOwner.\n", TPM_GetErrMsg(ret), ret); } } if (ret == 0) { printf("Successfully released the counter.\n"); } return ret; }