Skip to content

Commit 3f19fab

Browse files
committed
Fix CI, Fenrir, and Copilot
- wp_drbg_reseed: Replace parentClearSeed callback with OPENSSL_clear_free(seed, seedLen) - wp_drbg_reseed: Same fix as above — securely wipes and frees the seed buffer - wp_ecx_dup: Remove dead ok variable; when private key not selected, re-init the key and import only public part to avoid leaking private material - wp_rsa_kmgmt.c: SHA1 fallback replaced with ok = 0 error — unknown digest is now a failure, not a silent fallback - wp_hmac.c: Remove unused rc variable and (void)rc - wp_cmac.c: Add keyLen <= sizeof(dst->key) bounds check before XMEMCPY - test_tls_cbc.c: Check RAND_bytes() return value
1 parent 4232f8f commit 3f19fab

6 files changed

Lines changed: 43 additions & 22 deletions

File tree

src/wp_cmac.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,14 @@ static wp_CmacCtx* wp_cmac_dup(wp_CmacCtx* src)
167167
dst->type = src->type;
168168
dst->size = src->size;
169169
dst->expKeySize = src->expKeySize;
170-
XMEMCPY(dst->key, src->key, src->keyLen);
171-
dst->keyLen = src->keyLen;
170+
if (src->keyLen <= sizeof(dst->key)) {
171+
XMEMCPY(dst->key, src->key, src->keyLen);
172+
dst->keyLen = src->keyLen;
173+
}
174+
else {
175+
wp_cmac_free(dst);
176+
dst = NULL;
177+
}
172178
}
173179

174180
return dst;

src/wp_drbg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ static int wp_drbg_reseed(wp_DrbgCtx* ctx, int predResist,
377377
}
378378
}
379379

380-
/* Clear seed from parent if we obtained one. */
381-
if (seed != NULL && ctx->parentClearSeed != NULL) {
382-
ctx->parentClearSeed(ctx->parent, seed, seedLen);
380+
/* Securely clear and free locally allocated seed buffer. */
381+
if (seed != NULL) {
382+
OPENSSL_clear_free(seed, seedLen);
383383
}
384384

385385
(void)predResist;

src/wp_ecx_kmgmt.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,29 +361,40 @@ static wp_Ecx* wp_ecx_dup(const wp_Ecx* src, int selection)
361361
dst = wp_ecx_new(src->provCtx, src->data);
362362
}
363363
if (dst != NULL) {
364-
int ok = 1;
365-
366364
dst->includePublic = src->includePublic;
367365

368-
/* Copy the key union directly to preserve all internal state. */
366+
/* Copy the full key union to preserve internal wolfSSL state.
367+
* Private material is zeroized below if not selected. */
369368
XMEMCPY(&dst->key, &src->key, sizeof(src->key));
370369

371-
/* Copy public key flags if available and requested. */
370+
/* Set public key flag if available and requested. */
372371
if (src->hasPub &&
373372
((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)) {
374373
dst->hasPub = 1;
375374
}
376-
/* Copy private key flags if available and requested. */
375+
/* Set private key flag if available and requested. */
377376
if (src->hasPriv &&
378377
((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)) {
379378
dst->hasPriv = 1;
380379
dst->clamped = src->clamped;
381380
XMEMCPY(dst->unclamped, src->unclamped, sizeof(src->unclamped));
382381
}
383-
384-
if (!ok) {
385-
wp_ecx_free(dst);
386-
dst = NULL;
382+
else {
383+
/* Private key not selected — re-import only public key to
384+
* ensure no private material remains in the dst key object. */
385+
if (dst->hasPub) {
386+
byte buf[64];
387+
word32 len = (word32)sizeof(buf);
388+
int rc = (*src->data->exportPub)((void*)&src->key, buf, &len,
389+
ECX_LITTLE_ENDIAN);
390+
if (rc == 0) {
391+
/* Re-init key and import only public part. */
392+
(*dst->data->freeKey)((void*)&dst->key);
393+
(*dst->data->initKey)((void*)&dst->key);
394+
(*dst->data->importPub)(buf, len, (void*)&dst->key,
395+
ECX_LITTLE_ENDIAN);
396+
}
397+
}
387398
}
388399
}
389400

src/wp_hmac.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ static wp_HmacCtx* wp_hmac_dup(wp_HmacCtx* src)
188188
}
189189
if (dst != NULL) {
190190
int ok = 1;
191-
int rc;
192191

193192
dst->type = src->type;
194193
dst->size = src->size;
@@ -197,7 +196,6 @@ static wp_HmacCtx* wp_hmac_dup(wp_HmacCtx* src)
197196
/* Copy the Hmac struct directly to preserve in-progress state.
198197
* wc_HmacCopy is not available in all wolfSSL versions. */
199198
XMEMCPY(&dst->hmac, &src->hmac, sizeof(Hmac));
200-
(void)rc;
201199

202200
if (ok && (src->key != NULL) &&
203201
(!wp_hmac_set_key(dst, src->key, src->keyLen, 0))) {

src/wp_rsa_kmgmt.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,17 +1014,21 @@ static int wp_rsa_get_params_pss(wp_RsaPssParams* pss, OSSL_PARAM params[])
10141014
default: break;
10151015
}
10161016
if (mgfHash != WC_HASH_TYPE_NONE) {
1017-
wp_digest_to_ossl_digest(mgfHash, &mgfName);
1017+
if (!wp_digest_to_ossl_digest(mgfHash, &mgfName)) {
1018+
ok = 0;
1019+
}
10181020
}
10191021
}
10201022
/* Fall back to signing digest if MGF1 not explicitly set. */
1021-
if (mgfName == NULL) {
1023+
if (ok && mgfName == NULL) {
10221024
if (!wp_digest_to_ossl_digest(pss->hashType, &mgfName)) {
1023-
mgfName = OSSL_DIGEST_NAME_SHA1;
1025+
ok = 0;
10241026
}
10251027
}
1026-
if (!OSSL_PARAM_set_utf8_string(p, mgfName)) {
1027-
ok = 0;
1028+
if (ok && mgfName != NULL) {
1029+
if (!OSSL_PARAM_set_utf8_string(p, mgfName)) {
1030+
ok = 0;
1031+
}
10281032
}
10291033
}
10301034
}

test/test_tls_cbc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ static int test_des3_cbc_pad_roundtrip(OSSL_LIB_CTX *encCtx,
269269

270270
memset(key, 0xAA, sizeof(key));
271271
memset(iv, 0xBB, sizeof(iv));
272-
RAND_bytes(pt, sizeof(pt));
272+
if (RAND_bytes(pt, sizeof(pt)) != 1) {
273+
err = 1;
274+
}
273275

274276
/* Test various plaintext sizes to exercise all padding values (1-8). */
275277
for (i = 1; i <= 8 && err == 0; i++) {

0 commit comments

Comments
 (0)