mirror of
https://github.com/db9979/sshtermy.git
synced 2026-12-06 20:54:09 +01:00
* Absicherung: Tests auf Windows/macOS, govulncheck, Dependabot, Fuzz-Tests, Signatur-Anleitung - CI: Job platforms (windows-latest, macos-latest), vuln (govulncheck), fuzz (15 s je Ziel) - Go immer neuester 1.26-Patch (check-latest) statt fest 1.26.0 - Dependabot für Go-Module und Actions (wöchentlich, gruppiert) - Fuzz-Tests: Terminal-Emulator, Bildsequenzen, Telnet, PPK, LLDP/ARP/MAC, Import, Host-Übersicht, trzsz-Dateinamen - PPK: Argon2-Werte aus der Datei begrenzt (1 GiB, 1000 Durchläufe) - release.yml: Warnung bei unsigniertem Release, Abbruch bei Public Key ohne Secret - docs/signatur.md, make fuzz / make vuln Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz * Signatur-Anleitung: keygen im Repository-Ordner ausführen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz * Host-Übersicht macOS: Laufzeit aus kern.boottime richtig lesen (sed nahm usec statt sec) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz * Import ssh_config: Include nur normale Dateien bis 1 MiB, höchstens 64 (Fuzz-Fund: Import hing) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz * Windows: Switch-Auflegen auch bei WSAECONNRESET erkennen, Latenz nie 0; Tests plattformfest - isHangup: WSAECONNRESET/WSAECONNABORTED per Fehlercode (deutscher Windows-Text half der Textsuche nicht) - Keepalive-Latenz mindestens 1 ns (Windows-Uhr gröber als localhost-Rundreise) - Tests: USERPROFILE neben HOME, Unix-Rechte nur außerhalb Windows prüfen, Server-Skript-Test nicht unter Git-Bash, Windows-Pfad mit Laufwerk Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz * Sixel: Zahlen deckeln (Fuzz-Fund: überlaufende Wiederholung hielt das Terminal Sekunden bis endlos fest) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz * Eigenes Fenster (Windows): Named Pipe mit Puffer, Schreiben blockiert nicht mehr bis zum Lesen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz --------- Co-authored-by: Claude <noreply@anthropic.com>
104 lines
3.0 KiB
Go
104 lines
3.0 KiB
Go
package sshx
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
|
|
"golang.org/x/crypto/ssh"
|
|
)
|
|
|
|
func TestGenerateKeyWithPassphrase(t *testing.T) {
|
|
k, err := GenerateKey(KeyEd25519, "me@pc-sshtermy", []byte("pw"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.HasPrefix(k.PublicLine, "ssh-ed25519 ") || !strings.HasSuffix(k.PublicLine, " me@pc-sshtermy") {
|
|
t.Fatalf("PublicLine = %q", k.PublicLine)
|
|
}
|
|
if _, err := ssh.ParsePrivateKey(k.PrivatePEM); err == nil {
|
|
t.Fatal("Key ohne Passphrase lesbar")
|
|
}
|
|
s, err := ssh.ParsePrivateKeyWithPassphrase(k.PrivatePEM, []byte("pw"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(s.PublicKey().Marshal()) != string(k.Signer.PublicKey().Marshal()) {
|
|
t.Fatal("öffentlicher Teil passt nicht")
|
|
}
|
|
if _, err := LoadKey(k.PrivatePEM, nil); err == nil {
|
|
t.Fatal("LoadKey ohne Passphrase müsste scheitern")
|
|
}
|
|
if l, err := LoadKey(k.PrivatePEM, []byte("pw")); err != nil || !strings.HasPrefix(l.PublicLine, "ssh-ed25519 ") {
|
|
t.Fatal(l, err)
|
|
}
|
|
}
|
|
|
|
func TestWriteKeyFilesNoOverwrite(t *testing.T) {
|
|
k, err := GenerateKey(KeyEd25519, "x", nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p := filepath.Join(t.TempDir(), "sub", "id_test")
|
|
if err := WriteKeyFiles(p, k); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if st, _ := os.Stat(p); runtime.GOOS != "windows" && st.Mode().Perm() != 0o600 { // Windows: keine Unix-Rechte
|
|
t.Errorf("Rechte %v", st.Mode().Perm())
|
|
}
|
|
if b, _ := os.ReadFile(p + ".pub"); strings.TrimSpace(string(b)) != k.PublicLine {
|
|
t.Errorf(".pub = %q", b)
|
|
}
|
|
if err := CheckKeyFile(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := WriteKeyFiles(p, k); err == nil {
|
|
t.Fatal("vorhandene Datei überschrieben")
|
|
}
|
|
}
|
|
|
|
func TestInstallScript(t *testing.T) {
|
|
sh, err := exec.LookPath("sh")
|
|
if err != nil {
|
|
t.Skip("keine sh")
|
|
}
|
|
k, _ := GenerateKey(KeyEd25519, "a@b-sshtermy", nil)
|
|
script, err := InstallScript(k.PublicLine)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
home := t.TempDir()
|
|
// vorhandene Datei ohne Zeilenende am Schluss
|
|
os.MkdirAll(filepath.Join(home, ".ssh"), 0o755)
|
|
os.WriteFile(filepath.Join(home, ".ssh", "authorized_keys"), []byte("ssh-rsa AAAAold old"), 0o644)
|
|
run := func() string {
|
|
cmd := exec.Command(sh, "-c", script)
|
|
cmd.Env = []string{"HOME=" + home, "PATH=" + os.Getenv("PATH")}
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("%v: %s", err, out)
|
|
}
|
|
return string(out)
|
|
}
|
|
if out := run(); !strings.Contains(out, markAdded) {
|
|
t.Fatalf("erster Lauf: %q", out)
|
|
}
|
|
if out := run(); !strings.Contains(out, markHave) {
|
|
t.Fatalf("zweiter Lauf: %q", out)
|
|
}
|
|
b, _ := os.ReadFile(filepath.Join(home, ".ssh", "authorized_keys"))
|
|
want := "ssh-rsa AAAAold old\n" + k.PublicLine + "\n"
|
|
if string(b) != want {
|
|
t.Fatalf("authorized_keys = %q", b)
|
|
}
|
|
if st, _ := os.Stat(filepath.Join(home, ".ssh")); runtime.GOOS != "windows" && st.Mode().Perm() != 0o700 {
|
|
t.Errorf(".ssh Rechte %v", st.Mode().Perm())
|
|
}
|
|
if _, err := InstallScript("ssh-ed25519 AAAA'; rm -rf / #"); err == nil {
|
|
t.Fatal("Anführungszeichen im Key durchgelassen")
|
|
}
|
|
}
|