|
| 1 | +/* tpmclear.c |
| 2 | + * |
| 3 | + * Copyright (C) 2006-2024 wolfSSL Inc. |
| 4 | + * |
| 5 | + * This file is part of wolfTPM. |
| 6 | + * |
| 7 | + * wolfTPM is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * wolfTPM is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
| 20 | + */ |
| 21 | + |
| 22 | +/* This is a tool for performing a TPM2_Clear call to reset the NV */ |
| 23 | + |
| 24 | +#ifdef HAVE_CONFIG_H |
| 25 | + #include <config.h> |
| 26 | +#endif |
| 27 | + |
| 28 | +#include <wolftpm/tpm2_wrap.h> |
| 29 | +#include <examples/management/management.h> |
| 30 | +#include <hal/tpm_io.h> |
| 31 | +#include <examples/tpm_test.h> |
| 32 | + |
| 33 | +#include <stdio.h> |
| 34 | + |
| 35 | +#ifndef WOLFTPM2_NO_WRAPPER |
| 36 | +int TPM2_Clear_Tool(void* userCtx, int argc, char *argv[]) |
| 37 | +{ |
| 38 | + int rc = TPM_RC_FAILURE; |
| 39 | + WOLFTPM2_DEV dev; |
| 40 | + |
| 41 | + (void)argc; |
| 42 | + (void)argv; |
| 43 | + |
| 44 | + printf("Preparing to clear TPM\n"); |
| 45 | + rc = wolfTPM2_Init(&dev, TPM2_IoCb, userCtx); |
| 46 | + if (rc != TPM_RC_SUCCESS) { |
| 47 | + printf("wolfTPM2_Init failed 0x%x: %s\n", rc, TPM2_GetRCString(rc)); |
| 48 | + return rc; |
| 49 | + } |
| 50 | + |
| 51 | + /* reset all content on TPM and reseed */ |
| 52 | + rc = wolfTPM2_Clear(&dev); |
| 53 | + if (rc == 0) { |
| 54 | + printf("TPM Clear success\n"); |
| 55 | + } |
| 56 | + |
| 57 | + if (rc != 0) { |
| 58 | + printf("Failure 0x%x: %s\n", rc, wolfTPM2_GetRCString(rc)); |
| 59 | + } |
| 60 | + wolfTPM2_Cleanup(&dev); |
| 61 | + return rc; |
| 62 | +} |
| 63 | +#endif /* !WOLFTPM2_NO_WRAPPER */ |
| 64 | + |
| 65 | +#ifndef NO_MAIN_DRIVER |
| 66 | +int main(int argc, char *argv[]) |
| 67 | +{ |
| 68 | + int rc = NOT_COMPILED_IN; |
| 69 | + |
| 70 | +#ifndef WOLFTPM2_NO_WRAPPER |
| 71 | + rc = TPM2_Clear_Tool(NULL, argc, argv); |
| 72 | +#else |
| 73 | + printf("Flush tool not compiled in\n"); |
| 74 | + (void)argc; |
| 75 | + (void)argv; |
| 76 | +#endif |
| 77 | + |
| 78 | + return rc; |
| 79 | +} |
| 80 | +#endif |
0 commit comments