Skip to content

Commit c29ac26

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 8e2d7c2 commit c29ac26

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
@@ -170,8 +170,14 @@ static wp_CmacCtx* wp_cmac_dup(wp_CmacCtx* src)
170170
dst->type = src->type;
171171
dst->size = src->size;
172172
dst->expKeySize = src->expKeySize;
173-
XMEMCPY(dst->key, src->key, src->keyLen);
174-
dst->keyLen = src->keyLen;
173+
if (src->keyLen <= sizeof(dst->key)) {
174+
XMEMCPY(dst->key, src->key, src->keyLen);
175+
dst->keyLen = src->keyLen;
176+
}
177+
else {
178+
wp_cmac_free(dst);
179+
dst = NULL;
180+
}
175181
}
176182

177183
return dst;

src/wp_drbg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,9 @@ static int wp_drbg_reseed(wp_DrbgCtx* ctx, int predResist,
380380
}
381381
}
382382

383-
/* Clear seed from parent if we obtained one. */
384-
if (seed != NULL && ctx->parentClearSeed != NULL) {
385-
ctx->parentClearSeed(ctx->parent, seed, seedLen);
383+
/* Securely clear and free locally allocated seed buffer. */
384+
if (seed != NULL) {
385+
OPENSSL_clear_free(seed, seedLen);
386386
}
387387

388388
(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
@@ -1015,17 +1015,21 @@ static int wp_rsa_get_params_pss(wp_RsaPssParams* pss, OSSL_PARAM params[])
10151015
default: break;
10161016
}
10171017
if (mgfHash != WC_HASH_TYPE_NONE) {
1018-
wp_digest_to_ossl_digest(mgfHash, &mgfName);
1018+
if (!wp_digest_to_ossl_digest(mgfHash, &mgfName)) {
1019+
ok = 0;
1020+
}
10191021
}
10201022
}
10211023
/* Fall back to signing digest if MGF1 not explicitly set. */
1022-
if (mgfName == NULL) {
1024+
if (ok && mgfName == NULL) {
10231025
if (!wp_digest_to_ossl_digest(pss->hashType, &mgfName)) {
1024-
mgfName = OSSL_DIGEST_NAME_SHA1;
1026+
ok = 0;
10251027
}
10261028
}
1027-
if (!OSSL_PARAM_set_utf8_string(p, mgfName)) {
1028-
ok = 0;
1029+
if (ok && mgfName != NULL) {
1030+
if (!OSSL_PARAM_set_utf8_string(p, mgfName)) {
1031+
ok = 0;
1032+
}
10291033
}
10301034
}
10311035
}

test/test_tls_cbc.c

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

477477
memset(key, 0xAA, sizeof(key));
478478
memset(iv, 0xBB, sizeof(iv));
479-
RAND_bytes(pt, sizeof(pt));
479+
if (RAND_bytes(pt, sizeof(pt)) != 1) {
480+
err = 1;
481+
}
480482

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

0 commit comments

Comments
 (0)