Security: Memory Hardening — IDisposable & Buffer Zeroization#1107
Open
KonradSop wants to merge 2 commits intoNethereum:masterfrom
Open
Security: Memory Hardening — IDisposable & Buffer Zeroization#1107KonradSop wants to merge 2 commits intoNethereum:masterfrom
KonradSop wants to merge 2 commits intoNethereum:masterfrom
Conversation
Contributor
Author
|
I have upgraded the memory hardening implementation by conditionally moving from Array.Clear to CryptographicOperations.ZeroMemory for net5.0+ / netcoreapp3.1+. I have also completely eliminated the caching of _privateKeyHex as an immutable string inside EthECKey. Holding onto sensitive key materials in generic strings rendered the zeroing process pointless due to how strings are maintained inside .NET's memory. Recomputing it on the fly whenever GetPrivateKey() is called is exponentially safer |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security: Memory Hardening — IDisposable & Buffer Zeroization
🛡️ Summary
This PR improves the memory safety of sensitive cryptographic material in Nethereum.
It implements the
IDisposablepattern for EthECKey and enforces explicit zeroization (Array.Clear) for private key and derived key buffers throughout their lifecycle.🔒 Security Hardening Details
1. Nethereum.Signer (EthECKey)
_privateKeybyte array is now explicitly cleared in the Dispose method.EthECKey.GenerateKey()to use atry/finallyblock, ensuring that the temporary private key buffer is cleared instantly after the EthECKey instance is created.compresseed→compressed).2. Nethereum.KeyStore (KeyStoreCrypto)
try/finallyblocks to explicitly zero outderivedKeyandencryptKeybuffers immediately after the decryption operation is completed.✅ Verification Results
privateKeybuffer is zeroed after Dispose.derivedKeyis zeroed after decryption.net8.0.Strengthening Nethereum's resistance to memory dump analysis.