Skip to content

Commit

Permalink
Fix issue around adding incorrect KnownHost
Browse files Browse the repository at this point in the history
Host should always be check against remote as it could be a name or an IP. but if the name is passed then it won t match the remote IP and therefore saved the incorrect entry in the known host
  • Loading branch information
Emmanuel Pinault committed Dec 16, 2020
1 parent f67d58a commit 8a2536e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ func AddKnownHost(host string, remote net.Addr, key ssh.PublicKey, knownFile str

defer f.Close()

knownHost := knownhosts.Normalize(remote.String())
remoteNormalized := knownhosts.Normalize(remote.String())
hostNormalized := knownhosts.Normalize(host)

knownHost := hostNormalized
if hostNormalized == remoteNormalized {
knownHost = remoteNormalized
}

_, err = f.WriteString(knownhosts.Line([]string{knownHost}, key) + "\n")

Expand Down

0 comments on commit 8a2536e

Please sign in to comment.