Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wp_dec_pem2der.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ static int wp_pem2der_decode(wp_Pem2Der* ctx, OSSL_CORE_BIO* coreBio,
dataCbArg, pwCb, pwCbArg);
}
}
/* Dispose of the PEM data buffer. */
OPENSSL_free(data);
/* Dispose of the PEM data buffer (may contain private key material). */
OPENSSL_clear_free(data, len);

WOLFPROV_LEAVE(WP_LOG_COMP_PK, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
return ok;
Expand Down
2 changes: 2 additions & 0 deletions src/wp_ecx_kmgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ void wp_ecx_free(wp_Ecx* ecx)
wc_FreeMutex(&ecx->mutex);
#endif
(*ecx->data->freeKey)((void*)&ecx->key);
/* unclamped holds 2 bytes of the original private key. */
OPENSSL_cleanse(ecx->unclamped, sizeof(ecx->unclamped));
OPENSSL_free(ecx);
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/wp_file_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ static void wp_bio_consume_all(BIO* bio)
do {
bytes_read = BIO_read(bio, buffer, sizeof(buffer));
} while (bytes_read > 0);

/* buffer may hold private key material from the drained file. */
OPENSSL_cleanse(buffer, sizeof(buffer));
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/wp_hkdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,9 @@ static int wp_tls13_hkdf_extract(wp_HkdfCtx* ctx, unsigned char* key,
}
}

/* secret may hold a Derive-Secret intermediate used as the salt. */
OPENSSL_cleanse(secret, sizeof(secret));

WOLFPROV_LEAVE(WP_LOG_COMP_HKDF, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
return ok;
}
Expand Down
6 changes: 6 additions & 0 deletions src/wp_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,9 @@ int wp_read_der_bio(WOLFPROV_CTX *provctx, OSSL_CORE_BIO *coreBio, unsigned char
}
}

/* buf may hold plaintext private key DER fragments. */
OPENSSL_cleanse(buf, sizeof(buf));

BIO_free(bio);
WOLFPROV_LEAVE(WP_LOG_COMP_PROVIDER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
return ok;
Expand Down Expand Up @@ -1266,6 +1269,9 @@ int wp_read_pem_bio(WOLFPROV_CTX *provctx, OSSL_CORE_BIO *coreBio,
}
}

/* buf may hold plaintext private key PEM line fragments. */
OPENSSL_cleanse(buf, sizeof(buf));

BIO_free(bio);
WOLFPROV_LEAVE(WP_LOG_COMP_PROVIDER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__),
ok);
Expand Down
6 changes: 6 additions & 0 deletions src/wp_kbkdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ static int wp_kbkdf_init_hmac(wp_KbkdfCtx* ctx, unsigned char* key,
}
}

/* localKey holds a copy of the secret KDF key. */
OPENSSL_cleanse(localKey, sizeof(localKey));

WOLFPROV_LEAVE(WP_LOG_COMP_KDF, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
/* Use rc style return */
return (ok == 1) ? 0 : -1;
Expand Down Expand Up @@ -683,6 +686,9 @@ static int wp_kdf_kbkdf_derive(wp_KbkdfCtx* ctx, unsigned char* key,
wp_kbkdf_mac_free(ctx);
}

/* k_i holds derived key block(s) (and feedback state). */
OPENSSL_cleanse(k_i, sizeof(k_i));

WOLFPROV_LEAVE(WP_LOG_COMP_KDF, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
return ok;
}
Expand Down
4 changes: 4 additions & 0 deletions src/wp_krb5kdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ static int wp_kdf_krb5kdf_derive(wp_Krb5kdfCtx* ctx, unsigned char* key,

wc_AesFree(&aes);

/* block and cipherBlock hold derived key material. */
OPENSSL_cleanse(block, sizeof(block));
OPENSSL_cleanse(cipherBlock, sizeof(cipherBlock));

WOLFPROV_LEAVE(WP_LOG_COMP_KRB5KDF, "wp_kdf_krb5kdf_derive", ok);
return ok;
}
Expand Down
3 changes: 3 additions & 0 deletions src/wp_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ int wp_mp_read_unsigned_bin_le(mp_int* mp, const unsigned char* data,
}
}

/* rdata may hold private key material (RSA d/p/q, EC/DH private). */
OPENSSL_cleanse(rdata, sizeof(rdata));

WOLFPROV_LEAVE(WP_LOG_COMP_PROVIDER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
return ok;
}
Expand Down
9 changes: 7 additions & 2 deletions src/wp_rsa_kmgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -3316,6 +3316,10 @@ static int wp_rsa_encode_enc_pki(const wp_RsaEncDecCtx* ctx, const wp_Rsa* rsa,
}
}

/* encodedKey holds the plaintext PKCS#8 private key before encryption. */
if (encodedKey != NULL) {
OPENSSL_cleanse(encodedKey, len);
}
XFREE(encodedKey, NULL, DYNAMIC_TYPE_RSA_BUFFER);

OPENSSL_cleanse(password, sizeof(password));
Expand Down Expand Up @@ -4276,7 +4280,7 @@ static int wp_rsa_encode_text_format_hex(BIO *out, const mp_int* num,
}
else if (mp_to_unsigned_bin((mp_int*)num, binData) != MP_OKAY) {
ok = 0;
OPENSSL_free(binData);
OPENSSL_clear_free(binData, binLen);
binData = NULL;
}
else {
Expand Down Expand Up @@ -4315,7 +4319,8 @@ static int wp_rsa_encode_text_format_hex(BIO *out, const mp_int* num,
}
}

OPENSSL_free(binData);
/* binData may hold private CRT components (d/p/q/dP/dQ/u). */
OPENSSL_clear_free(binData, binLen);
binData = NULL;
}

Expand Down
4 changes: 2 additions & 2 deletions src/wp_seed_src.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,14 +657,14 @@ static size_t wp_seed_src_get_seed(wp_SeedSrcCtx* ctx, unsigned char** pSeed,
if (rc != (int)minLen) {
WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_LEVEL_DEBUG,
"wp_urandom_read failed", rc);
OPENSSL_free(buffer);
OPENSSL_clear_free(buffer, minLen);
buffer = NULL;
goto end;
}

/* Mix in additional input if provided */
if (!wp_seed_src_adin_mix_in(buffer, minLen, addIn, addInLen)) {
OPENSSL_free(buffer);
OPENSSL_clear_free(buffer, minLen);
buffer = NULL;
goto end;
}
Expand Down
Loading