Better zeroizing in CryptoKey.

This commit is contained in:
Fabio Alessandrelli 2020-06-07 17:27:22 +02:00
parent 8e68f2e5f4
commit a486783d3d

View file

@ -84,14 +84,14 @@ Error CryptoKeyMbedTLS::save(String p_path) {
int ret = mbedtls_pk_write_key_pem(&pkey, w, sizeof(w));
if (ret != 0) {
memdelete(f);
memset(w, 0, sizeof(w)); // Zeroize anything we might have written.
mbedtls_platform_zeroize(w, sizeof(w)); // Zeroize anything we might have written.
ERR_FAIL_V_MSG(FAILED, "Error writing key '" + itos(ret) + "'.");
}
size_t len = strlen((char *)w);
f->store_buffer(w, len);
memdelete(f);
memset(w, 0, sizeof(w)); // Zeroize temporary buffer.
mbedtls_platform_zeroize(w, sizeof(w)); // Zeroize temporary buffer.
return OK;
}