Skip to content

Commit

Permalink
Merge branch 'main' into bucket-provider-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
pa250194 authored Jan 26, 2022
2 parents 336b945 + 93c636e commit 2ba7629
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pkg/git/libgit2/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,29 @@ func knownHostsCallback(host string, knownHosts []byte) git2go.CertificateCheckC

// First, attempt to split the configured host and port to validate
// the port-less hostname given to the callback.
h, _, err := net.SplitHostPort(host)
hostWithoutPort, _, err := net.SplitHostPort(host)
if err != nil {
// SplitHostPort returns an error if the host is missing
// a port, assume the host has no port.
h = host
hostWithoutPort = host
}

// Check if the configured host matches the hostname given to
// the callback.
if h != hostname {
// Different versions of libgit handle this differently.
// This fixes the case in which ports may be sent back.
hostnameWithoutPort, _, err := net.SplitHostPort(hostname)
if err != nil {
hostnameWithoutPort = hostname
}

if hostnameWithoutPort != hostWithoutPort {
return git2go.ErrorCodeUser
}

// We are now certain that the configured host and the hostname
// given to the callback match. Use the configured host (that
// includes the port), and normalize it, so we can check if there
// is an entry for the hostname _and_ port.
h = knownhosts.Normalize(host)
h := knownhosts.Normalize(host)
for _, k := range kh {
if k.matches(h, cert.Hostkey) {
return git2go.ErrorCodeOK
Expand Down

0 comments on commit 2ba7629

Please sign in to comment.