Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hsmFreshenKey bugfix #78

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/wh_server_keystore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions tools/whnvmtool/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
whnvmtool
whNvmImage.bin
whNvmImage.hex
test/test_whnvmtool
*.bin
*.hex
22 changes: 22 additions & 0 deletions tools/whnvmtool/test/test_whnvmtool.c
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
/*
* tools/whnvmtool/test/test_whnvmtool.c
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
Expand Down
22 changes: 22 additions & 0 deletions tools/whnvmtool/whnvmtool.c
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
/*
* tools/whnvmtool/whnvmtool.c
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down