From ae4c73df88458261bbd3db3946eefb3a42e55557 Mon Sep 17 00:00:00 2001
From: Brett Nicholas <7547222+bigbrett@users.noreply.github.com>
Date: Fri, 18 Oct 2024 08:52:20 -0600
Subject: [PATCH 1/3] bugfix for freshen key to actually load from NVM
---
src/wh_server_keystore.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/src/wh_server_keystore.c b/src/wh_server_keystore.c
index c921216..31de301 100644
--- a/src/wh_server_keystore.c
+++ b/src/wh_server_keystore.c
@@ -321,17 +321,33 @@ int hsmFreshenKey(whServerContext* server, whKeyId keyId, uint8_t** outBuf,
int ret = 0;
int foundIndex = -1;
int foundBigIndex = -1;
- whNvmMetadata meta[1];
+ whNvmMetadata tmpMeta[1];
if ( (server == NULL) ||
WH_KEYID_ISERASED(keyId)) {
return WH_ERROR_BADARGS;
}
- ret = _FindInCache(server, keyId, &foundIndex, &foundBigIndex, outBuf, outMeta);
- if (ret != 0) {
- /* Not in cache. Check if it is in the NVM */
- ret = wh_Nvm_GetMetadata(server->nvm, keyId, meta);
+ ret = _FindInCache(server, keyId, &foundIndex, &foundBigIndex, outBuf,
+ outMeta);
+ if (ret != WH_ERROR_OK) {
+ /* Not in cache. Check if it is in NVM */
+ ret = wh_Nvm_GetMetadata(server->nvm, keyId, tmpMeta);
+ if (ret == WH_ERROR_OK) {
+ /* Key found in NVM, get a free cache slot */
+ ret = hsmCacheFindSlotAndZero(server, tmpMeta->len, outBuf,
+ outMeta);
+ if (ret == WH_ERROR_OK) {
+ /* Read the key from NVM into the cache slot */
+ ret = wh_Nvm_Read(server->nvm, keyId, 0, tmpMeta->len, *outBuf);
+ if (ret == WH_ERROR_OK) {
+ /* Copy the metadata to the cache slot if key read is
+ * successful*/
+ XMEMCPY((uint8_t*)*outMeta, (uint8_t*)tmpMeta,
+ sizeof(whNvmMetadata));
+ }
+ }
+ }
}
return ret;
}
From 1fa0d7fbc923400f5bc6ac364262a6ee00484f20 Mon Sep 17 00:00:00 2001
From: Brett Nicholas <7547222+bigbrett@users.noreply.github.com>
Date: Fri, 18 Oct 2024 09:16:25 -0600
Subject: [PATCH 2/3] add license headers to whnvmtool
---
tools/whnvmtool/test/test_whnvmtool.c | 22 ++++++++++++++++++++++
tools/whnvmtool/whnvmtool.c | 22 ++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/tools/whnvmtool/test/test_whnvmtool.c b/tools/whnvmtool/test/test_whnvmtool.c
index 6bae329..d766fd3 100644
--- a/tools/whnvmtool/test/test_whnvmtool.c
+++ b/tools/whnvmtool/test/test_whnvmtool.c
@@ -1,3 +1,25 @@
+/*
+ * Copyright (C) 2024 wolfSSL Inc.
+ *
+ * This file is part of wolfHSM.
+ *
+ * wolfHSM 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * wolfHSM 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 wolfHSM. If not, see .
+ */
+/*
+ * tools/whnvmtool/test/test_whnvmtool.c
+ *
+ */
#include
#include
#include
diff --git a/tools/whnvmtool/whnvmtool.c b/tools/whnvmtool/whnvmtool.c
index c68279d..deb8e62 100644
--- a/tools/whnvmtool/whnvmtool.c
+++ b/tools/whnvmtool/whnvmtool.c
@@ -1,3 +1,25 @@
+/*
+ * Copyright (C) 2024 wolfSSL Inc.
+ *
+ * This file is part of wolfHSM.
+ *
+ * wolfHSM 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * wolfHSM 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 wolfHSM. If not, see .
+ */
+/*
+ * tools/whnvmtool/whnvmtool.c
+ *
+ */
#include
#include
#include
From 65dbb81eb78b804ba7b2b4ca3b5eb53899a4e609 Mon Sep 17 00:00:00 2001
From: Brett Nicholas <7547222+bigbrett@users.noreply.github.com>
Date: Fri, 18 Oct 2024 09:16:35 -0600
Subject: [PATCH 3/3] generalize gitignore
---
tools/whnvmtool/.gitignore | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/whnvmtool/.gitignore b/tools/whnvmtool/.gitignore
index 3d2de7b..6f4897d 100644
--- a/tools/whnvmtool/.gitignore
+++ b/tools/whnvmtool/.gitignore
@@ -1,4 +1,4 @@
whnvmtool
-whNvmImage.bin
-whNvmImage.hex
test/test_whnvmtool
+*.bin
+*.hex