diff --git a/cmd/tailscale/cli/ssh_test.go b/cmd/tailscale/cli/ssh_test.go index 4332c9593..d1aad4885 100644 --- a/cmd/tailscale/cli/ssh_test.go +++ b/cmd/tailscale/cli/ssh_test.go @@ -147,6 +147,21 @@ func newMLDSA44TestKey(t *testing.T) (ssh.PublicKey, string) { return sshPub, strings.TrimSpace(string(ssh.MarshalAuthorizedKey(sshPub))) } +// newCompositeTestKey returns a new ssh-mldsa44-ed25519 SSH public key and its +// authorized_keys form, without the trailing newline. +func newCompositeTestKey(t *testing.T) (ssh.PublicKey, string) { + t.Helper() + priv, err := ssh.GenerateCompositeKey(ssh.KeyAlgoMLDSA44Ed25519) + if err != nil { + t.Fatal(err) + } + sshPub, err := ssh.NewPublicKey(priv.Public()) + if err != nil { + t.Fatal(err) + } + return sshPub, strings.TrimSpace(string(ssh.MarshalAuthorizedKey(sshPub))) +} + func TestGenKnownHostsPQ(t *testing.T) { if !slices.Contains(ssh.SupportedAlgorithms().HostKeys, ssh.KeyAlgoMLDSA44) { t.Skip("ML-DSA host keys are not supported in this build") @@ -154,11 +169,13 @@ func TestGenKnownHostsPQ(t *testing.T) { edKey, edStr := newSSHTestKey(t) pqKey, pqStr := newMLDSA44TestKey(t) otherPQKey, _ := newMLDSA44TestKey(t) + compKey, compStr := newCompositeTestKey(t) + otherCompKey, _ := newCompositeTestKey(t) foo := &ipnstate.PeerStatus{ DNSName: "foo.example.ts.net.", TailscaleIPs: []netip.Addr{netip.MustParseAddr("100.64.0.1")}, - SSH_HostKeys: []string{edStr, pqStr}, + SSH_HostKeys: []string{edStr, pqStr, compStr}, } st := sshTestStatus(foo) got := genKnownHosts(st) @@ -182,6 +199,9 @@ func TestGenKnownHostsPQ(t *testing.T) { {"dns_mldsa44", "foo.example.ts.net.", pqKey, false}, {"ip_mldsa44", "100.64.0.1", pqKey, false}, {"wrong_mldsa44", "foo.example.ts.net.", otherPQKey, true}, + {"dns_mldsa44_ed25519", "foo.example.ts.net.", compKey, false}, + {"ip_mldsa44_ed25519", "100.64.0.1", compKey, false}, + {"wrong_mldsa44_ed25519", "foo.example.ts.net.", otherCompKey, true}, } { err := check(net.JoinHostPort(tt.host, "22"), fakeAddr, tt.key) if (err != nil) != tt.wantErr { diff --git a/ssh/tailssh/hostkeys.go b/ssh/tailssh/hostkeys.go index fd6f93868..6c854a5d8 100644 --- a/ssh/tailssh/hostkeys.go +++ b/ssh/tailssh/hostkeys.go @@ -44,6 +44,7 @@ var allHostKeySpecs = []hostKeySpec{ {typ: "ecdsa", algo: ssh.KeyAlgoECDSA256}, {typ: "ed25519", algo: ssh.KeyAlgoED25519}, {typ: "mldsa44", algo: ssh.KeyAlgoMLDSA44}, + {typ: "mldsa44_ed25519", algo: ssh.KeyAlgoMLDSA44Ed25519}, } // supportedHostKeySpecs returns the entries in allHostKeySpecs whose algorithm @@ -197,6 +198,8 @@ func hostKeyFileOrCreate(keyDir, typ string) ([]byte, error) { priv, err = rsa.GenerateKey(rand.Reader, keySize) case "mldsa44": priv, err = mldsa.GenerateKey(mldsa.MLDSA44()) + case "mldsa44_ed25519": + priv, err = ssh.GenerateCompositeKey(ssh.KeyAlgoMLDSA44Ed25519) } if err != nil { return nil, err @@ -213,6 +216,13 @@ func hostKeyFileOrCreate(keyDir, typ string) ([]byte, error) { } func marshalHostPrivateKey(priv any) ([]byte, error) { + if _, ok := priv.(*ssh.CompositePrivateKey); ok { + block, err := ssh.MarshalPrivateKey(priv, "") + if err != nil { + return nil, err + } + return pem.EncodeToMemory(block), nil + } mk, err := x509.MarshalPKCS8PrivateKey(priv) if err != nil { return nil, err diff --git a/ssh/tailssh/hostkeys_test.go b/ssh/tailssh/hostkeys_test.go index 2862ef918..03d2e3864 100644 --- a/ssh/tailssh/hostkeys_test.go +++ b/ssh/tailssh/hostkeys_test.go @@ -7,6 +7,7 @@ package tailssh import ( "bytes" + "encoding/pem" "net" "os" "path/filepath" @@ -49,6 +50,17 @@ func TestSSHKeyGen(t *testing.T) { if slices.Contains(ssh.SupportedAlgorithms().HostKeys, ssh.KeyAlgoMLDSA44) { want[ssh.KeyAlgoMLDSA44] = true } + if slices.Contains(ssh.SupportedAlgorithms().HostKeys, ssh.KeyAlgoMLDSA44Ed25519) { + want[ssh.KeyAlgoMLDSA44Ed25519] = true + raw, err := os.ReadFile(filepath.Join(dir, "ssh", "ssh_host_mldsa44_ed25519_key")) + if err != nil { + t.Fatalf("read composite host key: %v", err) + } + block, _ := pem.Decode(raw) + if block == nil || block.Type != "OPENSSH PRIVATE KEY" { + t.Errorf("mldsa44_ed25519 PEM block = %v; want OPENSSH PRIVATE KEY", block) + } + } if !reflect.DeepEqual(got, want) { t.Fatalf("keys = %v; want %v", got, want) } diff --git a/ssh/tailssh/process_unix.go b/ssh/tailssh/process_unix.go index d64f74470..44c4f45d5 100644 --- a/ssh/tailssh/process_unix.go +++ b/ssh/tailssh/process_unix.go @@ -141,8 +141,8 @@ func (ss *sshSession) hangupProcess(mandated bool) { } // systemHostKeyFile returns the path of the system's OpenSSH host key of the -// given type (such as "rsa", "ecdsa", "ed25519", or "mldsa44") for tailssh to -// reuse, or "" when not running as root. +// given type (such as "rsa", "ecdsa", "ed25519", "mldsa44", or +// "mldsa44_ed25519") for tailssh to reuse, or "" when not running as root. func systemHostKeyFile(typ string) string { if os.Geteuid() != 0 { return ""