aboutsummaryrefslogtreecommitdiff
path: root/rsh/transport_test.go
diff options
context:
space:
mode:
authorLena <lena@omega>2026-07-01 00:00:00 +0000
committerLena <lena@omega>2026-07-01 00:00:00 +0000
commit1da5637997e7971cbde77dbf642ea734fbb2f4cc (patch)
tree8b3891c9a6e37275997f0e9d44df219d2b50076c /rsh/transport_test.go
parent72e37d2dac501faa300ca895c56c53eea43ae4ae (diff)
downloadrsend-1da5637997e7971cbde77dbf642ea734fbb2f4cc.tar.gz
keys: never write the plaintext private key to disk
rsh -keygen printed the pubkey but wrote the key pair into a directory, so generating a key briefly left the plaintext private key on flash, contradicting the documented invariant that it only ever exists in memory. -keygen now emits the private key PEM on stdout and nothing else; the app encrypts it immediately and derives the public key via -pubkey, reusing the validated import path. Keygen failures now surface as an error dialog instead of crashing the app from a bare thread.
Diffstat (limited to 'rsh/transport_test.go')
-rw-r--r--rsh/transport_test.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/rsh/transport_test.go b/rsh/transport_test.go
index 562c4d2..7ff74b1 100644
--- a/rsh/transport_test.go
+++ b/rsh/transport_test.go
@@ -15,24 +15,23 @@ import (
"golang.org/x/crypto/ssh/knownhosts"
)
-// genClientKey makes a client key via keygen and returns the private key path
-// and the parsed public key.
+// genClientKey makes a client key via keygen, writes it to a file for RSH_KEY,
+// and returns the private key path and the corresponding public key.
func genClientKey(t *testing.T) (keyPath string, pub ssh.PublicKey) {
t.Helper()
- dir := t.TempDir()
- if err := keygen(dir, io.Discard); err != nil {
+ var buf bytes.Buffer
+ if err := keygen(&buf); err != nil {
t.Fatal(err)
}
- keyPath = filepath.Join(dir, "id_ed25519")
- pb, err := os.ReadFile(filepath.Join(dir, "id_ed25519.pub"))
- if err != nil {
+ keyPath = filepath.Join(t.TempDir(), "id_ed25519")
+ if err := os.WriteFile(keyPath, buf.Bytes(), 0o600); err != nil {
t.Fatal(err)
}
- pub, _, _, _, err = ssh.ParseAuthorizedKey(pb)
+ signer, err := ssh.ParsePrivateKey(buf.Bytes())
if err != nil {
t.Fatal(err)
}
- return keyPath, pub
+ return keyPath, signer.PublicKey()
}
func writeKnownHosts(t *testing.T, host string, port int, hostKey ssh.PublicKey) string {