mirror of
https://github.com/db9979/sshtermy.git
synced 2026-12-05 12:24:08 +01:00
* Debug-Protokoll für Fehlerberichte, Barrierearm-Modus und Farbenblind-Themes - internal/debuglog: Ereignisse (SSH-Aufbau, Abbrüche, Updates, KI-Anfragen, Sync), Rotation 4 MiB - Schalter in Einstellungen, --debug, bereinigte Kopie (crash.Clean) nach Downloads - Barrierearm: keine Animationen, × für nicht erreichbar, Startanimation aus; geht mit dem Sync - Themes Farbenblind dunkel/hell (Okabe-Ito) - README, README.de, Webseite, Kurzreferenz Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz * Release-Signatur: Schlüssel tolerant lesen, klare Fehlermeldung, Abgleich mit UPDATE_PUBKEY Der Release-Lauf nach #81 brach mit „UPDATE_SIGNING_KEY fehlt oder ist ungültig“ ab. sshtermy-sign ignoriert jetzt Zeilenumbrüche, Leerzeichen, Anführungszeichen und die keygen-Überschrift, nennt bei Fehlern die gefundene Länge (nie den Schlüssel) und prüft, dass der private Schlüssel zu UPDATE_PUBKEY passt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz * Gesamtsicherung/Umzug und KI-Datenschutz - Gesamtsicherung: ganzer Datenordner als eine mit dem Master-Passwort verschlüsselte Datei (.sshtbak, Argon2id + AES-256-GCM in Blöcken); Einstellungen › Import / Export oder sshtermy backup / restore. Einspielen nach Rückfrage beim Neustart, der alte Ordner bleibt als <ordner>.vorher-<zeit> - KI-Datenschutz (Einstellungen › KI): alle Anbieter / nur lokale KI / KI aus, pro Verbindung per Tag ki-lokal / ki-aus (no-ai, ai-local); strengere Stufe gilt - „Letzte KI-Anfrage ansehen“: was zuletzt an welchen Host/welches Modell ging - Doku: README DE/EN, Webseite, Handout Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz * Audit-Protokoll und Herstellerprofile Juniper, MikroTik, Fortinet - internal/audit: fälschungssicheres Protokoll (HMAC-Kette mit Schlüssel aus dem Store, signierter Kopf gegen abgeschnittene Enden), Monatsdateien im Datenordner - Einstellungen › Sicherheit: Audit-Protokoll an/aus (nur dieser Rechner), prüfen und speichern; erfasst Verbindungen, Befehle (Agent/Broadcast markiert, private nur als „(privat)“), Übertragungen, Config-Sicherungen, Verbindungen, Master-Passwort, Gesamtsicherungen, KI-Anfragen (Host/Modell) - Host-Übersicht und Config-Sicherung für Juniper Junos, MikroTik RouterOS, FortiGate: eigene Befehle und Parser, Prompts „[admin@MikroTik] >“ / „FGT #“, Blättern „---(more)---“ / „-- [Q quit|D dump|down]“; geplante Sicherung nimmt den passenden Befehl - Schnellbefehle Juniper und FortiGate; „nur lesen“ kennt get …, /… print, /export - Doku: README DE/EN, Webseite, Handout Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUifSEzjZLFvqVjcUxz * Verbindungen überstehen Ruhezustand und Netzwechsel - internal/netwatch: Ruhezustand (Wanduhr läuft der monotonen Uhr davon oder der Takt kommt viel zu spät) und Netzwechsel (andere eigene Adressen) erkennen - danach prüft sshTermy jede SSH-Leitung sofort (sshx.Client.Check, 4 s) statt bis zu 30 s auf den Keepalive zu warten; wartende Neuverbindungen starten gleich neu - ohne Netz zählen Neuverbindungsversuche nicht, die Sitzung wartet auf eine Adresse - Doku: README DE/EN, Webseite 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>
203 lines
5.4 KiB
Go
203 lines
5.4 KiB
Go
package sshx
|
|
|
|
import (
|
|
"context"
|
|
"crypto/ed25519"
|
|
"crypto/rand"
|
|
"errors"
|
|
"fmt"
|
|
"net"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
|
|
"golang.org/x/crypto/ssh"
|
|
|
|
"github.com/db9979/sshtermy/internal/domain"
|
|
)
|
|
|
|
// stallServer beantwortet die ersten answer Keepalives und dann keine mehr
|
|
// (wie eine Leitung, die mitten in der Sitzung stumm wird).
|
|
type stallServer struct {
|
|
addr string
|
|
answer int32
|
|
seen atomic.Int32
|
|
conns chan net.Conn
|
|
openTCP chan net.Conn
|
|
}
|
|
|
|
func startStallServer(t *testing.T, answer int32) *stallServer {
|
|
t.Helper()
|
|
_, priv, _ := ed25519.GenerateKey(rand.Reader)
|
|
signer, _ := ssh.NewSignerFromKey(priv)
|
|
cfg := &ssh.ServerConfig{
|
|
PasswordCallback: func(ssh.ConnMetadata, []byte) (*ssh.Permissions, error) { return nil, nil },
|
|
ServerVersion: "SSH-2.0-OpenSSH_9.6",
|
|
}
|
|
cfg.AddHostKey(signer)
|
|
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { ln.Close() })
|
|
s := &stallServer{addr: ln.Addr().String(), answer: answer, openTCP: make(chan net.Conn, 4)}
|
|
go func() {
|
|
for {
|
|
nc, err := ln.Accept()
|
|
if err != nil {
|
|
return
|
|
}
|
|
s.openTCP <- nc
|
|
go func() {
|
|
sc, chans, reqs, err := ssh.NewServerConn(nc, cfg)
|
|
if err != nil {
|
|
return
|
|
}
|
|
defer sc.Close()
|
|
go func() {
|
|
for r := range reqs {
|
|
if s.seen.Add(1) <= s.answer && r.WantReply {
|
|
r.Reply(false, nil)
|
|
}
|
|
}
|
|
}()
|
|
for nch := range chans {
|
|
nch.Reject(ssh.Prohibited, "nein")
|
|
}
|
|
}()
|
|
}
|
|
}()
|
|
return s
|
|
}
|
|
|
|
func dialStall(t *testing.T, s *stallServer) *Client {
|
|
t.Helper()
|
|
hs, _ := NewHostKeyStore(filepath.Join(t.TempDir(), "known_hosts"))
|
|
host, port, _ := net.SplitHostPort(s.addr)
|
|
p, _ := strconv.Atoi(port)
|
|
c := domain.Connection{Alias: "x", Host: host, Port: p, Username: "u", Auth: domain.AuthPassword,
|
|
Password: "x", Device: domain.DeviceServer}
|
|
cl, err := Dial(context.Background(), c, Options{HostKeys: hs, Prompt: func(string, string, string) bool { return true }, Timeout: 5 * time.Second})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return cl
|
|
}
|
|
|
|
func TestDroppedWhenPeerGoesAway(t *testing.T) {
|
|
s := startStallServer(t, 100)
|
|
cl := dialStall(t, s)
|
|
defer cl.Close()
|
|
if cl.Dropped() {
|
|
t.Fatal("frische Verbindung gilt als abgebrochen")
|
|
}
|
|
(<-s.openTCP).Close() // Server/Netz weg
|
|
if !cl.WaitDropped(3 * time.Second) {
|
|
t.Fatal("Abbruch nicht erkannt")
|
|
}
|
|
}
|
|
|
|
func TestCloseIsNotADrop(t *testing.T) {
|
|
s := startStallServer(t, 100)
|
|
cl := dialStall(t, s)
|
|
cl.Close()
|
|
if cl.WaitDropped(500 * time.Millisecond) {
|
|
t.Fatal("eigenes Close darf nicht als Abbruch zählen")
|
|
}
|
|
}
|
|
|
|
func TestKeepAliveDetectsSilentLine(t *testing.T) {
|
|
s := startStallServer(t, 1)
|
|
cl := dialStall(t, s)
|
|
defer cl.Close()
|
|
cl.cancel() // Standard-Keepalive (10 s) stoppen, schnelle Variante testen
|
|
time.Sleep(50 * time.Millisecond)
|
|
s.seen.Store(0)
|
|
go cl.keepAliveLoop(context.Background(), 30*time.Millisecond, 300*time.Millisecond)
|
|
if !cl.WaitDropped(3 * time.Second) {
|
|
t.Fatal("stumme Leitung nicht erkannt")
|
|
}
|
|
if cl.Latency() <= 0 {
|
|
t.Fatal("Latenz der ersten Antwort fehlt")
|
|
}
|
|
}
|
|
|
|
func TestKeepAliveKeepsNeverAnsweringDevice(t *testing.T) {
|
|
// Gegenstelle antwortet nie auf Keepalives (manche Switches): nicht trennen.
|
|
s := startStallServer(t, 0)
|
|
cl := dialStall(t, s)
|
|
defer cl.Close()
|
|
cl.cancel()
|
|
go cl.keepAliveLoop(context.Background(), 20*time.Millisecond, 100*time.Millisecond)
|
|
if cl.WaitDropped(600 * time.Millisecond) {
|
|
t.Fatal("Verbindung ohne Keepalive-Antworten wurde getrennt")
|
|
}
|
|
}
|
|
|
|
func TestEncoding(t *testing.T) {
|
|
for in, want := range map[string]string{
|
|
"de_DE.UTF-8": "UTF-8", "en_US.utf8": "UTF-8", "C": "ASCII", "": "",
|
|
"de_DE.ISO-8859-1": "ISO-8859-1", "de_DE.UTF-8@euro": "UTF-8", "C.UTF-8": "UTF-8",
|
|
} {
|
|
if got := (RemoteInfo{Locale: in}).Encoding(); got != want {
|
|
t.Errorf("%q: %q, want %q", in, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPlainName(t *testing.T) {
|
|
for _, n := range []string{"a.txt", ".bashrc", "x y", "1:2.log"} {
|
|
if !plainName(n) {
|
|
t.Errorf("plainName(%q) = false", n)
|
|
}
|
|
}
|
|
for _, n := range []string{"", ".", "..", "../x", "a/b", `..\..\x`, "/etc/passwd"} {
|
|
if plainName(n) {
|
|
t.Errorf("plainName(%q) = true", n)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Windows meldet einen Reset als WSAECONNRESET mit deutschem oder
|
|
// englischem Text: zählt trotzdem als „Switch legt auf“ (neuer Versuch).
|
|
func TestIsHangupWindowsReset(t *testing.T) {
|
|
op := &net.OpError{Op: "read", Net: "tcp", Err: os.NewSyscallError("wsarecv", wsaECONNRESET)}
|
|
err := fmt.Errorf("ssh: handshake failed: %w", op)
|
|
if !isHangup(err) {
|
|
t.Fatalf("nicht erkannt: %v", err)
|
|
}
|
|
if isHangup(errors.New("ssh: unable to authenticate")) {
|
|
t.Fatal("Anmeldefehler als Auflegen gewertet")
|
|
}
|
|
}
|
|
|
|
// Nach Ruhezustand/Netzwechsel: Check trennt eine stumme Leitung sofort.
|
|
func TestCheckAfterResume(t *testing.T) {
|
|
s := startStallServer(t, 1)
|
|
cl := dialStall(t, s)
|
|
defer cl.Close()
|
|
deadline := time.Now().Add(3 * time.Second)
|
|
for !cl.answered.Load() && time.Now().Before(deadline) {
|
|
time.Sleep(10 * time.Millisecond)
|
|
}
|
|
if cl.Check(200 * time.Millisecond) {
|
|
t.Fatal("stumme Leitung gilt als lebendig")
|
|
}
|
|
if !cl.WaitDropped(time.Second) {
|
|
t.Fatal("nicht als Abbruch geschlossen")
|
|
}
|
|
|
|
ok := startStallServer(t, 100)
|
|
cl2 := dialStall(t, ok)
|
|
defer cl2.Close()
|
|
for !cl2.answered.Load() && time.Now().Before(deadline.Add(3*time.Second)) {
|
|
time.Sleep(10 * time.Millisecond)
|
|
}
|
|
if !cl2.Check(2 * time.Second) {
|
|
t.Fatal("gesunde Leitung getrennt")
|
|
}
|
|
}
|