Skip to content

Commit b56c027

Browse files
authored
Merge pull request wolfSSL#11807 from deadcaf3/worktree-wipe-before-free
Wipe long-term secrets before freeing them
2 parents aa3f7cb + 5f65921 commit b56c027

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎src/internal.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3723,6 +3723,10 @@ void FreeSSL_Ctx(WOLFSSL_CTX* ctx)
37233723
#if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && \
37243724
!defined(NO_SHA256) && !defined(WC_NO_RNG)
37253725
if (ctx->srp != NULL) {
3726+
if (ctx->srp_password != NULL) {
3727+
ForceZero(ctx->srp_password,
3728+
(word32)XSTRLEN((char*)ctx->srp_password));
3729+
}
37263730
XFREE(ctx->srp_password, ctx->heap, DYNAMIC_TYPE_SRP);
37273731
ctx->srp_password = NULL;
37283732
wc_SrpTerm(ctx->srp);

‎src/ssl_api_pk.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,10 +3021,18 @@ int wolfSSL_CTX_set_dh_auto(WOLFSSL_CTX* ctx, int onoff)
30213021
WOLFSSL_MSG("wc_SrpSetPassword failed.");
30223022
return WOLFSSL_FAILURE;
30233023
}
3024+
if (ctx->srp_password != NULL) {
3025+
ForceZero(ctx->srp_password,
3026+
(word32)XSTRLEN((char*)ctx->srp_password));
3027+
}
30243028
XFREE(ctx->srp_password, ctx->heap, DYNAMIC_TYPE_SRP);
30253029
ctx->srp_password = NULL;
30263030
} else {
30273031
/* save password for wolfSSL_set_srp_username */
3032+
if (ctx->srp_password != NULL) {
3033+
ForceZero(ctx->srp_password,
3034+
(word32)XSTRLEN((char*)ctx->srp_password));
3035+
}
30283036
XFREE(ctx->srp_password, ctx->heap, DYNAMIC_TYPE_SRP);
30293037

30303038
ctx->srp_password = (byte*)XMALLOC(XSTRLEN(password) + 1, ctx->heap,

‎src/ssl_tsp.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,9 @@ void wolfSSL_TS_RESP_CTX_free(WOLFSSL_TS_RESP_CTX* ctx)
20212021
{
20222022
if (ctx != NULL) {
20232023
XFREE(ctx->certDer, NULL, DYNAMIC_TYPE_OPENSSL);
2024+
if (ctx->keyDer != NULL) {
2025+
ForceZero(ctx->keyDer, ctx->keySz);
2026+
}
20242027
XFREE(ctx->keyDer, NULL, DYNAMIC_TYPE_OPENSSL);
20252028
XFREE(ctx->policy, NULL, DYNAMIC_TYPE_OPENSSL);
20262029
XFREE(ctx, NULL, DYNAMIC_TYPE_OPENSSL);
@@ -2096,6 +2099,9 @@ int wolfSSL_TS_RESP_CTX_set_signer_key(WOLFSSL_TS_RESP_CTX* ctx,
20962099
if ((derSz <= 0) || (der == NULL))
20972100
return 0;
20982101

2102+
if (ctx->keyDer != NULL) {
2103+
ForceZero(ctx->keyDer, ctx->keySz);
2104+
}
20992105
XFREE(ctx->keyDer, NULL, DYNAMIC_TYPE_OPENSSL);
21002106
ctx->keyDer = der;
21012107
ctx->keySz = (word32)derSz;

0 commit comments

Comments
 (0)