Skip to content

Commit 0a7fbf6

Browse files
committed
Fix key generation worker shutdown.
1 parent 13245e0 commit 0a7fbf6

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

examples/test_config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int etsi_client_connect(const char* urlStr)
4242
ETSI_TEST_CLIENT_CERT, WOLFSSL_FILETYPE_PEM);
4343

4444
if (urlStr) {
45-
strncpy(urlStrCopy, urlStr, HTTP_MAX_URI-1);
45+
strncpy(urlStrCopy, urlStr, (HTTP_MAX_URI - 1));
4646
memset(&url, 0, sizeof(url));
4747
wolfHttpUrlDecode(&url, urlStrCopy);
4848
}

src/svc_etsi.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ typedef struct EtsiSvcCtx {
5151
#ifdef WOLFKM_VAULT
5252
wolfVaultCtx* vault; /* key vault */
5353
#endif
54+
55+
byte shutdown:1; /* signal to shutdown workers */
5456
} EtsiSvcCtx;
5557
static EtsiSvcCtx gSvcCtx;
5658

@@ -130,6 +132,14 @@ static int EtsiSvcGenNewKey(EtsiSvcCtx* svcCtx, EtsiKeyType keyType, EtsiKey* ke
130132
return ret;
131133
}
132134

135+
static void WakeKeyGenWorker(EtsiSvcCtx* svcCtx)
136+
{
137+
/* signal key generation thread to wake */
138+
pthread_mutex_lock(&svcCtx->kgMutex);
139+
pthread_cond_signal(&svcCtx->kgCond);
140+
pthread_mutex_unlock(&svcCtx->kgMutex);
141+
}
142+
133143
static int SetupKeyPackage(SvcConn* conn, EtsiSvcCtx* svcCtx)
134144
{
135145
int ret = 0, i;
@@ -222,9 +232,7 @@ static int SetupKeyPackage(SvcConn* conn, EtsiSvcCtx* svcCtx)
222232

223233
if (wakeKg) {
224234
/* signal key generation thread to wake */
225-
pthread_mutex_lock(&svcCtx->kgMutex);
226-
pthread_cond_signal(&svcCtx->kgCond);
227-
pthread_mutex_unlock(&svcCtx->kgMutex);
235+
WakeKeyGenWorker(svcCtx);
228236
}
229237

230238
return ret;
@@ -318,7 +326,7 @@ static void* KeyPushWorker(void* arg)
318326
pthread_mutex_unlock(&svcCtx->kgMutex);
319327

320328
XLOG(WOLFKM_LOG_DEBUG, "Key Generation Worker Wake %d sec\n", ret);
321-
} while (1);
329+
} while (!svcCtx->shutdown);
322330

323331
return NULL;
324332
}
@@ -581,6 +589,10 @@ void wolfEtsiSvc_Cleanup(SvcInfo* svc)
581589

582590
wc_FreeRng(&svcCtx->rng);
583591

592+
/* signal shutdown and wake worker */
593+
svcCtx->shutdown = 1;
594+
WakeKeyGenWorker(svcCtx);
595+
584596
pthread_mutex_destroy(&svcCtx->kgMutex);
585597
pthread_cond_destroy(&svcCtx->kgCond);
586598

0 commit comments

Comments
 (0)