-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce soter_wipe() function (#488)
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.
- Loading branch information
Showing
10 changed files
with
136 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2019 Cossack Labs Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "soter/soter_wipe.h" | ||
|
||
#include <openssl/crypto.h> | ||
|
||
soter_status_t soter_wipe(void* data, size_t length) | ||
{ | ||
if (!data) { | ||
return SOTER_INVALID_PARAMETER; | ||
} | ||
|
||
OPENSSL_cleanse(data, length); | ||
|
||
return SOTER_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2019 Cossack Labs Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "soter/soter_wipe.h" | ||
|
||
#include <openssl/crypto.h> | ||
|
||
soter_status_t soter_wipe(void* data, size_t length) | ||
{ | ||
if (!data) { | ||
return SOTER_INVALID_PARAMETER; | ||
} | ||
|
||
OPENSSL_cleanse(data, length); | ||
|
||
return SOTER_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2019 Cossack Labs Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef SOTER_WIPE_H | ||
#define SOTER_WIPE_H | ||
|
||
#include <soter/soter_api.h> | ||
#include <soter/soter_error.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* Securely erases sensitive data from memory. | ||
* | ||
* Use this function to wipe sensitive data (e.g., passwords, private keys) | ||
* after you don't need it anymore. This function call will not be optimized | ||
* out by the compiler. | ||
* | ||
* @param [in] data pointer to data to wiped | ||
* @param [in] length length of the data in bytes | ||
* @return SOTER_SUCCESS on success, | ||
* SOTER_INVALID_PARAMETER on NULL data | ||
*/ | ||
SOTER_API | ||
soter_status_t soter_wipe(void* data, size_t length); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* SOTER_WIPE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters