tailcfg, ipn/ipnlocal: add Hostinfo.SSH_HostKeys, send when SSH enabled

(The name SSH_HostKeys is bad but SSHHostKeys is worse.)

Updates #3802

Change-Id: I2a889019c9e8b065b668dd58140db4fcab868a91
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2022-02-17 15:00:41 -08:00
committed by Brad Fitzpatrick
parent 4609096271
commit bb93e29d5c
7 changed files with 52 additions and 8 deletions
+13 -3
View File
@@ -11,6 +11,7 @@ import (
"errors"
"io/ioutil"
"os"
"strings"
"golang.org/x/crypto/ssh"
"tailscale.com/envknob"
@@ -18,15 +19,16 @@ import (
var useHostKeys = envknob.Bool("TS_USE_SYSTEM_SSH_HOST_KEYS")
func (b *LocalBackend) GetSSHHostKeys() ([]ssh.Signer, error) {
func (b *LocalBackend) GetSSH_HostKeys() ([]ssh.Signer, error) {
// TODO(bradfitz): generate host keys, at least as needed if
// an existing SSH server didn't put them on disk. But also
// because people may want tailscale-specific ones. For now be
// lazy and reuse the host ones.
return b.getSystemSSHHostKeys()
return b.getSystemSSH_HostKeys()
}
func (b *LocalBackend) getSystemSSHHostKeys() (ret []ssh.Signer, err error) {
func (b *LocalBackend) getSystemSSH_HostKeys() (ret []ssh.Signer, err error) {
// TODO(bradfitz): cache this?
for _, typ := range []string{"rsa", "ecdsa", "ed25519"} {
hostKey, err := ioutil.ReadFile("/etc/ssh/ssh_host_" + typ + "_key")
if os.IsNotExist(err) {
@@ -46,3 +48,11 @@ func (b *LocalBackend) getSystemSSHHostKeys() (ret []ssh.Signer, err error) {
}
return ret, nil
}
func (b *LocalBackend) getSSHHostKeyPublicStrings() (ret []string) {
signers, _ := b.GetSSH_HostKeys()
for _, signer := range signers {
ret = append(ret, strings.TrimSpace(string(ssh.MarshalAuthorizedKey(signer.PublicKey()))))
}
return ret
}