I'm trying to ensure that sensitive data (passwords, ...) are not kept in clear-text in process memory and I have found that all data sent to or received from OpenSSL is kept in memory...
This is a problem as data sent or received from an SSL connection may contain sensitive information that we don't want to keep in process memory.
Notes:
Reproduction is easy:
openssl client -tls1 -connect hostname:443
' to connect to an SSL serverkill -SEGV
for example)Is there a reason for which OpenSSL may need to keep that data? Is there an option to alter its behavior?
Note: I'm replying to my own question after having found the explanation I was looking for.
The data is kept in zlib buffers if compression is enabled on the connection. That's why it is not observed with some configuration/server. It is surely required by zlib to correctly compress the flow.
If you don't need compression and you don't want unencrypted data to stay for a long time in process memory, you can disable OpenSSL compression.
STACK_OF(SSL_COMP)* cm = SSL_COMP_get_compression_methods();
sk_SSL_COMP_zero(cm);