mirror of https://github.com/wolfSSL/wolfTPM.git
Merge pull request #391 from dgarske/tpmclear
Create separate tool for performing the TPM2_Clearpull/392/head
commit
415f714c66
|
@ -53,6 +53,7 @@ examples/pcr/policy_sign
|
||||||
examples/pcr/reset
|
examples/pcr/reset
|
||||||
examples/timestamp/clock_set
|
examples/timestamp/clock_set
|
||||||
examples/management/flush
|
examples/management/flush
|
||||||
|
examples/management/tpmclear
|
||||||
pkcs7tpmsigned.p7s
|
pkcs7tpmsigned.p7s
|
||||||
pkcs7tpmsignedex.p7s
|
pkcs7tpmsignedex.p7s
|
||||||
examples/tls/tls_server
|
examples/tls/tls_server
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include <wolftpm/tpm2_wrap.h>
|
#include <wolftpm/tpm2_wrap.h>
|
||||||
|
|
||||||
#include <examples/management/flush.h>
|
#include <examples/management/management.h>
|
||||||
#include <hal/tpm_io.h>
|
#include <hal/tpm_io.h>
|
||||||
#include <examples/tpm_test.h>
|
#include <examples/tpm_test.h>
|
||||||
|
|
||||||
|
|
|
@ -2,16 +2,23 @@
|
||||||
# All paths should be given relative to the root
|
# All paths should be given relative to the root
|
||||||
|
|
||||||
if BUILD_EXAMPLES
|
if BUILD_EXAMPLES
|
||||||
noinst_PROGRAMS += examples/management/flush
|
noinst_PROGRAMS += examples/management/flush \
|
||||||
|
examples/management/tpmclear
|
||||||
|
|
||||||
noinst_HEADERS += examples/management/flush.h
|
noinst_HEADERS += examples/management/management.h
|
||||||
|
|
||||||
examples_management_flush_SOURCES = examples/management/flush.c
|
examples_management_flush_SOURCES = examples/management/flush.c
|
||||||
examples_management_flush_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD)
|
examples_management_flush_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD)
|
||||||
examples_management_flush_DEPENDENCIES = src/libwolftpm.la
|
examples_management_flush_DEPENDENCIES = src/libwolftpm.la
|
||||||
|
|
||||||
|
examples_management_tpmclear_SOURCES = examples/management/tpmclear.c
|
||||||
|
examples_management_tpmclear_LDADD = src/libwolftpm.la $(LIB_STATIC_ADD)
|
||||||
|
examples_management_tpmclear_DEPENDENCIES = src/libwolftpm.la
|
||||||
endif
|
endif
|
||||||
|
|
||||||
example_managementdir = $(exampledir)/management
|
example_managementdir = $(exampledir)/management
|
||||||
dist_example_management_DATA = examples/management/flush.c
|
dist_example_management_DATA = examples/management/flush.c \
|
||||||
|
examples/management/tpmclear.c
|
||||||
|
|
||||||
DISTCLEANFILES+= examples/management/.libs/flush
|
DISTCLEANFILES+= examples/management/.libs/flush \
|
||||||
|
examples/management/.libs/tpmclear
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* flush.h
|
/* management.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2024 wolfSSL Inc.
|
* Copyright (C) 2006-2024 wolfSSL Inc.
|
||||||
*
|
*
|
||||||
|
@ -27,6 +27,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int TPM2_Flush_Tool(void* userCtx, int argc, char *argv[]);
|
int TPM2_Flush_Tool(void* userCtx, int argc, char *argv[]);
|
||||||
|
int TPM2_Clear_Tool(void* userCtx, int argc, char *argv[]);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
|
@ -0,0 +1,80 @@
|
||||||
|
/* tpmclear.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2024 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfTPM.
|
||||||
|
*
|
||||||
|
* wolfTPM is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfTPM is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* This is a tool for performing a TPM2_Clear call to reset the NV */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <wolftpm/tpm2_wrap.h>
|
||||||
|
#include <examples/management/management.h>
|
||||||
|
#include <hal/tpm_io.h>
|
||||||
|
#include <examples/tpm_test.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifndef WOLFTPM2_NO_WRAPPER
|
||||||
|
int TPM2_Clear_Tool(void* userCtx, int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int rc = TPM_RC_FAILURE;
|
||||||
|
WOLFTPM2_DEV dev;
|
||||||
|
|
||||||
|
(void)argc;
|
||||||
|
(void)argv;
|
||||||
|
|
||||||
|
printf("Preparing to clear TPM\n");
|
||||||
|
rc = wolfTPM2_Init(&dev, TPM2_IoCb, userCtx);
|
||||||
|
if (rc != TPM_RC_SUCCESS) {
|
||||||
|
printf("wolfTPM2_Init failed 0x%x: %s\n", rc, TPM2_GetRCString(rc));
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* reset all content on TPM and reseed */
|
||||||
|
rc = wolfTPM2_Clear(&dev);
|
||||||
|
if (rc == 0) {
|
||||||
|
printf("TPM Clear success\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rc != 0) {
|
||||||
|
printf("Failure 0x%x: %s\n", rc, wolfTPM2_GetRCString(rc));
|
||||||
|
}
|
||||||
|
wolfTPM2_Cleanup(&dev);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
#endif /* !WOLFTPM2_NO_WRAPPER */
|
||||||
|
|
||||||
|
#ifndef NO_MAIN_DRIVER
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int rc = NOT_COMPILED_IN;
|
||||||
|
|
||||||
|
#ifndef WOLFTPM2_NO_WRAPPER
|
||||||
|
rc = TPM2_Clear_Tool(NULL, argc, argv);
|
||||||
|
#else
|
||||||
|
printf("Flush tool not compiled in\n");
|
||||||
|
(void)argc;
|
||||||
|
(void)argv;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -47,13 +47,6 @@
|
||||||
/* --- BEGIN Wrapper API Tests -- */
|
/* --- BEGIN Wrapper API Tests -- */
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
static int resetTPM = 0;
|
|
||||||
|
|
||||||
void TPM2_Wrapper_SetReset(int reset)
|
|
||||||
{
|
|
||||||
resetTPM = reset;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
printf("Expected Usage:\n");
|
printf("Expected Usage:\n");
|
||||||
|
@ -209,12 +202,6 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
|
||||||
printf("Found %d persistent handles\n", rc);
|
printf("Found %d persistent handles\n", rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resetTPM) {
|
|
||||||
/* reset all content on TPM and reseed */
|
|
||||||
rc = wolfTPM2_Clear(&dev);
|
|
||||||
if (rc != 0) return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* unload all transient handles */
|
/* unload all transient handles */
|
||||||
rc = wolfTPM2_UnloadHandles_AllTransient(&dev);
|
rc = wolfTPM2_UnloadHandles_AllTransient(&dev);
|
||||||
if (rc != 0) goto exit;
|
if (rc != 0) goto exit;
|
||||||
|
@ -1045,16 +1032,11 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
|
|
||||||
if (argc > 1) {
|
|
||||||
#ifndef WOLFTPM2_NO_WRAPPER
|
|
||||||
TPM2_Wrapper_SetReset(1);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
(void)argv;
|
|
||||||
|
|
||||||
#ifndef WOLFTPM2_NO_WRAPPER
|
#ifndef WOLFTPM2_NO_WRAPPER
|
||||||
rc = TPM2_Wrapper_TestArgs(NULL, argc, argv);
|
rc = TPM2_Wrapper_TestArgs(NULL, argc, argv);
|
||||||
#else
|
#else
|
||||||
|
(void)argc;
|
||||||
|
(void)argv;
|
||||||
printf("Wrapper code not compiled in\n");
|
printf("Wrapper code not compiled in\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void TPM2_Wrapper_SetReset(int reset);
|
|
||||||
int TPM2_Wrapper_Test(void* userCtx);
|
int TPM2_Wrapper_Test(void* userCtx);
|
||||||
int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[]);
|
int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue