Added showHostKey function

This commit is contained in:
Thorsten Sommer 2017-07-02 13:45:34 +02:00
parent edfdb47f47
commit 444efe3d31

13
Main.go
View File

@ -3,8 +3,10 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"net"
"os" "os"
"runtime" "runtime"
"time"
"github.com/SommerEngineering/Sync/Sync" "github.com/SommerEngineering/Sync/Sync"
"github.com/howeyc/gopass" "github.com/howeyc/gopass"
@ -14,7 +16,7 @@ import (
func main() { func main() {
// Show the current version: // Show the current version:
log.Println(`Sync v1.3.0`) log.Println(`Sync v1.3.1`)
// Allow Go to use all CPUs: // Allow Go to use all CPUs:
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
@ -97,6 +99,7 @@ func main() {
ssh.PasswordCallback(Sync.PasswordCallback), ssh.PasswordCallback(Sync.PasswordCallback),
ssh.KeyboardInteractive(Sync.KeyboardInteractiveChallenge), ssh.KeyboardInteractive(Sync.KeyboardInteractiveChallenge),
}, },
HostKeyCallback: showHostKey(),
} }
// Connect to the SSH server: // Connect to the SSH server:
@ -111,3 +114,11 @@ func main() {
Sync.Synchronise(ssh, supervised, pushOnly, localDir, remoteDir) Sync.Synchronise(ssh, supervised, pushOnly, localDir, remoteDir)
log.Println("Synchronising done.") log.Println("Synchronising done.")
} }
func showHostKey() ssh.HostKeyCallback {
return func(hostname string, remote net.Addr, key ssh.PublicKey) error {
log.Printf("Your server's hostname is %s (%s) and its public key is %s. If this is wrong, please abort the program now! Wait 16 seconds for your check.", hostname, remote.String(), ssh.FingerprintSHA256(key))
time.Sleep(16 * time.Second)
return nil
}
}