fix: wipe private key bytes and passphrases when they're freed - #542
Draft
irvingouj@Devolutions (irvingoujAtDevolution) wants to merge 1 commit into
Draft
irvingouj@Devolutions (irvingoujAtDevolution) wants to merge 1 commit into
irvingouj@Devolutions (irvingoujAtDevolution) wants to merge 1 commit into
Conversation
irvingouj@Devolutions (irvingoujAtDevolution)
added this pull request to stack #540
September 30, 2026 03:01
Disposing a key object from .NET now zeroes what it held instead of just freeing it. - Pem: the decoded bytes, since a PEM can carry a private key - SshPrivateKey: the passphrase (picky already wipes the key itself) - SshPrivateKey/PuttyPpk ToRepr: the temporary string holding the encoded key - Ppk: the private key buffer and the copies made while encrypting, decrypting and converting. make_padding now allocates its final size up front so a resize can't leave a plaintext copy behind. Adds .NET round-trip tests for passphrase-protected SSH keys and encrypted PPKs, which had no coverage before. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
irvingouj@Devolutions (irvingoujAtDevolution)
force-pushed
the
ffi/zeroize-secrets
branch
from
September 30, 2026 03:31
32c05fb to
ccf3613
Compare
This branch has not been deployed
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.
On top of #541. Disposing a key from .NET now zeroes what it held instead of just freeing it.
Pem: the decoded bytes, since a PEM can carry a private keySshPrivateKey: the passphrase. picky already wipes the key itselfSshPrivateKey.ToRepr/PuttyPpk.ToRepr: the temporary string holding the encoded keyPpk(picky core): the private key buffer isZeroizingnow, so the copies made while encrypting, decrypting and converting get wiped too.make_paddingallocates its final size up front so a resize can't leave a plaintext copy behind. Field is private, no API changeWhat this doesn't cover (it's all outside picky):
ToReprstring, and thebyte[]C# builds for astringargument (Diplomat.Utf8.Clone). That's the generator, so it's a follow-up in Devolutions/diplomatstringyou get back fromToRepror pass in as a passphrase. It's immutable, nothing to wipeNew tests: passphrase-protected SSH key and encrypted PPK round trips. Neither had .NET coverage before.
Tested: 34/34 on net6 and 17/17 on net48, debug and release native. picky putty/ssh/pem 95/95.