forked from Blendman974/faceclaw
Add an ssh client to Terminal, as an alternative to (or tunnel for) g2mirror
This commit is contained in:
1 parent
ab692741f7
commit
2b75a9d66e
33 files changed
+4694
-99
No files matched your search
@@ -0,0 +1,58 @@
|
||||
package faceclawssh
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestOpenSSHInterop checks the parts of the handshake that need no
|
||||
// credentials against a real sshd: key exchange, host key reporting and
|
||||
// pinning, and how an authentication refusal is classified. Opt-in:
|
||||
//
|
||||
// FACECLAW_SSH_INTEROP_ADDR=127.0.0.1:22 go test -run Interop -v
|
||||
//
|
||||
// Compare the logged fingerprint with `ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub`.
|
||||
// It makes one failed login attempt (no password, an unknown key) as
|
||||
// FACECLAW_SSH_INTEROP_USER (default: $USER).
|
||||
func TestOpenSSHInterop(t *testing.T) {
|
||||
addr := os.Getenv("FACECLAW_SSH_INTEROP_ADDR")
|
||||
if addr == "" {
|
||||
t.Skip("FACECLAW_SSH_INTEROP_ADDR not set")
|
||||
}
|
||||
defer resetPool()
|
||||
user := os.Getenv("FACECLAW_SSH_INTEROP_USER")
|
||||
if user == "" {
|
||||
user = os.Getenv("USER")
|
||||
}
|
||||
host, portText, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
port, _ := strconv.Atoi(portText)
|
||||
spec := func(hostKeys []string) string {
|
||||
encoded, _ := json.Marshal(openSpec{
|
||||
Host: host, Port: port, User: user, HostKeys: hostKeys, UseKey: true,
|
||||
Channel: channelSpec{Type: "exec", Command: "true"},
|
||||
})
|
||||
return string(encoded)
|
||||
}
|
||||
|
||||
rec := newRecorder()
|
||||
Open(spec(nil), newSoftwareSigner(t), rec)
|
||||
f := rec.expectFailure(t)
|
||||
if f.Kind != "hostkey-unknown" || f.HostKey == nil {
|
||||
t.Fatalf("first contact: %+v", f)
|
||||
}
|
||||
t.Logf("host key: %s %s", f.HostKey.Type, f.HostKey.Fingerprint)
|
||||
|
||||
rec = newRecorder()
|
||||
Open(spec([]string{f.HostKey.Key}), newSoftwareSigner(t), rec)
|
||||
auth := rec.expectFailure(t)
|
||||
if auth.Kind != "auth" || !auth.KeyTried {
|
||||
t.Fatalf("pinned, unknown key: %+v", auth)
|
||||
}
|
||||
t.Logf("auth refusal: %+v", auth)
|
||||
}
|
||||
Reference in new issue
Block a user