From 469a686769e0f0702cc435818f8e2a1784fc379d Mon Sep 17 00:00:00 2001 From: Bill Roberts Date: Wed, 20 Dec 2023 16:11:44 -0600 Subject: [PATCH] Revert "session: do not delete on flush" This reverts commit b654a562ba86389ae0ac022555468fe7b0a15af5. Signed-off-by: Bill Roberts --- lib/tpm2_session.c | 10 ++++++++-- test/integration/tests/unseal.sh | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/tpm2_session.c b/lib/tpm2_session.c index 38c7df5eb..80efc7a96 100644 --- a/lib/tpm2_session.c +++ b/lib/tpm2_session.c @@ -361,8 +361,14 @@ tool_rc tpm2_session_close(tpm2_session **s) { } if ((*s)->internal.delete && path) { - rc = tool_rc_success; - goto out2; + if (remove(path)) { + LOG_ERR("File \"%s\" can't be deleted.", path); + rc = tool_rc_general_error; + goto out2; + } else { + rc = tool_rc_success; + goto out2; + } } FILE *session_file = path ? fopen(path, "w+b") : NULL; diff --git a/test/integration/tests/unseal.sh b/test/integration/tests/unseal.sh index a29857912..d0f7104f9 100644 --- a/test/integration/tests/unseal.sh +++ b/test/integration/tests/unseal.sh @@ -156,4 +156,9 @@ tpm2 sessionconfig enc_session.ctx --enable-encrypt --disable-continuesession unsealed=`tpm2 unseal -c seal_key.ctx -p sealkeypass -S enc_session.ctx` test "$unsealed" == "$secret" +if [ -e enc_session.ctx ]; then + echo "enc_session.ctx was not deleted."; + exit 1 +fi + exit 0