mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-09-03 15:47:27 -04:00
Check against ~/.ssh/known_hosts
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
// global variables used across multiple files
|
// global variables used across multiple files
|
||||||
var (
|
var (
|
||||||
home, _ = os.UserHomeDir()
|
Home, _ = os.UserHomeDir()
|
||||||
)
|
)
|
||||||
|
|
||||||
// global constants used across multiple files
|
// global constants used across multiple files
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
package backend
|
package backend
|
||||||
|
|
||||||
// EntryRoot path to libmutton entry directory
|
// EntryRoot path to libmutton entry directory
|
||||||
var EntryRoot = home + "/.local/share/libmutton"
|
var EntryRoot = Home + "/.local/share/libmutton"
|
||||||
var ConfigDir = home + "/.config/libmutton"
|
var ConfigDir = Home + "/.config/libmutton"
|
||||||
var ConfigPath = ConfigDir + "/libmutton.ini"
|
var ConfigPath = ConfigDir + "/libmutton.ini"
|
||||||
|
|
||||||
// PathSeparator defines the character used to separate directories in a path (platform-specific)
|
// PathSeparator defines the character used to separate directories in a path (platform-specific)
|
||||||
|
|||||||
+9
-1
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/rwinkhart/MUTN/src/backend"
|
"github.com/rwinkhart/MUTN/src/backend"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
|
"golang.org/x/crypto/ssh/knownhosts"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -46,14 +47,21 @@ func getSSHOutput(cmd string, manualSync bool) string {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// read known hosts file
|
||||||
|
hostKeyCallback, err := knownhosts.New(backend.Home + "/.ssh/known_hosts")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(backend.AnsiError + "Sync failed - Unable to read known hosts file:" + err.Error() + backend.AnsiReset)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
// configure SSH client
|
// configure SSH client
|
||||||
sshConfig := &ssh.ClientConfig{
|
sshConfig := &ssh.ClientConfig{
|
||||||
User: user,
|
User: user,
|
||||||
Auth: []ssh.AuthMethod{
|
Auth: []ssh.AuthMethod{
|
||||||
ssh.PublicKeys(parsedKey),
|
ssh.PublicKeys(parsedKey),
|
||||||
},
|
},
|
||||||
|
HostKeyCallback: hostKeyCallback,
|
||||||
}
|
}
|
||||||
sshConfig.HostKeyCallback = ssh.InsecureIgnoreHostKey() // TODO remove
|
|
||||||
|
|
||||||
// connect to SSH server
|
// connect to SSH server
|
||||||
sshClient, err := ssh.Dial("tcp", ip+":"+port, sshConfig)
|
sshClient, err := ssh.Dial("tcp", ip+":"+port, sshConfig)
|
||||||
|
|||||||
Reference in New Issue
Block a user