Skip to content

Commit 229a997

Browse files
authored
Merge pull request #129 from julek-wolfssl/nss-fixes-rebase-fixes
Fix nss stuff that got dropped during rebase
2 parents 34d4313 + 544d1b6 commit 229a997

2 files changed

Lines changed: 37 additions & 25 deletions

File tree

.github/workflows/nss.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
nss-test:
2525
runs-on: ubuntu-24.04
2626
if: github.repository_owner == 'wolfssl'
27+
timeout-minutes: 30
2728
steps:
2829
- name: Checkout repository
2930
uses: actions/checkout@v4
@@ -76,6 +77,7 @@ jobs:
7677
uses: actions/checkout@v4
7778
with:
7879
repository: LinuxJedi/nss
80+
ref: nss-tests
7981
path: nss
8082

8183
- name: Cache NSS build

src/internal.c

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,26 @@ static word32 wolfPKCS11_Store_Handle(int type, CK_ULONG id1, CK_ULONG id2)
10251025
return nvIndex;
10261026
}
10271027
#else
1028+
1029+
#ifdef WOLFPKCS11_NSS
1030+
static char* storeDir = NULL;
1031+
1032+
int WP11_SetStoreDir(const char *dir, size_t dirSz)
1033+
{
1034+
if (storeDir != NULL)
1035+
XFREE(storeDir, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1036+
storeDir = NULL;
1037+
if (dir != NULL) {
1038+
storeDir = (char*) XMALLOC(dirSz + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1039+
if (storeDir == NULL)
1040+
return MEMORY_E;
1041+
XMEMCPY(storeDir, dir, dirSz);
1042+
storeDir[dirSz] = '\0'; /* Ensure null termination */
1043+
}
1044+
return 0;
1045+
}
1046+
#endif
1047+
10281048
static int wolfPKCS11_Store_Name(int type, CK_ULONG id1, CK_ULONG id2, char* name,
10291049
int nameLen)
10301050
{
@@ -1036,15 +1056,21 @@ static int wolfPKCS11_Store_Name(int type, CK_ULONG id1, CK_ULONG id2, char* nam
10361056

10371057
/* Path order:
10381058
* 1. Environment variable WOLFPKCS11_TOKEN_PATH
1039-
* 2. Home directory with .wolfPKCS11 (or APPDIR with wolfPKCS11 for
1059+
* 2. NSS store directory, if set using C_Initialize
1060+
* 3. Home directory with .wolfPKCS11 (or APPDIR with wolfPKCS11 for
10401061
* Windows)
1041-
* 3. WOLFPKCS11_DEFAULT_TOKEN_PATH, if set
1042-
* 4. /tmp in Linux, %TEMP% or C:\Windows\Temp in Windows
1062+
* 4. WOLFPKCS11_DEFAULT_TOKEN_PATH, if set
1063+
* 5. /tmp in Linux, %TEMP% or C:\Windows\Temp in Windows
10431064
*/
10441065
#ifndef WOLFPKCS11_NO_ENV
10451066
str = XGETENV("WOLFPKCS11_TOKEN_PATH");
10461067
#endif
10471068

1069+
#ifdef WOLFPKCS11_NSS
1070+
if (str == NULL)
1071+
str = storeDir;
1072+
#endif
1073+
10481074
if (str == NULL) {
10491075
const char* homeDir = NULL;
10501076

@@ -1198,24 +1224,6 @@ int wolfPKCS11_Store_Remove(int type, CK_ULONG id1, CK_ULONG id2)
11981224
#endif
11991225
return ret;
12001226
}
1201-
#ifdef WOLFPKCS11_NSS
1202-
static char* storeDir = NULL;
1203-
1204-
int WP11_SetStoreDir(const char *dir, size_t dirSz)
1205-
{
1206-
if (storeDir != NULL)
1207-
XFREE(storeDir, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1208-
storeDir = NULL;
1209-
if (dir != NULL) {
1210-
storeDir = (char*) XMALLOC(dirSz + 1, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1211-
if (storeDir == NULL)
1212-
return MEMORY_E;
1213-
XMEMCPY(storeDir, dir, dirSz);
1214-
storeDir[dirSz] = '\0'; /* Ensure null termination */
1215-
}
1216-
return 0;
1217-
}
1218-
#endif
12191227

12201228
/**
12211229
* Opens access to location to read/write token data.
@@ -8937,8 +8945,9 @@ static int WP11_Object_SetKeyId(WP11_Object* object, unsigned char* keyId,
89378945
{
89388946
int ret = 0;
89398947

8940-
if (object->keyId != NULL)
8941-
XFREE(object->keyId, NULL, DYNAMIC_TYPE_TMP_BUFFER);
8948+
XFREE(object->keyId, NULL, DYNAMIC_TYPE_TMP_BUFFER);
8949+
object->keyId = NULL;
8950+
object->keyIdLen = 0;
89428951
if (keyIdLen > 0) {
89438952
object->keyId = (unsigned char*)XMALLOC(keyIdLen, NULL,
89448953
DYNAMIC_TYPE_TMP_BUFFER);
@@ -8968,8 +8977,9 @@ static int WP11_Object_SetData(byte** attribute, int* attributeLen, byte* data,
89688977
{
89698978
int ret = 0;
89708979

8971-
if (*attribute != NULL)
8972-
XFREE(*attribute, NULL, DYNAMIC_TYPE_TMP_BUFFER);
8980+
XFREE(*attribute, NULL, DYNAMIC_TYPE_TMP_BUFFER);
8981+
*attribute = NULL;
8982+
*attributeLen = 0;
89738983
if (dataLen > 0) {
89748984
*attribute = (byte*)XMALLOC(dataLen, NULL,
89758985
DYNAMIC_TYPE_TMP_BUFFER);

0 commit comments

Comments
 (0)