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

[Sec]: Zeroize the memory for each TWString #3511

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
02a2430
[Sec]: Zeroize the memory for each TWString
satoshiotomakan Oct 25, 2023
7cfebf9
[CI]: Downgrade Rust code coverage
satoshiotomakan Oct 25, 2023
9959935
[Sec]: Zeroize mnemonic data
satoshiotomakan Oct 25, 2023
95742cb
[Sec]: Do not zeroize an empty string
satoshiotomakan Oct 25, 2023
5646264
[Sec]: Delete TWString by the original sConst pointer
satoshiotomakan Oct 26, 2023
8dd59ea
[Sec]: Test without explicit_bzero
satoshiotomakan Oct 26, 2023
060b46f
[Sec]: Reinstall internal dependencies
satoshiotomakan Oct 26, 2023
2fdc5ba
[CI]: Clear and reinstall internal dependencies
satoshiotomakan Oct 26, 2023
cb06e32
[CI]: Try to avoid using the cache
satoshiotomakan Oct 26, 2023
aedc7ae
[CI]: Install clang-17
satoshiotomakan Oct 27, 2023
e2755ff
[CI]: Install clang-tidy-17
satoshiotomakan Oct 27, 2023
562f2b0
[CI]: Fix installing clang-tidy-17
satoshiotomakan Oct 27, 2023
c1aa1d5
[Sec]: Fix TWSegwitAddress.InitWithAddress
satoshiotomakan Oct 27, 2023
cadc3da
[CI]: Try using clang-14
satoshiotomakan Oct 27, 2023
3eab105
[CI]: Add -DCMAKE_CXX_COMPILER=clang++-17 -DCMAKE_C_COMPILER=clang-17…
satoshiotomakan Oct 27, 2023
162d9f2
[CI]: Try to use ubuntu-20.04
satoshiotomakan Oct 27, 2023
aebbd43
[CI]: Install clang-14 by using llvm.sh
satoshiotomakan Oct 27, 2023
369bc0e
[CI]: Reinstall internal deps
satoshiotomakan Oct 27, 2023
67ddac3
[CI]: Some fixes
satoshiotomakan Oct 27, 2023
4ed7aeb
[CI]: Fix filecoin boost usage
satoshiotomakan Oct 27, 2023
5e1497d
[CI]: Install boost from jammy ubuntu repository
satoshiotomakan Oct 27, 2023
42d6f9a
[CI]: Try using clang-15
satoshiotomakan Oct 27, 2023
648f4e0
[CI]: Install missing libboost-all-dev
satoshiotomakan Oct 27, 2023
867e149
[CI]: Fix sys dependencies
satoshiotomakan Oct 27, 2023
4a255d5
[CI]: Pass stdlib=libc++ and c++20 CXX flags
satoshiotomakan Oct 30, 2023
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
2 changes: 1 addition & 1 deletion rust/coverage.stats
Original file line number Diff line number Diff line change
@@ -1 +1 @@
92.0
91.0
7 changes: 6 additions & 1 deletion src/Keystore/StoredKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <nlohmann/json.hpp>
#include <TrezorCrypto/memzero.h>

#include <cassert>
#include <fstream>
Expand All @@ -32,7 +33,11 @@ StoredKey StoredKey::createWithMnemonic(const std::string& name, const Data& pas
}

Data mnemonicData = TW::Data(mnemonic.begin(), mnemonic.end());
return StoredKey(StoredKeyType::mnemonicPhrase, name, password, mnemonicData, encryptionLevel, encryption);
StoredKey key(StoredKeyType::mnemonicPhrase, name, password, mnemonicData, encryptionLevel, encryption);
if (!mnemonicData.empty()) {
memzero(mnemonicData.data(), mnemonic.size());
}
return key;
}

StoredKey StoredKey::createWithMnemonicRandom(const std::string& name, const Data& password, TWStoredKeyEncryptionLevel encryptionLevel, TWStoredKeyEncryption encryption) {
Expand Down
10 changes: 9 additions & 1 deletion src/interface/TWString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@


#include <TrustWalletCore/TWString.h>

#include <string>
#include <TrezorCrypto/memzero.h>

TWString *_Nonnull TWStringCreateWithUTF8Bytes(const char *_Nonnull bytes) {
auto* s = new std::string(bytes);
Expand Down Expand Up @@ -34,7 +36,13 @@ const char *_Nonnull TWStringUTF8Bytes(TWString *_Nonnull string) {
}

void TWStringDelete(TWString *_Nonnull string) {
auto* s = reinterpret_cast<const std::string*>(string);
auto *sConst = reinterpret_cast<const std::string*>(string);
// `const_cast` is safe here despite that the pointer to the string is const
// but `std::string` is not a constant value.
auto *s = const_cast<std::string*>(sConst);
if (!s->empty()) {
memzero(s->data(), s->size());
}
delete s;
}

Expand Down
Loading