mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-04 23:52:20 -08:00
ssh/tailssh: add OpenSSH ssh-mldsa44-ed25519 composite host key support
Add support for OpenSSH 10.6's composite ML-DSA-44 + Ed25519 host key format (ssh-mldsa44-ed25519, per draft-ietf-sshm-composite-sigs-00), enabled by the golang.org/x/crypto bump carrying upstream CL 848605 (golang/go#82315): - Look up /etc/ssh/ssh_host_mldsa44_ed25519_key (matching OpenSSH's _PATH_HOST_MLDSA44_ED25519_KEY_FILE) when running as root. - Generate and persist $TAILSCALE_VAR/ssh/ssh_host_mldsa44_ed25519_key in OpenSSH private key PEM format via ssh.GenerateCompositeKey and ssh.MarshalPrivateKey when no system key is present. - Cover ssh-mldsa44-ed25519 in host key generation, handshake, integration, and known_hosts tests. Updates #22864 Fixes #22807 Change-Id: I18daa6fee051f46792fc6e78896d9a8f6297b742 Signed-off-by: James Tucker <[email protected]>
This commit is contained in:
1 parent
6db878a571
commit
737e33224f
4 files changed
+45
-3
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 ""
|
||||
|
||||
Reference in new issue
Block a user