Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce soter_wipe() function #488

Merged
merged 3 commits into from
Jul 4, 2019
Merged

Conversation

ilammy
Copy link
Collaborator

@ilammy ilammy commented Jul 3, 2019

It's a good security practice to wipe out sensitive data from memory once it's no longer needed. Straightforward approach to this is to call memset(data, 0, size) before freeing the keys or something. However, compilers often optimize memset() implementation and end up optimizing out that call completely since they see that the data is freed. We can prevent that.

  • Introduce secure_wipe() function

Add a utility function to securely wipe memory region. We have quite a few places in our code where this can be useful, and it's a good function to export for the users (of Soter).

It's implemented via OPENSSL_cleanse() function on both OpenSSL and BoringSSL. That's an old function available since OpenSSL 1.0.2 so we should not run into any compatibility issues (and we do recommend using latest OpenSSL anyway).

Note that it intentionally accepts void*, not uint8_t* (just like free() does). Implicit cast is expected here and allow wiping any object without warnings from compiler.

  • Securely wipe sensitive data

Replace ad-hoc memset() calls with soter_wipe(). This ensures that these calls will not be optimized out by the compiler in release build mode.

Add a utility function to securely wipe memory region. We have quite
a few places in our code where this can be useful, and it's a good
function to export for the users (of Soter).

It's implemented via OPENSSL_cleanse() function on both OpenSSL and
BoringSSL. That's an old function available since OpenSSL 1.0.2 so we
should not run into any compatibility issues (and we *do* recommend
using latest OpenSSL anyway).

Note that it intentionally accepts `void*`, not `uint8_t*` (just like
free() does). Implicit cast is expected here and allow wiping any object
without warnings from compiler.
Replace ad-hoc memset() calls with soter_wipe(). This ensures that
these calls will not be optimized out by the compiler in release
build mode.
@ilammy ilammy added enhancement core Themis Core written in C, its packages labels Jul 3, 2019
@ilammy ilammy changed the title Introduce secure_wipe() function Introduce soter_wipe() function Jul 3, 2019
Copy link
Collaborator

@Lagovas Lagovas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, so we decided to use backend's implementations to securely clear data

@ilammy ilammy merged commit df8632a into cossacklabs:master Jul 4, 2019
@ilammy ilammy deleted the zeroize branch July 4, 2019 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Themis Core written in C, its packages enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants